:root {
  color-scheme: light;
  --page: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f1f1ef;
  --ink: #191919;
  --ink-2: #5f5f5f;
  --ink-3: #8a8a8a;
  --line: #e4e4e0;
  --grid: #ececec;
  --axis: #c2c2c2;
  --accent: #1f5fae;
  --accent-ink: #ffffff;
  --accent-soft: #e6eef9;
  --series: #257de0;
  --goal: #8a8a8a;
  --good: #0a7d1f;
  --good-bg: #e5f4e7;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --bad: #b42323;
  --bad-bg: #fbe7e7;
  --info-bg: #eef2f7;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 1px rgba(0,0,0,.03);
  --radius: 10px;
  --heat-0: #f2f7fd; --heat-1: #cce3fd; --heat-2: #9dc8f7; --heat-3: #6aabf1; --heat-4: #338ced; --heat-5: #1b64be;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0f0f0f; --surface: #191919; --surface-2: #232323; --ink: #efefef; --ink-2: #a8a8a8; --ink-3: #7c7c7c;
    --line: #2e2e2e; --grid: #2a2a2a; --axis: #474747; --accent: #5b9ef0; --accent-ink: #0b0b0b; --accent-soft: #1b2a3d;
    --series: #338ced; --goal: #9c9c9c; --good: #53c556; --good-bg: #16301a; --warn: #fbb315; --warn-bg: #3a2c08;
    --bad: #f07070; --bad-bg: #3d1717; --info-bg: #1f252d; --shadow: none;
    --heat-0: #1a2533; --heat-1: #0f4a96; --heat-2: #1757ac; --heat-3: #2370cd; --heat-4: #338ced; --heat-5: #6aabf1;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f0f0f; --surface: #191919; --surface-2: #232323; --ink: #efefef; --ink-2: #a8a8a8; --ink-3: #7c7c7c;
  --line: #2e2e2e; --grid: #2a2a2a; --axis: #474747; --accent: #5b9ef0; --accent-ink: #0b0b0b; --accent-soft: #1b2a3d;
  --series: #338ced; --goal: #9c9c9c; --good: #53c556; --good-bg: #16301a; --warn: #fbb315; --warn-bg: #3a2c08;
  --bad: #f07070; --bad-bg: #3d1717; --info-bg: #1f252d; --shadow: none;
  --heat-0: #1a2533; --heat-1: #0f4a96; --heat-2: #1757ac; --heat-3: #2370cd; --heat-4: #338ced; --heat-5: #6aabf1;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 1.45rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
h3 { font-size: .95rem; margin: 0 0 6px; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; padding: 4px 10px 16px; font-size: 1.02rem; display: flex; gap: 8px; align-items: center; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: .8rem; flex: none; }
.nav-group { margin: 14px 0 4px; padding: 0 10px; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 7px; color: var(--ink); text-decoration: none; font-size: .93rem; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge { background: var(--bad-bg); color: var(--bad); border-radius: 999px; padding: 0 7px; font-size: .75rem; font-weight: 600; }
.main { padding: 24px 28px 60px; min-width: 0; max-width: 1400px; }
.topbar { display: none; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.side-foot { margin-top: 18px; padding: 10px; border-top: 1px solid var(--line); font-size: .85rem; }
.side-foot .who { font-weight: 600; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 30; transform: translateX(-105%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .side.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
  .main { padding: 16px 16px 60px; }
}

/* ---------- controls ---------- */
.btn { border: 1px solid var(--line); background: var(--surface); padding: 7px 13px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: default; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=month], input[type=url], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0; }
textarea { width: 100%; min-height: 70px; }
label.field { display: grid; gap: 4px; font-size: .88rem; color: var(--ink-2); }
label.field > span { font-weight: 500; }
label.check { display: flex; gap: 8px; align-items: center; font-size: .92rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; font-size: .88rem; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 22px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 14px 10px; box-shadow: var(--shadow); text-decoration: none; color: inherit; display: block; min-width: 0; }
a.tile:hover { border-color: var(--axis); }
.tile .label { font-size: .84rem; color: var(--ink-2); display: flex; justify-content: space-between; gap: 6px; }
.tile .dept { font-size: .72rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.tile .value { font-size: 1.65rem; font-weight: 650; letter-spacing: -0.02em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: .8rem; color: var(--ink-2); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.delta-up { color: var(--good); } .delta-down { color: var(--bad); } .delta-flat { color: var(--ink-2); }
.chip { display: inline-flex; gap: 4px; align-items: center; border-radius: 999px; padding: 1px 8px; font-size: .76rem; font-weight: 600; white-space: nowrap; }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.info { background: var(--info-bg); color: var(--ink-2); }
.section { margin: 26px 0 12px; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.section h2 { margin: 0; }
.metric-card .head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.metric-card .big { font-size: 1.35rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.metric-card .tools { display: flex; gap: 4px; }
.iconbtn { border: 0; background: none; color: var(--ink-2); cursor: pointer; padding: 3px 6px; border-radius: 6px; font-size: .8rem; }
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }
.banner { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.banner.warn { background: var(--warn-bg); color: var(--ink); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.info { background: var(--info-bg); border: 1px solid var(--line); }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; min-width: 120px; }
.progress > div { height: 100%; background: var(--good); border-radius: 99px; }

/* ---------- charts ---------- */
.chart { position: relative; margin-top: 8px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series); opacity: .08; }
.chart .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .dot.unverified { fill: var(--surface); stroke: var(--series); stroke-width: 2; }
.chart .bar { fill: var(--series); }
.chart .bar.unverified { fill: var(--surface); stroke: var(--series); stroke-width: 1.5; }
.chart .goal { stroke: var(--goal); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .goal-label { fill: var(--ink-2); font-size: 11px; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.tooltip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 4px 14px rgba(0,0,0,.12); border-radius: 8px; padding: 7px 10px; font-size: .82rem; z-index: 5; min-width: 130px; max-width: 260px; }
.tooltip .t-val { font-weight: 650; font-size: .95rem; }
.legend { display: flex; gap: 14px; font-size: .78rem; color: var(--ink-2); margin-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.legend .k-ok { background: var(--series); }
.legend .k-un { border: 2px solid var(--series); background: var(--surface); }
.legend .k-goal { width: 16px; height: 0; border-top: 2px dashed var(--goal); border-radius: 0; vertical-align: 3px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-weight: 600; color: var(--ink-2); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.heat { text-align: center; font-variant-numeric: tabular-nums; border-left: 2px solid var(--surface); }
.heat-0 { background: var(--heat-0); } .heat-1 { background: var(--heat-1); } .heat-2 { background: var(--heat-2); }
.heat-3 { background: var(--heat-3); color: #fff; } .heat-4 { background: var(--heat-4); color: #fff; } .heat-5 { background: var(--heat-5); color: #fff; }
td.unv { box-shadow: inset 0 -2px 0 var(--warn); }
.sticky-col { position: sticky; left: 0; background: var(--surface); z-index: 1; }
th.sticky-col { background: var(--surface-2); z-index: 2; }

/* ---------- forms: entry ---------- */
.entry-row { display: grid; grid-template-columns: minmax(160px, 1.3fr) 130px minmax(140px, 1fr) minmax(120px, 1fr); gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.entry-row:last-child { border-bottom: 0; }
.entry-row .hint { font-size: .78rem; color: var(--ink-3); }
.entry-row .warn-msg { font-size: .8rem; color: var(--warn); font-weight: 500; }
.entry-row input.changed { border-color: var(--accent); background: var(--accent-soft); }
.entry-row input.flagged { border-color: var(--warn); }
@media (max-width: 700px) { .entry-row { grid-template-columns: 1fr 1fr; } .entry-row .hint-col { grid-column: 1 / -1; } }

/* ---------- misc ---------- */
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 9px; z-index: 50; font-size: .9rem; max-width: calc(100vw - 32px); }
.toast.error { background: var(--bad); color: #fff; }
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--surface); color: var(--ink); width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 40px); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog .d-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
dialog .d-body { padding: 16px 18px; display: grid; gap: 12px; overflow-y: auto; max-height: calc(100vh - 170px); }
dialog .d-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 10px 12px; border-radius: 8px; word-break: break-all; user-select: all; font-size: .95rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .83rem; }
pre { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; white-space: pre; }
.finding { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); align-items: start; }
.finding:last-child { border-bottom: 0; }
.finding.done { opacity: .62; }
.finding .where { font-size: .8rem; color: var(--ink-2); }
.finding .detail { font-size: .85rem; color: var(--ink-2); margin-top: 3px; }
@media (max-width: 700px) { .finding { grid-template-columns: 1fr; } }
.status-pill { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); font-weight: 600; white-space: nowrap; }
.status-pill.done { background: var(--good-bg); color: var(--good); }
.status-pill.in_progress { background: var(--accent-soft); color: var(--accent); }
.status-pill.on_hold { background: var(--warn-bg); color: var(--warn); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); display: grid; gap: 14px; }
.login input { width: 100%; }
.empty { padding: 26px; text-align: center; color: var(--ink-2); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .9rem; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.funnel-row { display: grid; grid-template-columns: 130px 1fr 64px; gap: 10px; align-items: center; margin: 5px 0; font-size: .86rem; }
.funnel-bar { height: 18px; background: var(--series); border-radius: 0 4px 4px 0; min-width: 2px; }
.funnel-track { background: var(--surface-2); border-radius: 0 4px 4px 0; }
.err-list { margin: 6px 0 0; padding-left: 18px; font-size: .85rem; color: var(--bad); }
.skip { position: absolute; left: -999px; } .skip:focus { left: 10px; top: 10px; z-index: 99; background: var(--surface); padding: 8px; }
@media print { .side, .topbar, .filters, .tools, .btn { display: none !important; } .app { display: block; } .card, .tile { break-inside: avoid; } }

/* fixes after visual review */
.app > div { min-width: 0; }
a.btn { text-decoration: none; display: inline-block; }
.metric-card .head > div:first-child { flex: 1; min-width: 0; }
td.unv { box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--warn) 70%, transparent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .heat-5, :root:not([data-theme="light"]) .heat-4 { color: #0b0b0b; } }
:root[data-theme="dark"] .heat-5, :root[data-theme="dark"] .heat-4 { color: #0b0b0b; }
