:root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1a2028;
    --border: #30363d;
    --text: #c9d1d9;
    --text-dim: #8b949e;
    --text-faint: #6e7681;
    --green: #3fb950;
    --yellow: #d29922;
    --red: #f85149;
    --blue: #58a6ff;
    /* GFS gets its own hue distinct from HRRR's yellow and any status color */
    --orange: #ff8c42;
    --now-gray: #8b949e;
    --mono: 'Consolas', 'Monaco', 'Courier New', monospace;
    --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { overflow-x: hidden; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.5;
    max-width: 1280px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 8px 0 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    flex-wrap: wrap;
}

header h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }

.live-meta {
    display: flex;
    align-items: baseline;
    gap: 10px;
    font-size: 12px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
    flex-wrap: wrap;
}

.live-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 0 rgba(63, 185, 80, 0.7);
    animation: live-pulse 2s ease-out infinite;
    flex: 0 0 auto;
    transform: translateY(-1px);
}

@keyframes live-pulse {
    0%   { box-shadow: 0 0 0 0   rgba(63, 185, 80, 0.55); }
    70%  { box-shadow: 0 0 0 8px rgba(63, 185, 80, 0);    }
    100% { box-shadow: 0 0 0 0   rgba(63, 185, 80, 0);    }
}

.clock {
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    letter-spacing: 0.02em;
    /* "HH:MM:SS UTC" is always 12 glyphs; reserve the width so tabular digits
       can't nudge later elements as the seconds tick. */
    min-width: 10ch;
    display: inline-block;
    text-align: left;
}

/* Countdown and freshness share the sans font + tabular digits so they read
   as a matched pair next to the (mono) clock instead of two different looks. */
.countdown,
.freshness {
    font-family: var(--sans);
    font-variant-numeric: tabular-nums;
    display: inline-block;
    text-align: left;
}

.countdown {
    color: var(--text-dim);
    min-width: 8ch;
}

.freshness {
    color: var(--text-faint);
    min-width: 12ch;
}

.reload-btn {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top));
    right: calc(10px + env(safe-area-inset-right));
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    transition: border-color 120ms ease, transform 100ms ease;
}
.reload-btn:hover { border-color: var(--blue); }
.reload-btn:active { transform: scale(0.92); }

@media (max-width: 600px) {
    .reload-btn {
        width: 44px;
        height: 44px;
        top: calc(8px + env(safe-area-inset-top));
        right: calc(8px + env(safe-area-inset-right));
        font-size: 22px;
    }
    /* Keep the header title from sliding under the button on narrow widths */
    header h1 { padding-right: 56px; }
}

.banner {
    background: #3d1f00;
    border: 1px solid var(--yellow);
    color: var(--yellow);
    padding: 8px 16px;
    border-radius: 4px;
    margin-bottom: 16px;
    font-size: 13px;
}

.hidden { display: none !important; }

section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 16px;
    margin-bottom: 16px;
}

section h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

/* Hero: System Status gets a subtle emphasis */
section.hero {
    background: var(--surface-2);
    border-color: #3b4650;
    padding: 20px;
}

section.hero h2 {
    color: var(--text);
    font-size: 15px;
    margin-bottom: 14px;
}

/* Demoted sections are less visually loud */
section.demoted {
    background: transparent;
    border-color: var(--border);
    padding: 12px 16px;
    opacity: 0.85;
}

section.demoted h2 {
    font-size: 11px;
    margin-bottom: 8px;
    color: var(--text-faint);
}

/* Status cards */
.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
}

.status-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--text-faint);
    border-radius: 4px;
    padding: 10px 12px;
    cursor: pointer;
    transition: border-color 120ms ease;
    min-width: 0;
}

.status-card:hover { border-color: var(--blue); }
.status-card.healthy { border-left-color: var(--green); }
.status-card.degraded { border-left-color: var(--yellow); }
.status-card.down { border-left-color: var(--red); }
.status-card.active {
    border-color: var(--blue);
    background: var(--surface-2);
}

.sc-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.sc-head .name {
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 0.3px;
}

.sc-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

.sc-meta .age {
    color: var(--text);
    font-weight: 500;
    /* single-unit form: widest expected is "99m ago" / "23h ago" ≈ 7 chars */
    min-width: 7ch;
    display: inline-block;
    text-align: left;
}
.sc-meta .stat { font-size: 11px; color: var(--text-faint); }

.dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--text-faint);
    flex: 0 0 auto;
}

.dot.healthy { background: var(--green); box-shadow: 0 0 6px rgba(63, 185, 80, 0.4); }
.dot.degraded { background: var(--yellow); }
.dot.down { background: var(--red); box-shadow: 0 0 6px rgba(248, 81, 73, 0.4); }

.detail-box {
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 12px;
    white-space: pre-line;
    overflow-x: auto;
}

/* Inline metrics (demoted current model) */
.inline-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
}

.inline-metrics > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.inline-metrics dt {
    font-size: 10px;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.inline-metrics dd { font-size: 15px; font-weight: 500; }

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

/* Kalshi vs HRRR comparison */
.comparison-legend {
    display: flex;
    gap: 16px;
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.legend-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.swatch-bar {
    display: inline-block;
    width: 18px;
    height: 10px;
    background: linear-gradient(to right, rgba(88, 166, 255, 0.2), rgba(88, 166, 255, 1));
    border-radius: 1px;
}
.swatch-hrrr, .swatch-gfs, .swatch-obs, .swatch-now {
    display: inline-block;
    width: 10px;
    height: 12px;
    position: relative;
}
.swatch-hrrr::after,
.swatch-gfs::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 0; bottom: 0;
    width: 2px;
    margin-left: -1px;
}
.swatch-hrrr::after { background: var(--yellow); }
.swatch-gfs::after {
    background: repeating-linear-gradient(
        to bottom, var(--orange) 0 3px, transparent 3px 5px);
}
.swatch-obs::after {
    content: "";
    position: absolute;
    left: 50%; top: 50%;
    width: 8px; height: 8px;
    margin: -4px 0 0 -4px;
    background: var(--green);
    border-radius: 50%;
    box-shadow: 0 0 4px rgba(63, 185, 80, 0.6);
}
.swatch-now::after {
    content: "";
    position: absolute;
    left: 50%; top: 50%;
    width: 6px; height: 6px;
    margin: -3px 0 0 -3px;
    border: 1.5px solid var(--now-gray);
    border-radius: 50%;
    background: transparent;
}

.comparison-row {
    display: grid;
    grid-template-columns: 56px 1fr 160px;
    gap: 12px;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}
.comparison-row:last-child { border-bottom: none; }

.comparison-station {
    font-family: var(--mono);
    font-weight: 600;
    color: var(--text);
}

.comparison-strip {
    position: relative;
    height: 22px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.comparison-bucket {
    position: absolute;
    top: 0;
    bottom: 0;
    color: var(--bg);
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.bucket-label {
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}
.comparison-marker {
    position: absolute;
    top: -3px;
    bottom: -3px;
    width: 2px;
    margin-left: -1px;
    z-index: 3;
    pointer-events: none;
}
.comparison-marker.hrrr  {
    background: var(--yellow);
    box-shadow: 0 0 6px rgba(210, 153, 34, 0.75);
}
.comparison-marker.gfs {
    background: repeating-linear-gradient(
        to bottom, var(--orange) 0 3px, transparent 3px 6px);
}
.comparison-marker.obs {
    /* A filled dot instead of a line — "we already hit this" signal */
    background: transparent;
    width: 10px; height: 10px;
    margin-left: -5px;
    top: 50%; bottom: auto;
    transform: translateY(-50%);
    border-radius: 50%;
    background-color: var(--green);
    box-shadow: 0 0 6px rgba(63, 185, 80, 0.7);
    z-index: 4;
}
.comparison-marker.now {
    background: transparent;
    width: 8px; height: 8px;
    margin-left: -4px;
    top: 50%; bottom: auto;
    transform: translateY(-50%);
    border: 1.5px solid var(--now-gray);
    border-radius: 50%;
    z-index: 4;
}

.comparison-stats {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px 6px;
    text-align: right;
}
.cmp-hrrr   { color: var(--yellow); }
.cmp-gfs    { color: var(--orange); }
.cmp-obs    { color: var(--green); }
.cmp-kalshi { color: var(--blue); }

.comparison-axis {
    display: flex;
    justify-content: space-between;
    padding: 6px 0 0;
    margin-left: 68px;   /* align with strip start (station col + gap) */
    margin-right: 152px; /* align with strip end  (stats col + gap) */
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text-faint);
    border-top: none;
}

@media (max-width: 600px) {
    .comparison-row {
        grid-template-columns: 42px 1fr;
        grid-template-rows: auto auto;
        gap: 4px 8px;
        row-gap: 2px;
    }
    .comparison-station { grid-column: 1; grid-row: 1 / span 2; align-self: center; }
    .comparison-strip   { grid-column: 2; grid-row: 1; }
    .comparison-stats   {
        grid-column: 2; grid-row: 2;
        grid-template-columns: repeat(4, auto);
        justify-content: flex-start;
        font-size: 10px;
        text-align: left;
        gap: 8px;
    }
    .bucket-label { display: none; }  /* tiny cells too cramped */
    .comparison-axis { margin-left: 50px; margin-right: 0; }
    .comparison-legend { font-size: 10px; gap: 10px; }
}

/* Charts */
.charts-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.chart-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px;
    min-width: 0;
}

.chart-title {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-bottom: 4px;
    text-align: center;
}

.chart-wrap {
    position: relative;
    height: 90px;
}

.empty-state {
    padding: 20px 12px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
    background: var(--bg);
    border: 1px dashed var(--border);
    border-radius: 4px;
}

/* Live trades feed */
#live-trades-section h2 .hint {
    color: var(--text-faint);
    font-size: 11px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    margin-left: 4px;
}
#live-trades-table {
    table-layout: auto;
}
#live-trades-table td.when {
    font-family: var(--mono);
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    width: 70px;
}
#live-trades-table td.market {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text);
}
#live-trades-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
#live-trades-table td.price { color: var(--blue); font-weight: 600; }
#live-trades-table td.size { color: var(--text-dim); }
#live-trades-table td.side-yes { color: var(--green); font-weight: 600; }
#live-trades-table td.side-no  { color: var(--red); font-weight: 600; }

/* Cap the feed height; scroll within so the rest of the page stays put. */
#live-trades-section .table-wrap {
    max-height: 360px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
}
#live-trades-table thead {
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}
#live-trades-table thead th { background: var(--surface); }

@media (max-width: 600px) {
    #live-trades-table td.when { width: 50px; font-size: 11px; }
    #live-trades-table td.market { font-size: 11px; }
    #live-trades-section .table-wrap { max-height: 280px; }
}

/* Tables */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text-dim);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    white-space: nowrap;
}

td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    font-family: var(--mono);
    font-size: 12px;
}

td.reason {
    font-family: var(--sans);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

td.loading {
    text-align: center;
    color: var(--text-dim);
    font-family: var(--sans);
}

.decision-promoted { color: var(--green); font-weight: 600; }
.decision-rejected { color: var(--red); font-weight: 600; }

.collapse-btn {
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0;
}

.collapse-btn:hover { color: var(--blue); }

.skeleton { opacity: 0.4; }

#kalshi-summary {
    padding: 8px 0 12px;
    color: var(--text-dim);
    font-size: 12px;
}

footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    color: var(--text-faint);
    font-size: 11px;
    border-top: 1px solid var(--border);
}

/* Tablet: drop charts from 4 to 2 columns */
@media (max-width: 900px) {
    .charts-row { grid-template-columns: repeat(2, 1fr); }
}

/* Mobile */
@media (max-width: 600px) {
    body {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        font-size: 14px;
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        padding: 4px 0 10px;
    }

    header h1 { font-size: 17px; padding-right: 56px; }

    .live-meta {
        gap: 8px;
        font-size: 11px;
    }

    .clock { font-size: 12px; }

    section {
        padding: 12px;
        margin-bottom: 12px;
    }

    section.hero { padding: 14px; }

    section h2 { margin-bottom: 10px; }

    /* Status cards: full-width stack */
    .status-grid { grid-template-columns: 1fr; gap: 8px; }

    .status-card { padding: 10px 12px; }

    .sc-meta { flex-direction: row; flex-wrap: wrap; gap: 8px; align-items: baseline; }
    .sc-meta .stat::before { content: "·"; color: var(--text-faint); margin-right: 6px; }

    /* Charts: single column, a bit taller so they're legible */
    .charts-row { grid-template-columns: 1fr; gap: 10px; }
    .chart-wrap { height: 80px; }

    .inline-metrics { grid-template-columns: repeat(2, 1fr); }
    .inline-metrics dd { font-size: 14px; }

    td.reason { max-width: 180px; }

    footer { flex-direction: column; gap: 4px; }
}

/* ============================== Tab nav ============================== */
.tabs {
    display: flex;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 200px;
}
.tab {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid transparent;
    border-bottom: 2px solid transparent;
    padding: 6px 14px;
    cursor: pointer;
    font: 600 14px var(--sans);
    border-radius: 6px 6px 0 0;
    transition: color 120ms, border-color 120ms, background 120ms;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active {
    color: var(--text);
    background: var(--surface);
    border-color: var(--border);
    border-bottom-color: var(--blue);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* =========================== Paper trading =========================== */
#paper-leaderboard .strategy-name {
    font-weight: 600;
    margin-right: 6px;
}
#paper-leaderboard .strategy-key,
#paper-fills-table .strategy-key {
    color: var(--text-faint);
    font-family: var(--mono);
    font-size: 12px;
}
.strategy-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    margin-right: 7px;
    vertical-align: middle;
}
.pnl-pos { color: var(--green); }
.pnl-neg { color: var(--red); }
#paper-pnl-section .chart-wrap,
#paper-daily-section .chart-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
}
#paper-fills-table .when { color: var(--text-dim); white-space: nowrap; }
#paper-fills-table .market { color: var(--text); }
.maker-pill,
.taker-pill {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 11px;
    line-height: 1.5;
}
.maker-pill { background: rgba(63, 185, 80, 0.15); color: var(--green); }
.taker-pill { background: rgba(248, 81, 73, 0.15); color: var(--red); }
.small { font-size: 12px; }
.empty-cell {
    color: var(--text-dim);
    text-align: center;
    padding: 18px 0;
}
@media (max-width: 600px) {
    #paper-leaderboard th, #paper-leaderboard td { font-size: 12px; padding: 4px 6px; }
    .tab { padding: 5px 10px; font-size: 13px; }
}

/* Clickable strategy rows */
.strategy-row { cursor: pointer; }
.strategy-row:hover { background: var(--surface-2); }
.strategy-row.selected { background: rgba(88, 166, 255, 0.10); }
.strategy-row.selected td:first-child { border-left: 3px solid var(--blue); }

/* Strategy detail panel */
#paper-detail-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    margin: 16px 0;
}
.paper-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 8px;
}
.paper-detail-header h2 { margin: 0; font-size: 15px; }
.link-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font: 12px var(--sans);
    padding: 0;
}
.link-btn:hover { color: var(--red); }
.paper-detail-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
}
.subtab {
    background: transparent;
    color: var(--text-dim);
    border: none;
    border-bottom: 2px solid transparent;
    padding: 5px 12px;
    cursor: pointer;
    font: 500 13px var(--sans);
}
.subtab:hover { color: var(--text); }
.subtab.active { color: var(--text); border-bottom-color: var(--blue); }
.subtab-panel { display: none; }
.subtab-panel.active { display: block; }
#paper-positions-table .num,
#paper-orders-table .num,
#paper-detail-fills-table .num { white-space: nowrap; }


