/* =========================================================
   Family Finance HQ — stylesheet v2 ("quiet ledger")
   From the Claude Design system (ffhq.css), sections 1–19.
   Sections 21–23 map the app's existing markup onto it.
   Plain CSS. No web fonts, no images, no inline styles needed.
   Light + dark via prefers-color-scheme.
   ========================================================= */

/* ---------- 1. Tokens: light (default) ---------- */
:root {
  /* surfaces + ink */
  --bg: #F6F3EC;          /* warm paper */
  --panel: #FFFDF8;       /* raised sheet */
  --soft: #EEE9DF;        /* quiet fill: hover, chips, skeleton */
  --line: #E2DCD0;        /* hairline */
  --line-strong: #CFC7B8; /* input borders */
  --ink: #1E2320;         /* body text  ~15:1 on bg */
  --muted: #5B6059;       /* secondary  ~5.8:1 on bg */

  /* one accent */
  --accent: #0F5961;      /* deep teal  ~7.4:1 on bg */
  --accent-hover: #0A474E;
  --accent-ink: #FFFFFF;  /* text on accent */
  --accent-soft: #E1ECEA;

  /* money + status */
  --in: #1F6A4A;          /* money in, green-teal ~6.2:1 */
  --in-soft: #E2EEE6;
  --out: #9C3B26;         /* money out, brick ~6.4:1 */
  --out-soft: #F5E5DF;
  --warn: #855600;        /* ~5.6:1 */
  --warn-soft: #F7ECD6;
  --bad: #A8271D;         /* ~6.3:1 */
  --bad-soft: #F7E1DD;

  /* chart series (distinct in lightness too) */
  --s1: #0F5961;
  --s2: #B9802F;
  --s3: #6F8551;
  --s4: #A45A48;
  --s5: #5F6596;
  --s6: #948D80;

  /* type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --fs-xs: 0.75rem;    /* 12  badges, captions */
  --fs-sm: 0.875rem;   /* 14  meta, table head */
  --fs-base: 0.9375rem;/* 15  body, table cells */
  --fs-md: 1.0625rem;  /* 17  section titles */
  --fs-lg: 1.25rem;    /* 20  card titles */
  --fs-xl: clamp(1.5rem, 1.2rem + 1vw, 1.875rem);  /* 24–30 KPI, page title */
  --fs-2xl: clamp(1.75rem, 1.3rem + 1.6vw, 2.25rem); /* 28–36 hero number */
  --lh: 1.5;
  --lh-tight: 1.2;
  --w-regular: 400;
  --w-medium: 500;
  --w-bold: 600;

  /* space: 8px grid (4 for hairline nudges) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;
  --gutter: clamp(16px, 4vw, 48px);
  --maxw: 1200px;
  --row: 44px;
  --ctl: 40px;           /* control height; 44 on touch */

  /* shape + motion */
  --r: 8px;
  --r-sm: 6px;
  --r-lg: 12px;
  --r-pill: 999px;
  --shadow-pop: 0 4px 16px rgba(30, 35, 32, 0.10);
  --dur: 120ms;
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  color-scheme: light;
}

/* ---------- 1b. Tokens: dark ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141715;
    --panel: #1B1F1D;
    --soft: #242927;
    --line: #2D3330;
    --line-strong: #414845;
    --ink: #ECE8DF;
    --muted: #A7A99F;
    --accent: #72C3C2;
    --accent-hover: #93D4D2;
    --accent-ink: #0B1A1A;
    --accent-soft: #1E3332;
    --in: #6FCB9B;
    --in-soft: #1C3127;
    --out: #F0907A;
    --out-soft: #3A231D;
    --warn: #E9B65C;
    --warn-soft: #362B17;
    --bad: #FF8F84;
    --bad-soft: #3D1F1C;
    --s1: #72C3C2;
    --s2: #E0AE62;
    --s3: #A3BC83;
    --s4: #E09481;
    --s5: #9EA4D8;
    --s6: #8A857B;
    --shadow-pop: 0 4px 16px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

@media (pointer: coarse) { :root { --ctl: 44px; } }

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
.app {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh);
  -webkit-font-smoothing: antialiased;
}
.app h1, .app h2, .app h3, .app h4, .app p { margin: 0; }
.app a { color: var(--accent); text-decoration: none; }
.app a:hover { text-decoration: underline; text-underline-offset: 3px; }
.app svg { flex: none; }
.app img { max-width: 100%; }
.app code, .app pre, .app kbd { font-family: var(--mono); }
.num, .app td.num, .app th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.strong { font-weight: var(--w-bold); }
.money-in { color: var(--in); }
.money-out { color: var(--out); }
.mask { font-family: var(--mono); font-size: 0.92em; letter-spacing: 0.02em; }
.code { color: var(--muted); font-size: var(--fs-xs); font-weight: var(--w-medium); margin-left: 4px; letter-spacing: 0.04em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible, .is-focus { outline: none; box-shadow: var(--focus); }

@media (prefers-reduced-motion: no-preference) {
  .btn, .seg button, .navlink, .fbtn, .iconbtn, .disclose svg { transition: background-color var(--dur), color var(--dur), border-color var(--dur), transform var(--dur); }
}

/* ---------- 3. Layout ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding-inline: var(--gutter); }
.stack { display: flex; flex-direction: column; gap: var(--sp-5); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-3); }
.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid-kpi { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-4); }
.grid-2 { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: var(--sp-5); }
.grid-2e { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-5); }
.side-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.main { padding-block: var(--sp-6) var(--sp-8); }
.main > .stack { gap: var(--sp-6); }
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }

/* ---------- 4. Top bar + navigation ---------- */
.topbar { background: var(--bg); border-bottom: 1px solid var(--line); }
.topbar-in { display: flex; align-items: center; gap: var(--sp-5); min-height: 64px; }
.brand { display: flex; align-items: center; gap: var(--sp-2); font-weight: var(--w-bold); color: var(--ink); white-space: nowrap; }
.app a.brand { color: var(--ink); }
.app a.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: var(--r-sm); background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.mainnav { display: flex; gap: var(--sp-1); }
.app .navlink {
  display: inline-flex; align-items: center; height: var(--ctl); padding: 0 var(--sp-3);
  border-radius: var(--r); color: var(--muted); font-weight: var(--w-medium);
}
.app .navlink:hover { color: var(--ink); background: var(--soft); text-decoration: none; }
.app .navlink[aria-current="page"] { color: var(--ink); background: var(--soft); }
.topbar-tools { display: flex; align-items: center; gap: var(--sp-2); margin-left: auto; }

.subnav { border-bottom: 1px solid var(--line); }
.subnav-in { display: flex; gap: var(--sp-5); flex-wrap: wrap; }
.app .sublink {
  display: inline-flex; align-items: center; min-height: 44px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: var(--fs-sm); font-weight: var(--w-medium);
}
.app .sublink:hover { color: var(--ink); text-decoration: none; }
.app .sublink[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
button.sublink { background: none; border: 0; border-bottom: 2px solid transparent; padding: 0; font: inherit; font-size: var(--fs-sm); font-weight: var(--w-medium); cursor: pointer; }
.subnav-2 { display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: center; padding: var(--sp-2) 0 var(--sp-3); }
.subnav-2[hidden] { display: none; }
.seg a.seg-a { display: inline-flex; align-items: center; height: 34px; padding: 0 var(--sp-3); border-radius: var(--r-sm); color: var(--muted);
  font-size: var(--fs-sm); font-weight: var(--w-medium); white-space: nowrap; text-decoration: none; }
.seg a.seg-a:hover { color: var(--ink); }
.seg a.seg-a[aria-current="page"] { background: var(--panel); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }

.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }
.pagehead h1 { font-size: var(--fs-xl); line-height: var(--lh-tight); font-weight: var(--w-bold); letter-spacing: -0.01em; }
.pagehead .lede { color: var(--muted); margin-top: var(--sp-1); }
.controls { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

.foot { border-top: 1px solid var(--line); padding-block: var(--sp-5); color: var(--muted); font-size: var(--fs-sm); }
.privacy { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: var(--fs-sm); }

.bottomnav { display: none; }
.only-mobile { display: none; }

/* ---------- 5. Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--ctl); padding: 0 var(--sp-4); border-radius: var(--r);
  border: 1px solid transparent; font: inherit; font-weight: var(--w-medium); line-height: 1;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.app .btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover, .btn-primary.is-hover { background: var(--accent-hover); }
.app a.btn-primary { color: var(--accent-ink); }
.btn-secondary { background: var(--panel); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover, .btn-secondary.is-hover { background: var(--soft); }
.app a.btn-secondary { color: var(--ink); }
.btn-quiet { background: transparent; color: var(--accent); padding: 0 var(--sp-2); }
.btn-quiet:hover, .btn-quiet.is-hover { background: var(--accent-soft); }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn-danger:hover, .btn-danger.is-hover { background: var(--bad-soft); }
.btn-sm { height: 32px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn[disabled], .btn.is-disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary[disabled]:hover { background: var(--accent); }

.iconbtn {
  display: inline-grid; place-items: center; width: var(--ctl); height: var(--ctl);
  border-radius: var(--r); border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
}
.iconbtn:hover, .iconbtn.is-hover { background: var(--soft); color: var(--ink); }
.app a.iconbtn { color: var(--muted); }
.app a.iconbtn:hover { color: var(--ink); }
.app a.iconbtn[aria-current="page"] { background: var(--soft); color: var(--ink); }
.iconbtn-sm { width: 32px; height: 32px; }

/* ---------- 6. Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: var(--fs-sm); font-weight: var(--w-medium); color: var(--ink); }
.hint { font-size: var(--fs-sm); color: var(--muted); }
.err { font-size: var(--fs-sm); color: var(--bad); }
.input, .select {
  height: var(--ctl); width: 100%; padding: 0 var(--sp-3);
  background: var(--panel); color: var(--ink); border: 1px solid var(--line-strong); border-radius: var(--r);
  font: inherit; min-width: 0;
}
.input::placeholder { color: var(--muted); }
.input:hover, .select:hover, .input.is-hover { border-color: var(--muted); }
.input:focus-visible, .select:focus-visible, .input.is-focus, .select.is-focus { border-color: var(--accent); box-shadow: var(--focus); outline: none; }
.input[disabled], .select[disabled], .input.is-disabled { background: var(--soft); color: var(--muted); cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--bad); }
.select-wrap { position: relative; display: inline-flex; min-width: 0; }
.select-wrap .select { appearance: none; -webkit-appearance: none; padding-right: 36px; cursor: pointer; }
.select-wrap > svg { position: absolute; right: 12px; top: 50%; margin-top: -8px; pointer-events: none; color: var(--muted); }
.select-sm { height: 32px; font-size: var(--fs-sm); }

.search { position: relative; width: 300px; max-width: 100%; }
.search .input { padding-left: 38px; padding-right: 40px; background: var(--panel); }
.search > svg { position: absolute; left: 12px; top: 50%; margin-top: -8px; color: var(--muted); pointer-events: none; }
.kbd {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  border: 1px solid var(--line-strong); border-radius: 4px; font-family: var(--mono); font-size: var(--fs-xs); color: var(--muted); background: var(--bg);
}
.search .kbd { position: absolute; right: 10px; top: 50%; margin-top: -11px; pointer-events: none; }
.search .input:not(:placeholder-shown) ~ .kbd, .search .input:focus ~ .kbd { display: none; }

.check { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.check input, input.cb { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.check input:disabled { cursor: not-allowed; }

.switch {
  position: relative; width: 40px; height: 24px; border-radius: var(--r-pill); border: 0; padding: 0;
  background: var(--line-strong); cursor: pointer; flex: none;
}
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--panel); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { left: 19px; }

/* ---------- 7. Segmented control + chips + filter buttons ---------- */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--soft); border-radius: var(--r); flex-wrap: wrap; }
.seg button {
  height: 34px; padding: 0 var(--sp-3); border: 0; border-radius: var(--r-sm); background: transparent;
  color: var(--muted); font: inherit; font-size: var(--fs-sm); font-weight: var(--w-medium); cursor: pointer; white-space: nowrap;
}
.seg button:hover, .seg button.is-hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.seg button[disabled] { opacity: 0.45; cursor: not-allowed; }
.seg .code { margin-left: 3px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 var(--sp-3);
  border-radius: var(--r-pill); border: 1px solid var(--line-strong); background: var(--panel);
  font: inherit; font-size: var(--fs-sm); color: var(--ink); cursor: pointer;
}
.chip:hover, .chip.is-hover { background: var(--soft); }
.chip[aria-pressed="true"], a.chip[aria-current="page"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
a.chip { text-decoration: none; }

.fbtn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 var(--sp-3);
  border-radius: var(--r); border: 1px solid var(--line-strong); background: var(--panel);
  font: inherit; font-size: var(--fs-sm); color: var(--ink); cursor: pointer; white-space: nowrap;
}
.fbtn:hover, .fbtn.is-hover { background: var(--soft); }
.fbtn .fval { font-weight: var(--w-bold); }
.fbtn.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.fbtn svg { color: currentColor; }

/* ---------- 8. Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px;
  border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: var(--w-bold); line-height: 1;
  white-space: nowrap; border: 1px solid transparent; background: var(--soft); color: var(--muted);
}
.b-ok { background: var(--in-soft); color: var(--in); }
.b-accent { background: var(--accent-soft); color: var(--accent); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-muted { background: transparent; color: var(--muted); border-color: var(--line-strong); }

/* ---------- 9. Panels, sections, KPI ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); }
.panel-pad { padding: var(--sp-5); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.section-head h2 { font-size: var(--fs-md); font-weight: var(--w-bold); }
.section-head .meta { color: var(--muted); font-size: var(--fs-sm); }
.eyebrow { font-size: var(--fs-xs); font-weight: var(--w-bold); color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }

.kpi { padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); }
.kpi-label { font-size: var(--fs-sm); color: var(--muted); font-weight: var(--w-medium); }
.kpi-value { font-size: var(--fs-xl); font-weight: var(--w-bold); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; line-height: var(--lh-tight); }
.kpi-sub { font-size: var(--fs-sm); color: var(--muted); font-variant-numeric: tabular-nums; }

/* simple lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: var(--sp-3); min-height: 56px; padding: var(--sp-2) 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.li-main { flex: 1 1 auto; min-width: 0; }
.li-title { font-weight: var(--w-medium); }
.li-meta { font-size: var(--fs-sm); color: var(--muted); }

/* category bars (SVG rect widths are attributes, so CSP-safe) */
.bars { display: flex; flex-direction: column; gap: var(--sp-3); }
.bar-row { display: grid; grid-template-columns: 150px minmax(0, 1fr) 96px; align-items: center; gap: var(--sp-3); }
.bar-row svg { width: 100%; height: 10px; display: block; }
.bar-track { fill: var(--soft); }
.bar-fill { fill: var(--s1); }
.bar-fill.f2 { fill: var(--s2); } .bar-fill.f3 { fill: var(--s3); } .bar-fill.f4 { fill: var(--s4); }
.bar-fill.f5 { fill: var(--s5); } .bar-fill.f6 { fill: var(--s6); }
.progress { width: 100%; height: 8px; display: block; }
.prog-track { fill: var(--soft); } .prog-fill { fill: var(--accent); }

/* ---------- 10. Data table ---------- */
.table-box { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); }
.table-box.scroll { max-height: 640px; overflow: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-base); }
.table th {
  position: sticky; top: 0; z-index: 1; background: var(--panel); text-align: left;
  font-size: var(--fs-sm); font-weight: var(--w-medium); color: var(--muted);
  padding: 0 var(--sp-4); height: var(--row); border-bottom: 1px solid var(--line-strong); white-space: nowrap;
}
.table td { padding: var(--sp-2) var(--sp-4); height: var(--row); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td, .table tr.is-hover td { background: var(--bg); }
.table tr.is-selected td { background: var(--accent-soft); }
.table tr.is-expanded td { background: var(--bg); border-bottom-color: transparent; }
.table tr.detail td { background: var(--bg); padding: 0 var(--sp-4) var(--sp-5); }
.table tr.group td { height: 40px; background: var(--bg); font-size: var(--fs-sm); font-weight: var(--w-bold); color: var(--ink); }
.table tr.group td .muted { font-weight: var(--w-regular); }
.table tr.is-closed td { color: var(--muted); }
.table tr.is-closed td .acct-name { font-weight: var(--w-regular); }
.table td.cb, .table th.cb { width: 48px; padding-right: 0; }
.table td.act, .table th.act { width: 56px; text-align: right; padding-left: 0; }
.acct { display: flex; flex-direction: column; }
.acct-name { font-weight: var(--w-medium); }
.acct-sub { font-size: var(--fs-sm); color: var(--muted); }
.cell-edit { height: 32px; font-size: var(--fs-sm); }
.disclose { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--r-sm); border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.disclose:hover { background: var(--soft); color: var(--ink); }
.disclose[aria-expanded="true"] svg { transform: rotate(180deg); }
.table-foot { display: flex; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--line); font-size: var(--fs-sm); color: var(--muted); }

/* month coverage strip (shape + text, never colour alone) */
.cov { display: inline-flex; gap: 3px; vertical-align: middle; }
.cov i { display: block; width: 9px; height: 18px; border-radius: 2px; }
.cov .c-ok { background: var(--accent); }
.cov .c-miss { background: transparent; border: 1.5px solid var(--bad); }
.cov .c-wait { background: var(--warn-soft); border: 1.5px dashed var(--warn); }
.cov .c-future { background: var(--soft); }
.cov-text { font-size: var(--fs-sm); color: var(--muted); margin-left: var(--sp-2); }

/* expanded detail */
.detail-box { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--sp-5); padding: var(--sp-5); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); }
.mini { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.mini th { text-align: left; color: var(--muted); font-weight: var(--w-medium); padding: 6px 0; border-bottom: 1px solid var(--line); }
.mini td { padding: 8px 0; border-bottom: 1px solid var(--line); }
.mini th.num, .mini td.num { text-align: right; padding-left: var(--sp-3); }
.mini tr:last-child td { border-bottom: 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px var(--sp-4); font-size: var(--fs-sm); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.reveal { font-family: var(--mono); background: var(--warn-soft); color: var(--ink); padding: 1px 6px; border-radius: 4px; }

/* selection bar */
.selbar {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-4); border-radius: var(--r-lg);
  background: var(--ink); color: var(--bg);
}
.selbar .strong { margin-right: auto; }
.selbar .btn-secondary { background: transparent; color: var(--bg); border-color: rgba(127,127,127,0.5); }
.selbar .btn-secondary:hover { background: rgba(127,127,127,0.2); }
.selbar .btn-primary { background: var(--bg); color: var(--ink); }

/* ---------- 11. Search results panel ---------- */
.searchpanel { width: 600px; max-width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); overflow: hidden; }
.sp-head { padding: 4px var(--sp-4); font-size: var(--fs-xs); font-weight: var(--w-bold); color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.sp-foot { display: flex; gap: var(--sp-4); padding: var(--sp-2) var(--sp-4); border-top: 1px solid var(--line); font-size: var(--fs-xs); color: var(--muted); flex-wrap: wrap; }

/* ---------- 12. Drop zone ---------- */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-2); text-align: center;
  padding: var(--sp-7) var(--sp-5); border: 2px dashed var(--line-strong); border-radius: var(--r-lg); background: var(--panel); color: var(--muted);
}
.drop .drop-title { color: var(--ink); font-size: var(--fs-md); font-weight: var(--w-bold); }
.drop.is-over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.drop.is-compact { flex-direction: row; padding: var(--sp-4) var(--sp-5); justify-content: flex-start; text-align: left; gap: var(--sp-3); }

/* ---------- 13. Notice + toast ---------- */
.notice { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--r); border: 1px solid var(--line); background: var(--panel); }
.notice > svg { margin-top: 2px; }
.notice .n-body { flex: 1 1 auto; min-width: 0; }
.notice .n-title { font-weight: var(--w-bold); }
.n-info { background: var(--accent-soft); border-color: transparent; }
.n-info > svg { color: var(--accent); }
.n-warn { background: var(--warn-soft); border-color: transparent; }
.n-warn > svg { color: var(--warn); }
.n-bad { background: var(--bad-soft); border-color: transparent; }
.n-bad > svg { color: var(--bad); }

.toast { display: inline-flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-4); border-radius: var(--r); background: var(--ink); color: var(--bg); font-size: var(--fs-sm); box-shadow: var(--shadow-pop); max-width: 100%; }
.app .toast a, .toast .tbtn { color: var(--bg); font-weight: var(--w-bold); text-decoration: underline; text-underline-offset: 3px; background: none; border: 0; font: inherit; cursor: pointer; }
.toast .t-ok { color: var(--in-soft); }
.toast .t-bad { color: var(--bad-soft); }
.toasts { position: fixed; right: var(--sp-5); bottom: var(--sp-5); display: flex; flex-direction: column; align-items: flex-end; gap: var(--sp-2); z-index: 20; max-width: min(480px, calc(100vw - 2 * var(--sp-5))); }

/* ---------- 14. Menu (download) ---------- */
.menu { min-width: 260px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); padding: var(--sp-2); }
.menu-head { padding: var(--sp-2) var(--sp-3); font-size: var(--fs-xs); color: var(--muted); }
.menuitem { display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 40px; padding: 0 var(--sp-3); border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.menuitem:hover, .menuitem.is-hover { background: var(--soft); }
.menuitem .mi-meta { margin-left: auto; font-size: var(--fs-xs); color: var(--muted); }
.popwrap { position: relative; display: inline-block; }
.popwrap .menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; }

/* ---------- 15. Import + mapping ---------- */
.steps { display: flex; gap: var(--sp-5); list-style: none; margin: 0; padding: 0; flex-wrap: wrap; font-size: var(--fs-sm); }
.steps li { display: flex; align-items: center; gap: var(--sp-2); color: var(--muted); }
.steps .dot { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--line-strong); font-size: var(--fs-xs); font-weight: var(--w-bold); }
.steps li[aria-current="step"] { color: var(--ink); font-weight: var(--w-medium); }
.steps li[aria-current="step"] .dot { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.steps li.done .dot { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.lockbox { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: var(--sp-5); align-items: end; }
.file { display: flex; align-items: center; gap: var(--sp-3); }
.file-ico { width: 36px; height: 36px; border-radius: var(--r-sm); background: var(--soft); color: var(--muted); display: grid; place-items: center; flex: none; }
.file-name { font-weight: var(--w-medium); overflow-wrap: anywhere; }

.tablist { display: flex; flex-direction: column; gap: 2px; }
.tabitem { display: flex; align-items: center; gap: var(--sp-3); min-height: 48px; padding: 0 var(--sp-3); border-radius: var(--r); border: 0; background: transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer; width: 100%; }
.tabitem:hover { background: var(--soft); }
.tabitem[aria-selected="true"] { background: var(--panel); box-shadow: 0 0 0 1px var(--line); font-weight: var(--w-medium); }
.tabitem .badge { margin-left: auto; }

.maprow { display: grid; grid-template-columns: minmax(0, 1.2fr) 24px minmax(0, 1fr) 110px; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; border-bottom: 1px solid var(--line); }
.maprow:last-child { border-bottom: 0; }
.maprow .src-col { font-weight: var(--w-medium); }
.maprow .src-sample { font-size: var(--fs-sm); color: var(--muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.maprow .arrow { color: var(--muted); }
.maprow .select-wrap { width: 100%; }
.maprow-head { padding: 0 0 var(--sp-2); border-bottom: 1px solid var(--line-strong); font-size: var(--fs-sm); color: var(--muted); }

/* ---------- 16. States ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-3); padding: var(--sp-8) var(--sp-5); }
.empty h2 { font-size: var(--fs-lg); }
.empty p { color: var(--muted); max-width: 46ch; }
.skel { display: block; height: 12px; border-radius: 4px; background: var(--soft); }
.skel.w40 { width: 40%; } .skel.w60 { width: 60%; } .skel.w80 { width: 80%; } .skel.w20 { width: 20%; }
.skel.tall { height: 28px; }
@media (prefers-reduced-motion: no-preference) {
  .skel { animation: pulse 1.4s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: 0.55; } }
}
.is-dim { opacity: 0.6; }
.overdue { color: var(--bad); font-weight: var(--w-medium); }

/* ---------- 17. Phone (≤ 640px) ---------- */
@media (max-width: 640px) {
  :root { --ctl: 44px; --gutter: 16px; }
  .only-desktop { display: none !important; }
  .only-mobile { display: inline-flex; }
  .topbar-in { min-height: 56px; gap: var(--sp-2); }
  .mainnav, .topbar .search { display: none; }
  .brand-text { font-size: var(--fs-base); }
  .subnav-in { gap: var(--sp-4); }
  .main { padding-block: var(--sp-5) var(--sp-7); }
  .main > .stack { gap: var(--sp-5); }
  .pagehead { align-items: stretch; flex-direction: column; }
  .controls { width: 100%; }
  .controls > .select-wrap { flex: 1 1 140px; }
  .controls .select-wrap .select { width: 100%; }
  .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
  .kpi { padding: var(--sp-4); }
  .grid-2, .grid-2e, .grid-3, .side-layout, .detail-box, .lockbox { grid-template-columns: minmax(0, 1fr); }
  .bar-row { grid-template-columns: minmax(0, 1fr) 88px; }
  .bar-row svg { grid-column: 1 / -1; grid-row: 2; }
  .panel-pad { padding: var(--sp-4); }

  /* tables become stacked records */
  .table-box { border: 0; background: transparent; overflow: visible; }
  .table.stackable thead { display: none; }
  .table.stackable, .table.stackable tbody { display: block; }
  .table.stackable tr { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px var(--sp-3); padding: var(--sp-4); margin-bottom: var(--sp-2); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); }
  .table.stackable td { display: block; height: auto; padding: 0; border: 0; background: transparent !important; }
  .table.stackable td.primary { grid-column: 1 / 3; }
  .table.stackable td.cb + td.primary { grid-column: 2 / 3; }
  .table.stackable td.num.primary-num { grid-column: 3; grid-row: 1; }
  .table.stackable td.act { grid-column: 3; grid-row: 1; width: auto; display: flex; align-items: flex-start; justify-content: flex-end; gap: 2px; white-space: nowrap; }
  .table.stackable td.lbl { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: var(--sp-3); font-size: var(--fs-sm); }
  .table.stackable td.lbl::before { content: attr(data-label); color: var(--muted); }
  .table.stackable td.cb + td.primary ~ td.lbl { grid-column: 2 / -1; }
  .table.stackable td.hide-m { display: none; }
  .table.stackable tr.group { background: transparent; border: 0; padding: var(--sp-4) 0 var(--sp-1); margin: 0; }
  .table.stackable tr.group td { grid-column: 1 / -1; height: auto; }
  .table.stackable tr.is-selected { border-color: var(--accent); }
  .table.stackable tr.is-selected td { background: transparent !important; }
  .table.stackable tr.is-expanded { margin-bottom: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom: 0; }
  .table.stackable tr.detail { display: block; padding: 0 var(--sp-3) var(--sp-3); border-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; }
  .table.stackable tr.detail td { padding: 0; }
  .table-foot { padding-inline: 0; border: 0; }
  .detail-box { padding: var(--sp-4); }
  .selbar { position: fixed; left: var(--sp-3); right: var(--sp-3); bottom: 76px; z-index: 15; }
  .selbar .btn-label { display: none; }

  .bottomnav {
    display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 14;
    background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .app .bnlink { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 60px; font-size: 10.5px; font-weight: var(--w-medium); color: var(--muted); min-width: 0; }
  .app .bnlink:hover { text-decoration: none; color: var(--ink); }
  .app .bnlink[aria-current="page"] { color: var(--accent); }
  .toasts { left: var(--sp-3); right: var(--sp-3); bottom: 76px; max-width: none; align-items: stretch; }
}
@media (min-width: 641px) { .only-mobile { display: none !important; } }

/* ---------- 18. Print ---------- */
@media print {
  .topbar, .subnav, .bottomnav, .controls, .selbar, .toasts, .btn, .iconbtn, .foot, .skip { display: none !important; }
  .app { background: #fff; color: #000; }
  .panel, .table-box, .tablewrap, .card { border-color: #bbb; }
  .table th, #view th { position: static; }
  .wrap { max-width: none; padding: 0; }
  .row.dl, .chips, .seg, .row.filters, #view button { display: none !important; }
  .tablewrap { max-height: none !important; overflow: visible !important; }
}

/* ---------- 19. Utilities ---------- */
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }
.amt-col { display: flex; flex-direction: column; gap: 2px; align-items: flex-end; text-align: right; }
.gap-0 { gap: 0; }
.nowrap { white-space: nowrap; }
.mb-2 { margin-bottom: var(--sp-2); }
.cellbtn { display: inline-flex; align-items: center; min-height: 32px; padding: 0 var(--sp-2); margin-left: calc(-1 * var(--sp-2)); border: 1px solid transparent; border-radius: var(--r-sm); background: transparent; color: var(--ink); font: inherit; cursor: pointer; text-align: left; }
.cellbtn:hover, .cellbtn.is-hover { background: var(--soft); border-color: var(--line-strong); }

/* ---------- 21. App shell ---------- */
[hidden] { display: none !important; }
body.app { display: flex; flex-direction: column; }
body.app > .main { flex: 1 0 auto; }
#view { outline: none; }
#view > * { min-width: 0; max-width: 100%; }
.skip { position: absolute; left: var(--sp-3); top: -64px; z-index: 30; background: var(--panel); color: var(--accent); padding: var(--sp-2) var(--sp-3); border-radius: var(--r); border: 1px solid var(--line); }
.skip:focus { top: var(--sp-2); }
.topbar { position: sticky; top: 0; z-index: 12; }
.topbar .btn-primary .btn-label { display: inline; }

/* search everything: results panel under the top-bar field */
.gs-panel { position: absolute; top: calc(100% + 6px); right: 0; width: min(600px, calc(100vw - 2 * var(--gutter))); max-height: min(70vh, 560px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); padding: var(--sp-2) 0; z-index: 20; }
.gs-group { padding: var(--sp-2) 0; }
.gs-group + .gs-group { border-top: 1px solid var(--line); }
.gs-head { padding: 4px var(--sp-4); font-size: var(--fs-xs); font-weight: var(--w-bold); color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.gs-head .muted { font-weight: var(--w-regular); letter-spacing: 0; text-transform: none; }
.gs-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 var(--sp-3); align-items: center; width: 100%; min-height: 40px; padding: 6px var(--sp-4);
  border: 0; border-radius: 0; background: transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.gs-item:hover { background: var(--bg); }
.gs-item.on, .gs-item[aria-selected="true"] { background: var(--accent-soft); }
.gs-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gs-sub { grid-column: 1 / -1; font-size: var(--fs-sm); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gs-more { color: var(--accent); font-weight: var(--w-medium); }
.gs-empty { padding: var(--sp-2) var(--sp-4); margin: 0; }
.gs-foot { display: flex; gap: var(--sp-4); padding: var(--sp-2) var(--sp-4) 0; margin-top: var(--sp-1); border-top: 1px solid var(--line); font-size: var(--fs-xs); color: var(--muted); flex-wrap: wrap; }

/* top bar at laptop-pane widths: drop the wordmark, then fold search and Import into icons */
.search-toggle, .app .import-icon { display: none; }
@media (max-width: 1120px) { .brand-text { display: none; } }
@media (max-width: 1080px) {
  .topbar .search { display: none; }
  .search-toggle { display: inline-grid; }
  .topbar.search-open .search { display: block; position: absolute; left: var(--gutter); right: var(--gutter); top: calc(100% + var(--sp-2)); width: auto; }
  .topbar .search .kbd { display: none; }
  .topbar .search .input { padding-right: var(--sp-3); }
  .gs-panel { left: 0; right: 0; width: auto; }
}
@media (max-width: 800px) { .import-full { display: none; } .app .import-icon { display: inline-grid; } }
@media (max-width: 640px) {
  .brand-text { display: inline; }
  .foot { padding-bottom: 88px; }
  .subnav-in { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .subnav-in::-webkit-scrollbar { display: none; }
  .app .sublink { white-space: nowrap; }
}

/* ---------- 22. Existing screens → v2 look ---------- */
/* page header: the first block of every screen */
#view h1 { font-size: var(--fs-xl); line-height: var(--lh-tight); font-weight: var(--w-bold); letter-spacing: -0.01em; }
#view h2 { font-size: var(--fs-md); font-weight: var(--w-bold); line-height: var(--lh-tight); }
#view h3 { font-size: var(--fs-base); font-weight: var(--w-bold); }
.lede { color: var(--muted); max-width: 75ch; }
#view h1 + .lede { margin-top: var(--sp-1); }
.spread { display: flex; flex-wrap: wrap; gap: var(--sp-3) var(--sp-4); justify-content: space-between; align-items: baseline; }
#view > .spread:first-child { align-items: flex-end; }
.in, .good { color: var(--in); } .out { color: var(--out); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.mono, .app code { font-family: var(--mono); font-size: 0.92em; }
.break { overflow-wrap: anywhere; }
td.break { min-width: 220px; }
.grid { display: grid; gap: var(--sp-5); grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); align-items: start; }

/* cards → panels */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--sp-5); display: grid; gap: var(--sp-4); align-content: start; min-width: 0; }
.card > .spread:first-child { align-items: baseline; }
.card > .spread:first-child > :not(h2) { color: var(--muted); }
.card > .spread:first-child > a { color: var(--accent); }
details.card > summary { color: var(--ink); font-weight: var(--w-medium); }
.doc { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--sp-5); display: grid; gap: var(--sp-3); min-width: 0; color: var(--ink); }
.doc.warn { border-color: var(--warn); }
.doc.bad { border-color: var(--bad); }
.card .doc { background: var(--bg); }

/* KPI tiles built by the older screens */
.kpis { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); }
.kpis > .kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); }
.kpi > .label { font-size: var(--fs-sm); color: var(--muted); font-weight: var(--w-medium); }
.kpi > .value { font-size: var(--fs-xl); font-weight: var(--w-bold); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; line-height: var(--lh-tight); }
.kpi > .sub { font-size: var(--fs-sm); color: var(--muted); font-variant-numeric: tabular-nums; }

/* chips (older markup uses .on) */
.chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* plain buttons and links styled as buttons */
:where(button:not([class])), button.primary, button.danger {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--ctl); padding: 0 var(--sp-4); border-radius: var(--r); border: 1px solid var(--line-strong);
  background: var(--panel); color: var(--ink); font: inherit; font-weight: var(--w-medium); line-height: 1;
  cursor: pointer; white-space: nowrap;
}
:where(button:not([class])):hover { background: var(--soft); }
:where(button:not([class])):disabled, button.primary:disabled, button.danger:disabled, button.link:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.danger:hover { background: var(--bad-soft); }
button.link { display: inline-flex; align-items: center; height: 32px; padding: 0 var(--sp-2); border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--accent); font: inherit; font-weight: var(--w-medium); cursor: pointer; white-space: nowrap; }
button.link:hover { background: var(--accent-soft); }
button.link.danger { color: var(--bad); }
button.link.danger:hover { background: var(--bad-soft); }
td :where(button:not([class])), td button.primary, td button.danger { height: 32px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn:not([class*="btn-"]) { background: var(--panel); border-color: var(--line-strong); }
.app a.btn:not([class*="btn-"]) { color: var(--ink); }
.btn:not([class*="btn-"]):hover { background: var(--soft); }

/* form controls */
:where(input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=range]), select, textarea) {
  height: var(--ctl); padding: 0 var(--sp-3); background: var(--panel); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r); font: inherit; min-width: 0; max-width: 100%;
}
:where(input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea):hover { border-color: var(--muted); }
:where(input, select, textarea):focus-visible { border-color: var(--accent); }
:where(input)::placeholder, :where(textarea)::placeholder { color: var(--muted); }
:where(input, select, textarea):disabled { background: var(--soft); color: var(--muted); cursor: not-allowed; }
:where(select) { cursor: pointer; }
:where(textarea) { height: auto; width: 100%; min-height: 88px; padding: var(--sp-2) var(--sp-3); font-family: var(--mono); font-size: var(--fs-sm); line-height: var(--lh); }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; flex: none; }
input[type=file] { font-size: var(--fs-sm); color: var(--muted); max-width: 100%; }
input[type=file]::file-selector-button { height: var(--ctl); padding: 0 var(--sp-4); margin-right: var(--sp-3); border-radius: var(--r); border: 1px solid var(--line-strong);
  background: var(--panel); color: var(--ink); font: inherit; font-weight: var(--w-medium); cursor: pointer; }
input[type=file]::file-selector-button:hover { background: var(--soft); }
td :where(input:not([type=checkbox]):not([type=radio]):not([type=file]), select) { height: 32px; padding: 0 var(--sp-2); font-size: var(--fs-sm); }
td select { max-width: 180px; }
label.f { display: flex; flex-direction: column; gap: 6px; min-width: 0; font-size: var(--fs-sm); font-weight: var(--w-medium); color: var(--ink); }
label.f > :where(input, select, textarea) { width: 100%; }
label.inline { display: inline-flex; gap: var(--sp-2); align-items: center; font-size: var(--fs-sm); color: var(--ink); }
.form { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); align-items: end; }
.row.filters input[type=search] { flex: 1 1 260px; min-width: min(100%, 220px); }
.row.dl { gap: var(--sp-2); }
.row.dl > span { margin-right: var(--sp-1); }
.row.dl button { height: 32px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }

/* tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); }
.tablewrap.short { max-height: 360px; overflow: auto; }
:where(#view) table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-base); }
:where(#view) th { position: sticky; top: 0; z-index: 1; background: var(--panel); text-align: left; font-size: var(--fs-sm); font-weight: var(--w-medium);
  color: var(--muted); padding: 0 var(--sp-4); height: var(--row); border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
:where(#view) td { padding: var(--sp-2) var(--sp-4); height: var(--row); border-bottom: 1px solid var(--line); vertical-align: middle; }
:where(#view) tbody > tr:last-child > td { border-bottom: 0; }
:where(#view) tbody > tr:hover > td { background: var(--bg); }
:where(.detail-row) tbody > tr:hover > td { background: var(--soft); }
td.desc { min-width: 240px; max-width: 480px; }
td.desc.small { min-width: 0; overflow-wrap: anywhere; }
td.empty { display: table-cell; text-align: center; color: var(--muted); padding: var(--sp-7) var(--sp-5); }
p.empty { color: var(--muted); }
tr.dim > td { color: var(--muted); }
tr.dim strong { font-weight: var(--w-medium); }
.detail-row > td { background: var(--bg); padding: var(--sp-4) var(--sp-4) var(--sp-5); }
.detail-row:hover > td { background: var(--bg) !important; }
.acct-detail { display: grid; gap: var(--sp-3); }
.acct-detail h3 { margin-top: var(--sp-3); }
.kv:not(dl) { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--sp-3) var(--sp-5); }
.kv:not(dl) > div { display: flex; flex-direction: column; gap: 2px; }

/* status text → badges */
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: var(--w-bold);
  line-height: 1; white-space: nowrap; background: transparent; color: var(--muted); border: 1px solid var(--line-strong); vertical-align: middle; }
.pill.ok, .pill.good, .pill.income { background: var(--in-soft); color: var(--in); border-color: transparent; }
.pill.expense { background: var(--out-soft); color: var(--out); border-color: transparent; }
.pill.invest { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.flag { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; margin-left: var(--sp-2); border-radius: var(--r-pill); font-size: var(--fs-xs);
  font-weight: var(--w-bold); background: var(--warn-soft); color: var(--warn); vertical-align: middle; white-space: nowrap; }

/* notices without an icon hold mixed inline text */
.notice:not(:has(> svg)) { display: block; }
.notice.warn { background: var(--warn-soft); border-color: transparent; color: var(--ink); }
.notice.bad { background: var(--bad-soft); border-color: transparent; color: var(--ink); }
.notice:not(:has(> svg)) > :is(p, div, ul, ol, details, .rule, .form, .row) + * { margin-top: var(--sp-2); }
.notice ul { margin: var(--sp-2) 0 0; padding-left: 18px; }
.notice > .n-body > a { font-weight: var(--w-medium); }

/* lists of due items */
.due { display: grid; grid-template-columns: 112px minmax(0, 1fr) auto; gap: var(--sp-3); align-items: baseline; min-height: 48px; padding: var(--sp-3) 0; border-bottom: 1px solid var(--line); }
.due:last-child { border-bottom: 0; }
.due:first-child { padding-top: 0; min-height: 0; }

/* drop zone */
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.drop > strong { color: var(--ink); font-size: var(--fs-md); font-weight: var(--w-bold); }
.drop .row { justify-content: center; margin-block: var(--sp-2); }

/* older bar charts (width set through CSSOM) */
.bar { display: grid; gap: 6px; }
.bar .top { display: flex; justify-content: space-between; gap: var(--sp-2); font-size: var(--fs-sm); }
.bar .track { position: relative; height: 10px; background: var(--soft); border-radius: 3px; }
.bar .fill { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: var(--s1); }
.bar .fill.over { background: var(--bad); }
.bar .limit { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: .55; }
.bar.click { cursor: pointer; border-radius: var(--r-sm); padding: 4px 6px; margin: -4px -6px; }
.bar.click:hover { background: var(--soft); }
.bar.sel { box-shadow: 0 0 0 1px var(--line-strong); }
@media (prefers-reduced-motion: no-preference) { .bar .fill { transition: width .3s ease-out; } }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 12px; font-family: var(--font); }
.chart .grid line { stroke: var(--line); }
.tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-sm); box-shadow: var(--shadow-pop); white-space: nowrap; display: grid; gap: 2px; font-variant-numeric: tabular-nums; z-index: 3; }
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-4); font-size: var(--fs-sm); color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* statement coverage per account */
.covrow { display: grid; gap: var(--sp-2); padding-top: var(--sp-4); border-top: 1px solid var(--line); }
.cov-strip { display: flex; flex-wrap: wrap; gap: 3px; padding-top: 14px; }
.cov-cell { position: relative; width: 10px; height: 20px; border-radius: 2px; background: var(--soft); }
.cov-cell.covered { background: var(--accent); }
.cov-cell.missing { background: transparent; border: 1.5px solid var(--bad); }
.cov-cell.current { background: transparent; border: 1.5px solid var(--line-strong); }
.cov-cell.waiting { background: var(--warn-soft); border: 1.5px dashed var(--warn); }
.cov-cell i { position: absolute; top: -16px; left: 0; font-style: normal; font-size: 10px; color: var(--muted); white-space: nowrap; }
.cov-key { display: inline-block; width: 10px; height: 14px; border-radius: 2px; margin-right: 6px; vertical-align: -2px; }
.cov-key.covered { background: var(--accent); }
.cov-key.missing { border: 1.5px solid var(--bad); }
.cov-key.current { border: 1.5px solid var(--line-strong); }
.cov-key.waiting { background: var(--warn-soft); border: 1.5px dashed var(--warn); }

/* misc */
details > summary { cursor: pointer; color: var(--accent); font-weight: var(--w-medium); min-height: 32px; line-height: 32px; }
details[open] > summary { margin-bottom: var(--sp-2); }
.instr { white-space: pre-wrap; font-size: var(--fs-sm); background: var(--soft); border-radius: var(--r); padding: var(--sp-2) var(--sp-3); margin-top: var(--sp-2); max-height: 220px; overflow: auto; }
.rule { display: grid; gap: 4px; padding: var(--sp-2) 0; border-bottom: 1px solid var(--line); }
.rule:last-of-type { border-bottom: 0; }
#view ol, #view ul:not(.list) { padding-left: 20px; margin: 0; }

/* ---------- 23. Overview ---------- */
.ov-cat { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app a.ov-cat { color: var(--ink); }
.bar-fill.over { fill: var(--bad); }
.bar-row .num.over { color: var(--bad); }
.kpi-head { margin-bottom: var(--sp-4); }
.ov-loading { display: grid; gap: var(--sp-4); }
.ov-loading .panel { padding: var(--sp-5); display: grid; gap: var(--sp-3); }
/* ---------- 24. Shared list toolbar pieces ---------- */
.search.search-sm { width: 240px; }
.search.search-sm .input { padding-right: var(--sp-3); }
.switch:disabled { opacity: 0.45; cursor: not-allowed; }
.popwrap.left .menu { left: 0; right: auto; }
.menu .menuitem { height: auto; }
.covwrap { display: inline-flex; align-items: center; white-space: nowrap; }
/* filter buttons: set ones read "Label: value" with an attached clear button */
.fgroup { display: inline-flex; }
.fgroup.is-active > .fbtn { border-top-right-radius: 0; border-bottom-right-radius: 0; border-right: 0; }
.fbtn-x { display: inline-grid; place-items: center; width: 32px; height: 36px; border: 1px solid var(--accent); border-left: 1px solid var(--line-strong);
  border-radius: 0 var(--r) var(--r) 0; background: var(--accent-soft); color: var(--accent); cursor: pointer; }
.fbtn-x:hover { background: var(--panel); }
.fmenu { max-height: 340px; overflow: auto; }
.fmenu .menuitem { gap: var(--sp-2); }
.fmenu .menuitem[aria-selected="true"] { font-weight: var(--w-medium); color: var(--accent); }
.fdates { padding: var(--sp-2); }
.search.grow-search { width: 100%; max-width: 560px; }
.table td.act .iconbtn + .iconbtn { margin-left: 2px; }
.table th.cb input, .table td.cb input { vertical-align: middle; }
.fs-md { font-size: var(--fs-md); }
/* transactions */
.muted-inv { font-weight: var(--w-regular); opacity: 0.75; }
.selbar .select-wrap .select { height: 32px; font-size: var(--fs-sm); background: transparent; color: var(--bg); border-color: rgba(127,127,127,0.5); }
.selbar .select-wrap .select option { color: var(--ink); background: var(--panel); }
.selbar .select-wrap > svg { color: var(--bg); }
.table td.desc { min-width: 220px; }
.table .cell-edit { width: auto; min-width: 140px; }
.table-foot .btn-quiet { height: 24px; padding: 0 var(--sp-1); }
.fbtn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* trackers */
.field-inline { flex-direction: row; align-items: center; gap: var(--sp-3); }
.tabitem .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.maprow .select-wrap .select { height: 32px; font-size: var(--fs-sm); }
.cellbtn.acct-name { font-weight: var(--w-medium); color: var(--accent); }
#map-h:focus { box-shadow: none; }
@media (max-width: 640px) {
  .field-inline { flex-direction: column; align-items: stretch; width: 100%; }
  .maprow { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .maprow .arrow { display: none; }
  .maprow .badge { grid-column: 1 / -1; justify-self: start; }
  .maprow-head { display: none; }
}
/* import */
.lock-more { border-top: 1px solid var(--line); padding-top: var(--sp-3); }
.lockbox .list > li { min-height: 48px; }
.drop > svg { color: var(--muted); }
.drop.is-over > svg { color: var(--accent); }
.drop .row { justify-content: center; }
.drop.is-compact .btn { flex: none; }
.table td .select-wrap { min-width: 160px; }
.table td .select-wrap .select { height: 32px; font-size: var(--fs-sm); }
.imp-detail .mini td:nth-child(2) { overflow-wrap: anywhere; }
.savebar { position: sticky; bottom: var(--sp-3); z-index: 5; box-shadow: var(--shadow-pop); }
@media (max-width: 640px) { .savebar { bottom: 72px; } .table td .select-wrap { min-width: 0; width: 100%; } }
.table tr.detail td { padding-top: 0; }
.table .mini td, .table tbody tr:hover .mini td, .table tr.detail .mini td, .table tr.detail .mini th { background: transparent; height: auto; padding: 8px 0; }
.table tr.detail .mini th { padding: 6px 0; }
.table tr.detail .mini td.num, .table tr.detail .mini th.num, .table tr.detail .mini td + td { padding-left: var(--sp-3); }
.detail-box .list > li { min-height: 48px; }
.detail-box .eyebrow { margin: 0; }
@media (max-width: 640px) {
  /* tables nested in an expanded record stay ordinary tables */
  .table.stackable .mini { display: table; }
  .table.stackable .mini thead { display: table-header-group; }
  .table.stackable .mini tbody { display: table-row-group; }
  .table.stackable .mini tr { display: table-row; padding: 0; margin: 0; border: 0; border-radius: 0; background: none; }
  .table.stackable .mini td, .table.stackable .mini th { display: table-cell; height: auto; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .table.stackable .mini .num { padding-left: var(--sp-3); }
  .table-box.scroll { max-height: none; }
  .row.grow > .search { width: 100%; }
  /* checkbox column stays beside the record, even with a hidden date cell between */
  .table.stackable td.cb { grid-column: 1; grid-row: 1; }
  .table.stackable td.cb ~ td.primary { grid-column: 2 / 3; grid-row: 1; }
  .table.stackable td.cb ~ td.lbl { grid-column: 2 / -1; }
  .table.stackable td.cb ~ td.num.lbl[data-label="Amount"] { grid-column: 3; grid-row: 1; display: block; }
  .table.stackable td.num.lbl[data-label="Amount"]::before { content: none; }
  .search.search-sm { width: 100%; }
  .covwrap { white-space: normal; flex-wrap: wrap; gap: 4px; }
  .covwrap .cov-text { margin-left: 0; }
}

@media (max-width: 640px) {
  .kpi-head .meta { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
  .kpis > .kpi { padding: var(--sp-4); }
}

/* 1Password edit form */
.op-edit { margin-top: var(--sp-3, 12px); }
.op-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--sp-3, 12px); }
.op-grid .f { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-sm, 13px); color: var(--muted); }
.op-grid .f input { color: var(--ink); }

/* details found */
.df-card { min-width: 0; max-width: 100%; }
.df-card h2 { overflow-wrap: anywhere; }
.df-card .table-box { overflow-x: auto; max-width: 100%; }
@media (max-width: 640px) { .df-card .table th, .df-card .table td { padding-left: 6px; padding-right: 6px; } }

/* tax estimate */
.tax-grid { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.tax-col.is-better { border-color: var(--accent); }
.tax-col table.mini tr.strong td { font-weight: 600; border-top: 1px solid var(--line); }
.kpi-btn { text-align: left; cursor: pointer; font: inherit; color: inherit; }
.kpi-btn.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.card { min-width: 0; }
.table-box.df-card { overflow-x: auto; max-width: 100%; }

.recovery { font-size: 1.05rem; letter-spacing: .04em; padding: 8px 0; overflow-wrap: anywhere; }

.restart-bar { background: var(--warn); color: #fff; padding: 8px 16px; font-size: 14px; text-align: center; }

/* expense manager */
.quick-row input[type=text] { flex: 1 1 320px; min-width: 0; }
.cat-row { display: grid; grid-template-columns: 28px 1fr auto; grid-template-areas: "i n v" ". b b"; gap: 2px 10px; align-items: center; width: 100%;
  text-align: left; background: none; border: 0; border-radius: 8px; padding: 6px 8px; font: inherit; color: inherit; cursor: pointer; }
.cat-row:hover, .cat-row.on { background: var(--soft); }
.cat-ico { grid-area: i; font-size: 18px; text-align: center; }
.cat-name { grid-area: n; }
.cat-row .num { grid-area: v; }
.cat-bar { grid-area: b; display: block; height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; }
.cat-bar i { display: block; height: 100%; background: var(--accent); }
.cat-bar i.near { background: var(--warn); } .cat-bar i.over { background: var(--bad); }
.tally-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card.tally .value { font-size: 22px; font-weight: 600; margin: 4px 0; }
.card.tally .row input { flex: 1 1 120px; min-width: 0; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-top: 12px; }
.cat-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; gap: 6px; }
.icon-input { width: 3.2em; text-align: center; }

/* sign-in, planner */
body.signed-out .topbar nav, body.signed-out .topbar-tools, body.signed-out .bottomnav, body.signed-out .subnav { display: none !important; }
.signin { max-width: 420px; margin: 8vh auto; }
.card.goal .value { font-size: 18px; font-weight: 600; margin: 4px 0; }
select, input:not([type=checkbox]):not([type=radio]) { max-width: 100%; }
label.f > select { width: 100%; }
.stack > *, .stack-sm > *, .grid > *, details { min-width: 0; }
.card > * { min-width: 0; }
.card p, .card li, .card .small, .notice { overflow-wrap: anywhere; }

/* People cards */
.people-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.person-card { grid-template-columns: auto 1fr; align-items: start; text-align: left; cursor: pointer; font: inherit; color: inherit; }
.person-card:hover, .person-card:focus-visible { border-color: var(--accent, #2f6f63); }
.person-card .stack-sm { display: grid; gap: 4px; min-width: 0; }
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; background: var(--line); color: var(--ink, inherit); }

.viewer-banner { background: var(--line); text-align: center; padding: 6px 16px; font-size: 13px; }

.suggestion { gap: 4px; padding: var(--sp-4); }
.suggestion p { margin: 0; }
.sg-warn { border-left: 3px solid #c58a1b; }
.sg-good { border-left: 3px solid #3d8b5a; }
.sg-info { border-left: 3px solid var(--line); }

.recovery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px 16px; font-size: 15px; }

/* ---------- 25. People: magazine cards with ID tiles ---------- */
.mag-grid { display: grid; gap: var(--sp-5); grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); align-items: start; }
.mag-card { padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); }
.mag-head { display: flex; align-items: center; gap: var(--sp-3); }
.mag-name { font-size: var(--fs-lg); font-weight: var(--w-bold); line-height: var(--lh-tight); }
.mag-foot { border-top: 1px solid var(--line); padding-top: var(--sp-3); }
.avatar-lg { width: 56px; height: 56px; font-size: var(--fs-md); background: var(--accent-soft); color: var(--accent); flex: none; }
.id-tiles { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
.id-tile { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-radius: var(--r); background: var(--bg); border: 1px solid var(--line); min-width: 0; }
.id-tile.is-expired { border-color: var(--bad); }
.id-value { font-family: var(--mono); font-size: var(--fs-md); letter-spacing: 0.04em; overflow-wrap: anywhere; }
.id-value .reveal { font-size: inherit; }
.id-actions { gap: var(--sp-1); }
.id-actions .btn-quiet { padding: 0 var(--sp-2); }
.id-edit { border-top: 1px solid var(--line); padding-top: var(--sp-2); }
.id-add { border: 1px dashed var(--line-strong); border-radius: var(--r); padding: var(--sp-3); }
.id-tile.id-missing { border-style: dashed; border-color: var(--line-strong); background: transparent; cursor: pointer; text-align: left; font: inherit; color: inherit; justify-content: center; min-height: 72px; }
.id-tile.id-missing:hover, .id-tile.id-missing:focus-visible { background: var(--soft); border-color: var(--accent); }
.op-grid { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); align-items: end; }

/* ---------- 26. Records: court cases, land & home ---------- */
.rec-grid { display: grid; gap: var(--sp-5); grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); align-items: start; }
.rec-card { padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-3); }
.rec-card .kv { font-size: var(--fs-sm); }
.slot-list { display: grid; gap: var(--sp-2); }
.slot { display: flex; align-items: center; gap: var(--sp-2); justify-content: space-between; padding: var(--sp-2) var(--sp-3); border-radius: var(--r); background: var(--bg); border: 1px solid var(--line); }
.slot .slot-name { font-weight: var(--w-medium); }
.slot.is-missing { border-style: dashed; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
.timeline li { display: grid; grid-template-columns: 104px minmax(0, 1fr) auto; gap: var(--sp-3); align-items: baseline; padding: var(--sp-2) 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }

.health-row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.health-row:last-child { border-bottom: 0; }

/* Home tiles: square boxes, the most urgent biggest */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-4); grid-auto-flow: dense; }
.tile { display: flex; flex-direction: column; gap: 6px; min-width: 0; aspect-ratio: 1 / 1; overflow: hidden; padding: var(--sp-4);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); color: var(--ink); text-decoration: none; }
a.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile.big { grid-column: span 2; grid-row: span 2; }
.tile.wide { grid-column: span 2; aspect-ratio: auto; }
.tile .t-label { font-size: var(--fs-sm); color: var(--muted); font-weight: var(--w-medium); }
.tile .t-value { font-size: 1.75rem; font-weight: 650; line-height: 1.15; }
.tile.big .t-value { font-size: 2.1rem; }
.tile .t-list { flex: 1; overflow: auto; min-height: 0; }
.tile .t-row { gap: var(--sp-2); }
.tile .bad, .tile .t-value.bad { color: var(--bad, #e5484d); }
@media (max-width: 760px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); } .tile .t-value { font-size: 1.35rem; } .tile.big .t-value { font-size: 1.6rem; } }
.tile .t-row { display: flex; flex-wrap: nowrap; align-items: baseline; justify-content: space-between; }
.tile .t-row > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .t-row > .num { white-space: nowrap; flex: none; }
