/* ============================================================
   SAT-AI Design System — modern, minimal, ChatGPT-like
   ============================================================ */

:root {
    --bg: #ffffff;
    --bg-secondary: #f7f7f8;
    --bg-tertiary: #ececf1;
    --bg-hover: #f0f1f3;
    --text: #1a1d21;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --primary: #1e56a0;
    --primary-hover: #17478a;
    --primary-soft: #e8f0fb;
    --accent: #e8571e;
    --accent-soft: #fdeee6;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08);
    --shadow-lg: 0 12px 32px rgba(0,0,0,.14);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-full: 999px;
    --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    --mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
    --sidebar-w: 268px;
    --transition: 160ms cubic-bezier(.4, 0, .2, 1);
}

[data-theme="dark"] {
    --bg: #16181d;
    --bg-secondary: #1d2026;
    --bg-tertiary: #262a31;
    --bg-hover: #262a31;
    --text: #ececf1;
    --text-secondary: #a3a8b3;
    --text-tertiary: #6b7280;
    --border: #2c3038;
    --border-strong: #3b4048;
    --primary: #5b8fd6;
    --primary-hover: #6f9fe2;
    --primary-soft: #1d2b40;
    --accent: #f06a34;
    --accent-soft: #3a251c;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,.35);
    --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* The hidden attribute must always win over author display rules
   (e.g. .dictate-live would otherwise stay visible). */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}
::selection { background: var(--primary-soft); color: var(--primary); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 16px; border: 1px solid var(--border); border-radius: var(--radius-md);
    background: var(--bg); color: var(--text); font: inherit; font-weight: 500;
    cursor: pointer; white-space: nowrap; user-select: none;
    transition: background var(--transition), border-color var(--transition), transform 80ms;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: var(--danger-soft); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg-hover); border-color: var(--border); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: var(--radius-sm); }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.field input, .field select, .field textarea {
    padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); color: var(--text); font: inherit; width: 100%;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ---------- Alerts / Toasts ---------- */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 12px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }

.toast-container {
    position: fixed; bottom: 16px; right: 16px; z-index: 1000;
    display: flex; flex-direction: column-reverse; gap: 8px;
}
.toast {
    background: var(--bg-tertiary); color: var(--text); padding: 12px 18px;
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg); font-size: 14px;
    max-width: 340px; animation: toast-in 220ms ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.45);
    display: flex; align-items: center; justify-content: center; z-index: 900;
    animation: fade-in 150ms ease;
}
.modal {
    background: var(--bg); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    padding: 24px; width: min(480px, calc(100vw - 32px)); max-height: 85vh; overflow: auto;
    animation: modal-in 180ms ease;
}
.modal h3 { font-size: 17px; margin-bottom: 8px; }
.modal p { color: var(--text-secondary); font-size: 14px; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: scale(.96) translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Login ---------- */
.login-page {
    display: flex; align-items: center; justify-content: center; min-height: 100vh;
    background: linear-gradient(160deg, var(--bg-secondary) 0%, var(--bg) 100%); padding: 24px;
}
.login-card {
    width: min(420px, 100%); background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 40px 36px 28px; box-shadow: var(--shadow-lg); text-align: center;
}
.login-logo { width: 64px; height: 64px; object-fit: contain; margin-bottom: 16px; }
.login-card h1 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.login-subtitle { color: var(--text-secondary); font-size: 14px; margin: 6px 0 24px; }
.login-card form { text-align: left; }
.login-footer { margin-top: 22px; font-size: 12px; color: var(--text-tertiary); }

/* ============================================================
   Chat layout
   ============================================================ */
.app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    flex-shrink: 0;
    transition: transform 220ms ease;
}
.sidebar-header {
    padding: 14px 14px 10px;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    text-align: center;
}
.sidebar-header img.sidebar-logo,
.admin-nav .brand-row img.sidebar-logo { width: 92px; height: 92px; object-fit: contain; }
.sidebar-header .brand-sub { text-align: center; }
/* Logo buttons (sidebar + mobile topbar): click -> neutral start screen */
.logo-btn {
    background: none; border: none; padding: 0; margin: 0;
    cursor: pointer; display: inline-flex; align-items: center;
    border-radius: var(--radius-sm);
    transition: opacity var(--transition), transform var(--transition);
}
.logo-btn:hover { opacity: .82; }
.logo-btn:active { transform: scale(.97); }
.sidebar-header .brand-sub,
.admin-nav .brand-row .brand-sub { font-size: 12.5px; font-weight: 500; color: var(--text-secondary); line-height: 1.35; }
.new-chat-btn {
    margin: 8px 12px 4px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg);
    color: var(--text);
    font: inherit; font-weight: 500; font-size: 14px;
    cursor: pointer; text-align: left;
    display: flex; align-items: center; gap: 10px;
    transition: background var(--transition), border-color var(--transition);
}
.new-chat-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.conversation-list {
    flex: 1; overflow-y: auto; padding: 8px 10px 16px;
    scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
}
.conversation-list h4 {
    font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-tertiary); margin: 14px 6px 6px;
}
.conversation-item {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 10px; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 14px;
    transition: background var(--transition);
    position: relative;
}
.conversation-item:hover { background: var(--bg-hover); }
.conversation-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.conversation-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item .conv-actions {
    display: none; gap: 2px; flex-shrink: 0;
}
.conversation-item:hover .conv-actions, .conversation-item.active .conv-actions { display: flex; }
.icon-btn {
    background: none; border: none; padding: 4px; border-radius: 6px;
    cursor: pointer; color: var(--text-secondary); line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-tertiary); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    display: flex; flex-direction: column; gap: 8px;
}
.budget-widget {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-size: 12.5px;
}
/* Mode display: "Modus:" label left, value right-aligned. Gold for Premium, grey for Free. */
.budget-widget .budget-row {
    display: flex; justify-content: space-between; align-items: center;
    color: var(--text-secondary);
}
.budget-widget .budget-row strong { font-weight: 600; }
.budget-widget .budget-row strong.premium { color: #d4af37; }
.budget-widget .budget-row strong.free { color: var(--text-tertiary); }
.mode-badge {
    display: inline-flex; align-items: center;
    padding: 3px 10px; border-radius: var(--radius-full);
    font-size: 11.5px; font-weight: 600; line-height: 1.2;
    border: 1px solid transparent;
}
.mode-badge.premium { color: #d4af37; border-color: #d4af3755; background: #d4af3714; }
.mode-badge.free { color: var(--text-tertiary); border-color: var(--border-strong); background: var(--bg-tertiary); }
.mode-badge[hidden] { display: none; }
.sidebar-footer .user-row {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 4px;
}
.avatar {
    width: 32px; height: 32px; border-radius: var(--radius-full);
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.user-row .user-meta { flex: 1; min-width: 0; }
.user-row .user-meta .name { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row .user-meta .mail { font-size: 11.5px; color: var(--text-tertiary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row .admin-link { font-size: 13px; text-decoration: none; color: var(--text-secondary); padding: 6px; border-radius: 6px; }
.user-row .admin-link:hover { background: var(--bg-hover); color: var(--text); }

/* Mobile: sidebar drawer + top bar */
.mobile-topbar { display: none; }
@media (max-width: 900px) {
    .mobile-topbar {
        display: flex; align-items: center; justify-content: space-between;
        gap: 10px; padding: 8px 12px;
        border-bottom: 1px solid var(--border);
        background: var(--bg); position: sticky; top: 0; z-index: 500;
        padding-top: calc(8px + env(safe-area-inset-top));
    }
    .topbar-logo { width: 34px; height: 34px; object-fit: contain; }
    .topbar-right { display: flex; align-items: center; gap: 8px; }

    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0;
        width: min(84vw, 320px);
        height: 100dvh;
        z-index: 600;
        transform: translateX(-100%);
        transition: transform 220ms ease;
        box-shadow: var(--shadow-lg);
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        overflow-y: auto;
    }
    .sidebar.open { transform: none; }
    .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 400; }
    /* Stack vertically: topbar spans the full width on top, chat below.
       (Default flex row would squeeze the topbar into a narrow left column.) */
    .app { height: 100dvh; flex-direction: column; }
    .chat-main { flex: 1; min-height: 0; width: 100%; }

    /* Mobile has ONLY the topbar (logo left, hamburger right).
       The desktop chat header (title + theme toggle) is hidden. */
    .chat-header { display: none; }

    /* Chat area on small screens */
    .messages-inner { padding: 14px 14px 6px; }
    .message { gap: 8px; margin-bottom: 16px; }
    .message .avatar { width: 28px; height: 28px; font-size: 12px; }
    .msg-content { font-size: 15px; }
    .msg-content h1 { font-size: 19px; } .msg-content h2 { font-size: 17px; }
    .msg-content pre { font-size: 12.5px; padding: 10px 12px; }
    .msg-content table { display: block; overflow-x: auto; }
    .msg-content blockquote { padding: 4px 10px; margin: 8px 0; }

    /* Composer: 16px textarea font prevents iOS zoom-on-focus */
    .composer-wrap { padding: 6px 10px calc(12px + env(safe-area-inset-bottom)); }
    .composer { padding: 8px 10px; }
    .composer textarea { font-size: 16px; }
    .attach-btn, .mic-btn { padding: 6px; }
    .send-btn { width: 36px; height: 36px; }
    .model-picker-label { max-width: 90px; }
    .composer-hint { font-size: 10.5px; margin-top: 6px; }
    .model-picker-menu { max-width: calc(100vw - 32px); }

    /* Hide secondary sidebar info, keep the drawer lean */
    .budget-widget .budget-row { font-size: 12px; }

    /* Mobile experience refinements */
    button { touch-action: manipulation; }
    .messages-container { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
    .message { margin-bottom: 16px; }
    .message.user .msg-body { max-width: 92%; }
    .message.user .msg-content { padding: 10px 14px; }
    .attach-btn, .mic-btn, .send-btn { min-width: 40px; min-height: 40px; }
    .composer-waveform { min-height: 36px; }
    .dictate-loading { font-size: 13.5px; }
    .msg-actions { opacity: 1; } /* touch devices have no hover */

    /* Welcome screen: fill exactly the visible area above the composer —
       no 60vh overflow, no wasted whitespace. */
    .empty-state { min-height: calc(100dvh - 260px); padding: 8px 16px 16px; }
    .empty-state img { width: 84px; height: 84px; margin-bottom: 14px; }
    .empty-state h2 { font-size: 23px; }
    .empty-state p { font-size: 15px; max-width: 340px; }

    /* Kill horizontal artifacts: the off-screen drawer, wide tables or long
       code blocks must never create stray content outside the viewport. */
    html, body { overflow-x: clip; max-width: 100vw; }
    .sidebar:not(.open) { visibility: hidden; transition: transform 220ms ease, visibility 0s 220ms; }
    .sidebar.open { visibility: visible; transition: transform 220ms ease; }

    /* Toasts are entirely hidden on mobile */
    .toast-container { display: none; }
}

/* Main chat area */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chat-header {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 18px; border-bottom: 1px solid var(--border);
    min-height: 52px;
}
.chat-header .chat-title { font-weight: 600; font-size: 15px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.messages-container {
    flex: 1; overflow-y: auto;
    scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
}
.messages-inner { max-width: 1100px; margin: 0 auto; padding: 28px 20px 12px; }

.message { display: flex; gap: 14px; margin-bottom: 26px; animation: msg-in 240ms ease; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.message .avatar { margin-top: 2px; }
.message.assistant .avatar { background: var(--accent); }
.message .msg-body { flex: 1; min-width: 0; }
.message .msg-content { font-size: 15px; overflow-wrap: break-word; }

/* User messages: avatar top-right, message card below, right-aligned.
   Text inside the card stays left-aligned for readability. */
.message.user { flex-direction: column; align-items: flex-end; gap: 6px; }
.message.user .avatar { margin: 0; order: -1; }
.message.user .msg-body {
    flex: none; max-width: 85%;
    display: flex; flex-direction: column; align-items: flex-end;
}
.message.user .msg-content {
    background: var(--bg-tertiary);
    padding: 10px 16px;
    border-radius: var(--radius-lg);
    border-bottom-right-radius: 6px;
    text-align: left;
    white-space: pre-wrap;
}
.message.user .msg-attachments { align-items: flex-end; }

/* Markdown content */
.msg-content h1, .msg-content h2, .msg-content h3 { margin: 18px 0 8px; line-height: 1.3; }
.msg-content h1 { font-size: 21px; } .msg-content h2 { font-size: 18px; } .msg-content h3 { font-size: 16px; }
.msg-content p { margin: 8px 0; }
.msg-content ul, .msg-content ol { margin: 8px 0; padding-left: 24px; }
.msg-content li { margin: 4px 0; }
.msg-content code {
    font-family: var(--mono); font-size: 13px;
    background: var(--bg-tertiary); padding: 2px 6px; border-radius: 5px;
}
.msg-content pre {
    background: #0f1115; color: #e6e6e6;
    border-radius: var(--radius-md); padding: 14px 16px;
    overflow-x: auto; margin: 12px 0;
    font-family: var(--mono); font-size: 13px; line-height: 1.6;
    position: relative;
}
.msg-content pre .code-lang {
    position: absolute; top: 8px; right: 12px; font-size: 11px; color: #888;
    text-transform: uppercase; letter-spacing: .05em;
}
.msg-content blockquote {
    border-left: 3px solid var(--border-strong); padding: 4px 14px;
    margin: 10px 0; color: var(--text-secondary);
}
.msg-content table { border-collapse: collapse; margin: 12px 0; width: 100%; font-size: 14px; }
.msg-content th, .msg-content td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; }
.msg-content th { background: var(--bg-secondary); font-weight: 600; }
.msg-content a { color: var(--primary); text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }
.msg-content hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* Scroll-to-bottom: appears when the user scrolled up while the output grows */
.messages-container { position: relative; }
.scroll-to-bottom {
    position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
    width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-tertiary); border: 1px solid var(--border-strong);
    color: var(--text-secondary); cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
    opacity: 0; visibility: hidden;
    transition: opacity .18s ease, transform .18s ease, visibility .18s;
    z-index: 30;
}
.scroll-to-bottom.visible { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(-2px); }
.scroll-to-bottom:hover { background: var(--bg-secondary); color: var(--text); }



.msg-actions { display: flex; gap: 4px; margin-top: 8px; opacity: 0; transition: opacity var(--transition); }
.message:hover .msg-actions { opacity: 1; }
.copy-btn { font-size: 12px; color: var(--text-tertiary); }
.copy-btn:hover { color: var(--text); }

/* Attachments in messages */
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.att-chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--bg-secondary); border: 1px solid var(--border);
    padding: 5px 10px; border-radius: var(--radius-sm); font-size: 12.5px;
    color: var(--text-secondary); text-decoration: none; max-width: 220px;
}
.att-chip:hover { border-color: var(--border-strong); }
.att-chip .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-chip img { width: 22px; height: 22px; object-fit: cover; border-radius: 4px; }

/* Empty state */
.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 60vh; text-align: center; padding: 24px;
}
.empty-state img { width: 72px; height: 72px; object-fit: contain; opacity: .9; margin-bottom: 18px; }
.empty-state h2 { font-size: 22px; font-weight: 650; letter-spacing: -.02em; margin-bottom: 8px; }
.empty-state p { color: var(--text-secondary); font-size: 14.5px; max-width: 420px; }
/* suggestion chips removed */

/* Composer */
.composer-wrap { padding: 8px 20px 18px; background: linear-gradient(transparent, var(--bg) 30%); }
.composer {
    max-width: 912px; margin: 0 auto;
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 10px 12px 8px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.composer:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.composer .pending-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.pending-att {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-full); padding: 4px 10px;
    font-size: 12.5px; max-width: 240px;
}
.pending-att .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-att .att-size { color: var(--text-tertiary); flex-shrink: 0; }
.pending-att .remove-att { cursor: pointer; color: var(--text-tertiary); background: none; border: none; padding: 0 2px; font-size: 14px; }
.pending-att .remove-att:hover { color: var(--danger); }
.pending-att.uploading { opacity: .6; }
.composer textarea {
    width: 100%; border: none; resize: none; outline: none;
    background: transparent; color: var(--text);
    font: inherit; font-size: 15px; line-height: 1.5;
    max-height: 200px; min-height: 24px;
}
.composer .composer-bar { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.composer-bar .spacer { flex: 1; }
.send-btn {
    width: 38px; height: 38px; border-radius: var(--radius-md);
    background: var(--primary); border: none; color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background var(--transition), transform 80ms;
}
.send-btn:hover { background: var(--primary-hover); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.send-btn:active { transform: scale(.94); }
.send-btn.stop { background: var(--danger); }
.attach-btn, .mic-btn {
    background: none; border: none; padding: 8px; border-radius: var(--radius-sm);
    color: var(--text-secondary); cursor: pointer;
    display: flex; align-items: center;
}
.attach-btn:hover, .mic-btn:hover { background: var(--bg-hover); color: var(--text); }
/* Recording state: subtle highlight only — the active visual feedback is the
   waveform in the composer area, not a pulsing red button. */
.mic-btn.recording { color: var(--accent); }
.mic-btn.busy { color: var(--primary); opacity: .6; pointer-events: none; }
/* Live dictation: waveform replaces the composer input while recording.
   Bars are generated dynamically by JS so the line spans the full width. */
.composer-waveform {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; min-height: 40px;
    padding: 2px 2px;
}
.composer-waveform .wf-bar {
    flex: 0 0 2px; width: 2px; min-width: 2px;
    height: 8px; border-radius: 2px;
    background: var(--primary);
    animation: wf-idle 1.6s ease-in-out infinite;
}
.composer-waveform.live .wf-bar { animation: none; transition: height 70ms ease-out; }
.composer-waveform.speaking .wf-bar { animation: wf-active .8s ease-in-out infinite; }
@keyframes wf-idle { 0%, 100% { transform: scaleY(.5); } 50% { transform: scaleY(1); } }
@keyframes wf-active { 0%, 100% { transform: scaleY(.4); } 50% { transform: scaleY(1.7); } }

/* Loading indicator while the dictation audio is transcribed */
.dictate-loading {
    display: flex; align-items: center; gap: 10px;
    width: 100%; min-height: 40px;
    padding: 2px 4px;
    color: var(--text-secondary); font-size: 14px;
}
.dictate-loading .spinner {
    width: 18px; height: 18px; flex-shrink: 0;
    border: 2.5px solid var(--border-strong);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* Model picker (composer, next to mic) */
.model-picker { position: relative; }
.model-picker-btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: none; border: none; padding: 6px 10px;
    border-radius: var(--radius-full); color: var(--text-secondary);
    font: inherit; font-size: 13px; font-weight: 500;
    cursor: pointer; max-width: 240px;
    transition: background var(--transition), color var(--transition);
}
.model-picker-btn:hover { background: var(--bg-hover); color: var(--text); }
.model-picker-btn[aria-expanded="true"] { background: var(--bg-hover); color: var(--text); }
.model-picker-btn .chevron { transition: transform var(--transition); flex-shrink: 0; }
.model-picker-btn[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.model-picker-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-picker-menu {
    position: absolute; bottom: calc(100% + 10px); left: 0; z-index: 60;
    min-width: 300px; max-width: min(380px, calc(100vw - 48px));
    max-height: 300px; overflow-y: auto;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    padding: 6px; animation: model-menu-in .14s ease;
}
@keyframes model-menu-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.model-picker-item {
    display: flex; align-items: center; gap: 8px; width: 100%;
    background: none; border: none; text-align: left; cursor: pointer;
    padding: 9px 10px; border-radius: var(--radius-sm);
    font: inherit; font-size: 13.5px; color: var(--text);
    transition: background var(--transition);
}
.model-picker-item:hover { background: var(--bg-hover); }
.model-picker-item .m-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.model-picker-item .m-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.model-picker-item .m-id { font-size: 11.5px; color: var(--text-tertiary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-picker-item .m-check { color: var(--primary); flex-shrink: 0; visibility: hidden; }
.model-picker-item.selected { background: var(--bg-hover); }
.model-picker-item.selected .m-check { visibility: visible; }
.model-picker-badge {
    flex-shrink: 0; font-size: 10.5px; font-weight: 600; padding: 2px 8px;
    border-radius: var(--radius-full); background: var(--primary-soft); color: var(--primary);
}
.composer-hint { text-align: center; font-size: 11.5px; color: var(--text-tertiary); margin-top: 8px; }

/* Typing indicator */
.typing-dots { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing-dots span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--text-tertiary);
    animation: dot-bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes dot-bounce { 0%, 60%, 100% { transform: none; opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* Skeleton */
.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-hover) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%; animation: shimmer 1.4s infinite;
    border-radius: var(--radius-sm);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skeleton.skel-msg { height: 16px; margin-bottom: 10px; }
.skeleton.skel-msg.w70 { width: 70%; } .skeleton.skel-msg.w90 { width: 90%; } .skeleton.skel-msg.w40 { width: 40%; }

/* ============================================================
   Admin layout
   ============================================================ */
.admin-layout { display: flex; height: 100vh; overflow: hidden; }
.admin-nav {
    width: 220px; flex-shrink: 0;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 16px 12px;
    display: flex; flex-direction: column; gap: 2px;
    overflow-y: auto;
}
.admin-nav .brand-row {
    display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 0 8px 14px;
}
.admin-nav .brand-row .brand-col { display: flex; flex-direction: column; gap: 4px; }
.admin-nav .brand-row .brand-tag {
    font-size: 10px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600;
    color: var(--text-tertiary); border: 1px solid var(--border); border-radius: 999px;
    padding: 2px 8px; width: fit-content;
}
.admin-nav .nav-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-tertiary); padding: 14px 8px 4px; }
.admin-nav a.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: var(--radius-sm);
    color: var(--text-secondary); text-decoration: none; font-size: 14px;
    transition: background var(--transition), color var(--transition);
}
.admin-nav a.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.admin-nav a.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.admin-nav .back-link { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }

.admin-content { flex: 1; overflow-y: auto; padding: 28px 32px 60px; min-width: 0; }
.admin-content h1 { font-size: 22px; font-weight: 650; letter-spacing: -.02em; margin-bottom: 6px; }
.admin-content .page-sub { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat-card {
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.stat-card .stat-label { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 4px; }
.stat-card .stat-value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; }
.stat-card .stat-sub { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }
.stat-card.ok { border-left: 3px solid var(--success); }
.stat-card.bad { border-left: 3px solid var(--danger); }

.data-table {
    width: 100%; border-collapse: collapse; font-size: 13.5px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-md); overflow: hidden;
}
.data-table th, .data-table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: var(--bg-secondary); font-weight: 600; font-size: 12.5px; color: var(--text-secondary); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { border-radius: var(--radius-md); border: 1px solid var(--border); overflow: auto; max-height: 65vh; }

.badge {
    display: inline-flex; align-items: center; padding: 2px 9px;
    border-radius: var(--radius-full); font-size: 11.5px; font-weight: 500;
}
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.gray { background: var(--bg-tertiary); color: var(--text-secondary); }
.badge.blue { background: var(--primary-soft); color: var(--primary); }

.filter-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.filter-bar input[type="text"], .filter-bar input[type="month"], .filter-bar select {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); color: var(--text); font: inherit; font-size: 13.5px;
}

.admin-form { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 20px; margin-bottom: 20px; }
.admin-form h3 { font-size: 15px; margin-bottom: 14px; }
.form-row { display: flex; gap: 12px; }
.form-row .field { flex: 1; }

.toggle-switch { position: relative; width: 40px; height: 22px; display: inline-block; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-switch .slider {
    position: absolute; inset: 0; cursor: pointer;
    background: var(--border-strong); border-radius: var(--radius-full);
    transition: background var(--transition);
}
.toggle-switch .slider::before {
    content: ""; position: absolute; left: 3px; top: 3px;
    width: 16px; height: 16px; background: #fff; border-radius: 50%;
    transition: transform var(--transition);
    box-shadow: var(--shadow-sm);
}
.toggle-switch input:checked + .slider { background: var(--success); }
.toggle-switch input:checked + .slider::before { transform: translateX(18px); }

.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 14px; }
.switch-row:last-child { border-bottom: none; }
.switch-row .switch-label { flex: 1; }
.switch-row .switch-label .desc { font-size: 12px; color: var(--text-tertiary); }

@media (max-width: 900px) {
    .admin-nav { position: fixed; z-index: 500; height: 100vh; transform: translateX(-100%); transition: transform 220ms; }
    .admin-nav.open { transform: none; }
    .admin-content { padding: 20px 16px 60px; }
}
