/* YouTube Transcriber — Cloudflare/Fin.ai-inspired Design System */

/* ============================================================
   1. Design Tokens
   ============================================================ */
:root {
    /* Backgrounds */
    --bg-primary: #ffffff;
    --bg-shell: #f5f6f7;
    --bg-surface: #ffffff;
    --bg-elevated: #f9fafb;
    --bg-overlay: #ffffff;

    /* Borders */
    --border-default: #e5e7eb;
    --border-muted: #f0f1f3;

    /* Text */
    --text-primary: #1a1a2e;
    --text-secondary: #4a5568;
    --text-tertiary: #6b7280;

    /* Accent (Orange) */
    --accent: #a84f0b;
    --accent-hover: #873b06;
    --accent-subtle: rgba(244, 129, 32, 0.08);

    /* Semantic */
    --success: #137333;
    --success-subtle: rgba(22, 163, 74, 0.08);
    --error: #b91c1c;
    --error-subtle: rgba(220, 38, 38, 0.08);
    --warning: #9a4f00;
    --warning-subtle: rgba(217, 119, 6, 0.08);
    --info: #1d4ed8;
    --info-subtle: rgba(37, 99, 235, 0.08);

    /* Navigation */
    --nav-bg: #1a1a2e;
    --nav-text: #ffffff;

    /* Fonts */
    --font-headline: Georgia, 'Times New Roman', serif;
    --font-body: ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-sans: var(--font-body);
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* ============================================================
   2. Base / Reset
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--bg-shell);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }

.skip-link {
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 100;
    padding: 0.65rem 0.9rem;
    border-radius: 0.5rem;
    background: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    transform: translateY(-150%);
}

.skip-link:focus { transform: translateY(0); }

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

/* ============================================================
   3. Typography
   ============================================================ */
.font-headline { font-family: var(--font-headline); }
.font-mono     { font-family: var(--font-mono); }

.page-title {
    font-family: var(--font-headline);
    font-size: clamp(1.6rem, 2.8vw, 2.2rem);
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.page-subtitle {
    margin-top: 0.35rem;
    color: var(--text-secondary);
    font-size: 0.92rem;
}

.section-title {
    font-family: var(--font-headline);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.kicker {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
}

/* ============================================================
   4. Top Navigation
   ============================================================ */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--nav-bg);
    color: var(--nav-text);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.top-nav-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    height: 3.5rem;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-family: var(--font-headline);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--nav-text);
    white-space: nowrap;
}

.nav-brand-icon {
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1rem;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-link {
    padding: 0.4rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.65);
    transition: all 150ms ease;
}

.nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.nav-link.is-active {
    color: #fff;
    background: rgba(244, 129, 32, 0.2);
    font-weight: 600;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.workspace-switch {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 0.6rem;
    background: rgba(255, 255, 255, 0.06);
}

.workspace-switch-link {
    padding: 0.35rem 0.65rem;
    border-radius: 0.4rem;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.78rem;
    font-weight: 600;
}

.workspace-switch-link:hover,
.workspace-switch-link:focus-visible { color: #fff; }

.workspace-switch-link.is-active {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.workspace-mobile-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 2.75rem;
    margin-top: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 0.5rem;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
}

/* Mobile hamburger */
.nav-mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--nav-text);
    cursor: pointer;
    padding: 0.25rem;
}

.mobile-nav {
    display: none;
    background: var(--nav-bg);
    padding: 0.5rem 1rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.mobile-nav.is-open { display: block; }

.mobile-nav .nav-link {
    display: block;
    padding: 0.6rem 0.75rem;
    width: 100%;
}

@media (max-width: 767px) {
    .nav-mobile-toggle { display: block; }
    .nav-links { display: none; }
    .nav-actions { display: none; }
    .top-nav-inner { height: 3.25rem; }
    .mobile-nav .nav-actions-mobile {
        display: flex;
        gap: 0.5rem;
        padding-top: 0.75rem;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        margin-top: 0.5rem;
    }

    .nav-mobile-toggle,
    .mobile-nav .nav-link,
    .workspace-mobile-link {
        min-height: 2.75rem;
    }
    .nav-mobile-toggle { min-width: 2.75rem; }
    .nav-brand { min-height: 2.75rem; }
    .page-btn { min-width: 2.75rem; height: 2.75rem; }
    button,
    .btn,
    .input-field,
    input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
    select,
    textarea { min-height: 2.75rem; }
    .modal-close,
    .chat-session-action-btn,
    .toggle-btn { min-width: 2.75rem; }
    .chat-session-actions { display: flex; }
}

/* ============================================================
   5. Page Shell
   ============================================================ */
.page-shell {
    max-width: 1300px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
}

@media (min-width: 768px) {
    .page-shell { padding: 2rem 1.5rem 3rem; }
}

@media (min-width: 1024px) {
    .page-shell { padding: 2.5rem 2rem 4rem; }
}

.page-head { margin-bottom: 1.5rem; }

/* ============================================================
   6. Surface Cards
   ============================================================ */
.surface {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.surface-body { padding: 1.25rem; }

@media (min-width: 768px) {
    .surface-body { padding: 1.5rem; }
}

.surface-elevated {
    background: var(--bg-elevated);
    border: 1px solid var(--border-muted);
    border-radius: 0.75rem;
}

/* ============================================================
   7. Corner Bracket Accents (Fin.ai-style)
   ============================================================ */
.bracket-accent {
    position: relative;
    padding: 1.5rem;
}

.bracket-accent::before,
.bracket-accent::after {
    content: '';
    position: absolute;
    width: 1.25rem;
    height: 1.25rem;
    border-color: var(--accent);
    border-style: solid;
    pointer-events: none;
}

.bracket-accent::before {
    top: 0; left: 0;
    border-width: 2px 0 0 2px;
}

.bracket-accent::after {
    bottom: 0; right: 0;
    border-width: 0 2px 2px 0;
}

/* ============================================================
   8. Stat Cards
   ============================================================ */
.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: 0.75rem;
    padding: 1rem 1.15rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.stat-label {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: clamp(1.45rem, 2.4vw, 1.9rem);
    font-weight: 800;
    line-height: 1;
}

.stat-desc {
    margin-top: 0.3rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* ============================================================
   9. Metadata Grid
   ============================================================ */
.meta-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.meta-card {
    border: 1px solid var(--border-default);
    border-radius: 0.65rem;
    background: var(--bg-surface);
    padding: 0.75rem 0.85rem;
}

.meta-label {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}

.meta-value {
    margin-top: 0.2rem;
    font-weight: 600;
    color: var(--text-primary);
}

@media (max-width: 640px) {
    .meta-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   10. Status Pills
   ============================================================ */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.22rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
}

.status-pill .dot {
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-completed       { background: var(--success-subtle); color: var(--success); }
.status-completed .dot  { background: var(--success); }

.status-failed          { background: var(--error-subtle); color: var(--error); }
.status-failed .dot     { background: var(--error); }

.status-running,
.status-downloading,
.status-transcribing,
.status-summarizing     { background: var(--warning-subtle); color: var(--warning); }
.status-running .dot,
.status-downloading .dot,
.status-transcribing .dot,
.status-summarizing .dot { background: var(--warning); }

.status-queued          { background: var(--info-subtle); color: var(--info); }
.status-queued .dot     { background: var(--info); }

.status-pending         { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border-default); }
.status-pending .dot    { background: var(--text-tertiary); }

.status-discovered      { background: var(--info-subtle); color: var(--info); }
.status-discovered .dot { background: var(--info); }

.status-transcribed,
.status-downloaded      { background: var(--success-subtle); color: var(--success); }
.status-transcribed .dot,
.status-downloaded .dot { background: var(--success); }

.status-cancelled       { background: var(--bg-elevated); color: var(--text-tertiary); }
.status-cancelled .dot  { background: var(--text-tertiary); }

.status-manual_review      { background: var(--warning-subtle); color: var(--warning); }
.status-manual_review .dot { background: var(--warning); }

.status-stale_reaped       { background: var(--info-subtle); color: var(--info); }
.status-stale_reaped .dot  { background: var(--info); }

/* ============================================================
   11. Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: var(--font-body);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 150ms ease;
    line-height: 1.4;
    white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-outline {
    background: transparent;
    border-color: var(--border-default);
    color: var(--text-primary);
}

.btn-outline:hover:not(:disabled) {
    background: var(--bg-elevated);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.btn-warning {
    background: var(--warning);
    border-color: var(--warning);
    color: #fff;
}

.btn-warning:hover:not(:disabled) {
    background: #b45309;
    border-color: #b45309;
}

.btn-error-outline {
    background: transparent;
    border-color: var(--error);
    color: var(--error);
}

.btn-error-outline:hover:not(:disabled) {
    background: var(--error-subtle);
}

.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
}

.btn-xs {
    padding: 0.2rem 0.5rem;
    font-size: 0.72rem;
}

.btn-nav {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 0.8rem;
    padding: 0.35rem 0.75rem;
}

.btn-nav:hover { background: rgba(255, 255, 255, 0.18); }

.btn-nav-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-size: 0.8rem;
    padding: 0.35rem 0.75rem;
}

.btn-nav-primary:hover { background: var(--accent-hover); }

/* ============================================================
   12. Form Controls
   ============================================================ */
.input-field {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--border-default);
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-family: var(--font-body);
    background: var(--bg-surface);
    color: var(--text-primary);
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.input-field::placeholder { color: var(--text-tertiary); }

.input-field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.input-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    margin-bottom: 0.35rem;
}

.checkbox-field {
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent);
    cursor: pointer;
}

/* ============================================================
   13. Tabs
   ============================================================ */
.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border-default);
    margin-bottom: 1.5rem;
}

.tab-item {
    padding: 0.65rem 1.15rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: all 150ms ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.tab-item:hover { color: var(--text-primary); }

.tab-item.is-active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.tab-count {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    background: var(--bg-elevated);
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
}

/* ============================================================
   14. Tables
   ============================================================ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.data-table th {
    text-align: left;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border-default);
    white-space: nowrap;
}

.data-table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border-muted);
    vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--bg-elevated); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ============================================================
   15. Progress Bars
   ============================================================ */
.progress-bar {
    width: 100%;
    height: 0.5rem;
    background: var(--border-muted);
    border-radius: 999px;
    overflow: hidden;
    appearance: none;
    -webkit-appearance: none;
}

.progress-bar::-webkit-progress-bar { background: var(--border-muted); border-radius: 999px; }
.progress-bar::-webkit-progress-value { background: var(--accent); border-radius: 999px; transition: width 300ms ease; }
.progress-bar::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

.progress-bar.progress-success::-webkit-progress-value { background: var(--success); }
.progress-bar.progress-success::-moz-progress-bar { background: var(--success); }
.progress-bar.progress-error::-webkit-progress-value { background: var(--error); }
.progress-bar.progress-error::-moz-progress-bar { background: var(--error); }

.progress-bar-lg { height: 0.75rem; }

/* ============================================================
   16. Pipeline Steps
   ============================================================ */
.pipeline-steps {
    display: flex;
    align-items: center;
    gap: 0;
    margin: 1.5rem 0;
}

.pipeline-step {
    flex: 1;
    text-align: center;
    position: relative;
    padding: 0.5rem 0;
}

.pipeline-step-dot {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    border: 2px solid var(--border-default);
    background: var(--bg-surface);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-tertiary);
    margin-bottom: 0.35rem;
    position: relative;
    z-index: 1;
}

.pipeline-step.is-done .pipeline-step-dot {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.pipeline-step.is-active .pipeline-step-dot {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.pipeline-step.is-error .pipeline-step-dot {
    border-color: var(--error);
    background: var(--error);
    color: #fff;
}

.pipeline-step-label {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-tertiary);
}

.pipeline-step.is-done .pipeline-step-label,
.pipeline-step.is-active .pipeline-step-label { color: var(--text-primary); }

.pipeline-step + .pipeline-step::before {
    content: '';
    position: absolute;
    top: calc(0.5rem + 0.875rem);
    left: -50%;
    right: 50%;
    height: 2px;
    background: var(--border-default);
    z-index: 0;
}

.pipeline-step.is-done + .pipeline-step::before { background: var(--accent); }

/* ============================================================
   17. Breadcrumbs
   ============================================================ */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    color: var(--text-tertiary);
    margin-bottom: 1rem;
}

.breadcrumb a { color: var(--text-secondary); }
.breadcrumb a:hover { color: var(--accent); }

.breadcrumb-sep { color: var(--text-tertiary); font-size: 0.75rem; }

/* ============================================================
   18. Chips
   ============================================================ */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--border-default);
    border-radius: 999px;
    font-size: 0.76rem;
    color: var(--text-secondary);
    background: var(--bg-surface);
}

.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ============================================================
   19. Modal / Dialog
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26, 26, 46, 0.5);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

dialog.modal-dialog {
    position: fixed;
    inset: 0;
    z-index: 100;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    background: transparent;
    border: none;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

dialog.modal-dialog::backdrop {
    background: rgba(26, 26, 46, 0.5);
}

dialog.modal-dialog:not([open]) { display: none; }

.modal-content {
    background: var(--bg-overlay);
    border: 1px solid var(--border-default);
    border-radius: 0.75rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 48rem;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-default);
}

.modal-body {
    padding: 1.25rem 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-default);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.25rem;
    line-height: 1;
}

.modal-close:hover { color: var(--text-primary); }

/* ============================================================
   20. Details/Summary (replaces daisyUI collapse)
   ============================================================ */
details.collapsible {
    border: 1px solid var(--border-default);
    border-radius: 0.65rem;
    background: var(--bg-elevated);
}

details.collapsible > summary {
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-weight: 500;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

details.collapsible > summary::-webkit-details-marker { display: none; }

details.collapsible > summary .chevron {
    transition: transform 200ms ease;
    color: var(--text-tertiary);
}

details.collapsible[open] > summary .chevron { transform: rotate(180deg); }

details.collapsible > .details-body {
    padding: 0 1rem 1rem;
}

/* ============================================================
   21. Pagination
   ============================================================ */
.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    margin-top: 2rem;
}

.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.5rem;
    border-radius: 0.4rem;
    font-size: 0.82rem;
    font-weight: 500;
    border: 1px solid var(--border-default);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 150ms ease;
}

.page-btn:hover { border-color: var(--accent); color: var(--accent); }

.page-btn.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ============================================================
   22. Alert / Notice Boxes
   ============================================================ */
.notice {
    padding: 0.7rem 0.9rem;
    border-radius: 0.5rem;
    font-size: 0.82rem;
    border: 1px solid var(--border-default);
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

.notice-info {
    background: var(--info-subtle);
    border-color: rgba(37, 99, 235, 0.15);
    color: var(--info);
}

.notice-error {
    background: var(--error-subtle);
    border-color: rgba(220, 38, 38, 0.15);
    color: var(--error);
}

/* ============================================================
   23. Proof Chips (Hero)
   ============================================================ */
.proof-chip {
    border: 1px solid var(--border-default);
    border-radius: 0.65rem;
    padding: 0.6rem 0.8rem;
    background: var(--bg-elevated);
    font-size: 0.82rem;
    color: var(--text-secondary);
}

/* ============================================================
   24. Video Cards
   ============================================================ */
.video-card {
    display: block;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: 0.75rem;
    overflow: hidden;
    transition: box-shadow 150ms ease, border-color 150ms ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.video-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.video-card-thumb {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    display: block;
}

.video-card-body { padding: 0.85rem; }

.video-card-placeholder {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: var(--bg-elevated);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    font-size: 0.82rem;
}

/* ============================================================
   25. Channel Avatar
   ============================================================ */
.channel-avatar {
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-default);
}

.channel-avatar-placeholder {
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    background: var(--nav-bg);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
}

.channel-avatar-sm { width: 2.5rem; height: 2.5rem; font-size: 1rem; }

/* ============================================================
   26. HTMX States
   ============================================================ */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-request.htmx-indicator { display: inline-flex; }

/* Spinner */
.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--border-default);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 600ms linear infinite;
}

.spinner-sm { width: 0.75rem; height: 0.75rem; border-width: 1.5px; }

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

/* ============================================================
   27. Links
   ============================================================ */
.link { color: var(--accent); }
.link:hover { color: var(--accent-hover); text-decoration: underline; }

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

/* ============================================================
   28. Transcript Segments
   ============================================================ */
.segment-time {
    cursor: pointer;
    font-family: var(--font-mono);
    color: var(--accent);
    font-size: 0.82rem;
}

.segment-time:hover { text-decoration: underline; }

/* ============================================================
   29. Accent Bar Top
   ============================================================ */
.accent-bar-top {
    height: 3px;
    background: var(--accent);
    border-radius: 0.75rem 0.75rem 0 0;
}

/* ============================================================
   30. Utilities
   ============================================================ */
.text-accent  { color: var(--accent); }
.text-success { color: var(--success); }
.text-error   { color: var(--error); }
.text-warning { color: var(--warning); }
.text-info    { color: var(--info); }
.text-muted   { color: var(--text-secondary); }
.text-faint   { color: var(--text-tertiary); }

.bg-accent-subtle  { background: var(--accent-subtle); }
.bg-success-subtle { background: var(--success-subtle); }
.bg-error-subtle   { background: var(--error-subtle); }

/* Orange bar on top of cards */
.accent-top { border-top: 3px solid var(--accent); }

/* Loading state for buttons */
.btn.is-loading { position: relative; color: transparent; pointer-events: none; }
.btn.is-loading::after {
    content: '';
    position: absolute;
    width: 1rem; height: 1rem;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 600ms linear infinite;
}

/* ============================================================
   31. Chat Toggle Switch
   ============================================================ */
.video-card-wrapper,
.channel-card-wrapper {
    position: relative;
    transition: opacity 200ms ease;
}

.video-card-wrapper.is-chat-disabled,
.channel-card-wrapper.is-chat-disabled {
    opacity: 0.6;
}

.chat-toggle {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 10;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(4px);
    padding: 0.2rem 0.45rem;
    border-radius: 999px;
    border: 1px solid var(--border-default);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chat-toggle input { display: none; }

.chat-toggle-track {
    width: 1.6rem;
    height: 0.9rem;
    background: var(--border-default);
    border-radius: 999px;
    position: relative;
    transition: background 150ms ease;
}

.chat-toggle-thumb {
    position: absolute;
    top: 0.1rem;
    left: 0.1rem;
    width: 0.7rem;
    height: 0.7rem;
    background: #fff;
    border-radius: 50%;
    transition: transform 150ms ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.chat-toggle input:checked ~ .chat-toggle-track {
    background: var(--accent);
}

.chat-toggle input:checked ~ .chat-toggle-track .chat-toggle-thumb {
    transform: translateX(0.7rem);
}

.chat-toggle-label {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}

.chat-toggle-channel {
    top: 0.4rem;
    right: 0.4rem;
}

/* ============================================================
   32. Chat UI
   ============================================================ */

/* Chat page overrides the page-shell max-width */
.chat-page-shell {
    max-width: 100%;
    margin: 0;
    padding: 0;
    height: calc(100dvh - 8.75rem);
    display: flex;
    overflow: hidden;
}

/* --- Sidebar --- */
.chat-sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-default);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.chat-sidebar-header {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-muted);
    flex-shrink: 0;
}

.chat-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.chat-sidebar-group-label {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    padding: 0.75rem 0.5rem 0.35rem;
}

.chat-session-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
    border-radius: 0.5rem;
    font-size: 0.84rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
    text-decoration: none;
    position: relative;
}

.chat-session-item:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.chat-session-item.is-active {
    background: var(--accent-subtle);
    color: var(--accent);
    font-weight: 600;
}

.chat-session-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.chat-session-title-input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--accent);
    border-radius: 0.3rem;
    padding: 0.1rem 0.3rem;
    font-size: 0.84rem;
    font-family: var(--font-body);
    background: var(--bg-surface);
    color: var(--text-primary);
    outline: none;
}

.chat-session-actions {
    display: none;
    align-items: center;
    gap: 0.15rem;
    flex-shrink: 0;
}

.chat-session-item:hover .chat-session-actions {
    display: flex;
}

.chat-session-action-btn {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0.15rem;
    border-radius: 0.25rem;
    font-size: 0.8rem;
    line-height: 1;
    transition: color 120ms ease, background 120ms ease;
}

.chat-session-action-btn:hover {
    color: var(--text-primary);
    background: var(--bg-shell);
}

.chat-session-action-btn.is-delete:hover {
    color: var(--error);
    background: var(--error-subtle);
}

/* --- Main chat area --- */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-shell);
    height: 100%;
}

.chat-header {
    padding: 0.6rem 1.25rem;
    border-bottom: 1px solid var(--border-default);
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header-title {
    font-family: var(--font-headline);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-video-count {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-tertiary);
    background: var(--bg-elevated);
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    border: 1px solid var(--border-muted);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.chat-messages-inner {
    max-width: 48rem;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* --- Messages --- */
.chat-msg {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.chat-msg-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
}

.chat-msg-avatar.is-user {
    background: var(--nav-bg);
    color: #fff;
}

.chat-msg-avatar.is-assistant {
    background: var(--accent);
    color: #fff;
}

.chat-msg-body {
    flex: 1;
    min-width: 0;
}

.chat-msg-role {
    font-size: 0.72rem;
    font-weight: 600;
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.25rem;
    color: var(--text-tertiary);
}

.chat-msg-content {
    font-size: 0.92rem;
    line-height: 1.65;
    color: var(--text-primary);
}

.chat-msg-content p { margin: 0 0 0.6rem; }
.chat-msg-content p:last-child { margin-bottom: 0; }
.chat-msg-content pre {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.82rem;
}
.chat-msg-content code {
    font-family: var(--font-mono);
    font-size: 0.84em;
    background: var(--bg-elevated);
    padding: 0.1rem 0.35rem;
    border-radius: 0.25rem;
}
.chat-msg-content pre code {
    background: none;
    padding: 0;
}
.chat-msg-content ul, .chat-msg-content ol {
    padding-left: 1.25rem;
    margin: 0.4rem 0 0.6rem;
}
.chat-msg-content li { margin-bottom: 0.25rem; }
.chat-msg-content blockquote {
    border-left: 3px solid var(--accent);
    margin: 0.5rem 0;
    padding: 0.25rem 0.75rem;
    color: var(--text-secondary);
}
.chat-msg-content h1, .chat-msg-content h2, .chat-msg-content h3 {
    font-family: var(--font-headline);
    margin: 0.75rem 0 0.35rem;
    line-height: 1.3;
}
.chat-msg-content h1 { font-size: 1.25rem; }
.chat-msg-content h2 { font-size: 1.1rem; }
.chat-msg-content h3 { font-size: 1rem; }

/* --- Source cards --- */
.chat-sources {
    margin-top: 0.6rem;
}

.chat-sources-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: none;
    border: 1px solid var(--border-default);
    border-radius: 999px;
    padding: 0.2rem 0.6rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-body);
    transition: all 120ms ease;
}

.chat-sources-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.chat-sources-toggle .chevron {
    transition: transform 200ms ease;
    font-size: 0.65rem;
}

.chat-sources-toggle.is-open .chevron {
    transform: rotate(180deg);
}

.chat-sources-list {
    display: none;
    margin-top: 0.5rem;
    gap: 0.4rem;
    flex-direction: column;
}

.chat-sources-list.is-open {
    display: flex;
}

.chat-source-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-muted);
    border-radius: 0.5rem;
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
}

.chat-source-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}

.chat-source-title {
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-source-time {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--accent);
    flex-shrink: 0;
}

.chat-source-similarity {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-tertiary);
    background: var(--bg-shell);
    padding: 0.1rem 0.35rem;
    border-radius: 999px;
    flex-shrink: 0;
}

.chat-source-snippet {
    color: var(--text-secondary);
    font-size: 0.78rem;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* --- Thinking indicator --- */
.chat-thinking {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0;
}

.chat-thinking-dots {
    display: flex;
    gap: 0.25rem;
}

.chat-thinking-dots span {
    width: 0.4rem;
    height: 0.4rem;
    background: var(--text-tertiary);
    border-radius: 50%;
    animation: chatBounce 1.2s infinite ease-in-out;
}

.chat-thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.chat-thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-0.35rem); opacity: 1; }
}

.chat-thinking-text {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    font-style: italic;
}

/* --- Input bar --- */
.chat-input-bar {
    padding: 0.75rem 1.25rem 1rem;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-default);
    flex-shrink: 0;
}

.chat-input-inner {
    max-width: 48rem;
    margin: 0 auto;
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.chat-input-field {
    flex: 1;
    resize: none;
    border: 1px solid var(--border-default);
    border-radius: 0.65rem;
    padding: 0.65rem 0.85rem;
    font-size: 0.9rem;
    font-family: var(--font-body);
    background: var(--bg-shell);
    color: var(--text-primary);
    min-height: 2.6rem;
    max-height: 8rem;
    line-height: 1.4;
    transition: border-color 150ms ease, box-shadow 150ms ease;
    overflow-y: auto;
}

.chat-input-field::placeholder { color: var(--text-tertiary); }

.chat-input-field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.chat-send-btn {
    width: 2.6rem;
    height: 2.6rem;
    border-radius: 0.65rem;
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background 150ms ease;
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Empty state --- */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    color: var(--text-tertiary);
}

.chat-empty-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: var(--border-default);
}

.chat-empty-title {
    font-family: var(--font-headline);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.chat-empty-desc {
    font-size: 0.88rem;
    color: var(--text-secondary);
    max-width: 28rem;
}

/* --- Mobile sidebar toggle --- */
.chat-mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1.1rem;
}

@media (max-width: 767px) {
    .chat-sidebar {
        position: fixed;
        top: 3.25rem;
        left: 0;
        bottom: 0;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform 200ms ease;
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.1);
    }

    .chat-sidebar.is-open {
        transform: translateX(0);
    }

    .chat-mobile-toggle {
        display: flex;
        min-width: 2.75rem;
        min-height: 2.75rem;
        align-items: center;
        justify-content: center;
    }

    .chat-input-inner {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 2.75rem;
        align-items: end;
    }
    #chat-retrieval-scope, #chat-channel-filter { grid-column: 1 / -1; width: 100%; max-width: none !important; }
    #chat-channel-filter:disabled { display: none; }
    .chat-input-field { grid-column: 1; min-width: 0; min-height: 2.75rem; }
    .chat-send-btn { width: 2.75rem; height: 2.75rem; }

    .chat-sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        top: 3.25rem;
        background: rgba(0, 0, 0, 0.3);
        z-index: 39;
    }

    .chat-sidebar-overlay.is-open {
        display: block;
    }
}

/* --- Chat/RAG toggle switch --- */
.toggle-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}
.toggle-track {
    display: inline-block;
    width: 2.25rem;
    height: 1.25rem;
    border-radius: 9999px;
    position: relative;
    transition: background 150ms ease;
}
.toggle-thumb {
    display: block;
    width: 1rem;
    height: 1rem;
    border-radius: 9999px;
    background: #fff;
    position: absolute;
    top: 0.125rem;
    transition: left 150ms ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.toggle-on .toggle-track  { background: var(--accent, #7c6af7); }
.toggle-on .toggle-thumb  { left: 1.125rem; }
.toggle-off .toggle-track { background: var(--border-default, #3a3a4a); }
.toggle-off .toggle-thumb { left: 0.125rem; }

/* video-card chat-enabled badge */
.video-card-rag-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    padding: 0.15rem 0.45rem;
    border-radius: 9999px;
    text-transform: uppercase;
}
.video-card-rag-badge.rag-on  { background: rgba(124,106,247,0.15); color: var(--accent, #7c6af7); }
.video-card-rag-badge.rag-off { background: rgba(255,255,255,0.05); color: var(--text-tertiary, #666); }
