:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --seg-on: #e4e2da; --seg-on-ring: rgba(0, 0, 0, 0.14);
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-ink: #b42323;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --other: #b4b2a9;
  --cell-ok: #cfe9cf; --cell-unrec: #fde3a7; --cell-partial: #fbe0cf; --cell-missing: #f6c9c9;
  --cell-snap: #cde2fb; --cell-na: #ecebe6; --cell-current: #f3f2ee;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --seg-on: #41413d; --seg-on-ring: rgba(255, 255, 255, 0.28);
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255, 255, 255, 0.10); --accent: #3987e5; --good-ink: #0ca30c; --critical-ink: #e66767;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --other: #5f5e59;
    --cell-ok: #1d4a1d; --cell-unrec: #5a4610; --cell-partial: #5a3320; --cell-missing: #5c2222;
    --cell-snap: #1c3f6b; --cell-na: #262624; --cell-current: #232321;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --seg-on: #41413d; --seg-on-ring: rgba(255, 255, 255, 0.28);
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255, 255, 255, 0.10); --accent: #3987e5; --good-ink: #0ca30c; --critical-ink: #e66767;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --other: #5f5e59;
  --cell-ok: #1d4a1d; --cell-unrec: #5a4610; --cell-partial: #5a3320; --cell-missing: #5c2222;
  --cell-snap: #1c3f6b; --cell-na: #262624; --cell-current: #232321;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--ink-2); }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--good-ink); }
.hint-i { color: var(--muted); font-weight: 400; margin-left: 4px; cursor: pointer; background: none; border: 0; padding: 0 2px; font-size: inherit; line-height: 1; }
.hint-i:hover { color: var(--ink); }
.seg + .hint-i { margin-left: -3px; }   /* next to a switch: half the usual 14px gap */
.neg { color: var(--critical-ink); }
.hidden { display: none !important; }

header.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px;
  padding: 0 20px; height: 54px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; white-space: nowrap; }
.brand svg { width: 22px; height: 22px; }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
nav.tabs a {
  padding: 8px; border-radius: 8px; color: var(--ink-2); white-space: nowrap; font-weight: 500;
}
nav.tabs a:hover { background: var(--surface-2); text-decoration: none; }
/* the current page, like an active switch option: own fill, thin ring, full-strength bold text */
nav.tabs a.active { background: var(--seg-on); color: var(--ink); font-weight: 600; box-shadow: inset 0 0 0 1px var(--seg-on-ring); }
nav.tabs .badge { margin-left: 6px; }
.who { display: flex; align-items: center; gap: 10px; color: var(--ink-2); white-space: nowrap; font-size: 13px; }

main { padding: 18px 20px 60px; max-width: 1560px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.check-group { display: flex; flex-wrap: nowrap; align-items: center; gap: 4px 12px; }
.check-group label { white-space: nowrap; }
@media (max-width: 700px) { .check-group { flex-wrap: wrap; } }
.toolbar label { color: var(--ink-2); font-size: 13px; display: flex; align-items: center; gap: 6px; }

button, .btn {
  font: inherit; font-size: 13px; border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--critical-ink); }
button.ghost { border-color: transparent; background: transparent; }
button:disabled { opacity: .5; cursor: default; }
button.icon { padding: 5px 8px; }

select, input, textarea {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 8px; min-width: 0;
}
input[type="checkbox"] { padding: 0; }
input.num { text-align: right; }
textarea { width: 100%; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 6px 10px; background: var(--surface); color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--border); }
/* the active option must stand out in both themes: its own fill, a thin ring and full-strength text */
.seg button.on { background: var(--seg-on); color: var(--ink); font-weight: 600; box-shadow: inset 0 0 0 1px var(--seg-on-ring); }

.grid { display: grid; gap: 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); gap: 12px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { color: var(--ink-2); font-size: 12.5px; }
.tile .value { font-size: 24px; font-weight: 650; margin-top: 4px; letter-spacing: -0.01em; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
/* a tile whose figure is a warning: red throughout */
.tile.alert { background: color-mix(in srgb, var(--critical) 14%, var(--surface)); border-color: color-mix(in srgb, var(--critical) 55%, transparent); }
.tile.alert .label, .tile.alert .value, .tile.alert .sub { color: var(--critical-ink); }
/* Data health → Beta-testing: rows whose difference is big */
table.t tr.var-big td { background: color-mix(in srgb, var(--critical) 12%, transparent); }
table.t tr.var-small td { background: color-mix(in srgb, var(--warning) 16%, transparent); }
.tile.clickable { cursor: pointer; }
.tile.clickable:hover { border-color: var(--axis); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 14px; min-width: 0; }
.card-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.card-head .spacer { flex: 1; }
.card-note { color: var(--muted); font-size: 12px; margin-top: 8px; }
.chart { width: 100%; height: 360px; }
.chart.tall { height: 420px; }
.chart.short { height: 260px; }
.cols-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 14px; }
.cols-even { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
@media (max-width: 1000px) { .cols-2, .cols-even { grid-template-columns: minmax(0, 1fr); } }

.table-wrap { overflow: auto; max-width: 100%; }
.table-wrap.scroll { max-height: 560px; }
.table-wrap.scroll.tall { max-height: calc(100vh - 140px); }
table.t { border-collapse: collapse; width: 100%; font-size: 13px; }
table.t th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; padding: 7px 8px; border-bottom: 1px solid var(--axis); position: sticky; top: 0; background: var(--surface); z-index: 1; white-space: nowrap; }
table.t td { padding: 6px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
table.t th.num { text-align: right; }
table.t.bva .m0 { border-left: 1px solid var(--border); }
/* Performance pop-up: the left-out (automated) debits are shown dimmed; a row comes back to full strength on hover */
.dim-section .card-head, .dim-section > .small, .dim-section tbody tr { opacity: 0.55; }
.dim-section tbody tr:hover { opacity: 1; }
table.t.bva thead tr:nth-child(2) th { top: 29px; }
table.t tr.group td { background: var(--surface-2); font-weight: 600; }
table.t tr.sub td:first-child { padding-left: 26px; }
table.t tr.clickable { cursor: pointer; }
table.t tr.clickable:hover td { background: var(--surface-2); }
table.t tr.total td { font-weight: 650; border-top: 1px solid var(--axis); }
table.t th.sortable { cursor: pointer; }
table.t.nowrap td, table.t.nowrap th { white-space: nowrap; }
table.t.aligned td.lab { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
table.t.aligned th, table.t.aligned td { padding-left: 4px; padding-right: 4px; }
table.t.aligned th:first-child, table.t.aligned td:first-child { padding-left: 8px; }
table.t td.wrap { white-space: normal; min-width: 220px; }
table.t tr.excluded td { opacity: .45; text-decoration: line-through; }
table.t td input { width: 100%; padding: 3px 6px; }
table.t td.breach { background: color-mix(in srgb, var(--critical) 16%, transparent); }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; font-weight: 500; }
.badge.good { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good-ink); }
.badge.warn { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--ink); }
.badge.bad { background: color-mix(in srgb, var(--critical) 15%, transparent); color: var(--critical-ink); }
.badge.info { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex: none; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-line { flex-wrap: nowrap; overflow: hidden; white-space: nowrap; }
.legend-line span { flex: none; }
.legend-more { flex: none; padding: 0 4px; font-size: 12px; color: var(--accent); }
.legend-line .legend-hatch { margin-left: auto; padding-left: 12px; }

.dropzone { border: 1.5px dashed var(--axis); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--ink-2); background: var(--surface); cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.dropzone b { color: var(--ink); }

.coverage td.acc, .coverage th.acc { width: 1%; white-space: nowrap; padding-right: 18px; }
.coverage td.cell { min-width: 30px; height: 24px; padding: 0; border: 2px solid var(--surface); border-radius: 4px; text-align: center; vertical-align: middle; line-height: 1; font-size: 10px; color: var(--ink-2); }
.coverage td.cell { cursor: pointer; }
.coverage td.cell:hover, .coverage td.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* the row under the pointer: a tint over its cells and name (status colours show through), so a month is easy to
   trace back to its account; the cell itself keeps its blue outline; the entity code, kept only on an entity's
   first row, shows faintly on the hovered one */
.coverage td.acc .ent-ghost { visibility: hidden; }
.coverage tbody tr:hover td.cell { background-image: linear-gradient(color-mix(in srgb, var(--accent) 22%, transparent), color-mix(in srgb, var(--accent) 22%, transparent)); }
.coverage tbody tr:hover td.acc { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--ink); }
.coverage tbody tr:hover td.acc .ent-ghost { visibility: visible; color: var(--muted); }
.cell-tip { position: absolute; z-index: 50; width: 320px; max-width: calc(100vw - 16px); background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 10px 12px; font-size: 13px; }
.cell-tip-head { display: flex; align-items: center; gap: 8px; }
.cell-tip-head b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-tip-sub { color: var(--ink-2); font-size: 12px; margin-top: 2px; display: flex; gap: 6px; align-items: center; }
.cell-tip p { margin: 8px 0; line-height: 1.45; }
.cell-tip-links { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; }
.cell.ok { background: var(--cell-ok); }
.cell.unreconciled { background: var(--cell-unrec); }
.cell.partial { background: var(--cell-partial); }
.cell.missing { background: var(--cell-missing); }
.cell.snapshot { background: var(--cell-snap); }
.cell.n\/a { background: var(--cell-na); }
.cell.current { background: var(--cell-current); }

.split { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: minmax(0, 1fr); } }
.tree { max-height: calc(100vh - 160px); overflow: auto; position: sticky; top: 70px; }
.tree .ent { padding: 7px 8px; font-weight: 600; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px; }
.tree .acc { padding: 5px 8px 5px 20px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px; color: var(--ink-2); }
.tree .ent:hover, .tree .acc:hover { background: var(--surface-2); }
.tree .sel { background: var(--surface-2); color: var(--ink); }
.tree .inactive { opacity: .5; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--ink); padding: 0; max-width: min(96vw, 1180px); width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog.narrow { max-width: min(96vw, 560px); }
dialog.wide { max-width: min(98vw, 1760px); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.dlg-head h2 { flex: 1; font-size: 16px; }
.dlg-body { padding: 16px 18px; max-height: calc(100vh - 170px); overflow: auto; }
.dlg-foot { display: flex; gap: 10px; justify-content: flex-end; align-items: center; padding: 12px 18px; border-top: 1px solid var(--border); }
.dlg-foot .spacer { flex: 1; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.form label.wide { grid-column: 1 / -1; }
.form label.check { flex-direction: row; align-items: center; }

.msg { padding: 9px 12px; border-radius: 8px; margin: 8px 0; font-size: 13px; }
.msg.warn { background: color-mix(in srgb, var(--warning) 18%, transparent); }
.msg.bad { background: color-mix(in srgb, var(--critical) 13%, transparent); }
.msg.good { background: color-mix(in srgb, var(--good) 13%, transparent); }
.msg.info { background: color-mix(in srgb, var(--accent) 10%, transparent); }

.ms { position: relative; }
.ms-panel { position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.16); padding: 8px; width: 330px; max-height: 420px; overflow: auto; }
.ms-panel label { display: flex; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; align-items: center; font-size: 13px; color: var(--ink); }
.ms-panel label:hover { background: var(--surface-2); }
.ms-panel .row { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px 4px 8px; border-bottom: 1px solid var(--grid); margin-bottom: 6px; }

.color-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 24px; }
.color-pick { width: 720px; }
.pick-grid { display: grid; grid-template-columns: repeat(32, 1fr); gap: 3px; margin-top: 10px; justify-items: center; }
.pick-grid .swatch { width: 18px; height: 18px; border-radius: 4px; border-width: 1px; position: relative; }
.pick-grid .swatch.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--ink); }
.pick-grid .taken-mark { font-size: 6px; }
@media (max-width: 760px) { .pick-grid { grid-template-columns: repeat(16, 1fr); } .pick-grid .swatch { width: 16px; height: 16px; } }
.taken-mark { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 8px; font-weight: 700; color: #fff; text-shadow: 0 0 2px rgba(0,0,0,.6); }
.color-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--grid); }
.color-row b { font-size: 13px; white-space: nowrap; }
#control-card .color-grid { grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }
#control-card .seg button { padding: 3px 8px; font-size: 12px; }
.swatches { display: flex; gap: 5px; }
.swatch { width: 20px; height: 20px; padding: 0; border-radius: 50%; border: 2px solid transparent; justify-content: center; font-size: 10px; color: var(--ink-2); }
.swatch.auto { background: var(--surface-2); border-color: var(--border); }
.pick-grid .swatch:has(.taken-mark) { opacity: .45; }
.swatch.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); opacity: 1; }
.swatch:hover { transform: scale(1.12); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 10px; z-index: 100; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 90vw; }
.toast.bad { background: var(--critical); color: #fff; }

.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--axis); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: 6px; }

@media (max-width: 700px) {
  header.top { padding: 0 12px; gap: 10px; }
  .brand span { display: none; }
  .who .name { display: none; }
  main { padding: 14px 16px 60px; }
  .chart { height: 300px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile .value { font-size: 20px; }
}

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login h1 { font-size: 19px; margin: 10px 0 4px; }
.login form { display: grid; gap: 10px; margin-top: 18px; }
.login input { padding: 9px 10px; font-size: 14px; }
.login button { justify-content: center; padding: 9px; font-size: 14px; }

/* data health */
.health-item { padding: 12px 0; border-top: 1px solid var(--grid); }
.health-item:first-of-type { border-top: 0; }
.health-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.health-head .spacer { flex: 1; }
.health-items { margin: 6px 0 2px 18px; padding: 0; font-size: 12.5px; color: var(--ink-2); line-height: 1.55; }
#health-badge { margin-left: 6px; }

/* bold-on-select without a width jump: an invisible bold copy of the label sets each option's width */
.seg button[data-label]::after, nav.tabs .lbl::after {
  content: attr(data-label); display: block; height: 0; overflow: hidden; visibility: hidden; font-weight: 600; pointer-events: none;
}
nav.tabs a { display: inline-flex; align-items: center; }   /* centre the label (and badge) on the bar */
nav.tabs .lbl { display: inline-flex; flex-direction: column; }
.seg button[data-label] { flex-direction: column; align-items: center; gap: 0; }   /* the copy goes under the label, not beside it */
