/* =============================================================================
   Reamind — Branded theme with light/dark modes
   Uses Reamind brand blues. Light mode default, dark mode toggle.
   ========================================================================== */

/* -----------------------------------------------------------------------------
   Design Tokens — Light mode (default)
   -------------------------------------------------------------------------- */
:root {
    /* Surfaces */
    --bg-canvas: #FFFFFF;
    --bg-surface: #F8FAFC;
    --bg-elevated: #F1F5F9;
    --bg-hover: #E2E8F0;
    --bg-input: #F8FAFC;

    /* Borders */
    --border-subtle: #E2E8F0;
    --border-default: #CBD5E1;
    --border-strong: #94A3B8;
    --border-focus: #1D4ED8;

    /* Text */
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-tertiary: #64748B;
    --text-disabled: #CBD5E1;
    --text-inverse: #FFFFFF;

    /* Brand accent */
    --color-accent: #1D4ED8;
    --color-accent-hover: #2563EB;
    --color-accent-light: #8FDBFE;
    --color-accent-text: #1E3A8A;

    /* Status (used sparingly) */
    --color-danger: #DC2626;
    --color-danger-bg: rgba(220, 38, 38, 0.06);
    --color-success: #047857;
    --color-success-bg: rgba(5, 150, 105, 0.06);
    --color-warning: #92400E;
    --color-warning-bg: rgba(217, 119, 6, 0.06);

    /* Scrollbar */
    --scrollbar-thumb: #CBD5E1;
    --scrollbar-thumb-hover: #94A3B8;

    /* Shadows */
    --shadow-sidebar: 0 0 40px rgba(0, 0, 0, 0.1);
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.08);

    /* Typography */
    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
    --fs-xs: 11px;
    --fs-sm: 13px;
    --fs-base: 14px;
    --fs-md: 15px;
    --fs-lg: 17px;
    --fs-xl: 20px;
    --fs-2xl: 24px;
    --fs-3xl: 32px;
    --fw-regular: 400;
    --fw-medium: 500;
    --fw-semibold: 600;
    --lh-tight: 1.25;
    --lh-normal: 1.5;
    --lh-relaxed: 1.65;

    /* Spacing scale */
    --s-1: 4px;
    --s-2: 8px;
    --s-3: 12px;
    --s-4: 16px;
    --s-5: 20px;
    --s-6: 24px;
    --s-8: 32px;
    --s-10: 40px;
    --s-12: 48px;
    --s-16: 64px;

    /* Radius */
    --r-sm: 4px;
    --r-md: 6px;
    --r-lg: 8px;
    --r-xl: 12px;
    --r-full: 999px;

    /* Layout */
    --sidebar-width: 260px;
    --composer-height: 96px;
    --max-content: 760px;

    /* Motion */
    --t-fast: 0.12s ease;
    --t-base: 0.18s ease;
}

/* -----------------------------------------------------------------------------
   Design Tokens — Dark mode
   -------------------------------------------------------------------------- */
[data-theme="dark"] {
    --bg-canvas: #060D1F;
    --bg-surface: #0C1425;
    --bg-elevated: #131C30;
    --bg-hover: #1A2540;
    --bg-input: #0A1220;

    --border-subtle: #1A2540;
    --border-default: #243352;
    --border-strong: #3B5080;
    --border-focus: #60A5FA;

    --text-primary: #EFF6FF;
    --text-secondary: #93C5FD;
    --text-tertiary: #60A5FA;
    --text-disabled: #3B5080;
    --text-inverse: #060D1F;

    --color-accent: #2563EB;
    --color-accent-hover: #60A5FA;
    --color-accent-light: rgba(96, 165, 250, 0.15);
    --color-accent-text: #93C5FD;

    --color-danger: #EF4444;
    --color-danger-bg: rgba(239, 68, 68, 0.10);
    --color-success: #10B981;
    --color-success-bg: rgba(16, 185, 129, 0.10);
    --color-warning: #F59E0B;
    --color-warning-bg: rgba(245, 158, 11, 0.10);

    --scrollbar-thumb: #243352;
    --scrollbar-thumb-hover: #3B5080;

    --shadow-sidebar: 0 0 40px rgba(0, 0, 0, 0.6);
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* -----------------------------------------------------------------------------
   Base reset
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg-canvas);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: var(--lh-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--text-primary);
    text-decoration: underline;
    text-decoration-color: var(--border-strong);
    text-underline-offset: 3px;
    transition: text-decoration-color var(--t-fast);
}
a:hover { text-decoration-color: var(--text-primary); }

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
    letter-spacing: -0.01em;
}
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }

p { margin: 0 0 var(--s-3); }

hr {
    border: none;
    border-top: 1px solid var(--border-subtle);
    margin: var(--s-6) 0;
}

::selection { background: var(--color-accent); color: #FFFFFF; }

/* Custom scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* -----------------------------------------------------------------------------
   Typography utilities
   -------------------------------------------------------------------------- */
.text-xs { font-size: var(--fs-xs); }
.text-sm { font-size: var(--fs-sm); }
.text-md { font-size: var(--fs-md); }
.text-lg { font-size: var(--fs-lg); }
.text-muted { color: var(--text-secondary); }
.text-dim { color: var(--text-tertiary); }
.text-mono { font-family: var(--font-mono); }
.text-uppercase { text-transform: uppercase; letter-spacing: 0.05em; }
.font-medium { font-weight: var(--fw-medium); }
.font-semibold { font-weight: var(--fw-semibold); }

/* -----------------------------------------------------------------------------
   Layout primitives
   -------------------------------------------------------------------------- */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--s-6);
}

.container-narrow {
    width: 100%;
    max-width: var(--max-content);
    margin: 0 auto;
    padding: 0 var(--s-6);
}

.stack { display: flex; flex-direction: column; }
.stack-2 > * + * { margin-top: var(--s-2); }
.stack-3 > * + * { margin-top: var(--s-3); }
.stack-4 > * + * { margin-top: var(--s-4); }
.stack-6 > * + * { margin-top: var(--s-6); }

.row { display: flex; align-items: center; gap: var(--s-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.row-wrap { flex-wrap: wrap; }

/* -----------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    font-family: inherit;
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    line-height: 1;
    padding: 0 var(--s-4);
    height: 36px;
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    background: var(--bg-elevated);
    color: var(--text-primary);
    cursor: pointer;
    text-decoration: none;
    transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
    white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.btn:disabled, .btn.is-disabled { opacity: 0.5; pointer-events: none; }

.btn-primary {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #FFFFFF;
    font-weight: var(--fw-semibold);
}
.btn-primary:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }

.btn-ghost {
    background: transparent;
    border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-elevated); border-color: var(--border-default); }

.btn-muted { /* alias for default */ }

.btn-danger {
    background: transparent;
    border-color: var(--border-default);
    color: var(--color-danger);
}
.btn-danger:hover { background: var(--color-danger-bg); border-color: var(--color-danger); }

.btn-summary-done {
    background: var(--color-success-bg);
    border-color: var(--color-success);
    color: var(--color-success);
    white-space: nowrap;
}
.btn-summary-done:hover { background: var(--color-success); color: #fff; }

.btn-icon {
    width: 36px;
    padding: 0;
}

.btn-sm { height: 28px; padding: 0 var(--s-3); font-size: var(--fs-xs); }
.btn-lg { height: 44px; padding: 0 var(--s-5); font-size: var(--fs-md); }

.btn-block { width: 100%; }

/* Loading spinner inside button */
.btn .spinner {
    width: 12px;
    height: 12px;
    border-radius: var(--r-full);
    border: 2px solid currentColor;
    border-top-color: transparent;
    display: none;
    animation: spin 0.7s linear infinite;
}
.btn.is-loading .spinner { display: inline-block; }
.btn.is-loading { pointer-events: none; opacity: 0.7; }

@keyframes spin { to { transform: rotate(360deg); } }

/* -----------------------------------------------------------------------------
   Form controls
   -------------------------------------------------------------------------- */
label {
    display: block;
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    color: var(--text-secondary);
    margin-bottom: var(--s-2);
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="url"], input[type="tel"], input[type="date"],
input[type="datetime-local"], select, textarea {
    width: 100%;
    font-family: inherit;
    font-size: var(--fs-base);
    line-height: 1.4;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    padding: 10px 12px;
    transition: border-color var(--t-fast), background var(--t-fast);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    background: var(--bg-surface);
}

input::placeholder, textarea::placeholder { color: var(--text-tertiary); }

textarea { resize: vertical; min-height: 80px; }

select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23A1A1A1' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

input[type="checkbox"], input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--text-primary);
    margin: 0;
}

.form-field { margin-bottom: var(--s-4); }
.form-field-row { display: flex; gap: var(--s-3); }
.form-field-row > * { flex: 1; }

.form-help {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    margin-top: var(--s-2);
}

ul.errorlist {
    list-style: none;
    margin: var(--s-2) 0 0;
    padding: 0;
    color: var(--color-danger);
    font-size: var(--fs-xs);
}

.errornote, .alert-error {
    background: var(--color-danger-bg);
    border: 1px solid var(--color-danger);
    color: var(--color-danger);
    border-radius: var(--r-lg);
    padding: var(--s-3) var(--s-4);
    margin-bottom: var(--s-4);
    font-size: var(--fs-sm);
}

.alert-info {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    border-radius: var(--r-lg);
    padding: var(--s-3) var(--s-4);
    margin-bottom: var(--s-4);
    font-size: var(--fs-sm);
}

.alert-success {
    background: var(--color-success-bg);
    border: 1px solid var(--color-success);
    color: var(--color-success);
    border-radius: var(--r-lg);
    padding: var(--s-3) var(--s-4);
    margin-bottom: var(--s-4);
    font-size: var(--fs-sm);
}

/* -----------------------------------------------------------------------------
   Cards / Panels
   -------------------------------------------------------------------------- */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-6);
    box-shadow: var(--shadow-card);
}
.card-elevated { background: var(--bg-elevated); }
.card-tight { padding: var(--s-4); }
.card-title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); margin-bottom: var(--s-3); }
.card-subtitle { font-size: var(--fs-sm); color: var(--text-secondary); margin-bottom: var(--s-4); }

.panel { /* alias */
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-4);
}

/* -----------------------------------------------------------------------------
   Badges & chips
   -------------------------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    height: 22px;
    padding: 0 var(--s-2);
    border-radius: var(--r-full);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    line-height: 1;
    white-space: nowrap;
}
.badge-success { color: var(--color-success); border-color: var(--color-success); background: var(--color-success-bg); }
.badge-danger { color: var(--color-danger); border-color: var(--color-danger); background: var(--color-danger-bg); }
.badge-warning { color: var(--color-warning); border-color: var(--color-warning); background: var(--color-warning-bg); }

/* -----------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-sm);
}
.table th, .table td {
    text-align: left;
    padding: var(--s-3) var(--s-4);
    border-bottom: 1px solid var(--border-subtle);
}
.table th {
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--bg-surface);
}
.table tbody tr:hover { background: var(--bg-surface); }
.table tbody tr:last-child td { border-bottom: none; }
.table-wrap {
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-gutter: stable;
    background: var(--bg-canvas);
}
.card > .table-wrap {
    border: none;
    margin: calc(-1 * var(--s-6));
    margin-top: 0;
    width: calc(100% + 2 * var(--s-6));
    border-radius: 0 0 var(--r-xl) var(--r-xl);
}
.table-wrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-sm);
}
.table-wrap th, .table-wrap td {
    text-align: left;
    padding: var(--s-3) var(--s-4);
    border-bottom: 1px solid var(--border-subtle);
}
.table-wrap th {
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--bg-surface);
}
.table-wrap tbody tr:last-child td { border-bottom: none; }
.table-wrap tbody tr:hover { background: var(--bg-hover); }

/* -----------------------------------------------------------------------------
   App shell (used for non-chat pages)
   -------------------------------------------------------------------------- */
.app-shell {
    width: min(1100px, 100%);
    margin: 0 auto;
    padding: var(--s-6) var(--s-4) var(--s-12);
}

.page-card { /* legacy alias used by some templates */
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-6);
}

.page-title {
    margin: 0 0 var(--s-2);
    font-size: var(--fs-2xl);
}

.top-links {
    display: flex;
    gap: var(--s-2);
    align-items: center;
    margin-bottom: var(--s-5);
    flex-wrap: wrap;
}

.muted { color: var(--text-secondary); }

/* -----------------------------------------------------------------------------
   Auth pages — centered card on black canvas
   -------------------------------------------------------------------------- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--s-6);
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-8);
    box-shadow: var(--shadow-card);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    margin-bottom: var(--s-6);
}
.auth-brand-logo {
    width: 32px;
    height: 32px;
    border-radius: var(--r-md);
    background: var(--color-accent);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--fw-semibold);
    font-size: var(--fs-lg);
}
.auth-brand-name {
    font-size: var(--fs-lg);
    font-weight: var(--fw-semibold);
}

.auth-title {
    font-size: var(--fs-2xl);
    margin-bottom: var(--s-2);
}
.auth-subtitle {
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    margin-bottom: var(--s-6);
}

.auth-actions { margin-top: var(--s-6); }
.auth-card-wide { max-width: 440px; }
.auth-footer-secondary { margin-top: var(--s-3); }
.form-field.is-invalid input,
.form-field.is-invalid select,
.form-field.is-invalid textarea { border-color: var(--color-danger); }
.field-errors { margin: var(--s-1) 0 0; padding: 0; color: var(--color-danger); font-size: var(--fs-xs); list-style: none; }
.field-help { margin-top: var(--s-1); color: var(--text-tertiary); font-size: var(--fs-xs); line-height: 1.5; }
.field-help ul { margin: var(--s-2) 0 0; padding-left: var(--s-4); }
.auth-footer {
    margin-top: var(--s-5);
    padding-top: var(--s-5);
    border-top: 1px solid var(--border-subtle);
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    text-align: center;
}

/* -----------------------------------------------------------------------------
   Chat layout (ChatGPT-style)
   -------------------------------------------------------------------------- */
.chat-shell {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    --doc-panel-width: min(620px, 46vw);
}

/* In-chat document side panel (split view) */
.doc-panel {
    display: none;
    position: relative;
    flex: 0 0 var(--doc-panel-width);
    width: var(--doc-panel-width);
    min-width: 0;
    flex-direction: column;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-default);
}
.chat-shell.panel-open .doc-panel { display: flex; }
.chat-shell.panel-open .composer-shell { right: var(--doc-panel-width); }
.doc-panel-resizer {
    position: absolute;
    left: -7px; top: 0; bottom: 0;
    width: 14px;
    cursor: col-resize;
    z-index: 10;
}
.doc-panel-resizer:hover { background: var(--border-strong); }
.doc-panel-header {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-3) var(--s-4);
    border-bottom: 1px solid var(--border-subtle);
    flex: 0 0 auto;
}
.doc-panel-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
}
.doc-panel-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px; height: 28px;
    border: 1px solid var(--border-default);
    border-radius: var(--r-md);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
}
.doc-panel-close:hover { color: var(--text-primary); border-color: var(--border-strong); }
.doc-panel-body { position: relative; flex: 1; min-height: 0; }
.doc-panel-frame { width: 100%; height: 100%; border: 0; background: var(--bg-canvas); }
.doc-panel-message {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--s-3);
    padding: var(--s-5);
    text-align: center;
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    background: var(--bg-surface);
}
.doc-panel-message[hidden] { display: none; }
.doc-panel-spinner {
    width: 24px; height: 24px;
    border: 2px solid var(--border-default);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: doc-panel-spin 0.7s linear infinite;
}
@keyframes doc-panel-spin { to { transform: rotate(360deg); } }
.doc-panel.is-resizing { user-select: none; }
.doc-panel.is-resizing .doc-panel-frame { pointer-events: none; }
body.doc-panel-resizing {
    cursor: col-resize;
    user-select: none;
}
body.doc-panel-modal-open { overflow: hidden; }
.source-cite { cursor: pointer; }
.source-collection-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    margin-left: 2px;
    border-radius: 4px;
    background: var(--surface-soft, rgba(255,255,255,0.08));
    color: var(--text-secondary, #999);
    vertical-align: middle;
    line-height: 1.4;
    letter-spacing: 0.02em;
}

@media (max-width: 880px) {
    .chat-shell.panel-open .doc-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        z-index: 40;
        flex-basis: auto;
    }
    .chat-shell.panel-open .composer-shell { right: 0; }
}

/* Sidebar */
.chat-sidebar {
    flex: 0 0 var(--sidebar-width);
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    transition: margin-left var(--t-base);
    position: relative;
}

.sidebar-resizer {
    position: absolute;
    right: -4px;
    top: 0;
    bottom: 0;
    width: 8px;
    cursor: col-resize;
    z-index: 10;
}
.sidebar-resizer:hover,
.sidebar-resizer.active {
    background: var(--color-accent);
    opacity: 0.4;
}

.chat-sidebar-header {
    padding: var(--s-4);
    border-bottom: 1px solid var(--border-subtle);
}

.chat-sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    font-weight: var(--fw-semibold);
    font-size: var(--fs-md);
    margin-bottom: var(--s-4);
}
.chat-sidebar-brand .brand-mark {
    width: 28px;
    height: 28px;
    border-radius: var(--r-md);
    background: var(--color-accent);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
}

.new-chat-form { margin: 0; }

.chat-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--s-2) var(--s-3);
}

.chat-sidebar-section-label {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--s-3) var(--s-2) var(--s-2);
}

.chat-row {
    position: relative;
    border-radius: var(--r-md);
    transition: background var(--t-fast);
    margin-bottom: 2px;
}
.chat-row:hover { background: var(--bg-elevated); }
.chat-row.active { background: var(--bg-elevated); }

.chat-row-link {
    display: block;
    width: 100%;
    min-width: 0;
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    font-size: var(--fs-sm);
    font-family: inherit;
    cursor: pointer;
    padding: var(--s-2) calc(var(--s-3) + 32px) var(--s-2) var(--s-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-decoration: none;
}

.chat-row-delete-form {
    position: absolute;
    top: 50%;
    right: var(--s-2);
    margin: 0;
    transform: translateY(-50%);
}

.chat-row-delete {
    width: 28px;
    height: 28px;
    border-radius: var(--r-sm);
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--t-fast), color var(--t-fast);
}
.chat-row:hover .chat-row-delete { opacity: 1; }
.chat-row-delete:hover { color: var(--color-danger); background: var(--bg-hover); }

.chat-sidebar-footer {
    padding: var(--s-3) var(--s-4);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-md);
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}
.user-chip-avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--r-full);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-xs);
    color: var(--text-primary);
    font-weight: var(--fw-semibold);
    flex: 0 0 28px;
}

/* Main chat pane */
.chat-main {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-canvas);
}

.chat-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--s-3) var(--s-5);
    border-bottom: 1px solid var(--border-subtle);
    min-height: 56px;
}
.chat-topbar-title {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: var(--s-2);
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
}
.chat-workspace-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-collaboration-status { display: flex; flex: 0 1 auto; align-items: center; gap: 4px; }
.chat-collaboration-status .badge { max-width: 180px; overflow: hidden; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.chat-topbar-actions { display: flex; flex: 0 0 auto; align-items: center; gap: var(--s-2); }
.chat-export-wrap { position: relative; }
.chat-export-menu { position: absolute; top: calc(100% + 4px); right: 0; z-index: 100; display: flex; min-width: 170px; flex-direction: column; gap: 2px; padding: var(--s-2); border: 1px solid var(--border-default); border-radius: var(--r-lg); background: var(--bg-surface); box-shadow: var(--shadow-card-hover); }
.chat-export-menu[hidden] { display: none !important; }
.chat-export-menu > a { padding: var(--s-2) var(--s-3); border-radius: var(--r-md); color: var(--text-primary); font-size: var(--fs-xs); text-decoration: none; }
.chat-export-menu > a:hover { background: var(--bg-elevated); }

.sidebar-toggle {
    display: none;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: var(--r-md);
}
.sidebar-toggle:hover { background: var(--bg-elevated); }

.chat-feed {
    flex: 1;
    overflow-y: auto;
    padding: var(--s-6) var(--s-4) 160px;
}
.chat-jump-latest { position: absolute; left: 50%; bottom: 118px; z-index: 12; display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-3); border: 1px solid var(--border-default); border-radius: 999px; background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-card-hover); font: inherit; font-size: var(--fs-xs); transform: translateX(-50%); cursor: pointer; }
.chat-jump-latest[hidden] { display: none; }

.chat-feed-inner {
    max-width: var(--max-content);
    margin: 0 auto;
}

.chat-history-loader {
    display: flex;
    justify-content: center;
    padding: var(--s-3) 0 var(--s-5);
}

/* Empty state */
.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 10vh var(--s-4) var(--s-8);
    color: var(--text-secondary);
}
.chat-empty-title {
    font-size: var(--fs-2xl);
    color: var(--text-primary);
    margin-bottom: var(--s-3);
}
.chat-empty-subtitle {
    font-size: var(--fs-sm);
    margin-bottom: var(--s-8);
    max-width: 480px;
}
.chat-starter-grid { display: grid; width: min(680px, 100%); grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-3); }
.chat-starter-grid > button { display: flex; min-width: 0; min-height: 96px; align-items: flex-start; justify-content: center; flex-direction: column; gap: 4px; padding: var(--s-4); border: 1px solid var(--border-subtle); border-radius: var(--r-xl); background: var(--bg-surface); color: var(--text-primary); font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-medium); text-align: left; cursor: pointer; transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast); }
.chat-starter-grid > button:hover { border-color: var(--border-strong); background: var(--bg-elevated); transform: translateY(-1px); }
.chat-starter-grid > button span { color: var(--text-tertiary); font-size: var(--fs-xs); font-weight: var(--fw-regular); line-height: 1.4; }
.chat-empty-upload-link { margin-top: var(--s-4); color: var(--text-secondary); font-size: var(--fs-xs); text-decoration: none; }
.chat-empty-upload-link:hover { color: var(--text-primary); }


/* Messages */
.message {
    margin-bottom: var(--s-6);
    display: flex;
}
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.message .bubble {
    max-width: 90%;
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-xl);
    line-height: var(--lh-relaxed);
}

.message.user .bubble {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    color: var(--text-primary);
    border-bottom-right-radius: var(--r-sm);
}

.message.assistant .bubble {
    background: transparent;
    border: none;
    padding-left: 0;
    padding-right: 0;
    max-width: 100%;
    width: 100%;
    color: var(--text-primary);
}

.bubble .content {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: var(--fs-md);
}

/* Citation chip */
.citation-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    margin: 0 2px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--r-sm);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: var(--fw-semibold);
    text-decoration: none;
    line-height: 1;
    vertical-align: super;
    transition: background var(--t-fast), color var(--t-fast);
}
.citation-chip:hover {
    background: var(--color-accent);
    color: #FFFFFF;
    border-color: var(--color-accent);
}

/* Result items (semantic search) */
.result-item {
    margin-bottom: var(--s-4);
    padding: var(--s-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
}
.result-item h3 { font-size: var(--fs-md); margin-bottom: var(--s-2); }
.result-item p { margin: 0; color: var(--text-secondary); font-size: var(--fs-sm); line-height: var(--lh-relaxed); }

.chunks-link {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    margin-top: var(--s-3);
    padding: 6px var(--s-3);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    color: var(--text-primary);
    border-radius: var(--r-md);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    text-decoration: none;
}
.chunks-link:hover { background: var(--bg-hover); border-color: var(--border-strong); }

.redo-filter {
    margin: var(--s-3) 0;
    padding: var(--s-3) var(--s-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

.filter-applied-tag {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 var(--s-2);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--r-full);
    color: var(--text-primary);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
}

.scope-checkboxes {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--s-2);
    padding: var(--s-3);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    max-height: 184px;
    overflow-y: auto;
}
.scope-checkbox {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    color: var(--text-primary);
    font-size: var(--fs-sm);
    font-weight: var(--fw-regular);
    margin: 0;
}
.filter-toggle {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    height: 32px;
    padding: 0 var(--s-3);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    color: var(--text-primary);
    font-size: var(--fs-sm);
    font-weight: var(--fw-regular);
    margin: 0;
    cursor: pointer;
}

.inline-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    margin-bottom: var(--s-3);
    flex-wrap: wrap;
}

.copy-status {
    color: var(--color-success);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
}

/* Composer */
.composer-shell {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: var(--s-3) var(--s-4) max(var(--s-5), env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--bg-canvas) 60%, transparent);
    pointer-events: none;
}

.composer-wrap {
    max-width: var(--max-content);
    margin: 0 auto;
    pointer-events: auto;
}

.composer {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--r-xl);
    padding: var(--s-3);
    transition: border-color var(--t-fast);
}
.composer:focus-within { border-color: var(--border-strong); }
.composer form { margin: 0; }

.composer-main {
    display: flex;
    align-items: flex-end;
    gap: var(--s-2);
}

.composer-main textarea {
    flex: 1;
    border: none;
    background: transparent;
    padding: var(--s-2) var(--s-2);
    min-height: 28px;
    max-height: 200px;
    font-size: var(--fs-md);
    line-height: var(--lh-normal);
    resize: none;
}
.composer-main textarea:focus { background: transparent; border: none; }

.settings-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    border: 1px solid var(--border-default);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: var(--fs-lg);
    cursor: pointer;
    flex: 0 0 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--t-fast), color var(--t-fast);
}
.settings-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.mic-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    border: 1px solid var(--border-default);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    flex: 0 0 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.mic-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.mic-btn.is-recording {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
    color: #ef4444;
}
.mic-btn .mic-pulse {
    display: none;
    position: absolute;
    inset: -3px;
    border-radius: var(--r-md);
    border: 2px solid #ef4444;
    animation: mic-pulse-ring 1.5s ease-out infinite;
}
.mic-btn.is-recording .mic-pulse { display: block; }
@keyframes mic-pulse-ring {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.3); }
}
.mic-btn.is-unsupported { display: none; }

.send-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    padding: 0;
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #FFFFFF;
    border-radius: var(--r-md);
    font-weight: var(--fw-semibold);
}
.send-btn:hover { background: var(--color-accent-hover); }
.send-btn .label { display: none; }
.send-btn::before {
    content: "↑";
    font-size: 18px;
    line-height: 1;
}
.send-btn.is-loading::before { display: none; }

.settings-panel {
    display: none;
    margin-top: var(--s-3);
    padding-top: var(--s-3);
    border-top: 1px solid var(--border-subtle);
}
.settings-panel.open { display: block; }

.settings-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--s-3);
}
.settings-field label {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--s-1);
}
.settings-field select {
    height: 32px;
    padding: 0 var(--s-3);
    font-size: var(--fs-sm);
}
.settings-field-scopes { grid-row: span 2; }
.settings-field-dates { grid-column: span 2; }
.settings-date-range { display: flex; min-width: 0; align-items: center; gap: var(--s-2); }
.settings-date-range input { min-width: 0; height: 32px; flex: 1; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.settings-date-range span { color: var(--text-tertiary); font-size: var(--fs-xs); }

/* -----------------------------------------------------------------------------
   Dashboard layout
   -------------------------------------------------------------------------- */
.dash-shell {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

.dash-sidebar {
    flex: 0 0 var(--dash-sidebar-width, 240px);
    width: var(--dash-sidebar-width, 240px);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    padding: var(--s-5) var(--s-3);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
}

.dash-sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    font-weight: var(--fw-semibold);
    margin-bottom: var(--s-6);
    padding: 0 var(--s-3);
}

.dash-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.dash-nav-item {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--fs-sm);
    transition: background var(--t-fast), color var(--t-fast);
}
.dash-nav-item:hover { background: var(--bg-elevated); color: var(--text-primary); text-decoration: none; }
.dash-nav-item.active {
    background: var(--color-accent-light);
    color: var(--text-primary);
    box-shadow: inset 3px 0 0 var(--color-accent);
    font-weight: var(--fw-semibold);
}
.dash-nav-item.active svg { color: var(--color-accent-hover); }
.dash-nav-section {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--s-4) var(--s-3) var(--s-1);
}

.dash-main {
    flex: 1;
    min-width: 0;
    padding: var(--s-8);
    overflow-x: auto;
    max-width: 1100px;
    margin: 0 auto;
}
.dash-main > .card { margin-bottom: var(--s-6); }
.dash-header {
    margin-bottom: var(--s-6);
}
.dash-header h1 {
    font-size: var(--fs-2xl);
    margin-bottom: var(--s-2);
}
.dash-header .muted { font-size: var(--fs-sm); }

.dash-section { margin-bottom: var(--s-8); }
.dash-section-title {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    margin-bottom: var(--s-3);
}

/* Stats tile */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--s-4);
    margin-bottom: var(--s-6);
}
.stat-tile {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-5);
}
.stat-tile-label {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--s-2);
}
.stat-tile-value {
    font-size: var(--fs-3xl);
    font-weight: var(--fw-semibold);
    line-height: 1;
}
.stat-tile-sub {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    margin-top: var(--s-2);
}

/* -----------------------------------------------------------------------------
   Landing
   -------------------------------------------------------------------------- */
.landing-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--s-8) var(--s-4);
}
.landing-card {
    max-width: 520px;
    width: 100%;
}
.landing-title {
    font-size: var(--fs-3xl);
    margin-bottom: var(--s-3);
}
.landing-tenant-list {
    list-style: none;
    padding: 0;
    margin: var(--s-5) 0 0;
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
}
.landing-tenant-list a {
    display: block;
    padding: var(--s-3) var(--s-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    text-decoration: none;
    color: var(--text-primary);
    transition: background var(--t-fast), border-color var(--t-fast);
}
.landing-tenant-list a:hover {
    background: var(--bg-elevated);
    border-color: var(--border-default);
    text-decoration: none;
}

/* -----------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 880px) {
    :root { --sidebar-width: 240px; }

    .chat-shell { position: relative; }
    .chat-sidebar {
        position: fixed;
        top: 0; bottom: 0;
        left: 0;
        z-index: 30;
        transform: translateX(-100%);
        transition: transform var(--t-base);
        box-shadow: var(--shadow-sidebar);
    }
    .chat-sidebar.open { transform: translateX(0); }
    .composer-shell { left: 0; }
    .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
    .chat-topbar { gap: var(--s-2); padding: var(--s-2) var(--s-3); }
    .chat-topbar-title { min-width: 0; flex: 1; }
    .chat-feed { padding-right: var(--s-3); padding-left: var(--s-3); }

    .sidebar-resizer { display: none; }
    .dash-sidebar { display: none; }
    .dash-main { padding: var(--s-5) var(--s-4); }
}

@media (max-width: 560px) {
    .settings-grid { grid-template-columns: 1fr; }
    .settings-field-scopes,
    .settings-field-dates { grid-row: auto; grid-column: auto; }
    .settings-panel.open { max-height: min(52dvh, 430px); overflow-y: auto; overscroll-behavior: contain; padding-right: 2px; }
    .settings-date-range { display: grid; grid-template-columns: 1fr; }
    .settings-date-range > span { display: none; }
    .chat-collaboration-status .badge { max-width: 86px; }
    .chat-action-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
    .chat-topbar-actions .btn { width: 34px; height: 34px; justify-content: center; padding: 0; }
    .composer-shell { padding-right: var(--s-2); padding-left: var(--s-2); }
    .chat-jump-latest { bottom: 108px; }
    .chat-empty { justify-content: flex-start; padding-top: var(--s-8); }
    .chat-starter-grid { grid-template-columns: 1fr; }
    .chat-starter-grid > button { min-height: 70px; }
    .auth-card { padding: var(--s-6); }
}

/* -----------------------------------------------------------------------------
   Dashboard aliases (preserve existing class names used by dashboard subpages)
   -------------------------------------------------------------------------- */
.card-header {
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    margin-bottom: var(--s-3);
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-5);
}
.stat-card .stat-label {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: var(--s-2);
    font-weight: var(--fw-semibold);
}
.stat-card .stat-value {
    font-size: var(--fs-3xl);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
    line-height: 1;
}
.stat-card .stat-sub {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    margin-top: var(--s-2);
}

.dashboard-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    gap: 1px;
    overflow: hidden;
    margin-bottom: var(--s-6);
    background: var(--border-subtle);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
}
.summary-group {
    min-width: 0;
    background: var(--bg-surface);
    padding: var(--s-5);
}
.summary-group-title {
    margin-bottom: var(--s-3);
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.summary-list {
    display: grid;
    gap: var(--s-3);
    margin: 0;
}
.summary-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--s-4);
    min-height: 38px;
}
.summary-row dt {
    min-width: 0;
    color: var(--text-secondary);
    font-size: var(--fs-sm);
}
.summary-row dd {
    display: grid;
    justify-items: end;
    gap: 2px;
    min-width: 0;
    margin: 0;
    text-align: right;
}
.summary-row strong {
    color: var(--text-primary);
    font-size: var(--fs-lg);
    font-weight: var(--fw-semibold);
    line-height: 1.2;
}
.summary-row span {
    color: var(--text-tertiary);
    font-size: var(--fs-xs);
    line-height: 1.3;
}
.usage-card { min-height: 280px; }
.chart-panel {
    position: relative;
    min-height: 220px;
}
.chart-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    text-align: center;
}
.dashboard-activity-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr));
    gap: var(--s-5);
    margin-bottom: var(--s-6);
}
.dashboard-activity-grid > .card {
    display: flex;
    flex-direction: column;
    overflow-x: auto;
}
.dashboard-activity-grid .table-wrap th,
.dashboard-activity-grid .table-wrap td {
    padding: var(--s-2) var(--s-3);
}

.form-group { margin-bottom: var(--s-4); }
.form-group label {
    display: block;
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    color: var(--text-secondary);
    margin-bottom: var(--s-2);
}
.form-control {
    width: 100%;
    font-family: inherit;
    font-size: var(--fs-base);
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    padding: 10px 12px;
    transition: border-color var(--t-fast), background var(--t-fast);
}
.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    background: var(--bg-surface);
}
select.form-control {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23A1A1A1' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}
textarea.form-control { resize: vertical; min-height: 80px; }

.checkbox-row {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-1) 0;
    font-size: var(--fs-sm);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-5); margin-bottom: var(--s-6); }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

.filter-bar {
    display: flex;
    gap: var(--s-3);
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: var(--s-5);
    padding: var(--s-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
}
.filter-bar .form-group { margin-bottom: 0; flex: 1; min-width: 140px; }
.filter-bar .form-group label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.04em; }

/* Django messages */
.messages { list-style: none; margin: 0 0 var(--s-4); padding: 0; }
.messages li {
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-lg);
    margin-bottom: var(--s-2);
    font-size: var(--fs-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    color: var(--text-primary);
}
.messages .success { background: var(--color-success-bg); border-color: var(--color-success); color: var(--color-success); }
.messages .error { background: var(--color-danger-bg); border-color: var(--color-danger); color: var(--color-danger); }
.messages .warning { background: var(--color-warning-bg); border-color: var(--color-warning); color: var(--color-warning); }

/* Color-named badges → map to neutral variants */
.badge-green { color: var(--color-success); border-color: var(--color-success); background: var(--color-success-bg); }
.badge-red { color: var(--color-danger); border-color: var(--color-danger); background: var(--color-danger-bg); }
.badge-yellow { color: var(--color-warning); border-color: var(--color-warning); background: var(--color-warning-bg); }
.badge-blue { color: var(--text-primary); border-color: var(--border-strong); background: var(--bg-elevated); }
.badge-gray { color: var(--text-secondary); border-color: var(--border-default); background: var(--bg-elevated); }

/* Match all old badges to the new badge shell */
.badge-green, .badge-red, .badge-yellow, .badge-blue, .badge-gray {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    height: 22px;
    padding: 0 var(--s-2);
    border-radius: var(--r-full);
    border: 1px solid;
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    line-height: 1;
    white-space: nowrap;
    text-transform: none;
    letter-spacing: 0;
}

/* -----------------------------------------------------------------------------
   Skeleton loaders
   -------------------------------------------------------------------------- */
@keyframes skeleton-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-elevated) 0%,
        var(--bg-hover) 50%,
        var(--bg-elevated) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: var(--r-md);
    color: transparent;
    user-select: none;
    pointer-events: none;
}

.skeleton-line {
    display: block;
    height: 12px;
    border-radius: var(--r-sm);
    margin-bottom: var(--s-2);
}
.skeleton-line:last-child { margin-bottom: 0; }
.skeleton-line.w-40 { width: 40%; }
.skeleton-line.w-60 { width: 60%; }
.skeleton-line.w-75 { width: 75%; }
.skeleton-line.w-90 { width: 90%; }

.skeleton-block {
    width: 100%;
    height: 64px;
    border-radius: var(--r-lg);
    margin-bottom: var(--s-3);
}

.skeleton-circle {
    width: 32px;
    height: 32px;
    border-radius: var(--r-full);
    flex: 0 0 32px;
}

.skeleton-paragraph {
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
    padding: var(--s-2) 0;
}
.skeleton-paragraph .skeleton-line { margin: 0; }

/* Initial page-load overlay — sits on top of the real DOM and fades out
   automatically. No JS dependency: if JS is slow or blocked, CSS animation
   still hides it. */
@keyframes skeleton-overlay-fade {
    0% { opacity: 1; visibility: visible; }
    85% { opacity: 1; visibility: visible; }
    100% { opacity: 0; visibility: hidden; }
}

.page-skeleton {
    position: fixed;
    inset: 0;
    background: var(--bg-canvas);
    z-index: 9999;
    pointer-events: none;
    animation: skeleton-overlay-fade 0.9s ease-out forwards;
}
.page-skeleton[data-hidden="true"] {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

/* Chat-page skeleton layout (matches .chat-shell structure) */
.page-skeleton-chat {
    display: flex;
    height: 100%;
}
.page-skeleton-chat .skel-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    padding: var(--s-4);
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
}
.page-skeleton-chat .skel-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: var(--s-6);
    gap: var(--s-4);
    align-items: center;
    justify-content: center;
}
.page-skeleton-chat .skel-main-inner {
    width: 100%;
    max-width: var(--max-content);
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
}

/* Dashboard-page skeleton layout */
.page-skeleton-dash {
    display: flex;
    height: 100%;
}
.page-skeleton-dash .skel-sidebar {
    width: 240px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    padding: var(--s-5) var(--s-3);
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
}
.page-skeleton-dash .skel-main {
    flex: 1;
    padding: var(--s-8);
    display: flex;
    flex-direction: column;
    gap: var(--s-4);
}

/* Auth-page skeleton */
.page-skeleton-auth {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--s-6);
}
.page-skeleton-auth .skel-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-8);
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
}

@media (max-width: 880px) {
    .page-skeleton-chat .skel-sidebar { display: none; }
    .page-skeleton-dash .skel-sidebar { display: none; }
}

/* -----------------------------------------------------------------------------
   Theme toggle
   -------------------------------------------------------------------------- */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-md);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast);
    width: 100%;
    text-align: left;
}
.theme-toggle:hover { background: var(--bg-elevated); color: var(--text-primary); }
.theme-toggle-icon { width: 16px; height: 16px; flex: 0 0 16px; }

/* Theme-aware logo swap */
.logo-light { display: block; }
.logo-dark { display: none; }
[data-theme="dark"] .logo-light { display: none; }
[data-theme="dark"] .logo-dark { display: block; }

/* Links with brand accent */
a { text-decoration-color: var(--border-default); }
a:hover { text-decoration-color: var(--text-primary); }

/* Smooth transition when switching themes */
html.theme-transitioning,
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
    transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease !important;
}

/* Document comparison diff blocks */
.diff-block { padding: var(--s-3) var(--s-4); border-radius: var(--r-md); margin-bottom: var(--s-2); font-size: var(--fs-sm); line-height: 1.7; white-space: pre-wrap; word-wrap: break-word; }
.diff-block-equal { color: var(--text-tertiary); }
.diff-block-delete { background: var(--color-danger-bg); border-left: 3px solid var(--color-danger); }
.diff-block-insert { background: var(--color-success-bg); border-left: 3px solid var(--color-success); }
.diff-block-replace { border-left: 3px solid var(--color-warning); background: var(--color-warning-bg); }
.diff-replace-old { text-decoration: line-through; color: var(--color-danger); margin-bottom: var(--s-2); }
.diff-replace-new { color: var(--color-success); }
.diff-word-del { background: var(--color-danger-bg); text-decoration: line-through; color: var(--color-danger); padding: 1px 2px; border-radius: 2px; }
.diff-word-ins { background: var(--color-success-bg); color: var(--color-success); padding: 1px 2px; border-radius: 2px; }

/* Bulk actions */
.doc-select { cursor: pointer; width: 16px; height: 16px; }
#bulk-action-bar { transition: transform 0.2s ease; }

/* -----------------------------------------------------------------------------
   Interaction and responsive polish
   -------------------------------------------------------------------------- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: fixed;
    top: var(--s-3);
    left: var(--s-3);
    z-index: 2000;
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-md);
    background: var(--color-accent);
    color: #fff;
    transform: translateY(-160%);
    transition: transform var(--t-fast);
}
.skip-link:focus { transform: translateY(0); }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.floating-theme-toggle {
    position: fixed;
    right: var(--s-4);
    bottom: var(--s-4);
    z-index: 50;
    width: auto;
    padding: var(--s-2) var(--s-3);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    background: var(--bg-surface);
    box-shadow: var(--shadow-card-hover);
}

.ui-notice {
    position: fixed;
    top: var(--s-4);
    left: 50%;
    z-index: 1200;
    max-width: min(420px, calc(100vw - 32px));
    padding: var(--s-3) var(--s-4);
    border: 1px solid var(--color-success);
    border-radius: var(--r-lg);
    background: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-card-hover);
    font-size: var(--fs-sm);
    transform: translateX(-50%);
}
.ui-notice.is-error { border-color: var(--color-danger); }
.ui-notice[hidden] { display: none; }

.chat-row:focus-within .chat-row-delete { opacity: 1; }
.assistant-markdown {
    white-space: normal;
    line-height: 1.72;
}
.assistant-markdown > :first-child { margin-top: 0; }
.assistant-markdown > :last-child { margin-bottom: 0; }
.assistant-markdown p { margin: 0 0 1em; }
.assistant-markdown h3,
.assistant-markdown h4,
.assistant-markdown h5,
.assistant-markdown h6 {
    margin: 1.35em 0 0.55em;
    color: var(--text-primary);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
}
.assistant-markdown h3 { font-size: var(--fs-xl); }
.assistant-markdown h4 { font-size: var(--fs-lg); }
.assistant-markdown h5,
.assistant-markdown h6 { font-size: var(--fs-md); }
.assistant-markdown ul,
.assistant-markdown ol { margin: 0 0 1em; padding-left: 1.5em; }
.assistant-markdown li { margin: 0.32em 0; padding-left: 0.15em; }
.assistant-markdown blockquote {
    margin: var(--s-4) 0;
    padding: var(--s-2) var(--s-4);
    border-left: 2px solid var(--color-accent);
    color: var(--text-secondary);
}
.assistant-markdown code {
    padding: 0.12em 0.38em;
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-sm);
    background: var(--bg-elevated);
    font-family: var(--font-mono);
    font-size: 0.88em;
}
.assistant-markdown pre {
    max-width: 100%;
    margin: var(--s-4) 0;
    padding: var(--s-4);
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    background: var(--bg-surface);
}
.assistant-markdown pre code { padding: 0; border: 0; background: transparent; }
.answer-table-wrap { max-width: 100%; margin: var(--s-4) 0; overflow-x: auto; }
.answer-table-wrap table { width: 100%; min-width: 420px; border-collapse: collapse; font-size: var(--fs-sm); }
.answer-table-wrap th,
.answer-table-wrap td { padding: var(--s-2) var(--s-3); border: 1px solid var(--border-subtle); text-align: left; }
.answer-table-wrap th { background: var(--bg-surface); font-weight: var(--fw-semibold); }

.inline-citations {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 3px;
    white-space: nowrap;
    vertical-align: 0.08em;
}
.assistant-markdown .source-cite:not(.source-card) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    border: 1px solid var(--border-default);
    border-radius: var(--r-full);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: var(--fw-semibold);
    line-height: 1;
    text-decoration: none;
}
.assistant-markdown .source-cite:not(.source-card):hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}
.answer-sources { margin-top: var(--s-4); white-space: normal; }
.answer-sources > summary {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    min-height: 30px;
    padding: 0 var(--s-2);
    border-radius: var(--r-md);
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    cursor: pointer;
    list-style: none;
}
.answer-sources > summary::-webkit-details-marker { display: none; }
.answer-sources > summary:hover { background: var(--bg-elevated); color: var(--text-primary); }
.answer-sources-icon { font-size: 16px; transform: rotate(90deg); }
.answer-sources-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--r-full);
    background: var(--bg-elevated);
    font-size: 10px;
}
.answer-sources-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s-2);
    margin-top: var(--s-2);
}
.source-card {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) auto;
    align-items: start;
    gap: var(--s-2);
    min-width: 0;
    padding: var(--s-3);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    background: var(--bg-surface);
    color: var(--text-primary);
    text-decoration: none;
    transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.source-card:hover { border-color: var(--border-strong); background: var(--bg-elevated); transform: translateY(-1px); }
.source-card-index {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: var(--r-md);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: var(--fw-semibold);
}
.source-card-copy { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.source-card-copy strong { overflow: hidden; font-size: var(--fs-xs); text-overflow: ellipsis; white-space: nowrap; }
.source-card-meta { color: var(--text-tertiary); font-size: 10px; }
.source-card-snippet {
    display: -webkit-box;
    overflow: hidden;
    color: var(--text-secondary);
    font-size: 11px;
    line-height: 1.4;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}
.source-card-arrow { color: var(--text-tertiary); font-size: 12px; }

.assistant-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    min-height: 32px;
    margin-top: var(--s-2);
    color: var(--text-tertiary);
}
.copy-answer-control { display: flex; align-items: center; gap: var(--s-2); }
.answer-action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: 30px;
    height: 30px;
    padding: 0 7px;
    border: 0;
    border-radius: var(--r-md);
    background: transparent;
    color: var(--text-tertiary);
    font: inherit;
    font-size: var(--fs-xs);
    cursor: pointer;
    list-style: none;
}
.answer-action-button::-webkit-details-marker { display: none; }
.answer-action-button:hover { background: var(--bg-elevated); color: var(--text-primary); }
.answer-action-button.is-copied { color: var(--color-success); }
.answer-action-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.copy-status { color: var(--text-secondary); font-size: var(--fs-xs); }
.refine-control { position: relative; }
.refine-control[open] > .answer-action-button { background: var(--bg-elevated); color: var(--text-primary); }
.refine-active-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--color-accent); }
.refine-popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 15;
    width: min(420px, calc(100vw - 48px));
    padding: var(--s-4);
    border: 1px solid var(--border-default);
    border-radius: var(--r-xl);
    background: var(--bg-surface);
    box-shadow: var(--shadow-card-hover);
    color: var(--text-primary);
}
.refine-popover-heading { display: flex; flex-direction: column; gap: 3px; margin-bottom: var(--s-3); }
.refine-popover-heading strong { font-size: var(--fs-sm); }
.refine-popover-heading span { color: var(--text-secondary); font-size: var(--fs-xs); }
.redo-filter-form { display: flex; flex-direction: column; gap: var(--s-3); }
.refine-mode-field { display: flex; flex-direction: column; gap: var(--s-1); margin: 0; color: var(--text-secondary); font-size: var(--fs-xs); }
.refine-mode-field select { width: 100%; }
.redo-filter-list {
    display: flex;
    max-height: 176px;
    overflow-y: auto;
    flex-direction: column;
    gap: 2px;
    padding: var(--s-1);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    background: var(--bg-canvas);
}
.redo-filter-list label { display: flex; align-items: flex-start; gap: var(--s-2); margin: 0; padding: var(--s-2); border-radius: var(--r-md); font-size: var(--fs-xs); }
.redo-filter-list label:hover { background: var(--bg-elevated); }
.redo-filter-list input { flex: 0 0 auto; margin-top: 2px; }
.redo-filter-list span { min-width: 0; overflow-wrap: anywhere; }

.chat-sidebar-overlay,
.dash-sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 25;
    border: 0;
    background: rgba(15, 23, 42, 0.48);
    cursor: pointer;
}
.chat-sidebar-overlay[hidden],
.dash-sidebar-overlay[hidden] { display: none; }

.dash-mobile-header { display: none; }
.dash-mobile-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    color: var(--text-primary);
    font-weight: var(--fw-semibold);
    text-decoration: none;
}
.dash-menu-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    min-height: 40px;
    padding: 0 var(--s-3);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    background: var(--bg-surface);
    color: var(--text-primary);
    font: inherit;
    cursor: pointer;
}
.dash-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--s-4);
    margin-bottom: var(--s-6);
}
.dash-page-header-copy { min-width: 0; }
.dash-page-header-copy h1 { font-size: var(--fs-2xl); }
.dash-page-header-copy p { margin: var(--s-1) 0 0; color: var(--text-secondary); font-size: var(--fs-sm); }
.dash-page-actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.analytics-error-state {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-4);
    margin-bottom: var(--s-5);
    padding: var(--s-4);
    border: 1px solid var(--color-danger);
    border-radius: var(--r-xl);
    background: var(--color-danger-bg);
}
.analytics-error-state[hidden] { display: none; }
.analytics-error-state p { margin: var(--s-1) 0 0; color: var(--text-secondary); font-size: var(--fs-sm); }

.documents-page-header,
.documents-page-actions,
.document-upload-form,
.document-actions {
    min-width: 0;
}
.document-upload-form {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(150px, 200px) minmax(150px, 200px) auto;
    align-items: end;
}
.document-upload-field,
.document-upload-field select,
.document-upload-file input { min-width: 0; max-width: 100%; }
.documents-table-wrap { max-width: 100%; overflow: visible; }
.document-name-link { color: var(--text-primary); font-weight: var(--fw-semibold); }
.compare-form-grid > * { min-width: 0; }
.compare-file-input { display: block; width: 100%; max-width: 100%; }

.documents-stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.document-upload-card { overflow: hidden; }
.document-section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--s-4);
    margin-bottom: var(--s-4);
}
.document-section-heading .card-title { margin: var(--s-1) 0 var(--s-1); font-size: var(--fs-xl); }
.document-section-heading p,
.documents-browser-heading p { margin: 0; color: var(--text-secondary); font-size: var(--fs-sm); }
.document-section-eyebrow {
    color: var(--color-accent);
    font-size: 10px;
    font-weight: var(--fw-semibold);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.document-step-badge {
    flex: 0 0 auto;
    padding: 5px var(--s-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-full);
    color: var(--text-tertiary);
    font-size: 10px;
}
.document-upload-flow { display: flex; flex-direction: column; gap: var(--s-3); }
.document-dropzone {
    position: relative;
    display: flex;
    min-height: 150px;
    align-items: center;
    justify-content: center;
    gap: var(--s-4);
    margin: 0;
    padding: var(--s-6);
    border: 1px dashed var(--border-strong);
    border-radius: var(--r-xl);
    background: color-mix(in srgb, var(--bg-elevated) 45%, transparent);
    cursor: pointer;
    transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.document-dropzone:hover,
.document-dropzone.is-dragging { border-color: var(--color-accent); background: var(--bg-elevated); }
.document-dropzone:focus-within,
.file-dropzone:focus-within { outline: 2px solid var(--border-focus); outline-offset: 3px; border-color: var(--color-accent); }
.document-dropzone.is-dragging { transform: scale(0.995); }
.document-file-input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.document-dropzone-icon {
    display: flex;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-default);
    border-radius: var(--r-xl);
    background: var(--bg-surface);
    color: var(--color-accent);
}
.document-dropzone-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.document-dropzone-copy { display: flex; flex-direction: column; gap: 3px; color: var(--text-secondary); font-size: var(--fs-sm); }
.document-dropzone-copy strong { color: var(--text-primary); font-size: var(--fs-md); }
.document-dropzone-copy small { margin-top: var(--s-1); color: var(--text-tertiary); font-size: var(--fs-xs); }
.document-browse-label { color: var(--color-accent); font-weight: var(--fw-medium); }
.document-upload-error { padding: var(--s-3); border-radius: var(--r-lg); background: var(--color-danger-bg); color: var(--color-danger); font-size: var(--fs-sm); }
.document-file-summary {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-3);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    background: var(--bg-elevated);
}
.document-file-kind { display: flex; width: 40px; height: 40px; align-items: center; justify-content: center; border-radius: var(--r-lg); background: var(--bg-surface); color: var(--color-accent); font-size: 9px; font-weight: var(--fw-semibold); letter-spacing: 0.04em; }
.document-file-copy { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.document-file-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); }
.document-file-copy span { color: var(--text-tertiary); font-size: var(--fs-xs); }
.document-upload-options {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    align-items: end;
    gap: var(--s-3);
    padding-top: var(--s-1);
}
.document-upload-field { display: flex; min-width: 0; flex-direction: column; gap: var(--s-1); }
.document-upload-field label { display: flex; justify-content: space-between; gap: var(--s-2); margin: 0; color: var(--text-secondary); font-size: var(--fs-xs); }
.document-upload-field label span { color: var(--text-tertiary); }
.document-upload-field select { width: 100%; height: 42px; }
.document-upload-submit { height: 42px; gap: var(--s-2); }
.document-upload-submit svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

.document-secondary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); margin-bottom: var(--s-5); }
.documents-secondary-panel { min-width: 0; padding: 0; }
.documents-secondary-panel > summary { display: flex; min-height: 82px; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-4) var(--s-5); cursor: pointer; list-style: none; }
.documents-secondary-panel > summary::-webkit-details-marker { display: none; }
.documents-secondary-panel > summary > span:first-child { display: flex; min-width: 0; flex-direction: column; gap: 4px; }
.documents-secondary-panel > summary strong { font-size: var(--fs-sm); }
.documents-secondary-panel > summary small { color: var(--text-secondary); font-size: var(--fs-xs); }
.documents-secondary-panel > summary > span:last-child { color: var(--text-tertiary); font-size: var(--fs-xl); transition: transform var(--t-fast); }
.documents-secondary-panel[open] > summary > span:last-child { transform: rotate(45deg); }
.document-secondary-form,
.documents-cloud-content { padding: 0 var(--s-5) var(--s-5); }
.document-secondary-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-2); }
.document-secondary-form label { grid-column: 1 / -1; margin: 0; color: var(--text-secondary); font-size: var(--fs-xs); }
.document-secondary-form input { width: 100%; }
.cloud-connection-list { display: flex; flex-direction: column; gap: var(--s-2); margin-bottom: var(--s-4); }
.cloud-connection-row { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-3); border: 1px solid var(--border-subtle); border-radius: var(--r-md); }
.cloud-connection-meta { display: flex; min-width: 0; align-items: center; flex-wrap: wrap; gap: var(--s-1) var(--s-2); overflow-wrap: anywhere; }
.cloud-connection-actions,
.cloud-provider-actions { display: flex; min-width: 0; align-items: center; flex-wrap: wrap; gap: var(--s-2); }
.cloud-connection-actions { flex: 0 0 auto; }
.cloud-connection-actions form { margin: 0; }

.document-bulk-bar { position: fixed; right: 0; bottom: 0; left: 0; z-index: 100; padding: var(--s-3) var(--s-5) max(var(--s-3), env(safe-area-inset-bottom)); border-top: 2px solid var(--color-accent); background: var(--bg-surface); box-shadow: 0 -2px 12px rgba(0,0,0,.14); }
.document-bulk-inner { display: flex; max-width: 1400px; align-items: center; gap: var(--s-3); margin: 0 auto; }
.document-bulk-inner > span { min-width: 92px; font-weight: var(--fw-semibold); }
.document-bulk-inner label { margin: 0; color: var(--text-secondary); font-size: var(--fs-sm); }
.document-bulk-inner select { width: min(300px, 100%); height: 34px; padding: 0 var(--s-2); font-size: var(--fs-sm); }

.documents-browser-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); padding: var(--s-5); }
.documents-toolbar {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) repeat(4, minmax(125px, 0.45fr)) auto;
    align-items: end;
    gap: var(--s-3);
    padding: 0 var(--s-5) var(--s-4);
    border-bottom: 1px solid var(--border-subtle);
}
.documents-search-field { position: relative; display: flex; min-width: 0; flex-direction: column; gap: 4px; margin: 0; }
.documents-search-field > span { color: var(--text-tertiary); font-size: 10px; font-weight: var(--fw-semibold); letter-spacing: 0.04em; text-transform: uppercase; }
.documents-search-field svg { position: absolute; bottom: 11px; left: var(--s-3); width: 16px; height: 16px; fill: none; stroke: var(--text-tertiary); stroke-width: 1.5; stroke-linecap: round; }
.documents-search-field input { width: 100%; height: 38px; padding-left: 38px; }
.documents-filter-field { display: flex; min-width: 0; flex-direction: column; gap: 4px; margin: 0; }
.documents-filter-field > span { color: var(--text-tertiary); font-size: 10px; font-weight: var(--fw-semibold); letter-spacing: 0.04em; text-transform: uppercase; }
.documents-filter-field select { width: 100%; height: 38px; }
.documents-toolbar-actions { display: flex; align-items: center; gap: var(--s-2); }
.documents-result-count { grid-column: 1 / -1; align-self: center; color: var(--text-tertiary); font-size: var(--fs-xs); white-space: normal; }
.documents-table { border-collapse: collapse; }
.documents-table th { font-size: 10px; }
.documents-table .document-name-cell { max-width: 340px; font-weight: var(--fw-medium); }
.documents-table .document-name-cell > * { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.documents-actions-heading,
.document-actions-cell { width: 54px; text-align: right; }
.document-actions-menu { position: relative; display: inline-block; }
.document-actions-menu > summary { font-size: 12px; letter-spacing: 1px; }
.document-actions-menu[open] > summary { background: var(--bg-elevated); color: var(--text-primary); }
.document-actions-popover {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 20;
    display: flex;
    width: 190px;
    flex-direction: column;
    gap: 2px;
    padding: var(--s-2);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    background: var(--bg-surface);
    box-shadow: var(--shadow-card-hover);
    text-align: left;
}
.document-actions-popover > a,
.document-actions-popover .summary-action > a,
.document-menu-button {
    display: flex;
    width: 100%;
    min-height: 34px;
    align-items: center;
    padding: 0 var(--s-3);
    border: 0;
    border-radius: var(--r-md);
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    font-size: var(--fs-xs);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.document-actions-popover > a:hover,
.document-actions-popover .summary-action > a:hover,
.document-menu-button:hover { background: var(--bg-elevated); }
.document-actions-popover form { width: 100%; margin: 0 !important; }
.document-menu-danger { color: var(--color-danger); }
.documents-filter-empty { padding: var(--s-8); color: var(--text-secondary); text-align: center; }

/* -------------------------------------------------------------------------
   Admin data browsers and action glyphs
   ------------------------------------------------------------------------- */

.action-glyph-sprite { position: absolute; width: 0; height: 0; overflow: hidden; pointer-events: none; }
.menu-glyph,
.button-glyph { width: 16px; height: 16px; flex: 0 0 16px; fill: none; stroke: currentColor; stroke-width: 1.45; stroke-linecap: round; stroke-linejoin: round; }
.button-glyph { width: 15px; height: 15px; flex-basis: 15px; }
.btn:has(> .button-glyph) { display: inline-flex; align-items: center; gap: var(--s-2); }
.document-actions-popover > a,
.document-actions-popover .summary-action > a,
.document-menu-button { gap: var(--s-2); }
.document-more-menu > a { gap: var(--s-2); }

.dash-page-eyebrow { display: block; margin-bottom: var(--s-1); color: var(--color-accent); font-size: 10px; font-weight: var(--fw-semibold); letter-spacing: .08em; text-transform: uppercase; }
.dash-page-header-copy > p { max-width: 620px; margin: var(--s-1) 0 0; color: var(--text-secondary); font-size: var(--fs-sm); }
.dash-page-actions .btn { gap: var(--s-2); }
.admin-document-stats { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.admin-compact-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.status-value-success { color: #6ee7a0; }
.status-value-warning { color: #f0c060; }
.status-value-danger { color: #ffa4ad; }

.admin-data-browser { padding: 0; overflow: visible; }
.admin-data-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); padding: var(--s-5); }
.admin-data-heading h2 { margin: 2px 0 0; font-size: var(--fs-lg); }
.admin-data-heading p { margin: var(--s-1) 0 0; color: var(--text-secondary); font-size: var(--fs-xs); }
.admin-data-toolbar {
    display: grid;
    grid-template-columns: minmax(220px, 1.6fr) repeat(4, minmax(130px, .75fr)) auto;
    align-items: end;
    gap: var(--s-3);
    padding: 0 var(--s-5) var(--s-4);
    border-bottom: 1px solid var(--border-subtle);
}
.admin-data-toolbar > label { display: flex; min-width: 0; flex-direction: column; gap: 4px; margin: 0; }
.admin-data-toolbar > label > span:first-child { color: var(--text-tertiary); font-size: 10px; font-weight: var(--fw-semibold); letter-spacing: .05em; text-transform: uppercase; }
.admin-data-toolbar input,
.admin-data-toolbar select { width: 100%; height: 38px; }
.admin-search-control { position: relative; display: block; }
.admin-search-control svg { position: absolute; top: 50%; left: var(--s-3); width: 16px; height: 16px; transform: translateY(-50%); fill: none; stroke: var(--text-tertiary); stroke-width: 1.5; stroke-linecap: round; }
.admin-search-control input { padding-left: 38px; }
.admin-toolbar-actions { display: flex; align-items: center; gap: var(--s-2); min-height: 38px; }
.admin-data-toolbar-client { grid-template-columns: minmax(260px, 1.6fr) repeat(2, minmax(150px, .6fr)) auto; }

.admin-responsive-table-wrap { overflow: visible; border-top: 0; }
.admin-responsive-table { width: 100%; border-collapse: collapse; }
.admin-responsive-table th { padding: var(--s-3) var(--s-4); color: var(--text-tertiary); font-size: 10px; font-weight: var(--fw-semibold); letter-spacing: .05em; text-align: left; text-transform: uppercase; white-space: nowrap; }
.admin-responsive-table td { padding: var(--s-3) var(--s-4); border-top: 1px solid var(--border-subtle); color: var(--text-secondary); font-size: var(--fs-xs); vertical-align: middle; }
.admin-responsive-table .admin-primary-cell { max-width: 360px; color: var(--text-primary); font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.admin-primary-cell > a,
.admin-primary-cell > span { display: block; overflow: hidden; color: inherit; text-overflow: ellipsis; white-space: nowrap; }
.admin-primary-cell > a:hover { color: var(--color-accent); }
.admin-row-actions { width: 54px; text-align: right; }
.admin-row-actions .document-actions-menu { text-align: left; }
.admin-row-actions > .answer-action-button { display: inline-flex; text-decoration: none; }
.admin-email-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-badge-list { display: flex; min-width: 0; flex-wrap: wrap; gap: 4px; }
.role-description-cell { max-width: 420px; color: var(--text-secondary); line-height: 1.45; }
.admin-row-actions .document-actions-popover { top: calc(100% + 4px); right: 0; bottom: auto; }
.document-actions-menu.open-upward .document-actions-popover,
.document-more-actions.open-upward .document-more-menu { top: auto; bottom: calc(100% + 4px); }
.admin-data-empty { display: flex; min-height: 150px; align-items: center; justify-content: center; flex-direction: column; gap: var(--s-1); padding: var(--s-6); color: var(--text-secondary); text-align: center; }
.admin-data-empty strong { color: var(--text-primary); font-size: var(--fs-sm); }
.admin-data-empty span { font-size: var(--fs-xs); }
.dashboard-panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); padding: var(--s-4) var(--s-5); }
.dashboard-panel-heading h2 { margin: 2px 0 0; font-size: var(--fs-md); }
.dashboard-panel-heading > a { color: var(--color-accent); font-size: var(--fs-xs); text-decoration: none; }
.dashboard-activity-card { padding: 0; overflow: visible; }
.compact-admin-table .admin-primary-cell { max-width: 260px; }
.dashboard-process-notice { display: flex; align-items: center; gap: var(--s-3); margin-top: var(--s-4); padding: var(--s-4); border: 1px solid var(--color-warning); border-radius: var(--r-xl); background: color-mix(in srgb, var(--color-warning-bg) 60%, transparent); }
.dashboard-process-notice > div { display: flex; min-width: 0; flex: 1; flex-direction: column; gap: 2px; }
.dashboard-process-notice strong { font-size: var(--fs-sm); }
.dashboard-process-notice span { color: var(--text-secondary); font-size: var(--fs-xs); }
.dashboard-process-notice > a { color: var(--text-primary); font-size: var(--fs-xs); font-weight: var(--fw-semibold); white-space: nowrap; }
#analytics-content { transition: opacity var(--t-fast); }
#analytics-content.is-refreshing { opacity: .62; }
.analytics-ranking-table .admin-primary-cell { max-width: 300px; }
.admin-pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-top: 1px solid var(--border-subtle); color: var(--text-tertiary); font-size: var(--fs-xs); }
.admin-pagination > div { display: flex; gap: var(--s-2); }

.admin-setting-disclosure { padding: 0; }
.admin-setting-disclosure > summary { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-4) var(--s-5); cursor: pointer; list-style: none; }
.admin-setting-disclosure > summary::-webkit-details-marker { display: none; }
.admin-setting-disclosure > summary > span:first-child { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.admin-setting-disclosure > summary strong { font-size: var(--fs-sm); }
.admin-setting-disclosure > summary small { color: var(--text-secondary); font-size: var(--fs-xs); }
.admin-setting-content { padding: 0 var(--s-5) var(--s-5); border-top: 1px solid var(--border-subtle); }
.admin-setting-content > p { max-width: 760px; color: var(--text-secondary); font-size: var(--fs-sm); line-height: 1.6; }
.admin-setting-content form { margin: 0; }
.admin-toggle-row { display: flex; align-items: flex-start; gap: var(--s-3); max-width: 600px; margin: var(--s-4) 0; cursor: pointer; }
.admin-toggle-row input { margin-top: 3px; }
.admin-toggle-row span { display: flex; flex-direction: column; gap: 2px; }
.admin-toggle-row strong { font-size: var(--fs-sm); }
.admin-toggle-row small { color: var(--text-secondary); font-size: var(--fs-xs); }
.admin-effective-access { margin-top: var(--s-4); padding: var(--s-3); border: 1px solid var(--border-subtle); border-radius: var(--r-lg); background: var(--bg-canvas); color: var(--text-secondary); font-size: var(--fs-xs); }
.admin-effective-access strong { color: var(--text-primary); }
.admin-info-popover { position: relative; }
.admin-info-popover > summary { list-style: none; }
.admin-info-popover > summary::-webkit-details-marker { display: none; }
.admin-info-popover > p { position: absolute; top: calc(100% + 6px); right: 0; z-index: 10; width: min(320px, 80vw); margin: 0; padding: var(--s-4); border: 1px solid var(--border-default); border-radius: var(--r-lg); background: var(--bg-surface); box-shadow: var(--shadow-card-hover); color: var(--text-secondary); font-size: var(--fs-xs); line-height: 1.55; }

.audit-data-toolbar { grid-template-columns: minmax(240px, 1.5fr) repeat(3, minmax(150px, .75fr)) auto; }
.audit-action-code { padding: 3px 6px; border-radius: var(--r-sm); background: var(--bg-elevated); color: var(--text-secondary); font-size: 11px; }
.audit-description-cell { max-width: 430px; line-height: 1.45; }
.audit-description > summary { cursor: pointer; color: var(--text-secondary); list-style-position: outside; }
.audit-description > p { margin: var(--s-2) 0; color: var(--text-primary); }
.audit-description > small { display: block; color: var(--text-tertiary); overflow-wrap: anywhere; }

@media (max-width: 1180px) {
    .admin-document-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .admin-data-toolbar,
    .audit-data-toolbar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .admin-toolbar-span-2 { grid-column: span 2; }
    .admin-toolbar-actions { justify-content: flex-end; }
}

@media (max-width: 880px) {
    .admin-document-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .admin-compact-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .admin-data-heading { align-items: stretch; flex-direction: column; padding: var(--s-4); }
    .dashboard-panel-heading { padding: var(--s-4); }
    .admin-data-toolbar,
    .admin-data-toolbar-client,
    .audit-data-toolbar { grid-template-columns: minmax(0, 1fr); padding: 0 var(--s-4) var(--s-4); }
    .admin-toolbar-span-2 { grid-column: auto; }
    .admin-toolbar-actions { justify-content: flex-start; }
    .admin-responsive-table,
    .admin-responsive-table tbody { display: block; width: 100%; }
    .admin-responsive-table thead { display: none; }
    .admin-responsive-table .admin-data-row { position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3) var(--s-4); padding: var(--s-4); border-top: 1px solid var(--border-subtle); }
    .admin-responsive-table .admin-data-row > td { display: block; min-width: 0; padding: 0; border: 0; white-space: normal; }
    .admin-responsive-table .admin-data-row > td::before { content: attr(data-label); display: block; margin-bottom: 4px; color: var(--text-tertiary); font-size: 9px; font-weight: var(--fw-semibold); letter-spacing: .05em; text-transform: uppercase; }
    .admin-responsive-table .admin-primary-cell { grid-column: 1 / -1; max-width: none; padding-right: 38px; font-size: var(--fs-md); }
    .admin-responsive-table .admin-primary-cell::before,
    .admin-responsive-table .admin-row-actions::before { display: none; }
    .admin-primary-cell > a,
    .admin-primary-cell > span { overflow-wrap: anywhere; text-overflow: clip; white-space: normal; }
    .admin-email-cell { max-width: none; overflow-wrap: anywhere; text-overflow: clip; white-space: normal; }
    .admin-row-actions { position: absolute; top: var(--s-3); right: var(--s-4); width: auto; }
    .admin-row-actions .document-actions-popover { right: 0; }
    .audit-description-cell { grid-column: 1 / -1; max-width: none; }
    .role-description-cell { grid-column: 1 / -1; max-width: none; }
    .admin-pagination { align-items: stretch; flex-direction: column; padding: var(--s-4); }
    .admin-pagination > div { justify-content: space-between; }
    .admin-setting-disclosure > summary,
    .admin-setting-content { padding-right: var(--s-4); padding-left: var(--s-4); }
}

@media (max-width: 560px) {
    .dashboard-process-notice { align-items: flex-start; }
    .dashboard-process-notice > a { display: none; }
}

@media (max-width: 1000px) {
    .documents-stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .documents-toolbar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .documents-search-field { grid-column: span 2; }
    .documents-toolbar-actions { grid-column: 1 / -1; justify-content: flex-end; }
    .documents-result-count { grid-column: 1 / -1; }
    .documents-table-wrap { overflow: visible !important; }
    .documents-table,
    .documents-table tbody { display: block; width: 100%; }
    .documents-table thead { display: none; }
    .documents-table .document-row {
        position: relative;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: var(--s-3) var(--s-4);
        padding: var(--s-4) var(--s-5);
        border-bottom: 1px solid var(--border-subtle);
    }
    .documents-table .document-row > td {
        display: block;
        min-width: 0;
        padding: 0;
        border: 0;
        text-align: left;
        white-space: normal !important;
    }
    .documents-table .document-row > td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 4px;
        color: var(--text-tertiary);
        font-size: 10px;
        font-weight: var(--fw-semibold);
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }
    .documents-table .document-select-cell { position: absolute; top: var(--s-4); right: var(--s-5); }
    .documents-table .document-row > td.document-select-cell::before { display: none; }
    .documents-table .document-name-cell { grid-column: 1 / -1; display: block; max-width: none; overflow: hidden; padding-right: 36px; font-size: var(--fs-md); text-align: left; }
    .documents-table .document-name-cell > * { overflow-wrap: anywhere; text-overflow: clip; white-space: normal; }
    .documents-table .document-row > td.document-actions-cell { grid-column: 1 / -1; display: flex; justify-content: flex-end; margin-top: var(--s-1); }
    .documents-table .document-name-cell::before,
    .documents-table .document-actions-cell::before { display: none; }
    .documents-table .document-row > td.document-actions-cell::before { display: none; }
    .documents-table .error-row { display: block; border-bottom: 1px solid var(--border-subtle); }
    .documents-table .error-row td { display: block; padding: 0 var(--s-5) var(--s-4) !important; }
}

@media (hover: none), (pointer: coarse) {
    .chat-row-delete { opacity: 1; }
}

@media (max-width: 880px) {
    body.navigation-drawer-open { overflow: hidden; }

    .dash-shell { display: block; }
    .dash-mobile-header {
        position: sticky;
        top: 0;
        z-index: 20;
        display: flex;
        align-items: center;
        gap: var(--s-3);
        min-height: 56px;
        padding: var(--s-2) var(--s-4);
        border-bottom: 1px solid var(--border-subtle);
        background: color-mix(in srgb, var(--bg-canvas) 94%, transparent);
        backdrop-filter: blur(12px);
    }
    .dash-mobile-brand {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .dash-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 30;
        display: flex;
        width: min(300px, calc(100vw - 48px));
        height: 100dvh;
        transform: translateX(-105%);
        transition: transform var(--t-base);
        box-shadow: var(--shadow-sidebar);
    }
    .dash-sidebar.open { transform: translateX(0); }
    .dash-main {
        max-width: none;
        padding: var(--s-5) var(--s-4) calc(var(--s-16) + 44px);
        overflow-x: hidden;
    }
    .dash-page-header { align-items: stretch; flex-direction: column; }
    .dash-page-actions { width: 100%; }

    .table-wrap {
        max-width: 100%;
        overflow-x: auto;
        overscroll-behavior-inline: contain;
        -webkit-overflow-scrolling: touch;
    }
    .table-wrap.is-scrollable::after {
        content: "Scroll table horizontally for more details";
        display: block;
        padding: var(--s-2) var(--s-3);
        border-top: 1px solid var(--border-subtle);
        color: var(--text-tertiary);
        font-size: var(--fs-xs);
    }
}

@media (max-width: 760px) {
    .documents-page-header {
        align-items: flex-start;
        flex-direction: column;
        gap: var(--s-3);
    }
    .documents-page-actions { width: 100%; flex-wrap: wrap; }
    .document-upload-form { grid-template-columns: 1fr; }
    .document-upload-form > .btn { width: 100%; }
    .compare-form-grid { grid-template-columns: 1fr !important; }
    .compare-panel { padding: var(--s-4) !important; }

    .documents-table-wrap { overflow: visible !important; }
    .documents-table,
    .documents-table tbody { display: block; width: 100%; }
    .documents-table thead { display: none; }
    .documents-table .document-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: var(--s-2) var(--s-4);
        padding: var(--s-4);
        border-bottom: 1px solid var(--border-subtle);
    }
    .documents-table .document-row > td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--s-3);
        min-width: 0;
        padding: 0;
        border: 0;
        text-align: right;
        white-space: normal !important;
    }
    .documents-table .document-row > td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        color: var(--text-tertiary);
        font-size: var(--fs-xs);
        font-weight: var(--fw-semibold);
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }
    .documents-table .document-select-cell {
        grid-column: 2;
        grid-row: 1;
        justify-content: flex-end;
    }
    .documents-table .document-row > td.document-select-cell::before { display: none; }
    .documents-table .document-name-cell {
        grid-column: 1;
        grid-row: 1;
        display: block;
        max-width: none !important;
        overflow: visible !important;
        font-size: var(--fs-md);
        text-align: left;
    }
    .documents-table .document-actions-cell {
        grid-column: 1 / -1;
        text-align: left;
    }
    .documents-table .document-name-cell::before,
    .documents-table .document-actions-cell::before { display: none; }
    .documents-table .document-actions-cell { margin-top: var(--s-2); }
    .documents-table .document-actions {
        width: 100%;
        justify-content: flex-start !important;
        flex-wrap: wrap !important;
    }
    .documents-table .error-row { display: block; border-bottom: 1px solid var(--border-subtle); }
    .documents-table .error-row td { display: block; padding: 0 var(--s-4) var(--s-4) !important; }
}

@media (max-width: 560px) {
    .app-shell { padding-bottom: calc(var(--s-16) + 44px); }
    .floating-theme-toggle {
        right: var(--s-3);
        bottom: var(--s-3);
        width: 40px;
        height: 40px;
        padding: 0;
        justify-content: center;
    }
    .floating-theme-toggle #theme-label { display: none; }
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stat-card { padding: var(--s-4); }
    .stat-card .stat-value { min-width: 0; overflow-wrap: anywhere; font-size: clamp(1.45rem, 8vw, 2rem); }
    .card { padding: var(--s-5); }
}

@media (max-width: 760px) {
    .answer-sources-list { grid-template-columns: 1fr; }
    .refine-popover { position: fixed; top: auto; right: var(--s-3); bottom: 92px; left: var(--s-3); width: auto; max-height: min(520px, calc(100dvh - 120px)); overflow-y: auto; }
    .document-section-heading,
    .documents-browser-heading { flex-direction: column; }
    .document-step-badge { align-self: flex-start; }
    .document-dropzone { min-height: 180px; flex-direction: column; padding: var(--s-5); text-align: center; }
    .document-upload-options,
    .document-secondary-grid,
    .documents-toolbar { grid-template-columns: 1fr; }
    .documents-search-field { grid-column: auto; }
    .documents-toolbar-actions .btn { flex: 1; }
    .document-upload-submit { width: 100%; }
    .documents-toolbar { padding: 0 var(--s-4) var(--s-4); }
    .documents-browser-heading { padding: var(--s-4); }
    .documents-secondary-panel > summary { padding: var(--s-4); }
    .document-secondary-form,
    .documents-cloud-content { padding: 0 var(--s-4) var(--s-4); }
    .cloud-connection-row { align-items: stretch; flex-direction: column; }
    .cloud-connection-actions,
    .cloud-provider-actions { display: grid; grid-template-columns: 1fr; width: 100%; }
    .cloud-connection-actions .btn,
    .cloud-provider-actions .btn,
    .cloud-connection-actions form,
    .cloud-connection-actions form .btn { width: 100%; }
    .document-bulk-bar { padding-right: var(--s-3); padding-left: var(--s-3); }
    .document-bulk-inner { display: grid; grid-template-columns: 1fr 1fr; }
    .document-bulk-inner > span,
    .document-bulk-inner label,
    .document-bulk-inner select { grid-column: 1 / -1; width: 100%; }
    .document-bulk-inner .btn { width: 100%; }
    .bulk-selection-active .floating-theme-toggle { display: none; }
    .documents-table .document-actions-popover { width: 190px; flex-wrap: nowrap !important; justify-content: flex-start !important; }
}

@media (max-width: 620px) {
    .documents-table .document-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* --------------------------------------------------------------------------
   Extended workflow and administration polish
   -------------------------------------------------------------------------- */

.page-breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    max-width: 1100px;
    margin: 0 auto var(--s-4);
    color: var(--text-tertiary);
    font-size: var(--fs-xs);
}
.page-breadcrumb a { color: var(--text-secondary); text-decoration: none; }
.page-breadcrumb a:hover { color: var(--text-primary); }
.workflow-page-header {
    display: flex;
    max-width: 1100px;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--s-5);
    margin: 0 auto var(--s-6);
}
.workflow-page-header h1 { margin: var(--s-1) 0 var(--s-2); font-size: var(--fs-3xl); line-height: var(--lh-tight); }
.workflow-page-header p { max-width: 680px; margin: 0; color: var(--text-secondary); font-size: var(--fs-sm); line-height: var(--lh-relaxed); }

.file-drop-field { min-width: 0; }
.file-dropzone {
    position: relative;
    display: flex;
    min-height: 170px;
    align-items: center;
    justify-content: center;
    gap: var(--s-4);
    margin: 0;
    padding: var(--s-6);
    border: 1px dashed var(--border-strong);
    border-radius: var(--r-xl);
    background: color-mix(in srgb, var(--bg-elevated) 45%, transparent);
    cursor: pointer;
    transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.file-dropzone:hover,
.file-dropzone.is-dragging { border-color: var(--color-accent); background: var(--bg-elevated); }
.file-dropzone.is-dragging { transform: scale(0.995); }
.file-dropzone input[type="file"] { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.file-dropzone > span:last-child { display: flex; flex-direction: column; gap: 4px; color: var(--text-secondary); font-size: var(--fs-sm); }
.file-dropzone > span:last-child strong { color: var(--text-primary); font-size: var(--fs-md); }
.file-dropzone > span:last-child small { color: var(--color-accent); font-size: var(--fs-xs); }
.file-dropzone-icon { display: flex; width: 46px; height: 46px; flex: 0 0 46px; align-items: center; justify-content: center; border: 1px solid var(--border-default); border-radius: var(--r-xl); background: var(--bg-surface); color: var(--color-accent); }
.file-dropzone-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.file-selection { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: var(--s-3); padding: var(--s-3); border: 1px solid var(--border-default); border-radius: var(--r-xl); background: var(--bg-elevated); }
.compare-inline-error { margin: 0 0 var(--s-3); color: var(--color-danger); font-size: var(--fs-xs); }
.compare-document-search { display: flex; flex-direction: column; gap: var(--s-1); margin-bottom: var(--s-5); padding-bottom: var(--s-4); border-bottom: 1px solid var(--border-subtle); }
.compare-document-search-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
.compare-document-search-fields label { display: flex; min-width: 0; flex-direction: column; gap: var(--s-1); margin: 0; color: var(--text-secondary); font-size: var(--fs-xs); }
.compare-document-search-fields input { width: 100%; min-width: 0; }
.compare-document-search-fields small,
.compare-document-search-actions small { color: var(--text-tertiary); font-size: var(--fs-xs); }
.compare-document-search-actions { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-2); }
.compare-document-search-actions small { margin-left: auto; }
.compare-diff-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--s-2) var(--s-4); margin-bottom: var(--s-4); }
.compare-diff-legend { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2) var(--s-3); font-size: var(--fs-xs); }

.passages-page { max-width: 1100px; margin: 0 auto; }
.passages-page .page-breadcrumb { margin-right: 0; margin-left: 0; }
.passages-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-5); margin-right: 0; margin-left: 0; }
.workflow-header-actions { display: flex; flex: 0 0 auto; flex-wrap: wrap; gap: var(--s-2); }
.passages-error { display: flex; flex-direction: column; gap: 4px; }
.passages-browser { padding: 0; }
.passages-toolbar { display: flex; align-items: center; gap: var(--s-2); padding: 0 var(--s-5) var(--s-4); border-bottom: 1px solid var(--border-subtle); }
.passages-toolbar .admin-search-field { flex: 1; }
.passages-list { display: flex; flex-direction: column; }
.passage-card { scroll-margin-top: var(--s-4); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--border-subtle); }
.passage-card:last-child { border-bottom: 0; }
.passage-card.is-highlighted { background: color-mix(in srgb, var(--color-accent-light) 52%, transparent); box-shadow: inset 3px 0 0 var(--color-accent); }
.passage-card > header { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-3); color: var(--text-tertiary); font-size: var(--fs-xs); }
.passage-card > header > span:first-child { margin-right: auto; font-weight: var(--fw-semibold); letter-spacing: .03em; text-transform: uppercase; }
.passage-card pre { margin: 0; overflow: visible; color: var(--text-primary); font-family: var(--font-mono); font-size: var(--fs-sm); line-height: 1.65; overflow-wrap: anywhere; white-space: pre-wrap; }

@media (max-width: 760px) {
    .passages-header { align-items: stretch; flex-direction: column; }
    .workflow-header-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .workflow-header-actions .btn { justify-content: center; }
    .passages-toolbar { padding-right: var(--s-4); padding-left: var(--s-4); }
    .passage-card { padding: var(--s-4); }
}

.bulk-upload-layout { display: grid; max-width: 1100px; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; gap: var(--s-4); margin: 0 auto; }
.bulk-upload-card { min-width: 0; }
.bulk-upload-card form { display: flex; flex-direction: column; gap: var(--s-4); }
.bulk-upload-options { display: flex; flex-direction: column; gap: var(--s-4); padding-top: var(--s-2); }
.bulk-upload-options-heading { display: flex; flex-direction: column; gap: 3px; }
.bulk-upload-options-heading strong { font-size: var(--fs-md); }
.bulk-upload-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
.bulk-upload-aside { display: flex; flex-direction: column; gap: var(--s-3); }
.bulk-upload-note h2 { margin: var(--s-2) 0; font-size: var(--fs-lg); }
.bulk-upload-note > p { margin: 0 0 var(--s-4); color: var(--text-secondary); font-size: var(--fs-sm); line-height: var(--lh-relaxed); }
.bulk-upload-note details { border-top: 1px solid var(--border-subtle); padding-top: var(--s-3); }
.bulk-upload-note summary { color: var(--text-secondary); font-size: var(--fs-xs); font-weight: var(--fw-semibold); cursor: pointer; }
.bulk-upload-note pre { margin: var(--s-3) 0 0; overflow-x: auto; color: var(--text-secondary); font-family: var(--font-mono); font-size: 11px; line-height: 1.65; }
.bulk-upload-safety { display: flex; flex-direction: column; gap: 4px; padding: var(--s-4); border: 1px solid var(--border-subtle); border-radius: var(--r-xl); color: var(--text-secondary); font-size: var(--fs-xs); }
.bulk-upload-safety strong { color: var(--text-primary); font-size: var(--fs-sm); }

.choice-card {
    display: flex;
    min-width: 0;
    align-items: flex-start;
    gap: var(--s-3);
    margin: 0;
    padding: var(--s-3);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    background: var(--bg-canvas);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color var(--t-fast), background var(--t-fast);
}
.choice-card:hover { border-color: var(--border-strong); background: var(--bg-elevated); }
.choice-card:has(input:checked) { border-color: var(--color-accent); background: color-mix(in srgb, var(--color-accent) 6%, var(--bg-surface)); }
.choice-card input { flex: 0 0 auto; margin-top: 3px; }
.choice-card > span { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.choice-card strong { font-size: var(--fs-sm); }
.choice-card small { color: var(--text-secondary); font-size: var(--fs-xs); font-weight: var(--fw-regular); line-height: 1.45; }
.choice-card-horizontal { align-items: center; }

.compare-documents-page { max-width: 960px; margin: 0 auto; }
.compare-page-header { margin-left: 0; margin-right: 0; }
.compare-mode-switch { display: inline-flex; gap: 3px; margin-bottom: var(--s-3); padding: 3px; border: 1px solid var(--border-subtle); border-radius: var(--r-lg); background: var(--bg-surface); }
.compare-mode-switch button { min-height: 34px; padding: 0 var(--s-3); border: 0; border-radius: var(--r-md); background: transparent; color: var(--text-secondary); font: inherit; font-size: var(--fs-xs); cursor: pointer; }
.compare-mode-switch button[aria-selected="true"] { background: var(--bg-elevated); color: var(--text-primary); box-shadow: var(--shadow-sm); }
.compare-panel { margin-bottom: var(--s-4); }
.compare-panel-heading { margin-bottom: var(--s-5); }
.compare-panel-heading h2 { margin: var(--s-1) 0; font-size: var(--fs-xl); }
.compare-panel-heading p { margin: 0; color: var(--text-secondary); font-size: var(--fs-sm); }
.compare-form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 38px minmax(0, 1fr); align-items: end; gap: var(--s-3); margin-bottom: var(--s-4); }
.compare-source-field { display: grid; min-width: 0; grid-template-columns: 30px minmax(0, 1fr); gap: var(--s-2); }
.compare-source-field > div { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.compare-source-field label { margin: 0; color: var(--text-primary); font-size: var(--fs-sm); }
.compare-source-field small { color: var(--text-tertiary); font-size: var(--fs-xs); }
.compare-source-field select { grid-column: 1 / -1; width: 100%; height: 42px; }
.compare-source-index { display: inline-flex; width: 26px; height: 26px; align-items: center; justify-content: center; border-radius: var(--r-md); background: var(--bg-elevated); color: var(--text-secondary); font-size: var(--fs-xs); font-weight: var(--fw-semibold); }
.compare-swap-button { width: 38px; height: 38px; margin-bottom: 2px; border: 1px solid var(--border-default); border-radius: var(--r-full); background: var(--bg-surface); color: var(--text-secondary); font-size: var(--fs-lg); cursor: pointer; }
.compare-swap-button:hover { color: var(--text-primary); background: var(--bg-elevated); }
.compare-upload-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); margin-bottom: var(--s-4); }
.file-dropzone-compact { min-height: 132px; padding: var(--s-4); }
.file-dropzone-compact > span:last-child strong { font-size: var(--fs-sm); }

.document-detail-page { max-width: 1100px; margin: 0 auto; }
.document-detail-page .page-breadcrumb { margin-left: 0; margin-right: 0; }
.document-detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-5); margin-bottom: var(--s-5); padding: var(--s-5); border: 1px solid var(--border-subtle); border-radius: var(--r-xl); background: var(--bg-surface); }
.document-detail-title-row { display: flex; min-width: 0; align-items: flex-start; gap: var(--s-4); }
.document-detail-icon { display: flex; width: 44px; height: 44px; flex: 0 0 44px; align-items: center; justify-content: center; border: 1px solid var(--border-default); border-radius: var(--r-xl); background: var(--bg-elevated); color: var(--color-accent); }
.document-detail-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; }
.document-detail-title-copy { min-width: 0; }
.document-detail-title-copy h1 { margin: var(--s-1) 0 var(--s-2); overflow-wrap: anywhere; font-size: var(--fs-2xl); line-height: var(--lh-tight); }
.document-detail-meta { display: flex; flex-wrap: wrap; gap: var(--s-2); color: var(--text-tertiary); font-size: var(--fs-xs); }
.document-detail-meta span:not(:last-child)::after { content: "·"; margin-left: var(--s-2); }
.document-detail-actions { display: flex; flex: 0 0 auto; align-items: center; gap: var(--s-2); }
.document-more-actions { position: relative; }
.document-more-actions > summary { list-style: none; cursor: pointer; }
.document-more-actions > summary::-webkit-details-marker { display: none; }
.document-more-menu { position: absolute; top: calc(100% + 5px); right: 0; z-index: 25; display: flex; width: 210px; flex-direction: column; gap: 2px; padding: var(--s-2); border: 1px solid var(--border-default); border-radius: var(--r-lg); background: var(--bg-surface); box-shadow: var(--shadow-card-hover); }
.document-more-menu > a { display: flex; min-height: 34px; align-items: center; padding: 0 var(--s-3); border-radius: var(--r-md); color: var(--text-primary); font-size: var(--fs-xs); text-decoration: none; }
.document-more-menu > a:hover { background: var(--bg-elevated); }
.document-more-menu form { margin: 0; }
.document-summary-panel,
.document-preview-panel { margin-bottom: var(--s-4); padding: var(--s-5); border: 1px solid var(--border-subtle); border-radius: var(--r-xl); background: var(--bg-surface); }
.document-panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-4); }
.document-panel-heading h2 { margin: var(--s-1) 0 0; font-size: var(--fs-lg); }
.document-panel-heading > a { color: var(--text-secondary); font-size: var(--fs-xs); text-decoration: none; }
.document-summary-copy { white-space: pre-wrap; color: var(--text-primary); font-size: var(--fs-sm); line-height: 1.75; }
.document-frame-wrap iframe { width: 100%; min-height: 70vh; border: 1px solid var(--border-default); border-radius: var(--r-lg); background: var(--bg-input); }
.document-text-preview { max-height: 70vh; margin: 0; padding: var(--s-5); overflow: auto; border: 1px solid var(--border-default); border-radius: var(--r-lg); background: var(--bg-canvas); color: var(--text-primary); font-family: var(--font-mono); font-size: var(--fs-sm); line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.document-preview-empty { display: flex; min-height: 260px; align-items: center; justify-content: center; gap: var(--s-4); color: var(--text-secondary); text-align: left; }
.document-preview-empty > div { display: flex; flex-direction: column; gap: 4px; }
.document-preview-empty strong { color: var(--text-primary); font-size: var(--fs-sm); }
.document-preview-empty span { font-size: var(--fs-xs); }
.document-process-state { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-4); padding: var(--s-4); border: 1px solid var(--border-subtle); border-radius: var(--r-xl); background: var(--bg-surface); }
.document-process-state > div { display: flex; flex-direction: column; gap: 3px; }
.document-process-state span { color: var(--text-secondary); font-size: var(--fs-xs); }
.status-pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--color-warning); box-shadow: 0 0 0 5px var(--color-warning-bg); }
.document-summary-error { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-4); }

.profile-page { max-width: 980px; margin: 0 auto; }
.profile-page .page-breadcrumb { margin-left: 0; margin-right: 0; }
.profile-hero { display: flex; align-items: center; gap: var(--s-4); margin-bottom: var(--s-5); }
.profile-avatar,
.admin-user-avatar { display: flex; width: 58px; height: 58px; flex: 0 0 58px; align-items: center; justify-content: center; border: 1px solid var(--border-default); border-radius: var(--r-xl); background: var(--bg-elevated); color: var(--text-primary); font-size: var(--fs-xl); font-weight: var(--fw-semibold); }
.profile-hero-copy { min-width: 0; flex: 1; }
.profile-hero h1 { margin: var(--s-1) 0; font-size: var(--fs-2xl); }
.profile-identity-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); color: var(--text-secondary); font-size: var(--fs-xs); }
.profile-identity-meta > span:not(.badge):not(:last-child)::after { content: "·"; margin-left: var(--s-2); }
.profile-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(260px, 0.75fr); align-items: start; gap: var(--s-4); margin-bottom: var(--s-4); }
.profile-section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); }
.profile-section-heading h2 { margin: var(--s-1) 0 0; font-size: var(--fs-lg); }
.profile-section-note { color: var(--text-tertiary); font-size: var(--fs-xs); }
.profile-form,
.profile-password-form,
.admin-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
.profile-field { display: flex; min-width: 0; flex-direction: column; gap: var(--s-1); }
.profile-field-full { grid-column: 1 / -1; }
.profile-field label { margin: 0; color: var(--text-secondary); font-size: var(--fs-xs); font-weight: var(--fw-medium); }
.profile-field input,
.profile-field textarea,
.profile-field select { width: 100%; }
.profile-field > small { color: var(--text-tertiary); font-size: 11px; line-height: 1.4; }
.profile-stat-list { display: flex; flex-direction: column; }
.profile-stat-list > div { display: grid; grid-template-columns: 80px minmax(0, 1fr); gap: 2px var(--s-3); padding: var(--s-3) 0; border-bottom: 1px solid var(--border-subtle); }
.profile-stat-list > div:last-child { border-bottom: 0; }
.profile-stat-list > div > span { grid-row: 1 / 3; color: var(--text-primary); font-size: var(--fs-xl); font-weight: var(--fw-semibold); }
.profile-stat-list strong { font-size: var(--fs-sm); }
.profile-stat-list small { color: var(--text-tertiary); font-size: var(--fs-xs); }
.profile-security { padding: 0; }
.profile-security > summary { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-4) var(--s-5); cursor: pointer; list-style: none; }
.profile-security > summary::-webkit-details-marker { display: none; }
.profile-security > summary > span:first-child { display: flex; flex-direction: column; gap: 3px; }
.profile-security > summary strong { font-size: var(--fs-sm); }
.profile-security > summary small { color: var(--text-secondary); font-size: var(--fs-xs); }
.profile-security > summary > span:last-child { color: var(--text-tertiary); font-size: var(--fs-xl); transition: transform var(--t-fast); }
.profile-security[open] > summary > span:last-child { transform: rotate(45deg); }
.profile-password-form { padding: 0 var(--s-5) var(--s-5); }
.profile-password-action { justify-content: flex-end; }

.admin-form-shell { display: flex; max-width: 980px; flex-direction: column; gap: var(--s-4); }
.admin-form-section h2 { margin: 0; font-size: var(--fs-lg); }
.admin-form-section-heading { display: flex; align-items: flex-start; gap: var(--s-3); margin-bottom: var(--s-4); }
.admin-form-section-heading > span { display: flex; width: 26px; height: 26px; flex: 0 0 26px; align-items: center; justify-content: center; border-radius: var(--r-md); background: var(--bg-elevated); color: var(--text-secondary); font-size: var(--fs-xs); font-weight: var(--fw-semibold); }
.admin-form-section-heading > div { display: flex; flex-direction: column; gap: 3px; }
.admin-form-section-heading p { margin: 0; color: var(--text-secondary); font-size: var(--fs-xs); }
.admin-choice-fieldset { min-width: 0; margin: 0 0 var(--s-4); padding: 0; border: 0; }
.admin-choice-fieldset legend { margin-bottom: var(--s-2); color: var(--text-secondary); font-size: var(--fs-xs); font-weight: var(--fw-medium); }
.admin-choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); }
.admin-access-toggle { display: flex; align-items: flex-start; gap: var(--s-3); margin: 0; padding: var(--s-3); border: 1px solid var(--color-warning); border-radius: var(--r-lg); background: var(--color-warning-bg); }
.admin-access-toggle.compact { margin-top: var(--s-4); border-color: var(--border-subtle); background: var(--bg-canvas); }
.admin-access-toggle input { margin-top: 3px; }
.admin-access-toggle > span { display: flex; flex-direction: column; gap: 3px; }
.admin-access-toggle strong { color: var(--text-primary); font-size: var(--fs-sm); }
.admin-access-toggle small { color: var(--text-secondary); font-size: var(--fs-xs); font-weight: var(--fw-regular); }
.admin-temp-password { max-width: 460px; }
.admin-form-actions { display: flex; align-items: center; gap: var(--s-2); }
.admin-role-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.7fr); align-items: start; gap: var(--s-4); }
.admin-role-main { display: flex; flex-direction: column; gap: var(--s-4); }
.role-collection-picker { margin-top: var(--s-3); }
.role-member-list { display: flex; max-height: 420px; overflow-y: auto; flex-direction: column; gap: var(--s-2); }
.admin-role-save { margin-top: var(--s-3); }
.admin-empty-copy { color: var(--text-secondary); font-size: var(--fs-sm); }
.admin-danger-zone { max-width: 980px; border: 1px solid color-mix(in srgb, var(--color-danger) 45%, var(--border-subtle)); border-radius: var(--r-xl); background: var(--color-danger-bg); }
.admin-danger-zone > summary { padding: var(--s-3) var(--s-4); color: var(--color-danger); font-size: var(--fs-sm); font-weight: var(--fw-semibold); cursor: pointer; }
.admin-danger-zone > div { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: 0 var(--s-4) var(--s-4); }
.admin-danger-zone p { margin: 0; color: var(--text-secondary); font-size: var(--fs-xs); }

.admin-user-header { align-items: center; }
.admin-user-identity { display: flex; min-width: 0; align-items: center; gap: var(--s-3); }
.admin-user-badges { display: flex; gap: var(--s-2); margin-top: var(--s-2); }
.admin-user-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }
.admin-account-controls,
.admin-user-danger { grid-column: 1 / -1; }
.admin-control-list { display: flex; flex-direction: column; }
.admin-control-list > div { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-3) 0; border-bottom: 1px solid var(--border-subtle); }
.admin-control-list > div:last-child { border-bottom: 0; }
.admin-control-list > div > span { display: flex; flex-direction: column; gap: 3px; }
.admin-control-list strong { font-size: var(--fs-sm); }
.admin-control-list small { color: var(--text-secondary); font-size: var(--fs-xs); }
.admin-control-list form { flex: 0 0 auto; margin: 0; }
.admin-temp-password-banner { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-4); padding: var(--s-4); border: 1px solid var(--color-warning); border-radius: var(--r-xl); background: var(--color-warning-bg); }
.admin-temp-password-banner > div:first-child { display: flex; flex-direction: column; gap: 3px; }
.admin-temp-password-banner span { color: var(--text-secondary); font-size: var(--fs-xs); }
.admin-temp-password-value { display: flex; align-items: center; gap: var(--s-2); }
.admin-temp-password-value input { width: 250px; font-family: var(--font-mono); }
.admin-activity-section { margin-top: var(--s-7); }
.admin-activity-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }
.admin-activity-list { display: flex; flex-direction: column; }
.admin-activity-list > div { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-3) 0; border-bottom: 1px solid var(--border-subtle); font-size: var(--fs-xs); }
.admin-activity-list > div:last-child { border-bottom: 0; }
.admin-activity-list code { color: var(--text-secondary); font-family: var(--font-mono); }
.admin-activity-list time { flex: 0 0 auto; color: var(--text-tertiary); }
.admin-activity-list p { color: var(--text-secondary); font-size: var(--fs-sm); }

.integration-empty-state { display: grid; max-width: 900px; grid-template-columns: 56px minmax(0, 1fr); gap: var(--s-4); padding: var(--s-6); }
.integration-empty-icon { display: flex; width: 54px; height: 54px; align-items: center; justify-content: center; border: 1px solid var(--border-default); border-radius: var(--r-xl); background: var(--bg-elevated); color: var(--color-accent); }
.integration-empty-icon svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.integration-empty-state h2 { margin: var(--s-1) 0 var(--s-2); font-size: var(--fs-xl); }
.integration-empty-state p { max-width: 620px; margin: 0; color: var(--text-secondary); font-size: var(--fs-sm); line-height: var(--lh-relaxed); }
.integration-empty-steps { grid-column: 2; display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-2); }
.integration-empty-steps span { display: inline-flex; align-items: center; gap: var(--s-2); color: var(--text-secondary); font-size: var(--fs-xs); }
.integration-empty-steps strong { display: inline-flex; width: 20px; height: 20px; align-items: center; justify-content: center; border-radius: var(--r-full); background: var(--bg-elevated); color: var(--text-primary); }
.integration-section { margin-bottom: var(--s-7); }
.integration-provider-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s-3); }
.integration-provider-card { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: var(--s-3); color: var(--text-primary); text-decoration: none; }
.integration-provider-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.integration-provider-icon { display: flex; width: 36px; height: 36px; align-items: center; justify-content: center; border-radius: var(--r-lg); background: var(--bg-elevated); color: #fff; font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.integration-provider-card > span:nth-child(2),
.integration-connection-title > span:last-child { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.integration-provider-card small,
.integration-connection-title small { color: var(--text-secondary); font-size: var(--fs-xs); }
.integration-connection-list { display: flex; flex-direction: column; gap: var(--s-3); }
.integration-connection-card > header { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: var(--s-4); }
.integration-connection-title { display: flex; min-width: 0; align-items: center; gap: var(--s-3); }
.integration-statuses,
.integration-actions { display: flex; align-items: center; gap: var(--s-2); }
.integration-actions form { margin: 0; }
.integration-folder-list { margin-top: var(--s-4); border-top: 1px solid var(--border-subtle); }
.integration-folder-list > div:not(.alert-error) { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-3) 0; border-bottom: 1px solid var(--border-subtle); }
.integration-folder-list > div > span { display: flex; flex-direction: column; gap: 3px; }
.integration-folder-list small { color: var(--text-tertiary); font-size: var(--fs-xs); }
.integration-no-folders { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); margin-top: var(--s-4); padding: var(--s-3); border-radius: var(--r-lg); background: var(--bg-canvas); color: var(--text-secondary); font-size: var(--fs-xs); }

.folder-picker-shell { max-width: 900px; }
.folder-picker-shell .profile-section-heading p { max-width: 700px; margin: var(--s-1) 0 0; color: var(--text-secondary); font-size: var(--fs-sm); line-height: 1.55; }
.cloud-folder-tree { min-height: 260px; max-height: min(58vh, 620px); overflow: auto; border: 1px solid var(--border-subtle); border-radius: var(--r-xl); background: var(--bg-canvas); overscroll-behavior: contain; }
.folder-tree-state { display: flex; min-height: 90px; align-items: center; justify-content: center; flex-direction: column; gap: var(--s-3); padding: var(--s-4); color: var(--text-secondary); font-size: var(--fs-sm); text-align: center; }
.folder-tree-state.is-error { color: var(--color-danger); }
.cloud-folder-row { display: flex; align-items: center; gap: var(--s-2); min-height: 44px; padding: var(--s-1) var(--s-3) var(--s-1) calc(var(--s-3) + var(--folder-depth) * 20px); border-bottom: 1px solid var(--border-subtle); }
.cloud-folder-row:hover { background: var(--bg-elevated); }
.folder-expand-button { display: inline-flex; width: 28px; height: 28px; flex: 0 0 28px; align-items: center; justify-content: center; border: 0; border-radius: var(--r-md); background: transparent; color: var(--text-secondary); font-size: var(--fs-xl); line-height: 1; cursor: pointer; transition: transform var(--t-fast), background var(--t-fast); }
.folder-expand-button:hover:not(:disabled) { background: var(--bg-surface); color: var(--text-primary); }
.folder-expand-button.is-open { transform: rotate(90deg); }
.folder-expand-button:disabled { cursor: default; }
.cloud-folder-label { display: flex; min-width: 0; flex: 1; align-items: center; gap: var(--s-2); margin: 0; cursor: pointer; }
.cloud-folder-label > span { min-width: 0; overflow: hidden; color: var(--text-primary); font-size: var(--fs-sm); text-overflow: ellipsis; white-space: nowrap; }
.cloud-folder-label > small { margin-left: auto; color: var(--text-tertiary); font-size: 10px; white-space: nowrap; }
.cloud-folder-label:has(input:disabled) { cursor: default; }
.folder-picker-actions { display: flex; align-items: center; gap: var(--s-3); margin-top: var(--s-4); }
.folder-selected-count { margin-left: auto; color: var(--text-secondary); font-size: var(--fs-xs); }
.folder-picker-actions + .alert-error { margin-top: var(--s-3); }

@media (max-width: 620px) {
    .folder-picker-actions { align-items: stretch; flex-direction: column; }
    .folder-selected-count { order: -1; margin-left: 0; }
    .cloud-folder-tree { max-height: 52dvh; }
    .cloud-folder-label > small { display: none; }
}

.section-search-page { max-width: 1180px; margin: 0 auto; }
.section-search-page .page-breadcrumb,
.section-search-page .workflow-page-header { margin-left: 0; margin-right: 0; }
.section-search-grid { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); align-items: start; gap: var(--s-4); }
.section-search-source,
.section-search-results { min-width: 0; }
.doc-preview-text { max-height: 330px; margin-bottom: var(--s-3); padding: var(--s-4); overflow: auto; border: 1px solid var(--border-default); border-radius: var(--r-lg); background: var(--bg-canvas); font-family: var(--font-mono); font-size: var(--fs-sm); line-height: 1.65; white-space: pre-wrap; user-select: text; }
.doc-preview-text::selection { background: color-mix(in srgb, var(--color-accent) 28%, transparent); }
.section-highlight-button { margin-bottom: var(--s-5); }
.section-query-fields { display: flex; flex-direction: column; gap: var(--s-3); padding-top: var(--s-4); border-top: 1px solid var(--border-subtle); }
.section-label-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.section-query-fields textarea.has-selection { border-color: var(--color-accent); }
.section-results-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); }
.section-results-header h2 { margin: var(--s-1) 0 0; font-size: var(--fs-lg); }
.section-search-error { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--s-3); }
.section-result-note,
.filter-applied-note { margin-bottom: var(--s-3); padding: var(--s-2) var(--s-3); border: 1px solid var(--border-subtle); border-radius: var(--r-lg); background: var(--bg-canvas); color: var(--text-secondary); font-size: var(--fs-xs); }
.section-refine { position: relative; margin-bottom: var(--s-3); }
.section-refine > summary { width: max-content; }
.section-refine-panel { display: flex; max-width: 420px; flex-direction: column; gap: var(--s-3); margin-top: var(--s-2); padding: var(--s-3); border: 1px solid var(--border-default); border-radius: var(--r-xl); background: var(--bg-canvas); }
.section-narrative { margin-top: var(--s-4); }
.section-narrative h3 { margin: var(--s-1) 0 var(--s-3); font-size: var(--fs-md); }
.summary-card { border: 1px solid var(--border-subtle); border-radius: var(--r-lg); padding: var(--s-4); background: var(--bg-canvas); line-height: var(--lh-relaxed); }
.section-results-empty { display: flex; min-height: 300px; align-items: center; justify-content: center; flex-direction: column; gap: var(--s-2); color: var(--text-secondary); text-align: center; }
.section-results-empty > span { display: flex; width: 44px; height: 44px; align-items: center; justify-content: center; border: 1px solid var(--border-default); border-radius: var(--r-xl); color: var(--text-tertiary); font-size: var(--fs-xl); }
.section-results-empty strong { color: var(--text-primary); font-size: var(--fs-sm); }
.section-results-empty p { max-width: 320px; margin: 0; font-size: var(--fs-xs); }
.section-result-list { display: flex; flex-direction: column; gap: var(--s-3); margin-top: var(--s-4); }
.section-result-title { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.section-result-title a { min-width: 0; overflow: hidden; color: var(--text-primary); font-weight: var(--fw-semibold); text-overflow: ellipsis; white-space: nowrap; }
.section-result-title span { flex: 0 0 auto; color: var(--text-tertiary); font-size: var(--fs-xs); }

@media (max-width: 980px) {
    .bulk-upload-layout,
    .section-search-grid,
    .admin-role-layout { grid-template-columns: 1fr; }
    .bulk-upload-aside { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .admin-role-members { order: 2; }
    .integration-connection-card > header { grid-template-columns: minmax(0, 1fr) auto; }
    .integration-actions { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
    .workflow-page-header,
    .document-detail-header,
    .profile-hero { align-items: stretch; flex-direction: column; }
    .workflow-page-header h1 { font-size: var(--fs-2xl); }
    .file-dropzone { min-height: 170px; flex-direction: column; text-align: center; }
    .bulk-upload-fields,
    .bulk-upload-aside,
    .compare-upload-grid,
    .profile-layout,
    .admin-user-layout,
    .admin-activity-grid { grid-template-columns: 1fr; }
    .compare-mode-switch { display: flex; }
    .compare-mode-switch button { flex: 1; }
    .compare-document-search-fields { grid-template-columns: 1fr; }
    .compare-document-search-actions small { width: 100%; margin-left: 0; }
    .compare-form-grid { grid-template-columns: 1fr; }
    .compare-swap-button { margin: -2px auto; transform: rotate(90deg); }
    .document-detail-title-row { align-items: center; }
    .document-detail-actions { flex-wrap: wrap; }
    .document-detail-actions .btn-primary { flex: 1; }
    .document-panel-heading { align-items: flex-start; flex-direction: column; }
    .profile-hero > .btn { align-self: flex-start; }
    .profile-form,
    .profile-password-form,
    .admin-form-grid,
    .admin-choice-grid { grid-template-columns: 1fr; }
    .profile-password-action { justify-content: flex-start; }
    .admin-control-list > div,
    .admin-temp-password-banner,
    .integration-folder-list > div:not(.alert-error) { align-items: stretch; flex-direction: column; }
    .admin-danger-zone > div { align-items: flex-start; flex-direction: column; }
    .admin-account-controls,
    .admin-user-danger { grid-column: auto; }
    .admin-temp-password-value { align-items: stretch; flex-wrap: wrap; }
    .admin-temp-password-value input { width: 100%; }
    .integration-empty-state { grid-template-columns: 1fr; }
    .integration-empty-steps { grid-column: 1; flex-direction: column; }
    .integration-connection-card > header { grid-template-columns: 1fr; }
    .integration-statuses,
    .integration-actions { grid-column: 1; flex-wrap: wrap; }
    .section-results-header { align-items: flex-start; flex-direction: column; }
    .section-results-empty { min-height: 220px; }
}

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