/* ============================================================================
   Algo — single source of truth for the app theme.
   A modern, dark "fintech" skin built on a small set of design tokens. The
   palette is derived from the live console window so the whole app feels like
   one product. Bootstrap 5.3 runs in dark color-mode (data-bs-theme="dark" on
   <html>); the overrides below recolor its component variables to these tokens
   so existing Bootstrap markup (cards, tables, buttons…) adopts the theme with
   no per-page changes.

   Sections:
     1. Design tokens
     2. Base / reset
     3. Bootstrap dark overrides
     4. App shell + sidebar + nav
     5. Top bar + process strip
     6. Cards, stat tiles, dashboard grid, charts
     7. Badges, status dots, tables, forms, buttons, misc
     8. Console (pop-out window)
     9. Chat (Ollama)
    10. Error UI + utilities
   ========================================================================== */

/* ----------------------------------------------------------- 1. tokens ---- */
:root {
    /* surfaces, deepest → most elevated */
    --algo-bg:        #0d0f14;
    --algo-bg-2:      #12141a;
    --surface:        #161922;
    --surface-2:      #1b1e26;
    --surface-3:      #232733;
    --surface-hover:  #20242f;

    /* lines */
    --border:         #2b2f3a;
    --border-strong:  #3a3f4b;

    /* text */
    --text:           #e6e9ef;
    --text-muted:     #9aa4b2;
    --text-dim:       #6b7280;

    /* brand + semantic */
    --accent:         #4f8cff;
    --accent-2:       #6cb6ff;
    --accent-soft:    rgba(79, 140, 255, 0.14);
    --accent-glow:    rgba(79, 140, 255, 0.40);
    --success:        #3fb950;
    --success-soft:   rgba(63, 185, 80, 0.14);
    --danger:         #ff6b66;
    --danger-soft:    rgba(255, 107, 102, 0.14);
    --warning:        #f2c14e;
    --warning-soft:   rgba(242, 193, 78, 0.14);
    --info:           #6cb6ff;

    /* shape + depth */
    --radius:    14px;
    --radius-sm: 9px;
    --radius-xs: 6px;
    --shadow:    0 1px 2px rgba(0,0,0,.35), 0 12px 32px -16px rgba(0,0,0,.65);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);

    --sidebar-w: 215px;
    --topbar-h:  46px;

    --font-sans: 'Inter', 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --font-mono: 'Cascadia Code', 'JetBrains Mono', 'Consolas', 'SFMono-Regular', monospace;
}

/* --------------------------------------------------------- 2. base ------- */
/* Global compaction: rem is the unit nearly everything (app + Bootstrap) is
   sized in, so shrinking the root font-size scales the whole UI down in one
   place. 13px ≈ 19% tighter than the 16px browser default — a denser, more
   data-rich layout without touching individual component sizes. */
html { font-size: 13px; }

html, body {
    font-family: var(--font-sans);
    background-color: var(--algo-bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body {
    margin: 0;
    min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text);
    font-weight: 650;
    letter-spacing: -0.01em;
}

h1 { font-size: 1.6rem; }
h1:focus { outline: none; }

a {
    color: var(--accent-2);
    text-decoration: none;
}
a:hover { color: #9fccff; text-decoration: underline; }

code, pre, .font-mono { font-family: var(--font-mono); }

hr { border-color: var(--border); opacity: 1; }

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

/* themed scrollbars */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: #4a505e; background-clip: content-box; }

/* ------------------------------------------- 3. Bootstrap dark overrides -- */
[data-bs-theme="dark"] {
    --bs-body-bg: var(--algo-bg);
    --bs-body-color: var(--text);
    --bs-emphasis-color: #ffffff;
    --bs-emphasis-color-rgb: 255, 255, 255;
    --bs-secondary-color: var(--text-muted);
    --bs-secondary-bg: var(--surface-2);
    --bs-tertiary-color: var(--text-dim);
    --bs-tertiary-bg: var(--surface-3);

    --bs-border-color: var(--border);
    --bs-border-color-translucent: rgba(255, 255, 255, 0.08);

    --bs-primary: #4f8cff;
    --bs-primary-rgb: 79, 140, 255;
    --bs-link-color: var(--accent-2);
    --bs-link-color-rgb: 108, 182, 255;
    --bs-link-hover-color: #9fccff;
    --bs-link-hover-color-rgb: 159, 204, 255;

    --bs-success: #3fb950; --bs-success-rgb: 63, 185, 80;
    --bs-danger:  #ff6b66; --bs-danger-rgb: 255, 107, 102;
    --bs-warning: #f2c14e; --bs-warning-rgb: 242, 193, 78;
    --bs-info:    #6cb6ff; --bs-info-rgb: 108, 182, 255;

    --bs-card-bg: var(--surface);
    --bs-card-border-color: var(--border);
    --bs-card-cap-bg: var(--surface-2);
    --bs-card-color: var(--text);

    --bs-border-radius: var(--radius-sm);
    --bs-border-radius-sm: var(--radius-xs);
    --bs-border-radius-lg: var(--radius);

    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-border-color: var(--border);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.025);
    --bs-table-striped-color: var(--text);
    --bs-table-hover-bg: var(--accent-soft);
    --bs-table-hover-color: var(--text);

    --bs-progress-bg: var(--surface-3);
    --bs-code-color: #ff9d96;
}

/* Cards: a touch of depth + crisp hairline. */
.card {
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card .card-header { border-bottom-color: var(--border); font-weight: 600; }

/* Inputs: lift off the page background so they're readable on the dark shell. */
.form-control, .form-select {
    background-color: var(--surface-3);
    border-color: var(--border);
    color: var(--text);
}
.form-control:focus, .form-select:focus {
    background-color: var(--surface-3);
    border-color: var(--accent);
    color: var(--text);
    box-shadow: 0 0 0 0.2rem var(--accent-soft);
}
.form-control::placeholder { color: var(--text-dim); }

.btn:focus-visible, .form-control:focus-visible, .form-check-input:focus-visible {
    box-shadow: 0 0 0 0.2rem var(--accent-soft);
}
.btn-primary { --bs-btn-color: #fff; --bs-btn-hover-color: #fff; --bs-btn-active-color: #fff; }

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

.validation-message, .invalid-feedback { color: var(--danger); }
.valid.modified:not([type=checkbox]) { outline: 1px solid var(--success); }
.invalid { outline: 1px solid var(--danger); }

/* --------------------------------------------- 4. shell + sidebar + nav --- */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.sidebar {
    background: linear-gradient(180deg, #14171f 0%, #0f1117 100%);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.content {
    padding: 1.5rem 1.75rem 3rem;
    flex: 1;
}

/* brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    height: var(--topbar-h);
    padding: 0 1.15rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: 0.01em;
    text-decoration: none;
}
.sidebar-brand:hover { color: var(--text); text-decoration: none; }
.sidebar-brand .brand-mark {
    display: grid;
    place-items: center;
    width: 30px; height: 30px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), #7b5bff);
    color: #fff;
    font-size: 1rem;
    box-shadow: 0 4px 14px -4px var(--accent-glow);
}
.sidebar-brand .brand-text { background: linear-gradient(90deg, #fff, #c9d4e3); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

/* collapsible region (brand stays put; this collapses on mobile) */
.nav-collapse {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* nav scroll area */
.nav-scrollable {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem 0.5rem 0.6rem;
}

.nav-section {
    padding: 0.7rem 0.6rem 0.3rem;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-dim);
}
.nav-section:first-child { padding-top: 0.3rem; }

/* collapsible group: native <details>/<summary> so it toggles with no JS / no interactivity */
.nav-group { margin: 0; }
.nav-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    cursor: pointer;
    user-select: none;
    list-style: none; /* hide the default disclosure triangle (Firefox) */
    transition: color .12s ease;
}
.nav-group-header::-webkit-details-marker { display: none; } /* hide the default triangle (WebKit) */
.nav-group-header::marker { content: ""; }
.nav-group-header:hover { color: var(--text-muted); }
.nav-group-header .nav-chevron {
    font-size: 0.68rem;
    opacity: 0.6;
    transition: transform .15s ease;
}
.nav-group[open] > .nav-group-header .nav-chevron { transform: rotate(180deg); }

/* nested child links sit under a guide rail so the group hierarchy reads at a glance */
.nav-group > .algo-nav-link,
.nav-group > * > .algo-nav-link,
.nav-group form .algo-nav-link {
    margin-left: 0.7rem;
    padding-left: 0.65rem;
    border-left: 1px solid var(--border);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}
.nav-group > .algo-nav-link:hover,
.nav-group form .algo-nav-link:hover { border-left-color: var(--border-strong); }
.nav-group > .algo-nav-link.active,
.nav-group form .algo-nav-link.active { border-left-color: var(--accent); }

.algo-nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.38rem 0.6rem;
    margin-bottom: 1px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.84rem;
    font-weight: 500;
    width: 100%;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    position: relative;
    transition: background-color .12s ease, color .12s ease, border-color .12s ease;
}
.algo-nav-link .bi { font-size: 0.98rem; width: 1.15rem; text-align: center; opacity: .9; }
.algo-nav-link:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.algo-nav-link.active {
    background: var(--accent-soft);
    color: #cfe0ff;
}
.algo-nav-link.is-action { color: var(--text-muted); }

.nav-footer {
    border-top: 1px solid var(--border);
    padding: 0.5rem 0.5rem;
}

/* mobile drawer plumbing — a pure-CSS checkbox (in MainLayout, a sibling of the
   sidebar) drives the slide-in; the hamburger + backdrop are <label for> targets
   so no JS/interactivity is needed under static server rendering. All hidden on
   desktop and revealed in the small-screen media query below. */
.nav-toggle-input { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.nav-hamburger { display: none; }
.nav-backdrop { display: none; }

@media (min-width: 768px) {
    .app-shell { flex-direction: row; }
    .sidebar {
        width: var(--sidebar-w);
        height: 100vh;
        position: sticky;
        top: 0;
    }
}

@media (max-width: 767.98px) {
    /* off-canvas drawer: parked just left of the viewport, slides in when checked */
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: min(82vw, 300px);
        z-index: 60;
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: 0 0 40px rgba(0, 0, 0, .5);
    }
    .nav-toggle-input:checked ~ .sidebar { transform: translateX(0); }

    /* dimmed scrim behind the open drawer; tapping it (a <label for>) closes the menu */
    .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 55;
        background: rgba(0, 0, 0, .55);
        backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity .22s ease;
    }
    .nav-toggle-input:checked ~ .nav-backdrop { opacity: 1; pointer-events: auto; }

    /* hamburger trigger living in the top bar */
    .nav-hamburger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        width: 2.2rem; height: 2.2rem;
        margin-right: 0.1rem;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        background: var(--surface-2);
        color: var(--text);
        font-size: 1.2rem;
        cursor: pointer;
    }
    .nav-hamburger:hover { background: var(--surface-hover); }
}

/* ------------------------------------------------- 5. top bar + strip ----- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    min-height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1.25rem;
    background: rgba(18, 20, 26, 0.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.process-strip {
    display: flex;
    align-items: stretch;
    gap: 0.6rem;
    flex-wrap: wrap;
    flex: 1 1 auto;
    min-width: 0;
}

/* ---- top-right ticker search ---- */
.stock-search {
    position: relative;
    flex: 0 0 auto;
    width: 230px;
}

.stock-search .ss-icon {
    position: absolute;
    left: 0.65rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
    font-size: 0.85rem;
    pointer-events: none;
}

.ss-input {
    width: 100%;
    height: 36px;
    padding: 0 0.7rem 0 2rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
    transition: border-color .12s ease, box-shadow .12s ease;
}

.ss-input::placeholder { color: var(--text-dim); }

.ss-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.ss-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    left: 0;
    z-index: 50;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    overflow: hidden;
    max-height: 360px;
    overflow-y: auto;
}

.ss-item {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.45rem 0.7rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

.ss-item:last-child { border-bottom: none; }
.ss-item:hover,
.ss-item.is-active { background: var(--surface-hover); }

.ss-item .ss-sym { font-weight: 600; color: var(--text); font-size: 0.85rem; }
.ss-item .ss-name {
    flex: 1 1 auto;
    min-width: 0;
    color: var(--text-muted);
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ss-item .ss-count {
    flex: 0 0 auto;
    color: var(--accent-2);
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
}

.ss-empty {
    padding: 0.6rem 0.7rem;
    color: var(--text-dim);
    font-size: 0.8rem;
}

@media (max-width: 720px) {
    .stock-search { width: 160px; }
}

.proc-chip {
    --chip: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    /* Fixed width so a long sub-line (e.g. a comment title) ellipsizes instead of
       widening the chip and shifting the whole strip. */
    flex: 0 0 auto;
    width: 210px;
    padding: 0.4rem 0.7rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    position: relative;
    overflow: hidden;
}
.proc-chip.is-running { --chip: var(--accent); border-color: rgba(79,140,255,.4); }
.proc-chip.is-ok      { --chip: var(--success); }
.proc-chip.is-failed  { --chip: var(--danger); border-color: rgba(255,107,102,.4); }
.proc-chip.is-idle    { --chip: var(--text-dim); }

.proc-chip .proc-icon {
    display: grid; place-items: center;
    width: 30px; height: 30px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--chip) 16%, transparent);
    color: var(--chip);
    font-size: 1rem;
    flex-shrink: 0;
}
.proc-body { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.proc-name {
    font-size: 0.7rem; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.04em;
    display: flex; align-items: center; gap: 0.35rem;
}
.proc-stat { font-size: 0.84rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 14rem; }
.proc-sub  { font-size: 0.72rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* the live underline progress bar inside a running chip */
.proc-chip .proc-progress {
    position: absolute;
    left: 0; bottom: 0; height: 2px;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
    transition: width .3s ease;
}
.proc-chip .proc-progress.indeterminate {
    width: 35% !important;
    animation: proc-slide 1.1s ease-in-out infinite;
}
@keyframes proc-slide { 0% { left: -35%; } 100% { left: 100%; } }

/* small live status dot */
.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--chip, var(--text-dim));
    flex-shrink: 0;
}
.status-dot.pulse { box-shadow: 0 0 0 0 var(--accent-glow); animation: dot-pulse 1.4s infinite; }
@keyframes dot-pulse {
    0%   { box-shadow: 0 0 0 0 var(--accent-glow); }
    70%  { box-shadow: 0 0 0 6px rgba(79,140,255,0); }
    100% { box-shadow: 0 0 0 0 rgba(79,140,255,0); }
}

/* ------------------------------------ 6. stat tiles / dashboard / charts -- */
.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.page-head .subtitle { color: var(--text-muted); font-size: 0.9rem; margin: 0.15rem 0 0; }

.dash-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.surface-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.surface-card.pad { padding: 1.1rem 1.2rem; }

.card-title-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.5rem; margin-bottom: 0.85rem;
}
.card-title-row h2, .card-title-row h3 { font-size: 1rem; margin: 0; }
.card-eyebrow {
    font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em;
    text-transform: uppercase; color: var(--text-dim);
}

/* stat tile */
.stat-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    /* visible (not hidden) so an InfoTip hover-card inside the label isn't clipped by the tile.
       The decorative .stat-icon is positioned within bounds, so nothing else overflows. */
    overflow: visible;
}
.stat-tile .stat-label {
    font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em;
    text-transform: uppercase; color: var(--text-muted);
    display: flex; align-items: center; gap: 0.4rem;
}
.stat-tile .stat-value {
    font-size: 1.7rem; font-weight: 700; line-height: 1.1; margin-top: 0.3rem;
    font-variant-numeric: tabular-nums;
}
.stat-tile .stat-sub { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.15rem; }
.stat-tile .stat-icon {
    position: absolute; top: 0.9rem; right: 1rem;
    font-size: 1.15rem; color: var(--text-dim); opacity: .6;
}
.stat-tile.accent { border-color: rgba(79,140,255,.35); }
.stat-tile.accent .stat-value { color: var(--accent-2); }

/* per-metric quality gauge — a little 5-segment bar above a KPI showing how good the metric is */
.qbars { display: flex; gap: 3px; margin-bottom: 0.5rem; }
.qbar { flex: 1 1 0; max-width: 16px; height: 4px; border-radius: 2px; background: var(--surface-3); }
.qbars.q-good .qbar.on { background: var(--success); }
.qbars.q-mid  .qbar.on { background: var(--warning); }
.qbars.q-low  .qbar.on { background: var(--danger); }

/* in-sample / holdout time-window strip under the backtest equity chart */
.window-strip { display: flex; gap: 4px; margin-top: 0.6rem; }
.window-strip .win {
    display: flex; flex-direction: column; gap: 1px; min-width: 0;
    padding: 0.3rem 0.5rem; border-radius: var(--radius-xs); border: 1px solid var(--border);
}
.window-strip .win-name {
    font-size: 0.68rem; font-weight: 700; letter-spacing: 0.02em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.window-strip .win-range {
    font-size: 0.66rem; color: var(--text-dim);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.window-strip .win-train { background: var(--accent-soft); border-color: rgba(79,140,255,.3); }
.window-strip .win-train .win-name { color: var(--accent-2); }
.window-strip .win-test { background: var(--warning-soft); border-color: rgba(242,193,78,.3); }
.window-strip .win-test .win-name { color: var(--warning); }

/* info tooltip — JS-free hover-card (see Components/Shared/InfoTip.razor) */
.info-tip {
    position: relative;
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    color: var(--text-dim);
    cursor: help;
}
.info-tip > .bi { font-size: 0.85em; line-height: 1; }
.info-tip:hover, .info-tip:focus-visible { color: var(--accent-2); outline: none; }
.info-pop {
    position: absolute;
    z-index: 50;
    left: 50%;
    bottom: calc(100% + 8px);
    transform: translateX(-50%);
    width: max-content;
    max-width: 280px;
    /* reset inherited label/header typography so the body reads as normal prose */
    text-transform: none;
    letter-spacing: normal;
    font-weight: 400;
    font-size: 0.78rem;
    line-height: 1.45;
    text-align: left;
    white-space: normal;
    color: var(--text);
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 0.6rem 0.7rem;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .12s ease;
}
.info-tip:hover .info-pop,
.info-tip:focus-within .info-pop { opacity: 1; visibility: visible; }
.info-pop .info-h { display: block; font-weight: 700; margin-bottom: 0.25rem; color: var(--text); }

/* labelled control group (e.g. the lookback / horizon selectors) */
.ctrl-group { display: inline-flex; flex-direction: column; gap: 0.2rem; }
.ctrl-label {
    display: inline-flex; align-items: center; gap: 0.3rem;
    font-size: 0.66rem; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--text-dim);
}
.info-pop::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--border-strong);
}
/* downward variant — opens below the icon (for table headers inside overflow containers) */
.info-tip.below .info-pop { top: calc(100% + 8px); bottom: auto; }
.info-tip.below .info-pop::after { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: var(--border-strong); }

/* process detail card (dashboard) */
.proc-card { padding: 1.1rem 1.2rem; }
.proc-card .proc-head { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.6rem; }
.proc-card .proc-title { font-size: 1rem; font-weight: 650; margin: 0; }
.proc-card .proc-meta { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; font-size: 0.8rem; color: var(--text-muted); margin-top: 0.5rem; }
.proc-card .proc-meta b { color: var(--text); font-weight: 600; }

/* chart wrapper — keeps Chart.js canvas responsive and theme-framed */
.chart-card { padding: 1.1rem 1.2rem 0.9rem; }
.chart-box { position: relative; width: 100%; }
.chart-box canvas { display: block; width: 100% !important; }

/* throughput panel — scrape inflow vs analysis keep-up verdict (Processing page) */
.tp-verdict {
    display: flex; align-items: center; gap: 0.55rem;
    padding: 0.6rem 0.8rem; margin: 0.2rem 0 0.9rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 0.9rem; font-weight: 550; line-height: 1.35;
    background: var(--surface-2);
}
.tp-verdict > .bi { font-size: 1.1rem; flex: 0 0 auto; }
.tp-verdict.ok   { border-color: rgba(63,185,80,.35);  color: #8de29a; background: var(--success-soft); }
.tp-verdict.warn { border-color: rgba(242,193,78,.35); color: var(--warning); background: var(--warning-soft); }
.tp-verdict.bad  { border-color: rgba(255,107,102,.35); color: #ffb0ac; background: var(--danger-soft); }

.tp-kpis {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.6rem; margin-bottom: 0.9rem;
}
@media (max-width: 575.98px) { .tp-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tp-kpi {
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 0.6rem 0.75rem;
}
.tp-kpi-label {
    display: flex; align-items: center; gap: 0.35rem;
    font-size: 0.68rem; font-weight: 600; letter-spacing: 0.04em;
    text-transform: uppercase; color: var(--text-muted);
}
.tp-kpi-val {
    font-size: 1.45rem; font-weight: 700; line-height: 1.1; margin-top: 0.2rem;
    font-variant-numeric: tabular-nums;
}
.tp-kpi-unit { font-size: 0.8rem; font-weight: 500; color: var(--text-dim); margin-left: 0.1rem; }
.tp-kpi-sub { font-size: 0.74rem; color: var(--text-dim); margin-top: 0.1rem; }

/* ----------------------------------- 7. badges / dots / tables / misc ----- */
.badge.rounded-pill { font-weight: 600; }

.state-badge {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.2rem 0.6rem; border-radius: 999px;
    font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em;
    border: 1px solid transparent;
}
.state-badge .status-dot { width: 7px; height: 7px; }
.state-running { background: var(--accent-soft);  color: #bcd6ff; border-color: rgba(79,140,255,.35); }
.state-ok,
.state-completed { background: var(--success-soft); color: #8de29a; border-color: rgba(63,185,80,.3); }
.state-failed   { background: var(--danger-soft);  color: #ffb0ac; border-color: rgba(255,107,102,.3); }
.state-idle,
.state-skipped  { background: var(--surface-3);    color: var(--text-muted); border-color: var(--border); }

.text-bull { color: var(--success) !important; }
.text-bear { color: var(--danger) !important; }

.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > thead th {
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--text-dim); font-weight: 600; border-bottom-color: var(--border);
}
.table > tbody td { border-color: var(--border); vertical-align: middle; }

.tag-pill {
    display: inline-block; padding: 0.05rem 0.45rem; border-radius: 999px;
    background: var(--surface-3); color: var(--text-muted);
    font-size: 0.72rem; font-family: var(--font-mono);
}

/* thin progress used in cards/strip */
.progress.thin { height: 5px; background: var(--surface-3); }
.progress-bar.striped-anim { background-image: linear-gradient(45deg, rgba(255,255,255,.15) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.15) 50%, rgba(255,255,255,.15) 75%, transparent 75%, transparent); background-size: 1rem 1rem; animation: bar-stripes 1s linear infinite; }
@keyframes bar-stripes { from { background-position: 1rem 0; } to { background-position: 0 0; } }

.empty-hint { color: var(--text-dim); font-style: italic; padding: 1.5rem; text-align: center; }

/* relative-time / muted helpers */
.muted-sm { color: var(--text-muted); font-size: 0.82rem; }
.dim-sm   { color: var(--text-dim);   font-size: 0.78rem; }

/* --------------------------------------------------- 8. console window ---- */
.console-window { height: 100vh; }

.console-root {
    display: flex; flex-direction: column; height: 100vh;
    background: var(--algo-bg-2); color: #d7dae0;
    font-family: var(--font-mono); font-size: 12.5px;
}
.console-toolbar {
    display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
    padding: 0.45rem 0.6rem; background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.console-title { font-weight: 600; color: var(--text-muted); margin-right: 0.25rem; }
.console-levels { display: inline-flex; gap: 0.25rem; }
.lvl {
    border: 1px solid transparent; border-radius: 4px; padding: 0.1rem 0.5rem;
    font-size: 11px; font-weight: 600; cursor: pointer; background: var(--surface-3); color: var(--text-dim);
}
.lvl.on.lvl-verbose { color: #cfd3da; border-color: #4b5563; background: #2c313c; }
.lvl.on.lvl-info    { color: var(--info); border-color: #2f5d86; background: #14283a; }
.lvl.on.lvl-warning { color: var(--warning); border-color: #7a5d16; background: #322a10; }
.lvl.on.lvl-error   { color: var(--danger); border-color: #8a2f2a; background: #341615; }
.lvl.off { opacity: 0.45; text-decoration: line-through; }
.console-search {
    flex: 1 1 160px; min-width: 120px; background: var(--algo-bg); border: 1px solid var(--border);
    border-radius: 4px; color: #d7dae0; padding: 0.2rem 0.5rem; font-family: inherit; font-size: 12px;
}
.console-check { display: inline-flex; align-items: center; gap: 0.3rem; color: var(--text-muted); font-size: 12px; user-select: none; }
.console-action {
    border: 1px solid var(--border); background: var(--surface-3); color: #d7dae0;
    border-radius: 4px; padding: 0.2rem 0.6rem; font-size: 12px; cursor: pointer;
}
.console-action:hover { background: #2f3441; }
.console-action.is-paused { color: var(--warning); border-color: #7a5d16; }
.console-output { flex: 1; overflow-y: auto; padding: 0.35rem 0.5rem 1rem; line-height: 1.45; }
.console-empty { color: var(--text-dim); padding: 1rem; font-style: italic; }
.log-row {
    display: grid; grid-template-columns: 5.5rem 2.4rem 9rem 1fr; gap: 0.5rem;
    padding: 0.05rem 0.25rem; border-left: 3px solid transparent; white-space: pre-wrap; word-break: break-word;
}
.log-row:hover { background: #181b22; }
.log-time { color: #5f6672; }
.log-level { font-weight: 700; }
.log-cat { color: #8a93a3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-msg { color: #d7dae0; }
.log-ex {
    grid-column: 4 / 5; margin: 0.2rem 0 0.3rem; padding: 0.4rem 0.6rem;
    background: #1a0f10; border: 1px solid #3a1d1c; border-radius: 4px; color: #ff9d96; font-size: 11.5px; overflow-x: auto;
}
.level-verbose { border-left-color: #3a3f4b; }
.level-verbose .log-level, .level-verbose .log-msg { color: #8b919c; }
.level-info    { border-left-color: #2f5d86; }
.level-info .log-level { color: var(--info); }
.level-warning { border-left-color: #7a5d16; background: rgba(242,193,78,0.04); }
.level-warning .log-level, .level-warning .log-msg { color: var(--warning); }
.level-error   { border-left-color: #8a2f2a; background: rgba(255,123,114,0.06); }
.level-error .log-level, .level-error .log-msg { color: var(--danger); }
.console-status {
    display: flex; align-items: center; gap: 1rem; padding: 0.3rem 0.6rem;
    background: var(--surface-2); border-top: 1px solid var(--border); color: var(--text-dim); font-size: 11.5px;
}
.console-counts { margin-left: auto; display: inline-flex; align-items: center; gap: 0.35rem; }
.console-trim { color: var(--warning); }
.dot { display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 50%; margin-left: 0.6rem; }
.dot.verbose { background: var(--text-dim); }
.dot.info    { background: var(--info); }
.dot.warning { background: var(--warning); }
.dot.error   { background: var(--danger); }

/* embedded (dashboard) log tail — same look, fixed height */
.log-tail { height: 260px; overflow-y: auto; background: var(--algo-bg-2); border-radius: var(--radius-sm); padding: 0.4rem 0.5rem; font-family: var(--font-mono); font-size: 12px; }

/* ------------------------------------------------------------ 9. chat ----- */
.chat-log { max-height: 28rem; overflow-y: auto; background-color: var(--surface-2); border-radius: var(--radius-sm); }
.chat-msg .chat-role { text-transform: capitalize; font-size: 0.7rem; letter-spacing: 0.03em; color: var(--text-muted); }
.chat-msg .chat-content { white-space: pre-wrap; word-break: break-word; }
.chat-user .chat-content { background-color: var(--accent-soft); border-radius: 0.5rem; padding: 0.4rem 0.6rem; }
.chat-assistant .chat-content { background-color: var(--surface-3); border: 1px solid var(--border); border-radius: 0.5rem; padding: 0.4rem 0.6rem; }
.chat-system .chat-content { font-style: italic; color: var(--text-dim); }

/* ------------------------------------------------- 10. error UI + utils --- */
#blazor-error-ui {
    color-scheme: dark only;
    background: #2a1112;
    color: #ffd7d4;
    border-top: 1px solid #5a2422;
    bottom: 0; left: 0; width: 100%;
    box-shadow: 0 -1px 12px rgba(0,0,0,.5);
    box-sizing: border-box;
    display: none;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
#blazor-error-ui .reload { color: #ffb0ac; }

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem 1rem 1rem 1rem;
    color: white;
    border-radius: var(--radius-sm);
}
.blazor-error-boundary::after { content: "An error has occurred."; }

.darker-border-checkbox.form-check-input { border-color: var(--border-strong); }

/* --------------------------------------------------- processing page ------ */
/* The Scrape process card is featured at 3× width; it goes full-width on small screens
   so it doesn't overflow the auto-fit .dash-grid. */
.proc-card.feature { grid-column: span 3; }
@media (max-width: 900px) {
    .proc-card.feature { grid-column: 1 / -1; }
}

/* prominent "analyzed today" figure on the Sentiment card */
.proc-today {
    display: flex;
    align-items: baseline;
    gap: 0.45rem;
    margin: 0.55rem 0 0.2rem;
}
.proc-today .stat-value { font-size: 1.5rem; line-height: 1; }

/* ----------------------------------------------- 11. market dashboard ----- */
/* one-line narrative headline above the dashboard */
.insight-banner {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0.7rem 1rem; margin-bottom: 1.25rem;
    background: linear-gradient(90deg, var(--accent-soft), transparent 70%);
    border: 1px solid var(--border); border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm); color: var(--text); font-size: 0.92rem; line-height: 1.4;
}
.insight-banner .bi { color: var(--accent-2); font-size: 1.15rem; flex-shrink: 0; }
.insight-banner b { font-weight: 650; }

/* a stat tile whose value is colored by direction (market mood) */
.stat-tile .stat-value.is-bull { color: var(--success); }
.stat-tile .stat-value.is-bear { color: var(--danger); }

/* generic inline sparkline (no Chart.js — cheap, render as many as needed) */
.spark { display: block; width: 100%; }
.spark polyline { fill: none; stroke: currentColor; stroke-width: 1.7; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.spark polygon  { fill: currentColor; opacity: 0.13; stroke: none; }

/* trending ticker cards (top movers) */
.trend-card {
    display: flex; flex-direction: column; gap: 0.55rem;
    padding: 0.85rem 1rem; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); cursor: pointer; text-decoration: none; color: var(--text);
    transition: border-color .12s ease, transform .12s ease, background-color .12s ease;
}
.trend-card:hover { border-color: var(--border-strong); background: var(--surface-hover); transform: translateY(-2px); color: var(--text); text-decoration: none; }
.trend-card .tc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.trend-card .tc-sym { font-weight: 700; font-size: 1.06rem; letter-spacing: -0.01em; }
.trend-card .tc-co  { color: var(--text-dim); font-size: 0.72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 8.5rem; }
.trend-card .tc-mid { display: flex; align-items: baseline; gap: 0.5rem; }
.trend-card .tc-mentions { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.15rem; }
.trend-card .tc-mentions small { font-weight: 500; font-size: 0.7rem; color: var(--text-dim); }
.trend-card .spark { height: 30px; }
.trend-card .tc-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }

/* directional delta chip */
.delta { font-size: 0.78rem; font-weight: 650; font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 0.12rem; white-space: nowrap; }
.delta.up   { color: var(--success); }
.delta.down { color: var(--danger); }
.delta.flat { color: var(--text-dim); }
.pill-new { background: var(--accent-soft); color: #bcd6ff; border: 1px solid rgba(79,140,255,.35); border-radius: 999px; padding: 0.02rem 0.4rem; font-size: 0.66rem; font-weight: 700; letter-spacing: 0.03em; }

/* sentiment value coloring (tables / cards) */
.sent-val { font-variant-numeric: tabular-nums; font-weight: 600; }
.sent-val.is-bull { color: var(--success); }
.sent-val.is-bear { color: var(--danger); }
.sent-val.is-neutral { color: var(--text-muted); }

/* share-of-voice horizontal bars */
.sov-row { display: grid; grid-template-columns: 3.6rem 1fr 2.8rem; align-items: center; gap: 0.6rem; margin-bottom: 0.55rem; }
.sov-row:last-child { margin-bottom: 0; }
.sov-sym { font-weight: 650; font-size: 0.85rem; }
.sov-track { display: block; height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.sov-fill  { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; }
.sov-pct   { text-align: right; font-size: 0.78rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.sov-more  { color: var(--text-dim); font-size: 0.78rem; font-style: italic; margin-top: 0.6rem; }

/* bull/bear split bar (leaderboard) */
.share-bar { display: inline-flex; height: 7px; width: 5.5rem; border-radius: 999px; overflow: hidden; background: var(--surface-3); vertical-align: middle; }
.share-bar .b-bull { background: var(--success); }
.share-bar .b-bear { background: var(--danger); }

/* ranked insight lists (most bullish / bearish / fastest rising) */
.rank-list { display: flex; flex-direction: column; }
.rank-row { display: flex; align-items: center; gap: 0.55rem; padding: 0.45rem 0.35rem; border-radius: var(--radius-xs); text-decoration: none; color: var(--text); border-bottom: 1px solid var(--border); }
.rank-row:last-child { border-bottom: none; }
.rank-row:hover { background: var(--surface-hover); text-decoration: none; color: var(--text); }
.rank-row .r-rank { color: var(--text-dim); font-variant-numeric: tabular-nums; width: 1.2rem; text-align: right; font-size: 0.8rem; }
.rank-row .r-sym  { font-weight: 650; min-width: 3.4rem; }
.rank-row .r-co   { color: var(--text-dim); font-size: 0.75rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-row .r-val  { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 0.86rem; }

/* leaderboard clickable rows */
.lead-table tbody tr { cursor: pointer; }
.lead-rank { color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ------------------------ 9. tabs / opportunity score / orientation split ---- */
/* server-side tab strip (underline style — distinct from the pill btn-group window selectors) */
.tab-strip {
    display: flex; gap: 0.2rem; flex-wrap: wrap;
    border-bottom: 1px solid var(--border); margin-bottom: 1.1rem;
}
.tab-btn {
    appearance: none; background: transparent; border: none; color: var(--text-muted);
    font-size: 0.86rem; font-weight: 600; padding: 0.5rem 0.9rem;
    border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer;
    transition: color .12s ease, border-color .12s ease;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent-2); border-bottom-color: var(--accent); }

/* opportunity score badge + letter grade (a Reddit-discussion signal, not advice) */
.opp-score {
    display: inline-flex; align-items: baseline; gap: 0.3rem;
    font-variant-numeric: tabular-nums; font-weight: 700;
    padding: 0.12rem 0.5rem; border-radius: var(--radius-xs);
    border: 1px solid var(--border); background: var(--surface-3);
}
.opp-score .opp-num { font-size: 1rem; }
.opp-score .opp-grade { font-size: 0.72rem; font-weight: 800; opacity: 0.85; }
.opp-a { border-color: rgba(63,185,80,.45);  color: var(--success);  background: var(--success-soft); }
.opp-b { border-color: rgba(79,140,255,.4);  color: var(--accent-2); background: var(--accent-soft); }
.opp-c { border-color: rgba(242,193,78,.4);  color: var(--warning);  background: var(--warning-soft); }
.opp-d, .opp-f { color: var(--text-muted); }

/* factor breakdown mini-bars (why a ticker scores the way it does) */
.factor { display: grid; grid-template-columns: 7.5rem 1fr 2.6rem; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.factor:last-child { margin-bottom: 0; }
.factor-label { font-size: 0.78rem; color: var(--text-muted); }
.factor-track { display: block; height: 7px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.factor-fill  { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; }
.factor-val   { text-align: right; font-size: 0.78rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* signal flag chips */
.flag { display: inline-block; padding: 0.05rem 0.45rem; border-radius: 999px; font-size: 0.66rem; font-weight: 700; letter-spacing: 0.02em; border: 1px solid transparent; margin-right: 0.25rem; }
.flag-rising     { background: var(--success-soft); color: #8de29a; border-color: rgba(63,185,80,.3); }
.flag-conviction { background: var(--accent-soft);  color: #bcd6ff; border-color: rgba(79,140,255,.35); }
.flag-euphoric   { background: var(--warning-soft); color: var(--warning); border-color: rgba(242,193,78,.3); }
.flag-thin       { background: var(--surface-3);    color: var(--text-dim); }
.flag-extended   { background: var(--surface-3);    color: var(--text-muted); }
.flag-coiled     { background: var(--accent-soft);  color: #bcd6ff; border-color: rgba(79,140,255,.35); }
.flag-caution    { background: var(--danger-soft);  color: #ffb0ac; border-color: rgba(255,107,102,.4); white-space: nowrap; }
.flag-caution i  { font-size: 0.62rem; margin-right: 0.1rem; }

.caution-callout { display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.55rem 0.75rem; border-radius: 0.5rem;
                   background: var(--danger-soft); border: 1px solid rgba(255,107,102,.35); color: #ffb0ac; font-size: 0.82rem; }
.caution-callout i { color: var(--danger); margin-top: 0.1rem; }
.caution-callout b, .caution-callout strong { color: #ffc9c6; }

/* orientation split bar: forward / backward / position / none (categorical, not bull/bear) */
.ori-bar { display: inline-flex; height: 7px; width: 6.5rem; border-radius: 999px; overflow: hidden; background: var(--surface-3); vertical-align: middle; }
.ori-bar .o-fwd  { background: var(--accent); }
.ori-bar .o-back { background: var(--warning); }
.ori-bar .o-pos  { background: var(--accent-2); }
.ori-bar .o-none { background: var(--surface-hover); }

/* compact stat (per-ticker "by the numbers" grid) */
.mini-stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 0.5rem 0.7rem; height: 100%; }
.mini-stat .mini-label { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); }
.mini-stat .mini-value { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 0.1rem; }
.mini-stat .mini-value.is-bull { color: var(--success); }
.mini-stat .mini-value.is-bear { color: var(--danger); }
.mini-stat .mini-value.is-neutral { color: var(--text-muted); }

/* orientation legend */
.ori-key { display: inline-flex; align-items: center; gap: 0.3rem; margin-right: 0.9rem; }
.ori-key .dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.ori-key .dot.o-fwd  { background: var(--accent); }
.ori-key .dot.o-back { background: var(--warning); }
.ori-key .dot.o-pos  { background: var(--accent-2); }
.ori-key .dot.o-none { background: var(--surface-hover); }

/* ---- Reddit Crawlers ---- */

/* sort toggle chips (hot/new/top/rising/controversial) */
.chip-row { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
.sort-chip {
    border: 1px solid var(--border); background: var(--surface-3); color: var(--text-dim);
    border-radius: 999px; padding: 0.1rem 0.55rem; font-size: 0.72rem; font-weight: 600;
    cursor: pointer; transition: all 0.12s ease; text-transform: lowercase;
}
.sort-chip:hover { color: var(--text); border-color: var(--text-dim); }
.sort-chip.on {
    background: var(--accent-soft); color: var(--accent-2); border-color: rgba(79, 140, 255, 0.45);
}
.badge-sort {
    display: inline-block; background: var(--surface-3); color: var(--text-muted);
    border: 1px solid var(--border); border-radius: var(--radius-xs);
    padding: 0.04rem 0.4rem; font-size: 0.72rem; font-weight: 600;
}

/* enable/disable pill toggle */
.toggle-pill {
    width: 34px; height: 18px; border-radius: 999px; border: 1px solid var(--border);
    background: var(--surface-3); position: relative; cursor: pointer; padding: 0; transition: background 0.15s ease;
}
.toggle-pill span {
    position: absolute; top: 1px; left: 1px; width: 14px; height: 14px; border-radius: 50%;
    background: var(--text-dim); transition: transform 0.15s ease, background 0.15s ease;
}
.toggle-pill.on { background: var(--accent-soft); border-color: rgba(79, 140, 255, 0.45); }
.toggle-pill.on span { transform: translateX(16px); background: var(--accent); }
.row-off td { opacity: 0.55; }

/* numeric depth inputs */
.depth-input { width: 4.2rem; display: inline-block; text-align: center; }

/* add-target form row */
.add-target { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 0.9rem; }
.add-target .add-name { width: 13rem; }
.add-target .add-num {
    display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.72rem;
    color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600;
}

/* backfill depth bar */
.depth-bar { display: block; height: 7px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.depth-bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.depth-label { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.72rem; color: var(--text-muted); margin-top: 0.2rem; }
.badge-end {
    background: var(--success-soft, rgba(63,185,80,.15)); color: #8de29a;
    border-radius: var(--radius-xs); padding: 0.02rem 0.35rem; font-size: 0.64rem; font-weight: 700;
}

/* ---- Score Builder ---- */

/* profile bar: pick + name + description + actions on one wrapping row */
.profile-bar {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.6rem 0.9rem;
}
.profile-pick { width: 16rem; }
.profile-name { width: 12rem; }
.profile-desc { flex: 1 1 16rem; min-width: 12rem; }
.profile-actions { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-left: auto; }

/* knob editor: groups laid out in a responsive grid */
.knob-grid {
    display: grid; gap: 1rem 1.4rem;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
}
.knob-group { display: flex; flex-direction: column; gap: 0.55rem; }
.knob-group-head {
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; font-weight: 700;
    color: var(--text-dim); padding-bottom: 0.2rem; border-bottom: 1px solid var(--border);
}
.knob { display: flex; flex-direction: column; gap: 0.2rem; }
.knob-head { display: flex; align-items: center; gap: 0.35rem; font-size: 0.78rem; color: var(--text); }
.knob-label { font-weight: 600; }
.knob-val { margin-left: auto; color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 0.74rem; }
.knob-inputs { display: flex; align-items: center; gap: 0.5rem; }
.knob-inputs .form-range { flex: 1 1 auto; }
.knob-num { width: 4.6rem; text-align: center; flex: 0 0 auto; }

/* editing-vs-active compare strip */
.compare-row { display: grid; gap: 0.8rem; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); }
.compare-cell {
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 0.6rem 0.8rem;
}
.compare-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-dim); }
.compare-value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.compare-delta { font-size: 0.72rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* auto-tune control row */
.auto-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.6rem 0.9rem; }
.auto-field { width: 13rem; }
.auto-field.auto-narrow { width: 7rem; }
.auto-actions { margin-left: auto; align-self: flex-end; }

/* profile manager modal */
.modal-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(8, 10, 14, 0.62); backdrop-filter: blur(3px);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 4vh 1rem; overflow-y: auto;
}
.modal-panel {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
    width: 100%; max-width: 38rem; display: flex; flex-direction: column;
}
.modal-panel.modal-wide { max-width: 64rem; }
.modal-head {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
    padding: 1rem 1.2rem; border-bottom: 1px solid var(--border);
}
.modal-body { padding: 0.6rem 1.2rem; overflow-x: auto; }
.modal-foot {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0.8rem 1.2rem; border-top: 1px solid var(--border);
}
.btn-close-x {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    font-size: 1rem; line-height: 1; padding: 0.2rem 0.35rem; border-radius: var(--radius-sm);
}
.btn-close-x:hover { color: var(--text); background: var(--surface-hover); }
.mgr-table .tnum { font-variant-numeric: tabular-nums; }
.mgr-table tbody tr.is-selected { background: var(--surface-hover); }
.tnum { font-variant-numeric: tabular-nums; }

/* experts trail */
.cohort-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.6rem 1.2rem; }
.cohort-controls > label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-dim); }
.cohort-controls input[type=number] { width: 7rem; }
.cohort-summary { margin-left: auto; align-self: center; font-size: 0.82rem; color: var(--text-muted); }
.expert-calls { padding: 0.35rem 0.15rem 0.15rem; }
.expert-calls .call-text { color: var(--text-muted); max-width: 34rem; }
.badge-mini { display: inline-block; font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding: 0.05rem 0.35rem; border-radius: 999px; border: 1px solid var(--border); }
.badge-mini.is-bull { color: var(--success); border-color: color-mix(in srgb, var(--success) 45%, transparent); }
.badge-mini.is-bear { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.badge-mini.is-neutral { color: var(--text-dim); }
