/* ── Reset & Base ─────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-tertiary: #1e293b;
    --bg-bubble-own: #2563eb;
    --bg-bubble-other: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.3);
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: rgba(255, 255, 255, 0.06);
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ── Modal ────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(12px);
    z-index: 100;
    animation: fadeIn 0.3s ease;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    max-width: 360px;
    width: 90%;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
    font-size: 28px;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent), #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 14px;
}

.modal-content input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 16px;
    outline: none;
    transition: border-color var(--transition);
    margin-bottom: 16px;
}

.modal-content input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.modal-content button {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    border: none;
    border-radius: var(--radius);
    color: white;
    font-family: var(--font);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.modal-content button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px var(--accent-glow);
}

.modal-content button:active {
    transform: translateY(0);
}

/* ── App Layout ───────────────────────────── */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 700px;
    margin: 0 auto;
}

#app.hidden {
    display: none;
}

/* ── Header ───────────────────────────────── */
#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.logo {
    font-size: 18px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-center {
    display: flex;
    align-items: center;
    gap: 6px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: background var(--transition);
}

.dot.online {
    background: var(--success);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.dot.offline {
    background: var(--danger);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

.dot.syncing {
    background: var(--warning);
    animation: pulse 1s infinite;
}

#status-text {
    font-size: 12px;
    color: var(--text-muted);
}

.user-badge {
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 4px 10px;
    border-radius: 20px;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

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

/* ── Messages ─────────────────────────────── */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}

#messages::-webkit-scrollbar {
    width: 4px;
}

#messages::-webkit-scrollbar-track {
    background: transparent;
}

#messages::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    animation: msgIn 0.25s ease;
    word-wrap: break-word;
    line-height: 1.45;
    font-size: 14.5px;
}

.msg.own {
    align-self: flex-end;
    background: var(--bg-bubble-own);
    border-bottom-right-radius: 4px;
    color: #fff;
}

.msg.other {
    align-self: flex-start;
    background: var(--bg-bubble-other);
    border-bottom-left-radius: 4px;
}

.msg-author {
    font-size: 12px;
    font-weight: 600;
    color: #818cf8;
    margin-bottom: 3px;
}

.msg.own .msg-author {
    display: none;
}

.msg-text {
    white-space: pre-wrap;
}

.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.45);
}

.msg.other .msg-meta {
    color: var(--text-muted);
}

.msg-status {
    font-size: 12px;
}

.msg.pending {
    opacity: 0.6;
}

.msg.sent {
    opacity: 1;
}

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

/* Date separator */
.date-sep {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 8px 0;
}

/* ── Compose ──────────────────────────────── */
#compose {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#msg-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 15px;
    outline: none;
    transition: border-color var(--transition);
}

#msg-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#msg-input::placeholder {
    color: var(--text-muted);
}

#send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
}

#send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px var(--accent-glow);
}

#send-btn:active {
    transform: scale(0.95);
}

/* ── Responsive ───────────────────────────── */
@media (max-width: 480px) {
    .modal-content {
        padding: 30px 24px;
    }

    .msg {
        max-width: 88%;
    }
}
