:root {
  --surface-0: #f4f6f9; --surface-1: #ffffff; --surface-2: #f0f3f7;
  --text-primary: #18212f; --text-secondary: #5b6575; --border: #dde3ea; --grid: #e8ecf1; --shade: rgba(120,130,150,.08);
  --brand: #12304f; --brand-2: #1d4a76; --accent: #257de0;
  --series-1: #257de0; --series-2: #f47230; --series-3: #00b894;
  --gain: #1b64be; --loss: #c23334; --warn-bg: #fff6e0; --warn-bd: #f2c04b; --ok: #0a7a1e;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--surface-0); color: var(--text-primary); font-size: 14px; line-height: 1.45; }
a { color: var(--brand-2); }
button, select, input { font: inherit; }
:focus-visible { outline: 3px solid #f2a600; outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; background: #fff; padding: 8px; z-index: 99; }
.skip:focus { left: 8px; }

/* header */
header.top { background: var(--brand); color: #fff; display: flex; align-items: center; gap: 16px; padding: 10px 18px; position: sticky; top: 0; z-index: 20; }
header.top h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: .2px; }
header.top .sub { font-size: 12px; opacity: .8; }
header.top .spacer { flex: 1; }
header.top select, header.top button { background: #1f4468; color: #fff; border: 1px solid #3a6087; border-radius: 6px; padding: 6px 10px; }
header.top button:hover { background: #2a5784; }
header.top label { font-size: 12px; opacity: .85; margin-right: 4px; }
.demo { background: var(--warn-bg); border-bottom: 1px solid var(--warn-bd); padding: 6px 18px; font-size: 12.5px; }

/* layout */
.shell { display: grid; grid-template-columns: 212px 1fr; min-height: calc(100vh - 90px); }
nav.side { background: var(--surface-1); border-right: 1px solid var(--border); padding: 10px 8px; position: sticky; top: 52px; height: calc(100vh - 52px); overflow: auto; }
nav.side .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-secondary); margin: 12px 10px 4px; }
nav.side button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 6px; color: var(--text-primary); cursor: pointer; }
nav.side button:hover { background: var(--surface-2); }
nav.side button[aria-current="page"] { background: #e6f0fc; color: var(--brand-2); font-weight: 600; }
main { padding: 18px 22px 40px; min-width: 0; }
main:focus { outline: none; }
.viewhead { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.viewhead h2 { margin: 0; font-size: 21px; }
.viewhead .hint { color: var(--text-secondary); }
.scenbar { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 14px; font-size: 13px; }
.scenbar b { color: var(--brand-2); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; background: var(--surface-2); border: 1px solid var(--border); }
.pill.real { background: #e7f6ec; border-color: #9fd7ae; color: #0d5b22; }
.pill.proxy { background: #eaf2fd; border-color: #a9c9f2; color: #194f8f; }
.pill.derived { background: #f3effd; border-color: #c9bdf2; color: #4b2fa8; }
.pill.dummy, .pill.assumption { background: #fff1e6; border-color: #f4b98f; color: #8a3b07; }
.pill.mod { background: #e7f6ec; color: #0d5b22; border-color: #9fd7ae; }
.pill.part { background: #eaf2fd; color: #194f8f; border-color: #a9c9f2; }
.pill.no { background: #f5f5f5; color: #555; }

/* cards & grid */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (max-width: 1250px) { .g6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g2 { grid-template-columns: 1fr; } }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .cap { color: var(--text-secondary); font-size: 12.5px; margin-bottom: 8px; }
.kpi .k { font-size: 12px; color: var(--text-secondary); }
.kpi .v { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .d { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.pos { color: var(--gain); } .neg { color: var(--loss); }
.narr { font-size: 15px; background: var(--surface-1); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; box-shadow: var(--shadow); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn { background: var(--brand-2); color: #fff; border: 0; border-radius: 6px; padding: 7px 12px; cursor: pointer; }
.btn:hover { background: var(--brand); }
.btn.ghost { background: var(--surface-1); color: var(--brand-2); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: #fff; color: var(--loss); border: 1px solid #f0b4b4; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
select, input[type=text], input[type=number], input[type=search] { border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; background: #fff; color: var(--text-primary); }

/* tables */
.tablewrap { overflow: auto; max-height: 620px; border: 1px solid var(--border); border-radius: 6px; }
table.t { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.t caption { text-align: left; font-weight: 600; padding: 6px 0; }
table.t th, table.t td { padding: 6px 9px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t td.l, table.t th.l { text-align: left; white-space: normal; }
table.t thead th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; z-index: 1; cursor: default; }
table.t thead th.sort { cursor: pointer; }
table.t thead th.sort:hover { background: #e3e9f0; }
table.t tbody tr:hover { background: #f6f9fd; }
table.t tbody tr.click { cursor: pointer; }
table.t tfoot td { font-weight: 650; background: var(--surface-2); }

/* controls */
.ctlgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.ctl { margin-bottom: 12px; }
.ctl label { display: flex; justify-content: space-between; font-weight: 550; font-size: 13px; }
.ctl label .v { font-weight: 650; color: var(--brand-2); font-variant-numeric: tabular-nums; }
.ctl input[type=range] { width: 100%; accent-color: var(--accent); }
.ctl .help { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-bottom: 14px; }
.preset { text-align: left; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; }
.preset:hover { border-color: var(--accent); }
.preset[aria-pressed="true"] { border: 2px solid var(--accent); background: #f2f8ff; }
.preset b { display: block; margin-bottom: 3px; }
.preset span { font-size: 12px; color: var(--text-secondary); }
.toggle { display: flex; gap: 6px; align-items: center; font-size: 13px; }
fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; margin: 0 0 10px; }
legend { font-size: 12px; color: var(--text-secondary); padding: 0 4px; }

/* charts */
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart text { font-size: 11.5px; fill: var(--text-primary); }
svg.chart text.tick { fill: var(--text-secondary); font-size: 11px; }
svg.chart text.val { fill: var(--text-secondary); font-size: 11px; }
svg.chart .mark:hover, svg.chart .mark:focus { stroke: #111; stroke-width: 1.5; }
svg.map .region:hover, svg.map .region:focus { stroke: #111; stroke-width: 1.6; }
.tip { position: fixed; z-index: 100; background: #111c2b; color: #fff; padding: 7px 10px; border-radius: 6px; font-size: 12.5px; pointer-events: none; display: none; max-width: 320px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.tip .sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
.legendrow { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }

.flag { background: var(--warn-bg); border: 1px solid var(--warn-bd); padding: 6px 10px; border-radius: 6px; font-size: 12.5px; margin: 4px 0; }
.ok { color: var(--ok); }
.muted { color: var(--text-secondary); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.eq { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; white-space: pre-wrap; }
.prose { max-width: 900px; }
.prose h3 { margin-top: 22px; }
.toast { position: fixed; bottom: 18px; right: 18px; background: #12304f; color: #fff; padding: 10px 14px; border-radius: 8px; z-index: 200; box-shadow: var(--shadow); display: none; }
footer { color: var(--text-secondary); font-size: 12px; padding: 10px 22px 24px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* report */
.report { background: #fff; max-width: 900px; margin: 0 auto; padding: 36px 44px; border: 1px solid var(--border); }
.report h1 { font-size: 24px; margin: 0 0 4px; color: var(--brand); }
.report h2 { font-size: 17px; border-bottom: 2px solid var(--brand); padding-bottom: 4px; margin-top: 26px; }
.report .meta { color: var(--text-secondary); margin-bottom: 14px; }
.report table.t { font-size: 12px; }
.report .kgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.report .kgrid div { border: 1px solid var(--border); border-radius: 6px; padding: 8px; }

@media print {
  header.top, nav.side, .demo, .noprint, footer, .scenbar, .viewhead, .toast, .tip, #saveDlg { display: none !important; }
  .shell { display: block; } main { padding: 0; }
  body { background: #fff; font-size: 11.5px; }
  .report { border: 0; padding: 0; max-width: none; }
  .report h2 { break-after: avoid; } table, svg { break-inside: avoid; }
  .card { box-shadow: none; }
}
.shell { background: linear-gradient(to right, var(--surface-1) 212px, transparent 212px); }
nav.side { align-self: start; }
