/* ============================================================================
   DoxAI — Dark theme with red accent.
   Award-winning means: restraint, hierarchy, motion that respects intent,
   contrast that reads at a glance, focus rings that never disappear.
   ============================================================================ */

:root,
[data-theme="dark"] {
    /* Surfaces: layered blacks, never pure #000 (kills contrast on OLED).      */
    --surface-0: #0a0a0c;
    --surface-1: #111116;
    --surface-2: #16161d;
    --surface-3: #1c1c25;
    --surface-4: #25252f;
    --hairline:  #2a2a35;

    /* Type. Inter or system; we let the OS pick its best UI font.              */
    --text-primary:   #f3f3f5;
    --text-secondary: #a8a8b3;
    --text-tertiary:  #6b6b78;
    --text-disabled:  #4a4a55;

    /* Accent — a red that's saturated but not screaming.                       */
    --accent-50:  #fff1f2;
    --accent-200: #fecdd3;
    --accent-400: #fb7185;
    --accent-500: #ef4444;   /* primary */
    --accent-600: #dc2626;   /* hover   */
    --accent-700: #b91c1c;   /* active  */
    --accent-rgb: 239, 68, 68;          /* used for theme-aware rgba(...) */
    --accent-glow: rgba(var(--accent-rgb), .35);

    --success: #22c55e;
    --success-rgb: 34, 197, 94;
    --warning: #f59e0b;
    --warning-rgb: 245, 158, 11;
    --danger:  #ef4444;
    --danger-rgb: 239, 68, 68;

    /* Episodic-memory citation chip — a dark yellow that reads apart from the
       accent-colored document chips. --mem-fg is the text/foreground; --mem-rgb
       drives the translucent tint + border. Foreground is lifted on this dark
       theme so it stays legible; the light theme overrides it to a deeper yellow. */
    --mem-fg: #d9a514;
    --mem-rgb: 202, 138, 4;

    /* Tinted accent overlays — used by hover states and bubble bgs. */
    --accent-tint-04: rgba(var(--accent-rgb), .04);
    --accent-tint-06: rgba(var(--accent-rgb), .06);
    --accent-tint-12: rgba(var(--accent-rgb), .12);
    --accent-tint-16: rgba(var(--accent-rgb), .16);
    --accent-tint-32: rgba(var(--accent-rgb), .32);

    --body-bg: var(--surface-0);
    --body-pattern: none;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 22px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 6px 18px rgba(0,0,0,.45), 0 2px 4px rgba(0,0,0,.3);
    --shadow-lg: 0 18px 48px rgba(0,0,0,.55), 0 4px 12px rgba(0,0,0,.35);
    --shadow-accent: 0 0 0 3px var(--accent-glow);

    --ease-out: cubic-bezier(.2,.8,.2,1);
    --ease-in-out: cubic-bezier(.65,.05,.36,1);

    --sidebar-w: 272px;

    --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI",
                 Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

/* =========================================================================
   LIGHT THEME — toggled via <html data-theme="light">.
   The accent shifts from red to blue and the surfaces invert. Body picks up
   a soft dot-grid pattern in the accent color so the page still has texture
   instead of feeling like a blank canvas.
   ========================================================================= */
[data-theme="light"] {
    --surface-0: #ffffff;
    --surface-1: #fbfcfe;
    --surface-2: #f4f6fa;
    --surface-3: #eaeef4;
    --surface-4: #dde3ec;
    --hairline:  #e2e8f0;

    --text-primary:   #0f172a;
    --text-secondary: #475569;
    --text-tertiary:  #94a3b8;
    --text-disabled:  #cbd5e1;

    /* Blue accent — saturated, professional, distinct from typical link blue. */
    --accent-50:  #eff6ff;
    --accent-200: #bfdbfe;
    --accent-400: #60a5fa;
    --accent-500: #3b82f6;
    --accent-600: #2563eb;
    --accent-700: #1d4ed8;
    --accent-rgb: 59, 130, 246;
    --accent-glow: rgba(var(--accent-rgb), .25);

    --success: #16a34a;
    --success-rgb: 22, 163, 74;
    --warning: #d97706;
    --warning-rgb: 217, 119, 6;
    --danger:  #dc2626;
    --danger-rgb: 220, 38, 38;

    /* Deeper dark yellow for the memory chip on light surfaces (yellow-700). */
    --mem-fg: #a16207;
    --mem-rgb: 202, 138, 4;

    /* Lighter shadows on light surfaces so cards lift without bruising. */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow-md: 0 6px 18px rgba(15, 23, 42, .08), 0 2px 4px rgba(15, 23, 42, .04);
    --shadow-lg: 0 18px 48px rgba(15, 23, 42, .14), 0 4px 12px rgba(15, 23, 42, .06);

    /* Soft blue dot grid behind the whole app — every 24px, tiny and quiet. */
    --body-bg: #f7f9fc;
    --body-pattern:
        radial-gradient(circle at 1px 1px, rgba(var(--accent-rgb), .12) 1px, transparent 1.5px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    height: 100%;
    /* var(--body-pattern) sits ON TOP of var(--body-bg). On dark theme the
       pattern is `none` so only the solid color shows; on light theme the
       layered radial-gradient paints the dot grid. background-attachment
       fixed keeps the pattern stable while the page scrolls. */
    background: var(--body-pattern), var(--body-bg);
    background-size: 24px 24px, auto;
    background-attachment: fixed;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14.5px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color .2s var(--ease-out), color .2s var(--ease-out);
}

a { color: var(--accent-400); text-decoration: none; }
    a:hover {
        color: var(--accent-500);
        text-decoration: none;
        cursor: pointer;
    }
.shadow-hover:hover {
    -webkit-box-shadow: 5px 5px 44px 5px rgba(0,0,0,0.26);
    box-shadow: 5px 5px 44px 5px rgba(0,0,0,0.26);
}

h1, h2, h3, h4 { color: var(--text-primary); margin: 0 0 .6em; letter-spacing: -0.01em; font-weight: 600; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }

::selection { background: var(--accent-500); color: white; }

/* --- Focus ring -------------------------------------------------------- */
:focus-visible {
    outline: none;
    box-shadow: var(--shadow-accent);
    border-color: var(--accent-500) !important;
}

/* --- App shell --------------------------------------------------------- */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

/* The mobile top bar is hidden on desktop. */
.topbar { display: none; }
.drawer-overlay { display: none; }

.sidebar {
    background: linear-gradient(180deg, var(--surface-1) 0%, var(--surface-0) 100%);
    border-right: 1px solid var(--hairline);
    display: flex;
    flex-direction: column;
    padding: 22px 14px 18px;
    position: sticky; top: 0; height: 100vh;
    z-index: 30;
    /* Long nav lists (admins see a second nav block) must never get clipped:
       let the sidebar scroll its own overflow instead of pushing the footer
       off-screen. overscroll-behavior keeps the scroll from chaining to the
       page behind it. */
    overflow-y: auto;
    overscroll-behavior: contain;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 22px; }
.brand-mark {
    width: 28px; height: 28px; border-radius: 8px;
    background: linear-gradient(135deg, var(--accent-500), var(--accent-700));
    box-shadow: 0 4px 12px rgba(var(--accent-rgb), .4);
    position: relative;
}
.brand-mark::after {
    content: ""; position: absolute; inset: 5px;
    background: var(--surface-0); border-radius: 4px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand-tagline { color: var(--text-tertiary); font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; }

/* Workspace switcher */
.ws-switcher { position: relative; margin: 4px 0 18px; }
.ws-switcher-button {
    width: 100%; display: flex; justify-content: space-between; align-items: center;
    background: var(--surface-2); border: 1px solid var(--hairline);
    border-radius: var(--radius-md); padding: 10px 12px;
    color: var(--text-primary); cursor: pointer; transition: border-color .15s var(--ease-out), background .15s var(--ease-out);
    text-align: left;
}
.ws-switcher-button:hover { border-color: var(--accent-500); background: var(--surface-3); }
.ws-label { display: block; font-size: .67rem; color: var(--text-tertiary); letter-spacing: .08em; text-transform: uppercase; }
.ws-name { display: block; font-weight: 600; }
.ws-caret { color: var(--text-secondary); }
.ws-menu {
    position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 10;
    background: var(--surface-2); border: 1px solid var(--hairline);
    border-radius: var(--radius-md); padding: 6px; box-shadow: var(--shadow-md);
    max-height: 320px; overflow-y: auto;
}
.ws-menu-item {
    display: block; width: 100%; text-align: left;
    background: transparent; border: 0; color: var(--text-primary);
    padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer;
    transition: background .12s var(--ease-out);
}
.ws-menu-item:hover { background: var(--surface-3); }
.ws-menu-item.active { background: var(--accent-tint-12); color: var(--accent-400); }
.ws-menu-name { display: block; font-weight: 500; }
.ws-menu-meta { display: block; font-size: .72rem; color: var(--text-tertiary); }
.ws-menu-divider { height: 1px; background: var(--hairline); margin: 4px 0; }
/* Type-to-filter box at the top of the switcher menu (shown for long lists). */
.ws-menu-search {
    display: block; width: 100%; box-sizing: border-box;
    background: var(--surface-1); color: var(--text-primary);
    border: 1px solid var(--hairline); border-radius: var(--radius-sm);
    padding: 7px 10px; margin-bottom: 6px; font-size: .85rem;
}
.ws-menu-search:focus { outline: none; border-color: var(--accent-500); }
.ws-menu-empty {
    padding: 10px; font-size: .8rem; color: var(--text-tertiary); text-align: center;
}

/* Nav */
.nav-section { margin: 18px 8px 6px; font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--text-tertiary); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    color: var(--text-secondary); padding: 9px 12px;
    border-radius: var(--radius-md); transition: background .14s var(--ease-out), color .14s var(--ease-out);
    font-weight: 500; position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text-primary); text-decoration: none; }
.nav-item.active {
    background: linear-gradient(90deg, var(--accent-tint-16), rgba(var(--accent-rgb), 0));
    color: var(--text-primary);
}
.nav-item.active::before {
    content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
    background: var(--accent-500); border-radius: 0 3px 3px 0;
}
.nav-item .icon { font-size: 1rem; opacity: .85; width: 20px; text-align: center; }

.sidebar-footer {
    margin-top: auto; padding-top: 16px; border-top: 1px solid var(--hairline);
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    color: var(--text-tertiary); font-size: .82rem;
}
.user-mail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }

.sidebar-footer-row {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; gap: 8px; margin-bottom: 6px;
}

/* --- Theme toggle ------------------------------------------------------ */
.theme-toggle {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--surface-2); color: var(--text-secondary);
    border: 1px solid var(--hairline); border-radius: 999px;
    padding: 6px 12px; cursor: pointer;
    font: inherit; font-size: .82rem; font-weight: 500;
    transition: background .15s var(--ease-out), color .15s var(--ease-out),
                border-color .15s var(--ease-out), transform .08s var(--ease-out);
}
.theme-toggle:hover {
    background: var(--surface-3); color: var(--text-primary);
    border-color: var(--accent-500);
}
.theme-toggle:active { transform: scale(.96); }
.theme-toggle-icon { display: inline-flex; line-height: 0; color: var(--accent-500); }
.theme-toggle-label { display: inline-block; }

.topbar-trailing { display: flex; align-items: center; gap: 6px; }
.topbar-trailing .theme-toggle {
    width: 36px; height: 36px; padding: 0;
    border-radius: var(--radius-md);
    justify-content: center;
}
.topbar-trailing .theme-toggle-label { display: none; }

/* In the sidebar footer the toggle is icon-only too — keep the row tidy. */
.sidebar-footer-row .theme-toggle {
    width: 32px; height: 32px; padding: 0;
    border-radius: 50%;
    justify-content: center;
}
.sidebar-footer-row .theme-toggle-label { display: none; }

/* Main content.
   `min-width: 0` is the magic incantation that lets a CSS-grid child shrink
   below its intrinsic content width — without it, an inner table's natural
   width stretches the cell and `overflow-x: auto` on `.table-wrap` never
   engages because there's nothing for it to clip against. */
.content {
    padding: 28px clamp(20px, 4vw, 56px);
    max-width: 1400px;
    width: 100%;
    min-width: 0;
}

/* The chat surface is a workspace view, not a reading column — on large screens
   let it use the full content width instead of the 1400px cap that suits the
   document/admin reading pages. :has() scopes this to the chats route only. */
.content:has(.chat-shell) {
    max-width: none;
    padding-left: clamp(16px, 2vw, 32px);
    padding-right: clamp(16px, 2vw, 32px);
}

/* --- Buttons ----------------------------------------------------------- */
.btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 16px; border-radius: var(--radius-md);
    font-weight: 600; font-size: .9rem; cursor: pointer;
    border: 1px solid transparent;
    transition: transform .08s var(--ease-out), background .15s var(--ease-out),
                border-color .15s var(--ease-out), box-shadow .15s var(--ease-out);
    text-decoration: none;
}
.btn-primary {
    background: var(--accent-500); color: white;
    box-shadow: 0 6px 14px var(--accent-tint-32);
}
.btn-primary:hover { background: var(--accent-600); transform: translateY(-1px); text-decoration: none; }
.btn-primary:active { background: var(--accent-700); transform: translateY(0); }

.btn-secondary { background: var(--surface-3); color: var(--text-primary); border-color: var(--hairline); }
.btn-secondary:hover { background: var(--surface-4); border-color: var(--accent-500); text-decoration: none; }

.btn-danger { background: transparent; color: var(--danger); border-color: rgba(var(--danger-rgb), .4); }
.btn-danger:hover { background: rgba(var(--danger-rgb), .1); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text-primary); text-decoration: none; }

.btn-retry {
    background: transparent;
    color: #C7DC6A;
    border-color: #DC9C6A;
}

.btn-retry:hover {
    background: #DCB86A;
}


.btn-link {
    background: transparent; border: 0; color: var(--accent-400);
    padding: 0; cursor: pointer; font: inherit;
}
.btn-link:hover { color: var(--accent-500); text-decoration: underline; }

/* --- Forms -------------------------------------------------------------
   Every control gets the dark-with-red-accent treatment. We cover every
   <input type="..."> the HTML spec defines, custom-style the controls
   browsers render inconsistently (checkbox, radio, select, file, range),
   and explicitly invert the date-picker indicator so it's visible on dark.
   ----------------------------------------------------------------------- */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group label { font-size: .82rem; color: var(--text-secondary); font-weight: 500; }

/* Text-like inputs and textarea/select. Listing every text-y type explicitly
   beats `input:not([type=checkbox])...` because selector specificity stays
   predictable and IDE autocomplete doesn't lie to you.
   `input:not([type])` catches bare <input> elements (Blazor's @bind without
   type=...) which browsers treat as text but CSS [type=text] does not match. */
.form-control,
input:not([type]),
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=search], input[type=tel], input[type=url],
input[type=date], input[type=time], input[type=datetime-local],
input[type=month], input[type=week],
textarea, select {
    width: 100%; padding: 10px 12px;
    background: var(--surface-2); color: var(--text-primary);
    border: 1px solid var(--hairline); border-radius: var(--radius-md);
    font: inherit;
    transition: border-color .15s var(--ease-out), box-shadow .15s var(--ease-out),
                background .15s var(--ease-out);
}
.form-control:hover,
input:not([type]):hover,
input[type=text]:hover, input[type=email]:hover, input[type=password]:hover,
input[type=number]:hover, input[type=search]:hover, input[type=tel]:hover,
input[type=url]:hover, input[type=date]:hover, input[type=time]:hover,
textarea:hover, select:hover { border-color: var(--surface-4); }

.form-control:focus, input:focus, textarea:focus, select:focus {
    outline: none; border-color: var(--accent-500); box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder, textarea::placeholder { color: var(--text-tertiary); }
.help { font-size: .78rem; color: var(--text-tertiary); }
.form-error { color: var(--danger); font-size: .82rem; }

/* Textarea-specific tweaks: minimum height, vertical-only resize. */
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }

/* --- Custom select chevron --------------------------------------------
   The native arrow is OS-dependent and ugly on dark; we draw our own. */
select {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    padding-right: 36px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='%23a8a8b3' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M4 6.5 L8 10.5 L12 6.5'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px;
    cursor: pointer;
}
select:focus {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='%23ef4444' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M4 6.5 L8 10.5 L12 6.5'/></svg>");
}
/* Native option lists honor the OS dark mode automatically in most browsers,
   but Firefox needs a hint. */
select option { background: var(--surface-2); color: var(--text-primary); }

/* --- Checkboxes & radios ----------------------------------------------
   Reset the native rendering and draw a 18px square / circle that fills
   with accent-red when checked. The check mark is an embedded SVG so it
   works in every browser and respects the surrounding font color. */
input[type=checkbox], input[type=radio] {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    width: 18px; height: 18px;
    margin: 0; padding: 0;
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    cursor: pointer;
    transition: background .12s var(--ease-out), border-color .12s var(--ease-out);
    flex-shrink: 0; vertical-align: middle;
    display: inline-block;
    position: relative;
}
input[type=checkbox] { border-radius: 4px; }
input[type=radio]    { border-radius: 50%; }

input[type=checkbox]:hover, input[type=radio]:hover { border-color: var(--accent-500); }

input[type=checkbox]:checked, input[type=radio]:checked {
    background-color: var(--accent-500);
    border-color: var(--accent-500);
}
input[type=checkbox]:checked {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round' d='M3.5 8.5 L6.7 11.5 L12.5 5'/></svg>");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 14px;
}
input[type=radio]:checked::after {
    content: ""; position: absolute;
    inset: 4px; border-radius: 50%; background: white;
}

input[type=checkbox]:focus-visible, input[type=radio]:focus-visible {
    box-shadow: 0 0 0 3px var(--accent-glow);
    outline: none;
}

input[type=checkbox]:indeterminate {
    background: var(--accent-500); border-color: var(--accent-500);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' d='M4 8 L12 8'/></svg>");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 14px;
}

/* --- File input --------------------------------------------------------
   Styling <input type="file"> directly is limited; the file-selector-button
   pseudo-element gives us the inner button. */
input[type=file] {
    width: 100%; padding: 0;
    background: var(--surface-2); color: var(--text-secondary);
    border: 1px solid var(--hairline); border-radius: var(--radius-md);
    font: inherit; cursor: pointer; overflow: hidden;
}
input[type=file]::file-selector-button {
    background: var(--accent-500); color: white; font: inherit; font-weight: 600;
    border: 0; padding: 10px 16px; margin-right: 12px;
    cursor: pointer;
    transition: background .12s var(--ease-out);
}
input[type=file]::file-selector-button:hover { background: var(--accent-600); }

/* --- Range slider ------------------------------------------------------
   Tracks need WebKit + Firefox prefixes — no shorthand exists yet. */
input[type=range] {
    width: 100%;
    appearance: none; -webkit-appearance: none;
    height: 22px; /* hit area */
    background: transparent; cursor: pointer;
    padding: 0;
}
input[type=range]::-webkit-slider-runnable-track {
    height: 4px; border-radius: 999px;
    background: var(--surface-3);
}
input[type=range]::-moz-range-track {
    height: 4px; border-radius: 999px;
    background: var(--surface-3);
}
input[type=range]::-webkit-slider-thumb {
    appearance: none; -webkit-appearance: none;
    width: 18px; height: 18px;
    margin-top: -7px; /* center on the 4px track */
    background: var(--accent-500);
    border: 2px solid var(--surface-0);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,.4);
    transition: transform .1s var(--ease-out);
}
input[type=range]::-moz-range-thumb {
    width: 18px; height: 18px;
    background: var(--accent-500);
    border: 2px solid var(--surface-0);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.1); }
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--accent-glow); }
input[type=range]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px var(--accent-glow); }

/* --- Color picker ------------------------------------------------------ */
input[type=color] {
    width: 48px; height: 38px;
    padding: 4px; cursor: pointer;
    background: var(--surface-2);
    border: 1px solid var(--hairline); border-radius: var(--radius-md);
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: 0; border-radius: var(--radius-sm); }

/* --- Date / time picker indicator -------------------------------------
   The native calendar/clock icon is dark-on-dark by default; invert it. */
input[type=date]::-webkit-calendar-picker-indicator,
input[type=time]::-webkit-calendar-picker-indicator,
input[type=datetime-local]::-webkit-calendar-picker-indicator,
input[type=month]::-webkit-calendar-picker-indicator,
input[type=week]::-webkit-calendar-picker-indicator {
    filter: invert(.7);
    cursor: pointer; opacity: .8;
    transition: opacity .12s var(--ease-out);
}
input[type=date]::-webkit-calendar-picker-indicator:hover,
input[type=time]::-webkit-calendar-picker-indicator:hover,
input[type=datetime-local]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* --- Number arrow buttons --------------------------------------------
   The default spinners on Chromium look painted-on. Tone them down so
   they only appear on hover/focus. */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    opacity: .35; cursor: pointer;
    transition: opacity .12s var(--ease-out);
}
input[type=number]:hover::-webkit-inner-spin-button,
input[type=number]:focus::-webkit-inner-spin-button { opacity: 1; }

/* --- Search input cancel button --------------------------------------- */
input[type=search]::-webkit-search-cancel-button {
    appearance: none; -webkit-appearance: none;
    width: 14px; height: 14px;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='%23a8a8b3' stroke-width='2' stroke-linecap='round' d='M4 4 L12 12 M12 4 L4 12'/></svg>") center/contain no-repeat;
    cursor: pointer;
}

/* --- Disabled state ---------------------------------------------------- */
input:disabled, textarea:disabled, select:disabled {
    opacity: .55; cursor: not-allowed;
    background: var(--surface-1);
}
input[type=checkbox]:disabled, input[type=radio]:disabled {
    background: var(--surface-3); border-color: var(--hairline);
}

/* --- Read-only --------------------------------------------------------- */
input:read-only, textarea:read-only {
    background: var(--surface-1); color: var(--text-secondary);
}

/* --- Autofill (Chromium) ---------------------------------------------
   Chromium paints autofilled fields a bright yellow that destroys the dark
   theme. The trick is an inset shadow that visually overrides the fill. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
textarea:-webkit-autofill {
    -webkit-text-fill-color: var(--text-primary);
    -webkit-box-shadow: 0 0 0 1000px var(--surface-2) inset;
    caret-color: var(--text-primary);
    transition: background-color 5000s ease-in-out 0s; /* defeat the default fill animation */
}

/* --- Switch (toggle) ---------------------------------------------------
   Optional: any checkbox with .switch becomes a pill toggle. */
input[type=checkbox].switch {
    width: 38px; height: 22px; border-radius: 999px;
    background: var(--surface-3); border-color: var(--hairline);
    position: relative; cursor: pointer;
    background-image: none;
}
input[type=checkbox].switch::after {
    content: ""; position: absolute;
    top: 2px; left: 2px; width: 16px; height: 16px;
    background: white; border-radius: 50%;
    transition: transform .18s var(--ease-out);
    box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
input[type=checkbox].switch:checked {
    background-color: var(--accent-500);
    background-image: none;
}
input[type=checkbox].switch:checked::after { transform: translateX(16px); }

/* --- Cards ------------------------------------------------------------- */
.card {
    background: var(--surface-1); border: 1px solid var(--hairline);
    border-radius: var(--radius-lg); padding: 20px;
    transition: border-color .15s var(--ease-out), transform .15s var(--ease-out);
}
.card.hover:hover { border-color: var(--accent-500); transform: translateY(-1px); }
.card-title { font-size: 1rem; font-weight: 600; margin: 0 0 4px; }
.card-meta { color: var(--text-tertiary); font-size: .82rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }

/* --- Workspace card: discrete corner-delete + action row -------------- */
.ws-card { position: relative; }

.ws-card-actions {
    margin-top: 14px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.ws-card-delete {
    position: absolute;
    top: 10px; right: 10px;
    width: 26px; height: 26px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-tertiary);
    font-size: 1.05rem; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s var(--ease-out), background .15s var(--ease-out),
                color .15s var(--ease-out), border-color .15s var(--ease-out);
}
.ws-card:hover .ws-card-delete,
.ws-card-delete:focus-visible { opacity: 1; }
.ws-card-delete:hover {
    background: rgba(var(--danger-rgb), .12);
    color: var(--danger);
    border-color: rgba(var(--danger-rgb), .25);
}

/* Touch devices have no meaningful hover — keep the delete affordance
   visible at low opacity so users know it's there, snap to full on press. */
@media (hover: none) {
    .ws-card-delete { opacity: .55; }
    .ws-card-delete:active { opacity: 1; }
}

/* --- Tables ------------------------------------------------------------ */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--hairline); }
.table th { font-weight: 600; color: var(--text-secondary); background: var(--surface-1); position: sticky; top: 0; }
.table tbody tr { transition: background .12s var(--ease-out); }
.table tbody tr:hover { background: var(--surface-2); }
.table-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* table-wrap turns any table into a horizontally-scrollable surface when its
   content is wider than the parent. The two key bits:
   - `width:100%; max-width:100%` so the wrap NEVER grows past its container.
   - `min-width:0` (defensively) plus `overflow-x:auto` to engage scrolling.
   - `min-width:max-content` on the inner <table> forces the table to keep its
     natural column widths, which produces overflow that the wrap clips and
     scrolls instead of letting columns squish into each other.
   The fade-edge indicator is omitted on purpose — the older `::after` +
   `position:sticky` + `float:right` shim could intercept the scroll itself
   on some mobile browsers. */
.table-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    /* A subtle mask creates the "more content offscreen" hint without using
       absolutely-positioned children that interfere with touch scrolling. */
    mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 18px), transparent 100%);
    -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 18px), transparent 100%);
}
.table-wrap > table { min-width: max-content; }

/* --- Badges ------------------------------------------------------------ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    font-size: .72rem;
    font-weight: 600;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-secondary);
    letter-spacing: .03em;
    cursor:none;
    -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Safari */
    -khtml-user-select: none; /* Konqueror HTML */
    -moz-user-select: none; /* Old versions of Firefox */
    -ms-user-select: none; /* Internet Explorer/Edge */
    user-select: none; /* Non-prefixed version, currently
                                  supported by Chrome, Edge, Opera and Firefox */
}
.badge.purple { background: #682363; color: #fef7ff; }
.badge.orange { background: #d37618; color: white }
.badge.accent { background: rgba(var(--accent-rgb), .14); color: var(--accent-400); }
.badge.success { background: rgba(var(--success-rgb), .14); color: var(--success); }
.badge.warn    { background: rgba(var(--warning-rgb), .14); color: var(--warning); }
.badge.danger  { background: rgba(var(--danger-rgb), .18); color: var(--danger); }
.badge.spacing {margin-left: 15px; }
/* --- Page header ------------------------------------------------------- */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; margin-bottom: 24px;
}
.page-title h1 { margin-bottom: 4px; }
.page-title .crumbs { color: var(--text-tertiary); font-size: .85rem; }

/* --- Empty state ------------------------------------------------------- */
.empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 60px 20px; text-align: center; color: var(--text-secondary);
    border: 1px dashed var(--hairline); border-radius: var(--radius-lg);
    background: var(--surface-1);
}
.empty .empty-mark {
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--accent-tint-12); color: var(--accent-500);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.6rem; margin-bottom: 14px;
}

/* --- Chat -------------------------------------------------------------- */
.chat-shell { display: grid; grid-template-columns: 280px 1fr; gap: 24px; height: calc(100vh - 56px); }
.chat-list-pane { display: flex; flex-direction: column; min-height: 0; }
.chat-list-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; }
.chat-new-fab {
    width: 36px; height: 36px; border-radius: 50%;
    padding: 0; font-size: 1.1rem; display: inline-flex; align-items: center; justify-content: center;
}
/* flex:1 + min-height:0 lets overflow-y actually clip when the list runs long.
   Without flex:1 the list takes its content height and never scrolls — just
   pushes past the parent's bounds. */
.chat-list { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; padding-right: 4px; }
/* Each row wraps the navigation link + the delete button so the button can be
   a sibling of the <a> (never nested inside it) and absolutely positioned. */
.chat-list-row { position: relative; }
.chat-list-item {
    display: block; padding: 10px 12px; padding-right: 34px; border-radius: var(--radius-md);
    color: var(--text-secondary); border: 1px solid transparent; cursor: pointer;
    transition: background .12s var(--ease-out), border-color .12s var(--ease-out);
    background: transparent; text-decoration: none;
}
.chat-list-item:hover { background: var(--surface-2); color: var(--text-primary); text-decoration: none; }
.chat-list-item.active {
    background: var(--surface-2); border-color: var(--accent-500); color: var(--text-primary);
    box-shadow: inset 3px 0 0 var(--accent-500);
}
.chat-list-title { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list-meta  { display: block; font-size: .72rem; color: var(--text-tertiary); margin-top: 2px; }

/* Per-row delete — a hover-reveal × matching the workspace row affordance.
   It lives outside the <a>, so it never triggers navigation; on touch devices
   (no hover) it stays dimmed-but-visible so it's reachable. */
.chat-row-delete {
    position: absolute; top: 8px; right: 8px;
    width: 24px; height: 24px; border-radius: 999px;
    background: transparent; border: 1px solid transparent;
    color: var(--text-tertiary); font-size: 1.05rem; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; opacity: 0; pointer-events: none;
    transition: opacity .15s var(--ease-out), background .15s var(--ease-out),
                color .15s var(--ease-out), border-color .15s var(--ease-out);
}
/* Only intercept clicks once revealed — otherwise a click in the row's
   top-right corner should still open the chat, not the (invisible) button. */
.chat-list-row:hover .chat-row-delete,
.chat-row-delete:focus-visible { opacity: 1; pointer-events: auto; }
.chat-row-delete:hover {
    background: rgba(var(--danger-rgb), .12);
    color: var(--danger);
    border-color: rgba(var(--danger-rgb), .3);
}
/* Touch devices have no hover — keep it dimmed-but-tappable. */
@media (hover: none) { .chat-row-delete { opacity: .55; pointer-events: auto; } }

/* Capability chips on each chat row — compact accent pills mirroring the chat
   header badges (HyDE, Decompose, Proxy, …). */
.cap-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.cap-badge {
    display: inline-flex; align-items: center;
    padding: 1px 6px; border-radius: 999px;
    font-size: .6rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    background: rgba(var(--accent-rgb), .14); color: var(--accent-400);
    border: 1px solid rgba(var(--accent-rgb), .22);
    white-space: nowrap; user-select: none;
}

.chat-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; max-width: 100%; }
.chat-header {
    display: flex; align-items: center; gap: 10px;
    padding-bottom: 12px; border-bottom: 1px solid var(--hairline); margin-bottom: 16px;
}
.chat-header-meta { flex: 1; min-width: 0; }
.chat-header-meta h2 {
    font-size: 1.05rem; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-header-badges { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; }
.chat-header-actions { display: flex; gap: 6px; flex-shrink: 0; }

.chat-back {
    display: none; /* desktop hides this; mobile shows it */
    width: 38px; height: 38px; border-radius: var(--radius-md);
    align-items: center; justify-content: center; flex-shrink: 0;
    color: var(--text-primary); background: var(--surface-2);
    border: 1px solid var(--hairline); font-size: 1.1rem;
    text-decoration: none; transition: background .12s var(--ease-out);
}
.chat-back:hover { background: var(--surface-3); text-decoration: none; }

.chat-stream { flex: 1; min-width: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 14px; padding-right: 6px; }

/* 80% keeps messages comfortable on normal screens; the px ceiling stops lines
   from becoming unreadably long once the pane is very wide on large monitors. */
.message { display: flex; gap: 12px; max-width: min(80%, 1600px); }
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message .avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--surface-3); color: var(--text-secondary);
    display: flex; align-items: center; justify-content: center; font-size: .8rem; flex-shrink: 0;
}
.message.user .avatar { background: var(--accent-500); color: white; }
.message .bubble {
    padding: 12px 14px; border-radius: var(--radius-lg);
    background: var(--surface-2); border: 1px solid var(--hairline);
    line-height: 1.55;
    /* `overflow-wrap: anywhere` lets long unbreakable runs (URLs, filenames
       like "(11.pdf") wrap inside the bubble; `min-width: 0` is the flex
       safety valve that allows the bubble to actually shrink to its
       container instead of inflating to its longest token. */
    overflow-wrap: anywhere;
    word-break: break-word;
    min-width: 0;
    position: relative;
}
.message.user .bubble {
    background: linear-gradient(140deg, var(--accent-tint-16), var(--accent-tint-06));
    border-color: rgba(var(--accent-rgb), .35);
}
.message-actions { position: absolute; top: 4px; right: 6px; opacity: 0; transition: opacity .12s var(--ease-out); }
.message:hover .message-actions { opacity: 1; }
/* Touch devices don't have meaningful hover — show actions persistently. */
@media (hover: none) {
    .message-actions { opacity: .55; }
    .message-actions:active { opacity: 1; }
}

.chat-composer {
    display: flex; gap: 10px; padding-top: 14px; border-top: 1px solid var(--hairline);
    min-width: 0;
}
/* Without `min-width: 0` flex items refuse to shrink below their intrinsic
   content width — a textarea picks up the placeholder size as min-content and
   on a phone that easily exceeds the viewport, pushing the Send button past
   the right edge. Both children get the override. */
.chat-composer > * { min-width: 0; }
.chat-composer textarea {
    flex: 1; min-height: 52px; max-height: 200px; resize: vertical;
    min-width: 0;
}

/* --- Markdown body ----------------------------------------------------- */
/* Scoped to .markdown-body so we don't bleed into navigation/admin tables.  */
.markdown-body { color: inherit; }
.markdown-body > *:first-child { margin-top: 0; }
.markdown-body > *:last-child { margin-bottom: 0; }

.markdown-body p { margin: 0 0 .55em; }
.markdown-body strong { color: var(--text-primary); font-weight: 600; }
.markdown-body em { color: var(--text-primary); }

.markdown-body a { color: var(--accent-400); text-decoration: underline; text-underline-offset: 2px; }
.markdown-body a:hover { color: var(--accent-500); }

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin: .9em 0 .35em; line-height: 1.3; font-weight: 600;
}
.markdown-body h1 { font-size: 1.18rem; }
.markdown-body h2 { font-size: 1.08rem; }
.markdown-body h3 { font-size: 1.0rem; }
.markdown-body h4, .markdown-body h5, .markdown-body h6 { font-size: .95rem; color: var(--text-secondary); }

.markdown-body ul, .markdown-body ol { margin: 0 0 .55em; padding-left: 1.25rem; }
.markdown-body li { margin: .15em 0; }
.markdown-body li > p { margin: 0; }

.markdown-body blockquote {
    margin: .5em 0; padding: .35em .9em;
    border-left: 3px solid var(--accent-500);
    background: var(--accent-tint-06);
    color: var(--text-secondary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.markdown-body hr {
    border: 0; border-top: 1px solid var(--hairline); margin: 1em 0;
}

.markdown-body code {
    font-family: var(--font-mono); font-size: .87em;
    padding: 1px 6px; border-radius: 4px;
    background: var(--surface-3); color: var(--accent-400);
    border: 1px solid var(--hairline);
}
.markdown-body pre {
    margin: .55em 0;
    padding: 12px 14px;
    background: var(--surface-0); color: var(--text-primary);
    border: 1px solid var(--hairline); border-radius: var(--radius-md);
    overflow-x: auto;
    font-family: var(--font-mono); font-size: .85rem; line-height: 1.5;
}
.markdown-body pre code {
    background: transparent; border: 0; padding: 0;
    color: inherit; font-size: inherit;
}

.markdown-body table {
    width: 100%; border-collapse: collapse; margin: .55em 0;
    font-size: .9rem;
}
.markdown-body th, .markdown-body td {
    border: 1px solid var(--hairline);
    padding: 6px 10px;
    text-align: left;
}
.markdown-body th { background: var(--surface-2); font-weight: 600; }
.markdown-body tbody tr:nth-child(even) { background: rgba(255,255,255,.02); }

.markdown-body input[type=checkbox] { /* task list checkboxes */
    margin-right: 6px; vertical-align: middle;
}

/* User-bubble accent — keep code/blockquote contrast on the red-tinted bg.   */
.message.user .bubble .markdown-body code { background: rgba(0,0,0,.3); }
.message.user .bubble .markdown-body pre  { background: rgba(0,0,0,.35); border-color: rgba(255,255,255,.08); }
.message.user .bubble .markdown-body blockquote { background: rgba(0,0,0,.2); }

/* --- Citation chip ----------------------------------------------------- */
.citation-chip-wrap { position: relative; display: inline-block; }
.citation-chip {
    display: inline-flex; align-items: center;
    background: var(--accent-tint-12); color: var(--accent-500);
    border: 1px solid rgba(var(--accent-rgb), .35);
    border-radius: 999px;
    padding: 1px 8px; margin: 0 2px;
    font-size: .72rem; font-weight: 600; line-height: 1.5;
    font-family: var(--font-sans);
    cursor: pointer; user-select: none;
    vertical-align: baseline;
    transition: background .12s var(--ease-out), color .12s var(--ease-out);
}
.citation-chip:hover { background: var(--accent-500); color: white; }
.citation-chip:focus-visible { outline: none; box-shadow: var(--shadow-accent); }
.citation-chip-missing { background: var(--surface-3); color: var(--text-tertiary); border-color: var(--hairline); }

/* Episodic-memory citations come from the chat's own memory rather than a
   document — flag them dark yellow so they're distinguishable at a glance from
   the accent-colored document chips. */
.citation-chip-memory {
    background: rgba(var(--mem-rgb), .14);
    color: var(--mem-fg);
    border-color: rgba(var(--mem-rgb), .40);
}
.citation-chip-memory:hover { background: rgb(var(--mem-rgb)); color: #1a1206; }
.citation-chip-memory:focus-visible { box-shadow: 0 0 0 3px rgba(var(--mem-rgb), .35); }

.citation-pop {
    position: absolute; left: 0; top: calc(100% + 6px);
    width: min(360px, 80vw);
    background: var(--surface-1); color: var(--text-primary);
    border: 1px solid var(--hairline); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 12px 14px;
    font-size: .85rem; line-height: 1.5;
    z-index: 30;
    display: flex; flex-direction: column; gap: 8px;
    white-space: normal;
}
/* The popover is rendered inline for every citation and toggled by the JS
   handler in App.razor via the [hidden] attribute. Without this override the
   .citation-pop { display: flex } rule wins over the user-agent default for
   [hidden] and the popover never actually hides. */
.citation-pop[hidden] { display: none; }

/* --- Developer log panel --------------------------------------------- */
/* 25vh console under the chat stream, above the composer. Toggled from the
   chat header's { } button. Renders one row per IChatTrace entry with a
   monospace timestamp + a colored source pill so the phases of the
   retrieval pipeline are visible at a glance. */
.dev-panel {
    height: 25vh;
    flex: 0 0 auto;
    display: flex; flex-direction: column;
    background: #0b0b0f;
    border-top: 1px solid var(--hairline);
    color: #d6d6df;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: .78rem;
    overflow: hidden;
}
[data-theme="light"] .dev-panel { background: #0f172a; color: #e2e8f0; }

.dev-panel-bar {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 10px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, .04);
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.dev-panel-title { font-weight: 700; letter-spacing: .04em; text-transform: uppercase; font-size: .7rem; color: var(--accent-500); }
.dev-panel-meta  { color: rgba(255,255,255,.55); font-size: .72rem; }
.dev-panel-spacer { flex: 1; }
.dev-panel-btn {
    color: rgba(255,255,255,.7);
    font-size: .8rem;
    padding: 2px 8px;
    border-radius: 6px;
}
.dev-panel-btn:hover { background: rgba(255,255,255,.08); color: #fff; }

.dev-panel-body {
    flex: 1; min-height: 0;
    overflow-y: auto;
    padding: 6px 10px 10px;
    display: flex; flex-direction: column-reverse; /* newest entries pinned to bottom view */
}
.dev-panel-row {
    display: grid;
    grid-template-columns: 92px 110px 1fr;
    gap: 10px;
    padding: 2px 0;
    border-bottom: 1px dashed rgba(255,255,255,.05);
    line-height: 1.4;
    word-break: break-word;
}
.dev-panel-time   { color: rgba(255,255,255,.45); font-variant-numeric: tabular-nums; }
.dev-panel-source {
    align-self: start;
    text-align: center;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(255,255,255,.08);
    color: rgba(255,255,255,.85);
    font-weight: 700; font-size: .7rem;
    text-transform: uppercase; letter-spacing: .04em;
}
.dev-panel-msg    { color: #e9e9f1; }

/* Per-source accent colors so the retrieval phases stand out at a glance. */
.dev-panel-source.src-core       { background: rgba(var(--accent-rgb), .35); color: #fff; }
.dev-panel-source.src-settings   { background: rgba(99, 102, 241, .35); color: #c7d2fe; }
.dev-panel-source.src-quota      { background: rgba(239, 68, 68, .35); color: #fecaca; }
.dev-panel-source.src-hyde       { background: rgba(168, 85, 247, .35); color: #e9d5ff; }
.dev-panel-source.src-embed      { background: rgba(14, 165, 233, .35); color: #bae6fd; }
.dev-panel-source.src-vector     { background: rgba(20, 184, 166, .35); color: #99f6e4; }
.dev-panel-source.src-multihop   { background: rgba(249, 115, 22, .35); color: #fed7aa; }
.dev-panel-source.src-rerank     { background: rgba(217, 70, 239, .35); color: #f5d0fe; }
.dev-panel-source.src-completion { background: rgba(34, 197, 94, .35); color: #bbf7d0; }
.dev-panel-source.src-cost       { background: rgba(234, 179, 8, .35); color: #fde68a; }
.dev-panel-source.src-suggest    { background: rgba(244, 114, 182, .3); color: #fbcfe8; }
.dev-panel-source.src-page       { background: rgba(148, 163, 184, .35); color: #e2e8f0; }
.dev-panel-source.src-default    { background: rgba(255, 255, 255, .08); color: rgba(255,255,255,.85); }

.dev-panel-empty { padding: 14px 4px; color: rgba(255, 255, 255, .5); font-style: italic; }

/* "Active" treatment for the dev toggle button so users can see at a glance
   that the panel is open. */
.btn-ghost.is-active {
    background: rgba(var(--accent-rgb), .12);
    color: var(--accent-500);
    border-color: rgba(var(--accent-rgb), .35);
}

/* --- Typing dots ----------------------------------------------------- */
/* Pinned to the end of the streaming assistant bubble. Three little dots
   pulse in sequence on a 1.2s loop while tokens are still arriving — when
   the stream finishes, the host element unmounts and the indicator vanishes
   without any state to manage. */
.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 6px;
    vertical-align: baseline;
    line-height: 1;
}
.typing-dots > span {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--accent-500);
    opacity: .3;
    animation: typing-dot-pulse 1.2s var(--ease-out) infinite;
}
.typing-dots > span:nth-child(2) { animation-delay: .15s; }
.typing-dots > span:nth-child(3) { animation-delay: .3s; }

/* Standalone "thinking" bubble — no streamed content yet, just the dots.
   Drops the leading margin so the indicator centers in the bubble, and
   tightens vertical padding so the bubble doesn't read as oversized while
   it's empty. */
.bubble.bubble-thinking {
    padding-top: 10px;
    padding-bottom: 10px;
}
.bubble.bubble-thinking .typing-dots { margin-left: 0; }
@keyframes typing-dot-pulse {
    0%, 60%, 100% { opacity: .25; transform: translateY(0); }
    30%           { opacity: 1;   transform: translateY(-2px); }
}
@media (prefers-reduced-motion: reduce) {
    .typing-dots > span { animation: none; opacity: .6; }
}

/* --- Sidebar usage badge --------------------------------------------- */
/* Pinned at the very top of the sidebar (above the workspace switcher) so
   users see their lifetime token + cost meter and quota progress on every
   page. Refreshes via UsageNotifier (instant) plus a 10s periodic poll. */
/* Sidebar ingestion-progress chip. Sits between the usage badge and the
   workspace switcher; visible from any page while a document upload or
   ingest is in flight on this circuit. Hidden entirely when nothing's
   processing, so it doesn't take up vertical space at rest. */
.ingest-badge {
    display: flex; align-items: center; gap: 8px;
    margin: 0 0 12px;
    padding: 8px 12px;
    background: rgba(var(--accent-rgb), .08);
    border: 1px solid rgba(var(--accent-rgb), .35);
    border-radius: var(--radius-md);
    color: var(--accent-400);
    font-size: .82rem;
    text-decoration: none;
    transition: background .18s var(--ease-out), border-color .18s var(--ease-out);
}
.ingest-badge:hover {
    background: rgba(var(--accent-rgb), .14);
    border-color: var(--accent-500);
    text-decoration: none;
}
.ingest-badge-spin {
    display: inline-block;
    animation: ingest-spin 1.6s linear infinite;
    line-height: 1;
}
.ingest-badge-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
@keyframes ingest-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.usage-badge {
    margin: 0 0 12px;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-md);
    display: flex; flex-direction: column; gap: 6px;
    font-size: .78rem;
    transition: border-color .18s var(--ease-out), background .18s var(--ease-out);
}
.usage-badge:hover { border-color: rgba(var(--accent-rgb), .35); }
.usage-badge-row {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: 8px; min-width: 0;
}
.usage-badge-label {
    font-size: .66rem; letter-spacing: .12em; text-transform: uppercase;
    color: var(--text-tertiary); font-weight: 700;
}
.usage-badge-limit {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    font-size: .72rem;
}
.usage-badge-bar {
    height: 6px;
    background: var(--surface-3);
    border-radius: 999px;
    overflow: hidden;
}
.usage-badge-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent-500), rgba(var(--accent-rgb), .65));
    transition: width .3s var(--ease-out);
    min-width: 2px;
}
.usage-badge-bar.is-full .usage-badge-fill {
    background: linear-gradient(90deg, var(--danger, #ef4444), rgba(var(--danger-rgb, 239, 68, 68), .65));
}
.usage-badge-foot {
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}
.usage-badge-tokens { color: var(--text-primary); }
.usage-badge-cost   { color: var(--accent-500); }

/* --- Custom tooltip --------------------------------------------------- */
/* Styled replacement for the browser's native title popup. The JS handler
   in App.razor stashes the [title] during hover so the OS tooltip never
   appears; this rectangle is positioned near the source element and styled
   to match the rest of the UI (dark surface, hairline border, accent
   shadow, soft fade-in). */
.dox-tip {
    position: fixed;
    z-index: 1000;
    max-width: 320px;
    padding: 8px 12px;
    background: var(--surface-1);
    color: var(--text-primary);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-md);
    box-shadow:
        0 10px 24px rgba(0, 0, 0, .35),
        0 0 0 1px rgba(var(--accent-rgb), .12);
    font: 500 .8rem/1.45 var(--font-sans);
    pointer-events: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    animation: dox-tip-in .12s var(--ease-out) both;
}
[data-theme="light"] .dox-tip {
    box-shadow:
        0 10px 24px rgba(15, 23, 42, .12),
        0 0 0 1px rgba(var(--accent-rgb), .08);
}
.dox-tip[hidden] { display: none; }
@keyframes dox-tip-in {
    from { opacity: 0; transform: translateY(2px); }
    to   { opacity: 1; transform: none; }
}

/* ===== Overview page ================================================== */

/* Flash notice — set by ChatsPage when redirecting a user that opened a
   chat from another workspace. Neutral surface, dismissable. */
.ov-notice {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 12px 16px;
    margin-bottom: 14px;
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    animation: ov-notice-in .18s var(--ease-out) both;
}
.ov-notice-mark {
    flex: 0 0 32px;
    width: 32px; height: 32px;
    border-radius: 999px;
    background: var(--accent-tint-12);
    color: var(--accent-500);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1rem;
}
.ov-notice-body { flex: 1; min-width: 0; }
.ov-notice-body strong { display: block; margin-bottom: 2px; }
.ov-notice-body p { margin: 0; color: var(--text-secondary); font-size: .85rem; line-height: 1.5; }
.ov-notice-close {
    flex: 0 0 auto;
    width: 28px; height: 28px;
    border-radius: 999px;
    background: transparent; border: 1px solid transparent;
    color: var(--text-tertiary);
    font-size: 1.1rem; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: background .12s var(--ease-out), color .12s var(--ease-out), border-color .12s var(--ease-out);
}
.ov-notice-close:hover { background: var(--surface-3); color: var(--text-primary); border-color: var(--hairline); }
.ov-notice-cta {
    flex: 0 0 auto;
    align-self: center;
    white-space: nowrap;
    padding: 7px 14px;
    font-size: .85rem;
}
@keyframes ov-notice-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
@media (max-width: 640px) {
    .ov-notice { flex-wrap: wrap; }
    .ov-notice-cta { width: 100%; }
}

/* Quota banner — only renders at ≥80%; "is-blocked" flips red when at cap. */
.ov-quota-banner {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 18px;
    margin-bottom: 18px;
    border-radius: var(--radius-lg);
    background: var(--accent-tint-12);
    border: 1px solid rgba(var(--accent-rgb), .35);
    color: var(--text-primary);
}
.ov-quota-banner.is-blocked {
    background: rgba(var(--danger-rgb, 239, 68, 68), .12);
    border-color: rgba(var(--danger-rgb, 239, 68, 68), .4);
}
.ov-quota-mark {
    flex: 0 0 36px;
    width: 36px; height: 36px;
    border-radius: 999px;
    background: var(--accent-500);
    color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700;
}
.ov-quota-banner.is-blocked .ov-quota-mark { background: var(--danger, #ef4444); }
.ov-quota-body { flex: 1; min-width: 0; }
.ov-quota-title { display: block; margin-bottom: 2px; font-size: .98rem; }
.ov-quota-text  { margin: 0; color: var(--text-secondary); font-size: .85rem; line-height: 1.5; }
.ov-quota-cta   { white-space: nowrap; }
@media (max-width: 640px) {
    .ov-quota-banner { flex-wrap: wrap; }
    .ov-quota-cta { width: 100%; }
}

/* ---- Workspace pulse hero ---- */
.ov-hero {
    position: relative;
    margin-bottom: 18px;
    border-radius: var(--radius-xl);
    background:
        radial-gradient(80% 110% at 0% 0%, hsl(var(--ov-hue, 0), 70%, 55%, .12), transparent 60%),
        linear-gradient(180deg, var(--surface-1) 0%, var(--surface-0) 100%);
    border: 1px solid var(--hairline);
    overflow: hidden;
}
.ov-hero-rail {
    position: absolute; top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg,
        hsl(var(--ov-hue, 0), 75%, 60%) 0%,
        hsl(calc(var(--ov-hue, 0) + 40), 75%, 50%) 100%);
}
.ov-hero-empty .ov-hero-rail { display: none; }

.ov-hero-banner {
    display: flex; gap: 16px; align-items: center;
    padding: 22px 24px;
}
.ov-hero-mark {
    flex: 0 0 56px;
    width: 56px; height: 56px;
    border-radius: 14px;
    background: linear-gradient(135deg,
        hsl(var(--ov-hue, 0), 75%, 55%),
        hsl(calc(var(--ov-hue, 0) + 50), 70%, 45%));
    color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1.5rem;
    box-shadow: 0 8px 18px hsl(var(--ov-hue, 0), 70%, 50%, .35);
    text-transform: uppercase;
    user-select: none;
}
.ov-hero-empty .ov-hero-mark {
    background: var(--accent-tint-12);
    color: var(--accent-500);
    box-shadow: none;
}
.ov-hero-meta { flex: 1; min-width: 0; }
.ov-hero-title {
    margin: 4px 0 8px;
    font-size: clamp(1.4rem, 2vw, 1.8rem);
    line-height: 1.2;
    letter-spacing: -.01em;
}
.ov-hero-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.ov-hero-sub  { margin: 0; color: var(--text-secondary); }
.ov-hero-actions { display: flex; gap: 8px; flex-shrink: 0; }
@media (max-width: 720px) {
    .ov-hero-banner { flex-wrap: wrap; }
    .ov-hero-actions { width: 100%; }
    .ov-hero-actions .btn-primary,
    .ov-hero-actions .btn-secondary { flex: 1; }
}

.ov-hero-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    padding: 0 24px 22px;
}
.ov-stat {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px;
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    transition: border-color .18s var(--ease-out), transform .18s var(--ease-out);
}
.ov-stat:hover { border-color: rgba(var(--accent-rgb), .35); transform: translateY(-1px); }
.ov-stat-mark {
    flex: 0 0 36px;
    width: 36px; height: 36px;
    border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent-tint-12);
    color: var(--accent-500);
    font-weight: 700; font-size: 1rem;
}
.ov-stat-meta { display: flex; flex-direction: column; min-width: 0; }
.ov-stat-value {
    font-size: 1.2rem; font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ov-stat-label {
    margin-top: 2px;
    font-size: .68rem; letter-spacing: .12em; text-transform: uppercase;
    color: var(--text-tertiary);
}
.ov-stat-sub {
    font-size: .76rem; color: var(--text-tertiary);
    margin-top: 2px;
}
.ov-stat-accent {
    background: linear-gradient(180deg, var(--accent-tint-12), var(--accent-tint-04));
    border-color: rgba(var(--accent-rgb), .35);
}
.ov-stat-accent .ov-stat-mark {
    background: linear-gradient(135deg, var(--accent-500), rgba(var(--accent-rgb), .65));
    color: #fff;
}
@media (max-width: 720px) {
    .ov-hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---- Personal usage panel ---- */
.ov-usage {
    padding: 22px 24px;
    background: var(--surface-1);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-xl);
}
.ov-usage-head {
    display: flex; justify-content: space-between; align-items: flex-end;
    gap: 12px; flex-wrap: wrap;
    margin-bottom: 12px;
}
.ov-usage-title { margin: 4px 0 0; font-size: 1.3rem; letter-spacing: -.01em; }
.ov-usage-limit-meta {
    text-align: right;
    display: flex; flex-direction: column; gap: 2px;
}
.ov-usage-limit-value { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.ov-usage-limit-pct   { font-size: .76rem; color: var(--text-tertiary); }

.ov-usage-bar {
    height: 8px;
    background: var(--surface-3);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 18px;
}
.ov-usage-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent-500), rgba(var(--accent-rgb), .65));
    transition: width .3s var(--ease-out);
    min-width: 4px;
}
.ov-usage-bar.is-full .ov-usage-fill {
    background: linear-gradient(90deg, var(--danger, #ef4444), rgba(var(--danger-rgb, 239, 68, 68), .65));
}

.ov-usage-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}
.ov-usage-card {
    display: flex; flex-direction: column; gap: 4px;
    padding: 14px 16px;
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
}
.ov-usage-big {
    font-size: 1.6rem; font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
@media (max-width: 560px) {
    .ov-usage-grid { grid-template-columns: 1fr; }
}

/* Spark chart — stacked bars, embed below chat. */
.ov-spark-head {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 6px;
}
.ov-spark-title {
    font-size: .68rem; letter-spacing: .12em; text-transform: uppercase;
    color: var(--text-tertiary); font-weight: 700;
}
.ov-spark-meta { color: var(--text-secondary); font-size: .82rem; font-variant-numeric: tabular-nums; }
.ov-spark {
    display: grid;
    grid-template-columns: repeat(14, 1fr);
    gap: 6px;
    height: 110px;
    padding: 8px;
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    position: relative;
}
.ov-spark-empty {
    grid-column: 1 / -1;
    align-self: center; justify-self: center;
    color: var(--text-tertiary);
    font-size: .85rem;
    font-style: italic;
}
.ov-spark-col {
    display: flex; flex-direction: column; align-items: stretch;
    min-width: 0;
}
.ov-spark-stack {
    flex: 1; min-height: 0;
    display: flex; flex-direction: column; justify-content: flex-end;
    overflow: hidden;
    border-radius: 4px 4px 0 0;
    background: rgba(var(--accent-rgb), .03);
}
.ov-spark-bar {
    transition: height .25s var(--ease-out);
    min-height: 0;
}
.ov-spark-chat  { background: var(--accent-500); border-radius: 4px 4px 0 0; }
.ov-spark-embed { background: rgba(20, 184, 166, .85); }
.ov-spark-axis {
    margin-top: 4px;
    text-align: center;
    font-size: .65rem;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
}

.ov-spark-legend {
    margin-top: 8px;
    display: flex; gap: 14px; flex-wrap: wrap;
    font-size: .78rem;
    color: var(--text-secondary);
}
.ov-spark-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.ov-legend-key {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 2px;
}
.ov-legend-chat  { background: var(--accent-500); }
.ov-legend-embed { background: rgba(20, 184, 166, .85); }

/* ---- Recent activity (chats + documents) ---- */
.ov-recent-grid {
    margin-top: 18px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}
@media (max-width: 800px) {
    .ov-recent-grid { grid-template-columns: 1fr; }
}
.ov-recent {
    background: var(--surface-1);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-xl);
    padding: 18px 20px;
}
.ov-recent-head {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 10px;
    gap: 8px;
}
.ov-recent-head h2 { margin: 0; font-size: 1.1rem; letter-spacing: -.01em; }
.ov-recent-scope {
    color: var(--text-tertiary);
    font-size: .82rem;
    font-weight: 500;
    margin-left: 6px;
}
.ov-recent-more {
    font-size: .82rem;
    color: var(--accent-500);
    text-decoration: none;
    white-space: nowrap;
}
.ov-recent-more:hover { text-decoration: underline; }
.ov-recent-empty { color: var(--text-tertiary); font-size: .85rem; padding: 10px 0; }
.ov-recent-empty a { color: var(--accent-500); }

.ov-recent-list {
    list-style: none;
    margin: 0; padding: 0;
    display: flex; flex-direction: column; gap: 2px;
}
.ov-recent-item {
    border-bottom: 1px solid var(--hairline);
    padding: 10px 0;
}
.ov-recent-item:last-child { border-bottom: 0; padding-bottom: 0; }
.ov-recent-item:first-child { padding-top: 0; }

.ov-recent-link {
    display: block;
    color: inherit;
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: transform .12s var(--ease-out);
}
.ov-recent-link:hover { transform: translateX(2px); }
.ov-recent-link:hover .ov-recent-title { color: var(--accent-500); }

.ov-recent-title {
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    transition: color .12s var(--ease-out);
}
.ov-recent-meta {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    color: var(--text-tertiary);
    font-size: .76rem;
    margin-top: 2px;
}
.ov-recent-dot { opacity: .55; }
.ov-recent-ws {
    color: var(--text-secondary);
    font-weight: 600;
}
.ov-recent-snippet {
    color: var(--text-secondary);
    font-size: .85rem;
    line-height: 1.45;
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ov-recent-doc { display: flex; flex-direction: column; gap: 4px; }
.ov-recent-doc-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px;
}
.ov-recent-doc-name {
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex: 1; min-width: 0;
}

/* ---- Get-started 3-step card ---- */
.ov-getstarted {
    margin-top: 18px;
    background:
        radial-gradient(60% 80% at 0% 0%, var(--accent-tint-12), transparent 70%),
        var(--surface-1);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-xl);
    padding: 22px 24px;
}
.ov-getstarted-head { margin-bottom: 14px; }
.ov-getstarted-head h2 { margin: 0 0 4px; font-size: 1.3rem; letter-spacing: -.01em; }
.ov-getstarted-steps {
    list-style: none;
    counter-reset: step;
    margin: 0; padding: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}
@media (max-width: 800px) {
    .ov-getstarted-steps { grid-template-columns: 1fr; }
}
.ov-getstarted-steps li {
    display: flex; gap: 12px;
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
}
.ov-getstarted-num {
    flex: 0 0 28px;
    width: 28px; height: 28px;
    border-radius: 999px;
    background: var(--accent-500);
    color: #fff;
    font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .85rem;
    margin-top: 2px;
}
.ov-getstarted-steps li > div { flex: 1; min-width: 0; }
.ov-getstarted-steps strong { display: block; margin-bottom: 4px; }
.ov-getstarted-steps p { margin: 0 0 10px; color: var(--text-secondary); font-size: .85rem; line-height: 1.5; }

/* --- Workspaces page: hero, toolbar, tiles ---------------------------- */
.ws-hero {
    position: relative;
    margin-bottom: 22px;
    padding: 26px 28px 24px;
    border-radius: var(--radius-xl);
    background:
        radial-gradient(80% 120% at 0% 0%, rgba(var(--accent-rgb), .14), transparent 60%),
        radial-gradient(70% 100% at 100% 0%, rgba(var(--accent-rgb), .07), transparent 60%),
        linear-gradient(180deg, var(--surface-1) 0%, var(--surface-0) 100%);
    border: 1px solid var(--hairline);
    box-shadow: 0 1px 0 rgba(255,255,255,.02) inset, 0 18px 36px rgba(0,0,0,.18);
    overflow: hidden;
}
.ws-hero::before {
    /* Faint diagonal line texture, reads as "studio paper" without competing. */
    content: "";
    position: absolute; inset: 0;
    background:
        repeating-linear-gradient(135deg,
            rgba(var(--accent-rgb), .035) 0 1px, transparent 1px 14px);
    pointer-events: none; opacity: .6;
}
.ws-hero > * { position: relative; }
.ws-hero-headline { max-width: 720px; }
.ws-hero-title {
    margin: 4px 0 6px;
    font-size: clamp(1.6rem, 2.4vw, 2.1rem);
    letter-spacing: -.015em;
}
.ws-hero-sub {
    margin: 0;
    color: var(--text-secondary);
    font-size: .95rem; line-height: 1.55;
    max-width: 56ch;
}
.ws-hero-cta {
    position: absolute; top: 26px; right: 28px;
    display: inline-flex; align-items: center; gap: 8px;
    box-shadow: 0 6px 18px rgba(var(--accent-rgb), .35);
}
.ws-hero-cta-glyph {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px;
    border-radius: 999px;
    background: rgba(255,255,255,.18);
    font-weight: 700; font-size: .85rem; line-height: 1;
}
.ws-hero-strip {
    margin-top: 22px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}
.ws-hero-stat {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-lg);
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    transition: border-color .18s var(--ease-out), transform .18s var(--ease-out), background .18s var(--ease-out);
}
.ws-hero-stat:hover {
    border-color: rgba(var(--accent-rgb), .35);
    transform: translateY(-1px);
}
.ws-hero-stat-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
    border-radius: 10px;
    background: var(--accent-tint-12);
    color: var(--accent-500);
    font-size: 1.05rem; font-weight: 700;
    flex: 0 0 36px;
}
.ws-hero-stat-meta { display: flex; flex-direction: column; min-width: 0; }
.ws-hero-stat-label {
    font-size: .68rem; letter-spacing: .12em; text-transform: uppercase;
    color: var(--text-tertiary);
}
.ws-hero-stat-value {
    font-size: 1.25rem; font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1.15; margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ws-hero-stat-accent {
    background: linear-gradient(180deg, var(--accent-tint-12), var(--accent-tint-04));
    border-color: rgba(var(--accent-rgb), .35);
}
.ws-hero-stat-accent .ws-hero-stat-mark {
    background: linear-gradient(135deg, var(--accent-500), rgba(var(--accent-rgb), .65));
    color: white;
}

@media (max-width: 720px) {
    .ws-hero { padding: 22px 18px 20px; }
    .ws-hero-cta { position: static; margin-top: 14px; }
    .ws-hero-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Toast for non-error status messages (replaces the bare success badge). */
.ws-toast {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 14px;
    background: rgba(var(--success-rgb, 34, 197, 94), .12);
    color: var(--success, #22c55e);
    border: 1px solid rgba(var(--success-rgb, 34, 197, 94), .35);
    border-radius: 999px;
    font-size: .85rem; font-weight: 600;
    margin-bottom: 14px;
    animation: ws-fade .2s var(--ease-out) both;
}
@keyframes ws-fade { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* Toolbar: search + sort. */
.ws-toolbar {
    display: flex; gap: 10px; flex-wrap: wrap;
    margin-bottom: 16px;
    align-items: center;
}
.ws-search {
    position: relative; flex: 1; min-width: 220px;
    display: inline-flex; align-items: center;
}
.ws-search-icon {
    position: absolute; left: 12px;
    color: var(--text-tertiary);
    font-size: 1rem;
    pointer-events: none;
}
.ws-search input[type="search"] {
    width: 100%;
    padding-left: 36px;
}
.ws-sort { width: auto; min-width: 200px; }

/* Tile grid. Wider min so the cap+stats layout breathes; collapses cleanly. */
.ws-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 18px;
}

/* The tile itself. Layered with a left rail tinted from a stable per-id hue,
   so each workspace gets its own visual fingerprint without the database
   carrying any color metadata. */
.ws-tile {
    position: relative;
    display: flex; flex-direction: column;
    background:
        linear-gradient(180deg, hsl(var(--ws-hue, 0), 60%, 50%, .04) 0%, transparent 90px),
        var(--surface-1);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-xl);
    overflow: hidden;
    transition: transform .2s var(--ease-out), border-color .2s var(--ease-out),
                box-shadow .2s var(--ease-out);
}
.ws-tile:hover {
    transform: translateY(-3px);
    border-color: hsl(var(--ws-hue, 0), 70%, 55%, .55);
    box-shadow:
        0 18px 40px rgba(0,0,0,.28),
        0 0 0 1px hsl(var(--ws-hue, 0), 70%, 55%, .15);
}
.ws-tile.is-active {
    border-color: var(--accent-500);
    box-shadow:
        0 0 0 1px var(--accent-500) inset,
        0 18px 40px rgba(var(--accent-rgb), .22);
}
.ws-tile.is-active::after {
    content: "";
    position: absolute; inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(var(--accent-rgb), .06), transparent 30%);
}
.ws-tile-rail {
    position: absolute; top: 0; left: 0; bottom: 0;
    width: 4px;
    background: linear-gradient(180deg,
        hsl(var(--ws-hue, 0), 75%, 60%) 0%,
        hsl(calc(var(--ws-hue, 0) + 40), 75%, 50%) 100%);
}
.ws-tile.is-active .ws-tile-rail {
    background: linear-gradient(180deg, var(--accent-500), rgba(var(--accent-rgb), .65));
}

.ws-tile-cap {
    position: relative;
    display: flex; align-items: center; gap: 12px;
    padding: 16px 18px 0 22px;
}
.ws-tile-mark {
    flex: 0 0 44px;
    width: 44px; height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg,
        hsl(var(--ws-hue, 0), 75%, 55%) 0%,
        hsl(calc(var(--ws-hue, 0) + 50), 70%, 45%) 100%);
    color: white;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1.15rem;
    box-shadow: 0 6px 14px hsl(var(--ws-hue, 0), 70%, 50%, .35);
    text-transform: uppercase;
    user-select: none;
}
.ws-tile-pills { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 0; }
.ws-pill {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: .68rem; font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    border: 1px solid var(--hairline);
    background: var(--surface-2);
    color: var(--text-secondary);
    white-space: nowrap;
}
.ws-pill-default {
    border-color: rgba(var(--accent-rgb), .35);
    background: var(--accent-tint-12);
    color: var(--accent-500);
}
.ws-pill-active {
    border-color: rgba(var(--accent-rgb), .5);
    background: var(--accent-500);
    color: white;
}
.ws-pill-mine { color: var(--text-tertiary); }

/* Chunk-rewriting badge on the workspaces list. Tinted with an accent
   gradient so it reads as a "premium" indicator alongside the more
   utilitarian Default / Active / Owner pills — admins enable rewriting
   per workspace and it materially changes ingest behavior, so it
   deserves visual weight. The little sparkle glyph rotates very subtly
   on hover; the pill itself doesn't pulse so it doesn't compete with
   the Active pill for attention. */
.ws-pill-rewrite {
    background: linear-gradient(135deg, rgba(var(--accent-rgb), .18), rgba(var(--accent-rgb), .08));
    border-color: rgba(var(--accent-rgb), .45);
    color: var(--accent-500);
    box-shadow: 0 1px 4px rgba(var(--accent-rgb), .18);
}
.ws-pill-rewrite-spark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 12px; height: 12px;
    transition: transform .25s var(--ease-out);
}
.ws-pill-rewrite:hover .ws-pill-rewrite-spark { transform: rotate(-12deg) scale(1.15); }

/* Inline sub-line hint underneath the workspace row's embedding model.
   Reads as muted secondary text but with the same accent color as the
   pill so the eye threads "Rewriting" → model name as a single signal. */
.ws-row-rewrite-hint {
    display: inline-flex; align-items: center; gap: 4px;
    color: var(--accent-500);
}
.ws-row-rewrite-hint-sep { color: var(--text-tertiary); padding: 0 4px; }
.ws-row-rewrite-hint-glyph { font-size: .9em; opacity: .85; }
.ws-row-rewrite-hint strong { font-weight: 600; }

.ws-tile-delete {
    width: 28px; height: 28px;
    border-radius: 999px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-tertiary);
    font-size: 1.2rem; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s var(--ease-out), background .15s var(--ease-out),
                color .15s var(--ease-out), border-color .15s var(--ease-out);
    align-self: flex-start;
}
.ws-tile:hover .ws-tile-delete,
.ws-tile-delete:focus-visible { opacity: 1; }
.ws-tile-delete:hover {
    background: rgba(var(--danger-rgb, 220, 38, 38), .12);
    color: var(--danger, #dc2626);
    border-color: rgba(var(--danger-rgb, 220, 38, 38), .3);
}
@media (hover: none) { .ws-tile-delete { opacity: .55; } }

.ws-tile-body { padding: 14px 22px 0; flex: 1; display: flex; flex-direction: column; gap: 12px; }
.ws-tile-title {
    margin: 0;
    font-size: 1.1rem; line-height: 1.3;
    letter-spacing: -.01em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ws-tile-desc {
    margin: 0;
    color: var(--text-secondary);
    font-size: .87rem; line-height: 1.5;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.6em;
}

.ws-tile-stats {
    display: flex; align-items: stretch;
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    padding: 10px 4px;
}
.ws-tile-stat {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column; gap: 2px;
    padding: 0 12px;
    text-align: center;
}
.ws-tile-stat-value {
    font-size: 1.1rem; font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.ws-tile-stat-label {
    font-size: .66rem; letter-spacing: .12em; text-transform: uppercase;
    color: var(--text-tertiary);
}
.ws-tile-stat-divider { flex: 0 0 1px; background: var(--hairline); margin: 4px 0; }

.ws-tile-cost { display: flex; flex-direction: column; gap: 6px; }
.ws-tile-cost-row {
    display: flex; align-items: center; justify-content: space-between;
    font-size: .82rem;
}
.ws-tile-cost-label {
    color: var(--text-tertiary);
    text-transform: uppercase; letter-spacing: .1em;
    font-size: .66rem; font-weight: 600;
}
.ws-tile-cost-value {
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
    font-size: .95rem;
}
.ws-tile-cost-meter {
    height: 6px;
    background: var(--surface-3);
    border-radius: 999px;
    overflow: hidden;
}
.ws-tile-cost-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg,
        hsl(var(--ws-hue, 0), 75%, 60%),
        hsl(calc(var(--ws-hue, 0) + 40), 75%, 50%));
    transition: width .3s var(--ease-out);
    min-width: 4px;
}
.ws-tile.is-active .ws-tile-cost-fill {
    background: linear-gradient(90deg, var(--accent-500), rgba(var(--accent-rgb), .65));
}

.ws-tile-actions {
    margin-top: auto;
    padding: 14px 22px 18px;
    display: flex; gap: 8px; flex-wrap: wrap;
}
.ws-tile-actions .btn-primary { flex: 1; min-width: 110px; }

/* Skeletons: shown while the list is loading so the page doesn't pop in. */
.ws-tile-skeleton { pointer-events: none; }
.ws-tile-skeleton .ws-tile-mark { background: var(--surface-3); box-shadow: none; }
.ws-tile-skeleton .ws-tile-rail { opacity: .35; }
.ws-skel {
    background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
    background-size: 200% 100%;
    border-radius: 6px;
    animation: ws-shimmer 1.2s linear infinite;
}
.ws-skel-title { height: 14px; width: 60%; margin: 16px 0 10px; }
.ws-skel-line  { height: 10px; width: 90%; margin-bottom: 6px; }
.ws-skel-line.short { width: 55%; }
@keyframes ws-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---- Workspaces as a vertical list of compact rows --------------------
   Replaces the tile grid: each row is a single line on desktop, fills the
   content width, and stays scrollable horizontally inside the row when the
   viewport gets too narrow to fit everything (the row itself is
   overflow-x: auto with white-space: nowrap so the layout stays tidy
   instead of wrapping into a tall stacked card). */
.ws-list {
    display: flex; flex-direction: column;
    gap: 8px;
}
.ws-row {
    position: relative;
    display: flex; align-items: center;
    gap: 14px;
    padding: 10px 56px 10px 22px; /* extra right room for the absolute delete × */
    background:
        linear-gradient(90deg, hsl(var(--ws-hue, 0), 60%, 50%, .03) 0%, transparent 280px),
        var(--surface-1);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    min-height: 60px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    transition: transform .18s var(--ease-out), border-color .18s var(--ease-out),
                box-shadow .18s var(--ease-out), background-color .18s var(--ease-out);
}
.ws-row::-webkit-scrollbar { height: 6px; }
.ws-row::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 999px; }
.ws-row:hover {
    transform: translateY(-1px);
    border-color: hsl(var(--ws-hue, 0), 70%, 55%, .55);
    box-shadow: 0 8px 18px rgba(0, 0, 0, .18);
}
.ws-row.is-active {
    border-color: var(--accent-500);
    box-shadow:
        0 0 0 1px var(--accent-500) inset,
        0 8px 18px rgba(var(--accent-rgb), .18);
}

/* Hue-derived left rail and circular avatar mark — same per-id fingerprint
   as the old tiles, so each workspace stays visually identifiable. */
.ws-row-rail {
    position: absolute; top: 0; left: 0; bottom: 0;
    width: 4px;
    background: linear-gradient(180deg,
        hsl(var(--ws-hue, 0), 75%, 60%) 0%,
        hsl(calc(var(--ws-hue, 0) + 40), 75%, 50%) 100%);
}
.ws-row.is-active .ws-row-rail {
    background: linear-gradient(180deg, var(--accent-500), rgba(var(--accent-rgb), .65));
}
.ws-row-mark {
    flex: 0 0 38px;
    width: 38px; height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg,
        hsl(var(--ws-hue, 0), 75%, 55%),
        hsl(calc(var(--ws-hue, 0) + 50), 70%, 45%));
    color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1rem;
    box-shadow: 0 4px 10px hsl(var(--ws-hue, 0), 70%, 50%, .3);
    text-transform: uppercase;
    user-select: none;
}

/* Title + description column. min-width:0 lets the title and description
   ellipsize cleanly inside their constrained slot. */
.ws-row-main { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ws-row-titleline {
    display: flex; align-items: center; gap: 8px;
    flex-wrap: nowrap;
    min-width: 0;
}
.ws-row-title {
    margin: 0;
    font-size: 1rem; font-weight: 600;
    letter-spacing: -.005em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex: 0 1 auto;
}
.ws-row-desc {
    margin: 0;
    color: var(--text-secondary);
    font-size: .82rem; line-height: 1.4;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    display: inline-flex; align-items: center; gap: 6px;
}
.ws-row-em-glyph {
    color: var(--accent-500);
    font-size: .9em;
    flex: 0 0 auto;
}

/* Stats — three numeric cells + a compact cost meter. All in one row. */
.ws-row-stats {
    flex: 0 0 auto;
    display: flex; align-items: center;
    gap: 18px;
    padding: 0 6px;
}
.ws-row-stat {
    display: flex; flex-direction: column; align-items: flex-end;
    gap: 1px;
    min-width: 44px;
}
.ws-row-stat-value {
    font-size: .95rem; font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.ws-row-stat-label {
    font-size: .62rem; letter-spacing: .12em; text-transform: uppercase;
    color: var(--text-tertiary);
}

.ws-row-cost {
    display: flex; flex-direction: column; align-items: flex-end;
    gap: 4px;
    min-width: 110px;
}
.ws-row-cost-value {
    font-size: .9rem; font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--accent-500);
    line-height: 1.1;
}
.ws-row-cost-meter {
    width: 90px;
    height: 4px;
    background: var(--surface-3);
    border-radius: 999px;
    overflow: hidden;
}
.ws-row-cost-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg,
        hsl(var(--ws-hue, 0), 75%, 60%),
        hsl(calc(var(--ws-hue, 0) + 40), 75%, 50%));
    transition: width .3s var(--ease-out);
    min-width: 3px;
}
.ws-row.is-active .ws-row-cost-fill {
    background: linear-gradient(90deg, var(--accent-500), rgba(var(--accent-rgb), .65));
}

/* Inline action buttons. .btn-sm is a one-off compact modifier so the row
   stays under 60px tall on desktop. */
.ws-row-actions {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 6px;
}
.btn-sm {
    padding: 6px 10px;
    font-size: .82rem;
    border-radius: 8px;
}
.ws-row-cog { padding: 6px 9px; font-size: 1rem; line-height: 1; }

/* Discrete delete pinned to the row's right edge. Reveals on hover; stays
   at low opacity on touch devices so the affordance is always discoverable. */
.ws-row-delete {
    position: absolute;
    top: 50%; right: 12px;
    transform: translateY(-50%);
    width: 26px; height: 26px;
    border-radius: 999px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-tertiary);
    font-size: 1.1rem; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s var(--ease-out), background .15s var(--ease-out),
                color .15s var(--ease-out), border-color .15s var(--ease-out);
}
.ws-row:hover .ws-row-delete,
.ws-row-delete:focus-visible { opacity: 1; }
.ws-row-delete:hover {
    background: rgba(var(--danger-rgb, 220, 38, 38), .12);
    color: var(--danger, #dc2626);
    border-color: rgba(var(--danger-rgb, 220, 38, 38), .3);
}
@media (hover: none) { .ws-row-delete { opacity: .55; } }

/* Skeletons. */
.ws-row-skeleton { pointer-events: none; min-height: 56px; }
.ws-row-skeleton .ws-row-mark { background: var(--surface-3); box-shadow: none; }
.ws-row-skeleton .ws-row-rail { opacity: .35; }

/* Description hides first on narrow viewports, then the per-row scroll
   takes over. The row never wraps — it just scrolls horizontally. */
@media (max-width: 720px) {
    .ws-row-desc { display: none; }
    .ws-row-stats { gap: 12px; }
    .ws-row-cost { min-width: 90px; }
    .ws-row-cost-meter { width: 60px; }
}
@media (max-width: 480px) {
    .ws-row { padding-left: 16px; padding-right: 44px; }
    .ws-row-mark { flex-basis: 32px; width: 32px; height: 32px; font-size: .9rem; }
    .ws-row-stat-label { display: none; }
    .ws-row-stats { gap: 10px; }
}

/* Empty + soft empty (filter miss). */
.ws-empty {
    text-align: center;
    padding: 56px 24px;
    border: 1px dashed var(--hairline);
    border-radius: var(--radius-xl);
    background: var(--surface-1);
    color: var(--text-secondary);
}
.ws-empty h3 { margin: 14px 0 6px; color: var(--text-primary); font-size: 1.15rem; }
.ws-empty p { margin: 0 0 18px; color: var(--text-tertiary); }
.ws-empty .btn-primary { display: inline-flex; }
.ws-empty-mark {
    width: 80px; height: 80px;
    margin: 0 auto;
    border-radius: 999px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent-tint-12);
    color: var(--accent-500);
    font-size: 1.6rem;
}
.ws-empty-soft { padding: 36px 24px; }

/* --- Quota-blocked overlay -------------------------------------------- */
.quota-blocked-backdrop {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, .55);
    backdrop-filter: blur(6px);
    z-index: 200;
    animation: quota-fade .18s var(--ease-out) both;
}
.quota-blocked-card {
    position: fixed;
    top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: min(460px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    background: var(--surface-1);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-xl, 16px);
    box-shadow: 0 30px 80px rgba(0,0,0,.45), 0 0 0 1px rgba(var(--accent-rgb), .25);
    z-index: 201;
    display: flex; flex-direction: column;
    animation: quota-rise .22s var(--ease-out) both;
    overflow: hidden;
}
.quota-blocked-rail {
    height: 4px;
    background: linear-gradient(90deg, var(--accent-500), rgba(var(--accent-rgb), .4));
}
.quota-blocked-body { padding: 26px 28px 24px; }
.quota-blocked-mark {
    width: 56px; height: 56px;
    border-radius: 999px;
    background: var(--accent-tint-12);
    color: var(--accent-500);
    display: inline-flex; align-items: center; justify-content: center;
    margin-bottom: 14px;
}
.quota-blocked-eyebrow {
    font-size: .72rem; letter-spacing: .12em; text-transform: uppercase;
    font-weight: 700; color: var(--accent-500);
    margin-bottom: 6px;
}
.quota-blocked-title {
    margin: 0 0 8px;
    font-size: 1.4rem; line-height: 1.25;
    color: var(--text-primary);
}
.quota-blocked-lede {
    margin: 0 0 18px;
    color: var(--text-secondary);
    line-height: 1.55;
}
.quota-blocked-meter {
    height: 10px;
    background: var(--surface-3);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 14px;
}
.quota-blocked-meter-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-500), rgba(var(--accent-rgb), .65));
    border-radius: 999px;
    transition: width .3s var(--ease-out);
}
.quota-blocked-stats {
    display: flex; align-items: stretch;
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg, 12px);
    padding: 12px;
    gap: 0;
    margin-bottom: 18px;
}
.quota-blocked-stats > div { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 0 10px; min-width: 0; }
.quota-blocked-stat-divider { flex: 0 0 1px; background: var(--hairline); margin: 4px 0; }
.quota-blocked-stat-label { font-size: .7rem; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: .08em; }
.quota-blocked-stat-value { font-size: 1.05rem; font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.quota-blocked-hint { color: var(--text-tertiary); font-size: .85rem; line-height: 1.5; margin: 0 0 18px; }
.quota-blocked-hint a { color: var(--accent-500); text-decoration: none; }
.quota-blocked-hint a:hover { text-decoration: underline; }
.quota-blocked-cta { width: 100%; padding: 11px 16px; font-size: .95rem; }

@keyframes quota-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes quota-rise {
    from { opacity: 0; transform: translate(-50%, calc(-50% + 8px)); }
    to   { opacity: 1; transform: translate(-50%, -50%); }
}
.citation-pop-head {
    display: flex; flex-direction: column; gap: 2px;
    padding-bottom: 6px; border-bottom: 1px solid var(--hairline);
}
.citation-pop-head strong { font-size: .9rem; }
.citation-pop-meta { color: var(--text-tertiary); font-size: .75rem; }
.citation-pop-body { color: var(--text-secondary); max-height: 220px; overflow-y: auto; }

/* User-bubble background is red-tinted; flip the chip styling so it stays readable. */
.message.user .citation-chip { background: rgba(255,255,255,.18); color: white; border-color: rgba(255,255,255,.35); }
.message.user .citation-chip:hover { background: white; color: var(--accent-700); }

/* --- Suggestion chips -------------------------------------------------- */
.bubble-stack { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.suggestion-row {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin-top: 2px;
}
.suggestion-chip {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--hairline);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: .8rem; font-weight: 500;
    cursor: pointer; text-align: left;
    transition: background .12s var(--ease-out), color .12s var(--ease-out),
                border-color .12s var(--ease-out);
    max-width: 100%;
    white-space: normal;
}
.suggestion-chip:hover {
    background: var(--accent-tint-12);
    color: var(--accent-500);
    border-color: var(--accent-500);
}
.suggestion-chip:disabled { opacity: .5; cursor: not-allowed; }

/* Starter prompts on the empty chat states — same chips, centered. */
.starter-row { justify-content: center; margin-top: 14px; max-width: 520px; margin-left: auto; margin-right: auto; }

/* Inline turn-error banner (e.g. Qdrant unreachable) above the composer. */
.chat-error {
    display: flex; align-items: flex-start; gap: 10px;
    margin: 8px 14px 0;
    padding: 10px 12px;
    background: rgba(var(--danger-rgb), .1);
    border: 1px solid rgba(var(--danger-rgb), .4);
    border-radius: var(--radius-md);
    color: var(--text-primary); font-size: .85rem;
}
.chat-error-text { flex: 1; line-height: 1.4; }

/* --- Settings drawer --------------------------------------------------- */
.drawer-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.5);
    z-index: 80; animation: fadeIn .15s var(--ease-out);
}
.drawer {
    position: fixed; top: 0; right: 0; width: min(420px, 100%);
    /* Explicit height pinned to the *dynamic* viewport (tracks the visible
       area as the mobile URL bar collapses/expands). top + bottom would
       resolve against the layout viewport, which on mobile is taller than
       the visible area — pushing the bottom of the drawer offscreen and
       leaving overflow-y nothing to clip against. svh as a fallback for
       browsers that haven't shipped dvh; layered values pick the best. */
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    background: var(--surface-1); border-left: 1px solid var(--hairline);
    z-index: 81; box-shadow: var(--shadow-lg);
    animation: slideInRight .22s var(--ease-out);
    /* The drawer itself is just a frame; the inside splits into a fixed
       header and a flex:1 body. Keeps the close X always visible while the
       body scrolls. */
    display: flex; flex-direction: column;
    overflow: hidden;            /* the body owns the scroll */
}

/* Drawer header — non-scrolling top bar with the title and a guaranteed
   one-tap close. flex-shrink:0 so it never collapses when the body grows. */
.drawer-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; padding: 16px 22px;
    background: var(--surface-1);
    border-bottom: 1px solid var(--hairline);
    flex-shrink: 0;
}
.drawer-header h2 { margin: 0; font-size: 1.1rem; }

/* Body holds the scrolling content. min-height:0 is the magic flex
   incantation that lets a flex:1 child actually shrink below its content
   height so overflow-y can do its job. */
.drawer-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 18px 22px 22px;
}

/* Footer is always visible at the bottom (Cancel / Save row). Drawers
   that don't use a footer simply put the buttons inside .drawer-body. */
.drawer-footer {
    flex-shrink: 0;
    padding: 12px 22px;
    border-top: 1px solid var(--hairline);
    display: flex; gap: 8px; justify-content: flex-end;
    background: var(--surface-1);
}

.drawer-close {
    width: 36px; height: 36px; border-radius: 50%;
    background: transparent; border: 0;
    color: var(--text-secondary); font-size: 1.4rem; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0;
    transition: background .12s var(--ease-out), color .12s var(--ease-out);
}
.drawer-close:hover { background: var(--surface-3); color: var(--text-primary); }
.drawer-close:focus-visible { box-shadow: var(--shadow-accent); outline: none; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideInRight { from { transform: translateX(100%) } to { transform: translateX(0) } }

/* --- Auth pages -------------------------------------------------------- */
.auth-shell {
    min-height: 100vh; display: grid; place-items: center;
    background:
        radial-gradient(1200px 600px at 80% -10%, rgba(var(--accent-rgb), .18), transparent 60%),
        radial-gradient(900px 500px at 0% 110%, rgba(var(--accent-rgb), .10), transparent 60%),
        var(--surface-0);
    padding: 24px;
}
.auth-card {
    background: var(--surface-1); border: 1px solid var(--hairline);
    border-radius: var(--radius-xl); padding: 36px;
    width: min(420px, 100%);
    box-shadow: var(--shadow-lg);
}
.auth-card h1 { font-size: 1.6rem; }
.auth-card .lead { color: var(--text-secondary); margin-bottom: 24px; }
.auth-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; }

/* --- Drag & drop upload zone ------------------------------------------- */
.dropzone { cursor:pointer; }
.dropzone:hover { color: var(--accent-400)}
.dropzone .hint { color: var(--text-tertiary); font-size: .85rem; }

/* --- Validation -------------------------------------------------------- */
.validation-summary { background: rgba(var(--danger-rgb), .08); border: 1px solid rgba(var(--danger-rgb), .3);
    border-radius: var(--radius-md); padding: 10px 14px; color: var(--accent-400); margin-bottom: 14px; }

/* --- Scrollbar (modern, subtle) ---------------------------------------- */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--surface-4); background-clip: padding-box; }

/* Workspace detail two-card grid — stacks on small screens. */
.ws-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* ---- Workspace detail: mobile-first tabbed layout -------------------- */

/* Header: title and actions stack on phones, sit side-by-side on desktop. */
.ws-detail-header { flex-wrap: wrap; align-items: flex-start; }
.ws-detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 640px) {
    .ws-detail-header { gap: 12px; }
    .ws-detail-actions { width: 100%; }
    /* Full-width, evenly-split action buttons are easier to tap. */
    .ws-detail-actions > * { flex: 1 1 auto; text-align: center; justify-content: center; }
}

/* Tab bar — horizontally scrollable when the labels overflow a narrow
   viewport, with the active tab underlined in the accent colour. */
.ws-tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--hairline);
    margin-bottom: 20px;
    overflow-x: auto;
    scrollbar-width: none;            /* Firefox — hide the scrollbar */
    -webkit-overflow-scrolling: touch;
}
.ws-tabs::-webkit-scrollbar { display: none; }
.ws-tab {
    flex: 0 0 auto;
    appearance: none;
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;             /* overlap the bar's hairline */
    padding: 12px 16px;
    font-size: .9rem; font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: color .12s var(--ease-out), border-color .12s var(--ease-out);
}
.ws-tab:hover { color: var(--text-primary); }
.ws-tab.active { color: var(--accent-500); border-bottom-color: var(--accent-500); }
.ws-tab-count {
    display: inline-block; min-width: 18px; padding: 0 6px;
    margin-left: 4px;
    border-radius: 999px; background: var(--surface-3);
    font-size: .72rem; line-height: 18px; text-align: center;
    color: var(--text-secondary); font-variant-numeric: tabular-nums;
}
.ws-tab.active .ws-tab-count { background: var(--accent-tint-12); color: var(--accent-500); }

/* Panel — single aligned column; capped width on desktop for readability,
   full-bleed on phones. Every field in every tab shares this left edge. */
.ws-tab-panel { display: flex; flex-direction: column; gap: 18px; max-width: 760px; }
.ws-tab-panel .card { width: 100%; box-sizing: border-box; }

/* Overview stat tiles — auto-fit so they sit in a row on desktop and stack
   on phones, all the same height and aligned to the panel's edges. */
.ws-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
}
.ws-stat { display: flex; flex-direction: column; gap: 4px; }
.ws-stat-value { font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Definition-list facts — label/value rows that align their colons on
   desktop and stack cleanly on phones. */
.ws-facts { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.ws-facts > div { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.ws-facts dt { flex: 0 0 130px; margin: 0; color: var(--text-secondary); font-size: .82rem; font-weight: 500; }
.ws-facts dd { margin: 0; color: var(--text-primary); word-break: break-word; }
@media (max-width: 480px) {
    .ws-facts > div { flex-direction: column; gap: 2px; }
    .ws-facts dt { flex-basis: auto; }
}

/* Add-member row — input grows, button hugs; wraps under on phones. */
.ws-add-member { display: flex; gap: 8px; margin-bottom: 14px; }
.ws-add-member input { flex: 1; min-width: 0; }
@media (max-width: 480px) {
    .ws-add-member { flex-wrap: wrap; }
    .ws-add-member .btn-primary { width: 100%; }
}

/* ============================================================================
   RESPONSIVE — mobile-first overrides applied below 900px.
   The shape of the page changes substantially on phones:
   - the sidebar becomes a slide-in drawer behind a hamburger;
   - the chat surface becomes master-detail (list OR chat, never both);
   - tables get horizontal-scroll affordances;
   - grids stack;
   - tap targets grow to 44px+;
   - the chat composer sticks to the bottom of the viewport.
   ============================================================================ */

@media (max-width: 900px) {

    :root { --topbar-h: 56px; }

    /* Last-resort guard against horizontal overflow. Any rogue child wider
       than the viewport gets clipped here instead of letting the user
       horizontally pan the entire page — a behavior that's especially
       jarring on the chat surface. */
    html, body { overflow-x: hidden; max-width: 100vw; }

    /* App shell ----------------------------------------------------------- */
    .app-shell { grid-template-columns: 1fr; max-width: 100vw; overflow-x: hidden; }

    /* Top bar — visible only on mobile. Centers the brand, hamburger on left.
       z-index: 50 so it sits above the drawer overlay (35) and the drawer (40),
       which keeps the hamburger reachable while the drawer is open. */
    .topbar {
        display: flex; align-items: center; justify-content: space-between;
        position: sticky; top: 0; z-index: 50;
        height: var(--topbar-h);
        padding: 0 14px;
        background: linear-gradient(180deg, var(--surface-1), var(--surface-0));
        border-bottom: 1px solid var(--hairline);
    }
    .topbar-burger {
        background: transparent; border: 0; padding: 6px; cursor: pointer;
        width: 36px; height: 36px;
        display: inline-flex; flex-direction: column; gap: 4px;
        align-items: center; justify-content: center;
        border-radius: var(--radius-md);
        transition: background .12s var(--ease-out);
    }
    .topbar-burger:hover { background: var(--surface-2); }
    .topbar-burger > span {
        display: block; width: 18px; height: 2px;
        background: var(--text-primary); border-radius: 2px;
        transition: transform .25s var(--ease-out), opacity .15s var(--ease-out);
    }
    /* Hamburger morphs to an X when the drawer is open. */
    .app-shell.drawer-open .topbar-burger > span:nth-child(1) {
        transform: translateY(6px) rotate(45deg);
    }
    .app-shell.drawer-open .topbar-burger > span:nth-child(2) { opacity: 0; }
    .app-shell.drawer-open .topbar-burger > span:nth-child(3) {
        transform: translateY(-6px) rotate(-45deg);
    }
    .topbar-brand {
        display: flex; align-items: center; gap: 8px;
        font-weight: 700; letter-spacing: -.01em;
    }
    .topbar-brand .brand-mark { width: 22px; height: 22px; border-radius: 6px; }
    .topbar-brand .brand-mark::after { inset: 4px; border-radius: 3px; }

    /* Sidebar becomes a slide-in drawer that lives BELOW the topbar so the
       hamburger and brand always stay visible above it. */
    .sidebar {
        position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
        width: min(82vw, 320px);
        /* 100vh on phones counts the area behind the URL bar, which pushes the
           footer below the visible viewport. dvh tracks the *visible* height
           (URL-bar collapse/expand) so everything fits; the vh line is the
           fallback for browsers without dvh support. */
        height: calc(100vh - var(--topbar-h));
        height: calc(100dvh - var(--topbar-h));
        transform: translateX(-100%);
        transition: transform .26s var(--ease-out);
        box-shadow: 0 0 0 transparent;
        z-index: 40;
        padding-top: 18px;
        /* Clear the home indicator on notched phones so the last item / footer
           is fully tappable. */
        padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
        /* Make the drawer itself scrollable on touch with momentum. */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    .app-shell.drawer-open .sidebar {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }
    /* Hide the in-sidebar brand on mobile — the topbar already shows it. */
    .sidebar > .brand { display: none; }

    /* Backdrop dims the page behind the open drawer. */
    .drawer-overlay {
        display: block;
        position: fixed; inset: 0; z-index: 35;
        background: rgba(0, 0, 0, .55);
        opacity: 0; pointer-events: none;
        transition: opacity .2s var(--ease-out);
    }
    .app-shell.drawer-open .drawer-overlay {
        opacity: 1; pointer-events: auto;
    }

    /* Content padding tightens; nothing should run edge-to-edge on phones
       because the topbar's hairline already provides the boundary. */
    .content { padding: 18px 16px 28px; }

    /* Page header packs vertically on phones. */
    .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .page-header h1 { font-size: 1.45rem; }
    .page-title .crumbs { font-size: .8rem; }

    /* Grids stack. */
    .grid-3 { grid-template-columns: 1fr; }
    .ws-detail-grid { grid-template-columns: 1fr; }

    /* Chat — master/detail navigation -------------------------------------
       Pinned to the viewport with position: fixed so it bypasses every
       parent-layout concern (.content padding, .app-shell min-height,
       100vh-vs-100dvh URL-bar quirks). Top: topbar height; bottom: 0 of the
       *layout viewport* — which on mobile browsers tracks the visible area
       (URL bar collapse/expand) automatically.
       z-index sits below the topbar (50) and the drawer (40) so those
       always overlay the chat. */
    .chat-shell {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        right: 0;
        bottom: 0;
        height: auto;               /* top + bottom determine height */
        grid-template-columns: 1fr;
        margin: 0;
        padding: 0;
        gap: 0;
        background: var(--surface-0);
        z-index: 10;
        overflow: hidden;
    }
    .chat-list-pane,
    .chat-pane {
        padding: 12px 14px 0;
        min-height: 0;              /* flex children with overflow need this */
    }

    /* When no chat is selected: list takes the full viewport, pane is hidden. */
    .chat-shell:not(.has-chat) .chat-pane { display: none; }
    /* When a chat IS selected: pane takes the full viewport, list is hidden. */
    .chat-shell.has-chat .chat-list-pane { display: none; }

    .chat-back { display: inline-flex; }
    .chat-header { padding-bottom: 10px; margin-bottom: 10px; }
    .chat-header-meta h2 { font-size: 1rem; }
    .chat-header-actions { gap: 4px; }

    .chat-stream { padding: 0 4px 8px 0; }
    .message { max-width: 92%; }

    /* Composer is the last flex child of chat-pane; chat-stream above it
       has flex:1 + overflow-y:auto, so the composer naturally pins to the
       bottom without `position: sticky` and without negative margins. */
    .chat-composer {
        position: static;
        margin: 0 -14px;
        padding: 10px 14px env(safe-area-inset-bottom, 10px);
        background: var(--surface-0);
        border-top: 1px solid var(--hairline);
        border-bottom: 0;
        flex-shrink: 0;
    }
    .chat-composer textarea { min-height: 44px; max-height: 120px; }

    /* Table affordance: highlight the scroll mask so it reads clearly. */
    .table-wrap::after { width: 28px; }

    /* On phones the drawer fills the screen for thumb-friendly scrolling.
       Header / body / footer keep their roles; the body's safe-area-aware
       padding-bottom keeps the last button clear of the iOS home-indicator
       gesture bar. */
    .drawer { width: 100%; max-width: 100vw; }
    .drawer-header { padding: 14px 18px; }
    .drawer-body { padding: 18px 18px 8px; }
    .drawer-footer {
        padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
    }

    /* Auth screens — let the card breathe on tiny screens. */
    .auth-card { padding: 24px 22px; border-radius: var(--radius-lg); }

    /* Buttons get a touch-friendly minimum. */
    .btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
        min-height: 40px; padding: 9px 14px;
    }

    /* Workspace switcher should never overflow the drawer on phones. */
    .ws-menu { max-height: 60vh; }
}

/* Honor reduced-motion preferences — drawer slides in instantly, message
   bubbles don't transform on hover, etc. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}

.no-cursor { cursor: none; }
.no-select {
    -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Safari */
    -khtml-user-select: none; /* Konqueror HTML */
    -moz-user-select: none; /* Old versions of Firefox */
    -ms-user-select: none; /* Internet Explorer/Edge */
    user-select: none; /* Non-prefixed version, currently
                                  supported by Chrome, Edge, Opera and Firefox */
}
/* --- Language switcher -------------------------------------------------- */
/* Sits at the top of every surface: the mobile top bar, the desktop sidebar's
   brand row, and the corner of the signed-out auth shell. Visually a sibling of
   .theme-toggle so the two controls read as one cluster. */
.lang-switcher { position: relative; display: inline-flex; flex: 0 0 auto; }
.lang-toggle {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface-2); color: var(--text-secondary);
    border: 1px solid var(--hairline); border-radius: 999px;
    padding: 6px 10px; cursor: pointer;
    font: inherit; font-size: .78rem; font-weight: 600;
    letter-spacing: .04em;
    transition: background .15s var(--ease-out), color .15s var(--ease-out),
                border-color .15s var(--ease-out), transform .08s var(--ease-out);
}
.lang-toggle:hover {
    background: var(--surface-3); color: var(--text-primary);
    border-color: var(--accent-500);
}
.lang-toggle:active { transform: scale(.96); }
.lang-toggle-icon { display: inline-flex; line-height: 0; color: var(--accent-500); }
.lang-toggle-label { line-height: 1; }
.lang-caret { font-size: .7rem; opacity: .7; line-height: 1; }

/* Compact variant used in the sidebar brand row and the mobile top bar:
   circular, icon + code only, no caret. */
.lang-switcher.is-compact .lang-toggle { padding: 6px 9px; border-radius: var(--radius-md); }
.lang-switcher.is-compact .lang-caret { display: none; }

.lang-menu {
    position: absolute; top: calc(100% + 6px); right: 0; z-index: 60;
    min-width: 190px;
    background: var(--surface-2); border: 1px solid var(--hairline);
    border-radius: var(--radius-md); padding: 6px;
    box-shadow: var(--shadow-md);
    display: flex; flex-direction: column; gap: 2px;
}
.lang-menu-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; text-align: left;
    background: transparent; border: 0; color: var(--text-primary);
    padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer;
    font: inherit; font-size: .86rem;
    transition: background .12s var(--ease-out);
}
.lang-menu-item:hover { background: var(--surface-3); }
.lang-menu-item.active { background: var(--accent-tint-12); color: var(--accent-400); }
.lang-menu-code {
    flex: 0 0 26px;
    font-size: .66rem; font-weight: 700; letter-spacing: .08em;
    color: var(--text-tertiary); text-align: center;
    border: 1px solid var(--hairline); border-radius: 4px; padding: 2px 0;
}
.lang-menu-item.active .lang-menu-code { color: var(--accent-400); border-color: var(--accent-500); }
.lang-menu-name { flex: 1; min-width: 0; }
.lang-menu-check { color: var(--accent-500); font-size: .8rem; }

/* Let the brand row push the picker to its trailing edge without squeezing
   the wordmark. */
.brand .brand-text { flex: 1; min-width: 0; }
.brand .lang-switcher { margin-left: auto; }

/* Signed-out shell: pin the picker to the top-right corner of the viewport so
   the language can be chosen before there's a sidebar to host it. */
.auth-shell { position: relative; }
.auth-lang { position: absolute; top: 18px; right: 18px; z-index: 5; }

@media (max-width: 520px) {
    .auth-lang { top: 12px; right: 12px; }
    .lang-switcher.is-compact .lang-toggle-label { display: none; }
}
