:root {
    --bg: #080808;
    --bg-surface: oklch(15% 0 0);
    --bg-elevated: oklch(18% 0 0);
    --bg-hover: oklch(22% 0 0);
    --bg-active: oklch(25% 0 0);
    --text: #f0ede8;
    --text-secondary: oklch(60% 0 0);
    --text-muted: oklch(45% 0 0);
    --accent: oklch(55% 0.2 250);
    --accent-hover: oklch(60% 0.22 250);
    --accent-subtle: oklch(35% 0.15 250 / 0.25);
    --danger: oklch(55% 0.22 30);
    --danger-subtle: oklch(35% 0.15 30 / 0.2);
    --success: oklch(55% 0.2 150);
    --success-subtle: oklch(35% 0.15 150 / 0.2);
    --warning: oklch(55% 0.2 85);
    --warning-subtle: oklch(35% 0.15 85 / 0.2);
    --info: oklch(55% 0.15 250);
    --info-subtle: oklch(35% 0.15 250 / 0.2);
    --border: oklch(25% 0 0);
    --border-light: oklch(22% 0 0);
    --radius: 8px;
    --radius-sm: 6px;
    --radius-lg: 12px;
    --font: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 32px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 48px rgba(0,0,0,0.5);
    color-scheme: dark;
}

[data-theme="light"] {
    --bg: #f5f2ec;
    --bg-surface: #ede9e0;
    --bg-elevated: #e5e0d6;
    --bg-hover: #ddd8cc;
    --bg-active: #d5cfc2;
    --text: #1a1412;
    --text-secondary: #6b6560;
    --text-muted: #958e88;
    --accent: oklch(45% 0.18 250);
    --accent-hover: oklch(50% 0.2 250);
    --accent-subtle: oklch(55% 0.15 250 / 0.12);
    --danger-subtle: oklch(60% 0.15 30 / 0.15);
    --success-subtle: oklch(65% 0.13 150 / 0.25);
    --warning-subtle: oklch(65% 0.13 85 / 0.25);
    --info-subtle: oklch(65% 0.13 250 / 0.2);
    --border: oklch(80% 0.01 60);
    --border-light: oklch(85% 0.01 60);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 8px 32px rgba(0,0,0,0.12);
    --shadow-lg: 0 12px 48px rgba(0,0,0,0.15);
    color-scheme: light;
}

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

html, body { height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    background-image:
        radial-gradient(ellipse 60% 80% at 10% 20%, oklch(30% 0.12 250 / 0.4) 0%, transparent 55%),
        radial-gradient(ellipse 70% 60% at 90% 80%, oklch(20% 0.1 30 / 0.3) 0%, transparent 55%);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
    min-height: 100dvh;
    overflow-x: hidden;
}

body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 150;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
}

[data-theme="light"] body {
    background-image:
        radial-gradient(ellipse 60% 80% at 10% 20%, oklch(70% 0.08 250 / 0.25) 0%, transparent 55%),
        radial-gradient(ellipse 70% 60% at 90% 80%, oklch(75% 0.06 30 / 0.2) 0%, transparent 55%);
}

a { color: var(--accent); text-decoration: none; transition: color 0.15s var(--ease-out); }
a:hover { color: var(--accent-hover); }

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

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-active); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Nav ── */
nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 48px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.nav-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    letter-spacing: -0.01em;
    white-space: nowrap;
    flex-shrink: 0;
}

.nav-links {
    display: flex;
    gap: 2px;
    align-items: center;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.nav-links::-webkit-scrollbar { display: none; }

.nav-links a {
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s var(--ease-out);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    min-height: 36px;
}

.nav-links a:hover, .nav-links a.active {
    background: var(--bg-hover);
    color: var(--text);
    text-decoration: none;
}

.nav-links a.active { background: var(--accent-subtle); color: var(--accent); }

.nav-links .icon-svg { width: 16px; height: 16px; flex-shrink: 0; }

.theme-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin-left: 4px;
    transition: all 0.15s var(--ease-out);
}
.theme-toggle:hover { background: var(--bg-hover); color: var(--text); }
.theme-toggle .icon-svg { width: 18px; height: 18px; }

/* ── Auth ── */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 20px;
}

.auth-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
}

.auth-card h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { color: var(--text-secondary); margin-bottom: 20px; font-size: 13px; }

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 3px;
}

.auth-tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font);
    transition: all 0.15s var(--ease-out);
}
.auth-tab.active { background: var(--bg); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }

/* ── Forms ── */
.form-group { margin-bottom: 14px; text-align: left; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; letter-spacing: 0.3px; cursor: pointer; }

input, select, textarea {
    width: 100%;
    min-height: 40px;
    padding: 9px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.15s var(--ease-out);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }
input:disabled, select:disabled, textarea:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg { padding: 8px 12px; border-radius: var(--radius-sm); background: var(--danger-subtle); color: var(--danger); border: 1px solid var(--danger); margin-bottom: 12px; font-size: 13px; }
.success-msg { padding: 8px 12px; border-radius: var(--radius-sm); background: var(--success-subtle); color: var(--success); border: 1px solid var(--success); margin-bottom: 12px; font-size: 13px; }
.hidden { display: none !important; }

button, .btn {
    min-height: 36px;
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.15s var(--ease-out);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:active:not(:disabled) { transform: scale(0.97); }

.btn-primary {
    background: var(--accent);
    color: #fff;
    width: auto;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.auth-card button[type="submit"], #account-save-btn { width: 100%; }

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-block {
  width: 100%;
  margin-top: 12px;
}
.btn-secondary:hover { background: var(--bg-active); }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid transparent;
}
.btn-danger:hover { background: var(--danger-subtle); border-color: var(--danger); }

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s var(--ease-out);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn .icon-svg { width: 18px; height: 18px; }

.small-btn {
    padding: 5px 10px;
    min-height: 32px;
    font-size: 12px;
    font-weight: 500;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font);
    transition: all 0.15s var(--ease-out);
}
.small-btn:hover { background: var(--bg-hover); color: var(--text); }
.small-btn:active { transform: scale(0.97); }
.small-btn .icon-svg { width: 18px; height: 18px; flex-shrink: 0; }

.help-text { display: block; font-size: 11px; color: var(--text-muted); margin-top: 3px; line-height: 1.5; }
.help-text code { font-size: 11px; }
.danger-hint { color: var(--danger); font-weight: 600; }

/* ── Page Layout ── */
.page {
    max-width: 800px;
    margin: 68px auto 0;
    padding: 0 20px 40px;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 24px;
}

/* ── Cards ── */
.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.card h2 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.card .card-subtitle { color: var(--text-secondary); font-size: 12px; margin-bottom: 16px; }

/* ── List items ── */
.list-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    transition: border-color 0.15s var(--ease-out);
}
.list-item:hover { border-color: var(--bg-active); }
.list-item .toggle-switch { margin-top: 2px; }

.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; font-size: 14px; color: var(--text); overflow-wrap: anywhere; }
.list-item-meta { font-size: 12px; color: var(--text-secondary); margin-top: 3px; display: flex; gap: 12px; flex-wrap: wrap; }
.list-item-meta span { display: inline-flex; align-items: center; gap: 4px; overflow-wrap: anywhere; }

.list-item-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
    align-items: center;
    margin-left: auto;
    padding-left: 8px;
}
.list-item-actions .icon-btn {
    width: 32px;
    height: 32px;
    padding: 0;
}
.list-item-actions .icon-btn .icon-svg { width: 16px; height: 16px; }

/* ── Stat Grid ── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 16px;
    text-align: center;
    min-width: 0;
}

.stat-card .stat-value {
    font-size: clamp(24px, 3vw, 28px);
    font-weight: 700;
    color: var(--accent);
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Badges ── */
.badge, .list-item-badge, .key-indicator {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 10px;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
}
.badge-success, .list-item-badge.success, .key-indicator.configured { background: var(--success-subtle); color: var(--success); }
.badge-danger, .list-item-badge.danger, .key-indicator.missing { background: var(--danger-subtle); color: var(--danger); }
.badge-muted, .list-item-badge.muted { background: var(--bg-hover); color: var(--text-muted); }
.badge-warning, .list-item-badge.warning { background: var(--warning-subtle); color: var(--warning); }
.badge-info { background: var(--info-subtle); color: var(--info); }

/* ── Modals ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: calc(100dvh - 40px);
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

.modal-actions button { width: auto; }

/* ── Chat Layout ── */
.chat-layout {
    position: fixed;
    top: 48px;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    overflow: hidden;
}

.sidebar {
    width: 280px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: margin-left 0.25s var(--ease-out), opacity 0.25s var(--ease-out);
}
.sidebar.collapsed { margin-left: -280px; opacity: 0; pointer-events: none; }

.sidebar-header { padding: 12px; }

.sidebar-toggle {
    position: absolute;
    bottom: 12px;
    left: calc(280px + 12px);
    z-index: 20;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    min-height: 32px;
    padding: 0;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: left 0.25s var(--ease-out), top 0.25s var(--ease-out), background 0.15s var(--ease-out);
}
.sidebar.collapsed ~ .sidebar-toggle { left: 8px; }
.sidebar-toggle:hover { background: var(--bg-hover); color: var(--text); }

/* Keep the sidebar toggle clear of the chat input row (upload button) */
@media (min-width: 769px) {
    .sidebar:not(.collapsed) ~ .chat-main .chat-input-area,
    .sidebar.collapsed ~ .chat-main .chat-input-area { padding-left: 52px; }
}

.conversation-list { flex: 1; overflow-y: auto; padding: 8px; }

.conv-item {
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all 0.15s var(--ease-out);
    margin-bottom: 2px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.conv-item:hover { background: var(--bg-hover); color: var(--text); }
.conv-item.active { background: var(--accent-subtle); color: var(--accent); }
.conv-item .conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.conv-item .conv-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.conv-item .conv-del-btn {
    opacity: 0;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    background: none;
    border: none;
    font-size: 14px;
    line-height: 1;
    min-height: 0;
    border-radius: var(--radius-sm);
    transition: opacity 0.15s var(--ease-out), color 0.15s var(--ease-out);
}
.conv-item:hover .conv-del-btn { opacity: 1; }
.conv-item .conv-del-btn:hover { color: var(--danger); }

.conv-group { margin-bottom: 4px; }
.conv-group-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 8px 12px 4px;
}

.conv-empty {
    padding: 24px 12px;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-msg { text-align: center; padding: 60px 20px; color: var(--text-secondary); }
.welcome-msg p { font-size: 15px; }
.welcome-msg .hint { font-size: 12px; margin-top: 8px; color: var(--text-muted); }

.setup-hint {
    align-self: center;
    text-align: center;
    padding: 8px 16px;
    font-size: 12px;
    max-width: 90%;
}

.msg { max-width: 80%; padding: 12px 16px; border-radius: var(--radius-lg); font-size: 13px; line-height: 1.6; word-wrap: break-word; overflow-wrap: anywhere; min-width: 0; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.assistant { align-self: flex-start; background: var(--bg-elevated); color: var(--text); }
.msg .role-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; opacity: 0.7; }
.msg pre {
    background: var(--bg);
    border: 1px solid var(--border-light);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-size: 12px;
    margin: 8px 0;
    max-width: 100%;
    line-height: 1.5;
}
.msg code { font-size: 12px; background: var(--bg-hover); padding: 1px 4px; border-radius: 3px; }

.chat-input-area {
    padding: 12px 16px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
}

.file-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 4px 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    color: var(--text);
}

.file-chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}

.file-chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    min-height: 18px;
    flex-shrink: 0;
}

.file-chip-remove:hover {
    background: var(--bg-hover);
    color: var(--danger);
}

#chat-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

#message-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text);
    font-size: 13px;
    outline: none;
    min-height: 40px;
}
#message-input:focus { border-color: var(--accent); }

#send-btn {
    padding: 8px 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    font-family: var(--font);
    width: 40px;
    height: 40px;
    white-space: nowrap;
    flex-shrink: 0;
}
#send-btn .icon-svg { width: 18px; height: 18px; }
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: 0.5; }

.clear-chat-btn {
    padding: 8px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font);
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}
.clear-chat-btn .icon-svg { width: 18px; height: 18px; }
.clear-chat-btn:hover { background: var(--bg-hover); color: var(--danger); border-color: var(--danger); }

/* ── Toggle Switch ── */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}

.toggle-row label { font-size: 13px; color: var(--text); cursor: pointer; }

.toggle-switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-hover);
    border-radius: 22px;
    transition: background 0.2s var(--ease-out);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: transform 0.2s var(--ease-out), background 0.2s var(--ease-out);
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); background: #fff; }

/* ── Progress Bar ── */
.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--bg-hover);
    border-radius: 2px;
    overflow: hidden;
    margin: 8px 0;
}
.progress-bar .progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s var(--ease-out);
}

/* ── Quick Actions ── */
.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.quick-actions a, .quick-actions button { width: auto; display: inline-flex; align-items: center; gap: 6px; }

/* ── Loading / Empty / Error states ── */
.loading-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
    font-size: 13px;
}

.empty-state {
    text-align: center;
    padding: 32px 20px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.6;
}
.empty-state a { color: var(--accent); }

.error-state {
    text-align: center;
    padding: 32px 20px;
    color: var(--danger);
    font-size: 13px;
}

.list-group > div {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.list-group > div:last-child { border-bottom: none; }
.list-group a { overflow-wrap: anywhere; min-width: 0; }

/* ── Responsive ── */
@media (max-width: 1024px) {
    .page { max-width: 100%; }
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
}

@media (max-width: 768px) {
    .sidebar { width: min(280px, 82vw); position: fixed; left: 0; top: 48px; bottom: 0; z-index: 50; box-shadow: var(--shadow-md); }
    .sidebar.collapsed { margin-left: calc(min(280px, 82vw) * -1); }
    /* Touch-friendly toggle pinned under the nav, top-left of the chat area.
       Never overlaps the input row, so no input padding hack is needed. */
    .sidebar-toggle {
        top: 12px;
        bottom: auto;
        left: 12px;
        width: 44px;
        height: 44px;
        min-height: 44px;
        padding: 0;
        font-size: 18px;
        border-radius: 14px;
        z-index: 60;
    }
    .sidebar:not(.collapsed) ~ .sidebar-toggle { left: calc(min(280px, 82vw) + 10px); }
    .msg { max-width: 90%; }
    nav { padding: 0 12px; }
    .nav-links a { padding: 6px 8px; font-size: 12px; }
    .nav-links a span { display: none; }
    .page { padding: 0 12px 40px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .modal-overlay { padding: 12px; }
    .modal { max-height: calc(100dvh - 24px); padding: 20px; }
    .chat-messages { padding: 16px; }
    .welcome-msg { padding: 40px 16px; }
}

@media (max-width: 560px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .list-item { flex-wrap: wrap; }
    .list-item-actions { margin-left: 0; padding-left: 0; width: 100%; justify-content: flex-end; }
    .list-item-badge { order: 3; }
    .modal-actions { flex-direction: column-reverse; }
    .modal-actions button { width: 100%; }
    .profile-header { align-items: flex-start; }
    .profile-actions { width: 100%; justify-content: flex-end; }
    .card { padding: 16px; }
    .auth-card { padding: 24px 20px; }
    #chat-form { flex-wrap: wrap; }
    #message-input { flex: 1 1 100%; order: 1; }
    #file-btn { order: 2; }
    #clear-btn { order: 3; }
    #send-btn { order: 4; }
}

@media (max-width: 360px) {
    .stat-grid { grid-template-columns: 1fr; }
    .nav-links a { padding: 6px 6px; }
    .theme-toggle { width: 28px; height: 28px; }
}

/* ── Legacy report card classes (used in tasks.html JS) ── */
.profile-card {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.profile-card:last-child { border-bottom: none; }
.profile-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.profile-name { font-weight: 600; font-size: 13px; color: var(--text); flex: 1; min-width: 0; }
.profile-model { font-size: 11px; color: var(--text-muted); }
.profile-detail { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.profile-actions { display: flex; gap: 4px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.key-indicator { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 500; }
.key-indicator.configured { background: var(--success-subtle); color: var(--success); }
.key-indicator.missing { background: var(--danger-subtle); color: var(--danger); }
.danger-btn {
    padding: 4px 8px;
    font-size: 11px;
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font);
    transition: all 0.15s var(--ease-out);
}
.danger-btn:hover { background: var(--danger-subtle); border-color: var(--danger); }

/* ── Report rendered content ── */
.report-rendered { font-size: 13px; line-height: 1.7; color: var(--text); max-height: 60vh; overflow-y: auto; min-width: 0; }

/* Chat messages reuse the report renderer but must not get the modal-style
   internal scroll */
.msg .report-rendered { max-height: none; overflow: visible; font-size: 13px; }
.msg:has(.report-rendered) { max-width: min(92%, 840px); }
.report-rendered .title-level-1 { font-size: 16px; font-weight: 700; margin: 16px 0 8px; color: var(--text); }
.report-rendered .title-level-2 { font-size: 14px; font-weight: 600; margin: 12px 0 6px; color: var(--text); }
.report-rendered .chart-inline-wrapper { margin: 12px 0; max-width: 100%; overflow-x: auto; }
.report-rendered .chart-inline-wrapper canvas { max-width: 100%; }
.report-rendered .data-table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 400px; }
.report-rendered .data-table th { background: var(--bg-hover); padding: 6px 10px; text-align: left; border: 1px solid var(--border); font-weight: 600; color: var(--text); }
.report-rendered .data-table td { padding: 5px 10px; border: 1px solid var(--border); color: var(--text); overflow-wrap: anywhere; }
.report-rendered .callout-box { border-left: 3px solid var(--accent); padding: 8px 12px; margin: 8px 0; background: var(--bg-hover); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.report-rendered .label-line { padding: 2px 0; color: var(--text-secondary); }
.report-rendered .chart-empty { padding: 20px; text-align: center; color: var(--text-muted); font-style: italic; }
.report-rendered .section-divider { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.report-rendered .table-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; }

.modal-lg { max-width: 640px; width: 100%; }

/* ── Confirm Dialog ── */
.confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: confirm-fade 0.18s var(--ease-out);
}
.confirm-overlay.hidden { display: none; }

.confirm-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px 24px 24px;
    width: min(400px, 100%);
    box-shadow: var(--shadow-lg);
    text-align: center;
    animation: confirm-pop 0.22s var(--ease-out);
}

.confirm-icon {
    width: 52px;
    height: 52px;
    margin: 0 auto 14px;
    border-radius: 50%;
    background: var(--danger-subtle);
    color: var(--danger);
    display: flex;
    align-items: center;
    justify-content: center;
}
.confirm-icon .icon-svg { width: 24px; height: 24px; }

.confirm-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}
.confirm-message {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 20px;
    overflow-wrap: anywhere;
}

.confirm-actions { display: flex; gap: 10px; justify-content: center; }
.confirm-actions button {
    flex: 1;
    padding: 10px 16px;
    min-height: 44px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s var(--ease-out);
}
.confirm-cancel {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.confirm-cancel:hover { background: var(--bg-hover); color: var(--text); }
.confirm-delete {
    background: var(--danger);
    border: 1px solid var(--danger);
    color: #fff;
}
.confirm-delete:hover { background: var(--danger); filter: brightness(1.15); }
.confirm-delete:focus-visible { outline: 2px solid var(--danger); outline-offset: 2px; }

@keyframes confirm-fade { from { opacity: 0; } }
@keyframes confirm-pop { from { opacity: 0; transform: scale(0.92) translateY(8px); } }
