:root {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #151b23;
  --surface-2: #1b222c;
  --input-bg: #10151c;
  --border: #262f3b;
  --border-strong: #364252;
  --text: #e6edf3;
  --text-2: #aab5c2;
  --muted: #7c8898;
  --side: #0a0e13;
  --side-2: #161d26;
  --side-text: #aab5c2;
  --side-muted: #6c798a;
  --side-line: rgba(255, 255, 255, .06);
  --accent: #3987e5;
  --accent-hover: #2a78d6;
  --accent-ink: #7ab1f0;
  --accent-soft: rgba(57, 135, 229, .16);
  --danger: #f07171;
  --danger-soft: rgba(240, 113, 113, .12);
  --danger-line: rgba(240, 113, 113, .35);
  --warn: #efb45c;
  --warn-soft: rgba(239, 180, 92, .12);
  --warn-line: rgba(239, 180, 92, .32);
  --ok: #4cc38a;
  --ok-soft: rgba(76, 195, 138, .14);
  --full-soft: rgba(217, 89, 38, .18);
  --neutral-soft: rgba(255, 255, 255, .07);
  --hover-soft: rgba(255, 255, 255, .06);
  --row-hover: rgba(57, 135, 229, .07);
  --focus-ring: rgba(57, 135, 229, .35);
  --overlay: rgba(0, 0, 0, .62);
  --tip-bg: #252f3c;
  --tip-text: #f2f5f8;
  --toast-bg: #252f3c;
  --toast-ok: #17432f;
  --login-bg: radial-gradient(1200px 600px at 20% -10%, #1b2a40 0%, #0d1117 60%);
  --series-1: #3987e5;
  --series-2: #d95926;
  --gridline: #212a35;
  --hover-band: rgba(57, 135, 229, .10);
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 0 0 1px rgba(255, 255, 255, .015);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, .55);
  --stage-0: #e5b53c; --stage-1: #e5b53c; --stage-2: #4fb57a; --stage-3: #3987e5; --stage-4: #d9679b; --stage-5: #2ea596;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --input-bg: #ffffff;
  --border: #dfe3e9;
  --border-strong: #c6ccd5;
  --text: #16202c;
  --text-2: #4d5866;
  --muted: #6b7684;
  --side: #14263d;
  --side-2: #1b3150;
  --side-text: #c7d3e3;
  --side-muted: #8fa3bd;
  --side-line: rgba(255, 255, 255, .08);
  --accent: #2a78d6;
  --accent-hover: #1c5cab;
  --accent-ink: #1c5cab;
  --accent-soft: #e7f0fb;
  --danger: #c93636;
  --danger-soft: #fdecec;
  --danger-line: #f3c4c4;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --warn-line: #f1d9a6;
  --ok: #17794f;
  --ok-soft: #e4f5ec;
  --full-soft: #fff1e6;
  --neutral-soft: #eef0f3;
  --hover-soft: rgba(0, 0, 0, .05);
  --row-hover: #f4f8fd;
  --focus-ring: rgba(42, 120, 214, .18);
  --overlay: rgba(15, 23, 35, .45);
  --tip-bg: #16202c;
  --tip-text: #ffffff;
  --toast-bg: #16202c;
  --toast-ok: #17392a;
  --login-bg: linear-gradient(160deg, #14263d, #24466f);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --gridline: #e8ebef;
  --hover-band: rgba(42, 120, 214, .07);
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, .25);
  --stage-0: #f6c343; --stage-1: #f6c343; --stage-2: #6cc28a; --stage-3: #5b9be6; --stage-4: #e97fb0; --stage-5: #37b3a4;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; }
a { color: var(--accent-ink); }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 13.5px; margin: 0 0 12px; font-weight: 650; color: var(--text); letter-spacing: .01em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.ic { flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { color: var(--danger); border-color: var(--danger-line); background: transparent; }
.btn.danger-ghost:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); padding-left: 6px; }
.btn.ghost:hover { background: var(--hover-soft); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; height: 40px; }
.icon-btn { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 6px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--hover-soft); color: var(--text); }
.icon-btn.light { color: var(--side-text); }
.icon-btn.light:hover { background: rgba(255,255,255,.1); color: #fff; }
.link-btn { border: 0; background: none; color: var(--accent-ink); cursor: pointer; font: inherit; font-size: 12px; padding: 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font: inherit; font-size: 13px; text-decoration: none; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent-ink); }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--login-bg); }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border-radius: 14px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.login-err { color: var(--danger); margin: 0; min-height: 1em; font-size: 13px; }

/* ---------- shell ---------- */
.shell { display: flex; height: 100vh; }
.side { width: 248px; flex: none; background: var(--side); border-right: 1px solid var(--side-line); color: var(--side-text); display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 14px; color: #fff; text-decoration: none; }
.brand b { display: block; font-size: 15px; }
.brand small { display: block; font-size: 11px; letter-spacing: .12em; color: var(--side-muted); }
.brand.big { color: var(--text); padding: 0 0 6px; }
.brand.big small { color: var(--muted); }
.logo { width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.nav { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.nav-top { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 7px; background: none; color: var(--side-text); font: inherit; text-decoration: none; cursor: pointer; text-align: left; }
.nav-top:hover { background: var(--side-2); color: #fff; }
.nav-top.active { background: var(--side-2); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-top .caret { margin-left: auto; transition: transform .15s; display: flex; }
.nav-group.open .caret { transform: rotate(90deg); }
.nav-kids { display: none; padding: 2px 0 6px 28px; }
.nav-group.open .nav-kids { display: block; }
.nav-kids a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--side-text); text-decoration: none; font-size: 13px; }
.nav-kids a:hover { color: #fff; background: var(--side-2); }
.nav-kids a.active { color: #fff; background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.side-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--side-line); }
.who b { display: block; color: #fff; font-size: 13px; }
.who small { color: var(--side-muted); }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; align-items: center; gap: 10px; height: 50px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border); color: var(--text); }
main { flex: 1; overflow-y: auto; padding: 22px 26px 60px; }
main:focus { outline: none; }
.view { max-width: 1400px; margin: 0 auto; }
.scrim { display: none; }

/* ---------- page parts ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.note { margin: 4px 0 0; color: var(--text-2); max-width: 820px; }
.meta { margin: -8px 0 14px; color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions.end { justify-content: flex-end; margin: -4px 0 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card .pad { padding: 14px 18px 0; margin-bottom: 10px; }
.banner { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; text-decoration: none; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-line); }
.banner.err { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger-line); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--accent-soft); color: var(--accent-ink); white-space: nowrap; }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.muted-b { background: var(--neutral-soft); color: var(--text-2); }
.badge.info { background: var(--accent-soft); color: var(--accent-ink); }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: 6px 0; border-bottom: 1px solid var(--gridline); }
ul.plain li:last-child { border-bottom: 0; }
.loading { padding: 30px 0; }

/* ---------- toolbar / list ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.search { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 0 10px; color: var(--muted); }
.search input { border: 0; outline: 0; height: 32px; min-width: 220px; background: transparent; font: inherit; color: var(--text); }
.inline { display: flex; align-items: center; gap: 6px; color: var(--text-2); }
.list-foot { display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: 13px; padding: 2px 4px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; }
table.data td { padding: 8px 12px; border-bottom: 1px solid var(--gridline); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: var(--row-hover); }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--border); }
table.data td.empty { text-align: center; color: var(--muted); padding: 28px; }
table.data.compact td, table.data.compact th { padding: 6px 8px; }
table.report td { white-space: nowrap; }

/* ---------- forms ---------- */
.fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.w2 { grid-column: span 2; }
.field.w3 { grid-column: span 3; }
.field.w4 { grid-column: 1 / -1; }
.field.bottom, .checkfield { justify-content: flex-end; }
.lbl { font-size: 12px; font-weight: 600; color: var(--text-2); }
.req { color: var(--danger); font-weight: 600; }
.help { color: var(--muted); font-size: 11.5px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--input-bg); border: 1px solid var(--border-strong); border-radius: 7px; height: 34px; padding: 0 9px; width: 100%; min-width: 0; }
textarea { height: auto; padding: 7px 9px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-2); }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.ro, .calc { height: 34px; display: flex; align-items: center; padding: 0 9px; border-radius: 7px; background: var(--surface-2); border: 1px dashed var(--border); color: var(--text-2); font-variant-numeric: tabular-nums; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.calc.num { justify-content: flex-end; }
.ro { font-weight: 600; color: var(--text); }

.grid-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
table.grid th { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.grid td { padding: 5px 6px; border-bottom: 1px solid var(--gridline); min-width: 90px; }
table.grid th.wide { min-width: 240px; }
table.grid td select { min-width: 150px; }
table.grid td.idx, table.grid th.idx { width: 34px; min-width: 34px; text-align: center; color: var(--muted); }
table.grid th.narrow { width: 90px; }
table.grid th.num { text-align: right; }
table.grid tfoot td { border-bottom: 0; }
table.grid .calc { background: transparent; border-color: transparent; }
.strong { font-weight: 700; }
.num { font-variant-numeric: tabular-nums; }
td.num.strong { text-align: right; padding-right: 15px; }

.totals-row { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.totals { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 16px; box-shadow: var(--shadow); }
.tot-line { display: flex; justify-content: space-between; padding: 4px 0; color: var(--text-2); }
.tot-line.sub { border-top: 1px dashed var(--border); margin-top: 4px; padding-top: 7px; color: var(--text); font-weight: 600; }
.tot-note { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); }
.tot-line.grand { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; color: var(--text); font-weight: 700; font-size: 16px; }

/* ---------- report filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 12px 16px; }
.filter { display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
.filter span { font-size: 12px; font-weight: 600; color: var(--text-2); }
.filter select { max-width: 280px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.hub { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.hub .card { margin: 0; }
ul.links a { text-decoration: none; }
ul.links a:hover { text-decoration: underline; }

/* ---------- dashboard ---------- */
.quick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: -4px 0 16px; }
.quick-label { color: var(--muted); font-size: 13px; margin-right: 4px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
a.kpi:hover { border-color: var(--accent); border-top-color: var(--edge); }
.kpi-label { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.pipeline { display: flex; align-items: stretch; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
.pipeline .arrow { display: flex; align-items: center; color: var(--border-strong); }
.stage { flex: 1 1 0; min-width: 130px; display: flex; flex-direction: column; gap: 2px; padding: 12px; border-radius: 9px; border: 1px solid var(--border); border-top: 4px solid var(--stage-0); text-decoration: none; color: var(--text); background: var(--surface); }
.stage:hover { background: var(--surface-2); }
.stage.s1 { border-top-color: var(--stage-1); } .stage.s2 { border-top-color: var(--stage-2); } .stage.s3 { border-top-color: var(--stage-3); } .stage.s4 { border-top-color: var(--stage-4); } .stage.s5 { border-top-color: var(--stage-5); }
.stage-ic { color: var(--text-2); }
.stage-label { font-size: 12px; color: var(--text-2); font-weight: 600; }
.stage-qty { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stage-val { font-size: 12px; color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.three { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.two > .card, .three > .card { min-width: 0; }
.recent li { font-size: 13px; }
.recent a { text-decoration: none; font-weight: 600; }

/* ---------- charts ---------- */
.chart { position: relative; }
.chart-top { display: flex; justify-content: space-between; align-items: center; margin: -4px 0 6px; min-height: 18px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend i, .chart-tip i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.plot { width: 100%; }
.plot svg { display: block; width: 100%; height: auto; }
.plot .gridline { stroke: var(--gridline); stroke-width: 1; }
.plot .axis { stroke: var(--border-strong); stroke-width: 1; }
.plot .tick { fill: var(--muted); font-size: 11px; font-family: inherit; }
.plot .hit { cursor: default; }
.chart-tip { display: none; position: absolute; top: 26px; transform: translateX(-50%); background: var(--tip-bg); color: var(--tip-text); padding: 7px 10px; border-radius: 7px; font-size: 12px; pointer-events: none; white-space: nowrap; box-shadow: 0 6px 18px rgba(0,0,0,.35); border: 1px solid var(--border-strong); z-index: 2; }
.chart-tip b { font-weight: 650; }

/* ---------- modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 12px; padding: 20px 22px; width: 100%; max-width: 440px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.modal h3 { font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--toast-bg); color: #fff; border: 1px solid var(--border-strong); padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); transition: opacity .4s, transform .4s; }
.toast.ok { background: var(--toast-ok); }
.toast.err { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .three { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .side { position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .side { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 30; }
  .topbar { display: flex; }
  main { padding: 16px 16px 60px; }
  .two { grid-template-columns: 1fr; }
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field.w3, .field.w2 { grid-column: 1 / -1; }
  .search input { min-width: 0; }
  .presets { margin-left: 0; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 19px; }
  .fields { grid-template-columns: 1fr; }
  .page-head .actions { width: 100%; }
}

/* ---------- print (reports) ---------- */
@media print {
  :root {
  color-scheme: light;
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #f7f8fa;
    --input-bg: #ffffff;
    --border: #dfe3e9;
    --border-strong: #c6ccd5;
    --text: #16202c;
    --text-2: #4d5866;
    --muted: #6b7684;
    --side: #14263d;
    --side-2: #1b3150;
    --side-text: #c7d3e3;
    --side-muted: #8fa3bd;
    --side-line: rgba(255, 255, 255, .08);
    --accent: #2a78d6;
    --accent-hover: #1c5cab;
    --accent-ink: #1c5cab;
    --accent-soft: #e7f0fb;
    --danger: #c93636;
    --danger-soft: #fdecec;
    --danger-line: #f3c4c4;
    --warn: #9a6200;
    --warn-soft: #fff4dc;
    --warn-line: #f1d9a6;
    --ok: #17794f;
    --ok-soft: #e4f5ec;
    --full-soft: #fff1e6;
    --neutral-soft: #eef0f3;
    --hover-soft: rgba(0, 0, 0, .05);
    --row-hover: #f4f8fd;
    --focus-ring: rgba(42, 120, 214, .18);
    --overlay: rgba(15, 23, 35, .45);
    --tip-bg: #16202c;
    --tip-text: #ffffff;
    --toast-bg: #16202c;
    --toast-ok: #17392a;
    --login-bg: linear-gradient(160deg, #14263d, #24466f);
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --gridline: #e8ebef;
    --hover-band: rgba(42, 120, 214, .07);
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, .25);
    --stage-0: #f6c343; --stage-1: #f6c343; --stage-2: #6cc28a; --stage-3: #5b9be6; --stage-4: #e97fb0; --stage-5: #37b3a4;
  }
  .side, .topbar, .filters, .page-head .actions, .quick, #toasts { display: none !important; }
  .shell { display: block; height: auto; }
  main { overflow: visible; padding: 0; }
  .card { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  body { background: #fff; }
  table.data th { position: static; }
}

/* ---------- roles & department home ---------- */
.perm-table { border-collapse: collapse; width: 100%; max-width: 720px; }
.perm-table td { padding: 5px 8px; border-bottom: 1px solid var(--gridline); }
.perm-table td:last-child { width: 200px; }
.perm-table tr.grp th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 14px 8px 4px; }
.perm-sel[data-level="none"] { color: var(--muted); }
.perm-sel[data-level="view"] { background: var(--accent-soft); }
.perm-sel[data-level="edit"] { background: var(--ok-soft); }
.perm-sel[data-level="full"] { background: var(--full-soft); }
.home-links { display: grid; gap: 2px; }
.home-link { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--gridline); }
.home-link:last-child { border-bottom: 0; }
.home-link > a:first-child { text-decoration: none; font-weight: 550; }
.card h3 .ic { vertical-align: -3px; }

/* ---------- theme toggle ---------- */
.side-foot .foot-btns { display: flex; gap: 2px; }
.theme-toggle .ic-sun { display: none; }
:root[data-theme="light"] .theme-toggle .ic-sun { display: block; }
:root[data-theme="light"] .theme-toggle .ic-moon { display: none; }
.login-theme { position: fixed; top: 14px; right: 14px; color: #c7d3e3; }
.login-theme:hover { background: rgba(255,255,255,.1); color: #fff; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
.nav::-webkit-scrollbar-thumb { background: var(--side-2); }

/* ---------- coloured top edge on every box (rotates so neighbours differ) ---------- */
:root {
  --edge-1: #e5b53c; --edge-2: #4fb57a; --edge-3: #3987e5; --edge-4: #d9679b;
  --edge-5: #2ea596; --edge-6: #d95926; --edge-7: #9085e9;
}
:root[data-theme="light"] {
  --edge-1: #f0b429; --edge-2: #3fae6a; --edge-3: #2a78d6; --edge-4: #e0609a;
  --edge-5: #1f9e8f; --edge-6: #eb6834; --edge-7: #6c5ce7;
}
.card, .kpi, .totals, .login-card { border-top: 4px solid var(--edge, var(--edge-3)); }
.card:nth-of-type(7n+1), .kpi:nth-child(7n+1) { --edge: var(--edge-1); }
.card:nth-of-type(7n+2), .kpi:nth-child(7n+2) { --edge: var(--edge-2); }
.card:nth-of-type(7n+3), .kpi:nth-child(7n+3) { --edge: var(--edge-3); }
.card:nth-of-type(7n+4), .kpi:nth-child(7n+4) { --edge: var(--edge-4); }
.card:nth-of-type(7n+5), .kpi:nth-child(7n+5) { --edge: var(--edge-5); }
.card:nth-of-type(7n+6), .kpi:nth-child(7n+6) { --edge: var(--edge-6); }
.card:nth-of-type(7n+7), .kpi:nth-child(7n+7) { --edge: var(--edge-7); }
.totals { --edge: var(--edge-2); }
.login-card { --edge: var(--edge-3); }
.kpi:hover { border-color: var(--border-strong); border-top-color: var(--edge); }
/* the stage boxes inside the pipeline card keep their own colours */
.pipeline .stage { border-top-width: 4px; }
@media print { .card, .kpi, .totals { border-top: 1px solid #bbb; } }

/* ---------- sidebar: every entry is a small box with its own coloured edge ---------- */
.nav { padding: 6px 10px 12px; }
.nav > .nav-top, .nav-group > .nav-top {
  border: 1px solid var(--side-line); border-left: 4px solid var(--edge, var(--edge-3));
  border-radius: 8px; margin-bottom: 5px; padding: 8px 10px 8px 9px; background: rgba(255, 255, 255, .02);
}
.nav > :nth-child(7n+1) { --edge: var(--edge-1); }
.nav > :nth-child(7n+2) { --edge: var(--edge-2); }
.nav > :nth-child(7n+3) { --edge: var(--edge-3); }
.nav > :nth-child(7n+4) { --edge: var(--edge-4); }
.nav > :nth-child(7n+5) { --edge: var(--edge-5); }
.nav > :nth-child(7n+6) { --edge: var(--edge-6); }
.nav > :nth-child(7n+7) { --edge: var(--edge-7); }
.nav-top .ic { color: var(--edge); }
.nav-top.active { background: var(--side-2); box-shadow: none; border-color: var(--edge); }
.nav-top.active .ic { color: #fff; }
.nav-group.open > .nav-top { background: var(--side-2); }

.nav-kids { padding: 0 0 8px 12px; }
.nav-kids a {
  border: 1px solid var(--side-line); border-left: 3px solid var(--kid, var(--edge-3));
  border-radius: 7px; margin: 0 0 4px; padding: 6px 10px;
}
.nav-kids a:nth-child(7n+1) { --kid: var(--edge-2); }
.nav-kids a:nth-child(7n+2) { --kid: var(--edge-3); }
.nav-kids a:nth-child(7n+3) { --kid: var(--edge-4); }
.nav-kids a:nth-child(7n+4) { --kid: var(--edge-5); }
.nav-kids a:nth-child(7n+5) { --kid: var(--edge-6); }
.nav-kids a:nth-child(7n+6) { --kid: var(--edge-7); }
.nav-kids a:nth-child(7n+7) { --kid: var(--edge-1); }
.nav-kids a:hover { border-color: var(--kid); }
.nav-kids a.active { background: var(--side-2); border-color: var(--kid); box-shadow: none; color: #fff; }

/* ---------- screens match the colour of the menu box that opened them ---------- */
main.themed .card, main.themed .totals { border-top-color: var(--page-edge); }

/* ================================================================== */
/* Premium pass + dashboard charts                                     */
/* ================================================================== */
:root {
  --spark: #5d6a7c;
  --ord-1: #184f95; --ord-2: #256abf; --ord-3: #3987e5; --ord-4: #86b6ef;   /* older dues read brighter on dark */
  --card-sheen: linear-gradient(180deg, rgba(255, 255, 255, .025), rgba(255, 255, 255, 0) 120px);
  --good: #4cc38a; --bad: #f07171;
}
:root[data-theme="light"] {
  --spark: #aab3bf;
  --ord-1: #86b6ef; --ord-2: #3987e5; --ord-3: #1c5cab; --ord-4: #0d366b;   /* older dues read darker on light */
  --card-sheen: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0));
  --good: #17794f; --bad: #c93636;
}
body { font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
h1 { font-family: "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif; font-size: 25px; font-weight: 650; }
.card { background: var(--card-sheen), var(--surface); border-radius: 14px; padding: 18px 20px; }
.card.flush { padding: 0; }
.kpi { background: var(--card-sheen), var(--surface); border-radius: 14px; }
.kpi-value, .stat-value { font-variant-numeric: normal; }
main { padding: 26px 30px 70px; }
.view { max-width: 1480px; }

/* dashboard layout */
.dfilters { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: -2px 0 18px; }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); flex-wrap: wrap; }
.seg-btn { border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: 13px; font-weight: 550; padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.seg-btn:hover { color: var(--text); background: var(--hover-soft); }
.seg-btn.on { background: var(--accent); color: #fff; }
.drange { display: flex; align-items: center; gap: 8px; }
.drange input { width: 150px; height: 34px; }
.dash-body { transition: opacity .15s; }
.dash-body.refetch { opacity: .5; pointer-events: none; }
.dgrid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }
.dgrid.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dgrid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.dgrid > .card { margin-bottom: 16px; min-width: 0; }
.dcard-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.dcard-head h3 { margin: 0; font-size: 14.5px; }
.dsub { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.cempty { padding: 26px 0; text-align: center; }

/* hero */
.hero-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin-bottom: 10px; }
.hero-fig { font-size: clamp(36px, 4.2vw, 52px); font-weight: 650; letter-spacing: -.02em; line-height: 1.05; color: var(--text); }
.hero-delta { margin-top: 6px; }
.hero-mini { display: flex; gap: 26px; flex-wrap: wrap; }
.hero-mini > div { display: flex; flex-direction: column; gap: 1px; }
.hero-mini span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.hero-mini b { font-size: 17px; font-weight: 650; }
.hero-mini small { color: var(--muted); font-size: 12px; }

/* money card */
.money-fig { font-size: 32px; font-weight: 650; letter-spacing: -.01em; margin: 2px 0 4px; }
.money-split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.money-mini { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); text-decoration: none; color: var(--text); }
.money-mini:hover { border-color: var(--border-strong); }
.money-mini > span:first-child { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.money-mini b { font-size: 18px; font-weight: 650; }

/* stat tiles */
.stats6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.stat { gap: 6px; padding: 14px 16px 13px; }
.stat-spark { height: 30px; width: 100%; margin: 2px 0 2px; }
.stat-spark .spark { display: block; }
.stat-value { font-size: 23px; font-weight: 650; letter-spacing: -.01em; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-foot { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.delta { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; font-weight: 650; padding: 2px 7px; border-radius: 999px; background: var(--neutral-soft); color: var(--text-2); white-space: nowrap; }
.delta small { font-weight: 500; opacity: .75; }
.delta.good { background: var(--ok-soft); color: var(--good); }
.delta.bad { background: var(--danger-soft); color: var(--bad); }

/* chart frame */
.cframe { position: relative; }
.ctop { display: flex; justify-content: space-between; align-items: center; min-height: 20px; margin-bottom: 6px; }
.clegend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12.5px; color: var(--text-2); }
.clegend span { display: inline-flex; align-items: center; gap: 6px; }
.lkey { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.lkey.line { width: 16px; height: 3px; border-radius: 2px; }
.cplot { width: 100%; outline: none; border-radius: 8px; }
.cplot:focus-visible { box-shadow: 0 0 0 2px var(--focus-ring); }
.csvg { display: block; width: 100%; height: auto; overflow: visible; }
.csvg .c-grid { stroke: var(--gridline); stroke-width: 1; }
.csvg .c-axis { stroke: var(--border-strong); stroke-width: 1; }
.csvg .c-tick { fill: var(--muted); font-size: 11px; font-family: inherit; font-variant-numeric: tabular-nums; }
.csvg .c-end { fill: var(--text-2); font-size: 11.5px; font-weight: 650; font-family: inherit; }
.csvg .c-cross { stroke: var(--text-2); stroke-width: 1; opacity: .45; }
.csvg .c-ref { stroke: var(--muted); stroke-width: 1; opacity: .8; }
.csvg .c-col { transition: opacity .12s; }
.csvg .c-col.dim { opacity: .4; }
.ctable { margin-top: 6px; max-height: 300px; overflow: auto; }
.ctip { display: none; position: absolute; top: 30px; z-index: 5; min-width: 150px; padding: 9px 11px; border-radius: 10px; background: var(--tip-bg); color: var(--tip-text); border: 1px solid var(--border-strong); box-shadow: 0 10px 28px rgba(0, 0, 0, .35); pointer-events: none; font-size: 12px; }
.ctip-title { color: var(--muted); font-size: 11.5px; margin-bottom: 5px; }
:root[data-theme="light"] .ctip-title { color: #b7c1cc; }
.ctip-row { display: flex; align-items: center; gap: 7px; line-height: 1.7; white-space: nowrap; }
.ctip-row b { font-weight: 650; font-variant-numeric: tabular-nums; }
.ctip-row span { opacity: .75; }
.ctip-key { width: 12px; height: 3px; border-radius: 2px; flex: none; }

/* horizontal bars */
.hbars { display: grid; gap: 12px; }
.hbar { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 12px; align-items: center; }
.hbar-label { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-label small { display: block; color: var(--muted); font-size: 11.5px; }
.hbar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hbar-fill { height: 12px; border-radius: 0 4px 4px 0; flex: none; max-width: calc(100% - 64px); }
.hbar-val { font-size: 12.5px; font-weight: 650; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* stacked bar */
.stackbar { display: flex; gap: 2px; height: 14px; border-radius: 5px; overflow: hidden; }
.stackseg { min-width: 3px; }
.stackseg.empty { flex: 1; background: var(--neutral-soft); }
.stacklegend { display: grid; gap: 6px; margin-top: 12px; }
.stackleg { display: grid; grid-template-columns: 12px 1fr auto 38px; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); }
.stackleg b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.stackleg small { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 1280px) {
  .stats6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dgrid.g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1000px) {
  .dgrid, .dgrid.g2, .dgrid.g3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .stats6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  main { padding: 16px 14px 60px; }
  .hero-mini { gap: 16px; }
  .drange input { width: 130px; }
  .seg-btn { padding: 6px 9px; }
}

/* ---------- department analytics ---------- */
.dept-section { margin-bottom: 30px; }
.dept-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 0 12px; }
.dept-head h2 { display: flex; align-items: center; gap: 9px; margin: 0; font-size: 19px; font-weight: 650; }
.dept-head h2 .ic { color: var(--accent-ink); }
.dept-kpis { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.dgrid.g1 { grid-template-columns: minmax(0, 1fr); }
.dept-links-title { font-size: 19px; font-weight: 650; margin: 8px 0 12px; }

/* ---------- full screen ---------- */
.fs-chip { border-color: var(--accent); color: var(--accent-ink); }
.fs-chip:hover { background: var(--accent-soft); }
:fullscreen body, :fullscreen #app { background: var(--bg); }
