* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #5e72e4 0%, #825ee4 100%);
    color: white;
    padding: 40px;
    text-align: center;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1em;
    opacity: 0.9;
}

.sync-indicator {
    margin-top: 15px;
    padding: 10px 20px;
    background: rgba(255,255,255,0.2);
    border-radius: 20px;
    display: inline-block;
}

.sync-indicator span {
    font-size: 0.9em;
}

.status-synced { color: #10b981; font-weight: bold; }
.status-syncing { color: #f59e0b; font-weight: bold; }
.status-error { color: #ef4444; font-weight: bold; }
.status-idle { color: #cbd5e1; }

.error-message {
    display: block;
    margin-top: 5px;
    color: #fee2e2;
    font-size: 0.85em;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 30px;
    padding: 40px;
}

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

.left-panel, .right-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

h3 {
    color: #333;
    margin-bottom: 15px;
    font-size: 1.3em;
}

.message-form {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 8px;
    border: 2px solid #e9ecef;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #495057;
    font-weight: 600;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    font-size: 1em;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #5e72e4;
}

.form-group textarea {
    resize: vertical;
}

button {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, #5e72e4 0%, #825ee4 100%);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(94, 114, 228, 0.4);
}

.btn-danger {
    background: #dc3545;
    color: white;
    width: 100%;
}

.btn-danger:hover {
    background: #c82333;
    transform: translateY(-2px);
}

.actions {
    background: #fff3cd;
    padding: 20px;
    border-radius: 8px;
    border: 2px solid #ffc107;
}

.stats-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    background: #f8f9fa;
    padding: 25px;
    border-radius: 8px;
    border: 2px solid #e9ecef;
}

.stat {
    text-align: center;
    padding: 20px;
    background: white;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.stat-value {
    display: block;
    font-size: 2.5em;
    font-weight: bold;
    color: #5e72e4;
    margin-bottom: 8px;
}

.stat-label {
    display: block;
    color: #6c757d;
    font-size: 0.9em;
}

.messages-list {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 8px;
    border: 2px solid #e9ecef;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message-item {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.2s;
}

.message-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e9ecef;
}

.author {
    color: #5e72e4;
    font-size: 1.1em;
}

.timestamp {
    color: #6c757d;
    font-size: 0.85em;
}

.message-text {
    color: #333;
    line-height: 1.6;
}

.empty-state {
    text-align: center;
    color: #6c757d;
    padding: 40px;
    font-style: italic;
}

footer {
    background: #343a40;
    color: white;
    text-align: center;
    padding: 30px;
}

footer p {
    margin: 5px 0;
    opacity: 0.9;
}

.messages-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.messages-header h3 {
    margin-bottom: 0;
}

.btn-refresh {
    padding: 8px 16px;
    background: #5e72e4;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-refresh:hover:not(:disabled) {
    background: #4c5fd8;
    transform: translateY(-1px);
}

.btn-refresh:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

/* Authentication Styles */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 450px;
    width: 100%;
    margin: 20px;
    overflow: hidden;
}

.auth-header {
    background: linear-gradient(135deg, #5e72e4 0%, #825ee4 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

.auth-header h1 {
    font-size: 1.8em;
    margin-bottom: 10px;
}

.auth-header p {
    opacity: 0.9;
    font-size: 0.95em;
}

.auth-form {
    padding: 40px;
}

.auth-form h2 {
    color: #333;
    margin-bottom: 25px;
    text-align: center;
}

.auth-error {
    background: #fee2e2;
    color: #dc2626;
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 20px;
    border: 1px solid #fca5a5;
}

.auth-switch {
    text-align: center;
    margin-top: 20px;
    color: #6c757d;
    font-size: 0.9em;
}

.auth-switch a {
    color: #5e72e4;
    text-decoration: none;
    font-weight: 600;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* User Info Header */
.header-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    gap: 20px;
    flex-wrap: wrap;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(255,255,255,0.2);
    padding: 10px 20px;
    border-radius: 20px;
}

.user-name {
    color: white;
    font-weight: bold;
}

.btn-logout {
    background: rgba(255,255,255,0.3);
    color: white;
    border: none;
    padding: 6px 16px;
    border-radius: 15px;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: rgba(255,255,255,0.4);
}

/* Loading Screen */
.loading-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 1.5em;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .auth-card {
        margin: 10px;
    }

    .auth-form {
        padding: 30px 20px;
    }

    .header-controls {
        flex-direction: column;
        align-items: stretch;
    }
}

/* ============================================ */
/* MESSAGE EDITING & HISTORY STYLES */
/* ============================================ */

/* Editable Message Item */
.message-item-editable {
    cursor: pointer;
    position: relative;
}

.message-item-editable:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(94, 114, 228, 0.3);
    border: 2px solid #5e72e4;
}

.message-edit-hint {
    margin-top: 8px;
    font-size: 0.8em;
    color: #5e72e4;
    font-style: italic;
    opacity: 0;
    transition: opacity 0.2s;
}

.message-item-editable:hover .message-edit-hint {
    opacity: 1;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Modal Content */
.modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 700px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Modal Header */
.modal-header {
    background: linear-gradient(135deg, #5e72e4 0%, #825ee4 100%);
    color: white;
    padding: 25px 30px;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: white;
    font-size: 1.5em;
}

.modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 2em;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* Modal Body */
.modal-body {
    padding: 30px;
}

.edit-textarea {
    width: 100%;
    min-height: 150px;
    padding: 15px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-size: 1em;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.2s;
}

.edit-textarea:focus {
    outline: none;
    border-color: #5e72e4;
    box-shadow: 0 0 0 3px rgba(94, 114, 228, 0.1);
}

/* Modal Actions */
.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.modal-actions button {
    flex: 1;
    min-width: 120px;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.btn-cancel {
    background: #e9ecef;
    color: #495057;
}

.btn-cancel:hover {
    background: #dee2e6;
    transform: translateY(-2px);
}

/* History View */
.history-view {
    margin-top: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px solid #e9ecef;
}

.history-view h4 {
    color: #333;
    margin-bottom: 15px;
    font-size: 1.2em;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-height: 400px;
    overflow-y: auto;
}

/* History Item */
.history-item {
    background: white;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    transition: all 0.2s;
}

.history-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateX(5px);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e9ecef;
}

.history-version {
    font-weight: bold;
    color: #5e72e4;
    font-size: 0.9em;
}

.history-timestamp {
    color: #6c757d;
    font-size: 0.85em;
}

.history-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-author,
.history-text,
.history-updated {
    color: #495057;
    font-size: 0.9em;
    line-height: 1.5;
}

.history-text {
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
    border-left: 3px solid #5e72e4;
}

/* History Timeline */
.history-timeline {
    margin-top: 25px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px solid #e9ecef;
}

.history-timeline h4 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.2em;
}

.timeline-events {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-height: 500px;
    overflow-y: auto;
    padding-left: 30px;
    position: relative;
}

/* Timeline vertical line */
.timeline-events::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #dee2e6;
}

.timeline-event {
    position: relative;
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.event-marker {
    position: absolute;
    left: -25px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.1em;
    background: white;
    border: 3px solid;
    z-index: 1;
}

.event-created .event-marker {
    border-color: #10b981;
    color: #10b981;
    background: #d1fae5;
}

.event-edited .event-marker {
    border-color: #3b82f6;
    color: #3b82f6;
    background: #dbeafe;
}

.event-deleted .event-marker {
    border-color: #ef4444;
    color: #ef4444;
    background: #fee2e2;
}

.event-restored .event-marker {
    border-color: #8b5cf6;
    color: #8b5cf6;
    background: #ede9fe;
}

.event-unknown .event-marker {
    border-color: #6c757d;
    color: #6c757d;
    background: #e9ecef;
}

.event-details {
    flex: 1;
    background: white;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.event-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e9ecef;
}

.event-type {
    font-weight: bold;
    font-size: 1em;
}

.event-created .event-type {
    color: #10b981;
}

.event-edited .event-type {
    color: #3b82f6;
}

.event-deleted .event-type {
    color: #ef4444;
}

.event-restored .event-type {
    color: #8b5cf6;
}

.event-time {
    color: #6c757d;
    font-size: 0.85em;
}

.event-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.event-author {
    color: #495057;
    font-size: 0.9em;
}

.event-text {
    padding: 10px;
    background: #f8f9fa;
    border-radius: 4px;
    border-left: 3px solid #5e72e4;
    color: #333;
    line-height: 1.5;
    font-size: 0.95em;
}

/* Deleted Message Notice */
.deleted-message-notice {
    background: #fee2e2;
    border: 2px solid #ef4444;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #dc2626;
    font-weight: bold;
}

.red-x {
    font-size: 1.5em;
    color: #ef4444;
}

.readonly-text {
    padding: 15px;
    background: #f8f9fa;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    color: #333;
    line-height: 1.6;
    min-height: 100px;
    white-space: pre-wrap;
}

/* Deleted Messages Toggle */
.messages-controls {
    margin-bottom: 15px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.deleted-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
}

.deleted-toggle label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    color: #495057;
    font-size: 0.95em;
}

.deleted-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #5e72e4;
}

/* Responsive Modal */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        max-height: 90vh;
    }

    .modal-body {
        padding: 20px;
    }

    .modal-actions {
        flex-direction: column;
    }

    .modal-actions button {
        width: 100%;
    }

    .history-list {
        max-height: 300px;
    }

    .timeline-events {
        padding-left: 25px;
        max-height: 400px;
    }

    .event-marker {
        left: -22px;
        width: 26px;
        height: 26px;
        font-size: 1em;
    }
}
