/* Quant Lab page (builds on site.css) */

:root {
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a;
  --accent: #1f4fd1; --accent-soft: #e8eefc;
  --muted-bar: #b9bcc6;
  --grid: #e8e8ec; --axis: #c9cbd3;
  --good: #006300; --warn: #9a5b00;
}
[data-theme="dark"] {
  --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  --accent: #7ea2ff; --accent-soft: #1d2640;
  --muted-bar: #4a4f5c;
  --grid: #262a34; --axis: #3a3f4c;
  --good: #3ec43e; --warn: #fab219;
}

.lab-hero { padding-top: 48px; padding-bottom: 8px; }
.lab-hero h1 { font-size: 44px; font-weight: 700; letter-spacing: -1px; margin-bottom: 14px; }
.lab-hero .bio { margin-bottom: 16px; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; }

.presets { padding-top: 20px; padding-bottom: 20px; }
.preset-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.preset-label { font-weight: 600; font-size: 14px; color: var(--muted); }
.preset-desc { color: var(--muted); font-size: 14.5px; margin-top: 10px; min-height: 1.6em; }

/* Layout */
.lab { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 24px; align-items: start; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px 20px; box-shadow: var(--shadow); min-width: 0;
}
.controls { line-height: 1.7; position: sticky; top: calc(var(--header-h) + 12px); max-height: calc(100vh - var(--header-h) - 24px); overflow-y: auto; }
.controls fieldset { border: 0; padding: 0; margin: 0 0 18px; min-width: 0; }
.controls legend { font: 600 15px var(--font-head); padding: 0; margin-bottom: 12px; }
.ctl { display: block; margin-bottom: 16px; font-size: 14px; line-height: 1.6; }
.ctl > span { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; color: var(--text); }
.ctl output { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.ctl input[type=range] { width: 100%; accent-color: var(--accent); margin: 0; }
.ctl select {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: 14px var(--font);
}
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 0 0 14px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.hint { font-size: 12.5px; color: var(--muted); margin: -4px 0 16px; line-height: 1.7; }
.controls .filters { margin-bottom: 10px; }
.controls .chip { padding: 5px 12px; font-size: 13px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row-between .hint { margin: 0; }
.run { width: 100%; justify-content: center; }
.center-text { text-align: center; margin: 10px 0 0; }
.muted { color: var(--muted); }

/* Results */
.results { display: grid; gap: 24px; min-width: 0; transition: opacity .2s; }
.results.busy .chart, .results.busy .kpis { opacity: .45; }
.status { line-height: 1.6; display: flex; align-items: center; gap: 14px; font-size: 13.5px; color: var(--muted); }
.status .bar { flex: 0 0 160px; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.status .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.status.done .bar i { background: var(--good); }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; transition: opacity .2s; }
.kpi {
  line-height: 1.6;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi-value { font: 600 26px var(--font-head); letter-spacing: -.5px; }
.kpi-sub { font-size: 12.5px; color: var(--muted); }
.kpi-sub.ok { color: var(--good); font-weight: 600; }
.kpi-sub.warn { color: var(--warn); font-weight: 600; }

.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; }
.panel h2 { font-size: 18px; font-weight: 600; }
.sub { color: var(--muted); font-size: 13.5px; margin: 4px 0 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg i { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.lg i.bar-key { width: 10px; height: 10px; border-radius: 2px; }

/* Charts */
.chart { position: relative; transition: opacity .2s; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.ax-grid { stroke: var(--grid); stroke-width: 1; }
.ax-base { stroke: var(--axis); stroke-width: 1; }
.ax-ref { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.ax-mark { stroke: var(--muted); stroke-width: 1; opacity: .5; }
.ax-cross { stroke: var(--muted); stroke-width: 1; }
.ax-text { fill: var(--muted); font: 12px var(--font); }
.ax-text.strong { fill: var(--text); font-size: 13px; }
.ax-val { fill: var(--text); font: 600 12px var(--font); font-variant-numeric: tabular-nums; }
.ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dot { stroke: var(--surface); stroke-width: 2; }
.chart-svg .hot { filter: brightness(1.15); }
.chart-svg rect:focus-visible { outline: none; stroke: var(--accent); stroke-width: 2; }
.chart-tip {
  line-height: 1.5;
  position: absolute; z-index: 5; pointer-events: none; min-width: 130px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-hover); padding: 8px 10px; font-size: 12.5px;
}
.chart-tip[hidden] { display: none; }
.tip-title { color: var(--muted); margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; }
.tip-row i { width: 12px; height: 3px; border-radius: 2px; flex-shrink: 0; }
.tip-row b { font-variant-numeric: tabular-nums; }
.tip-row span { color: var(--muted); }

/* Tables */
.table-view { margin-top: 12px; font-size: 14px; }
.table-view summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.table-wrap { max-height: 280px; overflow: auto; margin-top: 10px; border: 1px solid var(--border); border-radius: 10px; }
table.data, table.race { line-height: 1.5; width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.data th, .data td, .race th, .race td { padding: 7px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data th:first-child, .race th:first-child { text-align: left; font-weight: 500; }
.data thead th, .race thead th { position: sticky; top: 0; background: var(--surface); color: var(--muted); font-weight: 600; z-index: 1; }
.race-wrap { max-height: none; overflow-x: auto; border: 0; }
.race tr.best th, .race tr.best td { background: var(--accent-soft); }
.race .tag { margin-left: 8px; }
#race { margin-bottom: 6px; }

/* What-if */
#whatif { display: grid; grid-template-columns: 1.4fr 1fr; grid-template-areas: "s o" "s r"; grid-template-rows: auto 1fr; gap: 0 28px; }
#whatif .wi-sliders { grid-area: s; }
#whatif .wi-out { grid-area: o; }
#whatif > .btn { grid-area: r; justify-self: start; align-self: start; }
.wi-sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; margin-bottom: 6px; }
.wi-out { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin: 4px 0 14px; }
.wi-score { font: 600 30px var(--font-head); letter-spacing: -.5px; }
.wi-cap { font-size: 13px; color: var(--muted); }
.meter { position: relative; height: 8px; border-radius: 4px; background: var(--border); margin: 12px 0 8px; }
.meter b { position: absolute; top: 0; bottom: 0; left: 0; background: color-mix(in srgb, var(--muted) 45%, transparent); border-radius: 4px 0 0 4px; }
.meter b.right { left: auto; right: 0; background: var(--accent); border-radius: 0 4px 4px 0; opacity: .55; }
.meter i { position: absolute; top: -4px; width: 4px; height: 16px; margin-left: -2px; border-radius: 2px; background: var(--text); }

/* Explainer */
.lab-explain { padding-top: 56px; }
.steps { list-style: none; counter-reset: s; margin: 0 0 28px; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.steps li { counter-increment: s; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.steps li::before { content: counter(s); display: inline-flex; width: 28px; height: 28px; align-items: center; justify-content: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 600; margin-bottom: 10px; }
.steps h3 { font-size: 17px; margin-bottom: 8px; }
.steps p { font-size: 14.5px; color: var(--muted); }
.note { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 18px 22px; }
.note h3 { font-size: 17px; margin-bottom: 8px; }
.note ul { margin: 0 0 12px; padding-left: 20px; color: var(--muted); font-size: 14.5px; }
.note li { margin-bottom: 8px; }
.note p { font-size: 14.5px; color: var(--muted); }

@media (max-width: 1100px) {
  .lab { grid-template-columns: 1fr; }
  .controls { position: static; max-height: none; }
  .steps { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .two { grid-template-columns: 1fr; }
  #whatif { grid-template-columns: 1fr; grid-template-areas: "o" "s" "r"; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 680px) {
  .lab-hero h1 { font-size: 32px; }
  .lab-hero { padding-top: 32px; }
  .steps { grid-template-columns: 1fr; }
  .wi-sliders { grid-template-columns: 1fr; }
  .panel { padding: 14px 14px 16px; }
  .kpi-value { font-size: 22px; }
  .status .bar { flex-basis: 80px; }
  .preset-row .filters { flex-wrap: wrap; overflow: visible; }
}
