.viz-root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.22);
  --wash: rgba(11, 11, 11, 0.05);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --other: #c3c2b7;
  --up-good: #006300;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --accent: #1c5cab;
  --on-accent: #ffffff;
}
@media (prefers-color-scheme: dark) {
  .viz-root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.24);
    --wash: rgba(255, 255, 255, 0.07);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --other: #52514e;
    --up-good: #0ca30c;
    --accent: #3987e5;
    --on-accent: #0b0b0b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 14px; line-height: 1.45; background: var(--page); color: var(--text-primary); min-height: 100vh; }
button, select, input, textarea { font: inherit; color: inherit; }
h1 { font-size: 20px; font-weight: 650; margin: 0; }
h2 { font-size: 14px; font-weight: 600; margin: 0; }
p { margin: 0 0 10px; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
.boot { padding: 40px; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface-1); border-right: 1px solid var(--border); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 15px; padding: 4px 10px 14px; }
.sidetop { display: flex; align-items: center; gap: 12px; }
.menubtn { display: none; align-items: center; gap: 8px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface-1); padding: 7px 12px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.menubtn .navcount { margin-left: 0; }
.sidemenu { display: flex; flex-direction: column; gap: 4px; flex: 1; min-height: 0; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: block; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--text-secondary); }
.nav a:hover { background: var(--wash); }
.nav a[aria-current="page"] { background: var(--wash); color: var(--text-primary); font-weight: 600; }
.nav .section { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); padding: 14px 10px 4px; }
.account-box { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin: 0 0 10px; }
.account-box .who { font-weight: 600; overflow-wrap: anywhere; margin-bottom: 2px; }
.me { margin-top: auto; border-top: 1px solid var(--border); padding: 12px 10px 0; }
.me .who { font-weight: 600; overflow-wrap: anywhere; }
.me .links { display: flex; gap: 12px; margin-top: 6px; }
.main { padding: 24px 24px 56px; min-width: 0; }
.wrap { max-width: 1180px; margin: 0 auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.page-intro { color: var(--text-secondary); max-width: 75ch; margin-bottom: 18px; }

/* ---------- controls ---------- */
.btn { border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface-1); padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--wash); }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; color: var(--text-primary); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { border-color: var(--critical); color: var(--critical); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.link { border: 0; background: none; padding: 0; color: var(--text-secondary); cursor: pointer; text-decoration: underline; font-size: inherit; }
.field { display: block; margin-bottom: 14px; }
.field > .label { display: block; font-weight: 600; margin-bottom: 4px; }
.field > .hint { display: block; color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.input, select.input { width: 100%; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface-1); padding: 8px 10px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline .input { flex: 1; min-width: 0; }
.choice { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; cursor: pointer; }
.choice input { margin-top: 3px; flex: none; }
.choice .hint { display: block; color: var(--text-muted); font-size: 12px; }
.checklist { border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; max-height: 220px; overflow-y: auto; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend { font-weight: 600; padding: 0; margin-bottom: 4px; }
details.help { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin-bottom: 14px; }
details.help summary { cursor: pointer; font-weight: 600; }
details.help ol { margin: 8px 0 2px; padding-left: 20px; }
details.help li { margin-bottom: 4px; }
details.help ul { margin: 8px 0 2px; padding-left: 20px; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
textarea.input { resize: vertical; min-height: 64px; }
.steps { margin: 0 0 14px; padding-left: 20px; }
.steps li { margin-bottom: 8px; }
.key { background: var(--wash); border-radius: 6px; padding: 2px 6px; font-size: 13px; user-select: all; }
.codes { display: grid; grid-template-columns: repeat(2, max-content); gap: 6px 28px; font-size: 14px; margin: 0 0 14px; user-select: all; }
.notes-list { display: grid; gap: 10px; max-height: 320px; overflow-y: auto; }
.note { border-left: 3px solid var(--grid); padding-left: 10px; }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- surfaces ---------- */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card .sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--text-muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td { padding: 9px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--wash); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num { text-align: right; }
.nowrap { white-space: nowrap; }
.empty { color: var(--text-muted); padding: 28px 0; text-align: center; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; white-space: nowrap; color: var(--text-secondary); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.dot.warn { background: var(--warning); }
.dot.bad { background: var(--critical); }
.dot.off { background: var(--other); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; font-size: 12px; color: var(--text-secondary); }
.notice { border: 1px solid var(--border-strong); border-left: 4px solid var(--warning); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.notice.bad { border-left-color: var(--critical); }
.notice.good { border-left-color: var(--good); }
.error-text { color: var(--critical); margin: 0 0 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 14px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.actions-list { display: grid; gap: 8px; }
.action-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.action-row .what { font-weight: 600; }
.result-list { list-style: none; margin: 0 0 12px; padding: 0; }
.result-list li { display: flex; gap: 8px; align-items: center; padding: 3px 0; }
.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }

/* ---------- dialogs and toasts ---------- */
dialog { border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface-1); color: var(--text-primary); padding: 0; width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog.wide { width: min(680px, calc(100vw - 32px)); }
dialog[open] { overflow: hidden; }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 50px); }
.dlg-body { flex: 1 1 auto; min-height: 0; }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px 0; }
.dlg-head h2 { font-size: 16px; }
.dlg-body { padding: 14px 18px 4px; overflow-y: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 30; max-width: min(360px, calc(100vw - 32px)); }
.toast { background: var(--text-primary); color: var(--surface-1); border-radius: 8px; padding: 10px 14px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2); }
#tooltip { position: fixed; z-index: 20; pointer-events: none; display: none; min-width: 120px; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14); font-size: 12px; }
#tooltip .v { font-size: 15px; font-weight: 650; }
#tooltip .k { color: var(--text-secondary); }

/* ---------- sign-in pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: min(420px, 100%); padding: 24px; }
.auth h1 { margin-bottom: 6px; }
.auth .btn.primary { width: 100%; padding: 10px; margin-top: 4px; }

/* ---------- dashboard ---------- */
.sync { display: flex; align-items: center; gap: 12px; color: var(--text-secondary); font-size: 13px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 14px 0 20px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-1); }
.seg button { border: 0; background: transparent; padding: 7px 12px; cursor: pointer; color: var(--text-secondary); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { background: var(--wash); }
.seg button[aria-pressed="true"] { background: var(--text-primary); color: var(--surface-1); font-weight: 600; }
.pick { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.storepick { position: relative; display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.storebtn { display: inline-flex; align-items: center; gap: 8px; max-width: min(280px, 70vw); border: 1px solid var(--border); border-radius: 8px; background: var(--surface-1); padding: 6px 10px; color: var(--text-primary); cursor: pointer; }
.storebtn > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.storebtn:hover { background: var(--wash); }
.storebtn:disabled { opacity: 0.55; cursor: default; }
.storebtn .caret { color: var(--text-muted); font-size: 11px; }
.storepanel { position: absolute; top: calc(100% + 6px); left: 0; z-index: 15; width: min(320px, calc(100vw - 32px)); background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16); padding: 10px 12px; }
.storepanel[hidden] { display: none; }
.clearbtn { padding: 6px 10px; border-color: var(--border); }
.storepanel .choice { align-items: center; padding: 6px 4px; border-radius: 6px; }
.storepanel .choice:hover { background: var(--wash); }
.storepanel .choice input { margin: 0; width: 16px; height: 16px; }
.storepanel .input { margin-bottom: 8px; }
.storeall { font-weight: 600; border-bottom: 1px solid var(--grid); padding-bottom: 4px; margin-bottom: 4px; }
.storelist { max-height: min(300px, 45vh); overflow-y: auto; }
.storefoot { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid var(--grid); margin-top: 6px; padding-top: 8px; }
.storefoot .bad { color: var(--critical); }
.pick input, .pick select { border: 1px solid var(--border); border-radius: 8px; background: var(--surface-1); padding: 6px 10px; color: var(--text-primary); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 12px; }
.kpi.hero { grid-column: span 2; }
.kpi .label { color: var(--text-secondary); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 600; margin: 4px 0 2px; white-space: nowrap; }
.kpi.hero .value { font-size: 48px; line-height: 1.1; }
.delta { font-size: 12px; color: var(--text-muted); }
.delta b { font-weight: 600; }
.delta .good { color: var(--up-good); }
.delta .bad { color: var(--critical); }
.chg { font-weight: 600; }
.chg.good { color: var(--up-good); }
.chg.bad { color: var(--critical); }
.sortbtn { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; white-space: nowrap; }
.sortbtn:hover { color: var(--text-primary); text-decoration: underline; }
th[aria-sort] .sortbtn { color: var(--text-primary); font-weight: 600; }
.comparenote { margin: 0 0 12px; }
table.heat { width: 100%; min-width: 300px; table-layout: fixed; border-collapse: separate; border-spacing: 2px; }
table.heat th { border: 0; padding: 0 2px 2px; font-size: 11px; font-weight: 500; color: var(--text-muted); text-align: center; white-space: nowrap; overflow: hidden; }
table.heat tbody th { width: 34px; text-align: left; padding: 0 4px 0 0; }
table.heat td { padding: 0; border: 0; }
.heatcell { display: block; position: relative; width: 100%; height: 24px; border: 0; padding: 0; border-radius: 4px; background: var(--wash); cursor: pointer; overflow: hidden; }
.heatcell span { position: absolute; inset: 0; background: var(--series-1); }
.heatcell:hover, .heatcell:focus-visible { outline: 2px solid var(--text-primary); outline-offset: -2px; }
.heatinfo { margin: 10px 0 0; font-size: 13px; color: var(--text-secondary); min-height: 1.4em; }
.monthstep { display: inline-flex; align-items: center; gap: 8px; }
.monthstep .btn { padding: 5px 12px; font-size: 16px; line-height: 1.2; }
.monthname { min-width: 9.5em; text-align: center; font-weight: 600; }
.tbar { position: relative; height: 10px; min-width: 90px; background: var(--wash); border-radius: 5px; }
.tbar.empty { background: none; }
.tbar .fill { height: 10px; background: var(--series-1); border-radius: 5px; min-width: 2px; }
.tbar .fill.done { background: var(--good); }
.tbar .mark { position: absolute; top: -3px; width: 2px; height: 16px; background: var(--text-primary); border-radius: 1px; }
.targetlist { display: grid; gap: 8px; margin-top: 12px; max-height: min(420px, 55vh); overflow-y: auto; padding-right: 4px; }
.targetrow { display: grid; grid-template-columns: minmax(0, 1fr) 160px; align-items: center; gap: 10px; }
.targetrow > span:first-child { overflow-wrap: anywhere; }
.targetrow .money { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
table.report tfoot td { font-weight: 600; border-top: 2px solid var(--axis); border-bottom: 0; }
.navcount { display: inline-block; min-width: 18px; margin-left: 8px; padding: 1px 6px; border-radius: 9px; background: var(--critical); color: #fff; font-size: 11px; font-weight: 700; text-align: center; vertical-align: 1px; }
.dayname { min-width: 15em; }
.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.alertitem { padding: 10px 0; border-bottom: 1px solid var(--grid); display: grid; gap: 4px; }
.alertitem:last-child { border-bottom: 0; padding-bottom: 0; }
.alertitem:first-of-type { padding-top: 0; }
.alertitem.done { color: var(--text-secondary); }
.alertitem .what { font-weight: 600; }
.alerthead { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.newtag { background: var(--accent); color: var(--on-accent); border-radius: 9px; padding: 1px 8px; font-size: 11px; font-weight: 700; }
.emailpreview { margin-top: 12px; }
.emailpreview pre { margin: 8px 0 0; padding: 12px; background: var(--wash); border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.grid { display: grid; gap: 12px; margin-bottom: 12px; }
.two { grid-template-columns: 1.2fr 1fr; }
.stack { display: grid; gap: 12px; align-content: start; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; outline-offset: 4px; }
.tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.datalabel { fill: var(--text-secondary); font-size: 11px; font-weight: 600; }
.barcell { width: 26%; min-width: 90px; }
.hbar { height: 10px; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.segbar { display: flex; gap: 2px; height: 8px; margin: 4px 0 12px; }
.segbar span { display: block; height: 8px; border-radius: 4px; min-width: 3px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; }
.loading .card { opacity: 0.6; transition: opacity 0.15s; }
.notes { color: var(--text-muted); font-size: 12px; margin-top: 16px; max-width: 80ch; }

@media (max-width: 900px) {
  /* minmax(0, ...) lets the page be exactly as wide as the screen; a plain 1fr grows to fit the widest item. */
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 10px 12px; }
  .sidetop { justify-content: space-between; }
  .brand { padding: 2px 6px; }
  .menubtn { display: inline-flex; }
  .sidemenu { display: none; flex: none; padding-top: 10px; }
  .side.open .sidemenu { display: flex; }
  .nav a { padding: 11px 10px; }
  .me { margin-top: 8px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding-top: 8px; }
  .me .links { margin-top: 0; }
  .main { padding: 16px 16px 48px; }
  .card { overflow-x: auto; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi.hero { grid-column: 1 / -1; }
  .kpi.hero .value { font-size: 40px; }
  .two { grid-template-columns: minmax(0, 1fr); }
  .three { grid-template-columns: minmax(0, 1fr); }
  .pair { grid-template-columns: 1fr; }
  .account-box { margin-bottom: 6px; }
  .dayname { min-width: 0; }
}

/* Phones: the choices above the figures stack into two tidy columns instead of running off the side. */
@media (max-width: 640px) {
  .filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
  .filters > * { min-width: 0; }
  .filters > .seg, .filters > .wide, .filters > .monthstep, .filters > span { grid-column: 1 / -1; }
  .seg { display: flex; }
  .seg button { flex: 1 1 auto; padding: 9px 4px; white-space: nowrap; }
  .pick { display: flex; }
  .pick input, .pick select { flex: 1; min-width: 0; width: 100%; padding: 8px; }
  .storepick { display: flex; }
  .storebtn { flex: 1; min-width: 0; max-width: none; justify-content: space-between; padding: 8px 10px; }
  .filters .btn { white-space: normal; text-align: center; padding: 8px 10px; }
  .monthstep { display: flex; justify-content: space-between; }
  .monthname { min-width: 0; flex: 1; }
  .sync { flex-wrap: wrap; gap: 8px; }
  .opt { display: none; }
  .kpi .value { font-size: 22px; }
  .kpi.hero .value { font-size: 38px; }
  th, td { padding-left: 6px; padding-right: 6px; }
  .targetrow { grid-template-columns: minmax(0, 1fr) 130px; }
}

/* ---------- printing (the monthly report) ---------- */
@media print {
  .side, .filters, #toasts, #tooltip, .btn { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .card { border-color: #999; break-inside: avoid; }
  .scroll { overflow: visible; }
  body { background: #fff; color: #000; }
}
