:root {
  --bg: #fafaf8; --panel: #fff; --ink: #222; --muted: #777; --line: #e3e3de; --accent: #2c7fb8; --bad: #c0392b;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.muted { color: var(--muted); }
.clickable { cursor: pointer; border-bottom: 1px dotted #aaa; }
.clickable:hover { color: var(--accent); }
code { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; background: #f1f1ec; padding: 1px 4px; border-radius: 3px; }

header { position: sticky; top: 0; z-index: 20; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 24px; padding: 10px 18px; flex-wrap: wrap; }
header .brand { font-size: 16px; }
header nav { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; }
header nav a { color: var(--ink); text-decoration: none; }
header nav a:hover { color: var(--accent); }
header .about { color: var(--accent); }

.layout { display: grid; grid-template-columns: 300px 1fr; gap: 0; }
#controls { position: sticky; top: 49px; height: calc(100vh - 49px); overflow-y: auto; background: #fff;
  border-right: 1px solid var(--line); padding: 12px 14px 40px; }
.ctl-section { margin-bottom: 14px; }
.ctl-section summary { font-weight: 600; cursor: pointer; margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--muted); margin: 2px 0 8px; }
.lbl { display: block; font-size: 12px; color: var(--muted); margin: 6px 0 3px; }
select, input[type=number] { width: 100%; padding: 4px; font: inherit; }
#preset { width: calc(100% - 64px); }
button { font: inherit; padding: 4px 10px; border: 1px solid #bbb; background: #fff; border-radius: 4px; cursor: pointer; }
button:hover { border-color: var(--accent); color: var(--accent); }
button.small { width: 58px; padding: 4px 0; }
.status { font-size: 12px; margin-top: 6px; min-height: 16px; }
.ctl { margin: 8px 0 10px; }
.ctl-top { display: flex; justify-content: space-between; font-size: 13px; }
.ctl-val { font-variant-numeric: tabular-nums; font-weight: 600; }
.ctl-slider { position: relative; }
.ctl-slider input, .ctl input[type=range] { width: 100%; margin: 2px 0 0; }
.mark { position: absolute; top: 15px; width: 2px; height: 7px; background: var(--accent); transform: translateX(-1px); pointer-events: none; }
.ctl-hint { font-size: 11px; color: var(--muted); }

#results { padding: 16px 26px 80px; min-width: 0; }
section { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 18px; margin-bottom: 16px; scroll-margin-top: 60px; }
h2 { font-size: 18px; margin: 0 0 10px; display: inline-block; }
h3 { font-size: 13px; font-weight: 600; margin: 6px 0; color: #444; }
.lede { margin: 10px 0 0; color: #444; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-top: 8px; }
@media (max-width: 1100px) { .grid2, .grid3 { grid-template-columns: 1fr; } .layout { grid-template-columns: 260px 1fr; } }
.chartbox { width: 100%; min-height: 60px; }
.legend { font-size: 12px; color: var(--muted); font-weight: normal; }
.legend i, .split-legend i { display: inline-block; width: 10px; height: 10px; margin: 0 3px 0 8px; vertical-align: -1px; border-radius: 2px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; background: #fff; }
.card:hover { border-color: var(--accent); }
.card.big { grid-row: span 1; background: #f3f8fc; }
.card-label { font-size: 12px; color: var(--muted); }
.card-value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; margin: 2px 0; }
.card.big .card-value { font-size: 34px; color: var(--accent); }
.card-sub { font-size: 11.5px; color: var(--muted); }
.losssplit { margin-top: 14px; }
.split-title { display: inline-block; font-size: 13px; margin-bottom: 4px; }
.split-bar { display: flex; height: 26px; border-radius: 4px; overflow: hidden; background: #eee; }
.split-bar .seg { color: #fff; font-size: 12px; line-height: 26px; padding-left: 6px; white-space: nowrap; overflow: hidden; }
.split-bar .seg.keep { background: var(--accent); }
.split-legend { font-size: 12px; margin-top: 4px; display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.split-legend .muted { margin-left: auto; }

svg.chart { display: block; overflow: visible; }
svg .grid { stroke: #eee; }
svg .tick { font-size: 10.5px; fill: #888; }
svg .tick.clickable { fill: #444; text-decoration: underline dotted; cursor: pointer; }
svg .lab { font-size: 12px; fill: #333; }
svg .lab.clickable { cursor: pointer; text-decoration: underline dotted; }
svg .val { font-size: 11.5px; fill: #333; font-variant-numeric: tabular-nums; }
svg .axis0 { stroke: #999; }
svg .hover { stroke: #aaa; stroke-dasharray: 2 2; }
svg .connector { stroke: #999; stroke-dasharray: 2 2; }
svg .band { fill: #f3f3f3; }
svg .xband { fill: #2c7fb8; opacity: 0.08; }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 9px; margin-left: 4px; vertical-align: 2px; }
.badge.ok { background: #e3f3e8; color: #2e7d32; }
.badge.warn { background: #fdecea; color: #c0392b; font-weight: 600; }
#tip { position: fixed; z-index: 50; display: none; background: rgba(30, 30, 30, 0.92); color: #fff; padding: 6px 9px; border-radius: 5px;
  font-size: 12px; line-height: 1.45; pointer-events: none; max-width: 320px; }

.org-controls { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; }
.org-controls select { width: auto; }
.org-wrap { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .org-wrap { grid-template-columns: 1fr; } }
#org canvas { image-rendering: pixelated; cursor: crosshair; max-width: 100%; }
#unit-detail h4 { margin: 4px 0 8px; }

table.kv { border-collapse: collapse; width: 100%; font-size: 13px; }
table.kv th { text-align: left; font-weight: 600; color: #555; border-bottom: 1px solid var(--line); padding: 4px 8px; }
table.kv td { border-bottom: 1px solid #f0f0ec; padding: 4px 8px; font-variant-numeric: tabular-nums; }
table.kv td:first-child { color: #333; }
#signals table.kv td:nth-child(2), #signals table.kv td:nth-child(3) { text-align: right; width: 140px; }

#c-ideas { width: 100%; height: 300px; }
.axisnote { font-size: 11.5px; color: var(--muted); text-align: center; }
progress { display: none; width: 220px; vertical-align: middle; }
.stale { opacity: 0.45; }
.stale::before { content: "Parameters changed — rerun to update."; display: block; color: var(--bad); font-size: 12px; margin-bottom: 6px; }
button.try { padding: 1px 8px; font-size: 12px; }

.traces { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 1100px) { .traces { grid-template-columns: 1fr; } }
.trace { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; }
.trace h4 { margin: 2px 0 6px; display: inline-block; }
.trace p { margin: 4px 0; }
.approver { margin: 8px 0; }
.ap-h { font-size: 12.5px; margin-bottom: 3px; }
.ok { color: #2e8b57; } .bad { color: var(--bad); }
.tb { display: grid; grid-template-columns: 110px 1fr 54px; align-items: center; font-size: 12px; height: 17px; }
.tbl { color: #555; }
.tbbar { position: relative; height: 10px; background: #f3f3f0; }
.tbbar::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: #999; }
.tbbar span { position: absolute; top: 0; bottom: 0; }
.tbv { text-align: right; font-variant-numeric: tabular-nums; }
ol.tight, ul.tight { padding-left: 20px; margin: 4px 0 10px; }
ol.tight li, ul.tight li { margin-bottom: 4px; }

#drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 420px; max-width: 92vw; background: #fff; z-index: 40;
  box-shadow: -6px 0 24px rgba(0, 0, 0, 0.12); padding: 20px 22px; transform: translateX(105%); transition: transform 0.2s ease; overflow-y: auto; }
#drawer.open { transform: none; }
#drawer-close { position: absolute; top: 10px; right: 12px; font-size: 20px; border: none; }
#drawer h3 { font-size: 17px; margin-top: 4px; color: var(--ink); }
#drawer .model { background: #f6f6f1; border-radius: 6px; padding: 8px 10px; margin: 10px 0; font-size: 12.5px; }
#drawer .model code { background: none; padding: 0; }
body.busy #headline, body.busy .chartbox { opacity: 0.6; transition: opacity 0.2s; }
