/* ==========================================================================
   MelBill design system.
   All colours, type, spacing, radii, shadows and motion live in the variables
   at the top. Light and dark themes only change variables.
   ========================================================================== */
@font-face { font-family: "Poppins"; src: url("fonts/poppins-400.woff") format("woff"); font-weight: 300 450; font-style: normal; font-display: swap; }
@font-face { font-family: "Poppins"; src: url("fonts/poppins-500.woff") format("woff"); font-weight: 451 599; font-style: normal; font-display: swap; }
@font-face { font-family: "Poppins"; src: url("fonts/poppins-700.woff") format("woff"); font-weight: 600 900; font-style: normal; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("fonts/jetbrains-mono.woff") format("woff"); font-weight: 100 800; font-style: normal; font-display: swap; }

:root {
  --font: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-size: 15px;

  /* brand */
  --accent: #a5e325;
  --accent-strong: #4d7a06;
  --accent-ink: #14210a;
  --accent-soft: rgba(165, 227, 37, .18);

  /* surfaces and text (light) */
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f4f5f8;
  --line: #e7e9ee;
  --line-strong: #cdd2db;
  --ink: #0e1218;
  --muted: #596172;
  --link: #2c5fb3;

  /* status colours */
  --pos-bg: #e7f5cc;  --pos-fg: #2d6609;
  --warn-bg: #fff0d2; --warn-fg: #8a4f00;
  --neg-bg: #fde3e3;  --neg-fg: #a11f1f;
  --info-bg: #e3ecfe; --info-fg: #2443a3;
  --neu-bg: #ecedf3;  --neu-fg: #4a5263;
  --vio-bg: #ece8fb;  --vio-fg: #4b36a8;

  /* chart series */
  --c-billed: #6aa10c;
  --c-received: #3e8fe0;
  --c-warn: #e39b22;
  --c-bad: #e5484d;

  /* sidebar stays dark in both themes */
  --side-bg: #0d1015;
  --side-ink: #e8ebf0;
  --side-muted: #7e8798;
  --side-line: rgba(255, 255, 255, .07);

  /* shape and depth */
  --radius: 18px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --gap: 20px;
  --gap-sm: 10px;
  --sidebar-w: 264px;
  --topbar-h: 72px;
  --shadow: 0 1px 2px rgba(14, 18, 24, .04), 0 10px 28px -16px rgba(14, 18, 24, .14);
  --shadow-hover: 0 2px 4px rgba(14, 18, 24, .05), 0 22px 40px -18px rgba(14, 18, 24, .22);
  --shadow-pop: 0 24px 60px -18px rgba(14, 18, 24, .35);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --t-fast: .15s;
  --t: .25s;
  --t-slow: .6s;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #080a0e;
  --surface: #12151b;
  --surface-2: #181c24;
  --line: #232833;
  --line-strong: #363d4b;
  --ink: #f3f5f8;
  --muted: #9ba4b4;
  --link: #8fb1ff;
  --pos-bg: rgba(165, 227, 37, .14);  --pos-fg: #bdf267;
  --warn-bg: rgba(255, 181, 71, .14); --warn-fg: #ffc873;
  --neg-bg: rgba(255, 107, 107, .15); --neg-fg: #ff9c9c;
  --info-bg: rgba(110, 150, 255, .17); --info-fg: #aec4ff;
  --neu-bg: rgba(255, 255, 255, .07); --neu-fg: #b6becd;
  --vio-bg: rgba(160, 130, 255, .17); --vio-fg: #c9b8ff;
  --c-billed: #a5e325;
  --accent-strong: #a5e325;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 14px 32px -18px rgba(0, 0, 0, .7);
  --shadow-hover: 0 1px 0 rgba(255, 255, 255, .05) inset, 0 26px 44px -20px rgba(0, 0, 0, .85);
  --shadow-pop: 0 24px 60px -18px rgba(0, 0, 0, .9);
  color-scheme: dark;
}

/* ==========================================================================
   Layout is mobile-first: the rules below describe a phone (360 to 430px).
   Wider screens add to them with min-width breakpoints:
     640px   large phones and small tablets: two-column forms, two-up cards
     768px   tablets: data tables replace stacked cards
     961px   desktop shell: sidebar, top bar actions, PDF preview
     1280px  wide desktop: four-up KPI row, inline item editor
   ========================================================================== */

/* ---- base ---- */
* { box-sizing: border-box; }
html { font-size: var(--font-size); scroll-behavior: smooth; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: manipulation; max-width: 100%; overflow-x: clip; }
body { margin: 0; max-width: 100%; overflow-x: clip; font-family: var(--font); background: var(--bg); color: var(--ink); line-height: 1.5; -webkit-font-smoothing: antialiased; letter-spacing: -.005em; transition: background-color var(--t) ease, color var(--t) ease; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
h1 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.15; margin: 0; overflow-wrap: anywhere; }
h2 { font-size: 1.05rem; font-weight: 800; letter-spacing: -.02em; margin: 0 0 var(--gap-sm); }
h3 { font-size: .95rem; font-weight: 800; margin: var(--gap) 0 var(--gap-sm); }
p { margin: 0 0 var(--gap-sm); }
img, svg, iframe { max-width: 100%; }
::selection { background: var(--accent); color: var(--accent-ink); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.text-ok { color: var(--pos-fg); }
.empty { color: var(--muted); padding: 28px 12px; text-align: center; font-weight: 600; }
[hidden] { display: none !important; }
code { font-family: var(--font-mono); font-size: .85em; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; border: 1px solid var(--line); overflow-wrap: anywhere; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
[data-theme="dark"] :focus-visible { outline-color: var(--accent); }
.icon { vertical-align: -3px; flex: none; }
input, select, textarea { scroll-margin-top: 90px; scroll-margin-bottom: 120px; }
.only-desk { display: none !important; }
.only-mob { display: inline-flex !important; }

/* ---- motion ---- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes dd-in { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.rise { animation: rise var(--t-slow) var(--ease) both; }
.fade-in { animation: fade .8s ease both; }
.draw { stroke-dasharray: 1; animation: draw 1.5s cubic-bezier(.3, .7, .2, 1) .35s both; }
.grow { transform-origin: left center; animation: grow 1s var(--ease) .45s both; }

/* ---- app shell (phone: top bar, floating bottom navigation, bottom sheets) ---- */
:root { --bnav-h: 64px; }
.app { display: block; min-height: 100vh; }
.side { display: none; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; min-height: 60px; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--line); }
.topbar .spacer { display: none; }
.m-brand { display: inline-flex; flex: none; text-decoration: none; }
.m-brand .brand-mark { width: 40px; height: 40px; }
.brand-mark { width: 38px; height: 38px; flex: none; border-radius: 11px; background: var(--accent); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.1rem; }
.search { display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 8px 0 14px; border-radius: 13px; background: var(--surface); border: 1px solid var(--line); flex: 1; min-width: 0; margin: 0; transition: border-color var(--t) ease, box-shadow var(--t) ease; color: var(--muted); }
.search:focus-within { border-color: var(--accent-strong); box-shadow: 0 0 0 4px var(--accent-soft); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; margin: 0; padding: 0; min-height: 0; height: 100%; box-shadow: none; font-weight: 500; }
.search input:focus { outline: 0; box-shadow: none; }
.kbd { font-family: var(--font); font-size: .75rem; font-weight: 700; padding: 3px 7px; border-radius: 7px; border: 1px solid var(--line); color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.content { flex: 1; min-width: 0; width: 100%; max-width: 1480px; padding: 18px 16px calc(var(--bnav-h) + 44px + env(safe-area-inset-bottom, 0px)); margin: 0 auto; }

/* sidebar pieces (shown from 961px) */
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name { font-size: 1.15rem; font-weight: 800; letter-spacing: -.02em; }
.brand-sub { font-size: .75rem; font-weight: 600; color: var(--side-muted); }
.side .brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; text-decoration: none; color: var(--side-ink); }
.bizcard { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; background: color-mix(in srgb, var(--side-ink) 6%, transparent); border: 1px solid var(--side-line); text-decoration: none; color: inherit; transition: background var(--t) ease; }
.bizcard:hover { background: color-mix(in srgb, var(--side-ink) 10%, transparent); }
.bizcard-logo { width: 36px; height: 36px; flex: none; border-radius: 10px; background: color-mix(in srgb, var(--side-ink) 12%, transparent); display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--accent); overflow: hidden; }
.bizcard-logo img { width: 100%; height: 100%; object-fit: contain; background: var(--surface); }
.bizcard-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.bizcard-name { font-size: .93rem; font-weight: 700; color: var(--side-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bizcard-sub { font-family: var(--font-mono); font-size: .75rem; color: var(--side-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-nav { display: flex; flex-direction: column; gap: 22px; flex: 1; }
.side-group { display: flex; flex-direction: column; gap: 3px; }
.side-eyebrow { font-size: .75rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--side-muted); padding: 0 12px 8px; }
.side a.nav { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-md); color: var(--side-muted); font-size: .93rem; font-weight: 600; text-decoration: none; position: relative; transition: background var(--t) ease, color var(--t) ease; }
.side a.nav .icon { transition: color var(--t) ease; }
.side a.nav:hover { background: color-mix(in srgb, var(--side-ink) 7%, transparent); color: var(--side-ink); }
.side a.nav:hover .icon, .side a.nav.active .icon { color: var(--accent); }
.side a.nav.active { background: color-mix(in srgb, var(--side-ink) 10%, transparent); color: var(--side-ink); }
.side a.nav.active::before { content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.fycard { padding: 16px; border-radius: 16px; background: var(--accent-soft); border: 1px solid var(--side-line); display: flex; flex-direction: column; gap: 10px; }
.fycard-top { display: flex; justify-content: space-between; align-items: baseline; }
.fycard-title { font-size: .85rem; font-weight: 800; color: var(--side-ink); }
.fycard-pct { font-size: .75rem; font-weight: 700; color: var(--accent); }
.fycard-bar { height: 6px; border-radius: 99px; background: var(--side-line); overflow: hidden; }
.fycard-bar > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.fycard-note { font-size: .75rem; font-weight: 500; color: var(--side-muted); line-height: 1.45; }

/* floating bottom navigation */
.bnav { position: fixed; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); height: var(--bnav-h); z-index: 90; display: flex; align-items: center; justify-content: space-between; gap: 2px; padding: 0 8px; border-radius: 22px; background: color-mix(in srgb, var(--side-bg) 94%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border: 1px solid var(--side-line); box-shadow: var(--shadow-pop); }
.bn { flex: 1 1 0; min-width: 0; height: 46px; display: flex; align-items: center; justify-content: center; gap: 7px; border: 0; background: none; color: var(--side-muted); font: inherit; font-size: .8rem; font-weight: 700; text-decoration: none; border-radius: 15px; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: flex-grow var(--t) var(--ease), background-color var(--t) ease, color var(--t) ease; }
.bn span { display: none; white-space: nowrap; }
.bn:active { transform: scale(.94); }
.bn.active, .bn[aria-expanded="true"] { flex: 1.9 1 0; background: color-mix(in srgb, var(--side-ink) 10%, transparent); color: var(--side-ink); }
.bn.active .icon, .bn[aria-expanded="true"] .icon { color: var(--accent); }
.bn.active span, .bn[aria-expanded="true"] span { display: inline; }
.bn-fab { flex: none; width: 52px; height: 52px; margin: 0 6px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: transform var(--t) var(--ease); }
.bn-fab:active { transform: scale(.92); }
.bn-fab .icon { transition: transform var(--t) var(--ease); }
body.sheet-open .bn-fab .icon { transform: rotate(45deg); }
body.kb .bnav, body.pick-open .bnav { display: none; }
html:has(body.sheet-open) { overflow: hidden; }

/* bottom sheets */
.scrim { display: block; position: fixed; inset: 0; background: color-mix(in srgb, var(--side-bg) 55%, transparent); z-index: 70; opacity: 0; pointer-events: none; transition: opacity .3s ease; }
.scrim.on { opacity: 1; pointer-events: auto; }
.sheet { display: flex; flex-direction: column; position: fixed; left: 8px; right: 8px; bottom: calc(var(--bnav-h) + 20px + env(safe-area-inset-bottom, 0px)); max-height: 58vh; max-height: 58dvh; z-index: 80; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow-pop); transform: translateY(110%); transition: transform .42s cubic-bezier(.2, .9, .25, 1); touch-action: pan-y; }
.sheet[hidden] { display: none !important; }
.sheet.on { transform: none; }
.sheet.dragging { transition: none; }
.sheet-grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 10px auto 2px; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px 6px 20px; flex: none; }
.sheet-head h2 { margin: 0; font-size: 1.15rem; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 4px 14px 18px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.sheet-body::-webkit-scrollbar { display: none; }
.sheet .moon { display: inline-flex; } .sheet .sun { display: none; }
[data-theme="dark"] .sheet .sun { display: inline-flex; } [data-theme="dark"] .sheet .moon { display: none; }
.sheet-biz { background: var(--surface-2); border-color: var(--line); color: var(--ink); margin-bottom: 6px; }
.sheet-biz .bizcard-name { color: var(--ink); } .sheet-biz .bizcard-sub { color: var(--muted); }
.sheet-group { margin-top: 12px; }
.sheet-eyebrow { font-size: .75rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 0 6px 6px; }
.srow { display: flex; align-items: center; gap: 14px; width: 100%; padding: 11px 8px; border: 0; background: none; font: inherit; color: var(--ink); text-align: left; text-decoration: none; border-radius: 14px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.srow:active { background: var(--surface-2); }
.srow > .icon:last-child { color: var(--muted); }
.srow-ic { width: 38px; height: 38px; flex: none; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; color: var(--muted); }
.srow.active .srow-ic, .srow-ic.acc { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.srow-t { flex: 1; min-width: 0; font-weight: 700; font-size: .95rem; display: flex; flex-direction: column; }
.srow-t small { font-weight: 500; font-size: .78rem; color: var(--muted); }
.srow-big { padding: 12px 8px; }
.srow-danger, .srow-danger .srow-ic { color: var(--neg-fg); }
.switch { width: 44px; height: 26px; flex: none; border-radius: 13px; background: var(--line-strong); position: relative; transition: background var(--t) ease; }
.switch i { position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); transition: transform var(--t) var(--ease); box-shadow: var(--shadow); }
[data-theme="dark"] .switch { background: var(--accent); }
[data-theme="dark"] .switch i { transform: translateX(18px); background: var(--accent-ink); }
.sheet-pick { bottom: calc(var(--kb, 0px) + 8px); max-height: min(78vh, calc(var(--vvh, 100vh) - 20px)); height: auto; }
.pick-search { display: flex; align-items: center; gap: 10px; margin: 4px 14px 8px; padding: 0 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); flex: none; color: var(--muted); }
.pick-search:focus-within { border-color: var(--accent-strong); box-shadow: 0 0 0 4px var(--accent-soft); }
.pick-search input { border: 0; background: transparent; margin: 0; padding: 0; min-height: 48px; box-shadow: none; color: var(--ink); }
.pick-search input:focus { box-shadow: none; outline: 0; }
.pick-list { padding-top: 0; min-height: 120px; }
.pick-row { min-height: 54px; }
.pick-row.active .srow-t { color: var(--accent-strong); }
.pick-tick { color: var(--accent-strong); font-weight: 800; }
.pick-free { background: var(--accent-soft); }

/* ---- page structure ---- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; animation: rise var(--t-slow) var(--ease) both; }
.page-head .sub { font-size: .95rem; font-weight: 500; color: var(--muted); }
.page-head .sub a { color: var(--ink); font-weight: 700; text-decoration: none; border-bottom: 2px solid var(--accent); }
.page-head h1 { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; min-width: 0; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-sm); margin-top: var(--gap-sm); }
.page-head .actions { margin-top: 0; width: 100%; }
.page-head .actions .btn { flex: 1 1 140px; justify-content: center; }
form.inline { display: inline; margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); min-width: 0; transition: border-color var(--t) ease, background-color var(--t) ease; }
.card.narrow { max-width: 560px; }
.card > h2:first-child { margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; align-items: start; }
.card-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head h2 { margin: 0 0 4px; font-size: 1.1rem; }
.card-head .sub { font-size: .83rem; font-weight: 600; color: var(--muted); }

/* ---- flash messages, toasts ---- */
.flashes { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.flash { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-radius: var(--radius-md); border: 1px solid transparent; font-weight: 600; animation: toast-in .4s var(--ease) both; transition: opacity .4s ease, transform .4s ease; }
.flash .icon { margin-top: 2px; }
.flash .flash-body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.flash ul { margin: 4px 0 0 18px; padding: 0; font-weight: 500; }
.flash.leaving { opacity: 0; transform: translateY(-8px); }
.flash-close { background: transparent; border: 0; color: inherit; opacity: .6; cursor: pointer; padding: 8px; margin: -6px -8px -6px 0; border-radius: 8px; display: inline-flex; }
.flash-close:hover { opacity: 1; }
.flash-ok { background: var(--pos-bg); color: var(--pos-fg); border-color: color-mix(in srgb, var(--pos-fg) 25%, transparent); }
.flash-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: color-mix(in srgb, var(--warn-fg) 25%, transparent); }
.flash-error { background: var(--neg-bg); color: var(--neg-fg); border-color: color-mix(in srgb, var(--neg-fg) 25%, transparent); }
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius-md); margin-bottom: 16px; font-weight: 500; line-height: 1.5; border: 1px solid transparent; overflow-wrap: anywhere; }
.notice .icon { flex: none; margin-top: 2px; }
.notice-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: color-mix(in srgb, var(--warn-fg) 25%, transparent); }

/* ---- buttons ---- */
.btn, .icon-btn { font: inherit; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-decoration: none; }
.btn { position: relative; overflow: hidden; height: 46px; padding: 0 16px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); color: var(--ink); font-size: .93rem; line-height: 1; white-space: nowrap; transition: transform var(--t-fast) ease, background-color var(--t) ease, border-color var(--t) ease, opacity var(--t) ease; }
.btn:hover { border-color: var(--line-strong); background: var(--surface-2); text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); border-color: transparent; }
.btn-wa { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn-wa:hover { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn-danger { color: var(--neg-fg); border-color: color-mix(in srgb, var(--neg-fg) 35%, var(--line)); }
.btn-danger:hover { background: var(--neg-bg); border-color: var(--neg-fg); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn[disabled], .btn.is-busy { opacity: .6; pointer-events: none; }
.btn.is-busy::before { content: ""; width: 15px; height: 15px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
.icon-btn { width: 44px; height: 44px; padding: 0; border: 1px solid transparent; border-radius: var(--radius-md); background: transparent; color: var(--muted); list-style: none; position: relative; transition: background-color var(--t) ease, color var(--t) ease, transform var(--t-fast) ease; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.disabled { opacity: .35; pointer-events: none; }
.icon-btn.bordered { border-color: var(--line); background: var(--surface); }
summary.icon-btn::-webkit-details-marker, summary.btn::-webkit-details-marker { display: none; }
.theme-toggle .sun { display: none; }
[data-theme="dark"] .theme-toggle .sun { display: inline-block; }
[data-theme="dark"] .theme-toggle .moon { display: none; }

/* ---- forms ---- */
label { display: block; position: relative; font-size: .82rem; font-weight: 700; color: var(--muted); margin-bottom: 14px; }
label.check { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-size: .95rem; font-weight: 600; margin-right: var(--gap); margin-bottom: 8px; min-height: 40px; cursor: pointer; }
input, select, textarea, .dd-btn { font: inherit; font-size: 16px; font-weight: 500; color: var(--ink); width: 100%; margin-top: 6px; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); min-height: 46px; transition: border-color var(--t) ease, box-shadow var(--t) ease, background-color var(--t) ease; }
textarea { resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); font-weight: 500; }
input:hover, select:hover, textarea:hover, .dd-btn:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus, .dd-btn:focus-visible, .dd-btn[aria-expanded="true"] { outline: 0; border-color: var(--accent-strong); box-shadow: 0 0 0 4px var(--accent-soft); }
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; margin: 0; min-height: 0; padding: 0; accent-color: var(--accent-strong); cursor: pointer; flex: none; }
input[readonly], input:disabled, select:disabled, .dd-btn:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
input[type="file"] { padding: 8px; }
input[type="search"] { -webkit-appearance: none; appearance: none; }
input[type="file"]::file-selector-button { font: inherit; font-weight: 700; margin-right: 12px; padding: 7px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink); cursor: pointer; transition: background-color var(--t) ease; }
input[type="file"]::file-selector-button:hover { background: var(--line); }
select { appearance: none; -webkit-appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23808898' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.is-pick { cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23808898' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; text-overflow: ellipsis; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 16px; }
.form-grid .span-2 { grid-column: auto; }
.inline-row { display: flex; gap: var(--gap-sm); align-items: flex-end; }
.inline-row > input { flex: 1; min-width: 0; }
.subform { border: 1px dashed var(--line-strong); border-radius: var(--radius-md); padding: 14px; margin: 12px 0; background: var(--surface-2); animation: pop .25s var(--ease) both; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-md); padding: 14px; margin: 0 0 var(--gap-sm); min-width: 0; }
legend { font-weight: 800; padding: 0 8px; font-size: .9rem; }
.pay-form { display: block; }

/* filters: search stays visible, the rest folds away on phones */
.filters { padding: 14px; }
.filters-top { display: flex; gap: var(--gap-sm); align-items: flex-end; }
.filters-top > label { flex: 1; min-width: 0; margin: 0; }
.filters-body { display: none; margin-top: 12px; }
.filters.is-open .filters-body { display: block; }
.filters-body .fgrid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 12px; }
.filters label { margin-bottom: 12px; }
.filters .fgrid label.wide { grid-column: 1 / -1; }
.filters-actions { display: flex; gap: var(--gap-sm); }
.filters-actions .btn { flex: 1; }
.filters .btn[data-fold] { flex: none; }
.filters label.check { display: flex; margin: 0 0 10px; }
.filters:not(.fold) { display: grid; gap: 0 12px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.filters:not(.fold) > .btn, .filters:not(.fold) > .check, .filters:not(.fold) > label:has(input[type="search"]) { grid-column: 1 / -1; }
.filters:not(.fold) > .btn { width: 100%; }

.sticky-actions { position: sticky; bottom: calc(var(--bnav-h) + 22px + env(safe-area-inset-bottom, 0px)); z-index: 25; display: flex; flex-wrap: wrap; gap: var(--gap-sm); align-items: center; margin: 16px 0 0; padding: 10px; border: 1px solid var(--line); border-radius: 16px; background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: var(--shadow-pop); }
.sticky-actions .btn { flex: 1 1 auto; justify-content: center; }
.sticky-actions .btn-ghost { display: none; }
body.kb .sticky-actions { position: static; box-shadow: none; }

/* sub navigation: a swipeable pill strip on phones */
.subnav { scroll-padding-left: 16px; scroll-padding-right: 16px; display: flex; flex-wrap: nowrap; gap: 8px; overflow-x: auto; margin: 0 -16px 16px; padding: 2px 16px 8px; scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; }
.subnav::-webkit-scrollbar { display: none; }
.subnav a, .subnav button { flex: none; white-space: nowrap; scroll-snap-align: start; min-height: 44px; display: inline-flex; align-items: center; padding: 8px 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); text-decoration: none; color: var(--muted); font: inherit; font-size: .88rem; font-weight: 700; transition: color var(--t) ease, border-color var(--t) ease, background-color var(--t) ease; }
.subnav a:hover { color: var(--ink); border-color: var(--line-strong); }
.subnav a.active { background: var(--ink); color: var(--surface); border-color: var(--ink); }

/* ---- tables: plain tables scroll inside their card; .table-stack turns into cards on phones ---- */
.table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th, .table td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); white-space: nowrap; padding-top: 10px; padding-bottom: 10px; }
.table th a { color: inherit; text-decoration: none; transition: color var(--t) ease; }
.table th a:hover { color: var(--ink); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table tfoot th, .table tfoot td { background: transparent; border-top: 2px solid var(--line-strong); border-bottom: 0; color: var(--ink); text-transform: none; letter-spacing: 0; font-size: .95rem; font-weight: 800; }
.actions-col { white-space: nowrap; text-align: right !important; }
.actions-col .icon-btn { width: 36px; height: 36px; }

.table-stack thead { display: none; }
.table-stack, .table-stack tbody, .table-stack tfoot { display: block; width: 100%; }
.table-stack tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 14px; border: 1px solid var(--line); border-radius: var(--radius-md); margin-bottom: 10px; padding: 14px; background: var(--surface); }
.table-stack tfoot tr { background: var(--surface-2); }
.table-stack td, .table-stack th { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 0; border: 0; text-align: left !important; white-space: normal !important; font-weight: 600; overflow-wrap: anywhere; }
.table-stack td::before { content: attr(data-label); color: var(--muted); font-size: .75rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.table-stack td:first-child { grid-column: 1 / -1; font-size: 1.02rem; font-weight: 800; }
.table-stack td:first-child::before { content: none; }
.table-stack td:first-child a { color: var(--ink); text-decoration: none; font-weight: 800; }
.table-stack td[data-label="Customer"], .table-stack td[data-label="Entry"], .table-stack td[data-label="Notes"], .table-stack td[data-label="Reference"], .table-stack td[data-label="Item"], .table-stack td[data-label="Changes"] { grid-column: 1 / -1; }
.table-stack td[data-label="Customer"], .table-stack td[data-label="Entry"] { font-weight: 700; }
.table-stack td[data-label="Total"], .table-stack td[data-label="Amount"], .table-stack td[data-label="Balance"], .table-stack td[data-label="Net due"], .table-stack td[data-label="Outstanding"] { font-weight: 800; }
.table-stack.ts-status td:first-child { grid-column: 1; }
.table-stack.ts-status td[data-label="Status"] { grid-column: 2; grid-row: 1; align-items: flex-end; }
.table-stack.ts-status td[data-label="Status"]::before { content: none; }
.table-stack td.actions-col { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 4px; padding-top: 8px; margin-top: 2px; border-top: 1px solid var(--line); }
.table-stack td.actions-col::before { content: none; }
.table-stack .actions-col .icon-btn { width: 44px; height: 44px; }
.table-stack tfoot th::before { content: none; }
.table-stack tfoot th[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .75rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.table-stack tfoot th:first-child { grid-column: 1 / -1; }
.card:not(.tbl-card):has(> .table-wrap > .table-stack) { background: none; border: 0; box-shadow: none; padding: 0; }
.pager { display: flex; align-items: center; gap: var(--gap-sm); justify-content: space-between; padding-top: 10px; color: var(--muted); font-size: .85rem; font-weight: 600; }
pre { white-space: pre-wrap; font-family: var(--font-mono); font-size: .75rem; background: var(--surface-2); padding: 10px; border-radius: var(--radius-sm); max-height: 260px; overflow: auto; border: 1px solid var(--line); }
.log-list { margin: 0; padding-left: 18px; }
details > summary { cursor: pointer; font-weight: 700; color: var(--link); }

/* ---- status chips ---- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: .72rem; font-weight: 800; vertical-align: middle; background: var(--neu-bg); color: var(--neu-fg); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-paid, .badge-issued, .badge-active { background: var(--pos-bg); color: var(--pos-fg); }
.badge-partial, .badge-converted { background: var(--warn-bg); color: var(--warn-fg); }
.badge-draft { background: var(--neu-bg); color: var(--neu-fg); }
.badge-unpaid { background: var(--info-bg); color: var(--info-fg); }
.badge-overpaid { background: var(--vio-bg); color: var(--vio-fg); }
.badge-overdue, .badge-cancelled { background: var(--neg-bg); color: var(--neg-fg); }
.badge-inactive { background: var(--neu-bg); color: var(--neu-fg); }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 26px; padding: 4px 11px; border-radius: 999px; font-size: .75rem; font-weight: 800; line-height: 1.25; }
.chip-pos { background: var(--pos-bg); color: var(--pos-fg); } .chip-neg { background: var(--neg-bg); color: var(--neg-fg); }
.chip-warn { background: var(--warn-bg); color: var(--warn-fg); } .chip-info { background: var(--info-bg); color: var(--info-fg); }
.chip-neu { background: var(--neu-bg); color: var(--neu-fg); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: .78rem; font-weight: 800; flex: none; }
.cell-who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-who span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- dashboard ---- */
.greet { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; animation: rise var(--t-slow) var(--ease) both; }
.greet-eyebrow { display: inline-flex; align-items: center; gap: 8px; font-size: .8rem; font-weight: 700; color: var(--muted); }
.greet-eyebrow .icon { color: var(--accent-strong); }
.greet h1 { font-size: 1.5rem; }
.greet-name { font-weight: 700; color: var(--muted); }
.greet-sub { margin: 0; font-size: .95rem; font-weight: 500; color: var(--muted); }
.greet-sub b { color: var(--ink); }
.greet-sub a { color: var(--ink); font-weight: 700; text-decoration: none; border-bottom: 2px solid var(--accent); }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; min-width: 0; animation: rise var(--t-slow) var(--ease) both; }
.stat-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.stat-ico { width: 32px; height: 32px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex: none; }
.stat-label { flex: 1; min-width: 0; font-size: .78rem; font-weight: 700; color: var(--muted); line-height: 1.25; }
.stat-value { font-size: 1.3rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; font-variant-numeric: tabular-nums; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 2px; overflow-wrap: anywhere; }
.stat-value .cur { font-size: .95rem; font-weight: 700; color: var(--muted); }
.stat-value .frac { font-size: .85rem; font-weight: 700; color: var(--muted); letter-spacing: -.01em; }
.stat-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.stat-foot .meta { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 6px; font-size: .74rem; font-weight: 600; color: var(--muted); }
.stat-foot .meta .chip { height: auto; min-height: 24px; padding: 3px 9px; white-space: normal; line-height: 1.25; align-self: flex-start; font-size: .72rem; }
.spark { display: none; width: 104px; max-width: 46%; height: 40px; overflow: hidden; flex: 0 1 104px; min-width: 0; }
.spark.is-flat { display: none !important; }
.dash-row { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
.dash-row > .card { margin-bottom: 0; }
.chart-card { display: flex; flex-direction: column; gap: 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.legend .lg { display: flex; flex-direction: column; gap: 2px; }
.legend .lg-k { display: flex; align-items: center; gap: 7px; font-size: .72rem; font-weight: 700; color: var(--muted); }
.legend .lg-v { font-size: 1.05rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.sw-line { width: 18px; height: 4px; border-radius: 4px; background: var(--c-billed); }
.sw-dash { width: 18px; height: 0; border-top: 3px dashed var(--ink); }
.chart { display: flex; gap: 8px; }
.chart-y { width: 36px; position: relative; flex: none; }
.chart-y span { position: absolute; right: 0; transform: translateY(-50%); font-size: .75rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.chart-plot { position: relative; width: 100%; aspect-ratio: 16 / 11; }
.chart-grid { position: absolute; left: 0; right: 0; height: 0; border-top: 1px dashed var(--line); }
.chart-plot svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.chart-hits { position: absolute; inset: 0; display: flex; }
.chart-hit { flex: 1; cursor: crosshair; }
.chart-hit.edge { flex: .5; }
.chart-x { position: relative; height: 16px; }
.chart-x span:first-child { transform: none !important; }
.chart-x span:last-child { transform: translateX(-100%) !important; }
.chart-x span { position: absolute; transform: translateX(-50%); font-size: .75rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.chart-cursor { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px solid var(--line-strong); pointer-events: none; opacity: 0; transition: opacity var(--t-fast) ease; }
.chart-dot { position: absolute; border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; opacity: 0; transition: opacity var(--t-fast) ease; }
.chart-dot.b { width: 12px; height: 12px; background: var(--surface); border: 3px solid var(--c-billed); }
.chart-dot.r { width: 10px; height: 10px; background: var(--ink); border: 2px solid var(--surface); }
.chart-tip { position: absolute; top: -8px; z-index: 3; min-width: 150px; padding: 10px 12px; border-radius: 13px; background: var(--ink); color: var(--surface); box-shadow: var(--shadow-pop); display: none; flex-direction: column; gap: 6px; transform: translateX(-50%); pointer-events: none; font-size: .78rem; font-weight: 700; }
.chart-tip.on { display: flex; animation: pop .2s var(--ease) both; }
.chart-tip .tl { opacity: .65; }
.chart-tip .tr { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }
.chart-tip .tr i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; background: var(--accent); }
.chart-tip .tr i.r { background: transparent; border: 2px solid var(--surface); }
.chart-empty { position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 0 16px; }
.chart-empty b { font-size: .95rem; } .chart-empty small { color: var(--muted); font-weight: 600; max-width: 340px; line-height: 1.45; }
.chart-empty-ico { width: 42px; height: 42px; border-radius: 13px; display: inline-flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent-strong); }
.chart-plot.is-empty .chart-grid { opacity: .6; }
.age-card { display: flex; flex-direction: column; gap: 16px; }
.age-total { font-size: 1.6rem; font-weight: 800; letter-spacing: -.035em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.age-rows { display: flex; flex-direction: column; gap: 14px; }
.age-row-top { display: flex; justify-content: space-between; align-items: baseline; font-size: .85rem; font-weight: 700; margin-bottom: 8px; }
.age-row-top .l { display: flex; align-items: center; gap: 8px; }
.age-row-top .sq, .gst-row .l .sq { width: 9px; height: 9px; border-radius: 3px; }
.age-foot { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; font-weight: 700; border-top: 1px dashed var(--line); padding-top: 14px; }
.bar { height: 9px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 99px; }
.split-bar { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: var(--surface-2); gap: 3px; }
.split-bar > span { display: block; height: 100%; border-radius: 99px; }
.dash-main { display: flex; flex-direction: column; gap: 16px; }
.dash-main > .tbl-card { margin-bottom: 0; padding: 0; overflow: hidden; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.dash-main > .side-col { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.side-col > .card { margin-bottom: 0; }
.tbl-card .card-head { padding: 16px 16px 0; margin-bottom: 8px; }
.tbl-card .table-wrap { padding: 0 12px 4px; }
.tbl-card .table-stack tr { background: var(--surface-2); }
.tbl-foot { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); font-size: .83rem; font-weight: 600; color: var(--muted); }
.tbl-foot a { color: var(--ink); font-weight: 800; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }
.tbl-foot a:hover { color: var(--link); }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qa { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: var(--ink); min-width: 0; transition: border-color var(--t) ease, background-color var(--t) ease; }
.qa:hover { border-color: var(--accent-strong); text-decoration: none; }
.qa:active { transform: scale(.98); }
.qa-ico { width: 36px; height: 36px; border-radius: 11px; display: flex; align-items: center; justify-content: center; background: var(--surface-2); color: var(--ink); transition: background-color var(--t) ease, color var(--t) ease; }
.qa:hover .qa-ico { background: var(--accent); color: var(--accent-ink); }
.qa b { display: block; font-size: .9rem; font-weight: 800; }
.qa small { display: block; font-size: .74rem; font-weight: 600; color: var(--muted); }
.feed { display: flex; flex-direction: column; }
.feed-item { display: flex; gap: 12px; align-items: center; padding: 10px 8px; margin: 0 -8px; min-height: 56px; border-radius: 12px; text-decoration: none; color: inherit; transition: background-color var(--t) ease; }
.feed-item:hover { background: var(--surface-2); }
.feed-ico { width: 36px; height: 36px; border-radius: 11px; display: flex; align-items: center; justify-content: center; flex: none; background: var(--pos-bg); color: var(--pos-fg); }
.feed-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.feed-body b { font-size: .9rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-body small { font-size: .74rem; font-weight: 600; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-amt { text-align: right; font-weight: 800; font-size: .9rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.gst-list { display: flex; flex-direction: column; gap: 11px; margin-top: 16px; }
.gst-row { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; font-weight: 700; }
.gst-row .l { display: flex; align-items: center; gap: 9px; }
.link-quiet { font-weight: 700; text-decoration: none; color: var(--muted); font-size: .85rem; }

/* ---- document form: the item editor is a stack of cards on phones ---- */
.items-table thead { display: none; }
.items-table, .items-table tbody { display: block; width: 100%; }
.items-table tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-md); margin-bottom: 12px; padding: 14px; background: var(--surface-2); }
.items-table td { display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 0; border: 0; text-align: left; }
.items-table td::before { content: attr(data-label); color: var(--muted); font-size: .75rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.items-table td.c-name, .items-table td.c-hsn { grid-column: 1 / -1; }
.items-table td.c-name::before { content: none; }
.items-table input, .items-table select, .items-table .dd-btn { margin-top: 0; width: 100%; min-width: 0; }
.items-table input.num { text-align: right; }
.items-table td.amt { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; font-weight: 800; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.items-table td.row-actions { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: flex-end; gap: 4px; border-top: 1px solid var(--line); padding-top: 8px; white-space: nowrap; }
.items-table td.row-actions::before { content: none; }
.items-table .row-actions .icon-btn { width: 44px; height: 44px; }
.desc-toggle { display: block; text-align: left; align-self: flex-start; margin-top: 4px; border: 0; background: none; padding: 8px 0; min-height: 36px; font: inherit; font-size: .8rem; font-weight: 700; color: var(--accent-strong); cursor: pointer; }
.desc-toggle.on { color: var(--muted); }
.desc-input { margin-top: 6px !important; min-height: 56px !important; resize: vertical; font-size: 16px; }
.desc-input[hidden] { display: none; }
.totals { margin: 0; }
#t_tax { display: contents; }
.totals > div, .totals #t_tax > div { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: .93rem; }
.totals dt { color: var(--muted); font-weight: 600; } .totals dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.totals .strong dt { color: var(--ink); font-weight: 800; } .totals .strong { font-weight: 800; }
.totals .big { font-size: 1.3rem; border-top: 2px solid var(--ink); border-bottom: 0; margin-top: 8px; padding-top: 14px; letter-spacing: -.02em; }
.series-preview { font-family: var(--font-mono); font-weight: 600; }

/* ---- document view ---- */
.copies { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--gap); }
.copies > strong { flex: 1 1 100%; }
.copies label { margin: 0; }
.fin-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.fin-strip > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); min-width: 0; }
.fin-strip > div:last-child { grid-column: 1 / -1; }
.fin-strip span { font-size: .75rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.fin-strip strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.fin-strip .due strong { color: var(--neg-fg); } .fin-strip .ok strong { color: var(--pos-fg); }
.pdf-box { display: none; padding: 0; overflow: hidden; }
.pdf-box.card { padding: 0; }
.pdf-box iframe { width: 100%; height: 88vh; min-height: 680px; border: 0; display: block; background: var(--surface-2); }
.doc-bottom { margin-bottom: 16px; }
.doc-bottom > .card { margin-bottom: 16px; }
.kv { margin: 0; } .kv > div { display: flex; gap: var(--gap-sm); padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.kv > div:last-child { border-bottom: 0; }
.kv dt { flex: 0 0 104px; color: var(--muted); font-weight: 600; } .kv dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.line-desc { margin-top: 3px; font-size: .8rem; font-weight: 500; color: var(--muted); max-width: 46ch; }
.btn-wa .icon-brand { flex: none; }
.pop { display: block; position: relative; }
.pop[open] > form { margin-top: 8px; width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 14px; text-align: left; animation: pop .2s var(--ease) both; }
.table-stack td.actions-col .pop { flex: 1 1 100%; order: 2; }
.table-stack td.actions-col .pop > summary { display: inline-flex; }
.img-preview { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 10px; margin-bottom: var(--gap-sm); text-align: center; }
.img-preview img { max-width: 100%; max-height: 120px; }

/* ---- standalone pages: login, install ---- */
body.public-note { display: flex; justify-content: center; align-items: flex-start; padding: 6vh 16px; min-height: 100vh; background: var(--bg); }
body.public-note main { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 24px 20px; box-shadow: var(--shadow); height: fit-content; animation: rise var(--t-slow) var(--ease) both; }
body.public-note main.install { max-width: 600px; }
body.public-note main h1 { margin-bottom: 16px; font-size: 1.5rem; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand .brand-mark { width: 44px; height: 44px; border-radius: 13px; }
.auth-brand b { display: block; font-size: 1.2rem; font-weight: 800; letter-spacing: -.02em; }
.auth-brand small { display: block; color: var(--muted); font-weight: 600; font-size: .8rem; }
.req { list-style: none; padding: 0; margin: 0 0 var(--gap); display: grid; gap: 4px; } .req li { padding: 8px 12px; border-radius: 10px; background: var(--surface-2); font-weight: 600; font-size: .9rem; display: flex; justify-content: space-between; gap: 10px; }
.req li.bad b { color: var(--neg-fg); } .req li.ok b { color: var(--pos-fg); }

/* ---- own components: dropdowns, calendar, dialogs, tooltips, validation (see ui.js) ---- */
.dd-btn { display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left; cursor: pointer; margin-top: 6px; }
.dd-btn .dd-val { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-btn .icon { color: var(--muted); flex: none; }
.dd-btn.is-empty .dd-val { color: color-mix(in srgb, var(--muted) 80%, transparent); }
.dd-btn[aria-expanded="true"] .icon { color: var(--accent-strong); }
.dd-btn:not(.dp-btn)::after { content: ""; width: 16px; height: 16px; flex: none; background: currentColor; color: var(--muted); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center/contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center/contain no-repeat; transition: transform var(--t) var(--ease); }
.dd-btn[aria-expanded="true"]:not(.dp-btn)::after { transform: rotate(180deg); }
.dd-native { position: absolute !important; width: 1px !important; height: 1px !important; opacity: 0 !important; pointer-events: none !important; margin: 0 !important; padding: 0 !important; min-height: 0 !important; border: 0 !important; }
.dd-panel { display: none; position: fixed; z-index: 120; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 14px; box-shadow: var(--shadow-pop); padding: 6px; animation: dd-in .16s var(--ease) both; transform-origin: top center; max-width: calc(100vw - 16px); }
.dd-panel.up { transform-origin: bottom center; }
.dd-list { max-height: 184px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.dd-search { padding: 2px 2px 6px; }
.dd-search input { margin: 0; min-height: 38px; padding: 6px 10px; }
.dd-opt { display: flex; align-items: center; width: 100%; gap: 10px; text-align: left; border: 0; background: none; font: inherit; font-weight: 600; font-size: .92rem; color: var(--ink); padding: 8px 10px; min-height: 44px; border-radius: 9px; cursor: pointer; }
.dd-opt .dd-t { display: flex; flex-direction: column; min-width: 0; }
.dd-opt small { font-weight: 500; font-size: .76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-opt:hover, .dd-opt.act { background: var(--surface-2); }
.dd-opt.sel { background: var(--accent-soft); color: var(--accent-strong); }
.dd-opt[disabled] { opacity: .45; cursor: not-allowed; }
.dd-free { background: var(--accent-soft); }
.dd-empty { padding: 14px 10px; color: var(--muted); font-weight: 600; font-size: .9rem; }
/* calendar (inline in the date sheet on phones, a popover from 961px) */
.cal { width: 100%; max-width: none; margin: 0 auto; padding: 4px; user-select: none; }
.cal.dd-panel { width: 314px; }
.cal-head { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.cal-title { flex: 1; text-align: center; font-weight: 800; font-size: .95rem; }
.cal-nav { width: 44px; height: 44px; border: 0; border-radius: 10px; background: none; color: var(--ink); font-size: 1.15rem; font-weight: 700; cursor: pointer; }
.cal-nav:hover { background: var(--surface-2); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow span { text-align: center; font-size: .75rem; font-weight: 800; color: var(--muted); text-transform: uppercase; padding: 4px 0; }
.cal-day { height: 44px; border: 0; background: none; border-radius: 10px; font: inherit; font-weight: 600; font-size: .9rem; color: var(--ink); cursor: pointer; }
.cal-day:hover { background: var(--surface-2); }
.cal-day.today { box-shadow: inset 0 0 0 1.5px var(--accent-strong); }
.cal-day.sel { background: var(--accent); color: var(--accent-ink); }
.cal-foot { display: flex; justify-content: space-between; margin-top: 8px; padding: 0 4px; }
.cal-link { border: 0; background: none; font: inherit; font-weight: 700; font-size: .85rem; color: var(--accent-strong); cursor: pointer; padding: 12px 8px; min-height: 44px; }
.sheet-date .sheet-body { padding-bottom: 22px; }
/* confirm dialog: a bottom sheet on phones */
.dlg-wrap { position: fixed; inset: 0; z-index: 200; display: flex; align-items: flex-end; justify-content: center; padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px)); background: color-mix(in srgb, var(--side-bg) 55%, transparent); opacity: 0; transition: opacity .2s ease; }
.dlg-wrap.on { opacity: 1; }
.dlg { width: 100%; max-width: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 26px; padding: 24px 20px 20px; box-shadow: var(--shadow-pop); transform: translateY(110%); transition: transform .38s cubic-bezier(.2, .9, .25, 1); }
.dlg-wrap.on .dlg { transform: none; }
.dlg h2 { margin: 0 0 8px; font-size: 1.2rem; }
.dlg p { margin: 0 0 20px; color: var(--muted); font-weight: 500; line-height: 1.5; }
.dlg-grab { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: -10px auto 14px; }
.dlg-actions { display: flex; flex-direction: column-reverse; gap: 10px; }
.dlg-actions .btn { width: 100%; height: 48px; justify-content: center; }
.dlg .btn-danger { background: var(--neg-fg); border-color: transparent; color: var(--surface); }
.dlg .btn-danger:hover { background: var(--neg-fg); filter: brightness(1.08); }
body.dlg-open { overflow: hidden; }
/* toasts and tooltips */
.toasts { position: fixed; top: calc(10px + env(safe-area-inset-top, 0px)); left: 12px; right: 12px; z-index: 210; display: flex; flex-direction: column; gap: 10px; }
.toasts .flash { box-shadow: var(--shadow-pop); background: var(--surface); }
.tip { position: fixed; z-index: 220; pointer-events: none; background: var(--ink); color: var(--surface); font-size: .76rem; font-weight: 700; padding: 6px 10px; border-radius: 8px; opacity: 0; transition: opacity .12s ease; max-width: 260px; }
.tip.on { opacity: 1; }
/* validation */
.has-err > input, .has-err > select, .has-err > .dd-btn, .has-err > textarea, .has-err .inline-row > input { border-color: var(--neg-fg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--neg-fg) 14%, transparent); }
.field-err { display: block; color: var(--neg-fg); font-size: .76rem; font-weight: 700; margin-top: 5px; }
/* archive and ledger helpers */
.stats-ledger { margin-bottom: 16px; }

/* ==========================================================================
   Wider screens: everything below adds to the phone layout above.
   ========================================================================== */

/* ---- 640px: large phones, small tablets ---- */
@media (min-width: 640px) {
  .content { padding-left: 24px; padding-right: 24px; }
  .subnav { margin-left: -24px; margin-right: -24px; padding-left: 24px; padding-right: 24px; }
  h1 { font-size: 1.7rem; }
  .greet h1 { font-size: 1.9rem; }
  .page-head { align-items: flex-end; }
  .copies.card { padding: 14px 20px; }
  .copies > strong { flex: none; }
  .page-head .actions { width: auto; }
  .page-head .actions .btn { flex: none; }
  .card { padding: 22px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid .span-2 { grid-column: 1 / -1; }
  .filters-body .fgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters:not(.fold) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats { gap: 14px; }
  .stat { padding: 18px; gap: 14px; }
  .stat-value { font-size: 1.6rem; }
  .spark { display: block; }
  .stat-label { font-size: .85rem; }
  .fin-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .fin-strip > div:last-child { grid-column: auto; }
  .fin-strip strong { font-size: 1.25rem; }
  .quick { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .items-table tr { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .items-table td.c-hsn { grid-column: span 2; }
  .items-table td.c-qty, .items-table td.c-unit { grid-column: span 1; }
  .items-table td.c-name { grid-column: 1 / -1; }
  .items-table td.c-rate { grid-column: span 1; }
  .sheet { left: 50%; right: auto; width: min(520px, calc(100vw - 24px)); margin-left: calc(min(520px, calc(100vw - 24px)) / -2); }
  .dlg-wrap { align-items: center; padding: 16px; }
  .dlg { max-width: 420px; border-radius: 22px; transform: translateY(14px) scale(.97); transition: transform .28s var(--ease); }
  .dlg-grab { display: none; }
  .dlg-actions { flex-direction: row; justify-content: flex-end; }
  .dlg-actions .btn { width: auto; height: 44px; }
  .toasts { left: auto; right: 16px; top: 16px; max-width: min(380px, calc(100vw - 32px)); }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .doc-bottom > .card { margin-bottom: 0; }
  body.public-note { padding-top: 9vh; }
  body.public-note main { padding: 34px; border-radius: 24px; }
}

/* ---- 768px: tablets. Stacked cards turn back into real tables. ---- */
@media (min-width: 768px) {
  .table-stack { display: table; width: 100%; }
  .table-stack thead { display: table-header-group; }
  .table-stack tbody { display: table-row-group; width: auto; }
  .table-stack tfoot { display: table-footer-group; width: auto; }
  .table-stack tr { display: table-row; border: 0; border-radius: 0; margin: 0; padding: 0; background: none; }
  .table-stack tfoot tr, .tbl-card .table-stack tr { background: none; }
  .table-stack td, .table-stack th { display: table-cell; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; font-weight: inherit; }
  .table-stack th { padding-top: 10px; padding-bottom: 10px; white-space: nowrap !important; }
  .table-stack td::before, .table-stack tfoot th[data-label]::before { content: none; }
  .table-stack td:first-child { font-size: inherit; font-weight: inherit; }
  .table-stack td:first-child a { font-weight: 700; }
  .table-stack .num { text-align: right !important; white-space: nowrap !important; }
  .table-stack .actions-col, .table-stack td.actions-col { display: table-cell; text-align: right !important; white-space: nowrap !important; padding: 12px 10px; border-top: 0; margin: 0; }
  .table-stack tbody tr:last-child td { border-bottom: 0; }
  .table-stack tfoot th, .table-stack tfoot td { border-top: 2px solid var(--line-strong); border-bottom: 0; }
  .table-stack .actions-col .icon-btn { width: 36px; height: 36px; }
  .table-stack td.actions-col .pop { flex: none; }
  .card:not(.tbl-card):has(> .table-wrap > .table-stack) { background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 22px; }
  .tbl-card .table-wrap { padding: 0 16px 6px; }
  .tbl-card .card-head { padding: 22px 24px 0; }
  .tbl-foot { padding: 14px 24px; }
  .filters.fold { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0 14px; padding: 18px 20px; }
  .filters.fold .filters-top, .filters.fold .filters-body, .filters.fold .fgrid, .filters.fold .filters-actions { display: contents; }
  .filters.fold label { flex: 1 1 150px; margin: 0; }
  .filters.fold .filters-top > label { flex: 1 1 220px; }
  .filters.fold .fgrid label.wide, .filters.fold label.check { flex: 1 1 auto; }
  .filters.fold .filters-actions .btn { flex: none; }
  .filters.fold [data-fold] { display: none; }
  .filters.fold .filters-actions { gap: 10px; }
  .filters.fold > * > .btn, .filters.fold .filters-actions .btn { margin-bottom: 0; }
  .filters:not(.fold) { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; padding: 18px 20px; }
  .filters:not(.fold) label { flex: 1 1 150px; margin: 0; }
  .filters:not(.fold) .btn { width: auto; }
  .items-table tr { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .items-table td.c-name { grid-column: span 3; }
  .items-table td.c-hsn { grid-column: span 3; }
  .items-table td.c-qty, .items-table td.c-unit, .items-table td.c-num, .items-table td.c-rate { grid-column: span 1; }
  .kv dt { flex-basis: 120px; }
  .legend { gap: 8px 22px; }
}

/* ---- 961px: desktop shell. Sidebar replaces the bottom navigation. ---- */
@media (min-width: 961px) {
  :root { --bnav-h: 0px; }
  .app { display: flex; }
  .side { display: flex; width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: var(--side-bg); color: var(--side-ink); border-right: 1px solid var(--side-line); padding: 22px 14px 18px; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 40; scrollbar-width: thin; }
  .m-brand, .bnav, .sheet, .scrim { display: none !important; }
  .only-desk { display: inline-flex !important; }
  .only-mob { display: none !important; }
  .topbar { min-height: var(--topbar-h); padding: 14px 32px; background: color-mix(in srgb, var(--bg) 82%, transparent); }
  .topbar .spacer { display: block; flex: 1; }
  .search { flex: 1 1 280px; max-width: 520px; }
  .content { padding: 28px 32px 56px; }
  .subnav { flex-wrap: wrap; overflow: visible; margin: 0 0 var(--gap); padding: 0; }
  .subnav a, .subnav button { min-height: 0; padding: 8px 15px; }
  h1 { font-size: 1.85rem; }
  .greet h1 { font-size: 2.2rem; }
  .page-head { margin-bottom: 22px; }
  .card { padding: 24px; margin-bottom: var(--gap); }
  .copies.card { padding: 14px 24px; }
  .grid-2 { gap: var(--gap); }
  .btn { height: 42px; }
  .btn-primary:hover { transform: translateY(-1px); }
  .icon-btn { width: 40px; height: 40px; }
  input, select, textarea, .dd-btn { font-size: .95rem; min-height: 42px; }
  input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; }
  label.check { min-height: 0; font-size: .93rem; gap: 8px; }
  .form-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 18px; }
  .form-grid .span-2 { grid-column: span 2; }
  .dd-panel { display: block; }
  .is-pick { background-image: none; }
  .sticky-actions { position: sticky; bottom: 0; margin: var(--gap) -32px -56px; padding: 14px 32px; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: none; }
  .sticky-actions .btn { flex: none; }
  .sticky-actions .btn-ghost { display: inline-flex; }
  body.kb .sticky-actions { position: sticky; }
  .stats { gap: 18px; margin-bottom: 20px; }
  .stat { padding: 20px 22px 18px; gap: 16px; transition: transform .35s var(--ease), box-shadow .35s ease, border-color var(--t) ease; }
  .stat:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); border-color: var(--line-strong); }
  .stat-ico { width: 40px; height: 40px; border-radius: 12px; }
  .stat-label { font-size: .88rem; }
  .stat-value { font-size: 1.9rem; }
  .stat-value .cur { font-size: 1.2rem; } .stat-value .frac { font-size: 1.05rem; }
  .stat-foot { min-height: 44px; }
  .stat-foot .meta { font-size: .78rem; }
  .dash-row { flex-direction: row; flex-wrap: wrap; gap: 18px; margin-bottom: 20px; align-items: stretch; }
  .chart-card { flex: 2 1 560px; gap: 18px; }
  .age-card { flex: 1 1 340px; gap: 18px; }
  .age-total { font-size: 1.9rem; }
  .chart-y { width: 48px; }
  .legend .lg-v { font-size: 1.2rem; }
  .dash-main { flex-direction: row; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
  .dash-main > .tbl-card { flex: 2 1 620px; min-width: 0; }
  .dash-main > .side-col { flex: 1 1 340px; gap: 18px; }
  .side-col > .card { margin-bottom: 0; }
  .qa:hover { transform: translateY(-2px); }
  .quick { grid-template-columns: 1fr 1fr; gap: 12px; }
  .pdf-box { display: block; }
  .pdf-box.card { padding: 0; }
  .pdf-box iframe { height: 88vh; }
  .kv dt { flex-basis: 120px; }
  .pop { display: inline-block; }
  .pop[open] > form { position: absolute; right: 0; z-index: 20; width: 300px; margin-top: 0; padding: 18px; box-shadow: var(--shadow-pop); }
  body.public-note { padding-top: 9vh; }
}

/* ---- 1101px ---- */
@media (min-width: 1101px) {
  .totals-card { position: sticky; top: calc(var(--topbar-h) + 12px); }
}

/* ---- 1280px: wide desktop. Four KPI cards in one row. ---- */
@media (min-width: 1280px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat-value { font-size: 2.05rem; }
}

/* ---- 1366px: the item editor becomes a single-row table ---- */
@media (min-width: 1366px) {
  .items-table { display: table; width: 100%; }
  .items-table thead { display: table-header-group; }
  .items-table tbody { display: table-row-group; width: auto; }
  .items-table tr { display: table-row; border: 0; border-radius: 0; margin: 0; padding: 0; background: none; }
  .items-table td { display: table-cell; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
  .items-table td::before { content: none; }
  .items-table tbody tr:last-child td { border-bottom: 0; }
  .items-table td.c-name, .items-table td.c-hsn { grid-column: auto; }
  .items-table input, .items-table select, .items-table .dd-btn { min-height: 40px; padding: 7px 10px; }
  .items-table .c-name { min-width: 200px; }
  .items-table .c-hsn { width: 90px; } .items-table .c-qty, .items-table .c-unit { width: 84px; }
  .items-table .c-num { width: 100px; } .items-table .c-rate { width: 80px; }
  .items-table .amt { text-align: right; white-space: nowrap; min-width: 104px; font-size: .95rem; }
  .items-table td.row-actions { display: table-cell; border-top: 0; padding-top: 8px; text-align: right; }
  .items-table .row-actions .icon-btn { width: 32px; height: 32px; }
  .items-table td.amt { display: table-cell; grid-column: auto; }
  .items-table td > input, .items-table td > select, .items-table td > .dd-btn { min-width: 0; }
  .desc-toggle { padding: 2px 0; min-height: 0; font-size: .76rem; }
  .desc-input { font-size: .88rem; }
}

/* ---- reduced motion: no sliding or zooming, gentle fades only ---- */
@media (prefers-reduced-motion: reduce) {
  @keyframes rise { from { opacity: 0; } to { opacity: 1; } }
  @keyframes pop { from { opacity: 0; } to { opacity: 1; } }
  @keyframes toast-in { from { opacity: 0; } to { opacity: 1; } }
  @keyframes dd-in { from { opacity: 0; } to { opacity: 1; } }
  .stat:hover, .qa:hover { transform: none; }
}

@media print {
  .side, .topbar, .actions, .filters, .sticky-actions, .subnav, .icon-btn, .scrim, .bnav, .sheet { display: none !important; }
  body { background: #fff; color: #000; } .card { box-shadow: none; border-color: #bbb; } .content { padding: 0; max-width: none; }
  .app { display: block; }
}

/* ===== Mobile-first redesign v2: compact rows, hero card, focus flows, sheets ===== */
.m-only { display: block; }
@media (min-width: 961px) { .m-only { display: none !important; } .greet-name { display: inline; } }
@media (max-width: 960px) { .greet-name { display: none; } }
.fin-strip.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fin-strip.three > div:last-child { grid-column: auto; }
.fin-strip .bal strong { color: var(--warn-fg); }
.fin-strip .due.late strong { color: var(--neg-fg); }
.fin-strip.three strong, .fin-strip strong.num { font-size: 1.05rem; }
.btn-sm { height: 36px; padding: 0 12px; font-size: .82rem; border-radius: 10px; }
.wide { width: 100%; }
.late { color: var(--neg-fg) !important; }
.due-ok { color: var(--pos-fg) !important; }

.hero-card { background: var(--side-bg); color: var(--side-ink); border: 1px solid var(--side-line); border-radius: var(--radius); padding: 18px; margin-bottom: 12px; box-shadow: var(--shadow-pop); }
.hero-top { display: flex; align-items: center; justify-content: space-between; font-size: .85rem; font-weight: 700; color: var(--side-muted); }
.hero-val { font-size: 2.1rem; font-weight: 800; letter-spacing: -.035em; line-height: 1.15; margin: 6px 0 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hero-val .cur { font-size: 1.3rem; color: var(--side-muted); margin-right: 3px; font-weight: 700; }
.hero-val .frac { font-size: 1.1rem; color: var(--side-muted); font-weight: 700; }
.hero-sub { display: flex; justify-content: space-between; font-size: .78rem; font-weight: 700; color: var(--side-muted); margin-bottom: 8px; }
.hero-card .bar { background: var(--side-line); }
.hero-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.hero-actions .btn { padding: 0 10px; }
.hero-actions .btn:not(.btn-primary) { background: transparent; color: var(--side-ink); border-color: color-mix(in srgb, var(--side-ink) 22%, transparent); }
.hero-card .chip-neu { background: color-mix(in srgb, var(--side-ink) 12%, transparent); color: var(--side-ink); }

.list-card { padding: 0; overflow: hidden; }
.lrow { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; min-height: 64px; }
.list-card > .lrow:first-child { border-top: 0; }
.lrow:active { background: var(--surface-2); }
.lrow .avatar { width: 38px; height: 38px; font-size: .9rem; flex: none; }
.lrow-t { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lrow-t b { font-size: .95rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lrow-t small { font-size: .78rem; font-weight: 600; color: var(--muted); }
.lrow-t small:empty { display: none; }
.lrow-r { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.lrow-r b { font-size: .95rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; margin-bottom: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; }
.seg a { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; border-radius: 10px; color: var(--muted); font-weight: 800; font-size: .9rem; text-decoration: none; }
.seg a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.srch-row { display: flex; gap: 10px; margin-bottom: 12px; align-items: center; }
.srch-row .seg { flex: 1; margin: 0; }
.filter-dot { position: relative; }
.filter-dot::after { content: ""; position: absolute; top: 8px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent-strong); border: 2px solid var(--surface); }
.chips-active { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.chips-active a { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-size: .78rem; font-weight: 800; color: var(--ink); text-decoration: none; }

.flow-head { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-height: 60px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--line); }
.flow-head h1 { flex: 1; text-align: center; font-size: 1.05rem; font-family: var(--font-mono); letter-spacing: -.01em; margin: 0; }

.steps { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; list-style: none; padding: 0; margin: 4px 0 18px; }
.steps li { display: flex; flex-direction: column; gap: 6px; font-size: .78rem; font-weight: 800; color: var(--muted); }
.steps .sbar { height: 4px; border-radius: 4px; background: var(--line-strong); }
.steps li.done .sbar, .steps li.on .sbar { background: var(--accent); }
.steps li.on, .steps li.done { color: var(--ink); }
@media (min-width: 961px) { .steps { display: none; } }

.qbar { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 90; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 10px 10px 18px; border-radius: 22px; background: var(--side-bg); color: var(--side-ink); border: 1px solid var(--side-line); box-shadow: var(--shadow-pop); }
.qbar-t { display: flex; flex-direction: column; min-width: 0; }
.qbar-t small { font-size: .75rem; font-weight: 700; color: var(--side-muted); white-space: nowrap; }
.qbar-t b { font-size: 1.3rem; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.qbar .btn { flex: none; height: 48px; }
.qbar .btn:not(.btn-primary) { background: transparent; color: var(--side-ink); border-color: color-mix(in srgb, var(--side-ink) 22%, transparent); }
@media (min-width: 961px) { .qbar { display: none; } }
body.sheet-open .qbar, body.sheet-open .bnav { display: none; }

/* 2-step form on phones: only the active step shows */
@media (max-width: 960px) {
  form.flow [data-step] { display: none; }
  form.flow[data-cur="1"] [data-step="1"], form.flow[data-cur="2"] [data-step="2"] { display: block; }
  form.flow .sticky-actions { display: none; }
  form.flow[data-cur="1"] .s2-only, form.flow[data-cur="2"] .s1-only { display: none; }
  body.has-flow .content { padding-bottom: 112px; }
}
@media (min-width: 961px) { .qbar, .s1-only, .s2-only { display: none !important; } }

.sum-card { padding: 14px 16px; }
.sum-top { display: flex; align-items: center; gap: 12px; }
.sum-top .avatar { width: 40px; height: 40px; }
.sum-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sum-name b { font-weight: 800; }
.sum-name small { font-size: .78rem; font-weight: 600; color: var(--muted); }
.due-pill { display: inline-flex; align-items: center; gap: 8px; margin-top: 12px; padding: 6px 12px; border-radius: 99px; background: var(--surface-2); font-size: .82rem; font-weight: 800; }
.due-pill.late { background: var(--neg-bg); }
.due-pill.due-ok { background: var(--pos-bg); }
.amt-chips { display: flex; align-items: center; gap: 8px; margin: 6px 0 14px; flex-wrap: wrap; }
.amt-chips .chip { border: 0; font: inherit; font-size: .8rem; font-weight: 800; min-height: 36px; cursor: pointer; }
.subnav.copies-row { margin-bottom: 8px; }

@media (max-width: 960px) { .hide-mob { display: none !important; } }

/* ===== Desktop redesign v2 ===== */
.mono { font-family: var(--font-mono); letter-spacing: -.01em; }
.small { font-size: .82rem; }
.stat { position: relative; }
.stat-cover { position: absolute; inset: 0; border-radius: inherit; z-index: 1; }
.stat-cover:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
.stat.is-alert { border-color: color-mix(in srgb, var(--neg-fg) 35%, var(--line)); }
.greet { position: relative; }
.greet-actions { position: absolute; right: 0; top: 0; display: flex; gap: 10px; }
.attn-card { display: flex; flex-direction: column; gap: 4px; }
.attn-sec { font-size: .75rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 14px 0 0; }
.attn { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.attn-t { flex: 1; min-width: 0; display: flex; flex-direction: column; color: inherit; text-decoration: none; }
.attn-t b { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attn-t small { font-size: .78rem; font-weight: 600; color: var(--muted); }
.attn .num { font-weight: 800; white-space: nowrap; }
.age-mini { margin-top: auto; padding-top: 16px; }
.age-seg { display: flex; gap: 3px; height: 10px; }
.age-seg span { border-radius: 99px; min-width: 6px; }
.age-leg { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: .75rem; font-weight: 700; color: var(--muted); }
.age-leg i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }
.dtable td, .dtable th { white-space: nowrap; }
.dtable td { padding-top: 12px; padding-bottom: 12px; }
.dtable a.mono { font-weight: 700; text-decoration: none; color: var(--ink); }
.dtable a.mono:hover { text-decoration: underline; }
.dtable td:last-child { position: relative; }
.dtable tr.hov:hover td { background: var(--surface-2); }
.row-act { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); display: inline-flex; gap: 2px; opacity: 0; padding-left: 24px; background: linear-gradient(90deg, transparent, var(--surface-2) 24px); transition: opacity var(--t) ease; }
.row-act .icon-btn { width: 32px; height: 32px; }
tr.hov:hover .row-act, tr.hov:focus-within .row-act, tr.sel .row-act { opacity: 1; }
tr.sel td { background: var(--accent-soft) !important; }
td.ck, th.ck { width: 44px; padding-right: 0; }
.cell-who .t { display: flex; flex-direction: column; line-height: 1.25; }
.cell-who .t small { font-size: .72rem; font-weight: 600; }
.dtable td small { font-size: .75rem; font-weight: 700; }

/* invoice list */
.sumstrip { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.sumstrip > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); min-width: 0; }
.sumstrip span { font-size: .75rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.sumstrip strong { font-size: 1.15rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.sumstrip .ok { color: var(--pos-fg); } .sumstrip .bal { color: var(--warn-fg); } .sumstrip .late { color: var(--neg-fg); }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 12px; padding: 0 16px; scroll-padding-left: 16px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; display: flex; align-items: center; gap: 8px; padding: 12px 12px 10px; border-bottom: 3px solid transparent; font-weight: 800; font-size: .9rem; color: var(--muted); text-decoration: none; }
.tab.on { color: var(--ink); border-bottom-color: var(--accent); }
.tab .cnt { font-size: .72rem; padding: 1px 7px; border-radius: 99px; background: var(--neu-bg); color: var(--neu-fg); }
.bulk { display: none; align-items: center; gap: 10px; padding: 10px 20px; background: var(--side-bg); color: var(--side-ink); flex-wrap: wrap; }
.bulk.on { display: flex; }
.bulk .btn:not(.btn-wa) { background: transparent; color: var(--side-ink); border-color: color-mix(in srgb, var(--side-ink) 25%, transparent); }
.bulk .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.list-d { padding: 0 !important; overflow: hidden; }
.list-d .filters { margin: 0; border: 0; border-radius: 0; box-shadow: none; border-bottom: 1px solid var(--line); }
.list-d .table-wrap { padding: 0 8px; }
.list-d .pager { padding: 12px 20px; border-top: 1px solid var(--line); }
.late-note { display: block; font-size: .75rem; font-weight: 700; color: var(--neg-fg); }
.soon-note { display: block; font-size: .75rem; font-weight: 700; color: var(--muted); }

/* desktop-only layout fixes */
@media (min-width: 961px) {
  .main { flex: 1; }
  .sumstrip { grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
  .sumstrip strong { font-size: 1.4rem; }
  .tabs { margin: 0; padding: 0 20px; border-bottom: 1px solid var(--line); }
  .tab { padding: 16px 12px 14px; margin-bottom: -1px; }
  .stat-link .go { opacity: 0; }
  .stat:hover .go { opacity: 1; }
  .page-head .sub { margin-top: 2px; }
  .table td.nowrap, .table td.num, .table td.num { white-space: nowrap; }
}

/* item cards (phones and small laptops): name, quantity stepper and amount on top, price trio, then the rest */
.qty { display: flex; align-items: center; border: 1px solid var(--line-strong); border-radius: 12px; overflow: hidden; background: var(--surface); }
.qty-b { display: none; flex: none; width: 44px; height: 44px; border: 0; background: var(--surface-2); color: var(--ink); align-items: center; justify-content: center; cursor: pointer; }
.qty input { border: 0 !important; border-radius: 0 !important; box-shadow: none !important; text-align: center !important; font-weight: 800; min-width: 0; }
@media (max-width: 1365px) {
  .items-table tr { grid-template-columns: repeat(3, minmax(0, 1fr)); background: var(--surface); box-shadow: var(--shadow); }
  .items-table td.c-name { grid-column: 1 / -1; order: 1; }
  .items-table td.c-qty { grid-column: span 2; order: 2; }
  .items-table td.amt { grid-column: span 1; order: 3; flex-direction: column; align-items: flex-end; justify-content: flex-end; font-size: 1.15rem; letter-spacing: -.02em; }
  .items-table td.amt::before { align-self: flex-end; }
  .items-table td.c-num:nth-of-type(5) { order: 4; } .items-table td.c-num:nth-of-type(6) { order: 5; } .items-table td.c-num:nth-of-type(7) { order: 6; }
  .items-table td.c-hsn { grid-column: auto; order: 7; } .items-table td.c-unit { order: 8; } .items-table td.c-rate { order: 9; }
  .items-table td.row-actions { order: 10; }
  .qty-b { display: flex; }
  .items-table td.c-qty::before { content: attr(data-label); }
  .items-table .qty input { min-height: 44px; }
}
@media (min-width: 1366px) { .qty { display: contents; } .qty-b { display: none !important; } .qty input { border: 1px solid var(--line-strong) !important; border-radius: var(--radius-sm, 10px) !important; text-align: right !important; font-weight: inherit; } }

.crumb { display: flex; align-items: center; gap: 4px; font-size: .85rem; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a:hover { color: var(--ink); }
.hint { display: block; margin-top: 6px; font-size: .78rem; font-weight: 700; color: var(--muted); }
.hint a { color: var(--link); text-decoration: none; }
.tax-line { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 14px; }
.seg2 { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; margin-top: 6px; }
.seg2 a { text-align: center; padding: 9px 6px; border-radius: 9px; font-size: .88rem; font-weight: 800; color: var(--muted); text-decoration: none; }
.seg2 a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.sb-total { display: flex; flex-direction: column; margin-right: 12px; }
.sb-total small { font-size: .75rem; font-weight: 700; color: var(--muted); }
.sb-total b { font-size: 1.5rem; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.sb-sp { flex: 1; }
.kbhint { font-size: .75rem; font-weight: 600; color: var(--muted); }
@media (min-width: 961px) {
  .pm-select { display: none; }
  .sticky-actions { align-items: center; }
}

/* ===== invoice view: two panes on desktop, action bar and sheets on phones ===== */
.vsplit { display: flex; flex-direction: column; }
.vmain, .vrail { display: contents; }
.vfin { order: 1; } .vpdf { order: 2; } .vitems { order: 3; } .vrail > #payments { order: 4; } .vrail > .card:not(.vfin):not(.vpay):not(#payments) { order: 5; }
.vsplit .vpdf { margin: 0; }
.vpay { order: 3; }
.vhead h1 .badge { vertical-align: middle; }
.actbar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--bnav-h) + 20px + env(safe-area-inset-bottom, 0px)); z-index: 60; display: flex; gap: 8px; padding: 8px; border-radius: 22px; background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--line); box-shadow: var(--shadow-pop); backdrop-filter: blur(14px); }
.actbar .btn { flex: 1; min-width: 0; padding: 0 10px; }
.actbar .icon-btn { flex: none; width: 46px; height: 46px; }
body.sheet-open .actbar { display: none; }
.sheet-tall { max-height: 86vh; max-height: 86dvh; }
.opt { display: flex; align-items: center; gap: 14px; padding: 12px 6px; margin: 0; border-bottom: 1px solid var(--line); color: var(--ink); }
.opt span { display: flex; flex-direction: column; }
.opt b { font-size: .95rem; font-weight: 800; } .opt small { font-size: .78rem; font-weight: 500; color: var(--muted); }
.opt + .btn, .opt:last-of-type { margin-bottom: 14px; }
.amt-field { text-align: center; padding: 8px 0 8px; }
.amt-field small { font-weight: 700; color: var(--muted); }
.amt-val { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 2.2rem; font-weight: 800; letter-spacing: -.03em; }
.amt-val span { color: var(--muted); font-size: 1.6rem; }
.amt-val input { width: 220px; border: 0; margin: 0; padding: 0; min-height: 56px; font-size: 2.2rem; font-weight: 800; text-align: left; background: transparent; box-shadow: none; }
.amt-field .amt-chips { justify-content: center; }
.sheet-menu { display: flex; flex-direction: column; }
.sheet-menu .menu-item, .sheet-menu .menu-item-link { display: block; margin: 0; }
.menu-item button, .menu-item-link, .menu-item-btn { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 0 8px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--ink); font: inherit; font-weight: 700; text-align: left; text-decoration: none; cursor: pointer; }
.menu-item.danger button { color: var(--neg-fg); }
.tl { display: flex; flex-direction: column; }
.tl-i { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.tl-i:last-child { border-bottom: 0; }
.tl-i > i { width: 10px; height: 10px; border-radius: 50%; background: var(--accent-strong); flex: none; }
.tl-i > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tl-i small { font-size: .78rem; font-weight: 600; color: var(--muted); }
.row-act2 { display: inline-flex; gap: 2px; }
.pop { position: relative; }
.copy-pills { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; }
.copy-pill-note { padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); font-weight: 800; font-size: .84rem; color: var(--muted); }
.copy-pill-note.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.copy-sum { margin-left: auto; }

.split-btn { display: inline-flex; position: relative; }
.split-btn > .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split-btn .menu-copies > summary { padding: 0 10px; border-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; height: 42px; }
details.menu { position: relative; }
details.menu > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 8px); z-index: 50; min-width: 250px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow-pop); padding: 8px; }
.menu-title { padding: 6px 10px; font-size: .75rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.opt-row { display: flex; align-items: center; gap: 12px; padding: 9px 10px; margin: 0; border-radius: 10px; cursor: pointer; }
.opt-row:hover { background: var(--surface-2); }
.opt-row span { display: flex; flex-direction: column; } .opt-row b { font-size: .9rem; } .opt-row small { font-size: .75rem; font-weight: 500; color: var(--muted); }
.menu-panel .menu-item button, .menu-panel .menu-item-btn { border-bottom: 0; border-radius: 10px; min-height: 42px; padding: 0 10px; }
.menu-panel .menu-item button:hover, .menu-panel .menu-item-btn:hover { background: var(--surface-2); }
.menu-panel form.inline { display: block; }

@media (min-width: 961px) {
  .vsplit { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 20px; align-items: start; }
  .vmain { display: block; } .vrail { display: block; }
  .vfin, .vpdf, .vitems, .vpay, .vrail > #payments, .vrail > .card { order: 0; }
  .vpdf { position: sticky; top: calc(var(--topbar-h) + 14px); }
  .vrail > .card { margin-bottom: 14px; }
  .vfin .fin-strip { margin-bottom: 12px; }
  .vfin .fin-strip strong { font-size: .98rem; white-space: nowrap; }
  .vfin .fin-strip > div { padding: 10px 12px; }
  .vpay .form-grid { grid-template-columns: 1fr 1fr; }
  .vpay .span-2 { grid-column: 1 / -1; }
  .vactions { width: auto; flex-wrap: nowrap; margin: 0; }
  .vactions .btn { flex: none; }
  .actbar { display: none; }
  .pdf-box iframe { height: calc(100vh - var(--topbar-h) - 100px); min-height: 600px; }
}

.qa-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.qa-grid [hidden] { display: none; }
body.has-flow .bnav { display: none; }
@media (min-width: 961px) {
  .list-d .filters.fold { padding: 14px 20px; border-bottom: 1px solid var(--line); gap: 0 12px; flex-wrap: nowrap; }
  .list-d .filters.fold .filters-top > label { flex: 2 1 240px; }
  .list-d .filters.fold label { flex: 1 1 130px; }
  .list-d .filters.fold .fgrid label.wide { flex: 1.5 1 180px; }
  .list-d .filters.fold .filters-actions { flex: none; }
}
@media (min-width: 961px) {
  #pmSeg ~ .dd-btn { display: none; }
  .sticky-actions .sb-total { order: 0; } .sticky-actions .kbhint { order: 1; } .sticky-actions .sb-sp { order: 2; }
  .sticky-actions .btn-ghost { order: 3; } .sticky-actions .btn:not(.btn-primary):not(.btn-ghost) { order: 4; } .sticky-actions .btn-primary { order: 5; }
}
details.more > summary { list-style: none; cursor: pointer; }
details.more > summary::-webkit-details-marker { display: none; }
@media (max-width: 960px) {
  .vfin { padding: 12px; }
  .vfin .fin-strip { gap: 8px; }
  .vfin .fin-strip.three > div { padding: 10px 8px; }
  .vfin .fin-strip strong { font-size: .86rem !important; white-space: nowrap; overflow-wrap: normal; }
}

/* Quick sheet totals: keep numbers on one line */
#sheetQuick .fin-strip.three strong{white-space:nowrap;overflow-wrap:normal;font-size:.9rem}
#sheetQuick .fin-strip.three>div{padding:10px}


/* ===== Compact scale v3: Poppins, smaller type and controls ===== */
:root { --font-size: 14px; --radius: 14px; --radius-md: 10px; --radius-sm: 8px; --gap: 16px; }
body { letter-spacing: 0; }
h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
h2 { font-weight: 600; letter-spacing: -.01em; }
h1, h2, h3, .brand-name, legend, .table th, .fin-strip span, .tabs a { font-weight: 600; }
.btn { height: 42px; font-size: .9rem; padding: 0 14px; }
.icon-btn { width: 40px; height: 40px; }
input, select, textarea, .dd-btn { min-height: 44px; }
@media (min-width: 961px) {
  :root { --font-size: 13px; --sidebar-w: 224px; --topbar-h: 60px; --gap: 14px; --radius: 12px; --radius-md: 9px; --radius-sm: 7px; }
  .btn { height: 34px; font-size: .92rem; padding: 0 12px; font-weight: 600; }
  .icon-btn { width: 32px; height: 32px; }
  input, select, textarea, .dd-btn { font-size: 1rem; min-height: 36px; padding: 6px 10px; margin-top: 4px; font-weight: 400; }
  label { font-size: .82rem; margin-bottom: 10px; font-weight: 500; }
  .search { height: 36px; border-radius: 10px; }
  .brand-mark { width: 32px; height: 32px; border-radius: 9px; }
  .side a.nav { padding: 8px 10px; gap: 10px; font-size: .95rem; font-weight: 500; }
  .page-head .sub { font-size: .9rem; }
  .card-head h2, .card h2 { font-size: 1.05rem; }
  .items-table input, .items-table select, .items-table .dd-btn { min-height: 34px; padding: 5px 8px; }
  .items-table .c-hsn { width: 80px; } .items-table .c-qty, .items-table .c-unit { width: 76px; }
  .items-table .c-num { width: 88px; } .items-table .c-rate { width: 72px; }
  .items-table .amt { font-size: .95rem; min-width: 92px; }
  .items-table .row-actions .icon-btn { width: 28px; height: 28px; }
  .stat-ico { width: 34px; height: 34px; }
  .badge, .pill { font-size: .75rem; }
  .table td { padding-top: 9px; padding-bottom: 9px; }
}
@media (max-width: 960px) {
  .page-head .sub { font-size: .88rem; }
  .btn { font-weight: 600; }
}
.greet h1 { font-size: 1.4rem; }
@media (min-width: 961px) { .greet h1 { font-size: 1.7rem; } .greet-actions { gap: 8px; } }
@media (max-width: 960px) {
  .attn { flex-wrap: wrap; row-gap: 8px; }
  .attn-t { flex: 1 1 calc(100% - 120px); }
  .attn .num { margin-left: auto; }
  .attn .btn { flex: none; height: 36px; }
}

/* ===== Docked bottom navigation, add menu, Menu page ===== */
:root { --bnav-h: 58px; }
.bnav { left: 0; right: 0; bottom: 0; height: auto; padding: 0 4px env(safe-area-inset-bottom, 0px); gap: 0; border-radius: 0; border: 0; border-top: 1px solid var(--side-line); background: var(--side-bg); backdrop-filter: none; -webkit-backdrop-filter: none; box-shadow: 0 -8px 24px -16px rgba(0, 0, 0, .5); align-items: stretch; }
.bnav .bn { flex: 1 1 0; height: var(--bnav-h); flex-direction: column; gap: 3px; border-radius: 0; font-size: .66rem; font-weight: 500; letter-spacing: .01em; }
.bnav .bn span { display: block; }
.bnav .bn.active, .bnav .bn[aria-expanded="true"] { flex: 1 1 0; background: none; color: var(--side-ink); }
.bnav .bn::before { content: ""; position: absolute; top: 0; left: 50%; width: 26px; height: 3px; margin-left: -13px; border-radius: 0 0 4px 4px; background: var(--accent); transform: scaleX(0); transition: transform .3s var(--ease); }
.bnav .bn.active::before { transform: scaleX(1); }
.bnav .bn { position: relative; }
.bnav .bn.active .icon { animation: bnPop .42s var(--ease); }
@keyframes bnPop { 0% { transform: translateY(3px) scale(.8); } 55% { transform: translateY(-2px) scale(1.12); } 100% { transform: none; } }
.bnav .bn:active .icon { transform: scale(.88); }
.bnav .bn .icon { transition: transform .15s ease; }
.bn-add { position: relative; flex: none; align-self: center; width: 54px; height: 40px; margin: 0 6px; border: 0; border-radius: 13px; background: var(--accent); color: var(--accent-ink); cursor: pointer; display: block; transition: transform .2s var(--ease), border-radius .25s var(--ease), box-shadow .25s ease; -webkit-tap-highlight-color: transparent; }
.bn-add:active { transform: scale(.92); }
.bn-add .ai { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; transition: transform .32s var(--ease), opacity .2s ease; }
.bn-add .ai-x { opacity: 0; transform: rotate(-90deg) scale(.5); }
.bn-add[aria-expanded="true"] { border-radius: 20px; box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 28%, transparent); }
.bn-add[aria-expanded="true"] .ai-new { opacity: 0; transform: rotate(90deg) scale(.5); }
.bn-add[aria-expanded="true"] .ai-x { opacity: 1; transform: none; }
.addmenu { position: fixed; left: 50%; bottom: calc(var(--bnav-h) + 18px + env(safe-area-inset-bottom, 0px)); width: min(260px, calc(100vw - 32px)); margin-left: calc(min(260px, calc(100vw - 32px)) / -2); z-index: 95; padding: 6px; display: flex; flex-direction: column; gap: 2px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-pop); transform-origin: 50% 100%; opacity: 0; transform: translateY(14px) scale(.92); pointer-events: none; transition: opacity .18s ease, transform .3s var(--ease); }
.addmenu[hidden] { display: flex; visibility: hidden; }
.addmenu.on { opacity: 1; transform: none; pointer-events: auto; visibility: visible; }
.addmenu::after { content: ""; position: absolute; left: 50%; bottom: -6px; width: 12px; height: 12px; margin-left: -6px; background: var(--surface); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); transform: rotate(45deg); border-radius: 0 0 3px 0; }
.am { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 10px; border-radius: 12px; color: var(--ink); text-decoration: none; font-size: .92rem; font-weight: 500; opacity: 0; transform: translateY(10px); transition: opacity .2s ease, transform .3s var(--ease), background-color .15s ease; }
.addmenu.on .am { opacity: 1; transform: none; transition-delay: calc(var(--i) * 28ms + 40ms); }
.am:active { background: var(--surface-2); }
.am-ic { width: 30px; height: 30px; border-radius: 9px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; flex: none; }
.am-main { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.am-main .am-ic { background: rgba(0, 0, 0, .08); }
.am-main:active { background: var(--accent); filter: brightness(.95); }
body.add-open .scrim { opacity: 1; pointer-events: auto; }
body.add-open .scrim { z-index: 92; }
.menu-page { display: flex; flex-direction: column; gap: 14px; }
.menu-page .sheet-biz { margin: 0; }
.mgroup { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px 4px; box-shadow: var(--shadow); animation: mgIn .4s var(--ease) both; animation-delay: calc(var(--g) * 50ms); }
@keyframes mgIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.mgroup .srow:last-child { border-bottom: 0; }
@media (prefers-reduced-motion: reduce) { .bnav .bn.active .icon, .mgroup { animation: none; } .addmenu, .am, .bn-add, .bn-add .ai { transition: none; } }
@media (min-width: 961px) { .addmenu { display: none !important; } .menu-page { max-width: 520px; } }
body.add-open .bnav { z-index: 96; }

/* ===== Audit fixes ===== */
/* Dropdowns in the page header (copies, More) must sit above the PDF preview and cards that follow */
.page-head { position: relative; z-index: 30; }
details.menu[open] { z-index: 40; }
.qbar.s2-only { gap: 8px; }
.qbar.s2-only .qbar-t b { font-size: 1.15rem; }
.qbar.s2-only .btn { padding: 0 14px; }
@media (min-width: 961px) { .sumstrip:has(> div:nth-child(3):last-child) { grid-template-columns: repeat(3, 1fr); } }
