:root {
  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-serif: 'Source Serif 4', Georgia, serif;
  --bg: #f6f5f1; --surface: #fdfcf9; --surface-2: #efeee9; --border: #dedcd5;
  --text: #161614; --text-muted: #5f5d57;
  /* ink is the primary data color; amber marks live/highlighted data */
  --accent: #1c1c1a; --accent-soft: #ebe9e3;
  --pos: #2b7a3d; --neg: #b3261e; --warn: #9a5b00; --chart-muted: #b9b6ad;
  --shadow: none;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d0c; --surface: #131312; --surface-2: #1b1a18; --border: #2a2926;
    --text: #edebe6; --text-muted: #9a978f;
    --accent: #edebe6; --accent-soft: #24231f;
    --pos: #6cc27f; --neg: #f07167; --warn: #e3a440; --chart-muted: #4a4843;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0d0c; --surface: #131312; --surface-2: #1b1a18; --border: #2a2926;
    --text: #edebe6; --text-muted: #9a978f;
    --accent: #edebe6; --accent-soft: #24231f;
    --pos: #6cc27f; --neg: #f07167; --warn: #e3a440; --chart-muted: #4a4843;
    --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; }
body { font-family: var(--font-sans); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark { font-weight: 600; font-size: 20px; letter-spacing: -0.03em; }
.brand-sub { font-size: 12.5px; color: var(--text-muted); padding-left: 10px; border-left: 1px solid var(--border); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 2px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.notice { background: var(--surface-2); color: var(--text-muted); font-size: 12.5px; padding: 7px 20px; border-bottom: 1px solid var(--border); }

.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 90px); }
.sidenav { border-right: 1px solid var(--border); background: var(--surface); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidenav a { display: block; padding: 8px 12px; border-radius: 2px; text-decoration: none; color: var(--text-muted); font-weight: 500; }
.sidenav a:hover { background: var(--surface-2); color: var(--text); }
.sidenav a[aria-current="page"] { color: var(--text); box-shadow: inset 2px 0 0 var(--text); background: none; }
.sidenav .asof { margin-top: auto; padding: 12px; font-size: 12px; color: var(--text-muted); }
main { padding: 24px 28px 48px; min-width: 0; }
.boot { max-width: 560px; margin: 80px auto; text-align: center; color: var(--text-muted); }

.view-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.view-head h1 { font-family: var(--font-serif); font-size: 30px; font-weight: 400; letter-spacing: -0.01em; }
.view-head p { color: var(--text-muted); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 2px; padding: 2px; }
.seg button { border: 0; background: transparent; font: inherit; color: var(--text-muted); padding: 5px 10px; border-radius: 2px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.filters select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 2px; padding: 6px 10px; max-width: 100%; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 0; padding: 14px 16px; text-decoration: none; box-shadow: var(--shadow); text-align: left; font: inherit; color: inherit; width: 100%; }
a.kpi, button.kpi { cursor: pointer; }
a.kpi:hover, button.kpi:hover { border-color: var(--text-muted); }
.kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.kpi-value { font-family: var(--font-serif); font-size: 28px; font-weight: 400; letter-spacing: -0.01em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 0; padding: 16px; box-shadow: var(--shadow); min-width: 0; margin-bottom: 12px; }
.grid-2 > .card { margin-bottom: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3 { font-size: 14px; }
.card-head p { font-size: 12px; color: var(--text-muted); }
.chart { position: relative; height: 260px; }
.chart-fallback { display: grid; place-items: center; height: 100%; color: var(--text-muted); }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data-table th { text-align: left; font-size: 12px; color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border); padding: 0; white-space: nowrap; }
.data-table th button { all: unset; cursor: pointer; display: block; padding: 8px 10px; }
.data-table th button:focus-visible { outline: 2px solid var(--accent); }
.data-table th.num button { text-align: right; }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table .num { text-align: right; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover { background: var(--surface-2); }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 2px; }
.badge-Healthy, .badge-pos { background: color-mix(in srgb, var(--pos) 15%, transparent); color: var(--pos); }
.badge-Watch, .badge-warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.badge-Critical, .badge-neg { background: color-mix(in srgb, var(--neg) 15%, transparent); color: var(--neg); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 2px; padding: 4px 12px; font: inherit; font-size: 12.5px; cursor: pointer; color: var(--text); }
.chip[aria-pressed="true"] { border-color: var(--text); background: var(--text); color: var(--bg); font-weight: 500; }

.empty { padding: 48px 16px; text-align: center; color: var(--text-muted); background: var(--surface); border: 1px dashed var(--border); border-radius: 0; }
.footnote { font-size: 12px; color: var(--text-muted); margin-top: 4px; max-width: 80ch; }

.progress { position: relative; height: 14px; background: var(--surface-2); border-radius: 2px; overflow: hidden; display: flex; }
.progress span { display: block; height: 100%; }
.progress .won { background: var(--accent); }
.progress .weighted { background: color-mix(in srgb, var(--accent) 40%, transparent); }
.progress .target { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); margin-top: 10px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--surface); border-left: 1px solid var(--border); z-index: 41; display: flex; flex-direction: column;  }
.drawer header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer h2 { font-size: 16px; }
.drawer header p { font-size: 12px; color: var(--text-muted); }
.drawer-body { overflow: auto; padding: 8px 12px 24px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidenav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 8px 12px; }
  .sidenav a { white-space: nowrap; }
  .sidenav .asof { display: none; }
  main { padding: 16px 16px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
  .brand-sub { display: none; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 20px; }
  .topbar-actions .btn:not(.btn-primary) { display: none; }
  .drawer header { flex-direction: column; }
}
