:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f3f0;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: #c3c2b7;
  --grid: #e1e0d9;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;

  --accent: #2a78d6;
  --accent-ink: #ffffff;

  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --info: #2a78d6;

  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: #383835;
    --grid: #2c2c2a;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --accent: #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242422;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: #383835;
  --grid: #2c2c2a;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --accent: #3987e5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- header ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 { font-size: 16px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.brand span { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

button, .btn {
  font-family: var(--font);
  font-size: 13px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 550; }
button.primary:hover { filter: brightness(1.07); }
a.btn { display: inline-flex; align-items: center; text-decoration: none; line-height: 1.2; }
a.btn:hover { background: var(--surface-2); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px;
  padding: 20px 24px 60px;
  max-width: 1560px;
  margin: 0 auto;
  align-items: start;
}
@media (max-width: 1020px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static !important; }
}

.sidebar {
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 0;
}

/* ---------- form ---------- */
.group { border-bottom: 1px solid var(--border); }
.group:last-child { border-bottom: none; }
.group > summary {
  cursor: pointer;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before {
  content: "";
  width: 0; height: 0;
  border-left: 5px solid var(--text-muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
  flex: none;
}
.group[open] > summary::before { transform: rotate(90deg); }
.group-body { padding: 2px 16px 16px; display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; color: var(--text-secondary); font-weight: 500; }
.field .hint { font-size: 11.5px; color: var(--text-muted); line-height: 1.4; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

input[type="number"], input[type="text"], select {
  font-family: var(--font);
  font-size: 13.5px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--page);
  color: var(--text-primary);
  width: 100%;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); min-width: 0; }
.range-val {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 600;
  min-width: 34px;
  text-align: right;
}

.check { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.check input { accent-color: var(--accent); margin-top: 2px; flex: none; }

/* ---------- results ---------- */
.results { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  min-width: 0;
}
.card > h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin: 0 0 14px;
  font-weight: 600;
}
.card-note { font-size: 12px; color: var(--text-muted); margin-top: 12px; line-height: 1.5; }

/* hero */
.hero { display: flex; flex-wrap: wrap; gap: 28px 40px; align-items: flex-end; }
.hero-figure { display: flex; flex-direction: column; gap: 2px; }
.hero-figure .value { font-size: 40px; font-weight: 620; letter-spacing: -0.02em; line-height: 1.05; }
.hero-figure .unit { font-size: 20px; font-weight: 500; color: var(--text-secondary); margin-left: 4px; }
.hero-figure .label { font-size: 12.5px; color: var(--text-muted); }
.hero-driver {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface-2);
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tile { background: var(--surface); padding: 13px 15px; display: flex; flex-direction: column; gap: 2px; }
.tile .v { font-size: 21px; font-weight: 600; letter-spacing: -0.01em; }
.tile .v small { font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-left: 3px; }
.tile .k { font-size: 11.5px; color: var(--text-muted); }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; padding: 0 16px 8px 0; border-bottom: 1px solid var(--border-strong); }
td { padding: 8px 16px 8px 0; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td:last-child, th:last-child { padding-right: 0; }
td .sub { display: block; font-size: 11.5px; color: var(--text-muted); }
tr.highlight td { background: color-mix(in srgb, var(--accent) 9%, transparent); font-weight: 550; }
.table-scroll { overflow-x: auto; }

/* legend */
.legend { display: flex; flex-wrap: wrap; gap: 10px 26px; margin-top: 14px; }
.legend-item { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; color: var(--text-secondary); }
.legend-item .swatch { position: relative; top: 1px; }
.legend-item b { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }

/* stacked capacity bar */
.stackbar { display: flex; width: 100%; height: 40px; border-radius: 5px; overflow: hidden; gap: 2px; background: var(--surface); }
.stackbar > div { min-width: 3px; transition: flex-grow 0.25s ease; }

/* bottleneck bars */
.bars { display: flex; flex-direction: column; gap: 11px; }
.bar-row { display: grid; grid-template-columns: 96px minmax(0, 1fr) 78px; align-items: center; gap: 12px; }
.bar-row .name { font-size: 12.5px; color: var(--text-secondary); }
.bar-track { background: var(--surface-2); border-radius: 4px; height: 20px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.25s ease; }
.bar-row .val { font-size: 12.5px; font-variant-numeric: tabular-nums; text-align: right; color: var(--text-primary); }
.bar-row.binding .name { color: var(--text-primary); font-weight: 600; }
.bar-row .tag { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

/* warnings */
.warn-list { display: flex; flex-direction: column; gap: 10px; }
.warn {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  align-items: start;
}
.warn .icon { font-size: 13px; font-weight: 700; line-height: 1.35; flex: none; }
.warn.critical { border-left: 3px solid var(--critical); }
.warn.critical .icon { color: var(--critical); }
.warn.warning { border-left: 3px solid var(--warning); }
.warn.warning .icon { color: #b07d00; }
:root[data-theme="dark"] .warn.warning .icon { color: var(--warning); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .warn.warning .icon { color: var(--warning); } }
.warn.info { border-left: 3px solid var(--info); }
.warn.info .icon { color: var(--info); }
.warn .t { font-weight: 600; font-size: 13px; }
.warn .d { font-size: 12.5px; color: var(--text-secondary); margin-top: 2px; }
.all-clear { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--text-secondary); }
.all-clear .icon { color: var(--good); font-weight: 700; }

/* two-col */
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 20px; }

/* chart */
.chart-wrap { overflow-x: auto; }
svg.chart { display: block; max-width: 100%; }
svg.chart text { font-family: var(--font); }

/* sources */
.sources { font-size: 12.5px; color: var(--text-secondary); }
.sources ul { margin: 8px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.sources a { color: var(--accent); text-decoration: none; }
.sources a:hover { text-decoration: underline; }

.disclaimer {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.55;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 4px;
}

@media print {
  .sidebar, .topbar-actions { display: none; }
  .layout { grid-template-columns: 1fr; }
  body { background: #fff; }
  .card { break-inside: avoid; border-color: #ccc; }
}
