/* Klar design system.
   Neutral greys, one blue accent, hairline borders, small radii, no gradients or glows. One sans (Geist) for
   everything, Geist Mono for codes. Modelled on the restraint of Linear, Vercel and Stripe's dashboards. */

:root {
  --page: #f7f7f8; --surface: #ffffff; --raised: #ffffff; --hover: #f1f1f3; --border: #e4e4e7; --rule: #efeff1;
  --ink: #18181b; --ink-2: #52525b; --muted: #8b8b94;
  --brand: #2563eb; --brand-ink: #1d4ed8; --brand-soft: #eff4ff;
  --violet: var(--brand); --pink: var(--brand);                    /* old names, now the one accent */
  --gold: #2563eb; --gold-soft: #eff4ff;
  --accent: #2563eb; --accent-ink: #1d4ed8; --accent-soft: #eff4ff;
  --good: #16a34a; --good-ink: #15803d; --good-soft: #effaf2;
  --warn: #d97706; --warn-ink: #a1560a; --warn-soft: #fdf6e7;
  --crit: #dc2626; --crit-ink: #b91c1c; --crit-soft: #fdf0f0;
  --series: #2563eb; --series-fill: rgba(37,99,235,.10); --grid: #ececef;
  --navy: #18181b; --navy-2: #27272a;
  --side-bg: #fbfbfc; --side-ink: #3f3f46; --side-dim: #8b8b94; --side-hover: #f0f0f2; --side-on: #ebebee; --side-line: #ececef;
  --avatar-bg: #e4e4e7; --avatar-ink: #3f3f46;
  --glow: 0 1px 2px rgba(0,0,0,.06);
  --shadow-1: 0 1px 2px rgba(0,0,0,.04);
  --shadow-2: 0 12px 32px -12px rgba(0,0,0,.18), 0 2px 6px rgba(0,0,0,.05);
  --radius: 10px; --radius-s: 8px;
  --sans: "Geist", "Segoe UI", system-ui, -apple-system, sans-serif;
  --display: var(--sans);
  --serif: var(--sans);
  --mono: "Geist Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --side: 240px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0b0b0d; --surface: #121214; --raised: #18181b; --hover: #1c1c20; --border: #26262b; --rule: #1e1e22;
    --ink: #ededef; --ink-2: #a1a1aa; --muted: #71717a;
    --brand: #4f8cff; --brand-ink: #8ab4ff; --brand-soft: #14203a; --gold: #4f8cff; --gold-soft: #14203a;
    --accent: #4f8cff; --accent-ink: #8ab4ff; --accent-soft: #14203a;
    --good: #22c55e; --good-ink: #5fd98b; --good-soft: #0f2418;
    --warn: #f59e0b; --warn-ink: #f6bd5c; --warn-soft: #2a1f0b;
    --crit: #f05252; --crit-ink: #f78b8b; --crit-soft: #2c1213;
    --series: #4f8cff; --series-fill: rgba(79,140,255,.14); --grid: #222226;
    --side-bg: #0e0e10; --side-ink: #c4c4cc; --side-dim: #6b6b74; --side-hover: #18181b; --side-on: #1f1f23; --side-line: #1f1f23;
    --avatar-bg: #27272a; --avatar-ink: #d4d4d8;
    --shadow-1: none; --shadow-2: 0 16px 40px -12px rgba(0,0,0,.7); --glow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #0b0b0d; --surface: #121214; --raised: #18181b; --hover: #1c1c20; --border: #26262b; --rule: #1e1e22;
  --ink: #ededef; --ink-2: #a1a1aa; --muted: #71717a;
  --brand: #4f8cff; --brand-ink: #8ab4ff; --brand-soft: #14203a; --gold: #4f8cff; --gold-soft: #14203a;
  --accent: #4f8cff; --accent-ink: #8ab4ff; --accent-soft: #14203a;
  --good: #22c55e; --good-ink: #5fd98b; --good-soft: #0f2418;
  --warn: #f59e0b; --warn-ink: #f6bd5c; --warn-soft: #2a1f0b;
  --crit: #f05252; --crit-ink: #f78b8b; --crit-soft: #2c1213;
  --series: #4f8cff; --series-fill: rgba(79,140,255,.14); --grid: #222226;
  --side-bg: #0e0e10; --side-ink: #c4c4cc; --side-dim: #6b6b74; --side-hover: #18181b; --side-on: #1f1f23; --side-line: #1f1f23;
  --avatar-bg: #27272a; --avatar-ink: #d4d4d8;
  --shadow-1: none; --shadow-2: 0 16px 40px -12px rgba(0,0,0,.7); --glow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.55 var(--sans); letter-spacing: -.003em;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: var(--brand-ink); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--brand); }
::selection { background: color-mix(in srgb, var(--brand) 22%, transparent); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ---------- type ---------- */
h1, h2, h3 { font-family: var(--sans); color: var(--ink); }
h1, h2 { font-family: var(--display); }
h1 { font-size: 24px; line-height: 1.2; font-weight: 600; letter-spacing: -.02em; margin: 0 0 6px; }
h2 { font-size: 15px; line-height: 1.35; font-weight: 600; letter-spacing: -.01em; margin: 0 0 12px; }
h3 { font-size: 14px; font-weight: 600; margin: 18px 0 8px; }
h1 em, h2 em, .serif { font-style: normal; font-weight: inherit; }
.sub { color: var(--ink-2); margin: 0 0 24px; max-width: 72ch; }
.eyebrow { font: 500 12px/1 var(--sans); color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 13px; }
code, pre, kbd { font-family: var(--mono); font-size: 12.5px; }

/* ---------- shell: a quiet sidebar, the same family of greys as the page ---------- */
.shell { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; overflow-y: auto; overflow-x: hidden; color: var(--side-ink); padding: 0 10px;
  display: flex; flex-direction: column; background: var(--side-bg); border-right: 1px solid var(--side-line); scrollbar-width: thin; }
/* the name and the account stay in view while the menu scrolls */
.brandmark { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); padding: 18px 18px 12px;
  margin: 0 -10px 2px; position: sticky; top: 0; z-index: 3; background: var(--side-bg); }
.brandmark .globe { width: 30px; height: 30px; margin-left: auto; flex: none; }
.brandmark svg { flex: none; }
.brandmark b { font: 600 15px/1 var(--sans); letter-spacing: -.02em; }
.company { margin: 0 2px 12px; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--side-line); background: var(--surface); }
.company:hover { border-color: var(--border); background: var(--side-hover); }
.company .n { font-weight: 550; font-size: 13px; line-height: 1.3; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.company .s { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--side-dim); margin-top: 2px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--good); }
.navgroup { margin: 0 0 4px; }
.navgroup > span { display: block; font: 500 11.5px/1 var(--sans); color: var(--side-dim); padding: 9px 10px 5px; }
.navlink { display: flex; align-items: center; gap: 10px; padding: 5px 10px; border-radius: 6px; color: var(--side-ink); text-decoration: none;
  font-size: 13px; font-weight: 450; position: relative; transition: background .12s, color .12s; }
.navlink svg { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; opacity: .75; }
.navlink:hover { background: var(--side-hover); color: var(--ink); }
.navlink.on { color: var(--ink); background: var(--side-on); font-weight: 550; }
.navlink.on svg { opacity: 1; }
.side-foot { margin: auto -10px 0; padding: 10px 14px 10px; border-top: 1px solid var(--side-line); display: flex; align-items: center; gap: 10px;
  position: sticky; bottom: 0; z-index: 3; background: var(--side-bg); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none; color: var(--avatar-ink);
  font: 600 11px/1 var(--sans); letter-spacing: .02em; background: var(--avatar-bg); }
.side-foot .who { min-width: 0; flex: 1; line-height: 1.25; font-size: 13px; color: var(--ink); text-decoration: none; padding: 4px 6px; margin: -4px -6px; border-radius: 6px; }
.side-foot .who:hover { background: var(--side-hover); }
.side-foot .who b { display: block; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .who small { color: var(--side-dim); display: block; font-size: 12px; }
.side-foot .out { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: 6px; color: var(--side-dim); }
.side-foot .out:hover { background: var(--side-hover); color: var(--ink); }
.side-foot .out svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.content { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px 32px;
  background: color-mix(in srgb, var(--page) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent; transition: border-color .2s; }
.topbar.scrolled { border-bottom-color: var(--border); }
.topbar .crumb { font-size: 13px; color: var(--ink-2); display: flex; gap: 8px; align-items: center; }
.topbar .tools { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.iconbtn { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; border: 1px solid var(--border); background: var(--surface);
  color: var(--ink-2); cursor: pointer; transition: color .12s, background .12s; }
.iconbtn svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn:hover { color: var(--ink); background: var(--hover); }
.menu-btn { display: none; }
main { max-width: 1240px; margin: 0 auto; padding: 14px 32px 80px; }
@keyframes rise { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; left: 0; width: min(86vw, 300px); transform: translateX(-102%); transition: transform .3s cubic-bezier(.2,.7,.2,1); }
  body.nav-open .side { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
  .menu-btn { display: grid; }
  .topbar, main { padding-left: 16px; padding-right: 16px; }
  h1 { font-size: 22px; }
}

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
  box-shadow: var(--shadow-1); }
.card.ledger { position: relative; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.tiles, .kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
.tile, .kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; position: relative;
  box-shadow: var(--shadow-1); transition: border-color .12s; }
a.tile:hover, a.kpi:hover { border-color: color-mix(in srgb, var(--ink) 22%, var(--border)); }
.tile .k, .kpi .k { color: var(--ink-2); font-size: 12.5px; font-weight: 500; }
.tile .v, .kpi .v { font: 600 24px/1.2 var(--sans); letter-spacing: -.025em; font-variant-numeric: tabular-nums; margin-top: 4px; color: var(--ink); }
.kpi .d { font-size: 12.5px; margin-top: 3px; }
.up { color: var(--good-ink); } .down { color: var(--crit-ink); }
.kpi .v.down, .tile .v.down { color: var(--crit-ink); } .kpi .v.up, .tile .v.up { color: var(--good-ink); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { color: var(--muted); font: 500 12px/1.3 var(--sans); white-space: nowrap; }
tbody tr, table > tr { transition: background .15s; }
tbody tr:hover, table > tr:hover { background: var(--hover); }
td.num, th.num, .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- pills, buttons, forms ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 550; white-space: nowrap; }
.red { background: var(--crit-soft); color: var(--crit-ink); } .amber { background: var(--warn-soft); color: var(--warn-ink); }
.green { background: var(--good-soft); color: var(--good-ink); } .neutral { background: var(--brand-soft); color: var(--brand-ink); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--raised); color: var(--ink);
  padding: 7px 14px; border-radius: 8px; font: 500 13.5px/1.3 var(--sans); cursor: pointer; text-decoration: none;
  box-shadow: var(--shadow-1); transition: background .12s, border-color .12s, color .12s; }
.btn:hover { background: var(--hover); color: var(--ink); }
.btn:active { transform: translateY(.5px); }
.btn.primary { color: #fff; background: var(--brand); border-color: var(--brand); font-weight: 550; }
.btn.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); color: #fff; }
:root[data-theme="dark"] .btn.primary:hover { background: color-mix(in srgb, var(--brand) 85%, #fff); border-color: transparent; }
.btn.big { padding: 9px 18px; font-size: 14px; }
.btn.danger { color: var(--crit-ink); border-color: color-mix(in srgb, var(--crit) 40%, var(--border)); }
.btn.danger:hover { background: var(--crit-soft); color: var(--crit-ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month],
input[type=search], input[type=tel], input[type=url], input:not([type]), select, textarea, input[type=file] {
  font: inherit; font-size: 14px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-s);
  background: var(--raised); color: var(--ink); max-width: 100%; transition: border-color .12s, box-shadow .12s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
/* file boxes: the browser's "Choose Files" is hidden (still focusable) behind one Upload button, added in base.html */
input[type=file].filehide { position: absolute; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; overflow: hidden; pointer-events: none; }
label:has(> .filehide) { position: relative; }
.btn.upload { align-self: flex-start; justify-self: center; cursor: pointer; }
.btn.upload.off { opacity: .5; cursor: not-allowed; }
.filehide:focus-visible + .upload { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 16%, transparent); }
.upnames:empty { display: none; }
form.inline { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 2px 4px 2px 0; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.form-grid label.check { flex-direction: row; align-items: center; gap: 6px; display: inline-flex; margin-right: 14px; color: var(--ink); }
.form-grid input[type=text], .form-grid select { width: 100%; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-s); padding: 8px 12px 12px; }
legend { color: var(--ink-2); font-size: 13px; padding: 0 4px; }
details summary { cursor: pointer; color: var(--brand-ink); }

/* ---------- messages ---------- */
.flash { padding: 11px 14px 11px 40px; border-radius: 8px; margin-bottom: 12px; position: relative; overflow-wrap: anywhere; border: 1px solid transparent; }
.flash::before { position: absolute; left: 15px; top: 11px; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center;
  font: 700 11px/18px var(--sans); text-align: center; color: #fff; }
.flash.ok { background: var(--good-soft); color: var(--good-ink); border-color: color-mix(in srgb, var(--good) 20%, transparent); }
.flash.ok::before { content: "✓"; background: var(--good); }
.flash.error { background: var(--crit-soft); color: var(--crit-ink); border-color: color-mix(in srgb, var(--crit) 20%, transparent); }
.flash.error::before { content: "!"; background: var(--crit); }
.msg { margin: 4px 0; padding: 7px 11px; border-radius: 10px; font-size: 13px; }
.msg.error { background: var(--crit-soft); color: var(--crit-ink); } .msg.warn { background: var(--warn-soft); color: var(--warn-ink); }

/* ---------- existing page parts ---------- */
nav.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; position: sticky; top: 60px; background: var(--page); padding: 8px 0; z-index: 2; }
nav.tabs a { padding: 5px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--ink); font-size: 14px; }
.voucher { border: 1px solid var(--border); border-radius: 10px; padding: 13px; margin-bottom: 10px; background: var(--raised); }
.voucher .head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.voucher table td { border: 0; padding: 2px 8px; }
.new { border-left: 3px solid var(--brand); }
.chart-box { position: relative; } .chart-box svg { width: 100%; height: auto; display: block; }
.tip { position: absolute; pointer-events: none; background: var(--raised); border: 1px solid var(--border); border-radius: 11px;
  padding: 7px 11px; font-size: 13px; box-shadow: var(--shadow-2); display: none; max-width: 260px; }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.head-row:has(> h1) { margin-bottom: 18px; }                      /* a bare title needs room below it */
h1 { padding-bottom: .08em; }                                    /* so the tails of g, p and y are never cut */
section[id] { scroll-margin-top: 76px; }
@media (max-width: 640px) {
  nav.tabs { position: static; }
  .tile .v, .kpi .v { font-size: 22px; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  table.stack td { border: 0; padding: 3px 0; text-align: left; }
  table.stack td[data-label]::before { content: attr(data-label) ": "; color: var(--ink-2); font-size: 13px; }
}

:root[data-motion="off"] *, :root[data-motion="off"] *::before, :root[data-motion="off"] *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
@media print {
  .side, .topbar, .noprint { display: none !important; }
  .shell { display: block; } main { padding: 0; animation: none; } body { background: #fff; }
  .card { box-shadow: none; }
}

/* ---------- counts in the menu ---------- */
.navlink .tag { margin-left: auto; min-width: 18px; text-align: center; font: 600 11px/1 var(--sans); padding: 3px 6px; border-radius: 6px;
  color: var(--ink-2); background: var(--side-on); font-variant-numeric: tabular-nums; }
.navlink.on .tag { background: var(--surface); }
