:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --subtle: #f0f3f2;
  --border: #e2e7e5;
  --border-strong: #cdd5d2;
  --text: #13201d;
  --text-2: #45534f;
  --muted: #5f6d68;
  --accent: #1f5fbf;
  --accent-dark: #174a94;
  --accent-bg: #e8effb;
  --accent-soft: #8fb0e3;
  --good: #11714a;
  --good-bg: #e7f5ec;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --bad-bar: #d1543f;
  --warn: #8a5a00;
  --warn-bg: #fdf3e1;
  --up-1: #a6d9b8; --up-2: #c9e9d4; --up-3: #e7f5ec;
  --dn-1: #f1b5b0; --dn-2: #f8d3d0; --dn-3: #fcebea;
  --radius: 10px;
  --mono: 'Geist Mono', ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Geist, 'Helvetica Neue', Arial, system-ui, sans-serif;
  font-size: 13px;
  line-height: 20px;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.mono { font-family: var(--mono); }

/* Header */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  align-items: center; justify-content: space-between;
  padding: 10px 20px;
}
.top-left, .top-right { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.brand img { display: block; height: 30px; width: auto; }
.divider { width: 1px; height: 22px; background: var(--border); }
.app-name { font-size: 14px; font-weight: 600; }
.pill {
  border: 1px solid var(--border); border-radius: 999px;
  padding: 1px 9px; font-size: 11.5px; line-height: 16px; color: var(--muted);
}
.pill.warn { border-color: var(--warn-bg); background: var(--warn-bg); color: var(--warn); font-weight: 500; }
.pill.good { border-color: var(--good-bg); background: var(--good-bg); color: var(--good); font-weight: 500; }
.user { font-size: 11.5px; color: var(--muted); }
.btn {
  border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface);
  padding: 5px 12px; font-size: 12.5px; line-height: 18px; font-weight: 500; color: var(--text);
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px;
}
.btn:hover { background: var(--subtle); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn .count {
  background: var(--bad); color: #fff; border-radius: 999px; font-size: 10.5px; line-height: 14px;
  padding: 0 6px; font-weight: 600;
}
.menu-btn { display: none; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); width: 36px; height: 36px; align-items: center; justify-content: center; }
.menu-btn path, .icon-btn path { fill: none; stroke: var(--text-2); stroke-width: 1.6; stroke-linecap: round; }

/* Shell */
.shell { display: flex; align-items: stretch; min-height: calc(100vh - 53px); }
.rail {
  flex: 0 0 256px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px 24px; display: flex; flex-direction: column; gap: 2px;
}
.rail-group { display: flex; flex-direction: column; gap: 1px; padding-bottom: 14px; }
.rail-title {
  display: flex; justify-content: space-between; padding: 0 10px 4px;
  font-size: 10.5px; line-height: 14px; font-weight: 600; letter-spacing: 0.06em; color: var(--muted);
}
.rail a {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding: 7px 10px; border-radius: 6px; color: var(--text-2);
  font-size: 12.5px; line-height: 18px; font-weight: 500; text-decoration: none;
}
.rail a:hover { background: var(--subtle); color: var(--text); }
.rail a[aria-current="page"] { background: var(--accent-bg); color: var(--accent-dark); font-weight: 600; }
.rail a .phase { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.rail a .phase.later { color: #7b8783; }
.rail-legend {
  margin-top: 4px; padding: 10px; border-radius: 6px; background: var(--bg);
  font-size: 11px; line-height: 16px; color: var(--muted);
}
.rail-legend b { color: var(--text-2); font-weight: 600; }
.rail-sub { padding-left: 22px !important; font-size: 12px !important; }

main { flex: 1 1 auto; min-width: 0; padding: 20px 24px 48px; display: flex; flex-direction: column; gap: 24px; outline: none; }

/* Page heading */
.page-head { display: flex; flex-direction: column; gap: 4px; }
.eyebrow { font-size: 10.5px; line-height: 14px; font-weight: 600; letter-spacing: 0.06em; color: var(--muted); text-transform: uppercase; }
.page-head h1 { font-size: 28px; line-height: 32px; font-weight: 600; letter-spacing: -0.02em; }
.page-head .lede { font-size: 13px; line-height: 20px; color: var(--text-2); max-width: 820px; }
.crumbs { font-size: 12px; color: var(--muted); }
.crumbs a { text-decoration: none; }

/* Welcome */
.welcome {
  border: 1px solid var(--accent-bg); background: var(--accent-bg); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-start; justify-content: space-between;
  color: var(--accent-dark);
}
.welcome h2 { font-size: 14px; line-height: 20px; font-weight: 600; }
.welcome ul { margin: 6px 0 0; padding-left: 18px; font-size: 12.5px; line-height: 19px; color: #1d3f75; }
.welcome .btn { border-color: #b9cdee; }

/* Filters */
.filters {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  padding: 10px 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.chip {
  position: relative; display: inline-flex; align-items: baseline; gap: 6px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  padding: 5px 12px; font-size: 12.5px; line-height: 18px; color: var(--text-2); min-height: 32px;
}
.chip:hover { border-color: var(--border-strong); }
.chip .k { font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; color: var(--muted); }
.chip b { color: var(--text); font-weight: 600; }
.chip.on { background: var(--accent-bg); border-color: var(--accent-bg); color: var(--accent-dark); }
.chip.on .k, .chip.on b { color: var(--accent-dark); }
.chip .caret { width: 9px; height: 9px; align-self: center; }
.chip .caret path { fill: none; stroke: currentColor; stroke-width: 1.5; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--surface); }
.seg .k { align-self: center; padding: 0 4px 0 12px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; color: var(--muted); }
.seg button { border: none; background: none; padding: 5px 11px; font-size: 12.5px; line-height: 18px; color: var(--text-2); min-height: 32px; }
.seg button[aria-pressed="true"] { background: var(--accent-bg); color: var(--accent-dark); font-weight: 600; }
.filters .spacer { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.quiet { border: 1px solid var(--border); border-radius: 6px; background: var(--surface); padding: 4px 10px; font-size: 12.5px; line-height: 18px; font-weight: 500; color: var(--text-2); min-height: 30px; }
.quiet:hover { background: var(--subtle); }

.popover {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 15; min-width: 260px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(19, 32, 29, 0.12); padding: 8px; display: flex; flex-direction: column; gap: 2px;
  text-align: left; cursor: default;
}
.popover label { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px; font-size: 12.5px; color: var(--text); cursor: pointer; }
.popover label:hover { background: var(--subtle); }
.popover input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.popover .code { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.popover .pop-foot { display: flex; justify-content: space-between; border-top: 1px solid var(--border); margin-top: 4px; padding: 8px 4px 2px; }
.popover .pop-foot button { border: none; background: none; color: var(--accent); font-size: 12px; padding: 2px 4px; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.tile { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.tile .l { font-size: 12.5px; line-height: 18px; font-weight: 500; color: var(--text-2); }
.tile .v { font-size: 26px; line-height: 30px; font-weight: 600; letter-spacing: -0.02em; }
.tile .d { font-size: 12px; line-height: 16px; font-weight: 500; }
.tile .n { font-size: 11.5px; line-height: 16px; color: var(--muted); }
.tile.link { cursor: pointer; text-align: left; }
.tile.link:hover { border-color: var(--border-strong); }
.c-good { color: var(--good); } .c-bad { color: var(--bad); } .c-flat { color: var(--text-2); }

/* Sections and tables */
.section { display: flex; flex-direction: column; gap: 10px; }
.section-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; }
.section-head h2 { font-size: 14px; line-height: 20px; font-weight: 600; letter-spacing: -0.01em; }
.section-head .def { font-size: 11.5px; line-height: 16px; color: var(--muted); }
.tag { border-radius: 4px; padding: 1px 7px; font-size: 11px; line-height: 16px; font-weight: 600; background: var(--subtle); color: var(--text-2); white-space: nowrap; }
.tag.p2, .tag.p3, .tag.p4 { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.ok { background: var(--good-bg); color: var(--good); }
.tag.info { background: var(--accent-bg); color: var(--accent-dark); }
.card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.grid-table { min-width: 980px; }
th {
  background: var(--subtle); border-bottom: 1px solid var(--border-strong);
  padding: 8px 12px; text-align: right; font-size: 10.5px; line-height: 14px; font-weight: 600; letter-spacing: 0.06em; color: var(--muted);
  text-transform: uppercase; white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; }
th.l, td.l { text-align: left; }
td { border-top: 1px solid var(--border); padding: 4px 12px; text-align: right; font-size: 12.5px; line-height: 18px; white-space: nowrap; }
td.cell { padding: 3px 3px; }
td.cell span { display: block; padding: 4px 8px; border-radius: 4px; }
td.name { padding: 7px 12px; }
td.name .code { margin-left: 8px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
td.sub { padding-left: 28px; color: var(--text-2); }
tr.total td { background: var(--subtle); font-weight: 600; border-top-color: var(--border-strong); }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7f9f8; }
tr.click:hover td.name { color: var(--accent-dark); }
tr.click td.name::after { content: '›'; margin-left: 6px; color: var(--muted); }
tr.group td { background: var(--bg); border-top-color: var(--border-strong); padding: 9px 12px 7px; text-align: left; }
tr.group td b { font-size: 13px; }
tr.group td .code { margin-left: 8px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
tr.prov td { padding-top: 9px; text-align: left; border-top: 1px solid var(--border); }
tr.prov td .role { margin-left: 10px; font-size: 11.5px; color: var(--text-2); }
tr.prov td .since { margin-left: 10px; font-size: 11.5px; color: var(--muted); }
tr.metric td { border-top: none; }
td.avg { background: var(--subtle); color: var(--text-2); }
td.delta { font-size: 12px; font-weight: 500; text-align: left; }
td.spark { padding: 4px 8px 0 12px; text-align: left; }
.spark svg { display: block; }
.spark .area { fill: rgba(31, 95, 191, 0.12); }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.spark .dot { fill: var(--accent); }
.status { display: inline-block; border-radius: 4px; padding: 2px 8px; font-size: 11.5px; line-height: 16px; font-weight: 600; }
.foot-note { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border); padding-top: 16px; font-size: 11.5px; line-height: 16px; color: var(--muted); }
.foot-note b { color: var(--text-2); }

/* Bars */
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.box { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.box h2 { font-size: 14px; line-height: 20px; font-weight: 600; letter-spacing: -0.01em; }
.box .def { font-size: 11.5px; line-height: 16px; color: var(--muted); }
.box-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; align-items: baseline; }
.bar-row { display: flex; flex-direction: column; gap: 4px; }
.bar-row.btnlike { border: none; background: none; padding: 6px 8px; margin: -6px -8px; border-radius: 6px; text-align: left; }
.bar-row.btnlike:hover { background: var(--subtle); }
.bar-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.bar-top .lab { font-size: 12.5px; line-height: 18px; font-weight: 500; }
.bar-top .sub { margin-left: 8px; font-size: 11px; line-height: 14px; color: var(--muted); }
.bar-top .val { font-size: 12.5px; line-height: 18px; font-weight: 600; white-space: nowrap; }
.bar-top .val small { font-weight: 400; color: var(--muted); font-size: 12px; }
.track { height: 10px; border-radius: 4px; background: var(--subtle); }
.track > div { height: 10px; border-radius: 4px; background: var(--text-2); }
.track.blue > div { background: var(--accent); }
.track.red > div { background: var(--bad-bar); }
.callout { border-radius: 8px; background: var(--warn-bg); padding: 10px 12px; font-size: 12px; line-height: 18px; color: #5c3d00; }

/* Column chart */
.cols { position: relative; height: 200px; display: grid; gap: 8px; align-items: end; border-bottom: 1px solid var(--border-strong); padding: 0 4px; }
.cols .col { display: flex; flex-direction: column; align-items: stretch; gap: 3px; }
.cols .col span { text-align: center; font-size: 10.5px; line-height: 14px; color: var(--text-2); }
.cols .col div { border-radius: 3px 3px 0 0; background: var(--accent-soft); }
.cols .col.last div { background: var(--accent-dark); }
.cols .budget { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--warn); }
.cols .budget span { position: absolute; left: 0; top: -9px; z-index: 1; font-weight: 600; font-size: 10.5px; color: var(--warn); background: var(--surface); padding: 0 4px; }
.col-labels { display: grid; gap: 8px; padding: 0 4px; }
.col-labels span { text-align: center; font-size: 10.5px; line-height: 14px; color: var(--muted); }

/* Notes */
.notes { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.note { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.note .area { font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; color: var(--accent-dark); }
.note h3 { font-size: 13px; line-height: 19px; font-weight: 600; }
.note p { font-size: 12.5px; line-height: 19px; color: var(--text-2); }

/* Phase preview pages */
.phase-hero { border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface); padding: 18px 20px; display: flex; flex-wrap: wrap; gap: 16px 32px; }
.phase-hero .fact { display: flex; flex-direction: column; gap: 2px; min-width: 160px; }
.phase-hero .fact .k { font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; color: var(--muted); }
.phase-hero .fact .v { font-size: 14px; font-weight: 600; }
.metric-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.metric-groups .box ul { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.metric-groups .box li { border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; font-size: 11.5px; line-height: 16px; color: var(--text-2); background: var(--bg); }

/* Side panel */
.scrim { position: fixed; inset: 0; background: rgba(19, 32, 29, 0.28); z-index: 40; }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41; width: min(520px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border-strong); box-shadow: -12px 0 32px rgba(19, 32, 29, 0.12);
  transform: translateX(100%); transition: transform 0.22s ease; display: flex; flex-direction: column;
}
.panel.open { transform: translateX(0); }
.panel-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: 18px; line-height: 24px; font-weight: 600; letter-spacing: -0.01em; }
.icon-btn { border: none; background: none; width: 36px; height: 36px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--subtle); }
.panel-body { flex: 1 1 auto; overflow-y: auto; padding: 16px 20px 28px; display: flex; flex-direction: column; gap: 16px; }
.panel-body table td, .panel-body table th { padding-left: 8px; padding-right: 8px; }
.qs { display: flex; flex-direction: column; gap: 8px; }
.q { border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); padding: 9px 12px; text-align: left; font-size: 12.5px; line-height: 18px; color: var(--text); }
.q:hover { background: var(--subtle); }
.q[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-bg); color: var(--accent-dark); font-weight: 500; }
.answer { border-radius: 8px; background: var(--bg); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; font-size: 13px; line-height: 20px; }
.answer .who { font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; color: var(--accent-dark); }
.answer ul { margin: 0; padding-left: 18px; }
.ask-input { display: flex; gap: 8px; }
.ask-input input { flex: 1; min-width: 0; border: 1px solid var(--border-strong); border-radius: 6px; padding: 8px 10px; font: inherit; font-size: 13px; }
.alert-item { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--text); }
.alert-item:hover { border-color: var(--border-strong); background: #fafbfb; color: var(--text); }
.alert-item .when { font-size: 11.5px; color: var(--muted); }
.alert-item p { font-size: 12.5px; line-height: 19px; color: var(--text-2); }
.timeline { display: flex; flex-direction: column; gap: 0; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline div { position: relative; padding: 0 0 14px 16px; font-size: 12.5px; line-height: 19px; }
.timeline div::before { content: ''; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 999px; background: var(--surface); border: 2px solid var(--border-strong); }
.timeline div.now::before { border-color: var(--bad); background: var(--bad); }
.timeline .t { font-size: 11.5px; color: var(--muted); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 12.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 500; }
.filter-list { display: flex; flex-direction: column; gap: 4px; }
.filter-list div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); padding: 7px 0; font-size: 12.5px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: #fff; border-radius: 8px; padding: 10px 16px; font-size: 12.5px; z-index: 60;
  transition: opacity 0.2s, transform 0.2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.credit { padding: 14px 24px 24px; font-size: 11.5px; color: var(--muted); text-align: center; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 900px) {
  .menu-btn { display: inline-flex; }
  .top { padding: 10px 16px; }
  .top .divider, .top .app-name, .top .pill.mono, .user { display: none; }
  .top-right { width: 100%; }
  .top-right .btn { flex: 1 1 auto; justify-content: center; }
  .rail { position: fixed; top: 0; left: 0; bottom: 0; z-index: 42; width: 280px; transform: translateX(-100%); transition: transform 0.22s ease; overflow-y: auto; box-shadow: 12px 0 32px rgba(19, 32, 29, 0.12); }
  .rail.open { transform: translateX(0); }
  main { padding: 16px 16px 40px; }
  .page-head h1 { font-size: 24px; line-height: 28px; }
  .two { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile .v { font-size: 22px; line-height: 26px; }
  .kv { grid-template-columns: 110px 1fr; }
}
