/* kuemue finance. A faithful port of wholesale.kuemue.com's admin look (kuemue-b2b
   public/assets/base.css + public/admin.html): Shopify-admin-style neutrals, near-black
   ink, one blue accent, lowercase wordmark. Tokens and components below are copied
   verbatim from that system; a short compat block at the end of each section reskins
   this app's existing markup (header/.bar, nav.tabs, button.primary etc.) with the same
   tokens so the two apps read as one family, without touching index.html or app.js. */

/* ── 1. Design tokens ───────────────────────────────────────────────────────────── */
:root {
  color-scheme: light;
  --ink: #1a1a1a;
  --ink-2: #303030;
  --paper: #ffffff;
  --card: #ffffff;
  --line: #e3e3e3;
  --line-2: #c9c9c9;
  --accent: #005bd3;
  --accent-ink: #004299;
  --accent-soft: #eaf4ff;
  --muted: #616161;
  --hover: #f6f6f6;
  --chip: #f1f1f1;
  --skel-a: #ebebeb;
  --skel-b: #f7f7f7;
  --ok: #008060;    --ok-soft: #e5f3ee;
  --warn: #8a6116;  --warn-soft: #fdf3d8;
  --bad: #c5280c;   --bad-soft: #fedad9;
  --info: #00527c;  --info-soft: #e0f0fa;
  --violet: #6b4fa3; --violet-soft: #ece6f6;
  --teal: #1f7a72;  --teal-soft: #e0f0ee;
  --s1: #005bd3; --s2: #00897b; --s3: #6b4fa3; --s4: #b07d3f;
  --glass: rgba(255,255,255,.92);
  --r: 12px;
  --r-sm: 8px;
  --shadow: 0 1px 2px rgba(20,20,20,.05), 0 4px 16px rgba(20,20,20,.06);
  --shadow-lg: 0 4px 12px rgba(20,20,20,.08), 0 16px 48px rgba(20,20,20,.14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --ease-in-out: cubic-bezier(.77, 0, .175, 1);
  --ease-drawer: cubic-bezier(.32, .72, 0, 1);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e7e7e7;
  --ink-2: #cfcfcf;
  --paper: #202020;
  --card: #2a2a2a;
  --line: #3d3d3d;
  --line-2: #555555;
  --accent: #4c9aff;
  --accent-ink: #8ab8ff;
  --accent-soft: #1d2c40;
  --muted: #a3a3a3;
  --hover: #333333;
  --chip: #383838;
  --skel-a: #2e2e2e;
  --skel-b: #383838;
  --ok: #41bd90;    --ok-soft: #16352b;
  --warn: #d9ab52;  --warn-soft: #372c13;
  --bad: #ff7f68;   --bad-soft: #422019;
  --info: #5cb3e6;  --info-soft: #15303f;
  --violet: #ab90d9; --violet-soft: #2c2439;
  --teal: #58b6ac;  --teal-soft: #17312e;
  --s1: #3a7fe6; --s2: #219e90; --s3: #8f73c6; --s4: #b28a39;
  --glass: rgba(32,32,32,.92);
  --pdp-box: #242424;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.5), 0 16px 48px rgba(0,0,0,.55);
}

/* ── 2. Reset & base typography ─────────────────────────────────────────────────── */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
.hidden { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 26px; } h2 { font-size: 20px; } h3 { font-size: 16px; }
p { margin: 0 0 1em; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
::placeholder { color: #b5b5b5; }

/* ── 3. Brand / wordmark ────────────────────────────────────────────────────────── */
.wordmark { font-weight: 700; font-size: 22px; letter-spacing: -.5px; color: var(--ink); }
.wordmark b { font-weight: 700; }

/* ── 4. Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--card); color: var(--ink); font: 600 14px/1.2 var(--font);
  cursor: pointer; text-decoration: none;
  transition: background .12s, border-color .12s, opacity .12s, transform .16s var(--ease-out);
  min-height: 42px;
}
.btn:active { transform: scale(.97); }
.btn:disabled:active, .btn[disabled]:active { transform: none; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: default; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-ink); }
.btn-danger { background: var(--card); border-color: var(--bad); color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--hover); }
.btn-sm { padding: 6px 12px; min-height: 32px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

/* This app's bare <button> / .btn variants (index.html + app.js: button.primary,
   button.ghost, button.danger, button.tiny) — same shape and press feedback as .btn. */
button {
  font: inherit; font-size: 14px; display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--card); color: var(--ink); font-weight: 600; cursor: pointer;
  min-height: 42px; transition: background .12s, border-color .12s, opacity .12s, transform .16s var(--ease-out);
}
button:active { transform: scale(.97); }
button:disabled:active { transform: none; }
button:hover:not(:disabled) { background: var(--hover); }
button:disabled { opacity: .5; cursor: default; pointer-events: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-ink); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 8px 10px; min-height: auto; }
button.ghost:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
button.danger { color: var(--bad); }
button.danger:hover:not(:disabled) { background: var(--bad-soft); }
button.tiny { padding: 5px 10px; min-height: 30px; font-size: 13px; border-radius: 8px; }

/* ── 5. Forms ───────────────────────────────────────────────────────────────────── */
.label { display: block; font: 600 13px/1.3 var(--font); color: var(--ink-2); margin: 14px 0 6px; }
.label .req { color: var(--bad); }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 10px;
  background: var(--card); color: var(--ink); font: 400 15px/1.4 var(--font);
  outline: none; transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { min-height: 90px; resize: vertical; }
.field-err { color: var(--bad); font-size: 13px; margin-top: 4px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* This app's bare inputs (index.html: input[type=month/text/date/number/password],
   select, textarea — no wrapping .input class on the element itself). */
input[type="month"], input[type="text"], input[type="date"], input[type="number"],
input[type="password"], select, textarea {
  font: inherit; font-size: 15px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--card); color: var(--ink);
  outline: none; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none;
}

/* ── 6. App shell ───────────────────────────────────────────────────────────────── */
/* Wholesale's fixed global bar + sidebar shell, ported as reusable components.
   All bar-local colours come from the .topbar-scoped --tb-* props, same as b2b. */
.topbar {
  --tb-bg: #fbfbfb;                    /* light theme band — barely off the white page */
  --tb-ink: var(--ink);
  --tb-muted: var(--muted);
  --tb-line: var(--line);
  --tb-btn-hover: rgba(0,0,0,.05);
  position: fixed; top: 0; left: 0; right: 0; z-index: 45; height: 44px;
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: var(--tb-bg); border-bottom: 1px solid var(--line); color: var(--tb-ink);
}
html[data-theme="dark"] .topbar { --tb-bg: #232323; --tb-btn-hover: rgba(255,255,255,.07); }
.topbar .brand { flex: none; display: flex; align-items: center; gap: 8px; }
.topbar .brand .wordmark { font-size: 19px; text-decoration: none; }
.topbar .brand .wordmark:hover { text-decoration: none; }
.topbar .tb-badge {
  flex: none; font: 800 9px/1 var(--font); letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  padding: 3px 8px; border-radius: 999px; white-space: nowrap;
}
/* Utility buttons on the light bar: transparent, muted icon, subtle border, faint hover. */
.topbar .ubtn {
  width: 34px; height: 34px; min-height: 0; padding: 0; border-radius: 999px;
  background: transparent; border: 1px solid var(--tb-line); color: var(--ink-2); box-shadow: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.topbar .ubtn:hover { background: var(--tb-btn-hover); }
.topbar .ubtn .ic { width: 16px; height: 16px; }
.topbar input[type="month"] { padding: 4px 8px; font-size: 13px; min-height: 30px; border-radius: 8px; }
.ic { width: 17px; height: 17px; flex: none; }
.navbtn { display: none; margin-inline-end: 2px; }
@media (pointer: coarse) { .topbar .ubtn { width: 40px; height: 40px; } }
.shell { display: flex; min-height: 100vh; padding-top: 44px; }
.side {
  width: 220px; flex: none; border-inline-end: 1px solid var(--line); background: #fbfbfb;
  padding: 18px 12px; position: sticky; top: 44px; height: calc(100vh - 44px); overflow-y: auto;
  display: flex; flex-direction: column; overflow-x: hidden;
}
html[data-theme="dark"] .side { background: #232323; }
.sidenav { display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; }
.side .navlink {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--ink-2); font: 600 14px/1.2 var(--font); text-decoration: none; margin-bottom: 2px;
}
.side .navlink:hover { background: var(--hover); text-decoration: none; }
.side .navlink.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow), inset 0 0 0 1px var(--line); }
/* Switched off in Settings → Pages. Still listed, so you remember the page is
   there waiting, but greyed out and not clickable until you switch it back on. */
.side .navlink.off { opacity: .4; pointer-events: none; }
.side .navlink .nl-t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .navlink .ic { width: 17px; height: 17px; }
/* Settings sits at the bottom of the rail. */
.side .navlink[data-sec="settings"] { margin-top: auto; }
.side .cnt.badge { margin-inline-start: auto; background: var(--accent); color: #fff; font-size: 11px; padding: 1px 7px; }
@media (min-width: 1000px) {
  html.side-min .side { width: 64px; padding: 18px 8px; }
  html.side-min .nl-t { display: none; }
  html.side-min .side .navlink { justify-content: center; padding: 10px 0; position: relative; }
  html.side-min .side .cnt.badge {
    position: absolute; top: 3px; right: 8px; font-size: 0; min-width: 9px; height: 9px; padding: 0;
  }
}
.main { flex: 1; min-width: 0; padding: 22px 24px 60px; background: var(--card); }
.main > #view { max-width: 1200px; margin: 0 auto; }

/* ── 7. Open-tabs strip ─────────────────────────────────────────────────────────── */
#otabs { display: flex; gap: 6px; overflow-x: auto; max-width: 1200px; margin: 0 auto 12px; }
.otab {
  display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--line); background: var(--card);
  border-radius: 8px; padding: 4px 4px 4px 10px; font: 600 12.5px/1.5 var(--font); color: var(--ink-2);
  cursor: pointer; white-space: nowrap; max-width: 200px; flex: none;
}
.otab.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.otab .x {
  border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 14px; line-height: 1;
  padding: 2px 5px; border-radius: 5px; flex: none;
}
.otab .x:hover { background: var(--hover); color: var(--bad); }
.otab .tl { overflow: hidden; text-overflow: ellipsis; }
.otab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── 8. Breadcrumbs ─────────────────────────────────────────────────────────────── */
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 0 0 12px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); text-decoration: underline; }
.crumb-sep { color: var(--line-2); }
.crumb-now { color: var(--ink); font-weight: 600; }

/* ── 9. Page head & count pill ──────────────────────────────────────────────────── */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 0 14px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.count-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 20px; padding: 0 7px; border-radius: 999px;
  background: var(--chip); color: var(--muted);
  font: 600 12px/1 var(--font); font-variant-numeric: tabular-nums;
  vertical-align: middle; margin-inline-start: 8px; translate: 0 -1px;
}
.count-pill:empty { display: none; }

/* This app's page head (index.html/app.js: .page-head h1, .spacer, .count). */
.page-head { align-items: center; margin-bottom: 14px; }
.page-head .spacer { flex: 1; }
.count { font-size: 12px; color: var(--muted); background: var(--chip); padding: 2px 8px; border-radius: 999px; }
.count:empty { display: none; }

/* ── 10. Tabs component ─────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs .tab {
  padding: 10px 14px; font: 600 14px/1.2 var(--font); color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap; background: none; border-top: 0; border-left: 0; border-right: 0;
}
.tabs .tab.on { color: var(--ink); border-bottom-color: var(--ink); }
@media (max-width: 720px) {
  .tabs { flex-wrap: wrap; overflow-x: visible; }
  .tabs .tab { min-height: 44px; }
}

/* ── 11. Toolbar, inputs, filter chips ──────────────────────────────────────────── */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 12px 0; }
.toolbar .input { max-width: 280px; }
.filt { width: auto; padding: 5px 28px 5px 10px; font-size: 13px; border-radius: 8px; }
.tb-right { display: inline-flex; gap: 8px; align-items: center; margin-inline-start: auto; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.chip-row .chip {
  border: 1px solid var(--line-2); background: var(--card); color: var(--ink-2);
  font: 600 13px/1 var(--font); padding: 7px 13px; border-radius: 999px; cursor: pointer;
}
.chip-row .chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* This app's filter row (index.html/app.js: .filters > button.pill[aria-pressed]). */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.pill {
  font-size: 13px; padding: 6px 12px; border-radius: 999px; min-height: auto;
  border: 1px solid var(--line-2); background: var(--card); color: var(--ink-2);
}
.pill:hover:not(:disabled) { background: var(--hover); }
.pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ── 12. Cards ──────────────────────────────────────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card h3 { margin-bottom: 12px; }

/* This app's card (index.html/app.js: .card > h2 header row, .card > .body). */
.card { margin-bottom: 16px; overflow: hidden; }
.card > h2 { font-size: 14px; margin: 0; padding: 13px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.card > .body { padding: 16px; }

/* ── 13. Tables ─────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: start; font: 600 12px/1.3 var(--font); text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .rowlink { cursor: pointer; }
@media (hover: hover) and (pointer: fine) { .table .rowlink:hover { background: var(--hover); } }

/* This app's bare tables (index.html/app.js: <div class="scroll"><table>…). */
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font: 600 11px/1.3 var(--font); text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--hover); }
.row-actions { text-align: right; white-space: nowrap; }

/* Sale line-item editor rows (items/sale_items) — same table language, denser. */
.lines-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.lines-table th {
  text-align: left; font: 600 11px/1.3 var(--font); text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.lines-table td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.lines-table tr:last-child td { border-bottom: none; }
.lines-table .input { padding: 6px 8px; min-height: 32px; font-size: 13.5px; }
.lines-table tfoot td { font-weight: 600; border-top: 1px solid var(--line-2); border-bottom: 0; }

/* ── 14. Badges & status pills ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
  font: 600 12px/1.4 var(--font); background: var(--chip); color: var(--ink-2); white-space: nowrap;
}
.pill-pending { background: var(--warn-soft); color: var(--warn); }
.pill-paid { background: var(--ok-soft); color: var(--ok); }

/* This app's status chip (index.html/app.js: <span class="chip">, .chip.pending/.paid). */
.chip {
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--chip); color: var(--muted); display: inline-block; white-space: nowrap;
}
.chip.pending { background: var(--warn-soft); color: var(--warn); }
.chip.paid { background: var(--ok-soft); color: var(--ok); }

/* ── 15. Stats / dashboard grid ─────────────────────────────────────────────────── */
.grid-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.grid-stats .stat {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 5px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 14px; min-height: 88px;
  color: var(--ink);
}
.split { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* This app's dashboard stats (index.html/app.js: .stats grid, .stat, .label, .value, .sub,
   .stat.hero, .pos/.neg on the value). */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px 16px; box-shadow: var(--shadow); text-align: center;
}
.stat .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat .value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat.hero .value { font-size: 28px; }

/* ── 16. Money colours (this app's own convention, same visual language) ───────── */
.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dim { color: var(--muted); }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

/* ── 17. Fields & two-column form layout ────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 620px) {
  .two { grid-template-columns: 1fr; }
}

/* ── 18. Empty state & skeleton loaders ──────────────────────────────────────────── */
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty .big { font-size: 34px; margin-bottom: 8px; }
.skel { background: linear-gradient(90deg, var(--skel-a) 25%, var(--skel-b) 50%, var(--skel-a) 75%); background-size: 200% 100%; animation: skel 1.1s infinite linear; border-radius: 8px; min-height: 16px; }
@keyframes skel { to { background-position: -200% 0; } }

/* This app's own empty/loading copy (index.html/app.js: .empty .big text, .skeleton). */
.empty .big { font-size: 15px; color: var(--ink); font-weight: 550; }
.skeleton { padding: 30px; text-align: center; color: var(--muted); font-size: 14px; }

/* ── 19. Modal ──────────────────────────────────────────────────────────────────── */
.modal-back {
  position: fixed; inset: 0; z-index: 90; background: rgba(20,20,20,.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: overlayFade .16s var(--ease-out) both;
}
.modal {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto; padding: 22px;
}
.modal.modal-lg { max-width: 760px; }
@keyframes overlayFade { from { opacity: 0; } }
@media (prefers-reduced-motion: no-preference) {
  .modal { animation: modalIn .2s var(--ease-out) both; }
  @keyframes modalIn { from { opacity: 0; transform: scale(.97); } }
}
@media (max-width: 560px) {
  .modal-back { align-items: flex-end; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92vh; }
}
@media (prefers-reduced-motion: no-preference) and (max-width: 560px) {
  .modal { animation: sheetIn .28s var(--ease-drawer) both; }
  @keyframes sheetIn { from { transform: translateY(100%); } }
}

/* This app's own modal (index.html/app.js: .overlay backdrop, .modal h2, .modal .body,
   .modal .foot). Same card, same entrance animation. */
.overlay {
  position: fixed; inset: 0; background: rgba(20,20,20,.45); z-index: 90;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: overlayFade .16s var(--ease-out) both;
}
.modal { max-width: 460px; }
.modal h2 { font-size: 16px; margin: 0; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal .body { padding: 20px; }
.modal .foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
@media (max-width: 560px) { .overlay { align-items: flex-end; padding: 0; } }

/* ── 20. Toasts ─────────────────────────────────────────────────────────────────── */
#toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast {
  background: var(--ink); color: var(--paper); border-radius: 10px; padding: 12px 16px; font-size: 14px;
  box-shadow: var(--shadow-lg); animation: toastin .18s var(--ease-out);
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--bad); color: #fff; }
@keyframes toastin { from { opacity: 0; transform: translateY(-6px) scale(.98); } }

/* This app's own toast host (index.html: #toasts fixed at the BOTTOM; app.js: .toast.bad). */
#toasts { top: auto; bottom: 22px; transform: translateX(-50%); align-items: center; }
.toast { border-radius: 999px; padding: 10px 18px; text-align: center; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } }

/* ── 21. Floating action menu (b2b base.css .ao-menu, value for value) ──────────── */
.ao-menu {
  position: fixed; z-index: 80; background: var(--card); border: 1px solid var(--line-2);
  border-radius: 10px; box-shadow: var(--shadow); min-width: 160px; padding: 4px;
}
.ao-menu button {
  display: block; width: 100%; text-align: start; padding: 9px 14px; border: 0; background: none;
  font: 500 14px/1.2 var(--font); color: var(--ink); cursor: pointer;
}
.ao-menu button:hover { background: var(--hover); }
.ao-menu button.danger { color: var(--bad); }

/* ── 21b. Buying chain & channel calculator ─────────────────────────────────────── */
.chip.pkg { background: var(--violet-soft); color: var(--violet); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.money-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 0;
  border-bottom: 1px solid var(--line); font-size: 14px; }
.money-row:last-child { border-bottom: 0; }
.money-row .k { color: var(--muted); }
.money-row .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.money-row.big .v { font-size: 19px; font-weight: 700; }
.money-row.big .k { font-weight: 600; color: var(--ink-2); }
.note { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: var(--r-sm); padding: 10px 14px; font-size: 13px; color: var(--ink-2); margin-bottom: 14px; }
.note.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.below-floor td { background: var(--bad-soft); }
.split-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--chip); margin: 4px 0 8px; }
.split-bar i { display: block; height: 100%; }
.split-key { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.split-key b { color: var(--ink); }
.key-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 5px; }
.qty { width: 76px; text-align: end; }

/* ── 22. Settings two-column nav ────────────────────────────────────────────────── */
.pg-2col { display: grid; grid-template-columns: 208px minmax(0, 1fr); gap: 20px; align-items: start; }
.pg-nav {
  position: sticky; top: 12px; display: flex; flex-direction: column; gap: 11px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 8px;
}
.pg-nav-group { display: flex; flex-direction: column; gap: 2px; }
.pg-nav-head {
  font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--accent); padding: 0 10px 7px;
}
.pg-nav-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; text-align: start; padding: 6px 10px; border: 0; border-radius: 8px;
  background: none; color: var(--ink-2); font: 500 13.5px/1.25 var(--font); cursor: pointer;
  transition: background .12s, color .12s, transform .16s var(--ease-out);
}
.pg-nav-item .count-pill:empty { display: none; }
@media (hover: hover) and (pointer: fine) {
  .pg-nav-item:hover { background: var(--hover); color: var(--ink); }
}
.pg-nav-item:active { transform: scale(.98); }
.pg-nav-item.on { background: var(--chip); color: var(--ink); font-weight: 600; }
.pg-nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (max-width: 900px) {
  .pg-2col { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .pg-nav { position: static; flex-direction: row; flex-wrap: wrap; gap: 10px 18px; }
  .pg-nav-group { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px; }
  .pg-nav-head { padding: 0 6px 0 0; }
}

/* ── 23. Login screen ───────────────────────────────────────────────────────────── */
/* Sign in, and the first-run "claim this app" screen, share one centred card. */
#login, #setup { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
#login .card, #setup .card { width: 100%; max-width: 340px; margin: 0; }
#login .wordmark, #setup .wordmark { text-align: center; font-size: 24px; margin-bottom: 4px; }
#login .tagline, #setup .tagline { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 20px; }
#setup .tagline { margin-bottom: 4px; }

/* ── 24. Motion helper ──────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: no-preference) {
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
  .fade-in { animation: fadeIn .34s ease both; }
}

/* ── 25. Responsive ─────────────────────────────────────────────────────────────── */
tr.rowlink { cursor: pointer; }

@media (max-width: 999px) {
  .shell { display: block; }
  .side {
    position: static; width: auto; height: auto; display: flex; flex-direction: row;
    align-items: center; gap: 4px; flex-wrap: wrap; overflow-x: visible; overflow-y: visible;
    border-inline-end: 0; border-bottom: 1px solid var(--line); padding: 8px;
  }
  .sidenav { flex-direction: row; flex: 1 1 100%; min-width: 0; flex-wrap: wrap; gap: 4px; }
  .side .navlink { min-height: 44px; white-space: nowrap; }
}
@media (max-width: 999px) and (min-width: 561px) {
  .side .navlink[data-sec="settings"] { margin-top: 0; }   /* the rail is a row here */
}
@media (min-width: 1000px) {
  .side { top: 44px; height: calc(100vh - 44px); }
}
@media (max-width: 560px) {
  .side {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 80;
    width: min(78vw, 286px); flex-direction: column; align-items: stretch; flex-wrap: nowrap;
    overflow-y: auto; overscroll-behavior: contain; padding: 54px 10px 16px;
    border-inline-end: 1px solid var(--line); box-shadow: var(--shadow-lg);
    transform: translateX(-102%); visibility: hidden;
    transition: transform .22s ease-out, visibility 0s .22s;
  }
  html[dir="rtl"] .side { transform: translateX(102%); }
  html.nav-open .side { transform: none; visibility: visible; transition: transform .22s ease-out, visibility 0s; }
  .nav-back { position: fixed; inset: 0; z-index: 79; background: rgba(20, 20, 20, .45); }
  .sidenav { flex-direction: column; flex-wrap: nowrap; gap: 2px; flex: 0 0 auto; }
  .side .navlink { min-height: 46px; justify-content: flex-start; padding: 10px 12px; }
  .side .navlink .nl-t { display: inline; }
  .side .navlink[data-sec="settings"] { margin-top: auto; }
  .navbtn { display: inline-flex; }
  .topbar input[type="month"] { max-width: 120px; }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }

@media (max-width: 720px) {
  .table-wrap.cards-sm { overflow-x: hidden; }
  .table-wrap.cards-sm > .table,
  .table-wrap.cards-sm > .table > tbody,
  .table-wrap.cards-sm > .table > tbody > tr,
  .table-wrap.cards-sm > .table > tbody > tr > td { display: block; }
  .table-wrap.cards-sm > .table > thead { display: none; }
  .table-wrap.cards-sm > .table > tbody > tr {
    border: 1px solid var(--line); border-radius: var(--r); background: var(--card);
    padding: 9px 12px; margin-bottom: 8px;
  }
  .table-wrap.cards-sm > .table > tbody > tr:last-child { margin-bottom: 0; }
  .table-wrap.cards-sm > .table > tbody > tr > td {
    border: 0; padding: 5px 0; text-align: start; width: auto !important;
    display: flex; gap: 14px; align-items: baseline; justify-content: space-between;
  }
  .table-wrap.cards-sm > .table > tbody > tr > td[data-l]::before {
    content: attr(data-l); color: var(--muted); font-weight: 600; font-size: 11.5px;
    flex: 0 0 auto; text-align: start;
  }
}

/* This app's own compact tweaks. */
@media (max-width: 620px) {
  .two { grid-template-columns: 1fr; }
  td, th { padding: 9px 10px; }
}
