/* ══════════════════════════════════════════════════════════════
   Omega PA — Modern Apple-Inspired Theme
   Dark & Light mode with glassmorphism, gradients, and premium typography
   ══════════════════════════════════════════════════════════════ */

/* ── Inter Font (local) ───────────────────────────────────── */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('../fonts/inter-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('../fonts/inter-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── DARK THEME (default) — Apple-neutral palette ──────────── */
:root {
    --bg:          #000000;
    --bg-elevated: #1c1c1e;
    --surface:     #2c2c2e;
    --surface-2:   #3a3a3c;
    --surface-3:   #48484a;
    --border:      rgba(255,255,255,0.16);
    --border-light:rgba(255,255,255,0.08);
    --border-focus:rgba(255,255,255,0.35);

    --glass:       rgba(28,28,30,0.82);
    --glass-border:rgba(255,255,255,0.16);
    --glass-shadow:0 8px 32px rgba(0,0,0,0.6);

    --primary:     #0a84ff;
    --primary-hover:#0070e0;
    --primary-soft: rgba(10,132,255,0.16);
    --secondary:   #64d2ff;
    --accent:      #5ac8fa;
    --accent-soft: rgba(90,200,250,0.14);
    --danger:      #ff453a;
    --danger-soft:  rgba(255,69,58,0.14);
    --success:     #30d158;
    --success-soft: rgba(48,209,88,0.14);
    --warning:     #ffd60a;

    --text:        #f5f5f7;
    --text-secondary: #a1a1a6;
    --text-muted:  #86868b;
    --text-faint:  #636366;

    --gradient-surface: linear-gradient(135deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
    --gradient-hero: linear-gradient(135deg, #0a84ff, #5ac8fa);
    --gradient-hero-soft: linear-gradient(135deg, rgba(10,132,255,0.18), rgba(90,200,250,0.1));

    --sidebar-w:   220px;
    --font:        'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --mono:        'SF Mono', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
    --radius-sm:   8px;
    --radius:      12px;
    --radius-lg:   16px;
    --radius-xl:   20px;
    --radius-full: 9999px;

    --transition:  200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --transition-fast: 120ms ease;
    --transition-spring: 300ms cubic-bezier(0.34, 1.56, 0.64, 1);

    --shadow-sm:   0 1px 2px rgba(0,0,0,0.3);
    --shadow-md:   0 4px 12px rgba(0,0,0,0.25);
    --shadow-lg:   0 8px 24px rgba(0,0,0,0.3);
    --shadow-xl:   0 16px 48px rgba(0,0,0,0.4);

    color-scheme: dark;
}

/* ── LIGHT THEME ───────────────────────────────────────────── */
[data-theme="light"] {
    --bg:          #f8fafc;
    --bg-elevated: #ffffff;
    --surface:     #ffffff;
    --surface-2:   #f1f5f9;
    --surface-3:   #e2e8f0;
    --border:      rgba(0,0,0,0.08);
    --border-light:rgba(0,0,0,0.05);
    --border-focus:rgba(59,130,246,0.4);

    --glass:       rgba(255,255,255,0.72);
    --glass-border:rgba(0,0,0,0.06);
    --glass-shadow:0 8px 32px rgba(0,0,0,0.08);

    --primary:     #2563eb;
    --primary-hover:#1d4ed8;
    --primary-soft: rgba(37,99,235,0.08);
    --secondary:   #3b82f6;
    --accent:      #0891b2;
    --accent-soft: rgba(8,145,178,0.08);
    --danger:      #dc2626;
    --danger-soft:  rgba(220,38,38,0.08);
    --success:     #16a34a;
    --success-soft: rgba(22,163,74,0.08);
    --warning:     #d97706;

    --text:        #0f172a;
    --text-secondary: #475569;
    --text-muted:  #64748b;
    --text-faint:  #94a3b8;

    --gradient-surface: linear-gradient(135deg, rgba(59,130,246,0.04), rgba(6,182,212,0.02));
    --gradient-hero: linear-gradient(135deg, #2563eb, #0891b2);
    --gradient-hero-soft: linear-gradient(135deg, rgba(37,99,235,0.08), rgba(8,145,178,0.05));

    --shadow-sm:   0 1px 2px rgba(0,0,0,0.05);
    --shadow-md:   0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg:   0 8px 24px rgba(0,0,0,0.08);
    --shadow-xl:   0 16px 48px rgba(0,0,0,0.1);

    color-scheme: light;
}

/* ── Base ──────────────────────────────────────────────────── */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: pan-x pan-y;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
    text-rendering: optimizeLegibility;
}

::selection {
    background: rgba(10,132,255,0.3);
    color: var(--text);
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-faint); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
* { scrollbar-width: thin; scrollbar-color: var(--text-faint) transparent; }

/* ══════════════════════════════════════════════════════════════
   LAYOUT — Sidebar RIGHT, Main LEFT
   ══════════════════════════════════════════════════════════════ */

#app {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    overflow: hidden;
    background: var(--bg);
}

/* ── Sidebar (expanded, right side) ────────────────────────── */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    order: 2;
    background: var(--glass);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-left: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 16px 0;
    z-index: 50;
    transition: width var(--transition), min-width var(--transition);
    overflow: hidden;
}

.sidebar-header {
    padding: 16px 14px 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}

.sidebar-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius);
    transition: all var(--transition);
    position: relative;
    font-size: 14px;
    font-weight: 450;
    white-space: nowrap;
}

.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.nav-item:hover {
    background: var(--primary-soft);
    color: var(--text);
}

.nav-item.active {
    background: var(--primary-soft);
    color: var(--primary);
}

.nav-item.active::after {
    content: '';
    position: absolute;
    right: -1px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--primary);
    border-radius: 3px 0 0 3px;
}

.sidebar-footer {
    padding: 10px 14px 6px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-footer .btn-icon { margin-left: auto; }

.version-label {
    font-size: 11px;
    color: var(--text-faint);
    letter-spacing: 0.3px;
}

/* ── Main content ──────────────────────────────────────────── */
#main {
    flex: 1;
    min-width: 0;
    order: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Views ─────────────────────────────────────────────────── */
.view { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.view.active { display: flex; }

.view-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 28px;
    border-bottom: 1px solid var(--border);
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    background: var(--glass);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    min-height: 56px;
    letter-spacing: -0.01em;
}

.view-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 28px;
}

.center-message {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

/* ── Mobile burger toggle (right-aligned) ──────────────────── */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    margin-left: auto;
    order: 99;
}
.sidebar-toggle:hover { color: var(--text); background: var(--surface-2); }
.sidebar-toggle svg { width: 22px; height: 22px; }

/* ══════════════════════════════════════════════════════════════
   STATUS GRID
   ══════════════════════════════════════════════════════════════ */

.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.status-item {
    background: var(--gradient-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.status-item::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--gradient-hero);
    opacity: 0;
    transition: opacity var(--transition);
}

.status-item:hover {
    border-color: var(--border-focus);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.status-item:hover::before { opacity: 1; }

.status-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.status-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
}

/* ── Error row ─────────────────────────────────────────────── */
.error-row { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

.error-badge {
    font-size: 13px;
    padding: 6px 12px;
    border-radius: var(--radius-full);
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid rgba(239,68,68,0.15);
    transition: all var(--transition);
    font-weight: 500;
}
.error-badge.retryable { cursor: pointer; }
.error-badge.retryable::after { content: ' ↻'; }
.error-badge.retryable:hover { background: rgba(239,68,68,0.18); transform: translateY(-1px); }

/* ── Upload zone ───────────────────────────────────────────── */
.upload-zone { margin-bottom: 16px; }

.upload-zone-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 18px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--gradient-surface);
}
.upload-zone-inner:hover { border-color: var(--primary); color: var(--text); background: var(--primary-soft); }

.upload-zone.dragover .upload-zone-inner {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-soft);
}

.upload-status { margin-top: 8px; font-size: 13px; color: var(--text-muted); }

.upload-file-result { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 13px; }
.upload-file-result.ok { color: var(--success); }
.upload-file-result.failed { color: var(--danger); }

/* ── Action bar & Buttons ──────────────────────────────────── */
.action-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    font-size: 14px;
    font-family: var(--font);
    font-weight: 600;
    color: #fff;
    background: var(--primary);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    letter-spacing: -0.01em;
}
.btn:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(59,130,246,0.3); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary { background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { color: var(--text); border-color: var(--text-muted); background: var(--surface-3); box-shadow: var(--shadow-sm); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; box-shadow: 0 4px 12px rgba(239,68,68,0.3); }

/* ── Batch control ─────────────────────────────────────────── */
.batch-control { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; font-size: 14px; color: var(--text-muted); }

.batch-control input {
    width: 80px;
    padding: 8px 10px;
    font-size: 14px;
    font-family: var(--font);
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition);
}
.batch-control input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* ── Log panel ─────────────────────────────────────────────── */
.log-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.log-header {
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.log-body {
    padding: 12px 16px;
    max-height: 320px;
    overflow-y: auto;
    font-size: 13px;
    font-family: var(--mono);
    line-height: 1.6;
    color: var(--text-muted);
}

.log-entry { margin-bottom: 2px; }
.log-entry .log-time { color: var(--text-faint); margin-right: 8px; }
.log-entry.success { color: var(--success); }
.log-entry.error { color: var(--danger); }
.log-entry.info { color: var(--secondary); }

/* ══════════════════════════════════════════════════════════════
   LOGIN SCREEN
   ══════════════════════════════════════════════════════════════ */

.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(59,130,246,0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 20%, rgba(6,182,212,0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(139,92,246,0.04) 0%, transparent 40%);
}

.login-box {
    width: 400px;
    background: var(--glass);
    backdrop-filter: blur(40px) saturate(200%);
    -webkit-backdrop-filter: blur(40px) saturate(200%);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    padding: 44px 36px;
    box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255,255,255,0.04);
}

.login-logo {
    display: block;
    max-width: 200px;
    height: auto;
    margin: 0 auto 28px;
}

.login-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 24px;
    text-align: center;
    letter-spacing: -0.02em;
}

.login-error {
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 14px;
    color: var(--danger);
    background: var(--danger-soft);
    border: 1px solid rgba(239,68,68,0.15);
    border-radius: var(--radius);
}

.form-group { margin-bottom: 18px; }

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.login-btn {
    width: 100%;
    margin-top: 8px;
    padding: 13px 16px;
    font-size: 15px;
    border-radius: var(--radius);
    font-weight: 600;
    background: var(--gradient-hero);
    border: none;
    color: #fff;
    cursor: pointer;
    transition: all var(--transition);
}
.login-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(59,130,246,0.4); }
.login-btn:active { transform: translateY(0); }

.setup-hint { margin-top: 16px; font-size: 13px; color: var(--text-muted); text-align: center; }

/* ── Button icon ───────────────────────────────────────────── */
.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}
.btn-icon:hover { color: var(--text); background: var(--primary-soft); }
.btn-logout:hover { color: var(--danger); background: var(--danger-soft); }

/* ══════════════════════════════════════════════════════════════
   FILE BROWSER
   ══════════════════════════════════════════════════════════════ */

.files-body { padding: 16px; overflow-y: auto; }

.files-toolbar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.files-search { flex: 1; min-width: 200px; }

.files-search-input {
    width: 100%;
    padding: 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    transition: all var(--transition);
}
.files-search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.files-search-input::placeholder { color: var(--text-faint); }

.files-filters { display: flex; gap: 8px; }

.files-filter-select {
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    font-family: var(--font);
}

.files-count { font-size: 13px; color: var(--text-muted); margin-left: 8px; }
.files-table-wrap { overflow-x: auto; }

.files-table { width: 100%; border-collapse: collapse; font-size: 14px; }

.files-table th {
    text-align: left;
    padding: 10px 14px;
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 1;
}

.files-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text);
    vertical-align: middle;
}

.files-table tbody tr { transition: background var(--transition-fast); }
.files-table tbody tr:hover { background: var(--surface); }

.files-table .fname { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files-table .fname a { color: var(--secondary); text-decoration: none; transition: color var(--transition); }
.files-table .fname a:hover { text-decoration: underline; }

.files-table .meta-cell { color: var(--text-muted); font-size: 13px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.file-status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.03em;
}
.file-status.completed { background: var(--success-soft); color: var(--success); }
.file-status.pending { background: var(--accent-soft); color: var(--accent); }
.file-status.failed { background: var(--danger-soft); color: var(--danger); }
.file-status.processing { background: var(--primary-soft); color: var(--secondary); }
.file-status.skipped { background: rgba(100,116,139,0.12); color: var(--text-muted); }

.files-table .actions-cell { white-space: nowrap; text-align: right; }

.btn-file-action {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    padding: 5px 12px;
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font);
    margin-left: 4px;
    transition: all var(--transition);
}
.btn-file-action:hover { color: var(--text); border-color: var(--text-muted); }
.btn-file-action.danger:hover { color: var(--danger); border-color: var(--danger); }

.files-pagination { display: flex; gap: 4px; justify-content: center; align-items: center; padding: 16px 0; flex-wrap: wrap; }

.files-pagination button {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
    font-family: var(--font);
    min-width: 36px;
    transition: all var(--transition);
}
.files-pagination button:hover { border-color: var(--primary); color: var(--text); transform: translateY(-1px); }
.files-pagination button.active { background: var(--gradient-hero); border-color: transparent; color: #fff; }
.files-pagination button:disabled { opacity: 0.4; cursor: default; transform: none; }
.files-pagination .page-info { color: var(--text-muted); font-size: 13px; padding: 0 8px; }

.files-empty { text-align: center; padding: 40px; color: var(--text-muted); }

@media (max-width: 768px) {
    .files-toolbar { flex-direction: column; }
    .files-search { min-width: unset; }
    .files-table .meta-cell { max-width: 120px; }
    .files-table th, .files-table td { padding: 8px 10px; }
    .files-pagination { gap: 3px; }
    .files-pagination button { padding: 6px 10px; min-width: 32px; }
}

/* ══════════════════════════════════════════════════════════════
   CHAT LAYOUT
   ══════════════════════════════════════════════════════════════ */

.chat-layout { display: flex; flex: 1; overflow: hidden; height: 100%; }

.chat-sessions {
    width: 260px;
    min-width: 260px;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.chat-sessions-logo {
    padding: 14px 16px 6px;
    display: flex;
    align-items: center;
}
.sessions-logo {
    height: 32px;
    object-fit: contain;
}

.chat-sessions-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 16px 12px;
    text-decoration: none;
    cursor: pointer;
    border-radius: var(--radius);
    transition: background var(--transition);
}
.chat-sessions-user:hover { background: var(--surface-hover); }
.sessions-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700;
    flex-shrink: 0;
    text-transform: uppercase;
}
.sessions-username {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.sessions-theme-toggle {
    flex-shrink: 0;
    color: var(--text-muted);
    transition: color var(--transition);
}
.sessions-theme-toggle:hover { color: var(--text); }
[data-theme="dark"] .sessions-theme-toggle .icon-sun { display: inline; }
[data-theme="dark"] .sessions-theme-toggle .icon-moon { display: none; }
[data-theme="light"] .sessions-theme-toggle .icon-sun { display: none; }
[data-theme="light"] .sessions-theme-toggle .icon-moon { display: inline; }

.chat-sessions-search {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 12px 10px;
    padding: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    transition: border-color var(--transition);
}
.chat-sessions-search:focus-within { border-color: var(--primary); }
.chat-sessions-search svg { flex-shrink: 0; }
.chat-sessions-search input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
}
.chat-sessions-search input::placeholder { color: var(--text-faint); }

.sessions-fab {
    position: absolute;
    bottom: 16px; right: 16px;
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all var(--transition);
    z-index: 2;
}
.sessions-fab:hover { transform: scale(1.08); filter: brightness(1.1); }
.sessions-fab-left {
    left: 16px; right: auto;
    background: var(--surface-2);
    color: var(--text-muted);
    text-decoration: none;
}
.sessions-fab-left:hover { background: var(--surface-hover); color: var(--text); transform: scale(1.08); filter: none; }

.chat-sessions-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 8px 10px 76px; }

.session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 12px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    gap: 4px 8px;
    border: 1px solid transparent;
    margin-bottom: 2px;
}
.session-item:hover { background: var(--surface-2); border-color: var(--border); }
.session-item.active { background: var(--primary-soft); border-color: rgba(59,130,246,0.2); }
.session-item.active .session-title { color: var(--primary); }

.session-title {
    flex: 1;
    font-size: 15px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 450;
}

.session-delete { opacity: 0; transition: opacity var(--transition); }
.session-item:hover .session-delete { opacity: 1; }

.session-search-snippet {
    width: 100%;
    font-size: 12px;
    color: var(--text-faint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
    line-height: 1.4;
}
.session-search-snippet mark {
    background: rgba(250, 204, 21, 0.35);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

/* ── Chat main ─────────────────────────────────────────────── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    background: var(--bg);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    background: var(--glass);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    min-height: 56px;
    letter-spacing: -0.01em;
}

#chat-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
}

.chat-sessions-toggle { display: none; }

/* ── Messages ──────────────────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
}

.chat-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-faint);
    font-size: 16px;
    text-align: center;
    padding: 40px;
}

/* Welcome screen */
.welcome-screen { max-width: 400px; width: 100%; }
.welcome-logo { height: 48px; margin-bottom: 12px; opacity: 0.85; }
.welcome-subtitle { color: var(--text-muted); font-size: 15px; margin: 0 0 24px; }
.welcome-new-chat {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 24px; border-radius: 12px;
    background: var(--primary); color: #fff;
    border: none; font-size: 14px; font-weight: 600;
    cursor: pointer; transition: all var(--transition);
    white-space: nowrap;
}
.welcome-new-chat svg { flex-shrink: 0; width: 16px; height: 16px; }
.welcome-new-chat:hover { filter: brightness(1.1); transform: scale(1.02); }
.welcome-view-all {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 24px; border-radius: 12px;
    background: var(--surface); color: var(--text-secondary);
    border: 1px solid var(--border); font-size: 14px; font-weight: 500;
    cursor: pointer; transition: all var(--transition);
    white-space: nowrap; margin-top: 10px;
}
.welcome-view-all svg { flex-shrink: 0; width: 16px; height: 16px; }
.welcome-view-all:hover { background: var(--surface-hover); border-color: var(--primary); color: var(--text); }
.welcome-recent { margin-top: 28px; }
.welcome-recent-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-faint); margin-bottom: 8px;
}
.welcome-recent-item {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 10px 14px; border-radius: 10px;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text); font-size: 13px; cursor: pointer;
    transition: all var(--transition); margin-bottom: 6px;
    text-align: left;
}
.welcome-recent-item:hover { background: var(--surface-hover); border-color: var(--accent); }
.welcome-recent-item svg { flex-shrink: 0; color: var(--text-faint); }
.welcome-recent-item span {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.chat-msg {
    margin-bottom: 24px;
    max-width: 780px;
    animation: msgFadeIn 0.3s ease-out;
}

@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-msg-user { margin-left: auto; max-width: 600px; }

/* ── Message header (name, date, retry) ───────────────────────── */
.msg-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 4px 4px;
    font-size: 11px;
    color: var(--text-faint);
    letter-spacing: 0.02em;
}
.chat-msg-user .msg-header { justify-content: flex-end; }
.msg-header-name { font-weight: 600; color: var(--text-muted); }
.msg-header-date { opacity: 0.7; }
.msg-header-date::before { content: '·'; margin-right: 0px; }
.msg-header-retry {
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: pointer;
    padding: 1px 4px;
    border-radius: 4px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s, background 0.2s;
}
.chat-msg:hover .msg-header-retry { opacity: 1; }
.msg-header-retry:hover { color: var(--primary); background: var(--primary-soft); }

/* ── Attachment chips on user messages ─────────────────────── */
.msg-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
    justify-content: flex-end;
}

.msg-attach-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    text-decoration: none;
    transition: all var(--transition);
    cursor: pointer;
}
.msg-attach-chip:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-soft);
}
.msg-attach-chip svg { flex-shrink: 0; opacity: 0.7; }
.msg-attach-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #0d47a1;
    background: #e3f2fd;
    padding: 3px 10px;
    border-radius: var(--radius-full);
}

/* ── Error bubble for upload failures ─────────────────────── */
.chat-msg-system { max-width: 600px; margin: 8px auto; }
.msg-error-bubble {
    background: var(--danger-soft);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    padding: 10px 16px;
    color: var(--danger);
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-line;
}

.chat-msg-user .msg-bubble {
    background: var(--gradient-hero);
    border-radius: var(--radius-xl) var(--radius-xl) 6px var(--radius-xl);
    padding: 14px 20px;
    color: #fff;
    font-size: 15px;
    line-height: 1.6;
    box-shadow: 0 2px 12px rgba(59,130,246,0.25);
}

.chat-msg-assistant { max-width: 780px; }

.chat-msg-assistant .msg-bubble {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px var(--radius-xl) var(--radius-xl) var(--radius-xl);
    padding: 18px 22px;
    color: var(--text);
    font-size: 15px;
    line-height: 1.75;
    box-shadow: var(--shadow-sm);
}

/* ── Code blocks ───────────────────────────────────────────── */
.msg-bubble .code-block-wrap { position: relative; margin: 14px 0; }

.msg-bubble .code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font);
}

.msg-bubble .code-block-header .code-lang {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

.msg-bubble .code-copy-btn {
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font);
    transition: all var(--transition);
}
.msg-bubble .code-copy-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-muted); }
.msg-bubble .code-copy-btn.copied { color: var(--success); border-color: var(--success); background: var(--success-soft); }

.msg-bubble pre {
    background: #1c1c1e;
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 16px 18px;
    overflow-x: auto;
    margin: 0;
    font-size: 13px;
    line-height: 1.6;
}

[data-theme="light"] .msg-bubble pre { background: #f5f5f7; }

.msg-bubble pre code.hljs { background: transparent; padding: 0; }
.msg-bubble .code-block-wrap:not(:has(.code-block-header)) pre { border-radius: var(--radius); }
.msg-bubble > pre { border-radius: var(--radius); margin: 14px 0; }

.msg-bubble code { font-family: var(--mono); font-size: 0.88em; }
.msg-bubble pre code { background: none; padding: 0; font-size: 13px; }

.msg-bubble code:not(pre code) {
    background: var(--primary-soft);
    color: var(--secondary);
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 0.88em;
}

/* ── Code block preview ────────────────────────────────────── */
.msg-bubble .code-header-actions { display: flex; gap: 6px; align-items: center; }

.msg-bubble .code-preview-btn {
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font);
    transition: all var(--transition);
}
.msg-bubble .code-preview-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-muted); }
.msg-bubble .code-preview-btn.active { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }

.msg-bubble .code-block-wrap.previewing pre { border-radius: 0; border-bottom: none; }

.msg-bubble .code-block-wrap.previewing pre[style*="display: none"] + .code-preview,
.msg-bubble .code-block-wrap.previewing pre[style*="display:none"] + .code-preview {
    border-top: 1px solid var(--border);
}

.msg-bubble .code-preview {
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    overflow: hidden;
    background: #ffffff;
}
.msg-bubble .code-preview iframe { width: 100%; border: none; min-height: 60px; max-height: 500px; display: block; background: #ffffff; }

.msg-bubble .code-preview .csv-preview-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); }
.msg-bubble .code-preview .csv-preview-table th { background: var(--surface-2); color: var(--text); font-weight: 600; text-align: left; padding: 8px 12px; border-bottom: 2px solid var(--border); }
.msg-bubble .code-preview .csv-preview-table td { padding: 6px 12px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.msg-bubble .code-preview .csv-preview-table tr:last-child td { border-bottom: none; }

/* ── Message typography ────────────────────────────────────── */
.msg-bubble h2, .msg-bubble h3, .msg-bubble h4, .msg-bubble h5 {
    color: var(--text);
    margin: 20px 0 8px;
    line-height: 1.3;
    font-weight: 600;
    letter-spacing: -0.02em;
}
.msg-bubble h2 { font-size: 1.4em; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.msg-bubble h3 { font-size: 1.15em; color: var(--secondary); }
.msg-bubble h4 { font-size: 1.05em; }
.msg-bubble h5 { font-size: 1em; }
.msg-bubble p { margin: 6px 0; }

.msg-bubble ul, .msg-bubble ol { margin: 8px 0; padding-left: 24px; }
.msg-bubble li { margin: 4px 0; line-height: 1.7; }
.msg-bubble li::marker { color: var(--text-faint); }

.msg-bubble blockquote {
    border-left: 3px solid var(--accent);
    margin: 12px 0;
    padding: 10px 18px;
    color: var(--text-secondary);
    background: var(--accent-soft);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-style: italic;
}

.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

.msg-bubble table.md-table {
    border-collapse: collapse;
    margin: 14px 0;
    font-size: 14px;
    width: 100%;
    overflow-x: auto;
    display: block;
    border-radius: var(--radius);
}
.msg-bubble table.md-table th, .msg-bubble table.md-table td { border: 1px solid var(--border); padding: 8px 14px; text-align: left; }
.msg-bubble table.md-table th { background: var(--surface-2); font-weight: 600; color: var(--secondary); font-size: 0.9em; text-transform: uppercase; letter-spacing: 0.03em; }
.msg-bubble table.md-table tr:nth-child(even) td { background: rgba(255,255,255,0.02); }
[data-theme="light"] .msg-bubble table.md-table tr:nth-child(even) td { background: rgba(0,0,0,0.02); }
.msg-bubble table.md-table tr:hover td { background: var(--primary-soft); }

.msg-bubble a { color: var(--secondary); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color var(--transition); }
.msg-bubble a:hover { border-bottom-color: var(--secondary); }

.msg-error {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    color: var(--danger);
    font-size: 13px;
    line-height: 1.5;
    padding: 12px 16px;
    background: var(--danger-soft);
    border-radius: var(--radius);
    border-left: 3px solid var(--danger);
}
.msg-error svg {
    flex-shrink: 0;
    margin-top: 1px;
    opacity: 0.85;
}
.msg-error span {
    word-break: break-word;
}

/* ── Typing indicator ──────────────────────────────────────── */
.typing-indicator { display: inline-flex; align-items: center; gap: 4px; padding: 4px 0; }
.typing-indicator::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-faint);
    animation: typingDot 1.4s infinite;
    box-shadow: 12px 0 0 var(--text-faint), 24px 0 0 var(--text-faint);
}

@keyframes typingDot {
    0%, 20%  { opacity: 0.3; transform: scale(0.8); }
    50%      { opacity: 1;   transform: scale(1); }
    80%, 100% { opacity: 0.3; transform: scale(0.8); }
}

/* Document creation spinner (shown while streaming HTML code blocks) */
.doc-creating {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    margin: 12px 0;
    background: var(--surface-2);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
}
.doc-creating-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: docSpin 0.8s linear infinite;
}
@keyframes docSpin {
    to { transform: rotate(360deg); }
}
.doc-creating-chars { color: var(--text-muted); font-weight: 400; font-variant-numeric: tabular-nums; }

/* ── Search indicator (tool use) ───────────────────────────── */
.search-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 6px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--surface-2);
    border-radius: var(--radius-full);
    animation: searchPulse 1.5s ease-in-out infinite;
}
.search-indicator svg { opacity: 0.7; }
@keyframes searchPulse {
    0%, 100% { opacity: 0.6; }
    50%      { opacity: 1; }
}

/* ── Search log (inline collapsible blocks) ────────────────── */
.search-log {
    display: block;
    margin: 8px 0;
    font-size: 12px;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.search-log + .search-log { margin-top: 4px; }
.search-log summary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    cursor: pointer;
    user-select: none;
    background: var(--surface-2);
    font-weight: 500;
    list-style: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-log summary::-webkit-details-marker { display: none; }
.search-log summary::after {
    content: '\25B6';
    font-size: 8px;
    margin-left: auto;
    flex-shrink: 0;
    transition: transform 0.15s ease;
}
.search-log[open] summary::after { transform: rotate(90deg); }
.search-log summary svg { opacity: 0.6; flex-shrink: 0; }
.search-log-active summary { animation: searchPulse 1.5s ease-in-out infinite; }
.search-log-results {
    margin: 0;
    padding: 6px 10px 6px 26px;
    font-size: 11.5px;
    line-height: 1.6;
    color: var(--text-muted);
    background: var(--surface-1);
    list-style: none;
}
.search-log-results li { position: relative; padding-left: 10px; }
.search-log-results li::before { content: '\2022'; position: absolute; left: 0; color: var(--text-muted); opacity: 0.5; }
.search-log-results li + li { margin-top: 1px; }
.search-log-results a { color: var(--primary); text-decoration: none; }
.search-log-results a:hover { text-decoration: underline; }
.search-result-meta {
    display: inline-block;
    padding: 0 5px;
    margin-left: 4px;
    font-size: 10px;
    color: var(--text-secondary);
    background: var(--surface-2);
    border-radius: 3px;
    vertical-align: baseline;
}
.search-result-score {
    display: inline-block;
    padding: 0 5px;
    margin-left: 4px;
    font-size: 10px;
    font-weight: 600;
    color: var(--success, #4caf50);
    opacity: 0.8;
    vertical-align: baseline;
}
.search-log-loading {
    padding: 6px 10px;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--surface-1);
    font-style: italic;
}

/* ── Citations ─────────────────────────────────────────────── */
.msg-citations { margin-top: 14px; }

.msg-citations-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: var(--surface-2);
    border-radius: var(--radius);
    transition: background var(--transition);
}
.msg-citations-title:hover { background: var(--surface-3); }
.msg-citations-title::before { content: '\25B6'; font-size: 8px; transition: transform var(--transition); }
.msg-citations[open] > .msg-citations-title::before { transform: rotate(90deg); }
.msg-citations-title::-webkit-details-marker { display: none; }

.citation {
    display: block;
    padding: 12px 16px;
    margin: 4px 0;
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-secondary);
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all var(--transition);
}
.citation:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--text); }
.citation .cit-title { color: var(--secondary); font-weight: 600; font-size: 14px; }
.citation .cit-meta { display: block; color: var(--text-muted); font-size: 12px; margin-top: 3px; }
.citation .cit-excerpt { display: block; color: var(--text-muted); font-size: 12px; margin-top: 4px; line-height: 1.5; border-left: 2px solid var(--text-faint); padding-left: 8px; }

/* Citation source badges */
.cit-source-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 1px 6px;
    border-radius: 3px;
    margin-right: 6px;
    vertical-align: middle;
}
.cit-src-attachment { background: #e3f2fd; color: #1565c0; }
.cit-src-upload { background: #e3f2fd; color: #0d47a1; }
.cit-src-archive { background: #f3e5f5; color: #7b1fa2; }
.cit-src-tool-search { background: #e8f5e9; color: #2e7d32; }
.cit-source-summary { font-weight: 400; font-size: 10px; color: var(--text-muted); margin-left: 6px; text-transform: none; letter-spacing: 0; }

/* Similarity score badges */
.cit-sim {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    margin-right: 6px;
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
}
.cit-sim-high { background: #e8f5e9; color: #2e7d32; }
.cit-sim-med  { background: #fff3e0; color: #e65100; }
.cit-sim-low  { background: #fce4ec; color: #c62828; }

/* ── Web results ───────────────────────────────────────────── */
.web-results { margin-top: 12px; }

.web-results-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: var(--surface-2);
    border-radius: var(--radius);
    transition: background var(--transition);
}
.web-results-title:hover { background: var(--surface-3); }
.web-results-title::before { content: '\25B6'; font-size: 8px; transition: transform var(--transition); }
.web-results[open] > .web-results-title::before { transform: rotate(90deg); }
.web-results-title::-webkit-details-marker { display: none; }

.web-result-item {
    display: block;
    padding: 12px 16px;
    margin: 4px 0;
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-secondary);
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all var(--transition);
}
.web-result-item:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.web-result-item .wr-title { color: var(--accent); font-weight: 600; font-size: 14px; }
.web-result-item .wr-domain { display: block; color: var(--text-muted); font-size: 11px; opacity: 0.7; margin-top: 2px; }
.web-result-item .wr-desc { display: block; color: var(--text-muted); font-size: 12px; margin-top: 3px; line-height: 1.5; }

/* ── Chat input ────────────────────────────────────────────── */
.chat-input-area { padding: 14px 28px 24px; background: transparent; }

.chat-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
    max-width: 780px;
    margin-left: auto;
    margin-right: auto;
    max-height: 180px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.attach-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    font-size: 13px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    min-width: 340px;
    max-width: 380px;
}
.attach-chip .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.attach-chip .status {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 12px;
    opacity: 0.7;
}
.attach-chip.processing { color: var(--text-muted); border-style: dashed; }
.attach-chip.ready { border-color: var(--success); color: var(--success); }
.attach-chip.error { border-color: var(--danger); color: var(--danger); }
.attach-chip .remove { cursor: pointer; opacity: 0.5; margin-left: 2px; }
.attach-chip .remove:hover { opacity: 1; }

/* Batch progress bar */
.attach-progress {
    max-width: 780px;
    margin: 0 auto 8px;
    width: 100%;
}
.attach-progress-text {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.attach-progress-bar {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}
.attach-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

/* Input overlay while processing */
.chat-input-wrap { position: relative; }
.input-processing-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--glass);
    backdrop-filter: blur(6px);
    border-radius: var(--radius-xl);
    z-index: 2;
    color: var(--text-muted);
    font-size: 14px;
}
.input-overlay-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.attach-thumb {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}
#chat-view.drag-over {
    outline: 2px dashed var(--accent);
    outline-offset: -4px;
    background: color-mix(in srgb, var(--accent) 5%, transparent);
}

.chat-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--glass);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    padding: 10px 14px;
    box-shadow: var(--glass-shadow);
    transition: border-color var(--transition), box-shadow var(--transition);
    max-width: 780px;
    margin: 0 auto;
    width: 100%;
}
.chat-input-wrap:focus-within { border-color: var(--border-focus); box-shadow: var(--glass-shadow), 0 0 0 3px var(--primary-soft); }

.btn-attach {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 6px 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: color var(--transition);
}
.btn-attach:hover { color: var(--text); }
.btn-attach:disabled { opacity: 0.4; cursor: not-allowed; }

.chat-input-wrap textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 15px;
    font-family: var(--font);
    line-height: 1.5;
    resize: none;
    max-height: 150px;
}

/* Mic button */
.btn-mic {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    color: var(--text-secondary);
    width: 36px; height: 36px; min-width: 36px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition);
}
.btn-mic:hover { color: var(--text); transform: scale(1.08); border-color: var(--border-focus); }
.btn-mic.recording {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
    box-shadow: 0 2px 8px rgba(239,68,68,0.3);
    animation: micPulse 1.2s infinite;
}
.btn-mic.recording:hover { box-shadow: 0 4px 16px rgba(239,68,68,0.4); }
@keyframes micPulse {
    0%, 100% { box-shadow: 0 2px 8px rgba(239,68,68,0.3); }
    50% { box-shadow: 0 2px 16px rgba(239,68,68,0.5); }
}

.btn-send {
    background: var(--gradient-hero);
    border: none;
    border-radius: 50%;
    color: #fff;
    width: 36px;
    height: 36px;
    min-width: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    box-shadow: 0 2px 8px rgba(59,130,246,0.3);
}
.btn-send:hover { transform: scale(1.08); box-shadow: 0 4px 16px rgba(59,130,246,0.4); }
.btn-send:active { transform: scale(0.95); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

/* Stop button */
.btn-stop {
    background: var(--danger);
    border: none;
    border-radius: 50%;
    color: #fff;
    width: 36px; height: 36px; min-width: 36px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition);
    box-shadow: 0 2px 8px rgba(239,68,68,0.3);
    animation: stopPulse 1.5s infinite;
}
.btn-stop:hover { transform: scale(1.08); box-shadow: 0 4px 16px rgba(239,68,68,0.4); }
.btn-stop:active { transform: scale(0.95); }
@keyframes stopPulse {
    0%, 100% { box-shadow: 0 2px 8px rgba(239,68,68,0.3); }
    50% { box-shadow: 0 2px 16px rgba(239,68,68,0.5); }
}

/* Context bar */
.context-bar {
    padding: 0 16px 8px;
}
.context-bar-inner {
    display: flex; align-items: center; gap: 10px;
    font-size: 11px; color: var(--text-faint);
}
.context-bar-label { white-space: nowrap; min-width: 140px; }
.context-bar-track {
    flex: 1; height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}
.context-bar-fill {
    height: 100%; width: 0;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.4s ease;
}
.context-bar-fill.warning { background: var(--warning, #f59e0b); }
.context-bar-fill.danger { background: var(--danger); }
.context-bar-pct { min-width: 30px; text-align: right; font-weight: 600; }

/* Agent status panel (compact spinner icons) */
.agent-status-panel {
    display: flex; flex-wrap: wrap; gap: 2px;
    margin-bottom: 6px;
    padding: 0;
    align-items: center;
}
.agent-status-panel:empty { display: none; }

.agent-card {
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.3s ease;
    position: relative;
    width: 32px; height: 32px;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
}
.agent-card:hover { transform: scale(1.15); }

/* Entrance animation */
.agent-card.agent-enter {
    opacity: 0;
    transform: scale(0);
    animation: agentPopIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes agentPopIn {
    to { opacity: 1; transform: scale(1); }
}

/* The orb container */
.agent-orb {
    position: relative;
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
}

/* SVG ring */
.agent-ring {
    position: absolute;
    inset: 0;
    width: 100%; height: 100%;
}
.ring-track {
    stroke: var(--border);
}
.ring-progress {
    stroke: var(--primary);
    stroke-linecap: round;
    stroke-dasharray: 56.55; /* 2 * PI * 9 */
    stroke-dashoffset: 42.41; /* 75% hidden = spinning arc */
    transform-origin: center;
    transition: stroke 0.4s ease, stroke-dashoffset 0.6s ease;
}

/* Working: spinning ring arc */
.agent-card.working .ring-progress {
    animation: ringSpin 1s linear infinite;
}
@keyframes ringSpin {
    to { transform: rotate(360deg); }
}

/* Done: full ring, green */
.agent-card.done .ring-progress {
    stroke: var(--success, #22c55e);
    stroke-dashoffset: 0;
    animation: none;
}
.agent-card.done { opacity: 0.8; }
.agent-card.done:hover { opacity: 1; }

/* Error: full ring, red */
.agent-card.error .ring-progress {
    stroke: var(--danger);
    stroke-dashoffset: 0;
    animation: none;
}

/* Icon inside orb */
.agent-icon {
    font-size: 14px;
    z-index: 1;
    line-height: 1;
    width: 14px; height: 14px;
    display: flex; align-items: center; justify-content: center;
    text-align: center;
}

/* Stopped message */
.msg-stopped {
    color: var(--text-faint);
    font-style: italic;
    font-size: 14px;
}

/* ── Agent Detail Modal ────────────────────────────────────── */
.agent-modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.agent-modal-overlay.open { opacity: 1; }

.agent-modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%; max-width: 640px;
    max-height: 80vh;
    display: flex; flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    transform: translateY(20px) scale(0.95);
    transition: transform 0.2s ease;
}
.agent-modal-overlay.open .agent-modal {
    transform: translateY(0) scale(1);
}

.agent-modal-header {
    display: flex; align-items: center; gap: 8px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.agent-modal-icon { font-size: 22px; }
.agent-modal-title { font-size: 16px; font-weight: 700; flex: 1; }
.agent-modal-badge {
    font-size: 11px; font-weight: 600;
    color: var(--text-faint);
    text-transform: uppercase;
}
.agent-modal-close {
    background: none; border: none; cursor: pointer;
    font-size: 22px; color: var(--text-faint);
    padding: 0 4px; line-height: 1;
    transition: color 0.2s;
}
.agent-modal-close:hover { color: var(--text); }

.agent-modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

/* Modal sections */
.modal-section { margin-bottom: 16px; }
.modal-section:last-child { margin-bottom: 0; }
.modal-section-title {
    font-size: 11px; font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-faint);
    margin-bottom: 6px;
}
.modal-code {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-family: var(--font-mono, 'Fira Code', monospace);
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
}
.modal-code-sm { font-size: 11px; max-height: 120px; color: var(--text-faint); }

.modal-list {
    list-style: none; padding: 0; margin: 0;
}
.modal-list li {
    padding: 6px 10px;
    border-left: 3px solid var(--primary);
    margin-bottom: 4px;
    font-size: 13px;
    background: color-mix(in srgb, var(--primary), transparent 95%);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.modal-list-num {
    font-weight: 700; color: var(--primary);
    margin-right: 6px;
}

.modal-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.modal-tag {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}
.tag-name { background: color-mix(in srgb, #6366f1, transparent 85%); color: #6366f1; }
.tag-num { background: color-mix(in srgb, #f59e0b, transparent 85%); color: #d97706; }
.tag-type { background: color-mix(in srgb, #22c55e, transparent 85%); color: #16a34a; }

.modal-stats {
    display: flex; gap: 16px; flex-wrap: wrap;
    font-size: 13px; font-weight: 600;
}
.modal-stats span {
    padding: 4px 0;
    color: var(--text-faint);
}

.modal-table {
    width: 100%; border-collapse: collapse;
    font-size: 12px;
}
.modal-table th {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 2px solid var(--border);
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-faint);
}
.modal-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    max-width: 200px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sim-high { color: var(--success, #22c55e); font-weight: 700; }
.sim-med { color: var(--warning, #f59e0b); font-weight: 600; }
.sim-low { color: var(--text-faint); }

.modal-doc {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 8px;
}
.modal-doc:last-child { margin-bottom: 0; }
.modal-doc-header {
    display: flex; justify-content: space-between; align-items: center;
    font-weight: 600; font-size: 13px;
}
.modal-doc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.modal-doc-meta { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.modal-doc-preview {
    font-size: 11px; color: var(--text-faint);
    margin-top: 6px; padding-top: 6px;
    border-top: 1px solid var(--border);
    line-height: 1.4;
    max-height: 60px; overflow: hidden;
}

.modal-empty {
    text-align: center;
    color: var(--text-faint);
    font-style: italic;
    padding: 12px;
}

.modal-log { font-size: 12px; }
.modal-log-entry {
    display: flex; align-items: baseline; gap: 4px;
    padding: 3px 0;
    color: var(--text-faint);
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        right: 0; top: 0; bottom: 0;
        z-index: 100;
        transform: translateX(100%);
        transition: transform 250ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
        width: 260px;
        min-width: 260px;
    }

    .sidebar-open #sidebar { transform: translateX(0); }

    .sidebar-toggle { display: block; }

    .chat-sessions {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        z-index: 90;
        transform: translateX(-100%);
        transition: transform 250ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
        width: 280px;
    }
    .chat-sessions.open { transform: translateX(0); }
    .chat-sessions-toggle { display: inline-flex; }

    .panel-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 89;
        cursor: pointer;
    }
    .panel-overlay.active { display: block; }

    .status-grid { grid-template-columns: repeat(2, 1fr); }
    .action-bar { flex-direction: column; }
    .btn { justify-content: center; }
}

@media (max-width: 480px) {
    .status-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .status-item { padding: 14px 16px; }
    .status-value { font-size: 22px; }
    .status-label { font-size: 10px; }
    .view-body { padding: 14px; }
    .view-header { padding: 14px 16px; }

    .chat-messages { padding: 12px 10px; }
    .chat-input-area { padding: 10px 10px 16px; }
    .attach-chip { min-width: 0; max-width: 100%; flex: 1 1 100%; }
    .chat-msg { max-width: 100%; }
    .chat-msg-user { max-width: 92%; }
    .chat-msg-assistant { max-width: 100%; }
    .chat-msg-user .msg-bubble { border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg); padding: 12px 16px; }
    .chat-msg-assistant .msg-bubble { border-radius: 4px var(--radius-lg) var(--radius-lg) var(--radius-lg); padding: 14px 16px; }
    .chat-input-wrap { border-radius: var(--radius-lg); padding: 8px 12px; }

    .msg-bubble pre { padding: 12px 14px; font-size: 12px; }
    .msg-bubble .code-block-header { padding: 6px 12px; font-size: 10px; }
    .msg-bubble table.md-table th, .msg-bubble table.md-table td { padding: 6px 8px; font-size: 13px; }

    .citation { padding: 10px 12px; }
    .web-result-item { padding: 10px 12px; }

    .login-box { padding: 32px 24px; border-radius: var(--radius-lg); width: 92vw; }
    .login-logo { max-width: 160px; }

    .batch-control { flex-wrap: wrap; }
    .agent-select { max-width: 120px; font-size: 13px; }
    .chat-empty svg { width: 36px; height: 36px; }
    .chat-empty p { font-size: 14px; }
    .welcome-logo { height: 36px; }
    .welcome-subtitle { font-size: 13px; margin-bottom: 18px; }
    .welcome-new-chat { padding: 9px 20px; font-size: 13px; }
    .welcome-view-all { padding: 9px 20px; font-size: 13px; }
    .welcome-recent { margin-top: 20px; }
}

/* ── Agent selector ────────────────────────────────────────── */
.agent-select {
    margin-left: auto;
    padding: 6px 10px;
    font-size: 13px;
    font-family: var(--font);
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    max-width: 180px;
    transition: all var(--transition);
}
.agent-select:focus { outline: none; border-color: var(--primary); color: var(--text); }

/* ══════════════════════════════════════════════════════════════
   AGENTS MANAGEMENT
   ══════════════════════════════════════════════════════════════ */

.agents-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.agent-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all var(--transition);
}
.agent-card:hover { border-color: var(--border-focus); box-shadow: var(--shadow-md); }

.agent-card-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.agent-card-name { font-size: 16px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }

.agent-card-type {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: var(--radius-full);
    background: var(--primary-soft);
    color: var(--primary);
    border: 1px solid rgba(59,130,246,0.2);
    font-weight: 600;
    letter-spacing: 0.03em;
}

.agent-card-desc { font-size: 14px; color: var(--text-secondary); line-height: 1.5; }

.agent-card-prompt {
    font-size: 13px;
    color: var(--text-faint);
    font-family: var(--mono);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    max-height: 80px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.agent-card-actions { display: flex; gap: 6px; margin-top: 4px; }
.agent-card.inactive { opacity: 0.5; }

/* ── Agent editor ──────────────────────────────────────────── */
.agent-editor {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
}

.agent-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.agent-form { display: flex; flex-direction: column; gap: 14px; }

.agent-form select,
.agent-form input[type="text"],
.agent-form textarea {
    width: 100%;
    padding: 10px 14px;
    font-size: 15px;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.agent-form textarea { font-family: var(--mono); font-size: 13px; line-height: 1.5; resize: vertical; min-height: 120px; }
.agent-form select:focus, .agent-form input:focus, .agent-form textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.agent-form-actions { display: flex; gap: 8px; }

/* ══════════════════════════════════════════════════════════════
   SETTINGS
   ══════════════════════════════════════════════════════════════ */

.settings-body { padding: 24px; overflow-y: auto; }

.settings-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 16px;
}

.settings-section-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 18px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    letter-spacing: -0.02em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}
.settings-section-title::after {
    content: '';
    width: 18px; height: 18px; flex-shrink: 0;
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/contain no-repeat;
    transition: transform 0.2s ease;
    opacity: 0.5;
}
.settings-section.collapsed .settings-section-title { margin-bottom: 0; padding-bottom: 10px; border-bottom: none; }
.settings-section.collapsed .settings-section-title::after { transform: rotate(-90deg); }
.settings-section-body { overflow: hidden; }
.settings-section.collapsed .settings-section-body { display: none; }

.settings-subsection {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 24px 0 14px;
    padding-top: 14px;
}

.settings-row { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.settings-row label { width: 150px; flex-shrink: 0; font-size: 14px; color: var(--text-secondary); font-weight: 450; }

.settings-row-full { flex-direction: column; align-items: stretch; }
.settings-row-full label { width: auto; margin-bottom: 6px; }

.settings-input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text);
    font-size: 15px;
    font-family: var(--font);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.settings-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.settings-input:disabled { opacity: 0.5; cursor: not-allowed; }
.settings-input.mono { font-family: var(--mono); font-size: 13px; }

.settings-textarea {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    min-height: 80px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.settings-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.btn-settings-save {
    margin-top: 10px;
    padding: 10px 24px;
    background: var(--gradient-hero);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
}
.btn-settings-save:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(59,130,246,0.3); }

.btn-settings-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    padding: 10px 24px;
    background: transparent;
    color: var(--danger, #ff453a);
    border: 1px solid var(--danger, #ff453a);
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
    width: fit-content;
}
.btn-settings-logout:hover {
    background: var(--danger, #ff453a);
    color: #fff;
    transform: translateY(-1px);
}

/* ── Settings stats ────────────────────────────────────────── */
.settings-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }

.stat-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    text-align: center;
}
.stat-card .stat-value { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── User management ───────────────────────────────────────── */
.users-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.users-table th, .users-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
.users-table th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }

.users-table .btn-sm {
    padding: 4px 10px;
    font-size: 13px;
    font-family: var(--font);
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    margin-left: 4px;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.users-table .btn-sm .btn-icon-svg { flex-shrink: 0; }
.users-table .btn-sm:hover { border-color: var(--text); color: var(--text); }
.users-table .btn-sm.danger:hover { border-color: var(--danger); color: var(--danger); }
.user-actions { white-space: nowrap; }

@media (max-width: 600px) {
    .users-table .hide-mobile { display: none; }
    .users-table .btn-sm .btn-label { display: none; }
    .users-table .btn-sm { padding: 6px; margin-left: 2px; }
    .users-table th, .users-table td { padding: 8px 6px; font-size: 13px; }
}

.role-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.role-badge.admin { background: var(--primary-soft); color: var(--primary); }
.role-badge.user { background: var(--success-soft); color: var(--success); }

@media (max-width: 600px) {
    .settings-row { flex-direction: column; align-items: stretch; gap: 4px; }
    .settings-row label { width: auto; }
    .settings-section { padding: 16px; }
    .settings-section-title { font-size: 16px; }
    .settings-textarea { min-height: 100px; }
    .settings-stats { grid-template-columns: 1fr 1fr; }
}

/* ── Impersonate Banner ─────────────────────────────────────── */
.impersonate-banner {
    position: fixed;
    top: 0; left: 0; right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 6px 16px;
    background: var(--warning, #ff9f0a);
    color: #000;
    font-size: 12px;
    font-weight: 600;
    z-index: 300;
}
.impersonate-banner ~ .chat-layout { padding-top: 32px; }
body.impersonating #app { margin-top: 30px; }
.impersonate-banner button {
    padding: 2px 10px;
    border: 1px solid rgba(0,0,0,0.3);
    border-radius: var(--radius-sm);
    background: rgba(0,0,0,0.15);
    color: #000;
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
}
.impersonate-banner button:hover { background: rgba(0,0,0,0.25); }

/* ── Print ─────────────────────────────────────────────────── */
* {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
}

@media print {
    .chat-sessions, .sidebar, .chat-header, .chat-input-area,
    .panel-overlay, .sessions-fab, .sidebar-toggle, .chat-sessions-toggle,
    .impersonate-banner {
        display: none !important;
    }
    .chat-main { margin: 0; padding: 0; width: 100%; max-width: 100%; }
    .chat-messages { overflow: visible; height: auto; max-height: none; }
    body, html { background: #fff; }
    .message { break-inside: avoid; }
}
