:root {
  --bg: #f6f5f1; --card: #fff; --ink: #1d2320; --muted: #5c6661; --line: #e2e0d8; --edge: #7d8782;
  --accent: #2f6f5e; --on-accent: #fff; --ok: #2a6f45; --warn: #8a5a0b; --bad: #a63a32;
  --s1: 4px; --s2: 8px; --s3: 16px; --s4: 24px; --s5: 32px;
  --t0: 16px; --t1: 19px; --t2: 23px; --tab-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151917; --card: #1f2522; --ink: #e8ece9; --muted: #9aa49f; --line: #333b37; --edge: #68746e;
          --accent: #6cc3a8; --on-accent: #0f1a16; --ok: #6cc38a; --warn: #e0b45c; --bad: #e57f76; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: var(--t0)/1.5 system-ui, sans-serif; }
header { display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: calc(env(safe-area-inset-top) + var(--s2)) calc(var(--s3) + env(safe-area-inset-right)) var(--s2) calc(var(--s3) + env(safe-area-inset-left)); background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2; min-height: 48px; }
header a { text-decoration: none; }
.brand { font-weight: 700; color: var(--accent); font-size: var(--t1); }
main { max-width: 640px; margin: 0 auto; padding: var(--s3) calc(var(--s3) + env(safe-area-inset-right)) calc(var(--s5) + var(--s3)) calc(var(--s3) + env(safe-area-inset-left)); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
main :is(h2, h3, section, div)[tabindex="-1"]:focus { outline: none; }
body.has-nav main { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + var(--s4)); }
h2 { font-size: var(--t1); line-height: 1.2; margin: var(--s4) 0 var(--s2); }
.big { font-size: var(--t2); line-height: 1.2; font-weight: 700; }

/* Links */
main a:not(.card) { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
main a:not(.card):hover { text-decoration-thickness: 2px; }
a.back { display: inline-flex; align-items: center; min-height: 44px; font-size: 14px; }
a.card { display: block; color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--edge); }
a.btn { display: block; text-align: center; padding: 11px var(--s3); min-height: 44px; border-radius: 10px; font-weight: 600;
  background: var(--accent); color: var(--on-accent); text-decoration: none; margin: var(--s2) 0; }
main a.btn { color: var(--on-accent); text-decoration: none; }
main a.btn.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
a.btn.sm { display: inline-flex; align-items: center; justify-content: center; margin: 0; padding: 0 var(--s3); white-space: nowrap; }
.row.head { align-items: center; margin-top: var(--s4); }
.row.head h2 { margin: 0; }
a.btn:hover { filter: brightness(1.08); }
a.btn:active { filter: brightness(.92); }

/* Navigation: bottom tab bar on phones, top bar on wide screens */
nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; display: flex;
  background: var(--card); border-top: 1px solid var(--line); padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
nav[hidden] { display: none; }
nav a { flex: 1; min-height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 12px; position: relative; }
nav a svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav a:hover { color: var(--ink); }
nav a[aria-current=page] { color: var(--accent); font-weight: 700; }
nav a[aria-current=page]::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
@media (min-width: 768px) {
  nav { position: static; border: 0; padding: 0; background: none; gap: var(--s1); }
  nav a { flex: none; flex-direction: row; gap: var(--s2); min-height: 44px; padding: 0 var(--s3); font-size: 15px; border-radius: 10px; }
  nav a svg { width: 20px; height: 20px; }
  nav a[aria-current=page]::before { top: auto; bottom: 0; left: var(--s3); right: var(--s3); height: 3px; border-radius: 3px 3px 0 0; }
  body.has-nav main { padding-bottom: calc(var(--s5) + var(--s3)); }
}

/* Cards and text */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: var(--s3); margin: var(--s2) 0; }
.row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.muted { color: var(--muted); font-size: 14px; }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: var(--s2); }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.over > i { background: var(--bad); }
.over-text { color: var(--bad); font-weight: 600; }
.pill { font-size: 12px; padding: 2px var(--s2); border-radius: 99px; border: 1px solid currentColor; white-space: nowrap; }
.s-open { color: var(--accent); } .s-cooling { color: var(--muted); } .s-approved { color: var(--ok); }
.s-deferred { color: var(--warn); } .s-denied { color: var(--bad); }

/* Forms */
label, .lbl { display: block; margin: var(--s3) 0 var(--s1); font-weight: 600; font-size: 14px; }
input, select, textarea, button { font: inherit; width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--edge); background: var(--card); color: var(--ink); }
textarea { min-height: 90px; }
button { background: var(--accent); color: var(--on-accent); border: 1px solid transparent; font-weight: 600; margin-top: var(--s3); cursor: pointer; }
button:hover:not(:disabled) { filter: brightness(1.08); }
button:active:not(:disabled) { filter: brightness(.92); }
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button.secondary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 12%, transparent); filter: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.linkbtn { width: auto; min-height: 44px; margin: 0; padding: 0 var(--s2); background: none; border: 0; font-weight: 500; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
button.danger { color: var(--bad); }
button.linkbtn:hover:not(:disabled) { background: color-mix(in srgb, var(--bad) 10%, transparent); filter: none; }
.actions { display: flex; justify-content: flex-end; margin-top: var(--s2); }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }
.choices label { margin: 0; font-weight: 500; text-align: center; border: 1px solid var(--edge); border-radius: 10px; padding: 10px 4px; min-height: 44px; }
/* Visually hidden but still focusable and in the accessibility tree (same idea as .filepick). */
.choices input { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; border: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.choices label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.choices input:checked + span { font-weight: 700; color: var(--accent); }
.choices label:has(input:checked) { border-color: var(--accent); border-width: 2px; padding: 9px 3px; }
.note { background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.err { color: var(--bad); font-size: 14px; margin: var(--s2) 0 0; }
.err.ok { color: var(--ok); }
.err:empty { display: none; }
.pendchoices { display: grid; gap: var(--s2); margin-top: var(--s2); }
.pendchoices .muted { margin-top: var(--s1); }
.tblwrap { overflow-x: auto; }
.card > :last-child, form > :last-child { margin-bottom: 0; }
img.photo { max-width: 100%; border-radius: 10px; margin-top: var(--s2); }
.inline { display: flex; gap: var(--s2); align-items: center; min-height: 44px; }
.inline input[type=checkbox] { width: 24px; height: 24px; min-height: 0; flex: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2) var(--s3); }
.grid2 > div { min-width: 0; }
details > summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: var(--s2); list-style: none; }
/* One disclosure marker everywhere: browsers disagree about the native triangle, so hide it and draw our own chevron
   (summaries that carry their own .chev span, like the envelope and category rows, keep that). */
details > summary::-webkit-details-marker { display: none; }
details > summary:not(:has(.chev))::after { content: "▾"; color: var(--accent); font-size: 18px; }
details[open] > summary:not(:has(.chev))::after { content: "▴"; }
details.card[open] > summary { margin-bottom: var(--s1); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* File picker: native input visually hidden but focusable */
.filepick { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); }
.filepick input[type=file] { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; border: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.filebtn { display: inline-flex; align-items: center; justify-content: center; margin: 0; min-height: 52px; padding: 0 var(--s3);
  border: 1px dashed var(--accent); border-radius: 10px; color: var(--accent); font-size: var(--t0); cursor: pointer; flex: 1 1 auto; }
.filebtn:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.filepick input:focus-visible + .filebtn { outline: 2px solid var(--accent); outline-offset: 2px; }
.fname { flex: 1 1 100%; overflow-wrap: anywhere; }
label + .filepick, input + .filepick { margin-top: var(--s3); }

/* Tabs / chips */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: var(--s1) 0 var(--s2); }
main .tabs a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s3); border-radius: 99px; border: 1px solid var(--edge); color: var(--ink); text-decoration: none; white-space: nowrap; font-size: 14px; }
main .tabs a.on { border-color: var(--accent); border-width: 2px; padding: 0 15px; color: var(--accent); font-weight: 700; }
.top3 { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); }
.top3 button.chip { width: auto; margin: 0; min-height: 44px; padding: 0 12px; border-radius: 99px; font-size: 14px; font-weight: 500; }
.pill + .pill { margin-left: var(--s1); }
.brow { margin: 10px 0; }
.bar.prev { height: 4px; margin-top: 3px; }
.bar.prev > i { background: var(--muted); opacity: .6; }
.price-note { margin-top: var(--s1); }
.credit { color: var(--ok); font-weight: 600; }
.raw { font-size: 13px; overflow-wrap: anywhere; }

/* Report jump chips */
.jump { flex-wrap: nowrap; padding-bottom: var(--s1); }
.jump button.chip { width: auto; margin: 0; min-height: 44px; padding: 0 14px; border-radius: 99px; font-size: 14px; font-weight: 500; white-space: nowrap;
  background: transparent; color: var(--ink); border: 1px solid var(--edge); }
.jump button.chip:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); filter: none; }
[id^="sec-"] { scroll-margin-top: 72px; }

/* Collapsible category checkbox tree */
.ctree-wrap { border: 1px solid var(--edge); border-radius: 10px; overflow: hidden; }
.ctree-wrap > * + * { border-top: 1px solid var(--line); }
.ctree-wrap > .ctree-row { padding-left: var(--s3); padding-right: var(--s3); }
details.ctree > summary { padding: 0 var(--s3); font-weight: 600; }
details.ctree[open] > summary { border-bottom: 1px solid var(--line); }
.ctree-body { padding: var(--s1) var(--s3); }
.ctree-body .ctree-body { padding-right: 0; padding-left: var(--s2); }
.ctree-body details.ctree > summary { padding-left: var(--s2); }
.ctree-row { gap: 12px; margin: 0; font-weight: 400; font-size: var(--t0); min-height: 44px; }
.ctree-row span { overflow-wrap: anywhere; }
.count { font-weight: 400; }

/* Home: summary + compact envelope rows */
.summary .big { margin: var(--s1) 0; }
details.env { padding: 0 var(--s3); }
details.env > summary { display: block; list-style: none; padding: 10px 0; min-height: 44px; font-weight: 400; }
details.env > summary::-webkit-details-marker { display: none; }
details.env > summary .row strong { font-weight: 600; }
details.env > summary .bar { height: 6px; margin-top: 6px; }
details.env[open] > summary { padding-bottom: var(--s2); }
details.env .detail { padding: 0 0 var(--s3); }
.card.env-row { padding: 10px var(--s3); min-height: 44px; }
.card.env-row .bar { height: 6px; margin-top: 6px; }
.chev::after { content: " ▾"; color: var(--muted); }
details[open] > summary .chev::after { content: " ▴"; }

@media (prefers-reduced-motion: no-preference) {
  button, a.btn, a.card, nav a, .filebtn { transition: background-color .15s, border-color .15s, filter .15s, color .15s; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; scroll-behavior: auto !important; }
}

/* Quick check + accuracy tables */
.qc > * + * { margin-top: var(--s2); }
.qc-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
button.qc-btn { min-height: 56px; font-size: 18px; font-weight: 700; margin: 0; }
.qc-actions .qc-btn:first-child { background: var(--ok); color: var(--on-accent); }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--muted); font-weight: 600; }

/* Request options */
.opt { margin: var(--s2) 0; }
.opt.chosen { border-color: var(--accent); border-width: 2px; padding: calc(var(--s3) - 1px); }
.opt > * + * { margin-top: var(--s2); }
.optprice { font-weight: 700; white-space: nowrap; }
.optmeta { align-items: center; }
.inline-opt { background: color-mix(in srgb, var(--accent) 6%, var(--card)); margin: var(--s2) 0 0; }
img.thumb { display: block; width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
main a.optlink { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-width: 44px; min-height: 44px; text-decoration: none; }
main a.optlink.textlink { justify-content: flex-start; text-decoration: underline; }
.optblk { border-top: 1px solid var(--line); margin-top: var(--s3); padding-top: var(--s2); }
.optblk h3 { margin: 0; font-size: var(--t0); }
.pick { border: 1px solid var(--edge); border-radius: 10px; margin: var(--s3) 0 0; padding: var(--s2) var(--s3) var(--s3); }
.pick legend { font-weight: 600; font-size: 14px; padding: 0 var(--s1); }
.pick[hidden] { display: none; }
.pickrow { display: flex; align-items: center; gap: var(--s3); margin: var(--s2) 0 0; padding: var(--s2) var(--s3); min-height: 44px; font-weight: 500; font-size: var(--t0);
  border: 1px solid var(--edge); border-radius: 10px; cursor: pointer; }
.pickrow input { width: 22px; height: 22px; min-height: 0; flex: none; margin: 0; padding: 0; accent-color: var(--accent); }
.pickrow:has(input:checked) { border-color: var(--accent); border-width: 2px; padding: calc(var(--s2) - 1px) calc(var(--s3) - 1px); }
details.suggest { margin-top: var(--s2); }
details.suggest > summary { color: var(--accent); }

/* Settings > Categories: collapsible nodes nested to any depth */
.cadm { margin-top: var(--s3); }
details.cnode > summary { padding: 0 var(--s3); font-weight: 600; }
details.cnode > summary .cname { overflow-wrap: anywhere; }
details.cnode[open] > summary { border-bottom: 1px solid var(--line); }
.cadm details.cnode { border-top: 1px solid var(--line); }
.cadm > details.cnode:first-child { border-top: 0; }
.cnode-body { padding: var(--s2) 0 0; }
.cnode-body > details.cnode { margin-left: 6px; border-left: 2px solid var(--line); }
.cnode-body > details.cnode > summary { padding: 0 var(--s2); }
.cact { display: flex; flex-wrap: wrap; gap: var(--s2); padding: 0 var(--s3) var(--s2); }
.cnode-body > details.cnode .cact { padding-left: var(--s2); padding-right: var(--s2); }
.cact button { width: auto; margin: 0; min-height: 44px; padding: 0 var(--s3); font-size: 14px; }
button.secondary.danger { color: var(--bad); border-color: var(--bad); }
button.danger-solid { background: var(--bad); color: var(--on-accent); }
.cpanel { margin: 0 var(--s2) var(--s2); padding: var(--s2) var(--s3) var(--s3); border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.cpanel[hidden] { display: none; }
.cform label { margin-top: var(--s1); }
.cform p { margin: var(--s2) 0 0; }
.crow { display: flex; flex-wrap: wrap; gap: var(--s2); }
.crow button { width: auto; flex: 1 1 120px; margin-top: var(--s3); }
.cprev { margin-top: var(--s2); }

/* Accounts: balances, hidden-account lock, sparkline */
svg.lock { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -2px; flex: none; }
.pill svg.lock { width: 12px; height: 12px; vertical-align: -1px; }
.big-num { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.own-total { margin: 0 0 var(--s2); padding: var(--s2) var(--s3); border: 1px dashed var(--edge); border-radius: 10px; }
.acct-card a.muted { display: inline-flex; align-items: center; min-height: 44px; }
.spark-wrap { margin: var(--s2) 0; min-height: 30px; }
svg.spark { display: block; width: 100%; height: 36px; fill: none; stroke: var(--accent); stroke-width: 2; }
svg.spark polyline { vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.acct-card details summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
.hide-opt { margin-top: var(--s2); }
.hide-opt[hidden], .credit-only[hidden], .liab-only[hidden] { display: none; }
