:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --surface-3: #e7e6e1;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --grid: #e9e8e3;
  --axis: #c9c8c2;
  --leader: #d6d5cf;
  --frontier: #0b0b0b;
  --accent: #2a78d6;
  --live: #0ca30c;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --s-other: #8f8e88;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0b0a;
    --surface: #131312;
    --surface-2: #1d1d1b;
    --surface-3: #282826;
    --border: #262624;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8d8c85;
    --grid: #222220;
    --axis: #3a3a37;
    --leader: #31312e;
    --frontier: #f0efec;
    --accent: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
    --s-other: #8d8c85;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b0a;
  --surface: #131312;
  --surface-2: #1d1d1b;
  --surface-3: #282826;
  --border: #262624;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #8d8c85;
  --grid: #222220;
  --axis: #3a3a37;
  --leader: #31312e;
  --frontier: #f0efec;
  --accent: #3987e5;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
  --s-other: #8d8c85;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--text-3); font-weight: 400; }
.logo { display: inline-block; flex: none; color: var(--text); vertical-align: middle; }
.mono {
  display: inline-grid; place-items: center; flex: none; border-radius: 50%;
  background: var(--surface-3); color: var(--text-2); font-size: 8px; font-weight: 700; letter-spacing: -0.02em;
}

/* header */
.topbar {
  display: flex; gap: 16px 24px; align-items: flex-start; justify-content: space-between;
  padding: 22px 24px 10px; max-width: 1600px; margin: 0 auto;
}
.title h1 { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.title .sub { margin: 6px 0 0; color: var(--text-2); max-width: 78ch; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.live {
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 5px 12px; font-size: 12px; color: var(--text-2);
}
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 0 var(--live); animation: pulse 2.4s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 60%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end;
  padding: 6px 24px 14px; max-width: 1600px; margin: 0 auto;
}
.ctl { display: inline-flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-3); }
.ctl.inline { flex-direction: row; align-items: center; gap: 8px; }
select, input[type="search"], input[type="number"], input:not([type]) {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; min-height: 34px; color: var(--text); font-size: 14px;
}
select { padding-right: 28px; }
select:focus-visible, input:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 6px 12px; min-height: 32px; cursor: pointer; color: var(--text-2); white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); font-weight: 600; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; color: var(--text-2); }
.icon-btn:hover { color: var(--text); }

/* layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px;
  padding: 0 24px 16px; max-width: 1600px; margin: 0 auto;
}
.chart-card, .panel, .table-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.chart-card { position: relative; padding: 12px 8px 10px; min-width: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0 10px 2px; flex-wrap: wrap; }
.status { color: var(--text-3); font-size: 12px; }
.status strong { color: var(--text-2); font-weight: 600; }
.status.error { color: #d03b3b; }
.chart-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.ghost-btn { background: none; border: 1px solid transparent; border-radius: 6px; color: var(--text-2); cursor: pointer; padding: 3px 8px; font-size: 12px; }
.ghost-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.chart { width: 100%; height: clamp(460px, 74vh, 860px); }
.chart svg { display: block; width: 100%; height: 100%; touch-action: none; font-family: "DM Sans", system-ui, sans-serif; }
.hint { margin: 2px 10px 0; color: var(--text-3); font-size: 12px; }
.cost-note { margin: 2px 10px 6px; color: var(--text-2); font-size: 12px; line-height: 1.5; max-width: 78ch; }
.cost-note a { color: var(--accent); white-space: nowrap; }
.cost-note:empty { display: none; }

/* chart internals */
.grid line { stroke: var(--grid); }
.grid-x line { stroke-dasharray: 2 4; }
.grid .domain { display: none; }
.axis text { fill: var(--text-3); font-size: 12px; }
.axis .domain { stroke: var(--axis); }
.axis line { stroke: var(--axis); }
.axis-title { fill: var(--text-3); font-size: 12px; }
.series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; transition: opacity 150ms; }
.pt { stroke: var(--surface); stroke-width: 2; transition: opacity 150ms; }
.pt.front { stroke-width: 2.5; }
.halo { fill: var(--frontier); opacity: 0.08; pointer-events: none; transition: opacity 150ms; }
.frontier-line { fill: none; stroke: var(--frontier); stroke-width: 1.5; stroke-dasharray: 6 4; opacity: 0.7; }
.frontier-area { fill: var(--frontier); opacity: 0.035; }
.frontier-tag { fill: var(--text-3); font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.leader { stroke: var(--leader); stroke-width: 1; fill: none; transition: opacity 150ms, stroke 150ms; }
.leader.hl { stroke: var(--text-3); }
.lbl { cursor: pointer; transition: opacity 150ms; }
.lbl .lbl-name { fill: var(--text-2); font-size: 13px; font-weight: 600; }
.lbl .lbl-bg { fill: transparent; }
.lbl:hover .lbl-name, .lbl.hl .lbl-name { fill: var(--text); }
.lbl:hover .lbl-bg, .lbl.hl .lbl-bg { fill: var(--surface-2); }
.lbl .logo-use { color: var(--text); }
.dim { opacity: 0.12; }
.lbl.dim { opacity: 0.3; }
.effort-lbl { fill: var(--text); font-size: 11px; font-weight: 600; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; pointer-events: none; }
.guide { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.readout rect { fill: var(--text); }
.readout text { fill: var(--surface); font-size: 11px; font-weight: 600; }
.hover-ring { fill: none; stroke: var(--text); stroke-width: 2; pointer-events: none; }
.custom-pt { stroke: var(--text); stroke-width: 2; fill: var(--surface); }
.empty-msg { fill: var(--text-3); font-size: 14px; }

/* tooltip */
.tooltip {
  position: absolute; pointer-events: none; z-index: 10;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 12px 14px; width: 270px; font-size: 13px;
}
.tooltip.pinned { pointer-events: auto; border-color: var(--axis); }
.tt-head { display: flex; align-items: center; gap: 8px; }
.tt-name { font-weight: 700; font-size: 14px; line-height: 1.25; }
.tt-sw { width: 4px; align-self: stretch; border-radius: 2px; flex: none; }
.tt-sub { color: var(--text-3); font-size: 12px; margin: 2px 0 8px; }
.tooltip dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; }
.tooltip dt { color: var(--text-3); }
.tooltip dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); font-weight: 500; }
.tt-flag { margin-top: 8px; font-size: 12px; color: var(--text-2); display: flex; gap: 6px; align-items: baseline; }
.tt-flag b { font-weight: 600; color: var(--text); }
.tt-note { margin-top: 8px; font-size: 12px; color: var(--text-3); border-top: 1px solid var(--border); padding-top: 8px; }
.tt-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
.tt-actions button, .tt-actions a {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 6px;
  padding: 3px 8px; font-size: 12px; cursor: pointer; text-decoration: none;
}
.tt-actions a { margin-left: auto; color: var(--accent); }
.tt-hint { margin-top: 8px; color: var(--text-3); font-size: 11px; }
.tooltip.pinned .tt-hint { display: none; }
.tooltip:not(.pinned) .tt-actions { display: none; }

/* panel */
.panel { display: flex; flex-direction: column; min-height: 0; max-height: calc(74vh + 64px); position: sticky; top: 12px; align-self: start; overflow: hidden; }
.panel-head { padding: 14px 14px 10px; display: grid; gap: 10px; border-bottom: 1px solid var(--border); }
.panel-title { display: flex; align-items: baseline; justify-content: space-between; }
.panel-head h2 { font-size: 15px; margin: 0; font-weight: 700; }
.panel-head input[type="search"] { width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 3px 10px; cursor: pointer; font-size: 12px; color: var(--text-2); }
.chips button:hover { background: var(--surface-2); color: var(--text); }
.model-list { list-style: none; margin: 0; padding: 4px 0 8px; overflow-y: auto; flex: 1; min-height: 120px; }
.prov { border-bottom: 1px solid var(--border); }
.prov:last-child { border-bottom: 0; }
.prov-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 12px; }
.prov-toggle { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; background: none; border: 0; cursor: pointer; padding: 2px 0; text-align: left; }
.prov-toggle .chev { color: var(--text-3); transition: transform 150ms; flex: none; }
.prov[data-open="true"] .chev { transform: rotate(90deg); }
.prov-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prov-count { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.prov-all { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 12px; padding: 2px 4px; }
.prov-models { list-style: none; margin: 0; padding: 0 0 6px; }
.prov[data-open="false"] .prov-models { display: none; }
.model-row { position: relative; }
.model-row label { display: grid; grid-template-columns: 16px 10px 1fr auto; gap: 8px; align-items: center; padding: 4px 12px 4px 14px; cursor: pointer; }
.model-row label:hover, .model-row.hl label { background: var(--surface-2); }
.model-row input { margin: 0; accent-color: var(--accent); }
.model-row .sw { width: 10px; height: 10px; border-radius: 50%; }
.model-row .nm { min-width: 0; }
.model-row .nm b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-row .nm small { display: block; color: var(--text-3); font-size: 11px; }
.model-row .meta { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
.model-row .only {
  position: absolute; right: 64px; top: 50%; transform: translateY(-50%);
  display: none; border: 1px solid var(--border); background: var(--surface); border-radius: 6px;
  font-size: 11px; padding: 1px 6px; cursor: pointer; color: var(--text-2);
}
.model-row:hover .only, .model-row .only:focus-visible { display: block; }
.model-row.off .nm b { color: var(--text-2); }
.empty { padding: 16px 14px; color: var(--text-3); }

.custom { border-top: 1px solid var(--border); padding: 10px 14px 14px; }
.custom summary { cursor: pointer; color: var(--text-2); font-weight: 600; }
.custom form { display: grid; gap: 8px; margin-top: 10px; }
.custom label { display: grid; gap: 2px; font-size: 12px; color: var(--text-3); }
.custom input { width: 100%; }
.custom .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.custom button[type="submit"] { border: 0; border-radius: 8px; padding: 8px; background: var(--text); color: var(--surface); cursor: pointer; font-weight: 600; }
.custom-list { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 4px; }
.custom-list li { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.custom-list button { background: none; border: 0; color: var(--text-3); cursor: pointer; }

/* The table sits under the chart in the left column, and the sticky model panel spans both
   rows, so it follows you down the page beside the table instead of floating over it. */
.panel { grid-column: 2; grid-row: 1 / span 2; }
.table-card { grid-column: 1; padding: 10px 14px; min-width: 0; }
.table-card summary { cursor: pointer; font-weight: 600; }
.table-wrap { overflow-x: auto; margin-top: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-3); font-weight: 500; cursor: pointer; user-select: none; }
td.num, th.num { text-align: right; }
td .cell-model { display: inline-flex; align-items: center; gap: 8px; }

.foot { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; padding: 8px 16px 28px; color: var(--text-3); font-size: 12px; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; padding: 0 16px 16px; }
  .topbar { padding: 16px 16px 8px; }
  .toolbar { padding: 4px 16px 12px; }
  .panel { position: static; max-height: 520px; grid-column: auto; grid-row: auto; }
  .table-card { grid-column: auto; }
  .chart { height: 540px; }
}
@media (max-width: 560px) {
  .title h1 { font-size: 20px; }
  .seg button { padding: 6px 9px; font-size: 13px; }
  .chart { height: 460px; }
  .live #live-text { display: none; }
  .tooltip { width: min(270px, calc(100% - 16px)); }
}
@media (forced-colors: active) {
  .series-line, .frontier-line { stroke: CanvasText; }
}
