/* Cadence — dracula (default) + light theme */
:root, :root[data-theme="dark"] {
    --bg:           #282a36;
    --bg-alt:       #21222c;
    --panel:        #2f3142;
    --border:       #44475a;
    --fg:           #f8f8f2;
    --dim:          #6272a4;
    --accent:       #bd93f9;
    --primary:      #50fa7b;
    --warn:         #f1fa8c;
    --danger:       #ff5555;
    --info:         #8be9fd;
    --pink:         #ff79c6;

    /* SQL tokens */
    --sql-keyword:  #ff79c6;
    --sql-string:   #f1fa8c;
    --sql-param:    #bd93f9;
    --sql-num:      #bd93f9;
    --sql-cast:     #8be9fd;
    --sql-comment:  #6272a4;

    /* Spacing / radius / shadow / type tokens — single source of truth.
       Use these instead of magic numbers when adding new components. */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --radius-sm: 3px;
    --radius-md: 6px;
    --radius-lg: 10px;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.18);
    --shadow-2: 0 6px 18px rgba(0, 0, 0, 0.24);
    --font-xs: 11px;
    --font-sm: 13px;
    --font-md: 15px;
    --font-lg: 18px;
    --font-xl: 24px;

    color-scheme: dark;
}

:root[data-theme="light"] {
    --bg:           #f6f7f9;
    --bg-alt:       #ffffff;
    --panel:        #ffffff;
    --border:       #d8dde4;
    --fg:           #1f2328;
    --dim:          #6e7781;
    --accent:       #6f42c1;
    --primary:      #1f883d;
    --warn:         #b08800;
    --danger:       #cf222e;
    --info:         #0969da;
    --pink:         #bf3989;

    --sql-keyword:  #cf222e;
    --sql-string:   #0a3069;
    --sql-param:    #6f42c1;
    --sql-num:      #0550ae;
    --sql-cast:     #0969da;
    --sql-comment:  #6e7781;

    color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
    font-size: 14px;
    min-height: 100vh;
    /* Prevent the page itself from ever scrolling horizontally — pane
       contents have ``min-width: 0`` and shrink/ellipsize, so a horizontal
       scrollbar here only ever means a layout bug pushed past the viewport.
       Use ``clip`` (vs. hidden) so descendants can still position:sticky. */
    overflow-x: clip;
}

header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 14px 24px;
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border);
}
header h1 {
    margin: 0;
    color: var(--accent);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
header .brand-link {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}
header .brand-logo {
    height: 32px;
    width: auto;
    display: block;
}
header .tag {
    color: var(--dim);
    font-size: 13px;
}
header .spacer { flex: 1; }
.health {
    color: var(--primary);
    font-size: 18px;
    transition: color 0.3s;
}
.health.down { color: var(--danger); }

main {
    display: grid;
    /* minmax(0, …) on the flexible tracks so 1fr can shrink below the
       intrinsic min-width of its content (chart legend, comparison table,
       etc.). Column widths are CSS variables so the drag-resizer + collapse
       toggles can adjust them at runtime; persisted to localStorage. */
    --col-form: 440px;
    --col-history: 420px;
    /* minmax on the side rails lets them shrink if the viewport (or a
       persisted drag-resize width) would otherwise push the page past
       its track. The 1fr center can collapse to 0 because of minmax(0,1fr),
       but the side rails are fixed-width unless we wrap them in minmax too. */
    grid-template-columns:
        minmax(0, var(--col-form)) 4px
        minmax(280px, 1fr) 4px
        minmax(0, var(--col-history));
    gap: 14px;
    padding: 18px 24px;
    align-items: start;
}
/* Collapsed-state modifiers on <main> set the affected track to a thin strip. */
/* !important so the collapsed width wins against the inline --col-form
   that the pane resizer writes to <main> via JS. Without it, after the
   user drags either pane to a non-default width, the collapse class
   would be overridden by the inline style. */
main.form-collapsed     { --col-form:    32px !important; }
main.history-collapsed  { --col-history: 32px !important; }

.pane {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 18px 20px;
    /* Grid items default to ``min-width: auto`` (= min-content), which
       lets wide children push the column past its 1fr share and the
       page past the viewport. Force the items to honor their grid
       track and let inner content overflow/shrink instead. */
    min-width: 0;
}
.pane h2 {
    margin: 0 0 14px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--dim);
}

/* Form */
form { display: flex; flex-direction: column; gap: 12px; }
/* The HTML ``hidden`` attribute should always win over any ``display: …``
   rule we set on labels / fieldsets — without this, ``<label hidden>``
   stays visible because our ``label { display: flex }`` overrides the
   default UA ``[hidden] { display: none }``. */
[hidden] { display: none !important; }
label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--dim);
}
input, select {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--fg);
    padding: 7px 10px;
    font-size: 13px;
    font-family: inherit;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(189, 147, 249, 0.25);
}
fieldset.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    border: none;
    margin: 0;
    padding: 0;
}
.switches {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 4px;
}
.switch {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--fg);
    cursor: pointer;
}
.switch input { accent-color: var(--accent); }

.actions {
    display: flex;
    gap: var(--space-2);
    /* Pin the Start / Stop bar to the bottom of the viewport so the user
       never has to scroll to reach it after expanding the configure-run
       sections. The pane scrolls with the page; ``position: sticky``
       relative to the viewport works because the form pane is taller
       than the viewport. */
    position: sticky;
    bottom: 0;
    background: var(--panel);
    padding: var(--space-3) 0 var(--space-2);
    margin-top: var(--space-3);
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 12px -8px rgba(0, 0, 0, 0.25);
    z-index: 5;
}
button {
    padding: 9px 16px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-alt);
    color: var(--fg);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
button:hover:not(:disabled) { transform: translateY(-1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary {
    background: var(--primary);
    color: var(--bg);
    border-color: var(--primary);
}
button.danger {
    background: var(--danger);
    color: var(--fg);
    border-color: var(--danger);
}

.error {
    color: var(--danger);
    margin: 12px 0 0;
    font-size: 12px;
    background: rgba(255, 85, 85, 0.1);
    border-left: 3px solid var(--danger);
    padding: 8px 12px;
    border-radius: 2px;
}
.reuse-warning {
    color: var(--bg);
    margin: 8px 0 0;
    font-size: 11px;
    background: var(--warn);
    padding: 6px 10px;
    border-radius: 3px;
    line-height: 1.5;
}

/* Dashboard */
#status-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}
.pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 700;
}
.pill.idle { background: var(--border); color: var(--dim); }
.pill.running { background: var(--warn); color: var(--bg); }
.pill.complete { background: var(--primary); color: var(--bg); }
.pill.early { background: var(--pink); color: var(--bg); }
.pill.error { background: var(--danger); color: var(--fg); }
.dim { color: var(--dim); font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 14px;
}
.kpi {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.kpi-label { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; }
.kpi-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi.success .kpi-value { color: var(--primary); }
.kpi.danger .kpi-value { color: var(--danger); }

.chart-wrap {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 14px;
}
.chart-legend {
    display: flex;
    gap: 18px;
    font-size: 12px;
    color: var(--dim);
    margin-bottom: 6px;
}
.swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 4px;
    vertical-align: middle;
    border-radius: 2px;
}
.swatch.achieved { background: var(--primary); }
.swatch.p95 { background: var(--info); }
canvas { width: 100%; height: 280px; display: block; }

/* Drill-down grid table view */
.chart-table {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0;
    margin-top: 0;
}
.chart-table-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
}
.chart-table-head .spacer { flex: 1; }
.chart-table-wrap {
    max-height: 320px;
    overflow-y: auto;
    overflow-x: auto;
}
#chart-table-grid {
    width: 100%;
    border-collapse: collapse;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11px;
}
#chart-table-grid th,
#chart-table-grid td {
    padding: 5px 10px;
    border-bottom: 1px solid var(--border);
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
#chart-table-grid th:first-child,
#chart-table-grid td:first-child {
    text-align: left;
    color: var(--dim);
}
#chart-table-grid thead th {
    position: sticky;
    top: 0;
    background: var(--bg);
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 10px;
    font-weight: 700;
    z-index: 1;
}
#chart-table-grid tbody tr:hover { background: rgba(189, 147, 249, 0.05); }
:root[data-theme="light"] #chart-table-grid tbody tr:hover { background: rgba(111, 66, 193, 0.04); }
#chart-table-grid tbody tr:last-child td { border-bottom: none; }

.report {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 12px;
}
.report summary {
    cursor: pointer;
    color: var(--accent);
    font-weight: 600;
    user-select: none;
}
.report pre {
    margin: 10px 0 0;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 12px;
    color: var(--fg);
    overflow-x: auto;
    line-height: 1.5;
}

footer {
    padding: 12px 24px;
    color: var(--dim);
    font-size: 12px;
    border-top: 1px solid var(--border);
}
footer a { color: var(--info); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ============================================================
   Responsive layout — mobile / small-screen friendly
   ============================================================ */

/* Tablet: collapse history under the main content */
@media (max-width: 1280px) {
    main {
        grid-template-columns: minmax(0, var(--col-form)) 4px minmax(0, 1fr);
    }
    #resizer-dash-history { display: none; }
    #history-pane { grid-column: 1 / -1; }
    #history-pane > .pane-collapse,
    #history-pane > .pane-collapsed-label { display: none; }
}

/* Narrow tablets / large phones: single-column stack */
@media (max-width: 920px) {
    main {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 12px 14px;
    }
    /* No multi-column resize/collapse at phone width — hide controls. */
    .pane-resizer, .pane-collapse, .pane-collapsed-label { display: none !important; }
    .kpi-grid { grid-template-columns: repeat(3, 1fr); }
    .kpi-value { font-size: 18px; }
    .kpi-label { font-size: 10px; }

    /* Chart legend wraps */
    #chart-legend { width: 100%; margin-left: 0; margin-top: 4px; }

    /* Tile grid still works at 2 columns minimum */
    .example-tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

    /* Live runs cards shrink */
    #live-runs-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

    /* Header buttons wrap */
    header { flex-wrap: wrap; padding: 10px 14px; gap: 8px; }
    header h1 { font-size: 18px; }
    header .tag { display: none; }   /* "SQL load tester · Web UI" — hide for room */
    .hotkey { display: none; }       /* hide ⌘↵ start · esc stop hint */
    #live-runs-bar { padding: 0 14px; }
}

/* Phones */
@media (max-width: 640px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .kpi-value { font-size: 16px; }

    /* Form layout shrinks: 2-up grid becomes single column */
    fieldset.grid-2 { grid-template-columns: 1fr; }

    /* Section headers wrap properly so the meta text doesn't overflow */
    .section-summary { flex-wrap: wrap; }
    .section-meta {
        flex-basis: 100%;
        text-align: left;
        padding-left: 22px;
        white-space: normal;
    }
    .section-actions { margin-left: auto; }

    /* Stats panel modal cards stack */
    .modal-grid { grid-template-columns: 1fr; }

    /* Chart canvas a little shorter so KPI grid + chart still fit on one screen */
    canvas { height: 220px; }

    /* Text inputs grow comfortably */
    input, select, textarea, button { font-size: 14px; }

    /* Modals fill most of the screen */
    dialog.modal { width: 96vw; max-height: 92vh; padding: 0; }
    .modal-head { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
    .modal-head h3 { font-size: 14px; }
    .modal-body { padding: 12px 14px; }

    /* Library / settings sidebars become full-width row above the editor */
    .library-body, .docs-body {
        grid-template-columns: 1fr;
        height: auto;
        max-height: none;
    }
    .library-list, .docs-nav {
        max-height: 180px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    /* Drill-down toggle bar wraps comfortably */
    .metric-toggles { flex-wrap: wrap; row-gap: 4px; }

    /* Header buttons are smaller on phones */
    .theme-btn { padding: 4px 7px; font-size: 12px; }
    #docs-btn, #settings-btn, #library-btn { padding: 4px 7px; font-size: 12px; }

    /* Tray cards a little tighter */
    .run-card { padding: 8px 10px; gap: 4px; }
    .compact-kpis { font-size: 10px; }
    .card-query { font-size: 10px; }
}

/* Touch-target boost: anything inside header / cards / modals interactive
   gets ≥36px when on a coarse pointer. */
@media (pointer: coarse) {
    button, .link-btn, select, .multi-option, .example-tile, .run-card {
        min-height: 36px;
    }
    .row-delete, .stop-mini, .card-detail, .close-btn {
        min-width: 28px; min-height: 28px;
    }
}

/* ============================================================
   Collapsible sections (1 · Choose queries / 2 · Run settings / 3 · Advanced)
   ============================================================ */
details.section {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 12px;
    overflow: hidden;
}
details.section[open] {
    border-color: var(--accent);
}
:root[data-theme="light"] details.section[open] {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(111, 66, 193, 0.08);
}
details.section > summary.section-summary {
    list-style: none;
    cursor: pointer;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    user-select: none;
    transition: background 0.15s;
}
details.section > summary.section-summary::-webkit-details-marker { display: none; }
details.section > summary.section-summary:hover {
    background: rgba(189, 147, 249, 0.05);
}
:root[data-theme="light"] details.section > summary.section-summary:hover {
    background: rgba(111, 66, 193, 0.04);
}
.section-chev {
    color: var(--accent);
    font-size: 11px;
    width: 12px;
    flex-shrink: 0;
    transition: transform 0.18s;
}
details.section[open] > summary .section-chev { transform: rotate(0deg); }
details.section:not([open]) > summary .section-chev { transform: rotate(-90deg); }

.section-title {
    color: var(--fg);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    flex-shrink: 0;
}
.section-meta {
    flex: 1;
    font-size: 11px;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-left: 12px;
}
.section-actions { display: flex; gap: 6px; flex-shrink: 0; }
.section-actions .link-btn { font-size: 10px; padding: 2px 6px; }
.section-body {
    padding: 8px 14px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ============================================================
   Tile grid for sample picking
   ============================================================ */
.example-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
}
.example-tile {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 10px 12px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
/* Compact mode: single-line head, no tile-meta description, smaller padding.
   The full details (description, SQL, values, run history) live in the
   Library modal — opened via the per-tile ⓘ button. */
.example-tile.compact {
    padding: 6px 8px;
    gap: 4px;
}
.example-tile.compact .tile-meta { display: none; }
.example-tile.compact .tile-head { flex-wrap: nowrap; }
.example-tile.compact .tile-name {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.tile-info {
    background: transparent;
    border: none;
    color: var(--dim);
    cursor: pointer;
    padding: 0 4px;
    font-size: 13px;
    line-height: 1;
    flex-shrink: 0;
    opacity: 0.55;
    transition: opacity 0.15s, color 0.15s;
}
.tile-info:hover { opacity: 1; color: var(--accent); }
.example-tile:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}
.example-tile.selected {
    border-color: var(--accent);
    background: rgba(189, 147, 249, 0.08);
    box-shadow: inset 3px 0 0 var(--accent);
}
:root[data-theme="light"] .example-tile.selected {
    background: rgba(111, 66, 193, 0.06);
}
.tile-head {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.tile-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1.5px solid var(--border);
    color: transparent;
    font-size: 10px;
    flex-shrink: 0;
    transition: all 0.15s;
}
.example-tile.selected .tile-check {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
}
.tile-name {
    font-weight: 600;
    color: var(--fg);
    font-size: 12px;
    flex: 1;
}
.tile-pill {
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    flex-shrink: 0;
}
.tile-pill.easy   { background: var(--info);    color: var(--bg); }
.tile-pill.medium { background: var(--warn);    color: var(--bg); }
/* Dialect filter banner — sits above the tile grid. Two flavors: a steady
   ``dim`` context line, and a transient ``warn`` flash when the connection
   change deselected incompatible queries. */
.tile-filter-banner {
    padding: 6px 2px;
    font-size: 11px;
    line-height: 1.35;
}
.tile-filter-banner.dim { color: var(--dim); }
.tile-filter-banner.warn {
    color: var(--bg);
    background: var(--warn);
    border: 1px solid var(--warn);
    border-radius: 4px;
    padding: 6px 10px;
    font-weight: 600;
    margin-bottom: 6px;
}

/* Dialect badge — one notch smaller than difficulty so the pair reads as
   "EASY · postgres" without crowding. Color hints which engine it speaks. */
.tile-dialect {
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 999px;
    text-transform: lowercase;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    letter-spacing: 0.2px;
    font-weight: 600;
    flex-shrink: 0;
    border: 1px solid var(--border);
    color: var(--dim);
}
.tile-dialect.dialect-postgres  { color: #336791; border-color: #336791; }
.tile-dialect.dialect-cockroach { color: #6933ff; border-color: #6933ff; }
.tile-dialect.dialect-oracle    { color: #c74634; border-color: #c74634; }
.tile-dialect.dialect-ansi      { color: var(--dim); }
.tile-pill.hard   { background: var(--pink);    color: var(--bg); }
.tile-meta {
    color: var(--dim);
    font-size: 11px;
    line-height: 1.4;
}
.tile-tps {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed var(--border);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
}
.tile-tps-label {
    color: var(--dim);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.tile-tps input {
    flex: 1;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--accent);
    border-radius: 3px;
    padding: 3px 6px;
    font-family: ui-monospace, monospace;
    font-size: 11px;
    text-align: left;
    -moz-appearance: textfield;
}
.tile-tps input:focus { outline: none; border-color: var(--accent); }
.tile-tps-badge {
    color: var(--accent);
    font-size: 10px;
    font-weight: 700;
}

/* Hide the legacy chips area — tiles are the source of truth now. */
.multi-chips, .examples-row, #examples-block { display: none !important; }

/* Examples picker (legacy — keeping as-is for any pages still referencing it) */
#examples-block-legacy {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 10px 12px;
    margin-bottom: 14px;
}
.examples-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.examples-label {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    margin-bottom: 0;
    width: auto;
    flex: 0 0 auto;
}

/* ---- Custom multi-select dropdown ------------------------ */
.multi-select { position: relative; flex: 1; }
.multi-trigger {
    width: 100%;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--fg);
    border-radius: 4px;
    padding: 7px 10px;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: inherit;
    font-size: 13px;
}
.multi-trigger:hover { border-color: var(--accent); }
.multi-trigger .caret { color: var(--dim); margin-left: 8px; }
.multi-trigger.has-selection #multi-trigger-label { color: var(--accent); font-weight: 600; }

.multi-popover {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    z-index: 50;
    max-height: 320px;
    overflow-y: auto;
}
:root[data-theme="light"] .multi-popover { box-shadow: 0 6px 20px rgba(0,0,0,0.12); }

.multi-actions {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
.link-btn {
    background: transparent;
    border: none;
    color: var(--accent);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 6px;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.link-btn:hover { text-decoration: underline; }

.multi-option {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12px;
    color: var(--fg);
    border-left: 2px solid transparent;
    flex-direction: row;
}
.multi-option:hover {
    background: var(--bg-alt);
    border-left-color: var(--accent);
}
.multi-option input[type="checkbox"] {
    margin: 2px 0 0;
    accent-color: var(--accent);
    flex: 0 0 auto;
}
.multi-option .opt-body { flex: 1; min-width: 0; }
.multi-option .opt-name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.multi-option .opt-desc {
    color: var(--dim);
    font-size: 11px;
    margin-top: 2px;
    line-height: 1.45;
}

.multi-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}
.multi-chips .selected-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(189, 147, 249, 0.15);
    border: 1px solid var(--accent);
    color: var(--accent);
    border-radius: 999px;
    padding: 2px 4px 2px 10px;
    font-size: 11px;
    font-family: ui-monospace, monospace;
    cursor: pointer;
}
:root[data-theme="light"] .multi-chips .selected-chip { background: rgba(111, 66, 193, 0.08); }
.multi-chips .selected-chip .x {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    margin-left: 2px;
}
.multi-chips .selected-chip:hover { filter: brightness(1.15); }
.multi-chips .selected-chip .chip-name {
    cursor: pointer;
}
.multi-chips .selected-chip .chip-tps {
    width: 80px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--accent);
    border-radius: 3px;
    padding: 1px 6px;
    margin: 0 2px;
    font-family: ui-monospace, monospace;
    font-size: 11px;
    text-align: left;
    -moz-appearance: textfield;
}
.multi-chips .selected-chip.sweep .chip-tps {
    width: 130px;
    border-color: var(--accent);
}
.multi-chips .selected-chip.sweep .chip-tps-label {
    color: var(--accent);
    font-weight: 700;
}
.multi-chips .selected-chip .chip-tps::-webkit-outer-spin-button,
.multi-chips .selected-chip .chip-tps::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.multi-chips .selected-chip .chip-tps:focus {
    outline: none;
    border-color: var(--accent);
}
.multi-chips .selected-chip .chip-tps-label {
    font-size: 9px;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 4px;
}

/* Chart legend: per-run entries (one row per active run) */
#chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-left: auto;
    align-items: center;
}
#chart-legend .legend-run {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--dim);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 3px;
    transition: background 0.15s;
}
#chart-legend .legend-run:hover { background: var(--bg-alt); }
#chart-legend .legend-run.focused {
    background: var(--bg-alt);
    color: var(--fg);
    font-weight: 600;
}
#chart-legend .legend-run.legend-done { opacity: 0.7; }
#chart-legend .legend-run.legend-done .legend-swatch { opacity: 0.7; }
#chart-legend .legend-run.legend-historical {
    border: 1px dashed var(--accent);
    padding: 1px 6px;
}
#chart-legend .link-btn { margin-left: 6px; }
#chart-legend .legend-run .legend-swatch {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 2px;
    flex-shrink: 0;
}
#chart-legend .legend-empty {
    color: var(--dim);
    font-size: 11px;
    font-style: italic;
}

/* Run-card border color is overridable per run */
.run-card {
    border-left: 3px solid var(--run-color, var(--border));
}
.example-meta {
    font-size: 12px;
    margin-top: 8px;
    line-height: 1.5;
}
.example-meta .pill {
    margin-right: 6px;
    font-size: 10px;
    padding: 2px 8px;
}
.example-preview {
    margin-top: 8px;
    border-top: 1px dashed var(--border);
    padding-top: 8px;
}
.example-preview summary {
    cursor: pointer;
    color: var(--accent);
    font-size: 12px;
    user-select: none;
}
.example-preview h4 {
    color: var(--dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 10px 0 4px;
}
.example-preview pre {
    margin: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 8px 10px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11px;
    line-height: 1.5;
    color: var(--fg);
    overflow-x: auto;
    max-height: 200px;
}

.pill.easy { background: var(--info); color: var(--bg); }
.pill.medium { background: var(--warn); color: var(--bg); }
.pill.hard { background: var(--pink); color: var(--bg); }

/* Drill-down metric toggles (visible when on TPS/time tab) */
.metric-toggles {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 8px;
    padding: 6px 10px;
    background: var(--bg-alt);
    border: 1px dashed var(--border);
    border-radius: 4px;
    font-size: 11px;
}
.metric-toggles-label {
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    margin-right: 6px;
}
.metric-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--fg);
    cursor: pointer;
    user-select: none;
    flex-direction: row;
    margin: 0;
}
.metric-toggle input[type="checkbox"] {
    accent-color: var(--accent);
    margin: 0;
}
.metric-toggle:has(input:not(:checked)) {
    color: var(--dim);
    text-decoration: line-through;
    opacity: 0.6;
}

/* Tabs */
.chart-tabs {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.tab {
    padding: 4px 10px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--dim);
    border-radius: 3px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    font-weight: 600;
}
.tab.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}
.chart-tabs .chart-legend { margin-left: auto; }
.swatch.hist { background: var(--accent); }

/* History */
#history-pane.history { padding: 18px 16px; }
#history-pane h2 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
#history-clear { font-size: 10px; }
/* Pass/fail verdict banner — sits above the KPI grid on the dashboard.
   Hidden by default; the JS shows it only on completion when at least
   one threshold was set on the run. */
.verdict-banner {
    display: flex; align-items: center; gap: 14px;
    padding: 10px 14px; margin: 0 0 10px;
    border-radius: 6px; border: 1px solid;
    font-size: 13px;
}
.verdict-banner.pass { background: color-mix(in srgb, var(--primary) 10%, var(--panel)); border-color: var(--primary); }
.verdict-banner.fail { background: color-mix(in srgb, var(--danger)  10%, var(--panel)); border-color: var(--danger); }
.verdict-badge {
    font-weight: 800; letter-spacing: 0.6px;
    padding: 2px 10px; border-radius: 4px;
}
.verdict-banner.pass .verdict-badge { color: var(--bg); background: var(--primary); }
.verdict-banner.fail .verdict-badge { color: var(--bg); background: var(--danger); }
.verdict-criteria { color: var(--dim); font-size: 12px; flex: 1; }
.verdict-reasons {
    margin: -6px 0 10px 8px; padding: 0 0 0 14px;
    color: var(--danger); font-size: 12px;
}
.verdict-reasons li { margin-top: 2px; }

/* Inline baseline-comparison strip — same band as the verdict banner. */
.baseline-compare {
    padding: 8px 12px; margin: 0 0 10px;
    border-radius: 6px; border: 1px dashed var(--border);
    background: var(--panel);
    font-size: 12px;
}
.baseline-compare .bcmp-head { color: var(--dim); margin-bottom: 6px; }
.baseline-compare .bcmp-row { display: flex; flex-wrap: wrap; gap: 14px; }
.bcmp-item {
    display: inline-flex; align-items: baseline; gap: 6px;
    padding: 2px 8px; border-radius: 999px;
    background: var(--bg-alt); border: 1px solid var(--border);
}
.bcmp-metric { color: var(--dim); text-transform: uppercase; font-size: 10px; letter-spacing: 1px; }
.bcmp-delta  { font-family: ui-monospace, monospace; font-weight: 700; }
.bcmp-item.lat.up   .bcmp-delta { color: var(--danger); }   /* latency up = worse */
.bcmp-item.lat.down .bcmp-delta { color: var(--primary); }  /* latency down = better */
.bcmp-item.tps.up   .bcmp-delta { color: var(--primary); }  /* tps up = better */
.bcmp-item.tps.down .bcmp-delta { color: var(--danger); }   /* tps down = worse */
.bcmp-item.flat .bcmp-delta { color: var(--dim); }

/* History row pass/fail badge — replaces the simple ✓ status icon. */
.result-cell {
    display: inline-block;
    font-weight: 700;
    font-size: 10.5px;
    letter-spacing: 0.5px;
    padding: 1px 6px;
    border-radius: 3px;
    white-space: nowrap;
}
.result-cell.pass { color: var(--bg); background: var(--primary); }
.result-cell.fail { color: var(--bg); background: var(--danger); }

/* Optional pass-criteria fieldset — sits inside Section 2 of the form.
   Slim border so it visually groups without dominating. */
fieldset.pass-criteria {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 12px 8px;
    margin: 4px 0 0;
}
fieldset.pass-criteria legend {
    color: var(--dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 0 6px;
}

/* Children of the pane all need ``min-width: 0`` so they honor the pane's
   own min-width:0 — without it, intrinsic min-content of a wide cell or
   long unbreakable token would push the pane track past the viewport. */
#history-pane > * { min-width: 0; }
#history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    /* Fixed layout so the table honors its container width and truncates
       wide cells (RUN id, batch-meta) instead of forcing the table — and
       the surrounding pane — to grow with content. */
    table-layout: fixed;
}
#history-table th, #history-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* Column sizing: Run takes all remaining width; Status + delete are
   narrow so the green check sits flush right against the delete cell
   instead of floating in dead space. */
#history-table th:nth-child(1), #history-table td:nth-child(1) { width: auto; }
#history-table th:nth-child(2), #history-table td:nth-child(2) { width: 28px; text-align: center; }
#history-table th:nth-child(3), #history-table td:nth-child(3) { width: 28px; }
#history-table .row-delete {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--dim);
    width: 22px; height: 22px;
    border-radius: 3px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}
#history-table tr:hover .row-delete { opacity: 1; }
#history-table .row-delete:hover { color: var(--danger); border-color: var(--danger); }
#history-table td.delete-cell {
    text-align: right;
    width: 28px;
    padding-right: 4px;
}
#history-table th, #history-table td {
    text-align: left;
    padding: 7px 6px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
#history-table th {
    color: var(--dim);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 10px;
}
#history-table tr.current td { background: rgba(189, 147, 249, 0.08); }
#history-table tr.batch-row .run-id {
    color: var(--accent);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 10.5px;
}
#history-table tr.batch-row .batch-meta {
    font-size: 10px;
    margin-top: 2px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    text-transform: none;
    letter-spacing: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}
#history-table .run-id {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11px;
    color: var(--accent);
}
.center { text-align: center; padding: 18px 0; }

.hotkey {
    color: var(--dim);
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11px;
}

.theme-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--fg);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 14px;
    cursor: pointer;
    line-height: 1;
}
.theme-btn:hover { background: var(--bg-alt); }

/* Preview drawer enhancements */
.preview-section { margin-top: 12px; }
.preview-section:first-of-type { margin-top: 8px; }
.preview-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}
.preview-header h4 {
    margin: 0;
    flex: 0 0 auto;
}
.preview-header .dim {
    font-size: 11px;
    flex: 1;
}
.copy-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--dim);
    border-radius: 3px;
    padding: 2px 8px;
    font-size: 11px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
.copy-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* SQL preview */
pre.sql {
    margin: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 10px 12px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11.5px;
    line-height: 1.55;
    color: var(--fg);
    overflow-x: auto;
    max-height: 240px;
    white-space: pre;
    tab-size: 4;
}
pre.sql .tk-k    { color: var(--sql-keyword); font-weight: 600; }
pre.sql .tk-s    { color: var(--sql-string); }
pre.sql .tk-p    {
    color: var(--sql-param);
    background: rgba(189, 147, 249, 0.18);
    border-radius: 2px;
    padding: 0 2px;
    font-weight: 600;
}
:root[data-theme="light"] pre.sql .tk-p { background: rgba(111, 66, 193, 0.12); }
pre.sql .tk-n    { color: var(--sql-num); }
pre.sql .tk-cast { color: var(--sql-cast); }
pre.sql .tk-c    { color: var(--sql-comment); font-style: italic; }

/* Parameter chips below the SQL */
.param-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.param-chips .chip {
    background: rgba(189, 147, 249, 0.12);
    border: 1px solid var(--accent);
    color: var(--accent);
    border-radius: 999px;
    padding: 2px 10px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11px;
}
:root[data-theme="light"] .param-chips .chip { background: rgba(111, 66, 193, 0.08); }
.param-chips .chip .dim { font-family: inherit; }

/* Values table */
.values-table-wrap {
    border: 1px solid var(--border);
    border-radius: 3px;
    overflow: auto;
    max-height: 260px;
    background: var(--bg);
}
.values-table {
    width: 100%;
    border-collapse: collapse;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11px;
}
.values-table th, .values-table td {
    text-align: left;
    padding: 5px 8px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.values-table thead th {
    background: var(--bg-alt);
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 10px;
    font-weight: 700;
    position: sticky;
    top: 0;
    z-index: 1;
}
.values-table thead .hdr-mapped {
    color: var(--accent);
    margin-left: 4px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
}
.values-table tbody tr:hover { background: rgba(189, 147, 249, 0.06); }
:root[data-theme="light"] .values-table tbody tr:hover { background: rgba(111, 66, 193, 0.06); }
.values-table tbody tr:last-child td { border-bottom: none; }
.values-table td { color: var(--fg); }

/* Help tooltips */
.help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--border);
    color: var(--dim);
    font-size: 9px;
    font-weight: 700;
    margin-left: 4px;
    cursor: help;
    position: relative;
    vertical-align: middle;
    transition: all 0.15s;
}
.help:hover { background: var(--accent); color: var(--bg); }
.help::after {
    content: attr(data-help);
    position: absolute;
    bottom: 130%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-alt);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 11px;
    font-weight: 400;
    line-height: 1.5;
    width: 240px;
    text-align: left;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 100;
    text-transform: none;
    letter-spacing: 0;
}
.help:hover::after { opacity: 1; }

/* Onboarding */
.onboarding {
    background: linear-gradient(135deg, rgba(189, 147, 249, 0.08), rgba(80, 250, 123, 0.05));
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 14px 18px;
    margin-bottom: 14px;
}
:root[data-theme="light"] .onboarding {
    background: linear-gradient(135deg, rgba(111, 66, 193, 0.06), rgba(31, 136, 61, 0.04));
}
.onboarding strong {
    color: var(--accent);
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
}
.onboarding ol {
    margin: 0 0 8px 18px;
    padding: 0;
    color: var(--fg);
    font-size: 12px;
    line-height: 1.7;
}
.onboarding code, .onboarding kbd {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0 5px;
    font-family: ui-monospace, monospace;
    font-size: 11px;
}

/* Achievement badge */
.badge {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 3px 10px;
    border-radius: 4px;
    font-weight: 700;
}
.badge-ok   { background: var(--primary); color: var(--bg); }
.badge-warn { background: var(--warn); color: var(--bg); }
.badge-bad  { background: var(--danger); color: var(--fg); }
#status-row .spacer { flex: 1; }

/* ============================================================
   Run-detail modal
   ============================================================ */
dialog.modal {
    border: none;
    background: var(--panel);
    color: var(--fg);
    padding: 0;
    border-radius: 10px;
    width: min(960px, 92vw);
    max-height: 88vh;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
dialog.modal::backdrop {
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
}
:root[data-theme="light"] dialog.modal::backdrop {
    background: rgba(0, 0, 0, 0.32);
}
.modal-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 22px;
    border-bottom: 1px solid var(--border);
}
.modal-head h3 {
    margin: 0;
    color: var(--accent);
    font-size: 16px;
}
.modal-head .dim {
    font-size: 12px;
    display: block;
    margin-top: 2px;
}
.modal-head .spacer { flex: 1; }
.close-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--dim);
    width: 28px; height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}
.close-btn:hover { color: var(--danger); border-color: var(--danger); }

.modal-body {
    padding: 18px 22px 24px;
    overflow-y: auto;
    max-height: calc(88vh - 56px);
}
.historical-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, rgba(189, 147, 249, 0.12), rgba(189, 147, 249, 0.04));
    border: 1px dashed var(--accent);
    border-radius: 5px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 12px;
    color: var(--fg);
}
:root[data-theme="light"] .historical-banner {
    background: linear-gradient(135deg, rgba(111, 66, 193, 0.08), rgba(111, 66, 193, 0.02));
}
.historical-banner .hb-icon { font-size: 16px; }
.historical-banner em { color: var(--accent); font-style: normal; font-weight: 600; }

/* Dashboard pane in historical-mode — recolor the title + status pill so
   it's obvious you're not looking at a live stream. */
#dashboard-title { transition: color 120ms; }
#dashboard-subtitle { margin-left: 8px; font-size: 13px; font-weight: 400; }
#dashboard-pane.historical-mode #dashboard-title { color: var(--accent); }
#dashboard-pane.historical-mode {
    /* dashed accent border to mirror the past-run tray treatment */
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent);
}
.pill.historical {
    background: color-mix(in srgb, var(--accent) 22%, transparent);
    color: var(--accent);
    border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}

/* Multi-run comparison table — shown only when ≥2 historical runs are loaded. */
.historical-compare {
    border: 1px dashed color-mix(in srgb, var(--accent) 50%, transparent);
    border-radius: 6px;
    padding: 8px 10px 10px;
    margin: 0 0 12px;
    background: color-mix(in srgb, var(--accent) 5%, transparent);
    /* Scroll horizontally inside the box if the table is wider than the
       pane — never push the pane wider than its grid track. */
    overflow-x: auto;
    max-width: 100%;
}
.historical-compare .hc-head {
    display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px;
}
.historical-compare .hc-title { font-size: 12px; font-weight: 600; color: var(--accent); letter-spacing: 0.04em; text-transform: uppercase; }
.historical-compare .hc-hint  { font-size: 11px; }
.historical-compare table.hc-table {
    width: 100%; border-collapse: collapse; font-size: 12px;
}
.historical-compare .hc-table th,
.historical-compare .hc-table td {
    padding: 5px 8px; text-align: right; white-space: nowrap;
}
.historical-compare .hc-table th:first-child,
.historical-compare .hc-table th:nth-child(2),
.historical-compare .hc-table td:first-child,
.historical-compare .hc-table td:nth-child(2) {
    text-align: left;
}
/* Query column truncates with ellipsis so the table's intrinsic min-width
   stays small — long paths get a tooltip via the title attr. */
.historical-compare .hc-table td:nth-child(2) {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.historical-compare .hc-table th { color: var(--dim); font-weight: 500; border-bottom: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); }
.historical-compare .hc-table tbody tr { cursor: pointer; }
.historical-compare .hc-table tbody tr:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.historical-compare .hc-table tbody tr.focused { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.historical-compare .hc-swatch {
    display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: middle;
}
.historical-compare .hc-actions { white-space: nowrap; text-align: right; }
.historical-compare .hc-actions .link-btn {
    padding: 2px 6px; font-size: 12px; opacity: 0.55;
}
.historical-compare .hc-actions .link-btn:hover { opacity: 1; }
.historical-compare .hc-actions .hc-drop:hover { color: var(--danger, #ff5555); }
.historical-compare .hc-actions a.link-btn,
.historical-compare .hc-actions button.link-btn {
    margin-left: var(--space-1);
}

/* Insights panel — sits where the chart canvas would be when the
   Insights tab is active. Same scrollable area; one card per insight. */
.insights-panel {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    max-height: 360px;
    overflow-y: auto;
}
.insights-panel .insights-head {
    margin-bottom: var(--space-2);
    font-size: var(--font-sm);
}
.insights-panel .insight {
    border-left: 3px solid var(--border);
    background: var(--panel);
    padding: var(--space-2) var(--space-3);
    margin: var(--space-1) 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.insights-panel .insight.issue { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--panel)); }
.insights-panel .insight.warn  { border-left-color: var(--warn);   background: color-mix(in srgb, var(--warn) 8%, var(--panel)); }
.insights-panel .insight.info  { border-left-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--panel)); }
.insights-panel .insight-title { font-weight: 600; font-size: var(--font-sm); color: var(--fg); }
.insights-panel .insight-body  { font-size: var(--font-xs); color: var(--fg); margin-top: 2px; line-height: 1.4; }
.insights-panel .insight-evidence {
    font-size: 10px; color: var(--dim); margin-top: var(--space-1);
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.modal-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 14px;
}
.modal-card {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 14px;
}
.modal-card h4 {
    margin: 0 0 8px;
    color: var(--dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.kv { width: 100%; border-collapse: collapse; font-size: 12px; }
.kv th {
    text-align: left;
    color: var(--dim);
    font-weight: 500;
    padding: 3px 0;
    width: 50%;
}
.kv td {
    text-align: right;
    color: var(--fg);
    font-family: ui-monospace, monospace;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.modal-section { margin: 14px 0; }
.modal-section h4 {
    margin: 0 0 8px;
    color: var(--dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.modal-section summary {
    color: var(--accent);
    cursor: pointer;
    font-weight: 600;
    user-select: none;
    font-size: 12px;
}
#m-histogram {
    display: block;
    width: 100%;
    height: 180px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 6px;
}
#m-fulltext {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 12px;
    font-family: ui-monospace, monospace;
    font-size: 11.5px;
    line-height: 1.55;
    margin: 8px 0 0;
    overflow-x: auto;
    color: var(--fg);
}

/* Diagnostics hints */
.diagnostics {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}
.hint {
    border-left: 3px solid var(--border);
    padding: 8px 12px;
    background: var(--bg-alt);
    border-radius: 0 4px 4px 0;
    font-size: 12px;
    line-height: 1.5;
}
.hint-ok   { border-left-color: var(--primary); }
.hint-warn { border-left-color: var(--warn); background: rgba(241, 250, 140, 0.06); }
.hint-info { border-left-color: var(--info); }
:root[data-theme="light"] .hint-warn { background: rgba(176, 136, 0, 0.06); }

/* Errors table */
.error-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.error-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
}
.error-table tr:last-child td { border-bottom: none; }
.error-table .err-count {
    width: 50px;
    color: var(--danger);
    font-family: ui-monospace, monospace;
    font-weight: 700;
}

/* Download buttons */
.dl-row { display: flex; gap: 8px; flex-wrap: wrap; }
.dl-btn {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 7px 14px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.15s;
}
.dl-btn:hover {
    border-color: var(--accent);
    background: rgba(189, 147, 249, 0.1);
    transform: translateY(-1px);
}
:root[data-theme="light"] .dl-btn:hover { background: rgba(111, 66, 193, 0.06); }

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

/* ============================================================
   Live runs tray (concurrent runs)
   ============================================================ */
#live-runs-bar {
    padding: 0 24px;
}
.live-runs {
    margin-top: 18px;
}
.live-runs.showing-historical {
    border-color: var(--accent);
    border-style: dashed;
    background: linear-gradient(180deg, rgba(189, 147, 249, 0.04), transparent);
}
:root[data-theme="light"] .live-runs.showing-historical {
    background: linear-gradient(180deg, rgba(111, 66, 193, 0.04), transparent);
}
.live-runs.showing-historical h2 { color: var(--accent); }
.live-runs.showing-historical h2 .dim { color: var(--accent); opacity: 0.85; font-weight: 600; }
.live-runs h2 {
    display: flex;
    align-items: center;
    gap: 8px;
}
#live-runs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
}
.run-card {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s, border-color 0.15s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.run-card:hover { border-color: var(--accent); }
.run-card.focused {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(189, 147, 249, 0.25);
}
:root[data-theme="light"] .run-card.focused {
    box-shadow: 0 0 0 2px rgba(111, 66, 193, 0.18);
}
.run-card.dimming { opacity: 0; transform: scale(0.96); }
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.card-head .run-id {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11px;
    color: var(--accent);
    font-weight: 700;
}
.card-pill {
    font-size: 9px;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.card-pill.running  { background: var(--warn); color: var(--bg); }
.card-pill.complete { background: var(--primary); color: var(--bg); }
.card-pill.error    { background: var(--danger); color: var(--fg); }
.card-pill.early    { background: var(--pink); color: var(--bg); }
.card-pill.historical { background: var(--accent); color: var(--bg); }
.run-card.historical {
    background: linear-gradient(135deg, var(--bg-alt) 0%, rgba(189, 147, 249, 0.06) 100%);
    border-style: dashed;
}
:root[data-theme="light"] .run-card.historical {
    background: linear-gradient(135deg, var(--bg-alt) 0%, rgba(111, 66, 193, 0.05) 100%);
}

.card-query {
    font-size: 11px;
    color: var(--dim);
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
table.compact-kpis {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}
table.compact-kpis th, table.compact-kpis td {
    padding: 2px 0;
    text-align: left;
}
table.compact-kpis th {
    color: var(--dim);
    font-weight: 500;
    width: 40%;
}
table.compact-kpis td {
    text-align: right;
    color: var(--fg);
    font-family: ui-monospace, monospace;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}
.run-card .spark {
    display: block;
    width: 100%;
    height: 36px;
    background: var(--bg);
    border-radius: 3px;
}
.card-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}
.stop-mini {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 2px 10px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
}
.stop-mini:hover { background: var(--danger); color: var(--fg); }
.card-detail {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--dim);
    width: 22px; height: 22px;
    border-radius: 3px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    transition: all 0.15s;
}
.card-detail:hover { color: var(--accent); border-color: var(--accent); }

/* ============================================================
   Docs modal
   ============================================================ */
dialog.logs-modal { width: min(1100px, 96vw); max-height: 88vh; }
.logs-modal .modal-body { padding: 0; }
.logs-modal .modal-head { gap: 12px; flex-wrap: wrap; }
.logs-modal .logs-toolbar-row {
    display: inline-flex; align-items: center; gap: 6px;
    color: var(--dim); font-size: 11px;
}
.logs-modal .logs-pause {
    display: inline-flex; align-items: center; gap: 4px;
    color: var(--dim); font-size: 12px; cursor: pointer;
}
.logs-pane {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11.5px;
    line-height: 1.45;
    padding: 12px 14px;
    height: 70vh;
    overflow: auto;
    white-space: pre;
    border-top: 1px solid var(--border);
}

dialog.docs-modal { width: min(1080px, 94vw); max-height: 92vh; }
.docs-modal .modal-body { padding: 0; }
.docs-modal h5 {
    margin: 14px 0 6px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent);
}
pre.ascii-diagram {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 10px 12px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11px;
    line-height: 1.4;
    overflow-x: auto;
    color: var(--fg);
}
.docs-body {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 0;
    height: calc(92vh - 56px);
    max-height: calc(92vh - 56px);
}
.docs-nav {
    background: var(--bg-alt);
    border-right: 1px solid var(--border);
    padding: 18px 0;
    overflow-y: auto;
}
.docs-link {
    display: block;
    padding: 8px 22px;
    color: var(--dim);
    font-size: 12.5px;
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all 0.15s;
}
.docs-link:hover {
    color: var(--accent);
    background: rgba(189, 147, 249, 0.06);
    border-left-color: var(--accent);
}
:root[data-theme="light"] .docs-link:hover { background: rgba(111, 66, 193, 0.05); }
.docs-content {
    overflow-y: auto;
    padding: 18px 28px 24px;
    line-height: 1.65;
}
.docs-content section { padding-bottom: 12px; }
.docs-content section + section {
    margin-top: 28px;
    padding-top: 22px;
    border-top: 1px solid var(--border);
}
.docs-content h4 {
    margin: 0 0 12px;
    color: var(--accent);
    font-size: 16px;
}
.docs-content p {
    margin: 0 0 10px;
    color: var(--fg);
    font-size: 13px;
}
.docs-content ul, .docs-content ol {
    margin: 0 0 12px;
    padding-left: 22px;
    font-size: 13px;
    color: var(--fg);
}
.docs-content li { margin-bottom: 5px; line-height: 1.65; }
.docs-content code, .docs-content kbd {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 6px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11.5px;
    color: var(--accent);
}
.docs-content kbd {
    background: var(--bg);
    box-shadow: 0 1px 0 var(--border);
}
.docs-content strong { color: var(--fg); }
.docs-content em { color: var(--accent); font-style: normal; font-weight: 600; }
.docs-content .callout {
    background: rgba(189, 147, 249, 0.08);
    border-left: 3px solid var(--accent);
    padding: 10px 14px;
    margin: 12px 0;
    border-radius: 0 4px 4px 0;
}
:root[data-theme="light"] .docs-content .callout {
    background: rgba(111, 66, 193, 0.06);
}
.docs-dl {
    margin: 0;
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 8px 18px;
    font-size: 13px;
}
.docs-dl dt {
    color: var(--accent);
    font-weight: 600;
}
.docs-dl dd {
    margin: 0;
    color: var(--fg);
}
.docs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin: 6px 0 12px;
}
.docs-table th, .docs-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
.docs-table th {
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 10px;
    font-weight: 700;
}
.docs-table.compare th { width: 50%; }
.docs-table.compare td:first-child {
    color: var(--primary);
    border-right: 1px solid var(--border);
}
.docs-table.compare td:last-child { color: var(--dim); }

/* Section-group label inside the docs nav. */
.docs-nav-group {
    color: var(--dim);
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    padding: 14px 12px 4px;
}
.docs-nav-group:first-child { padding-top: 4px; }

/* Brochure hero — first section of the docs panel. */
.doc-hero {
    margin: -24px -24px 24px;
    padding: 28px 28px 24px;
    background: linear-gradient(135deg,
        rgba(189, 147, 249, 0.10) 0%,
        rgba(80, 250, 123, 0.05) 60%,
        transparent 100%);
    border-bottom: 1px solid var(--border);
}
:root[data-theme="light"] .doc-hero {
    background: linear-gradient(135deg,
        rgba(111, 66, 193, 0.06) 0%,
        rgba(31, 136, 61, 0.04) 60%,
        transparent 100%);
}
.doc-hero-title {
    font-size: 30px;
    font-weight: 800;
    margin: 0 0 6px;
    color: var(--accent);
    letter-spacing: -0.02em;
}
.doc-hero-tagline {
    font-size: 16px;
    color: var(--fg);
    font-weight: 500;
    margin: 0 0 14px;
    line-height: 1.45;
    max-width: 60ch;
}
.doc-hero p {
    color: var(--fg);
    line-height: 1.65;
}
.doc-hero-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 18px;
}
@media (max-width: 720px) {
    .doc-hero-grid { grid-template-columns: 1fr; }
}
.doc-hero-card {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
}
.doc-hero-card-h {
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
    font-size: 13px;
}
.doc-hero-card p {
    margin: 0;
    font-size: 12px;
    color: var(--dim);
    line-height: 1.5;
}

/* Code blocks inside the docs panel. Mono, scrollable, copy-friendly. */
.docs-code {
    display: block;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin: 6px 0 14px;
    font-family: ui-monospace, "SF Mono", Monaco, "Cascadia Code", monospace;
    font-size: 12px;
    line-height: 1.55;
    color: var(--fg);
    overflow-x: auto;
    white-space: pre;
}
:root[data-theme="light"] .docs-code {
    background: #f4f5f7;
}

@media (max-width: 720px) {
    .docs-body { grid-template-columns: 1fr; }
    .docs-nav { display: none; }
    .docs-dl { grid-template-columns: 1fr; }
    .doc-hero { margin: -16px -16px 16px; padding: 20px 18px; }
    .doc-hero-title { font-size: 24px; }
    .doc-hero-tagline { font-size: 14px; }
}

/* Connection picker row in run-form Section 2 */
.conn-row {
    display: flex;
    align-items: stretch;
    gap: 6px;
}
.conn-row select { flex: 1; }
.conn-row .link-btn {
    padding: 6px 10px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    text-transform: none;
    letter-spacing: 0;
    font-size: 12px;
}
.conn-row .link-btn:hover { border-color: var(--accent); text-decoration: none; }
.raw-url-toggle { margin-top: 4px; font-size: 11px; }

/* Type pill on saved-connection list rows */
.type-pill {
    font-size: 9px;
    padding: 1px 6px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    flex-shrink: 0;
}
.type-pill.postgres   { background: var(--info); color: var(--bg); }
.type-pill.cockroach  { background: var(--warn); color: var(--bg); }
.type-pill.oracle     { background: var(--pink); color: var(--bg); }
.type-pill.system     { background: var(--fg-dim, #888); color: var(--bg); }

/* ============================================================
   Query library modal
   ============================================================ */
dialog.library-modal { width: min(1200px, 96vw); max-height: 92vh; }
.library-modal .modal-body { padding: 0; }
.library-body {
    display: grid;
    grid-template-columns: 260px 1fr;
    height: calc(92vh - 56px);
    max-height: calc(92vh - 56px);
}
.library-list {
    background: var(--bg-alt);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}
.library-list-head {
    padding: var(--space-3) var(--space-4) var(--space-2);
    border-bottom: 1px solid var(--border);
    background: var(--bg-alt);
    position: sticky;
    top: 0;
    z-index: 2;
}
#library-search {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--fg);
    font-size: var(--font-xs);
    margin-bottom: var(--space-2);
}
#library-search:focus { outline: none; border-color: var(--accent); }
.library-filters {
    display: flex;
    gap: 4px;
}
.lib-filter {
    flex: 1;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--dim);
    padding: 3px 6px;
    border-radius: var(--radius-sm);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
}
.lib-filter:hover { color: var(--fg); }
.lib-filter.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

/* Category groups */
.library-group { border-bottom: 1px solid var(--border); }
.library-group > summary {
    list-style: none;
    cursor: pointer;
    padding: 8px 14px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--accent);
    background: var(--bg);
    user-select: none;
}
.library-group > summary::-webkit-details-marker { display: none; }
.library-group > summary::before {
    content: "▾";
    margin-right: 6px;
    transition: transform 120ms;
}
.library-group:not([open]) > summary::before {
    content: "▸";
}
.library-group .cat-count { font-size: 10px; font-weight: 400; margin-left: 4px; }
.library-list ul { list-style: none; padding: 0; margin: 0; }
.library-list li {
    padding: 9px 14px;
    cursor: pointer;
    border-left: 3px solid transparent;
    font-size: 12px;
    color: var(--fg);
    display: flex;
    align-items: center;
    gap: 7px;
    transition: background 0.15s;
}
.library-list li:hover { background: var(--bg); }
.library-list li.selected {
    background: var(--bg);
    border-left-color: var(--accent);
}
.library-list li .lib-name { flex: 1; }
.library-list li .lib-pill {
    font-size: 9px;
    padding: 1px 6px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
}
.library-list li .lib-pill.easy   { background: var(--info); color: var(--bg); }
.library-list li .lib-pill.medium { background: var(--warn); color: var(--bg); }
.library-list li .lib-pill.hard   { background: var(--pink); color: var(--bg); }
.library-list li .lib-row-actions {
    display: inline-flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}
.library-list li:hover .lib-row-actions,
.library-list li.selected .lib-row-actions {
    opacity: 1;
}
.library-list li .lib-row-actions button {
    background: transparent;
    border: none;
    color: var(--dim);
    cursor: pointer;
    padding: 2px 5px;
    font-size: 11px;
    line-height: 1;
    border-radius: var(--radius-sm);
}
.library-list li .lib-row-actions button:hover {
    color: var(--accent);
    background: var(--bg);
}
.library-list li .lib-row-actions .lib-row-del:hover {
    color: var(--danger);
}
.library-list li .lib-row-actions button:disabled {
    opacity: 0.25;
    cursor: not-allowed;
}
.library-list li.cloned .lib-name::after {
    content: " (custom)";
    color: var(--accent);
    font-size: 10px;
    font-weight: 600;
}

.library-pane {
    overflow-y: auto;
    padding: 18px 24px 24px;
}
.library-empty {
    color: var(--dim);
    text-align: center;
    padding: 80px 0;
    font-size: 13px;
}

.library-fields {
    display: grid;
    grid-template-columns: 1fr 200px;
    gap: 10px 14px;
    margin-bottom: 18px;
}
.library-fields label {
    color: var(--dim);
    font-size: 11px;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 0;
}
.library-fields label.full { grid-column: 1 / -1; }
.library-fields input,
.library-fields select {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--fg);
    border-radius: 4px;
    padding: 6px 9px;
    font-size: 13px;
    font-family: inherit;
}
.library-fields label.readonly input {
    color: var(--dim);
    font-family: ui-monospace, monospace;
    font-size: 11px;
    background: var(--bg);
    cursor: default;
}

/* Oracle ADB / wallet sub-form inside the connection editor. */
fieldset.oracle-extra {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px 14px;
    margin: 4px 0 12px;
}
fieldset.oracle-extra legend {
    color: var(--dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 0 6px;
}
.oracle-mode-row {
    display: flex;
    gap: 18px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
label.radio-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--fg);
    font-size: 13px;
    cursor: pointer;
}
label.radio-inline input[type="radio"] { margin: 0; }
#set-descriptor {
    width: 100%;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--fg);
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 12px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    resize: vertical;
    min-height: 70px;
}
.wallet-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.wallet-upload-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-alt);
    border: 1px dashed var(--border);
    color: var(--fg);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}
.wallet-upload-label:hover { border-color: var(--accent); color: var(--accent); }
.ok { color: var(--primary); }
.err { color: var(--danger); }

.library-section { margin-bottom: 16px; }
.library-section-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}
.library-section-head h4 {
    margin: 0;
    color: var(--dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.library-section textarea {
    width: 100%;
    min-height: 180px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 10px 12px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 12px;
    color: var(--fg);
    resize: vertical;
    line-height: 1.5;
    tab-size: 4;
}
.library-section textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(189, 147, 249, 0.18);
}

.library-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
}
#lib-status { font-size: 11px; }
#lib-status.ok { color: var(--primary); }
#lib-status.err { color: var(--danger); }

@media (max-width: 720px) {
    .library-body { grid-template-columns: 1fr; }
    .library-list { display: none; }
}

/* Footer */
.app-footer {
    margin-top: var(--space-5);
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border);
    background: var(--bg-alt);
    text-align: center;
    font-size: var(--font-xs);
}
.app-footer a { color: inherit; text-decoration: none; }
.app-footer a:hover { color: var(--accent); }

/* Print stylesheet — hide nav and form, expand the dashboard so a quick
   Cmd-P captures a clean snapshot of the live run. */
@media print {
    header, #form-pane, #history-pane, #live-runs, #live-runs-bar,
    #onboarding, .app-footer {
        display: none !important;
    }
    main {
        display: block !important;
        padding: 12px !important;
    }
    #dashboard-pane {
        border: none !important;
        page-break-inside: avoid;
    }
    canvas { max-width: 100% !important; }
    .historical-compare { background: transparent !important; }
    body { background: #ffffff !important; color: #222 !important; }
}

/* Per-query mini-stats strip in the library editor */
.lib-stats-strip {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-3);
    font-size: var(--font-xs);
}
.lib-stats-strip .stats-row { line-height: 1.7; }
.lib-stats-strip .stats-row.last5 { margin-top: 4px; }
.lib-stats-strip .run-mini {
    display: inline-block;
    padding: 1px 6px;
    margin-right: 4px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    color: var(--dim);
}

/* Quick-run row */
.library-quickrun {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) 0;
    border-top: 1px dashed var(--border);
    border-bottom: 1px dashed var(--border);
    margin: var(--space-3) 0;
    font-size: var(--font-xs);
}
.library-quickrun .lib-qr {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--font-xs);
    font-weight: 600;
}
.library-quickrun .lib-qr:hover {
    background: var(--accent);
    color: var(--bg);
}
.library-quickrun .hint { font-size: 10px; }

/* ────────────────────────────────────────────────────────────────────
   Pane chrome — collapsible rails, drag-resize, chart popout
   ──────────────────────────────────────────────────────────────────── */

/* Drag-resize handles between grid columns. Thin (4px), get a strong
   accent on hover so they're discoverable; cursor changes to col-resize. */
.pane-resizer {
    background: transparent;
    align-self: stretch;
    height: 100%;
    min-height: 200px;
    cursor: col-resize;
    border-radius: 2px;
    transition: background 0.15s;
    position: relative;
    z-index: 1;
}
.pane-resizer:hover,
.pane-resizer.dragging,
.pane-resizer:focus-visible {
    background: var(--accent);
    outline: none;
}
.pane-resizer:focus-visible { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
body.col-resizing { cursor: col-resize !important; user-select: none !important; }
body.col-resizing * { cursor: col-resize !important; user-select: none !important; }

/* Collapse / expand button on each rail. Sits at the top-right of the
   pane (or top-left for the right pane) so it's reachable but doesn't
   eat into the title row. */
.pane-collapse {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--border);
    background: var(--bg-alt);
    color: var(--dim);
    border-radius: var(--radius-sm);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
    opacity: 0.55;
    transition: opacity 0.15s, color 0.15s;
}
.pane-collapse:hover { opacity: 1; color: var(--accent); border-color: var(--accent); }
/* History pane collapse button sits on the LEFT edge so it doesn't fight
   the existing "Clear" link in the h2. */
#history-pane > .pane-collapse {
    left: 6px;
    right: auto;
}

/* Collapsed-label vertical banner — shown only when the pane is collapsed.
   The whole strip is the click target (single, obvious affordance);
   the small .pane-collapse chevron is hidden in this state to avoid two
   buttons doing the same thing in 32px of width. */
.pane-collapsed-label {
    display: none;
    position: absolute;
    inset: 0;                          /* fill the entire 32px-wide strip */
    align-items: center;
    justify-content: center;
    color: var(--dim);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    user-select: none;
    background: transparent;
    transition: background 0.15s, color 0.15s;
}
.pane-collapsed-label::before {
    content: "›";
    display: inline-block;
    font-size: 16px;
    font-weight: 400;
    margin-right: 8px;
    opacity: 0.7;
}
.pane-collapsed-label:hover {
    background: var(--bg-alt);
    color: var(--accent);
}
.pane-collapsed-label:hover::before { opacity: 1; }

/* Form pane on the LEFT: rotate label so it reads bottom-to-top, with the
   "expand" chevron pointing right (into the page). */
main.form-collapsed #form-pane > .pane-collapsed-label {
    display: flex;
    writing-mode: vertical-rl;
    transform: rotate(180deg);         /* read bottom-to-top */
}
/* History pane on the RIGHT: read top-to-bottom, chevron points left. */
main.history-collapsed #history-pane > .pane-collapsed-label {
    display: flex;
    writing-mode: vertical-rl;
}
main.history-collapsed #history-pane > .pane-collapsed-label::before {
    content: "‹";
}

/* When collapsed, hide every child except the label — and hide the small
   .pane-collapse chevron too (the whole strip is now the click target). */
main.form-collapsed #form-pane > :not(.pane-collapsed-label),
main.history-collapsed #history-pane > :not(.pane-collapsed-label) {
    display: none;
}
main.form-collapsed #form-pane,
main.history-collapsed #history-pane {
    padding: 0;
    overflow: hidden;
    min-height: 200px;
    position: relative;
}
/* Make the panes positioning context for the absolute children. */
#form-pane, #history-pane { position: relative; }

/* Chart pop-out button (in chart-tabs row, right side). */
.chart-popout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--dim);
    width: 24px;
    height: 24px;
    padding: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    margin-left: var(--space-2);
    align-self: center;
    flex-shrink: 0;
}
.chart-popout:hover { color: var(--accent); border-color: var(--accent); }

/* Native fullscreen styling for the chart-wrap. */
.chart-wrap:fullscreen {
    background: var(--bg);
    padding: var(--space-5);
    overflow: auto;
}
.chart-wrap:fullscreen canvas { max-height: 80vh; }

/* Single "↓ Download ▾" dropdown shared across the dashboard, the
   compare-table rows, and the run-detail modal. Built on native
   <details>/<summary> so no JS toggle plumbing is needed. */
.dl-menu {
    position: relative;
    display: inline-block;
    margin-left: var(--space-2);
}
.dl-menu > summary {
    list-style: none;
    cursor: pointer;
    background: var(--accent);
    color: var(--bg);
    border: 1px solid var(--accent);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: var(--font-xs);
    font-weight: 600;
    user-select: none;
    transition: opacity 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.dl-menu > summary::-webkit-details-marker { display: none; }
.dl-menu > summary:hover { opacity: 0.88; }
.dl-menu .dl-caret {
    font-size: 10px;
    opacity: 0.85;
    transition: transform 0.15s;
    display: inline-block;
}
.dl-menu[open] > summary .dl-caret { transform: rotate(180deg); }

/* Floating menu items */
.dl-menu-items {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 140px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-2);
    z-index: 100;
    padding: 4px;
    display: flex;
    flex-direction: column;
}
.dl-menu-items a {
    padding: 6px 12px;
    color: var(--fg);
    text-decoration: none;
    font-size: var(--font-xs);
    border-radius: var(--radius-sm);
    transition: background 0.1s;
}
.dl-menu-items a:hover {
    background: var(--bg);
    color: var(--accent);
}

/* Compact variant for the per-row dropdown in the compare table —
   keep the action cell narrow. */
.hc-dl-menu > summary {
    padding: 2px 6px;
    font-size: 10px;
}
.hc-dl-menu .dl-menu-items { min-width: 120px; }

/* Advanced section: tab toggle between "Library asset" and "File path". */
.advanced-tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-3);
}
.adv-tab {
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    color: var(--dim);
    padding: 6px 12px;
    font-size: var(--font-sm);
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.adv-tab:hover { color: var(--fg); }
.adv-tab.active {
    color: var(--accent);
    border-color: var(--border);
    border-bottom-color: var(--bg);
    background: var(--panel);
    margin-bottom: -1px;
}
.adv-pane label {
    display: block;
    margin-bottom: var(--space-2);
}
.adv-pane select { width: 100%; }

/* Library assets modal — uses the existing .library-modal styles for the
   shell; just a textarea-friendly tweak here. */
#assets-editor textarea {
    width: 100%;
    min-height: 240px;
    font-family: ui-monospace, "SF Mono", Monaco, "Cascadia Code", monospace;
    font-size: var(--font-sm);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-alt);
    color: var(--fg);
    padding: var(--space-2);
    resize: vertical;
}
#assets-list-ul {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
}
#assets-list-ul li {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: var(--font-sm);
}
#assets-list-ul li:hover { background: var(--bg-alt); }
#assets-list-ul li.selected { background: var(--bg-alt); border-left: 3px solid var(--accent); }
#assets-list-ul li .asset-name { font-weight: 600; }
#assets-list-ul li .asset-meta { color: var(--dim); font-size: var(--font-xs); margin-top: 2px; }

/* Source chip in the history "Run" cell — tiny pill that shows where the
   run was launched from (web / cli / tui). Color-coded so CLI runs are
   easy to spot when scanning the history list. */
.src-chip {
    display: inline-block;
    margin-left: 4px;
    padding: 1px 5px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    color: var(--dim);
    vertical-align: middle;
    line-height: 1.4;
}
.src-chip.src-web { color: var(--info);    border-color: var(--info); }
.src-chip.src-cli { color: var(--accent);  border-color: var(--accent); }
.src-chip.src-tui { color: var(--pink);    border-color: var(--pink); }

/* Compact status indicator in the history table — green check for the
   common "complete" case (instead of a wide COMPLETE pill) and a red
   cross for "error". "running" still uses the full pill so it's loud. */
.status-icon {
    display: inline-block;
    width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 800;
}
.status-icon.status-complete {
    background: rgba(80, 250, 123, 0.15);
    color: var(--primary);
    border: 1px solid var(--primary);
}
.status-icon.status-error {
    background: rgba(255, 85, 85, 0.15);
    color: var(--danger);
    border: 1px solid var(--danger);
}
