/* /assets/styles.css */
/* A single, combined stylesheet for all ByteGuard Frontend components. */

/* --- Global Styles --- */
html,
body {
    background: #fff;
}

:root {
    --bgf-primary: #0EA5E9;          /* sky-500 — electric cyan-blue */
    --bgf-primary-hover: #0284C7;    /* sky-600 — darker on hover */
    --bgf-primary-text: #FFFFFF;     /* readable on cyan */
    --bgf-accent: #0891B2;           /* cyan-600 — secondary accent */
    --bgf-accent-soft: #BAE6FD;      /* sky-200 — soft accent border */
    --bgf-active-bg: #E0F2FE;        /* sky-100 — selected/active tint */
    --bgf-hover-bg: #F0F9FF;         /* sky-50 — hover tint */
    --bgf-glow: #22D3EE;             /* cyan-400 — neon glow */
    --bgf-deep: #0B1E3F;             /* deep navy from hero brain */
    --bgf-card-bg: #ffffff;
    --bgf-text: #0f172a;             /* slate-900 */
    --bgf-muted: #64748b;             /* slate-500 */
    --bgf-border: #cbd5e1;           /* slate-300 */
    --focus-ring: #0EA5E9;           /* matches primary so focus reads cohesive */

    /* Cap used by chat window auto-grow JS (read via getComputedStyle). */
    --composer-actions-h: 140;
}

*:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

/* --- Layout & Utilities --- */
.bgf-wrap {
    max-width: 720px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* Stacked layout: chat first, sidebar (session / AI settings / convos)
   below. Single column, centered, capped width for readability. */
.layout {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 1rem;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
}

.main {
    order: 1;
    display: flex;
    flex-direction: column;
    min-height: 280px;
    overflow: hidden;
}

.sidebar {
    order: 2;
}

.card {
    border: 1px solid #e3e6ea;
    border-radius: 12px;
    padding: 1rem;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.lbl {
    font-size: .85rem;
    color: #57606a;
    font-weight: 500;
}

.muted {
    color: #6b7280;
    font-size: .9rem;
}

.muted.success {
    color: #0c7a43;
}

.muted.danger {
    color: #b42318;
}

.link {
    color: #2563eb;
    text-decoration: none;
}

.link:hover {
    text-decoration: underline;
}

.inp {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: .6rem .7rem;
    font: inherit;
    background: #f9fafb;
    transition: box-shadow .15s, border-color .15s, background-color .15s;
}

.inp.small {
    padding: .3rem .5rem;
    font-size: .9rem;
}

.inp:focus,
.inp:focus-visible {
    background: #fff;
    border-color: var(--bgf-primary, #0EA5E9);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, .25);
    outline: none;
}

/* Browser autofill (Chrome / Edge / Safari) ships with a hardcoded
   yellow background and border. Repaint it in our cyan theme. The
   long transition is the standard trick to stall Chrome's yellow
   flash before swapping in our own background. */
.inp:-webkit-autofill,
.inp:-webkit-autofill:hover,
.inp:-webkit-autofill:focus,
.inp:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 1000px #ffffff inset !important;
    box-shadow: 0 0 0 1000px #ffffff inset !important;
    -webkit-text-fill-color: var(--bgf-text, #0f172a) !important;
    caret-color: var(--bgf-text, #0f172a);
    border-color: var(--bgf-border, #cbd5e1) !important;
    transition: background-color 5000s ease-in-out 0s;
}

.inp:-webkit-autofill:focus {
    border-color: var(--bgf-primary, #0EA5E9) !important;
    -webkit-box-shadow: 0 0 0 1000px #ffffff inset, 0 0 0 3px rgba(14, 165, 233, .25) !important;
    box-shadow: 0 0 0 1000px #ffffff inset, 0 0 0 3px rgba(14, 165, 233, .25) !important;
}

.btn {
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    padding: .5rem .8rem;
    border-radius: 10px;
    font: inherit;
    cursor: pointer;
    transition: background-color 0.2s, box-shadow .15s, border-color .15s;
}

.btn:hover {
    background: #eef2ff;
}

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

.btn.btn-primary {
    background: var(--bgf-primary);
    border-color: var(--bgf-primary);
    color: var(--bgf-primary-text);
    font-weight: 500;
}

.btn.btn-primary:hover {
    background: var(--bgf-primary-hover);
    border-color: var(--bgf-primary-hover);
}

.btn.btn-primary:focus-visible {
    box-shadow: 0 0 0 3px rgba(14, 165, 233, .45);
}

.btn.btn-ghost {
    background: transparent;
    border: none;
    color: #475569;
}

.btn.btn-ghost:hover {
    background: #f1f5f9;
}

/* Inline action buttons */
.btn-inline {
    all: unset;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    cursor: pointer;
    font-size: .85rem;
    color: #2563eb;
    padding: 2px 8px;
    border-radius: 999px;
}
.btn-inline:hover {
    background: #e2e8f0;
}
.btn-inline:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

/* --- API Keys (AI settings) --- */
.api-keys-card {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.api-keys-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.api-keys-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}

.api-keys-table th,
.api-keys-table td {
    padding: .5rem .6rem;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
    font-size: .9rem;
    vertical-align: top;
}

.api-keys-table th {
    background: #f8fafc;
    color: #475569;
    font-weight: 600;
}

.api-key-raw {
    padding: .6rem .7rem;
    border: 1px solid var(--bgf-accent-soft, #BAE6FD);
    background: var(--bgf-hover-bg, #F0F9FF);
    border-radius: 10px;
    color: #0c4a6e;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    word-break: break-all;
}

.model-narrative {
    margin: .45rem 0 .55rem;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    padding: .55rem .65rem;
    display: grid;
    gap: .25rem;
}

.model-narrative-name {
    font-size: .87rem;
    font-weight: 600;
    color: #0f172a;
}

.model-narrative-line {
    font-size: .83rem;
    color: #334155;
    line-height: 1.3;
}

.model-current-row {
    align-items: center;
}

.current-agent-name {
    font-size: .86rem;
    font-weight: 700;
    color: #0c4a6e;
    background: var(--bgf-active-bg, #E0F2FE);
    border: 1px solid var(--bgf-primary, #0EA5E9);
    border-radius: 999px;
    padding: .15rem .6rem;
    max-width: 64%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-select-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
    gap: .5rem;
}

.model-select-row #agentSelect {
    min-width: 0;
}

.voice-clone-controls {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.voice-clone-select-row {
    display: flex;
    align-items: stretch;
}

.voice-clone-select-row #voiceCloneSelect {
    flex: 1 1 auto;
}

.voice-clone-action-row {
    display: flex;
    align-items: stretch;
    gap: .5rem;
}

.voice-clone-add-wrap {
    flex: 1 1 50%;
    min-width: 0;
}

.voice-clone-add-wrap #addVoiceBtn {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.voice-clone-right-wrap {
    flex: 1 1 50%;
    min-width: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: .4rem;
}

.voice-clone-right-wrap #testVoiceBtn {
    min-width: 112px;
}

.voice-clone-right-wrap #deleteVoiceBtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Left utility panel: normalize control heights/alignment */
.layout .sidebar .card .model-select-row #agentSelect,
.layout .sidebar .card .model-select-row #saveModelBtn,
.layout .sidebar .card .voice-clone-select-row #voiceCloneSelect,
.layout .sidebar .card .voice-clone-add-wrap #addVoiceBtn,
.layout .sidebar .card .voice-clone-right-wrap #testVoiceBtn,
.layout .sidebar .card .voice-clone-right-wrap #deleteVoiceBtn {
    height: 48px;
    min-height: 48px;
    box-sizing: border-box;
}

.layout .sidebar .card .model-select-row #saveModelBtn,
.layout .sidebar .card .voice-clone-add-wrap #addVoiceBtn,
.layout .sidebar .card .voice-clone-right-wrap #testVoiceBtn {
    padding-top: 0;
    padding-bottom: 0;
    line-height: 1;
}

@media (max-width: 640px) {
    .voice-clone-action-row {
        flex-direction: column;
        align-items: stretch;
    }

    .voice-clone-right-wrap {
        justify-content: space-between;
    }
}

/* --- Toast Notification Styles --- */
.toast {
    background: #111827;
    color: #fff;
    padding: .5rem .75rem;
    border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .15);
    font-size: .9rem;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 360px;
}

.toast.error {
    background: #b42318;
}

.toast-message {
    flex-grow: 1;
}

.toast-close-btn {
    margin-left: 8px;
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0.25rem;
}

/* --- Responsive & Accessibility --- */
@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
        height: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .btn,
    .inp,
    .conv-item,
    .toggle-switch,
    .composer textarea {
        transition: none;
    }
}

/* --- Chat Window --- */
.chat-window-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    height: min(78vh, 920px);
    max-height: 920px;
    min-height: 520px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
}

@supports (height: 100dvh) {
    .chat-window-shell {
        height: min(78dvh, 920px);
    }
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    flex: 0 0 auto;
}

/* ============================================================
   Ingest cards row (replaces the old API-Docs / narrate toolbar)
   ============================================================ */
.toolbar.ingest-cards {
    /* Three equal-width cards spanning the full chat-window width. */
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    padding: 8px;
}

.ingest-card {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 12px;
    min-height: 56px;
    border: 1px solid var(--bgf-border, #d0d0d0);
    border-radius: 10px;
    background: var(--bgf-card-bg, #fff);
    color: var(--bgf-text, #222);
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    overflow: hidden;
    transition: filter 0.25s ease,
                background 0.15s ease,
                box-shadow 0.15s ease,
                transform 0.1s ease,
                border-color 0.15s ease;
}

.ingest-card:hover {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
    transform: translateY(-1px);
    border-color: var(--bgf-accent, #0891B2);
}

.ingest-card:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.10);
}

.ingest-card:focus-visible {
    outline: 2px solid var(--bgf-accent, #0891B2);
    outline-offset: 2px;
}

.ingest-card-icon {
    font-size: 1.35rem;
    line-height: 1;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.ingest-card:hover .ingest-card-icon {
    transform: scale(1.12);
}

.ingest-card-label {
    flex: 0 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Optional small status text under the label (e.g. "Running") — populated
   by ingest_panels.js when a job is active. */
.ingest-card-status {
    position: absolute;
    bottom: 4px;
    right: 8px;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--bgf-muted, #888);
}

/* Wikipedia card: grayscale + dimmed by default, restored on hover.
   Indicates "low-priority public utility, not user-related". */
.ingest-card-wikipedia {
    filter: grayscale(1) opacity(0.72);
}
.ingest-card-wikipedia:hover {
    filter: grayscale(0) opacity(1);
}

/* Active job indicator: small pulsing green dot in the top-right corner.
   When active, the wiki card overrides its grayscale so the running
   state is always visible. */
.ingest-card.ingest-card-active {
    border-color: var(--bgf-accent, #0891B2);
    filter: none;
    background: var(--bgf-active-bg, #E0F2FE);
}
.ingest-card.ingest-card-active::after {
    content: "";
    position: absolute;
    top: 8px;
    right: 8px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #2ecc71;
    box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.6);
    animation: bgf-ingest-pulse 1.5s infinite;
}
@keyframes bgf-ingest-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.6); }
    70%  { box-shadow: 0 0 0 9px rgba(46, 204, 113, 0); }
    100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

/* Narrow screens: stack the cards vertically so labels stay readable. */
@media (max-width: 720px) {
    .toolbar.ingest-cards {
        grid-template-columns: 1fr;
    }
    .ingest-card {
        min-height: 48px;
        padding: 10px 12px;
    }
}

/* ============================================================
   Ingest popup subpanels (form + progress) — Phase C
   ============================================================ */
.ingest-subpanel {
    border: 1px solid var(--bgf-border, #d0d0d0);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 12px;
    background: var(--bgf-card-bg, #fff);
}
.ingest-subpanel:last-child {
    margin-bottom: 0;
}
.ingest-subpanel-heading {
    margin: 0 0 8px 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--bgf-text, #222);
    border-bottom: 1px solid var(--bgf-border, #e0e0e0);
    padding-bottom: 6px;
}
.ingest-subpanel-help {
    margin: 4px 0 10px 0;
    font-size: 0.85rem;
    color: var(--bgf-muted, #666);
    line-height: 1.4;
}

/* Form fields inside a subpanel */
.ingest-subpanel-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}
.ingest-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
    color: var(--bgf-text, #222);
}
.ingest-field-checkbox {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.ingest-field-checkbox input[type="checkbox"] {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    cursor: pointer;
}
.ingest-field-label {
    font-weight: 500;
}
.ingest-field input[type="text"],
.ingest-field input[type="date"] {
    padding: 6px 9px;
    border: 1px solid var(--bgf-border, #d0d0d0);
    border-radius: 5px;
    font-family: inherit;
    font-size: 0.88rem;
    background: var(--bgf-card-bg, #fff);
    color: var(--bgf-text, #222);
}
.ingest-field input[type="text"]:focus,
.ingest-field input[type="date"]:focus {
    outline: none;
    border-color: var(--bgf-accent, #0891B2);
    box-shadow: 0 0 0 2px rgba(230, 168, 23, 0.18);
}

/* Inline error display above the action buttons */
.ingest-subpanel-error {
    margin: 6px 0 8px 0;
    padding: 6px 9px;
    border: 1px solid #f5c6cb;
    border-radius: 5px;
    background: #fdecea;
    color: #b71c1c;
    font-size: 0.83rem;
    line-height: 1.35;
}

/* Action button row (Start / Stop) */
.ingest-subpanel-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-bottom: 8px;
}
.ingest-subpanel-actions .btn[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Progress display: status badge + bar + log */
.ingest-progress {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--bgf-border, #e0e0e0);
}
.ingest-progress[hidden] { display: none; }

.ingest-progress-status {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--bgf-hover-bg, #F0F9FF);
    color: var(--bgf-text, #222);
    font-size: 0.78rem;
    font-weight: 600;
    margin-bottom: 6px;
}
.ingest-progress-status[data-status-value="running"],
.ingest-progress-status[data-status-value="starting"] {
    background: rgba(46, 204, 113, 0.18);
    color: #1c7a3a;
}
.ingest-progress-status[data-status-value="paused"],
.ingest-progress-status[data-status-value="pause_requested"] {
    background: rgba(230, 168, 23, 0.20);
    color: #8a5a00;
}
.ingest-progress-status[data-status-value="failed"] {
    background: #fdecea;
    color: #b71c1c;
}
.ingest-progress-status[data-status-value="cancelled"],
.ingest-progress-status[data-status-value="canceled"],
.ingest-progress-status[data-status-value="stopped"] {
    background: #eceff1;
    color: #455a64;
}
.ingest-progress-status[data-status-value="completed"],
.ingest-progress-status[data-status-value="complete"] {
    background: rgba(46, 204, 113, 0.30);
    color: #145a26;
}

.ingest-progress-stage {
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--bgf-text, #222);
}

.ingest-progress-bar {
    height: 8px;
    background: var(--bgf-hover-bg, #E0F2FE);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 6px;
}
.ingest-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--bgf-accent, #0891B2);
    transition: width 0.5s ease;
}
.ingest-progress-fill.indeterminate {
    width: 35% !important;
    background: linear-gradient(
        90deg,
        var(--bgf-accent, #0891B2) 0%,
        rgba(230, 168, 23, 0.4) 50%,
        var(--bgf-accent, #0891B2) 100%
    );
    background-size: 200% 100%;
    animation: bgf-indeterminate 1.6s linear infinite;
}
@keyframes bgf-indeterminate {
    0%   { background-position: -100% 0; }
    100% { background-position:  100% 0; }
}

.ingest-progress-text {
    font-size: 0.82rem;
    color: var(--bgf-muted, #666);
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums;
}
.ingest-progress-detail {
    font-size: 0.82rem;
    color: var(--bgf-text, #222);
    margin-bottom: 6px;
    line-height: 1.4;
}
.ingest-progress-log {
    list-style: none;
    margin: 6px 0 0 0;
    padding: 6px 9px;
    background: var(--bgf-hover-bg, #F0F9FF);
    border: 1px solid var(--bgf-border, #e8e8e8);
    border-radius: 5px;
    font-size: 0.78rem;
    color: var(--bgf-muted, #666);
    max-height: 110px;
    overflow-y: auto;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.ingest-progress-log:empty {
    display: none;
}
.ingest-progress-log li {
    padding: 1px 0;
    border-bottom: 1px dotted transparent;
}

.ingest-modal-footnote {
    font-style: italic;
    opacity: 0.8;
    margin: 4px 0 0 0;
}

.chat {
    flex: 1 1 auto;
    min-height: 220px;
    overflow-y: auto;
    scrollbar-width: thin;
    overscroll-behavior: contain;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

/* ============================================================
   Burst-active banner
   ------------------------------------------------------------
   Shown by media_jobs.js while a media job is in flight. The
   GPU broker stops ollama-voice + ollama-persistent during gen,
   so the chat agent is unreachable for the duration. Banner
   tells the user *why* chat isn't responding.
   ============================================================ */
.bgf-burst-banner {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0;
    padding: .55rem .9rem;
    font-weight: 600;
    font-size: .9rem;
    letter-spacing: 0.01em;
    color: #fff8e1;
    background: linear-gradient(90deg, rgba(217, 119, 6, 0.95), rgba(245, 158, 11, 0.95));
    border-bottom: 1px solid rgba(0, 0, 0, 0.25);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .9rem;
    flex-wrap: wrap;
}
.bgf-burst-banner-text {
    flex: 0 1 auto;
    text-align: center;
}
.bgf-burst-banner-timer {
    flex: 0 0 auto;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: .85rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: .2rem .55rem;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #fff8e1;
    white-space: nowrap;
    /* Stable width so the elapsed counter ticking up doesn't reflow the
       banner. 7ch covers "MM:SS / ~MM:00" reasonably; switch to a wider
       value if jobs ever exceed 99 minutes. */
    min-width: 8.5ch;
    text-align: center;
}
.bgf-burst-banner-timer-sep,
.bgf-burst-banner-timer-total {
    opacity: 0.78;
}
.bgf-burst-banner-cancel {
    flex: 0 0 auto;
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.55);
    background: rgba(0, 0, 0, 0.18);
    color: #fff8e1;
    padding: .25rem .7rem;
    border-radius: 6px;
    font: inherit;
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
}
.bgf-burst-banner-cancel:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.32);
    border-color: rgba(255, 255, 255, 0.8);
}
.bgf-burst-banner-cancel:active:not(:disabled) {
    transform: translateY(1px);
}
.bgf-burst-banner-cancel:disabled {
    opacity: 0.6;
    cursor: progress;
}

/* ============================================================
   Just-arrived flash on freshly-rendered media bubbles
   ------------------------------------------------------------
   Set briefly by media_jobs.js when an image/video bubble is
   inserted into the chat area, then removed ~1.8s later.
   Combined with scrollIntoView() it makes new generations
   unmistakable even if the user is scrolled to the page footer
   when the gen completes.
   ============================================================ */
@keyframes bgf-media-result-flash-anim {
    0%   { box-shadow: 0 0 0 0 rgba(14, 165, 233, 0.0); }
    20%  { box-shadow: 0 0 0 8px rgba(14, 165, 233, 0.55); }
    100% { box-shadow: 0 0 0 0 rgba(14, 165, 233, 0.0); }
}
.bgf-media-result-flash {
    animation: bgf-media-result-flash-anim 1.8s ease-out;
    border-radius: 14px;
}

/* ============================================================
   Stop button on Recent Jobs rows (only rendered while the row
   is in an active stage). Visually distinguished from
   Open / Retry / Duplicate so the destructive action stands out.
   ============================================================ */
.bgf-recent-job-stop {
    color: #fecaca;
    border-color: rgba(239, 68, 68, 0.55);
    background: rgba(239, 68, 68, 0.10);
    transition: background .15s, border-color .15s, color .15s;
}
.bgf-recent-job-stop:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.22);
    border-color: rgba(239, 68, 68, 0.85);
    color: #fff;
}
.bgf-recent-job-stop:disabled {
    opacity: 0.6;
    cursor: progress;
}

/* ============================================================
   Video preset picker cards (inside the generate-prompt modal)
   ------------------------------------------------------------
   Each card is one of the 4 (duration_s, resolution) combos
   that fit on the 2× 2070 SUPER pool. Selected state uses the
   primary cyan to match .btn.btn-primary.
   ============================================================ */
.bgf-preset-card {
    display: flex !important;
    align-items: flex-start !important;
    text-align: left !important;
    white-space: normal !important;
    line-height: 1.25;
    transition: border-color .15s, background .15s, transform .05s;
}
.bgf-preset-card:hover {
    border-color: rgba(14, 165, 233, 0.6);
}
.bgf-preset-card.bgf-preset-selected {
    background: rgba(14, 165, 233, 0.18);
    border-color: rgba(14, 165, 233, 0.85);
    box-shadow: 0 0 0 1px rgba(14, 165, 233, 0.4) inset;
}

.chat::-webkit-scrollbar {
    width: 10px;
}

.chat::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.chat::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

.msg {
    display: flex;
}

.msg.user {
    justify-content: flex-end;
}

.msg.ai,
.msg.error {
    justify-content: flex-start;
}

.bubble {
    max-width: min(90%, 760px);
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    background: #f8fafc;
    padding: .7rem .8rem;
}

.msg.user .bubble {
    background: var(--bgf-active-bg, #E0F2FE);
    border-color: var(--bgf-primary, #0EA5E9);
}

.bubble.error {
    background: #fef2f2;
    border-color: #fecaca;
}

.bubble-content {
    white-space: pre-wrap;
    word-break: break-word;
}

.msg-actions {
    display: flex;
    align-items: center;
    gap: .45rem;
    margin: .25rem 0 .75rem;
}

.thinking-panel,
.narration-bar {
    margin: 0 1rem .5rem;
    border: 1px solid #dbeafe;
    background: #eff6ff;
    border-radius: 10px;
    padding: .5rem .65rem;
    flex: 0 0 auto;
}

.thinking-panel #thinkingSummary {
    cursor: pointer;
    user-select: none;
    font-size: .9rem;
    color: #1e40af;
}

.thinking-panel.is-loading {
    border-color: var(--bgf-primary, #0EA5E9);
    background: var(--bgf-hover-bg, #F0F9FF);
}

.thinking-panel.is-loading #thinkingSummary {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
}

.thinking-panel.is-loading #thinkingSummary::before {
    content: "";
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(34, 211, 238, .35);
    border-top-color: var(--bgf-glow, #22D3EE);
    border-radius: 50%;
    animation: bgf-spin .8s linear infinite;
}

/* Finished state: subtle, non-intrusive */
.thinking-panel:not(.is-loading) {
    border-color: #e2e8f0;
    background: #f8fafc;
}
.thinking-panel:not(.is-loading) #thinkingSummary {
    color: #64748b;
    font-size: .85rem;
}

.thinking-content,
.narration-content {
    margin-top: .4rem;
    max-height: 200px;
    overflow: auto;
    font-size: .82rem;
    color: #475569;
}

.thinking-line {
    padding: .15rem 0;
    border-bottom: 1px dashed #e2e8f0;
}

.thinking-line:last-child {
    border-bottom: none;
}

.chat-load-status {
    margin: 0 1rem .5rem;
    padding: .55rem .7rem;
    border-radius: 8px;
    border: 1px solid #fed7aa;
    background: #fff7ed;
    color: #9a3412;
    font-size: .9rem;
    flex: 0 0 auto;
    display: none !important;
}

.chat-load-status[hidden] {
    display: none !important;
}

.composer {
    border-top: 1px solid #e5e7eb;
    padding: .8rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .6rem;
    background: #fff;
    flex: 0 0 auto;
}

.composer textarea {
    width: 100%;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: .65rem .75rem;
    font: inherit;
    line-height: 1.45;
    max-height: 140px;
}

.composer-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
}

.attachment-preview {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: .2rem .35rem;
    background: #f8fafc;
}

.attachment-preview img {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 6px;
}

.chat-busy-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .42);
    backdrop-filter: blur(1px);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    display: none !important;
}

.chat-busy-overlay[hidden] {
    display: none !important;
}

.chat-busy-box {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    background: #111827;
    color: #fff;
    border-radius: 999px;
    padding: .6rem 1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}

.bgf-spinner,
.btn-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: bgf-spin .8s linear infinite;
}

.btn-inline.is-loading {
    opacity: .95;
    color: #334155;
    cursor: wait;
}

.btn-inline.is-loading .btn-spinner {
    width: 14px;
    height: 14px;
    border-color: rgba(37, 99, 235, .35);
    border-top-color: #2563eb;
}

body.bgf-page-locked {
    overflow: hidden !important;
}

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

@media (max-width: 900px) {
.chat-window-shell {
        height: 70vh;
        min-height: 70vh;
        max-height: none;
    }

    .bubble {
        max-width: 96%;
    }
}

.chat-window-shell.bgf-interaction-locked {
    cursor: progress;
}

body.bgf-ui-locked #convList,
body.bgf-ui-locked .conv-item,
body.bgf-ui-locked .conv-actions,
body.bgf-ui-locked .conv-action-btn,
.chat-window-shell.bgf-interaction-locked .conv-list,
.chat-window-shell.bgf-interaction-locked .conv-item {
    pointer-events: none;
}

body.bgf-ui-locked #chatWindowShell {
    cursor: progress;
}

/* ============================================================
   Conversation list items
   ============================================================ */
.conv-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.35rem;
    border: 1px solid var(--bgf-border, #d0d0d0);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    background: var(--bgf-card-bg, #fff);
}

.conv-item:hover {
    background: var(--bgf-hover-bg, #F0F9FF);
    border-color: var(--bgf-accent, #0891B2);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.conv-item.active {
    border-color: var(--bgf-accent, #0891B2);
    background: var(--bgf-active-bg, #E0F2FE);
    box-shadow: 0 0 0 2px rgba(230, 168, 23, 0.18);
}

.conv-title {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.92rem;
    line-height: 1.4;
    color: var(--bgf-text, #222);
}

.conv-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
    margin-left: 0.5rem;
    opacity: 0;
    transition: opacity 0.15s;
}

.conv-item:hover .conv-actions {
    opacity: 1;
}

.conv-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--bgf-muted, #888);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.conv-action-btn svg {
    width: 16px;
    height: 16px;
}

.conv-action-btn:hover {
    background: var(--bgf-hover-bg, #E0F2FE);
    color: var(--bgf-text, #333);
    border-color: var(--bgf-border, #ccc);
}

/* Delete button turns red on hover */
.conv-action-btn:last-child:hover {
    background: #fdecea;
    color: #d32f2f;
    border-color: #f5c6cb;
}

/* ============================================================
   Project folders (conversation groups)
   ============================================================ */
.group-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.2rem 0.3rem;
    margin-top: 0.6rem;
    border-bottom: 1px solid var(--bgf-border, #d0d0d0);
}
.group-section-header:first-child {
    margin-top: 0;
}
.group-section-title {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--bgf-muted, #888);
}
.group-section-actions {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.group-action-btn {
    padding: 0.2rem 0.55rem;
    font-size: 0.78rem;
    border: 1px solid var(--bgf-border, #d0d0d0);
    border-radius: 6px;
    background: var(--bgf-card-bg, #fff);
    color: var(--bgf-text, #333);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.group-action-btn:hover {
    background: var(--bgf-hover-bg, #F0F9FF);
    border-color: var(--bgf-accent, #0891B2);
}

/* Icon-only refresh button on the projects header */
.group-refresh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    width: 26px;
    height: 26px;
    color: var(--bgf-muted, #888);
}
.group-refresh-btn svg {
    width: 14px;
    height: 14px;
    transition: transform 0.4s ease-out;
}
.group-refresh-btn:hover svg {
    transform: rotate(180deg);
    color: var(--bgf-accent, #0891B2);
}
.group-refresh-btn:active svg {
    transform: rotate(360deg);
}
.group-empty {
    padding: 0.3rem 0.6rem;
    font-size: 0.82rem;
    font-style: italic;
}

.group-folder {
    margin: 0.4rem 0;
    border: 1px solid var(--bgf-border, #d0d0d0);
    border-radius: 8px;
    background: var(--bgf-card-bg, #fff);
    overflow: hidden;
}
.group-folder-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.7rem;
    background: var(--bgf-hover-bg, #F0F9FF);
    border-bottom: 1px solid var(--bgf-border, #d0d0d0);
}
.group-folder-icon {
    flex-shrink: 0;
    font-size: 1rem;
}
.group-folder-name {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    color: var(--bgf-text, #222);
    font-size: 0.92rem;
}
.group-folder-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
}
.group-folder-header:hover .group-folder-actions {
    opacity: 1;
}
.group-folder-body {
    padding: 0.4rem 0.5rem;
    min-height: 32px;
}
.group-folder-body .conv-item {
    margin-bottom: 0.3rem;
}
.group-folder-body .conv-item:last-child {
    margin-bottom: 0;
}

/* Drag-and-drop affordances */
.conv-item.dragging {
    opacity: 0.55;
}
.group-folder-body.drop-target-active,
.ungrouped-drop-zone.drop-target-active {
    background: rgba(230, 168, 23, 0.10);
    outline: 2px dashed var(--bgf-accent, #0891B2);
    outline-offset: -2px;
    border-radius: 6px;
}
.ungrouped-drop-zone {
    min-height: 24px;
    padding: 0.1rem 0;
}

/* "Has instructions" badge on the project folder header */
.group-folder-instructions-badge {
    display: none;
    flex-shrink: 0;
    font-size: 0.85rem;
    line-height: 1;
    margin-left: -0.25rem;
}
.group-folder-header.has-instructions .group-folder-instructions-badge {
    display: inline-block;
}

/* Project filter input */
.group-filter-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    margin: 0.35rem 0 0.45rem;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--bgf-text, #222);
    background: var(--bgf-card-bg, #fff);
    border: 1px solid var(--bgf-border, #d0d0d0);
    border-radius: 6px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.group-filter-input:focus {
    outline: none;
    border-color: var(--bgf-accent, #0891B2);
    box-shadow: 0 0 0 2px rgba(230, 168, 23, 0.18);
}
.group-filter-input::placeholder {
    color: var(--bgf-muted, #999);
    font-style: italic;
}

/* Filtered-out folders */
.group-folder.group-folder-hidden {
    display: none;
}

.group-filter-no-matches {
    padding: 0.4rem 0.2rem;
    font-size: 0.82rem;
    font-style: italic;
}

/* ============================================================
   Generic modal (used by project instructions, possibly more)
   ============================================================ */
.bgf-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: bgfModalFade 0.12s ease-out;
}
@keyframes bgfModalFade {
    from { opacity: 0; }
    to { opacity: 1; }
}
.bgf-modal {
    width: min(640px, 100%);
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
    background: var(--bgf-card-bg, #fff);
    border: 1px solid var(--bgf-border, #d0d0d0);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}
.bgf-modal-header {
    padding: 0.9rem 1.1rem 0.6rem;
    border-bottom: 1px solid var(--bgf-border, #d0d0d0);
}
.bgf-modal-header h3 {
    margin: 0 0 0.15rem 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--bgf-text, #222);
}
.bgf-modal-subtitle {
    font-size: 0.85rem;
    color: var(--bgf-muted, #888);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bgf-modal-body {
    padding: 0.8rem 1.1rem;
    overflow-y: auto;
    flex: 1 1 auto;
}
.bgf-modal-help {
    margin: 0 0 0.6rem 0;
    font-size: 0.85rem;
    color: var(--bgf-muted, #666);
    line-height: 1.4;
}
.bgf-modal-textarea {
    width: 100%;
    min-height: 220px;
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--bgf-border, #d0d0d0);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.92rem;
    line-height: 1.45;
    resize: vertical;
    background: var(--bgf-card-bg, #fff);
    color: var(--bgf-text, #222);
    box-sizing: border-box;
}
.bgf-modal-textarea:focus {
    outline: none;
    border-color: var(--bgf-accent, #0891B2);
    box-shadow: 0 0 0 2px rgba(230, 168, 23, 0.18);
}
.bgf-modal-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    margin-top: 0.4rem;
    font-size: 0.78rem;
    color: var(--bgf-muted, #888);
}
.bgf-modal-counter-warn {
    color: #b8860b;
}
.bgf-modal-counter-error {
    color: #d32f2f;
    font-weight: 600;
}
.bgf-modal-warn {
    flex: 1 1 auto;
    text-align: right;
    color: #b8860b;
    font-style: italic;
}
.bgf-modal-footer {
    padding: 0.7rem 1.1rem;
    border-top: 1px solid var(--bgf-border, #d0d0d0);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    background: var(--bgf-hover-bg, #F0F9FF);
}

/* ============================================================
   Media jobs indicator (toolbar badge)
   ============================================================ */
.media-jobs-indicator {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    background: #1e293b;
    color: #94a3b8;
    border-radius: 999px;
    padding: .3rem .75rem;
    font-size: .8rem;
    line-height: 1;
}

.media-jobs-indicator[hidden] {
    display: none !important;
}

.media-jobs-count {
    font-weight: 700;
    color: #f1f5f9;
    min-width: 1ch;
    text-align: center;
}

/* ============================================================
   Media result message bubble (injected into chat area)
   ============================================================ */
.bgf-media-result {
    display: flex;
    justify-content: flex-start;
    padding: .5rem 0;
}

.bgf-media-bubble {
    background: #0f172a;
    border: 1px solid #1e3a5f;
    border-radius: 12px;
    padding: 1rem;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.bgf-media-bubble img,
.bgf-media-bubble video,
.bgf-media-bubble audio {
    max-width: 100%;
    border-radius: 8px;
    display: block;
}

.bgf-media-bubble audio {
    width: 100%;
}

.bgf-media-bubble .bgf-media-download {
    font-size: .8rem;
    color: #60a5fa;
    text-decoration: none;
}

.bgf-media-bubble .bgf-media-download:hover {
  text-decoration: underline;
}
.bgf-generation-lifecycle {
  font-size: .76rem;
  margin-top: .25rem;
  opacity: .88;
}
.bgf-generation-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .28rem .6rem;
  border-radius: 999px;
  border: 1px solid var(--border, rgba(255, 255, 255, .18));
  background: var(--panel, rgba(255, 255, 255, .06));
  color: var(--muted, #c8d0de);
  font-size: .75rem;
  line-height: 1;
}
.bgf-generation-chip-dot {
  width: .42rem;
  height: .42rem;
  border-radius: 999px;
  background: currentColor;
  opacity: .9;
}
.bgf-generation-chip[data-state="running"] .bgf-generation-chip-dot,
.bgf-generation-chip[data-state="postprocessing"] .bgf-generation-chip-dot {
  animation: bgf-gen-pulse 1.2s ease-in-out infinite;
}
.bgf-generation-chip[data-state="failed"] {
  color: #ff9b9b;
}
.bgf-generation-chip[data-state="done"] {
  color: #9ed7b0;
}
/* User-cancelled jobs: not a real failure, just an intentional stop.
   Slate-grey rather than angry red so the row doesn't read as "broken". */
.bgf-generation-chip[data-state="cancelled"] {
  color: #94a3b8;
}
.bgf-recent-jobs {
  border-top: 1px solid #1e3a5f;
  padding: .55rem .95rem .85rem;
  background: rgba(15, 23, 42, .72);
}
.bgf-recent-jobs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .45rem;
  color: #cbd5e1;
}
.bgf-recent-jobs-title {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
}
.bgf-active-count-wrap {
  font-size: .78rem;
  color: #94a3b8;
}
.bgf-recent-jobs-filters {
  display: inline-flex;
  gap: .35rem;
}
.bgf-recent-jobs-list {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  max-height: 220px;
  overflow: auto;
}
.bgf-recent-job-row {
  border: 1px solid #1e3a5f;
  border-radius: 10px;
  padding: .45rem .55rem;
  background: rgba(15, 23, 42, .6);
}
.bgf-recent-job-main {
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.bgf-recent-job-prompt {
  color: #e2e8f0;
  font-size: .8rem;
}
.bgf-recent-job-actions {
  display: inline-flex;
  gap: .55rem;
  margin-top: .35rem;
}
.media-jobs-indicator,
#bgfBurstBanner {
  display: none !important;
}
.bgf-job-timeline {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  margin-top: .2rem;
}
.bgf-tl-step {
  font-size: .68rem;
  padding: .14rem .42rem;
  border-radius: 999px;
  border: 1px solid #334155;
  color: #64748b;
  background: rgba(15, 23, 42, .55);
  text-transform: lowercase;
}
.bgf-tl-step.is-active {
  color: #93c5fd;
  border-color: #3b82f6;
  background: rgba(30, 64, 175, .25);
}
.bgf-tl-step.is-done {
  color: #9ed7b0;
  border-color: #166534;
  background: rgba(22, 101, 52, .22);
}
.bgf-tl-step.is-failed {
  color: #ff9b9b;
  border-color: #7f1d1d;
  background: rgba(127, 29, 29, .2);
}
@keyframes bgf-gen-pulse {
  0% { transform: scale(1); opacity: .55; }
  50% { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(1); opacity: .55; }
}

/* ============================================================
   Media generation modal (fallback when no chat area)
   ============================================================ */
.bgf-media-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .72);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 1rem;
}

.bgf-media-modal-box {
    background: #0f172a;
    border: 1px solid #1e3a5f;
    border-radius: 14px;
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}

.bgf-media-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .9rem 1.25rem;
    border-bottom: 1px solid #1e3a5f;
    flex-shrink: 0;
}

.bgf-media-modal-header h3 {
    margin: 0;
    font-size: 1rem;
    color: #f1f5f9;
    font-weight: 600;
}

.bgf-media-modal-close {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 .25rem;
    border-radius: 4px;
}

.bgf-media-modal-close:hover {
    color: #f1f5f9;
    background: rgba(255, 255, 255, .08);
}

.bgf-media-modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.bgf-media-modal-body img,
.bgf-media-modal-body video,
.bgf-media-modal-body audio {
    max-width: 100%;
    border-radius: 8px;
    display: block;
}

.bgf-media-modal-body audio {
    width: 100%;
}

.bgf-media-modal-body .bgf-media-download {
    font-size: .85rem;
    color: #60a5fa;
    text-decoration: none;
}

.bgf-media-modal-body .bgf-media-download:hover {
    text-decoration: underline;
}

/* ============================================================
   Phase 3 — Panel shared utilities
   ============================================================ */

/* Toast / inline status message */
.bgf-panel-toast {
    display: block;
    padding: .5rem .9rem;
    border-radius: 6px;
    font-size: .85rem;
    margin-bottom: .75rem;
}

.bgf-panel-toast[hidden] {
    display: none !important;
}

.bgf-toast-ok {
    background: #052e16;
    color: #86efac;
    border: 1px solid #166534;
}

.bgf-toast-err {
    background: #2d0a0a;
    color: #fca5a5;
    border: 1px solid #7f1d1d;
}

/* Status badge pill */
.bgf-badge {
    display: inline-block;
    padding: .15rem .55rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.bgf-badge-ok      { background: #052e16; color: #86efac; }
.bgf-badge-err     { background: #2d0a0a; color: #fca5a5; }
.bgf-badge-pending { background: #1c1917; color: #a8a29e; }
.bgf-badge-running { background: #0c1a2e; color: #93c5fd; }

/* Data table */
.bgf-panel-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.bgf-panel-table th,
.bgf-panel-table td {
    padding: .5rem .6rem;
    text-align: left;
    border-bottom: 1px solid #1e293b;
    vertical-align: middle;
}

.bgf-panel-table th {
    color: #64748b;
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom-color: #334155;
}

.bgf-panel-table tbody tr:last-child td {
    border-bottom: none;
}

.bgf-panel-table tbody tr:hover td {
    background: rgba(255, 255, 255, .025);
}

/* Inline edit form (appears as a table row) */
.bgf-edit-row td {
    padding: .6rem .6rem !important;
    background: #0c1624 !important;
}

.bgf-inline-form {
    display: grid;
    gap: .4rem;
}

.bgf-inline-form .inp {
    width: 100%;
}

/* File drop zone */
.bgf-dropzone {
    border: 2px dashed #334155;
    border-radius: 10px;
    padding: 2rem 1.25rem;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
    background: transparent;
    color: #94a3b8;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .4rem;
}

.bgf-dropzone:hover,
.bgf-dropzone:focus {
    border-color: #3b82f6;
    background: rgba(59, 130, 246, .06);
    outline: none;
}

.bgf-dropzone--over {
    border-color: #60a5fa;
    background: rgba(59, 130, 246, .12);
}

.bgf-dropzone-label {
    line-height: 1.5;
    pointer-events: none;
}

/* Key value display (copy modal) */
.bgf-key-value {
    color: #67e8f9;
}

/* --- File cards (coding agent multi-file responses) --- */
.bgf-file-card {
    border: 1px solid #334155;
    border-radius: 6px;
    margin: 0.75rem 0;
    overflow: hidden;
    background: #0f172a;
}

.bgf-file-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.75rem;
    background: #1e293b;
    border-bottom: 1px solid #334155;
}

.bgf-file-card-path {
    flex: 1;
    font-family: ui-monospace, 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.72rem;
    color: #94a3b8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bgf-file-card-toggle,
.bgf-file-card-copy {
    flex-shrink: 0;
    padding: 2px 9px;
    font-size: 0.68rem;
    border: 1px solid #475569;
    border-radius: 4px;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    line-height: 1.4;
    transition: background 0.12s, color 0.12s;
}

.bgf-file-card-toggle:hover,
.bgf-file-card-copy:hover {
    background: #334155;
    color: #e2e8f0;
}

/* Body collapses by default */
.bgf-file-card-body {
    display: none;
}

.bgf-file-card[data-collapsed="false"] .bgf-file-card-body {
    display: block;
}

/* Flush the inner codebox — card provides the border/radius already */
.bgf-file-card .codebox {
    margin: 0;
    border-radius: 0;
    border: none;
    border-top: none;
}

.bgf-file-card .codebox-header {
    border-radius: 0;
    border-top: none;
}

/* --- Media gallery in assistant chat bubbles --- */
.bubble-media-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0;
}

.bubble-media-thumb {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.bubble-media-thumb:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.bubble-media-videos {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 8px 0;
}

.bubble-media-video-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 6px 12px;
    color: inherit;
    text-decoration: none;
    font-size: 0.9em;
    transition: background 0.15s;
    max-width: fit-content;
}

.bubble-media-video-link:hover {
    background: rgba(255, 255, 255, 0.15);
}

.bubble-media-play-icon {
    font-size: 1.2em;
    opacity: 0.8;
}

/* ============================================================
   Media Gallery
   ============================================================ */
.mg-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--bgf-border, #d0d0d0);
}

.mg-nav {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.mg-month-label {
    font-weight: 600;
    font-size: 1.05rem;
    min-width: 160px;
    text-align: center;
}

.mg-filters {
    display: flex;
    gap: 0.25rem;
}

.mg-filters .mg-filter {
    font-size: 0.82rem;
    padding: 0.25rem 0.65rem;
    border-radius: 20px;
    border: 1px solid var(--bgf-border, #ccc);
    background: transparent;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.mg-filters .mg-filter.active {
    background: var(--bgf-accent, #0891B2);
    color: #fff;
    border-color: var(--bgf-accent, #0891B2);
}

.mg-filters .mg-filter:hover:not(.active) {
    background: var(--bgf-hover-bg, #f0f0f0);
}

.mg-actions {
    margin-left: auto;
}

.mg-download-zip {
    font-size: 0.85rem;
    padding: 0.35rem 0.8rem;
}

.mg-status {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

/* Grid */
.mg-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
}

.mg-card {
    border: 1px solid var(--bgf-border, #d0d0d0);
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
    background: var(--bgf-card-bg, #fff);
}

.mg-card:hover {
    border-color: var(--bgf-accent, #0891B2);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

.mg-thumb {
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
    position: relative;
}

.mg-thumb img,
.mg-thumb video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mg-thumb-video,
.mg-thumb-audio,
.mg-thumb-file {
    color: #999;
    background: #f0f0f0;
}

.mg-play-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5rem;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
    pointer-events: none;
}

.mg-card-info {
    padding: 0.4rem 0.6rem;
    font-size: 0.82rem;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mg-empty {
    text-align: center;
    padding: 2rem;
    font-size: 0.95rem;
}

/* Spinner */
@keyframes mg-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
.mg-spin { animation: mg-spin 1s linear infinite; }

/* ============================================================
   Lightbox
   ============================================================ */
.mg-lightbox {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mg-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.82);
}

.mg-lightbox-container {
    position: relative;
    z-index: 1;
    max-width: 92vw;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    background: #1a1a1a;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

.mg-lightbox-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.8rem;
    background: #222;
    color: #eee;
    font-size: 0.9rem;
}

.mg-lightbox-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mg-lightbox-close {
    font-size: 1.4rem;
    color: #ccc;
    padding: 0 0.3rem;
}

.mg-lightbox-close:hover { color: #fff; }

.mg-lightbox-dl {
    color: #ccc;
    text-decoration: none;
}
.mg-lightbox-dl:hover { color: #fff; }

.mg-lightbox-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow: auto;
    max-height: 82vh;
}

.mg-lightbox-body img {
    max-width: 100%;
    max-height: 78vh;
    object-fit: contain;
    border-radius: 4px;
}

.mg-lightbox-body video {
    max-width: 100%;
    max-height: 78vh;
    border-radius: 4px;
}

.mg-lightbox-audio-icon {
    color: #666;
    margin-bottom: 1rem;
    text-align: center;
}

/* ============================================================
   Chat inline media (replaces [media_id] references)
   ============================================================ */
.chat-inline-photo {
    position: relative;
    display: inline-block;
    max-width: 280px;
    margin: 0.3rem 0.2rem;
    border-radius: 8px;
    overflow: hidden;
    cursor: zoom-in;
    border: 1px solid var(--bgf-border, #d0d0d0);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-inline-photo:hover {
    border-color: var(--bgf-accent, #0891B2);
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.chat-inline-photo img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 240px;
    object-fit: cover;
}

.chat-inline-photo::after {
    content: "⤢";
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    background: rgba(11, 30, 63, 0.55);
    border-radius: 6px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    pointer-events: none;
    opacity: 0.85;
    transition: opacity 0.15s, background 0.15s;
}

.chat-inline-photo:hover::after {
    opacity: 1;
    background: var(--bgf-primary, #0EA5E9);
}

.chat-inline-video {
    display: block;
    max-width: 400px;
    margin: 0.4rem 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--bgf-border, #d0d0d0);
}

.chat-inline-video video {
    display: block;
    width: 100%;
    max-height: 300px;
}

.chat-inline-audio {
    display: block;
    margin: 0.4rem 0;
    max-width: 400px;
}

.chat-inline-audio audio {
    width: 100%;
}

/* Sources list styling */
.bubble-sources {
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(0,0,0,0.1);
    font-size: 0.85rem;
}

.bubble-sources-title {
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--bgf-muted, #666);
}

.bubble-sources-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.bubble-sources-list li {
    line-height: 1.4;
}

.bubble-source-badge {
    display: inline-block;
    font-size: 0.75rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    background: var(--bgf-hover-bg, #E0F2FE);
    color: var(--bgf-muted, #666);
    font-family: monospace;
}

.bubble-source-snippet {
    font-size: 0.8rem;
    color: var(--bgf-muted, #888);
    margin-top: 0.15rem;
    line-height: 1.3;
}

@media (max-width: 640px) {
    .mg-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    .mg-toolbar { flex-direction: column; align-items: flex-start; }
    .mg-actions { margin-left: 0; }
}

/* ============================================================
   ByteGuard cyan theme — sci-fi accents
   ============================================================ */

/* Auth wrapper used to carry its own light background + hex texture
   when the WP body was white. Now that the page bg is the dark hex
   theme, the wrapper just frames the card — keep it transparent so
   the page bg shows through cleanly. */
.bgf-wrap {
    position: relative;
    isolation: isolate;
    background: transparent;
    border-radius: 16px;
    padding: 1.25rem 1rem 2rem;
}

/* Branded header strip on auth cards. Shows the ByteGuard banner
   logo on a deep-navy field that frames the neon glow. The card body
   stays white for legibility. */
.bgf-wrap .card::before {
    content: "";
    display: block;
    height: 160px;
    margin: -1rem -1rem 1rem;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    background-color: var(--bgf-deep, #0B1E3F);
    background-image: url('images/byteguard-banner.png');
    background-position: center;
    background-size: contain;
    background-repeat: no-repeat;
    box-shadow: inset 0 -1px 0 var(--bgf-accent-soft, #BAE6FD);
}

/* The hero's bottom edge gets a glowing cyan rule — echoes the
   horizontal accent line in the hex reference. */
.bgf-wrap .card {
    border-color: var(--bgf-accent-soft, #BAE6FD);
    box-shadow: 0 1px 0 rgba(14, 165, 233, 0.08), 0 8px 24px rgba(11, 30, 63, 0.06);
}

/* Chat shell gets the hex texture as a faint backdrop so the sci-fi
   feel carries through, but cards on top remain crisp white. */
.layout {
    background:
        radial-gradient(ellipse at top right, rgba(34, 211, 238, 0.05), transparent 55%),
        url('images/byteguard-hex-bg.jpg') center/cover no-repeat;
    background-color: #f8fbff;
    border-radius: 12px;
}

/* Pills used on the login API status row — re-skin to match. */
.bgf-wrap .pill {
    border: 1px solid var(--bgf-accent-soft, #BAE6FD);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-radius: 999px;
    padding: .25rem .7rem;
    font-size: .85rem;
    color: #0c4a6e;
}

/* Primary button picks up a soft cyan glow on hover so the
   electric vibe from the brain image carries into actions. */
.btn.btn-primary {
    box-shadow: 0 1px 0 rgba(11, 30, 63, 0.06), 0 0 0 0 rgba(34, 211, 238, 0);
    transition: background-color 0.2s, box-shadow .2s, border-color .15s;
}
.btn.btn-primary:hover {
    box-shadow: 0 1px 0 rgba(11, 30, 63, 0.06), 0 0 18px rgba(34, 211, 238, 0.45);
}

/* Link color — keep readable but lean cyan to match the rest. */
.link {
    color: var(--bgf-accent, #0891B2);
}
.link:hover {
    color: var(--bgf-primary-hover, #0284C7);
}

/* ============================================================
   Chat bubble attached image — 480×270 max (16:9), click to zoom
   ============================================================ */
.bubble-image {
    /* Render as a button without the default button chrome. */
    all: unset;
    box-sizing: border-box;
    position: relative;
    display: inline-block;
    margin-top: .5rem;
    max-width: 480px;
    max-height: 270px;
    border-radius: 10px;
    overflow: hidden;
    cursor: zoom-in;
    border: 1px solid var(--bgf-border, #cbd5e1);
    background: #f1f5f9;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
    line-height: 0; /* kill inline-block descender gap */
}

.bubble-image:hover,
.bubble-image:focus-visible {
    border-color: var(--bgf-primary, #0EA5E9);
    box-shadow: 0 0 0 1px var(--bgf-primary, #0EA5E9), 0 4px 14px rgba(11, 30, 63, 0.12);
}

.bubble-image:focus-visible {
    outline: 2px solid var(--focus-ring, #0EA5E9);
    outline-offset: 2px;
}

.bubble-image img {
    display: block;
    max-width: 480px;
    max-height: 270px;
    width: auto;
    height: auto;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

/* Zoom-in indicator overlaid on the top-right corner. */
.bubble-image-zoom {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: rgba(11, 30, 63, 0.6);
    border-radius: 7px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    pointer-events: none;
    opacity: 0.9;
    transition: opacity 0.15s, background 0.15s, transform 0.15s;
}

.bubble-image:hover .bubble-image-zoom,
.bubble-image:focus-visible .bubble-image-zoom {
    opacity: 1;
    background: var(--bgf-primary, #0EA5E9);
    transform: scale(1.05);
}

.bubble-image-zoom svg {
    display: block;
}

/* ============================================================
   Chat bubble attached video — same 480×270 cap, inline player.
   ============================================================ */
.bubble-video {
    display: block;
    margin-top: .5rem;
    max-width: 480px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--bgf-border, #cbd5e1);
    background: #000;
    line-height: 0;
}
.bubble-video video {
    display: block;
    width: 100%;
    max-width: 480px;
    max-height: 270px;
    height: auto;
    background: #000;
}
.bubble-video:hover {
    border-color: var(--bgf-primary, #0EA5E9);
    box-shadow: 0 0 0 1px var(--bgf-primary, #0EA5E9), 0 4px 14px rgba(11, 30, 63, 0.12);
}

/* ============================================================
   Dark-glass overhaul (chat layout only)
   Reduces "white slab" feel — cards become translucent navy,
   cyan glow reads against dark, less wasted whitespace.
   Scoped to .layout so login/register pages stay light.
   ============================================================ */

/* Chat shell — frosted dark glass instead of solid white. */
.layout .chat-window-shell {
    background: rgba(11, 30, 63, 0.62) !important;
    backdrop-filter: blur(12px) saturate(140%);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    border: 1px solid rgba(186, 230, 253, 0.22);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(34, 211, 238, 0.08) inset;
    color: #e2e8f0;
}

/* Chat scroll surface: transparent so the glass shows through. */
.layout .chat {
    background: transparent;
    color: #e2e8f0;
}
.layout .chat::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.04); }
.layout .chat::-webkit-scrollbar-thumb { background: rgba(186, 230, 253, 0.28); }

/* AI / system bubbles: subtle on dark, with cyan-tinted border. */
.layout .bubble {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(186, 230, 253, 0.18);
    color: #e2e8f0;
}

/* User bubbles: cyan with white text for legibility. */
.layout .msg.user .bubble {
    background: rgba(14, 165, 233, 0.85);
    border-color: rgba(34, 211, 238, 0.6);
    color: #ffffff;
}
.layout .msg.user .bubble * { color: inherit; }

/* Error bubble keeps red, dark-surface friendly. */
.layout .bubble.error {
    background: rgba(239, 68, 68, 0.18);
    border-color: rgba(252, 165, 165, 0.4);
    color: #fecaca;
}

/* Composer: translucent dark band, no harsh white. */
.layout .composer {
    background: rgba(11, 30, 63, 0.45);
    border-top: 1px solid rgba(186, 230, 253, 0.15);
    padding: 0.7rem 0.9rem;
    position: sticky;
    bottom: 0;
    z-index: 35;
    backdrop-filter: blur(8px) saturate(120%);
    -webkit-backdrop-filter: blur(8px) saturate(120%);
}

/* Inputs everywhere in the chat layout stay readable: light field, dark text. */
.layout .composer textarea,
.layout .composer .inp,
.layout .sidebar .card .inp,
.layout .sidebar .card input[type="text"],
.layout .sidebar .card input[type="email"],
.layout .sidebar .card input[type="password"],
.layout .sidebar .card input[type="search"],
.layout .sidebar .card select,
.layout .sidebar .card textarea {
    background: rgba(255, 255, 255, 0.95) !important;
    color: #0f172a !important;
    border: 1px solid rgba(186, 230, 253, 0.30) !important;
}

/* Sidebar cards: dark glass treatment, tighter padding. */
.layout .sidebar .card {
    background: rgba(11, 30, 63, 0.62);
    backdrop-filter: blur(12px) saturate(140%);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    border: 1px solid rgba(186, 230, 253, 0.22);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
    color: #e2e8f0;
    padding: 0.85rem 1rem;
    border-radius: 14px;
}

.layout .sidebar .bgf-ingest-utility-card .ingest-cards--sidebar {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0;
    border: 0;
    background: transparent;
}

.layout .sidebar .bgf-ingest-utility-card .ingest-cards--sidebar .ingest-card {
    width: 100%;
    min-height: 48px;
    justify-content: flex-start;
}

/* Utility tool cards keep light surfaces; force dark readable text/icons. */
.layout .sidebar .bgf-ingest-utility-card .ingest-card,
.layout .sidebar .bgf-ingest-utility-card .ingest-card .ingest-card-label,
.layout .sidebar .bgf-ingest-utility-card .ingest-card .ingest-card-icon,
.layout .sidebar .bgf-ingest-utility-card .ingest-card .ingest-card-status {
    color: #0f172a !important;
}

/* Card text reads light by default. */
.layout .sidebar .card,
.layout .sidebar .card p,
.layout .sidebar .card span,
.layout .sidebar .card div,
.layout .sidebar .card li {
    color: #e2e8f0;
}
.layout .sidebar .card .muted,
.layout .sidebar .card .lbl,
.layout .sidebar .card label,
.layout .sidebar .card small {
    color: #94a3b8;
}
.layout .sidebar .card h2,
.layout .sidebar .card h3,
.layout .sidebar .card h4 {
    color: #BAE6FD;
    margin-top: 0;
}

/* Pills/badges on cards: cyan-tinted glass instead of bright white. */
.layout .sidebar .card .pill,
.layout .sidebar .card .badge {
    background: rgba(186, 230, 253, 0.12);
    border: 1px solid rgba(186, 230, 253, 0.4);
    color: #BAE6FD;
}

/* Conversation / project list items inside cards. */
.layout .sidebar .card .conversation-item,
.layout .sidebar .card .conv-item,
.layout .sidebar .card [class*="conversation"] li {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(186, 230, 253, 0.12);
    color: #e2e8f0;
    border-radius: 8px;
    padding: 0.45rem 0.7rem;
    transition: background 0.15s, border-color 0.15s;
}
.layout .sidebar .card .conversation-item:hover,
.layout .sidebar .card .conv-item:hover {
    background: rgba(14, 165, 233, 0.15);
    border-color: rgba(34, 211, 238, 0.5);
}

/* Brand label inside the menu is redundant — page already has a header. */
.layout .sidebar .brand { display: none; }

/* Inset blocks that had light backgrounds (model description, etc.):
   re-skin to a slightly darker inset so light text reads. */
.layout .sidebar .card .model-narrative,
.layout .sidebar .card .api-keys-table,
.layout .sidebar .card .api-key-raw {
    background: rgba(11, 30, 63, 0.45) !important;
    border-color: rgba(186, 230, 253, 0.2) !important;
    color: #cbd5e1 !important;
}
.layout .sidebar .card .model-narrative-name,
.layout .sidebar .card .api-keys-table th {
    color: #BAE6FD !important;
}
.layout .sidebar .card .model-narrative-line,
.layout .sidebar .card .api-keys-table td {
    color: #cbd5e1 !important;
}

/* Lighten the agent-name pill text + bg for clarity. */
.layout .sidebar .card .current-agent-name {
    background: rgba(14, 165, 233, 0.18) !important;
    border-color: rgba(34, 211, 238, 0.5) !important;
    color: #BAE6FD !important;
}

/* Conversation/project list items: keep dark, but re-tighten so
   active item reads as cyan-highlighted. */
.layout .sidebar .card .conversation-item.active,
.layout .sidebar .card .conv-item.active,
.layout .sidebar .card li.active {
    background: rgba(14, 165, 233, 0.22);
    border-color: rgba(34, 211, 238, 0.6);
    color: #ffffff;
}

/* Project/conversation manager uses light inset blocks: restore dark text contrast. */
.layout .sidebar .card .group-folder {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.layout .sidebar .card .group-folder-header {
    background: #e2e8f0;
    border-bottom-color: #cbd5e1;
}

.layout .sidebar .card .group-folder-name,
.layout .sidebar .card .group-empty,
.layout .sidebar .card .group-section-title,
.layout .sidebar .card .group-action-btn,
.layout .sidebar .card .group-refresh-btn,
.layout .sidebar .card .group-folder .conv-item,
.layout .sidebar .card .group-folder .conv-item * {
    color: #0f172a !important;
}

.layout .sidebar .card .group-folder .conv-item {
    background: #ffffff;
    border-color: #d1d5db;
}

/* ============================================================
   Extended Thinking toggle button
   - Lives in .composer-actions (flex row)
   - margin-left: auto pushes it to the right edge of the row,
     visually separating it from the Upload/Send/Stop cluster
   - Three visual states via [data-mode]:
       normal   = subdued glass
       auto     = cyan-tinted
       extended = purple→cyan gradient with glow
   ============================================================ */
.btn.btn-thinking {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    border-radius: 9px;
    font-weight: 600;
    font-size: 0.88rem;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background 0.2s, border-color 0.15s, box-shadow 0.2s, transform 0.1s, color 0.15s;
    white-space: nowrap;
    user-select: none;
}
.btn.btn-thinking .thinking-icon {
    font-size: 1rem;
    line-height: 1;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

/* State: Quick (normal) — subdued, "off" feeling */
.btn.btn-thinking[data-mode="normal"] {
    background: rgba(255, 255, 255, 0.06);
    color: #cbd5e1;
    border: 1px solid rgba(186, 230, 253, 0.25);
}
.btn.btn-thinking[data-mode="normal"]:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(186, 230, 253, 0.5);
    color: #ffffff;
}

/* State: Auto — cyan tint, "ready" feeling */
.btn.btn-thinking[data-mode="auto"] {
    background: rgba(34, 211, 238, 0.12);
    color: #BAE6FD;
    border: 1px solid rgba(34, 211, 238, 0.5);
}
.btn.btn-thinking[data-mode="auto"]:hover {
    background: rgba(34, 211, 238, 0.2);
    border-color: #22D3EE;
    color: #ffffff;
}

/* State: Extended — gradient with glow, "engaged" feeling */
.btn.btn-thinking[data-mode="extended"] {
    background: linear-gradient(135deg, #6D5DFB 0%, #0EA5E9 50%, #22D3EE 100%);
    color: #ffffff;
    border: 1px solid rgba(34, 211, 238, 0.65);
    box-shadow: 0 0 18px rgba(34, 211, 238, 0.45),
                0 4px 14px rgba(109, 93, 251, 0.3);
}
.btn.btn-thinking[data-mode="extended"]:hover {
    box-shadow: 0 0 28px rgba(34, 211, 238, 0.6),
                0 6px 20px rgba(109, 93, 251, 0.4);
    transform: translateY(-1px);
}

/* Focus ring (keyboard nav) */
.btn.btn-thinking:focus-visible {
    outline: 2px solid #22D3EE;
    outline-offset: 2px;
}

/* ============================================================
   Polish pass — match the homepage palette (purple→cyan gradient,
   white headings with subtle shadow, dark-glass inline code).
   ============================================================ */

/* Primary buttons (Send, Save, Sign in, Create account) get the
   same purple→cyan gradient as the homepage Login button. */
.btn.btn-primary {
    background: linear-gradient(135deg, #6D5DFB 0%, #0EA5E9 48%, #22D3EE 100%) !important;
    color: #ffffff !important;
    border: 1px solid rgba(34, 211, 238, 0.65) !important;
    border-radius: 9px;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(14, 165, 233, 0.28) !important;
    transition: background 0.2s, box-shadow 0.2s, transform 0.1s, border-color 0.15s;
}
.btn.btn-primary:hover {
    background: linear-gradient(135deg, #7C6DFF 0%, #22D3EE 100%) !important;
    border-color: #BAE6FD !important;
    box-shadow: 0 0 24px rgba(34, 211, 238, 0.55), 0 10px 32px rgba(0, 0, 0, 0.25) !important;
    transform: translateY(-1px);
}
.btn.btn-primary:focus-visible {
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.55), 0 8px 24px rgba(14, 165, 233, 0.28) !important;
}

/* Secondary buttons (Stop, Upload) — outlined glass to match the
   homepage Register button. Scoped to .layout so login/register
   pages keep their own .btn styling. */
.layout .btn:not(.btn-primary) {
    background: rgba(7, 22, 47, 0.45) !important;
    color: #EAF6FF !important;
    border: 1px solid rgba(186, 230, 253, 0.45) !important;
    transition: background 0.2s, border-color 0.15s;
}
.layout .btn:not(.btn-primary):hover {
    background: rgba(34, 211, 238, 0.14) !important;
    border-color: #22D3EE !important;
    color: #ffffff !important;
}

/* Markdown content inside chat bubbles — headings, code, lists,
   tables. The AI's responses use these. */
.layout .bubble h1,
.layout .bubble h2,
.layout .bubble h3,
.layout .bubble h4,
.layout .bubble h5,
.layout .bubble h6,
.layout .bubble-content h1,
.layout .bubble-content h2,
.layout .bubble-content h3,
.layout .bubble-content h4,
.layout .bubble-content h5,
.layout .bubble-content h6 {
    color: #ffffff;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    margin-top: 0.8em;
    margin-bottom: 0.4em;
}
.layout .bubble h1, .layout .bubble-content h1 { font-size: 1.4rem; }
.layout .bubble h2, .layout .bubble-content h2 { font-size: 1.2rem; }
.layout .bubble h3, .layout .bubble-content h3 { font-size: 1.05rem; }

/* Inline code: dark glass pill with cyan text. */
.layout .bubble code,
.layout .bubble-content code,
.layout .msg .bubble code {
    background: rgba(7, 22, 47, 0.7) !important;
    color: #BAE6FD !important;
    border: 1px solid rgba(186, 230, 253, 0.25) !important;
    border-radius: 5px;
    padding: 0.1em 0.4em;
    font-size: 0.92em;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

/* Pre/code blocks: deeper dark with cyan-tinted border. */
.layout .bubble pre,
.layout .bubble-content pre {
    background: rgba(2, 11, 31, 0.85) !important;
    border: 1px solid rgba(186, 230, 253, 0.2);
    border-radius: 10px;
    padding: 0.85rem 1rem;
    overflow-x: auto;
    color: #EAF6FF;
}
.layout .bubble pre code,
.layout .bubble-content pre code {
    background: transparent !important;
    border: none !important;
    color: inherit !important;
    padding: 0;
    font-size: 0.9rem;
}

/* Tables in chat: dark glass with cyan-soft headers. */
.layout .bubble table,
.layout .bubble-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.5rem 0;
    background: rgba(7, 22, 47, 0.4);
    border-radius: 8px;
    overflow: hidden;
}
.layout .bubble th,
.layout .bubble-content th {
    background: rgba(34, 211, 238, 0.12);
    color: #BAE6FD;
    font-weight: 700;
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid rgba(186, 230, 253, 0.25);
}
.layout .bubble td,
.layout .bubble-content td {
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid rgba(186, 230, 253, 0.1);
    color: #e2e8f0;
}
.layout .bubble tr:last-child td,
.layout .bubble-content tr:last-child td {
    border-bottom: none;
}

/* Lists in chat */
.layout .bubble ul,
.layout .bubble ol,
.layout .bubble-content ul,
.layout .bubble-content ol {
    margin: 0.4rem 0 0.4rem 1.25rem;
    padding: 0;
}
.layout .bubble li,
.layout .bubble-content li {
    margin-bottom: 0.25rem;
    color: #e2e8f0;
}
.layout .bubble li::marker,
.layout .bubble-content li::marker {
    color: #22D3EE;
}

/* Bold inside bubbles — slightly brighter so it pops on dark. */
.layout .bubble strong,
.layout .bubble-content strong {
    color: #ffffff;
    font-weight: 700;
}

/* Blockquote */
.layout .bubble blockquote,
.layout .bubble-content blockquote {
    border-left: 3px solid #22D3EE;
    padding: 0.3rem 0.85rem;
    margin: 0.5rem 0;
    color: #cbd5e1;
    background: rgba(34, 211, 238, 0.06);
    border-radius: 0 8px 8px 0;
}

/* Links inside chat content */
.layout .bubble a,
.layout .bubble-content a {
    color: #22D3EE;
    text-decoration: underline;
    text-decoration-color: rgba(34, 211, 238, 0.4);
    text-underline-offset: 2px;
}
.layout .bubble a:hover,
.layout .bubble-content a:hover {
    color: #BAE6FD;
    text-decoration-color: #BAE6FD;
}

/* ============================================================
   Image renderer selector
   ============================================================ */
.bgf-image-renderer-wrap {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    flex: 0 1 auto;
    min-width: 0;
}

.bgf-image-renderer-label {
    font-size: .78rem;
    font-weight: 600;
    color: var(--bgf-muted, #64748b);
    white-space: nowrap;
}

.bgf-image-renderer-select {
    min-width: 150px;
    max-width: 190px;
    cursor: pointer;
}

.layout .composer .bgf-image-renderer-wrap {
    color: #e2e8f0;
}

.layout .composer .bgf-image-renderer-label {
    color: rgba(226, 232, 240, 0.82);
}

@media (max-width: 640px) {
    .bgf-image-renderer-wrap {
        width: 100%;
        justify-content: space-between;
    }

    .bgf-image-renderer-select {
        flex: 1 1 auto;
        max-width: none;
    }
}

/* ============================================================
   Phase 2: Left Utility Window Layout
   - Left column holds utility/configuration controls
   - Right column stays focused on chat + generation
   ============================================================ */
.layout {
    display: grid;
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
    max-width: 1680px;
    margin: 0 auto;
    padding: 1rem;
}

.layout .sidebar {
    order: initial;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow: auto;
    padding-right: .15rem;
}

.layout .main {
    order: initial;
    min-width: 0;
}

.layout .sidebar .card {
    margin-bottom: .65rem;
}

.layout .sidebar .card:last-child {
    margin-bottom: 0;
}

@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
        gap: .6rem;
    }

    .layout .sidebar {
        position: static;
        max-height: none;
        overflow: visible;
        padding-right: 0;
    }
}

/* ============================================================
   Phase 3: Left Panel Controls + Drawer Behavior
   ============================================================ */
.layout {
    position: relative;
    padding-top: 3.2rem;
}

.bgf-leftpanel-toggle {
    position: absolute;
    left: .35rem;
    top: .5rem;
    z-index: 45;
    border-radius: 10px;
    font-weight: 600;
}

.bgf-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .6rem;
}

.bgf-sidebar-head-title {
    color: #cbd5e1;
    letter-spacing: .01em;
}

.bgf-leftpanel-close {
    display: none;
}

.bgf-left-section-title {
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #7dd3fc;
    margin: .2rem 0 .25rem;
    padding-left: .1rem;
}

.bgf-sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, .5);
    z-index: 70;
}

/* Desktop collapse: hide utility panel, keep focused workspace */
@media (min-width: 901px) {
    .bgf-sidebar-head {
        display: none;
        margin-bottom: 0;
    }

    .layout.bgf-sidebar-collapsed {
        grid-template-columns: 0 minmax(0, 1fr);
    }

    .layout.bgf-sidebar-collapsed .sidebar {
        opacity: 0;
        pointer-events: none;
        max-height: 0;
        overflow: hidden;
        padding: 0;
    }
}

/* Mobile drawer mode */
@media (max-width: 900px) {
    .bgf-sidebar-head {
        display: flex;
    }

    .bgf-leftpanel-toggle {
        position: fixed;
        left: .75rem;
        top: .75rem;
        z-index: 85;
    }

    .layout .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(88vw, 360px);
        max-height: none;
        overflow: auto;
        z-index: 90;
        padding: 3.2rem .9rem .9rem;
        transform: translateX(-104%);
        transition: transform .2s ease;
        background: rgba(11, 30, 63, .96);
        border-right: 1px solid rgba(186, 230, 253, .24);
        box-shadow: 0 14px 40px rgba(0, 0, 0, .32);
    }

    .layout.bgf-sidebar-open .sidebar {
        transform: translateX(0);
    }

    .layout.bgf-sidebar-open .bgf-sidebar-backdrop {
        display: block !important;
    }

    .bgf-leftpanel-close {
        display: inline-flex;
    }
}

/* ============================================================
   Ingest modals readability fix
   - Keep light modal surface, force strong dark text contrast
   - Scoped to .bgf-modal so sidebar/chat theme is unchanged
   ============================================================ */
.bgf-modal .ingest-subpanel,
.bgf-modal .ingest-subpanel * {
    color: #0f172a;
}

.bgf-modal .bgf-modal-help,
.bgf-modal .bgf-modal-subtitle,
.bgf-modal .ingest-subpanel-help,
.bgf-modal .ingest-modal-footnote,
.bgf-modal .ingest-progress-text,
.bgf-modal .ingest-progress-log {
    color: #64748b;
}

.bgf-modal .ingest-subpanel-heading,
.bgf-modal .ingest-field-label,
.bgf-modal .ingest-progress-stage,
.bgf-modal .ingest-progress-detail {
    color: #0f172a;
}

.bgf-modal .ingest-field input[type="text"],
.bgf-modal .ingest-field input[type="date"] {
    background: #ffffff;
    color: #0f172a;
    border-color: #b7c5d8;
}

.bgf-modal .ingest-field input::placeholder {
    color: #6b7280;
    opacity: 1;
}

.bgf-modal .ingest-field-checkbox input[type="checkbox"] + .ingest-field-label {
    color: #0f172a;
}

.bgf-modal .ingest-progress-log li {
    color: #334155;
}

.bgf-modal .ingest-subpanel-actions .btn.btn-secondary {
    background: #f1f5f9 !important;
    color: #0f172a !important;
    border-color: #c7d2e0 !important;
}

.bgf-modal .ingest-subpanel-actions .btn.btn-secondary[disabled] {
    color: #94a3b8 !important;
}
