:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #256abf;
  --accent-wash: #cde2fb66;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #006300;
  --good-wash: #0ca30c1f;
  --warn: #8a4a00;
  --warn-wash: #fab21933;
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 4px 16px rgba(11, 11, 11, .04);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --line: #2c2c2a;
    --axis: #383835;
    --accent: #6da7ec;
    --accent-wash: #3987e52e;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #0ca30c;
    --good-wash: #0ca30c26;
    --warn: #fab219;
    --warn-wash: #fab21926;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
h2 { font-size: 15px; }
.loading, .empty { color: var(--muted); padding: 32px; text-align: center; }
.error { color: var(--warn); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* --- layout ---------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.nav { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px;
       display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 15px; padding: 0 8px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.switch { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 3px;
          background: var(--surface-2); border-radius: 9px; }
.switch a { text-align: center; padding: 6px 4px; border-radius: 7px; color: var(--ink-2); font-weight: 550; }
.switch a:hover { text-decoration: none; color: var(--ink); }
.switch a[aria-current] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.menu { display: flex; flex-direction: column; gap: 2px; }
.menu a { display: flex; justify-content: space-between; padding: 7px 10px; border-radius: 7px; color: var(--ink-2); }
.menu a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.menu a[aria-current] { background: var(--accent-wash); color: var(--ink); font-weight: 600; }
.menu .count { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 400; }
.account { margin-top: auto; padding: 0 8px; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.account .who { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-button { all: unset; cursor: pointer; color: var(--accent); font-size: 12px; }
.link-button:hover { text-decoration: underline; }
.link-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nav-foot { padding: 0 8px; font-size: 12px; color: var(--muted); }
.account + .nav-foot { margin-top: 0; }
.nav > .menu + .nav-foot { margin-top: auto; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { max-width: 440px; width: 100%; }
.auth h1 { margin-bottom: 8px; }
.auth p { color: var(--ink-2); }
.main { padding: 24px 28px 48px; min-width: 0; }
.top { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.top h1 { margin-right: auto; }
.top .crumb { color: var(--muted); font-size: 13px; display: block; font-weight: 400; letter-spacing: 0; }

/* --- controls --------------------------------------------------------------- */
input[type=search], select, button, .button {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; min-height: 34px;
}
input[type=search] { min-width: 220px; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
button, .button { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .45; cursor: default; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters .spacer { flex: 1; }
.summary { color: var(--ink-2); margin: 0 0 10px; }
.summary strong { color: var(--ink); }

/* --- cards & tables --------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px 20px; }
.card > h2:not(.doc-title) { padding: 14px 18px 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.stack { display: grid; gap: 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; background: var(--surface); }
th.num { text-align: right; }
th button { all: unset; cursor: pointer; }
th button:hover { color: var(--ink); }
th button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--accent-wash); }
/* max-width: 0 lets these cells give way first, so wide tables fit before they scroll */
td.clip { max-width: 0; width: 22%; min-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tfoot td { font-weight: 600; border-top: 1px solid var(--axis); border-bottom: 0; }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; padding: 10px 12px; color: var(--ink-2); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 550;
         background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.good { background: var(--good-wash); color: var(--good); }
.badge.warn { background: var(--warn-wash); color: var(--warn); }
.badge.client { background: var(--accent-wash); color: var(--accent); }

/* --- dashboard -------------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--ink-2); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; }
.kpi .value small { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.chart-card { padding: 16px 18px 8px; }
.chart-head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-head h2 { margin-right: auto; }
.legend { display: flex; gap: 14px; color: var(--ink-2); font-size: 13px; }
.legend i, .tip i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.swatch-1 { background: var(--series-1); }
.swatch-2 { background: var(--series-2); }
.chart { position: relative; }
.chart svg { display: block; width: 100%; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .base-line { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .s1 { fill: var(--series-1); }
.chart .s2 { fill: var(--series-2); }
.chart .band { fill: transparent; cursor: pointer; }
.chart .band.on { fill: var(--accent-wash); }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line);
       border-radius: 8px; box-shadow: var(--shadow); padding: 8px 10px; font-size: 12px; min-width: 190px; z-index: 2; }
.tip b { display: block; margin-bottom: 4px; font-size: 13px; }
.tip div { display: flex; justify-content: space-between; gap: 14px; color: var(--ink-2); }
.tip div span:last-child { color: var(--ink); font-variant-numeric: tabular-nums; }
.rank td:first-child { width: 100%; }
.bar-cell { position: relative; }
.bar-track { height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 5px; overflow: hidden; }
.bar-track svg { display: block; width: 100%; height: 4px; }
.bar-track rect { fill: var(--series-1); }

/* --- detail pages ----------------------------------------------------------- */
.doc { padding: 32px 36px; max-width: 900px; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: 28px; }
.doc-head .issuer { font-weight: 650; font-size: 16px; }
.doc-title { font-size: 24px; font-weight: 650; letter-spacing: -.02em; margin: 0 0 4px; }
.doc-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 24px; margin-bottom: 24px; }
.address { white-space: pre-line; }
.address strong { display: block; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
dl.facts dt { color: var(--ink-2); }
dl.facts dd { margin: 0; }
.subject { font-weight: 600; margin: 0 0 12px; }
.totals { margin: 12px 0 0 auto; width: min(320px, 100%); }
.totals td { border: 0; padding: 4px 12px; }
.totals tr.grand td { font-weight: 700; font-size: 16px; border-top: 1px solid var(--axis); padding-top: 8px; }
.note { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin-top: 16px; white-space: pre-wrap; }
.archive-mark { color: var(--muted); font-size: 12px; margin-top: 24px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.toolbar .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 6px 10px; border-radius: 7px; color: var(--ink-2); border: 1px solid transparent; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; }
.tabs a[aria-current] { background: var(--surface); border-color: var(--line); color: var(--ink); font-weight: 600; }
.raw td { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; gap: 10px; }
  .menu { flex-direction: row; overflow-x: auto; }
  .menu a { white-space: nowrap; gap: 6px; }
  .nav-foot { display: none; }
  .account { margin-top: 0; flex-direction: row; justify-content: space-between; align-items: baseline; gap: 12px; }
  .main { padding: 16px; }
  .doc { padding: 20px 16px; }
  input[type=search] { min-width: 0; flex: 1; }
}

@media print {
  :root { color-scheme: light; --page: #fff; --surface: #fff; --surface-2: #f3f3f3; --ink: #000; --ink-2: #333;
          --muted: #666; --line: #ccc; --axis: #999; --accent: #000; --shadow: none; }
  .nav, .top, .toolbar, .no-print { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .card { border: 0; }
  .doc { padding: 0; max-width: none; }
  body { font-size: 11pt; }
  @page { margin: 18mm 16mm; }
}
