/* Light theme by default: white surfaces, neutral ink, green only as the highlight
   (active nav, buttons, links, key figures). Dark is a neutral charcoal, chosen by
   the switch in the sidebar or by the system setting when set to Auto. */
:root {
  color-scheme: light;
  --bg: #f6f7f9; --card: #ffffff; --card-2: #f9fafb; --ink: #111827; --body: #374151; --muted: #6b7280;
  --line: #e5e7eb; --line-2: #f1f3f5; --accent: #14a37f; --accent-ink: #0b7a5e; --accent-soft: #e8f7f1;
  --brand: #12936f; --brand-2: #0b7a5e; --good: #0ca30c; --good-ink: #006300; --warn: #fab219; --bad: #c44545;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --shadow: 0 1px 2px rgba(17,24,39,.04), 0 2px 8px rgba(17,24,39,.04);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1116; --card: #161a21; --card-2: #1b2029; --ink: #f3f4f6; --body: #cbd2da; --muted: #8b95a3;
    --line: #2a313c; --line-2: #20262f; --accent: #3cc1a2; --accent-ink: #5fd4b4; --accent-soft: rgba(60,193,162,.12);
    --brand: #1f9e7f; --brand-2: #17866b; --good-ink: #5fd35f; --bad: #e66767;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --shadow: 0 1px 2px rgba(0,0,0,.35), 0 2px 10px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1116; --card: #161a21; --card-2: #1b2029; --ink: #f3f4f6; --body: #cbd2da; --muted: #8b95a3;
  --line: #2a313c; --line-2: #20262f; --accent: #3cc1a2; --accent-ink: #5fd4b4; --accent-soft: rgba(60,193,162,.12);
  --brand: #1f9e7f; --brand-2: #17866b; --good-ink: #5fd35f; --bad: #e66767;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 2px 10px rgba(0,0,0,.25);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--body); font: 14px/1.5 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent-ink); text-decoration: none; }
h1, h2, h3 { color: var(--ink); margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.mono, .addr { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.err { color: var(--bad); margin: 0; font-size: 13px; min-height: 0; }
.err:empty { display: none; }

/* layout */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
nav.side { background: var(--card); border-right: 1px solid var(--line); color: var(--body); padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; color: var(--ink); font-weight: 700; font-size: 16px; }
.logo img { width: 28px; height: 28px; display: block; border-radius: 7px; }
nav.side a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; margin: 1px 0; border-radius: 8px; color: var(--body); font-weight: 500; position: relative; }
nav.side a:hover { background: var(--card-2); color: var(--ink); }
nav.side a.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
nav.side a.on::before { content: ""; position: absolute; left: -14px; top: 6px; bottom: 6px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
nav.side .badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 11px; font-weight: 700; }
nav.side .sect { text-transform: uppercase; font-size: 10.5px; letter-spacing: .08em; color: var(--muted); padding: 16px 10px 4px; }
nav.side .foot { margin-top: auto; padding-top: 18px; display: grid; gap: 8px; }
nav.side a.signout { color: var(--muted); font-size: 13px; }
.theme-switch { display: flex; background: var(--card-2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.theme-switch button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 5px 0; border-radius: 7px; font-size: 12px; justify-content: center; }
.theme-switch button.on { background: var(--card); color: var(--accent-ink); box-shadow: var(--shadow); }
main { padding: 24px 28px 64px; min-width: 0; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.top .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g2 { grid-template-columns: 3fr 2fr; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card > header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; gap: 8px; flex-wrap: wrap; }
.tile .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.tile .value { color: var(--ink); font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .foot { font-size: 12px; color: var(--muted); margin-top: 4px; }
.tile.hero { border-top: 3px solid var(--accent); }
.tile.hero .value { color: var(--accent-ink); }
a.tile, button.tile { display: block; text-align: left; color: inherit; width: 100%; }
a.tile.on, button.tile.on { border: 2px solid var(--accent); }

/* controls */
button, .btn { font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--accent); }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--brand-2); }
button.ghost { background: transparent; border-color: transparent; color: var(--accent-ink); padding: 4px 8px; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: inline-flex; background: var(--card-2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* tables */
.tbl-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; background: var(--card); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tr:hover td { background: var(--card-2); }
tr.total td { font-weight: 650; color: var(--ink); border-top: 1px solid var(--line); border-bottom: 0; }
tr.grand td { font-weight: 700; color: var(--ink); border-top: 2px solid var(--ink); }
tr.section td { font-weight: 600; color: var(--ink); background: var(--card-2); padding-top: 12px; }
tr.group td { font-weight: 600; color: var(--body); }
tr.sub td:first-child { padding-left: 26px; }
td.wrap { white-space: normal; min-width: 220px; max-width: 520px; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--line-2); color: var(--body); white-space: nowrap; }
.pill.good { background: rgba(12,163,12,.12); color: var(--good-ink); }
.pill.warn { background: rgba(250,178,25,.18); color: #8a5b00; }
:root[data-theme="dark"] .pill.warn { color: #ffd27a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill.warn { color: #ffd27a; } }
.pill.bad { background: rgba(196,69,69,.13); color: var(--bad); }
.pill.info { background: var(--accent-soft); color: var(--accent-ink); }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.callout { border-left: 3px solid var(--warn); background: var(--card); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; box-shadow: var(--shadow); }

/* charts */
.chart { position: relative; }
.chart svg { display: block; max-width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--line-2); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 12px; color: var(--body); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tip { position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--body); min-width: 150px; z-index: 5; display: none; }
.tip b { color: var(--ink); }
.tip .r { display: flex; justify-content: space-between; gap: 14px; }
.tip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 6px; }
.alloc { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; background: var(--card); }
.alloc div { height: 100%; }

/* drawer + toast */
.drawer { position: fixed; inset: 0; background: rgba(4,32,26,.45); display: none; z-index: 20; }
.drawer.open { display: block; }
.drawer .panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(640px, 100%); background: var(--bg); padding: 22px; overflow-y: auto; overflow-x: hidden; box-shadow: -8px 0 32px rgba(0,0,0,.2); }
.drawer .panel pre { white-space: pre-wrap; word-break: break-word; font-size: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); display: none; z-index: 30; max-width: 380px; }
.field { display: grid; gap: 4px; margin-bottom: 12px; } .field label { font-size: 12px; color: var(--muted); }
.statement td:first-child { min-width: 260px; }

/* sign in */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; border-top: 3px solid var(--accent); padding: 28px; display: grid; gap: 10px; }
.login-card h1 { text-align: center; font-size: 19px; }
.login-card p.muted { text-align: center; margin: 0 0 6px; }
.login-card label { font-size: 12px; color: var(--muted); }
.login-card button { justify-content: center; margin-top: 4px; padding: 10px; }
.login-logo { display: flex; justify-content: center; }
.login-logo img { width: 52px; height: 52px; display: block; border-radius: 12px; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g2, .g3 { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  nav.side { position: static; height: auto; flex-direction: row; overflow-x: auto; gap: 4px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  nav.side a.on::before { display: none; }
  nav.side .foot { margin: 0; padding: 0; display: flex; }
  nav.side .sect, .logo span { display: none; } .logo { padding: 0 8px 0 0; }
  nav.side a { white-space: nowrap; }
  main { padding: 16px; } .g4 { grid-template-columns: 1fr 1fr; } .hide-sm { display: none; }
  .tile .value { font-size: 20px; }
}
@media print {
  nav.side, .top .row, .noprint { display: none !important; }
  .shell { display: block; } main { padding: 0; }
  .card { box-shadow: none; border: 0; }
  body { background: #fff; color: #000; }
}

/* Page-to-page: the current page stays up while the next loads; this bar shows only if that takes >120ms. */
body.busy::before { content: ''; position: fixed; top: 0; left: 0; height: 2px; width: 100%; z-index: 100; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 40% 100%; background-repeat: no-repeat; animation: busy 0.9s ease-in-out infinite; }
@keyframes busy { from { background-position: -40% 0 } to { background-position: 140% 0 } }
@media (prefers-reduced-motion: reduce) { body.busy::before { animation: none; background: var(--accent); opacity: .5 } }
