/* ============================================================
   Nexus Messenger — Styles v2.0
   Dark + Light theme, responsive (mobile/tablet/desktop)
   ============================================================ */

/* ── Dark theme (default) ─────────────────────────────── */
:root, [data-theme="dark"] {
    --bg-deep:       #0d0f14;
    --bg-base:       #111318;
    --bg-raised:     #181b22;
    --bg-overlay:    #1e2130;
    --bg-hover:      #232738;
    --bg-active:     #262c3d;
    --border:        rgba(255,255,255,0.07);
    --border-strong: rgba(255,255,255,0.13);
    --text-primary:  #e8eaf0;
    --text-secondary:#8a8fa8;
    --text-muted:    #565b73;
    --text-inverse:  #0d0f14;
    --shadow-sm:     0 2px 8px rgba(0,0,0,0.4);
    --shadow-md:     0 4px 20px rgba(0,0,0,0.5);
    --shadow-lg:     0 8px 40px rgba(0,0,0,0.6);
    --scrollbar-bg:  rgba(255,255,255,0.08);
    --theme-icon:    '☀️';
}

/* ── Light theme ──────────────────────────────────────── */
[data-theme="light"] {
    --bg-deep:       #f0f2f7;
    --bg-base:       #ffffff;
    --bg-raised:     #f8f9fc;
    --bg-overlay:    #eef0f6;
    --bg-hover:      #e8ecf4;
    --bg-active:     #dde3f0;
    --border:        rgba(0,0,0,0.08);
    --border-strong: rgba(0,0,0,0.15);
    --text-primary:  #1a1d2e;
    --text-secondary:#5a6080;
    --text-muted:    #9096b0;
    --text-inverse:  #ffffff;
    --shadow-sm:     0 2px 8px rgba(0,0,0,0.08);
    --shadow-md:     0 4px 20px rgba(0,0,0,0.12);
    --shadow-lg:     0 8px 40px rgba(0,0,0,0.16);
    --scrollbar-bg:  rgba(0,0,0,0.1);
    --theme-icon:    '🌙';
}

/* ── Shared tokens ────────────────────────────────────── */
:root {
    --accent:        #4f8aff;
    --accent-dim:    rgba(79,138,255,0.15);
    --accent-hover:  #6b9fff;
    --green:         #3dd68c;
    --green-dim:     rgba(61,214,140,0.15);
    --red:           #ff5f5f;
    --red-dim:       rgba(255,95,95,0.15);
    --orange:        #ff9f40;
    --yellow:        #ffd166;
    --sidebar-w:     320px;
    --header-h:      60px;
    --input-h:       56px;
    --radius-sm:     6px;
    --radius-md:     10px;
    --radius-lg:     16px;
    --radius-full:   9999px;
    --font-mono:     'Space Mono', monospace;
    --font-sans:     'DM Sans', sans-serif;
    --trans:         150ms cubic-bezier(0.4,0,0.2,1);
    --trans-slow:    300ms cubic-bezier(0.4,0,0.2,1);
}

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

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

::selection { background: var(--accent-dim); color: var(--text-primary); }

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-bg); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Visibility helpers ─────────────────────────────────── */
.hidden { display: none !important; }

/* ── Screens ─────────────────────────────────────────────── */
.screen { display: none; height: 100%; }
.screen.active { display: flex; }
.screen.hidden { display: none !important; }

/* ── Auth Screen ─────────────────────────────────────────── */
#auth-screen {
    align-items: center;
    justify-content: center;
    background: var(--bg-deep);
    position: relative;
    overflow: hidden;
}

.auth-bg { position: absolute; inset: 0; pointer-events: none; }
.auth-grid {
    position: absolute; inset: 0;
    background-image:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, black 30%, transparent 100%);
    opacity: 0.6;
}

.auth-container { width: 100%; max-width: 420px; padding: 24px; position: relative; z-index: 1; }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 40px; justify-content: center; }
.logo-text { font-family: var(--font-mono); font-size: 22px; font-weight: 700; letter-spacing: 6px; color: var(--text-primary); }

.auth-form {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-lg);
}
.auth-title { font-family: var(--font-mono); font-size: 20px; font-weight: 700; margin-bottom: 6px; color: var(--text-primary); }
.auth-sub { font-size: 13px; color: var(--text-secondary); margin-bottom: 28px; }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: 12px; font-weight: 500; color: var(--text-secondary);
    margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.8px; font-family: var(--font-mono);
}
.form-group input {
    width: 100%; background: var(--bg-overlay); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary); font-family: var(--font-sans);
    font-size: 14px; padding: 10px 14px; outline: none; transition: border-color var(--trans);
}
.form-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.form-group select {
    width: 100%; background: var(--bg-overlay); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary); font-size: 14px;
    padding: 10px 14px; outline: none; cursor: pointer;
}
.form-group textarea {
    width: 100%; background: var(--bg-overlay); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary); font-family: var(--font-sans);
    font-size: 14px; padding: 10px 14px; outline: none; resize: vertical; min-height: 80px;
    transition: border-color var(--trans);
}
.form-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

.input-wrapper { position: relative; }
.input-wrapper input { padding-right: 44px; }
.toggle-pw {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px;
}

.form-error { font-size: 12px; color: var(--red); margin-top: 4px; padding: 6px 10px; background: var(--red-dim); border-radius: var(--radius-sm); }

.btn-primary {
    width: 100%; padding: 12px; background: var(--accent); border: none;
    border-radius: var(--radius-sm); color: #fff; font-family: var(--font-sans);
    font-size: 14px; font-weight: 600; cursor: pointer; transition: background var(--trans);
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-loader { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth-switch { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-secondary); }
.auth-switch a { color: var(--accent); text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

.invite-status { font-size: 12px; margin-top: 4px; }
.invite-status.valid { color: var(--green); }
.invite-status.invalid { color: var(--red); }

/* ── App Screen ──────────────────────────────────────────── */
#app-screen { flex-direction: row; background: var(--bg-deep); overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    height: 100%;
    background: var(--bg-base);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform var(--trans-slow);
}

.sidebar-header {
    height: var(--header-h);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; }
.sidebar-logo-icon { color: var(--accent); display: flex; }
.sidebar-logo-text { font-family: var(--font-mono); font-size: 15px; font-weight: 700; letter-spacing: 3px; color: var(--text-primary); }
.sidebar-actions { display: flex; gap: 4px; }

.search-wrap { padding: 12px 12px 8px; flex-shrink: 0; }
.search-box {
    display: flex; align-items: center; gap: 8px; background: var(--bg-overlay);
    border: 1px solid var(--border); border-radius: var(--radius-full); padding: 8px 14px;
    transition: border-color var(--trans);
}
.search-box:focus-within { border-color: var(--accent); }
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.search-box input { background: none; border: none; outline: none; color: var(--text-primary); font-family: var(--font-sans); font-size: 13px; width: 100%; }
.search-box input::placeholder { color: var(--text-muted); }

.chat-list { flex: 1; overflow-y: auto; }
.chat-list-empty { padding: 40px 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

.chat-item {
    display: flex; align-items: center; gap: 12px; padding: 10px 16px;
    cursor: pointer; border-bottom: 1px solid var(--border);
    transition: background var(--trans); position: relative;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active {
    background: var(--bg-active);
    border-left: 3px solid var(--accent);
}
.chat-item-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.chat-item-top {
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.chat-item-name {
    font-size: 14px; font-weight: 600; color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.chat-item-handle { font-size: 11px; color: var(--text-muted); font-weight: 400; margin-left: 4px; }
.chat-item-time { font-size: 11px; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.chat-item-bottom {
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.chat-item-preview {
    font-size: 12.5px; color: var(--text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.chat-item-badge {
    background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
    min-width: 20px; height: 20px; border-radius: 10px; display: flex; align-items: center;
    justify-content: center; padding: 0 6px; flex-shrink: 0;
    box-shadow: 0 2px 8px var(--accent-dim);
}
.chat-item-badge-placeholder { width: 0; flex-shrink: 0; }
.chat-type-badge {
    font-size: 10px; background: var(--bg-overlay); color: var(--text-muted);
    padding: 1px 5px; border-radius: 3px; margin-left: 4px; flex-shrink: 0; font-family: var(--font-mono);
}

.sidebar-footer {
    padding: 12px 16px; border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.my-avatar-wrap { flex-shrink: 0; }
.my-info { flex: 1; min-width: 0; }
#my-username { font-size: 14px; font-weight: 500; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#my-role { font-size: 11px; color: var(--text-muted); }
.sidebar-footer-actions { display: flex; gap: 2px; }

/* ── Avatar ──────────────────────────────────────────────── */
.avatar {
    border-radius: var(--radius-full);
    background: var(--accent-dim);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: var(--accent); font-family: var(--font-mono);
    flex-shrink: 0; overflow: hidden; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 36px; height: 36px; font-size: 14px; }
.avatar.md { width: 44px; height: 44px; font-size: 17px; }
.avatar.lg { width: 60px; height: 60px; font-size: 24px; }
.avatar.xl { width: 80px; height: 80px; font-size: 32px; }

/* ── Buttons ─────────────────────────────────────────────── */
.icon-btn {
    width: 34px; height: 34px; border-radius: var(--radius-sm); border: none;
    background: transparent; color: var(--text-secondary); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background var(--trans), color var(--trans);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn.active { background: var(--accent-dim); color: var(--accent); }

/* ── Chat Area ───────────────────────────────────────────── */
.chat-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg-deep); min-width: 0; }

/* Empty state */
.empty-state {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 16px; color: var(--text-muted); padding: 40px;
}
.empty-state-icon { opacity: 0.4; }
.empty-state h3 { font-size: 18px; font-weight: 600; color: var(--text-secondary); }
.empty-state p { font-size: 13px; text-align: center; max-width: 280px; }

/* Chat view */
.chat-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.chat-header {
    height: var(--header-h); padding: 0 16px; display: flex; align-items: center;
    gap: 12px; border-bottom: 1px solid var(--border);
    background: var(--bg-base); flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name { font-size: 15px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-status { font-size: 12px; color: var(--text-muted); }
.chat-header-actions { display: flex; gap: 4px; }

/* Messages */
.messages-container {
    flex: 1; overflow-y: auto; padding: 12px 16px 8px;
    display: flex; flex-direction: column; position: relative;
    background: var(--bg-deep);
}

/* Message highlight on scroll-to */
@keyframes msgHighlight {
    0%   { background: rgba(59,130,246,0.35); }
    60%  { background: rgba(59,130,246,0.18); }
    100% { background: transparent; }
}
.msg-highlight { animation: msgHighlight 1.8s ease forwards; border-radius: 8px; }

/* Date separator */
.date-sep {
    display: flex; align-items: center; justify-content: center; margin: 16px 0 10px;
}
.date-sep span {
    background: var(--bg-overlay); color: var(--text-muted); font-size: 11px;
    padding: 3px 12px; border-radius: 10px; border: 1px solid var(--border);
}

/* Message row */
.msg-row {
    display: flex; align-items: flex-end; gap: 8px;
    margin-bottom: 2px; max-width: 100%;
    animation: msgIn 0.15s ease;
}
@keyframes msgIn { from { opacity:0; transform:translateY(4px); } to { opacity:1; transform:none; } }
.msg-row:not(.continuation) { margin-top: 10px; }
.msg-row.continuation { margin-top: 2px; }
.msg-row.own { flex-direction: row-reverse; }

/* Avatar */
.msg-avatar { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; margin-bottom: 2px; }
.msg-row.own .msg-avatar,
.msg-row.continuation .msg-avatar { visibility: hidden; }

/* Group */
.msg-group { display: flex; flex-direction: column; max-width: min(480px, 72vw); gap: 1px; }
.msg-row.own .msg-group { align-items: flex-end; }

/* Sender name */
.msg-sender { font-size: 12px; font-weight: 600; padding: 0 2px; margin-bottom: 2px; }

/* Bubble */
.msg-bubble {
    padding: 8px 12px; border-radius: 16px;
    word-break: break-word; line-height: 1.5;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
    position: relative;
}
/* Incoming */
.msg-row:not(.own) .msg-bubble {
    background: #252836; border: 1px solid rgba(255,255,255,0.08);
    border-bottom-left-radius: 4px; color: #e8eaf0;
}
[data-theme="light"] .msg-row:not(.own) .msg-bubble {
    background: #fff; border: 1px solid rgba(0,0,0,0.09);
    color: #1a1c23;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.msg-row:not(.own).continuation .msg-bubble {
    border-top-left-radius: 4px; border-bottom-left-radius: 4px;
    background: #252836;
}
[data-theme="light"] .msg-row:not(.own).continuation .msg-bubble {
    background: #fff;
}
.msg-row:not(.own) .msg-group .msg-bubble:last-of-type { border-bottom-left-radius: 16px; }
/* Own */
.msg-row.own .msg-bubble {
    background: #1a56db; border: none;
    border-bottom-right-radius: 4px; color: #f0f4ff;
}
.msg-row.own.continuation .msg-bubble {
    border-top-right-radius: 4px; border-bottom-right-radius: 4px;
}
.msg-row.own .msg-group .msg-bubble:last-of-type { border-bottom-right-radius: 16px; }
.msg-bubble.deleted { opacity: 0.6; font-style: italic; font-size: 13px; }

/* Content */
.msg-content { font-size: 14px; white-space: pre-wrap; }

/* Meta (time + status) */
.msg-meta {
    display: inline-flex; align-items: center; gap: 3px;
    float: right; margin: 2px -2px -2px 8px;
    font-size: 11px; white-space: nowrap; opacity: 0.75;
}
.msg-row.own .msg-meta { color: rgba(220,235,255,0.9); }
.msg-row:not(.own) .msg-meta { color: var(--text-muted); }

/* Reply */
.msg-reply-bar {
    background: rgba(255,255,255,0.07); border-left: 3px solid var(--accent);
    border-radius: 6px 6px 0 0; padding: 6px 8px; margin-bottom: 6px;
    font-size: 12px; cursor: pointer; overflow: hidden; max-height: 52px;
    transition: background 0.15s;
}
.msg-reply-bar:hover { background: rgba(255,255,255,0.12); }
.msg-row.own .msg-reply-bar {
    background: rgba(255,255,255,0.15); border-left-color: rgba(255,255,255,0.9); color: rgba(255,255,255,0.9);
}

/* Reactions */
.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.reaction-chip {
    background: var(--bg-overlay); border: 1px solid var(--border); border-radius: 12px;
    padding: 2px 8px; font-size: 12px; cursor: pointer; display: flex;
    align-items: center; gap: 3px; transition: background var(--trans); user-select: none;
}
.reaction-chip:hover { background: var(--bg-hover); }
.reaction-count { font-size: 11px; color: var(--text-secondary); }

/* System message */
.msg-system {
    text-align: center; color: var(--text-muted); font-size: 12px; padding: 3px 14px;
    margin: 4px auto; background: var(--bg-overlay); border-radius: 10px; align-self: center;
}

/* Media */
.msg-media { max-width: 280px; }
.msg-media img { width: 100%; border-radius: 10px; cursor: pointer; display: block; }
.media-info { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.media-icon {
    width: 36px; height: 36px; background: var(--accent-dim); border-radius: 8px;
    display: flex; align-items: center; justify-content: center; color: var(--accent); flex-shrink: 0;
}


/* Input area */
.input-area {
    padding: 12px 16px; border-top: 1px solid var(--border);
    background: var(--bg-base); flex-shrink: 0;
}
.reply-preview {
    display: flex; align-items: center; gap: 8px; background: var(--bg-overlay);
    border-radius: var(--radius-sm); padding: 6px 10px; margin-bottom: 8px;
    border-left: 3px solid var(--accent);
}
.reply-preview-text { flex: 1; font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.input-row { display: flex; align-items: flex-end; gap: 8px; }
#message-input {
    flex: 1; background: var(--bg-overlay); border: 1px solid var(--border);
    border-radius: var(--radius-md); color: var(--text-primary); font-family: var(--font-sans);
    font-size: 14px; padding: 10px 14px; outline: none; resize: none; max-height: 160px;
    min-height: 44px; line-height: 1.5; transition: border-color var(--trans);
}
#message-input:focus { border-color: var(--accent); }
#message-input::placeholder { color: var(--text-muted); }

.send-btn {
    width: 44px; height: 44px; border-radius: var(--radius-md); border: none;
    background: var(--accent); color: #fff; cursor: pointer; display: flex;
    align-items: center; justify-content: center; transition: background var(--trans); flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-hover); }

/* Typing indicator */
.typing-indicator { padding: 6px 20px; font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.typing-dots span { display: inline-block; width: 4px; height: 4px; background: var(--text-muted); border-radius: 50%; animation: typing-dot 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-dot { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }

/* Scroll to bottom */
.scroll-bottom {
    position: absolute; bottom: 80px; right: 24px; width: 36px; height: 36px;
    border-radius: var(--radius-full); background: var(--bg-raised); border: 1px solid var(--border);
    color: var(--text-secondary); cursor: pointer; display: flex; align-items: center;
    justify-content: center; box-shadow: var(--shadow-md); transition: background var(--trans);
}
.scroll-bottom:hover { background: var(--bg-overlay); color: var(--text-primary); }
.unread-badge {
    position: absolute; top: -6px; right: -6px; background: var(--accent); color: #fff;
    font-size: 10px; font-weight: 700; min-width: 18px; height: 18px;
    border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 4px;
}

/* Media messages */
.msg-media { max-width: 300px; }
.msg-media img { width: 100%; border-radius: var(--radius-sm); cursor: pointer; display: block; }
.media-info { display: flex; align-items: center; gap: 8px; padding: 8px 0; }
.media-icon { width: 36px; height: 36px; background: var(--accent-dim); border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; color: var(--accent); flex-shrink: 0; }
.media-name { font-size: 13px; color: var(--text-primary); word-break: break-all; }
.media-progress { height: 3px; background: var(--border); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.media-progress-bar { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.3s; }
.media-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); opacity: 0; transition: opacity var(--trans); }
.msg-media:hover .media-overlay { opacity: 1; }

/* Info panel */
.info-panel {
    width: 300px; min-width: 300px; height: 100%; background: var(--bg-base);
    border-left: 1px solid var(--border); display: flex; flex-direction: column;
    overflow: hidden; transition: width var(--trans-slow), min-width var(--trans-slow);
}
.info-panel.hidden { width: 0; min-width: 0; }
.info-panel:not(.hidden) { display: flex; }
.info-panel-header { height: var(--header-h); padding: 0 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.info-panel-header h3 { font-size: 14px; font-weight: 600; }
.info-panel-body { flex: 1; overflow-y: auto; padding: 20px; }
.info-section { margin-bottom: 24px; }
.info-section-title { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; font-family: var(--font-mono); margin-bottom: 12px; }
.info-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.info-row:last-child { border-bottom: none; }
.info-row-label { font-size: 12px; color: var(--text-muted); min-width: 80px; }
.info-row-value { font-size: 13px; color: var(--text-primary); word-break: break-all; }

/* Context menu */
.context-menu {
    position: fixed; background: var(--bg-raised); border: 1px solid var(--border-strong);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg); min-width: 180px;
    z-index: 1000; overflow: hidden; animation: fadeIn 0.1s ease;
}
.context-item {
    padding: 9px 16px; font-size: 13px; cursor: pointer; display: flex; align-items: center;
    gap: 10px; color: var(--text-primary); transition: background var(--trans);
}
.context-item:hover { background: var(--bg-hover); }
.context-item.danger { color: var(--red); }
.context-item.danger:hover { background: var(--red-dim); }
.context-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex;
    align-items: center; justify-content: center; z-index: 1000;
    backdrop-filter: blur(4px); animation: fadeIn 0.15s ease;
    padding: 16px;
}
.modal-box {
    background: var(--bg-raised); border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg); width: 100%; max-width: 480px;
    box-shadow: var(--shadow-lg); animation: slideUp 0.2s ease; max-height: 90vh; display: flex; flex-direction: column;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-header h3 { font-family: var(--font-mono); font-size: 14px; font-weight: 700; letter-spacing: 0.5px; }
.modal-content { padding: 20px; overflow-y: auto; }

/* Toast */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; }
.toast {
    background: var(--bg-overlay); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    padding: 12px 16px; font-size: 13px; color: var(--text-primary); box-shadow: var(--shadow-md);
    display: flex; align-items: center; gap: 10px; max-width: 320px; animation: slideIn 0.2s ease;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }
.toast.warn    { border-left: 3px solid var(--orange); }

/* Admin screen */
#admin-screen { flex-direction: row; background: var(--bg-deep); }

/* Sidebar */
.admin-sidebar {
    width: 220px; flex-shrink: 0; background: var(--bg-surface);
    border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.admin-header { height: var(--header-h); padding: 0 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.admin-header h2 { font-size: 15px; font-weight: 700; font-family: var(--font-mono); }
.admin-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.admin-nav-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 16px;
    font-size: 13px; color: var(--text-secondary); cursor: pointer;
    text-decoration: none; border-left: 3px solid transparent;
    transition: all var(--trans);
}
.admin-nav-item:hover  { background: var(--bg-hover); color: var(--text-primary); }
.admin-nav-item.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-dim); }
.admin-main { flex: 1; overflow-y: auto; padding: 24px 28px; min-width: 0; }

/* Section header */
.admin-section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.admin-section-header h2 { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }

/* Stats grid */
.astat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 14px; margin-bottom: 20px; }
.astat-card { background: var(--bg-raised); border: 1px solid var(--border); border-radius: 12px; padding: 16px; display: flex; gap: 14px; align-items: flex-start; }
.astat-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.astat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.astat-value { font-size: 24px; font-weight: 700; color: var(--text-primary); line-height: 1; }
.astat-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* Info card */
.ainfo-card { background: var(--bg-raised); border: 1px solid var(--border); border-radius: 12px; padding: 16px 20px; margin-bottom: 20px; }
.ainfo-title { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.8px; font-family: var(--font-mono); margin-bottom: 12px; }
.ainfo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ainfo-item { display: flex; gap: 8px; font-size: 13px; }
.ainfo-key { color: var(--text-muted); min-width: 100px; }

/* Toolbar */
.atoolbar { margin-bottom: 14px; }
.asearch { width: 100%; max-width: 380px; background: var(--bg-raised); border: 1px solid var(--border); border-radius: 8px; padding: 9px 14px; color: var(--text-primary); font-size: 13px; outline: none; transition: border-color var(--trans); }
.asearch:focus { border-color: var(--accent); }

/* Table */
.atable-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
.atable { width: 100%; border-collapse: collapse; font-size: 13px; }
.atable th { text-align: left; padding: 10px 14px; font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); background: var(--bg-raised); }
.atable td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.atable tr:last-child td { border-bottom: none; }
.atable tr:hover td { background: var(--bg-hover); }
.aempty-row { text-align: center; color: var(--text-muted); padding: 32px !important; }
.amore-wrap { text-align: center; margin-top: 14px; }

/* Cells */
.auser-cell { display: flex; align-items: center; gap: 10px; }
.aavatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.atype-icon { width: 32px; height: 32px; border-radius: 8px; background: var(--bg-overlay); display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.afont-med { font-weight: 500; color: var(--text-primary); }
.amuted { color: var(--text-muted); font-size: 12px; }
.asmall { font-size: 12px; }
.amono { font-family: var(--font-mono); }
.aaccent { color: var(--accent); }
.acount { font-size: 13px; font-weight: 400; color: var(--text-muted); margin-left: 6px; }

/* Badges */
.abadge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.abadge-green  { background: #10b98120; color: #10b981; }
.abadge-gray   { background: var(--bg-overlay); color: var(--text-muted); }
.abadge-blue   { background: #3b82f620; color: #3b82f6; }
.abadge-purple { background: #8b5cf620; color: #8b5cf6; }

/* Buttons */
.abtns { display: flex; gap: 4px; flex-wrap: wrap; }
.abtn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 500; cursor: pointer; border: 1px solid var(--border); background: var(--bg-overlay); color: var(--text-primary); transition: all var(--trans); }
.abtn:hover { background: var(--bg-hover); }
.abtn:disabled { opacity: 0.5; cursor: default; }
.abtn-sm { padding: 4px 10px; font-size: 12px; }
.abtn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.abtn-primary:hover { background: var(--accent-hover, #1a56db); }
.abtn-danger { background: var(--red-dim); color: var(--red); border-color: var(--red); }
.abtn-danger:hover { background: var(--red); color: #fff; }
.abtn-ok { background: #10b98115; color: #10b981; border-color: #10b981; }

/* Invite code */
.ainvite-code { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.ainvite-code:hover .acopy-hint { opacity: 1; }
.acopy-hint { opacity: 0; font-size: 14px; transition: opacity var(--trans); }

/* Invite result */
.ainv-result { margin-top: 14px; padding: 12px 14px; background: #10b98115; border: 1px solid #10b981; border-radius: 8px; }
.ainv-result-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.ainv-code { font-family: var(--font-mono); font-size: 18px; color: var(--accent); cursor: pointer; letter-spacing: 2px; }
.ainv-code:hover { text-decoration: underline; }

/* Forms */
.aform-group { margin-bottom: 14px; }
.aform-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.aform-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.aform-input { width: 100%; background: var(--bg-raised); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; color: var(--text-primary); font-size: 13px; outline: none; box-sizing: border-box; transition: border-color var(--trans); }
.aform-input:focus { border-color: var(--accent); }
textarea.aform-input { resize: vertical; }

/* Settings */
.asettings-form { max-width: 540px; }
.asettings-section { background: var(--bg-raised); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; margin-bottom: 14px; }
.asettings-section-title { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 14px; }
.asettings-actions { display: flex; align-items: center; gap: 16px; margin-top: 4px; }
.asettings-status { font-size: 13px; }

/* Role modal */
.arole-list { display: flex; flex-direction: column; gap: 8px; }
.arole-btn { text-align: left; padding: 12px 14px; background: var(--bg-raised); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; transition: all var(--trans); width: 100%; }
.arole-btn:hover { border-color: var(--accent); background: var(--accent-dim); }
.arole-label { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.arole-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Misc */
.admin-loading { display: flex; justify-content: center; padding: 48px; }
.admin-error { color: var(--red); padding: 20px; background: var(--red-dim); border-radius: 8px; margin: 20px 0; }
.admin-empty { color: var(--text-muted); padding: 48px; text-align: center; font-size: 14px; }
.acode { font-family: var(--font-mono); background: var(--bg-overlay); padding: 2px 6px; border-radius: 4px; font-size: 12px; }


/* Badges */
.badge {
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px;
    border-radius: var(--radius-sm); font-size: 11px; font-family: var(--font-mono);
    font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
}
.badge.online   { background: var(--green-dim);   color: var(--green); }
.badge.offline  { background: var(--bg-overlay);   color: var(--text-muted); border: 1px solid var(--border); }
.badge.role-super_admin { background: rgba(255,159,64,0.15); color: var(--orange); }
.badge.role-admin       { background: var(--red-dim);   color: var(--red); }
.badge.role-moderator   { background: var(--accent-dim); color: var(--accent); }
.badge.role-user        { background: var(--green-dim);  color: var(--green); }
.badge.role-readonly    { background: var(--bg-overlay); color: var(--text-muted); border: 1px solid var(--border); }

/* Theme toggle button */
.theme-toggle {
    width: 34px; height: 34px; border-radius: var(--radius-sm); border: none;
    background: transparent; color: var(--text-secondary); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background var(--trans), color var(--trans); font-size: 16px;
}
.theme-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }

/* New chat menu */
.new-chat-menu {
    position: absolute; top: calc(100% + 4px); right: 0;
    background: var(--bg-raised); border: 1px solid var(--border-strong);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg); min-width: 200px;
    z-index: 200; overflow: hidden; animation: fadeIn 0.1s ease;
}
.new-chat-option {
    display: flex; align-items: center; gap: 10px; padding: 11px 16px;
    font-size: 13px; cursor: pointer; color: var(--text-primary);
    transition: background var(--trans);
}
.new-chat-option:hover { background: var(--bg-hover); }
.new-chat-option svg { color: var(--accent); flex-shrink: 0; }

/* Permission select */
.perm-select {
    display: flex; flex-direction: column; gap: 8px; margin-top: 8px;
}
.perm-option {
    display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
    transition: border-color var(--trans), background var(--trans);
}
.perm-option:hover { background: var(--bg-hover); }
.perm-option.selected { border-color: var(--accent); background: var(--accent-dim); }
.perm-option input { margin-top: 3px; flex-shrink: 0; accent-color: var(--accent); }
.perm-option-label { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.perm-option-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Profile modal */
.profile-avatar-section {
    display: flex; align-items: center; gap: 16px; padding: 16px;
    background: var(--bg-overlay); border-radius: var(--radius-md); margin-bottom: 20px;
}
.profile-avatar-edit { position: relative; cursor: pointer; }
.profile-avatar-edit:hover .avatar-edit-overlay { opacity: 1; }
.avatar-edit-overlay {
    position: absolute; inset: 0; border-radius: var(--radius-full);
    background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity var(--trans); color: #fff; font-size: 18px;
}
.profile-name { font-size: 18px; font-weight: 700; color: var(--text-primary); }
.profile-username { font-size: 13px; color: var(--text-muted); }
.profile-role { font-size: 11px; margin-top: 4px; }

.profile-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.profile-tab {
    padding: 8px 16px; font-size: 13px; font-weight: 500; cursor: pointer;
    color: var(--text-secondary); border-bottom: 2px solid transparent;
    transition: all var(--trans); background: none; border-top: none; border-left: none; border-right: none;
}
.profile-tab:hover { color: var(--text-primary); }
.profile-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Animations */
@keyframes fadeIn    { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp   { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn   { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — Tablet (768–1024px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    :root { --sidebar-w: 280px; }
    .info-panel { width: 260px; min-width: 260px; }
    .messages-container { padding: 12px 16px; }
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — Mobile (<768px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
    :root { --sidebar-w: 100vw; --header-h: 56px; }

    /* Auth form full-width */
    .auth-container { padding: 16px; }
    .auth-form { padding: 24px 20px; }

    /* App layout: sidebar covers full screen, chat-area covers full screen */
    #app-screen { position: relative; }

    .sidebar {
        position: absolute; left: 0; top: 0; bottom: 0; z-index: 100;
        width: 100vw; min-width: 100vw;
        transform: translateX(0);
        transition: transform var(--trans-slow);
    }
    .sidebar.slide-out { transform: translateX(-100%); }

    .chat-area {
        position: absolute; left: 0; top: 0; right: 0; bottom: 0;
        transform: translateX(100%);
        transition: transform var(--trans-slow);
        background: var(--bg-deep);
    }
    .chat-area.slide-in { transform: translateX(0); }

    .chat-view { display: flex; }

    /* Back button visible on mobile */
    #back-btn { display: flex !important; }

    /* Info panel: full screen overlay on mobile */
    .info-panel {
        position: fixed; right: 0; top: 0; bottom: 0; z-index: 150;
        width: 100vw; min-width: 100vw; transform: translateX(100%); transition: transform var(--trans-slow);
    }
    .info-panel:not(.hidden) { transform: translateX(0); }

    /* Admin: stack vertically */
    #admin-screen { flex-direction: column; }
    .admin-sidebar { width: 100%; min-width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
    .admin-nav { display: flex; overflow-x: auto; padding: 4px 8px; }
    .admin-nav-item { flex-shrink: 0; border-left: none; border-bottom: 3px solid transparent; padding: 8px 12px; }
    .admin-nav-item.active { border-left-color: transparent; border-bottom-color: var(--accent); }
    .admin-main { padding: 16px; }

    /* Modal: full screen on mobile */
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal-box { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-width: 100%; max-height: 90vh; }

    /* Messages */
    .messages-container { padding: 10px 12px; }
    .msg-bubble { max-width: calc(100vw - 80px); }
    .input-area { padding: 8px 12px; }

    /* Toast bottom center on mobile */
    .toast-container { left: 12px; right: 12px; bottom: 12px; align-items: stretch; }
    .toast { max-width: 100%; }

    /* New chat menu */
    .new-chat-menu { right: -8px; }

    /* Hide desktop-only elements */
    .desktop-only { display: none !important; }
}

/* Desktop-specific */
@media (min-width: 768px) {
    .mobile-only { display: none !important; }
    #back-btn { display: none !important; }
}

/* Light theme adjustments */
[data-theme="light"] .auth-grid { opacity: 0.3; }
[data-theme="light"] .msg-bubble { box-shadow: none; border-color: rgba(0,0,0,0.1); }
[data-theme="light"] .msg-row.own .msg-bubble { background: var(--accent); }
[data-theme="light"] .sidebar { box-shadow: 2px 0 8px rgba(0,0,0,0.06); }
[data-theme="light"] .chat-header { box-shadow: 0 1px 4px rgba(0,0,0,0.06); }

/* ── Search panel ───────────────────────────────────── */
.msg-search-panel { background: var(--bg-raised); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.msg-search-bar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; }
.msg-search-bar input { flex: 1; background: var(--bg-overlay); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px; color: var(--text-primary); font-size: 13px; outline: none; }
.msg-search-bar input:focus { border-color: var(--accent); }
.msg-search-results { max-height: 260px; overflow-y: auto; border-top: 1px solid var(--border); }
.msearch-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 10px 16px; cursor: pointer; border-bottom: 1px solid var(--border); transition: background var(--trans); }
.msearch-item:hover { background: var(--bg-hover); }
.msearch-sender { font-size: 12px; font-weight: 600; color: var(--accent); grid-column: 1; }
.msearch-text { font-size: 13px; color: var(--text-secondary); grid-column: 1; }
.msearch-text mark { background: rgba(59,130,246,0.3); color: var(--text-primary); border-radius: 2px; }
.msearch-time { font-size: 11px; color: var(--text-muted); grid-column: 2; grid-row: 1 / 3; align-self: center; }
.msearch-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ── Pinned banner ──────────────────────────────────── */
.pinned-banner {
    display: flex; align-items: center; gap: 10px; padding: 8px 16px;
    background: var(--bg-raised); border-bottom: 1px solid var(--border);
    cursor: pointer; flex-shrink: 0; transition: background var(--trans);
}
.pinned-banner:hover { background: var(--bg-hover); }
.pinned-icon { font-size: 16px; flex-shrink: 0; }
.pinned-body { flex: 1; min-width: 0; }
.pinned-label { font-size: 11px; color: var(--accent); font-weight: 600; margin-bottom: 1px; }
.pinned-text { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinned-close { color: var(--text-muted); flex-shrink: 0; }

/* ── Poll ────────────────────────────────────────────── */
.poll-bubble { min-width: 220px; }
.poll-question { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text-primary); }
.poll-options { display: flex; flex-direction: column; gap: 6px; }
.poll-option {
    position: relative; border: 1px solid var(--border); border-radius: 8px;
    overflow: hidden; cursor: pointer; transition: border-color 0.15s;
}
.poll-option:hover { border-color: var(--accent); }
.poll-option.voted { border-color: var(--accent); }
.poll-option-bar { position: absolute; top: 0; left: 0; height: 100%; background: var(--accent-dim); transition: width 0.4s ease; z-index: 0; }
.poll-option-content { position: relative; z-index: 1; display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; }
.poll-option-text { font-size: 13px; color: var(--text-primary); }
.poll-option-pct { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.poll-footer { font-size: 11px; color: var(--text-muted); margin-top: 8px; }

/* ── Read status ─────────────────────────────────────── */
.msg-read { color: rgba(130,200,255,0.9); }
.msg-row.own .msg-meta .msg-read { color: rgba(180,220,255,0.95); }

/* ── Chat header search btn ──────────────────────────── */
#chat-search-btn { margin-right: 4px; }

/* ── Password Recovery ──────────────────────────────── */
.recover-notice {
    display: flex; align-items: center; gap: 12px; padding: 12px 14px;
    background: var(--accent-dim); border: 1px solid var(--accent);
    border-radius: 10px; margin-bottom: 16px;
}
.recover-avatar {
    width: 40px; height: 40px; background: var(--accent); color: #fff;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 700; flex-shrink: 0;
}
.abtn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.abtn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── Search modal tabs & results ───────────────────── */
.search-tabs { display: flex; gap: 6px; margin-bottom: 4px; }
.search-tab {
    flex: 1; padding: 8px; background: var(--bg-overlay);
    border: 1px solid var(--border); border-radius: 8px;
    color: var(--text-secondary); font-size: 13px; cursor: pointer;
    transition: all var(--trans);
}
.search-tab.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.search-tab:hover:not(.active) { background: var(--bg-hover); }

.search-result-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 8px; cursor: pointer;
    transition: background var(--trans);
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-icon {
    width: 36px; height: 36px; background: var(--bg-overlay);
    border-radius: 50%; display: flex; align-items: center;
    justify-content: center; font-size: 18px; flex-shrink: 0;
}
.search-result-body { flex: 1; min-width: 0; }
.search-result-name { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.search-result-sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.search-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ── Emoji Picker ───────────────────────────────────── */
.emoji-picker {
    position: fixed; z-index: 9999;
    background: var(--bg-raised); border: 1px solid var(--border);
    border-radius: 12px; padding: 8px;
    display: flex; flex-wrap: wrap; gap: 4px; width: 256px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    animation: emojiIn 0.12s ease;
}
@keyframes emojiIn { from { opacity:0; transform:scale(0.85) translateY(4px); } to { opacity:1; transform:none; } }
.emoji-btn {
    width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
    font-size: 20px; border-radius: 8px; cursor: pointer; transition: background 0.1s;
    user-select: none;
}
.emoji-btn:hover { background: var(--bg-hover); transform: scale(1.2); }

/* ── Media Preview ──────────────────────────────────── */
.media-wrap { max-width: 320px; width: 100%; }

/* Image */
.media-img {
    display: block; width: 100%; max-width: 320px; max-height: 280px;
    object-fit: cover; border-radius: 10px; cursor: zoom-in;
    transition: opacity 0.2s; background: var(--bg-overlay);
}
.media-img:hover { opacity: 0.92; }

/* Video */
.media-video {
    display: block; width: 100%; max-width: 320px; max-height: 240px;
    border-radius: 10px; background: #000;
    outline: none;
}

/* Audio */
.media-audio-name { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; word-break: break-all; }
.media-audio { width: 100%; max-width: 320px; height: 36px; border-radius: 8px; outline: none; }

/* Generic file */
.media-file {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; background: rgba(0,0,0,0.12);
    border-radius: 10px; min-width: 180px;
}
.media-file-icon { font-size: 28px; flex-shrink: 0; }
.media-file-name { font-size: 13px; font-weight: 500; color: var(--text-primary); word-break: break-all; }
.media-file-ext  { font-size: 11px; color: var(--accent); font-weight: 600; margin-top: 2px; }

/* Actions bar */
.media-actions {
    display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap;
}
.media-action-btn {
    font-size: 12px; color: var(--accent); text-decoration: none;
    padding: 3px 8px; border-radius: 6px; background: var(--accent-dim);
    transition: background var(--trans); cursor: pointer;
    display: inline-flex; align-items: center; gap: 4px;
}
.media-action-btn:hover { background: var(--bg-hover); }
.msg-row.own .media-action-btn { color: rgba(255,255,255,0.9); background: rgba(255,255,255,0.15); }
.msg-row.own .media-action-btn:hover { background: rgba(255,255,255,0.25); }

/* ── Media Modal (fullscreen) ────────────────────────── */
.media-modal {
    position: fixed; inset: 0; z-index: 10000;
    display: flex; align-items: center; justify-content: center;
}
.media-modal-bg {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.88); backdrop-filter: blur(6px);
}
.media-modal-content {
    position: relative; z-index: 1;
    display: flex; flex-direction: column;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 32px);
    background: var(--bg-raised); border-radius: 14px;
    overflow: hidden; box-shadow: 0 24px 64px rgba(0,0,0,0.5);
    animation: modalIn 0.18s ease;
}
@keyframes modalIn { from { opacity:0; transform:scale(0.92); } to { opacity:1; transform:none; } }
.media-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid var(--border); gap: 12px;
    flex-shrink: 0;
}
.media-modal-name { font-size: 13px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-modal-btn {
    padding: 6px 12px; border-radius: 8px; font-size: 13px; cursor: pointer;
    background: var(--bg-overlay); border: none; color: var(--text-primary);
    text-decoration: none; transition: background var(--trans); flex-shrink: 0;
}
.media-modal-btn:hover { background: var(--bg-hover); }
.media-modal-body {
    overflow: auto; display: flex; align-items: center; justify-content: center;
    padding: 16px; flex: 1;
}
.media-modal-img {
    max-width: 100%; max-height: calc(100vh - 120px);
    object-fit: contain; border-radius: 6px; display: block;
    user-select: none;
}
