/* =====================================================================================================
   Munshi web — design system
   Layers: 1 tokens (primitives → semantic roles, light + dark) · 2 base · 3 app shell · 4 components ·
           5 screens · 6 responsive / print / motion.
   Rules: use semantic tokens only (never raw hex below layer 1) · spacing on the 4 px scale · type from the
   scale · every control ≥ 44 px tall on touch · visible focus ring · money = tabular numbers, red = you will
   get (customer owes), green = you will give / received. See docs/design-system.md.
   ===================================================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  /* Primitives */
  --green-950: #062b16; --green-900: #0b3d26; --green-800: #0f5132; --green-700: #146c43; --green-600: #198754;
  --green-300: #7fd0a5; --green-200: #b7e4c9; --green-100: #dcf3e4; --green-50: #eef8f1;
  --neutral-0: #ffffff; --neutral-25: #fbfbf9; --neutral-50: #f6f7f4; --neutral-100: #eef0ec; --neutral-200: #e2e6e1;
  --neutral-300: #cdd3cc; --neutral-500: #78837d; --neutral-600: #5f6b66; --neutral-700: #3e4843; --neutral-900: #1b1f1d;
  --red-700: #b42318; --red-600: #c0392b; --red-50: #fdecea;
  --amber-500: #e0a100; --amber-100: #fff1c7; --amber-50: #fff8e6;
  --wa-500: #25d366; --wa-950: #062b16;

  /* Semantic roles (light) */
  --bg: var(--neutral-50);            /* page */
  --surface: var(--neutral-0);        /* cards, sheets, inputs */
  --surface-2: var(--neutral-100);    /* subtle fills, table heads, chips */
  --ink: var(--neutral-900);          /* body text */
  --muted: var(--neutral-600);        /* secondary text (5.3:1 on bg) */
  --line: var(--neutral-200);         /* hairlines */
  --line-strong: var(--neutral-300);  /* input borders */
  --brand: var(--green-800);
  --brand-hover: var(--green-900);
  --brand-soft: var(--green-50);      /* selected rows, tints */
  --brand-tint: var(--green-100);
  --on-brand: #ffffff;
  --accent: var(--amber-500);         /* attention, review */
  --accent-soft: var(--amber-50);
  --danger: var(--red-700);
  --danger-soft: var(--red-50);
  --ok: var(--green-700);
  --recv: var(--red-700);             /* "you will get" */
  --pay: var(--green-700);            /* "you will give" / money in */
  --focus: color-mix(in srgb, var(--brand) 45%, transparent);
  --scrim: rgb(10 20 15 / .48);

  /* Legacy names kept so older rules and pages keep working */
  --card: var(--surface); --brand-2: var(--green-600);

  /* Type */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", "Noto Sans Bengali", sans-serif;
  --fs-xs: .75rem;   /* 12 */  --fs-sm: .875rem; /* 14 */  --fs-md: 1rem;     /* 16 */
  --fs-lg: 1.125rem; /* 18 */  --fs-xl: 1.25rem; /* 20 */  --fs-2xl: 1.5rem;  /* 24 */
  --fs-3xl: 1.875rem;/* 30 */  --fs-4xl: 2.25rem;/* 36 */
  --lh-tight: 1.2; --lh: 1.5;

  /* Space (4 px scale) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;

  /* Shape, depth, motion, size */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 20px; --r-pill: 999px;
  --e1: 0 1px 2px rgb(16 24 20 / .05), 0 1px 3px rgb(16 24 20 / .06);
  --e2: 0 4px 12px rgb(16 24 20 / .08), 0 2px 4px rgb(16 24 20 / .05);
  --e3: 0 12px 32px rgb(16 24 20 / .16), 0 4px 8px rgb(16 24 20 / .06);
  --shadow: var(--e1);
  --dur-fast: 120ms; --dur: 200ms; --ease: cubic-bezier(.2, .7, .2, 1);
  --tap: 44px;
  --sidebar: 240px; --content-max: 1180px; --panel: min(560px, 46vw);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1311; --surface: #161d19; --surface-2: #1d2621; --ink: #e8ece9; --muted: #a2aea8;
    --line: #27312c; --line-strong: #36423b;
    --brand: #4cc38a; --brand-hover: #6ad3a0; --brand-soft: #15291f; --brand-tint: #1b3a2a; --on-brand: #062b16;
    --accent: #f2b72a; --accent-soft: #2b2412; --danger: #ff8a7a; --danger-soft: #3a1a17; --ok: #4cc38a;
    --recv: #ff8a7a; --pay: #4cc38a; --brand-2: #3fb57d; --scrim: rgb(0 0 0 / .6);
    --e1: 0 1px 2px rgb(0 0 0 / .4); --e2: 0 4px 14px rgb(0 0 0 / .45); --e3: 0 14px 36px rgb(0 0 0 / .6);
  }
}

/* ---------- 2. Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: var(--fs-md)/var(--lh) var(--font); -webkit-font-smoothing: antialiased; }
body { padding-bottom: 190px; max-width: 720px; margin: 0 auto; }
h1, h2, h3 { line-height: var(--lh-tight); letter-spacing: -.01em; }
h1 { margin: 0; font-size: var(--fs-xl); font-weight: 800; }
h2 { font-size: var(--fs-xl); font-weight: 700; margin: var(--sp-6) 0 var(--sp-3); }
h3 { font-size: var(--fs-md); font-weight: 700; margin: var(--sp-6) 0 var(--sp-2); }
p { margin: 0 0 var(--sp-3); }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
::selection { background: var(--brand-tint); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); } .small { font-size: var(--fs-sm); }
.row { display: flex; align-items: center; flex-wrap: wrap; } .gap { gap: var(--sp-2); } .end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.wide { width: 100%; margin: var(--sp-3) 0 var(--sp-1); }
.timer, .amt, strong[id^="d-"], .kpi strong, .hero-cell strong, .results td, .ledger td, .bill-totals { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- 3. App shell ---------- */
.top { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-4) var(--sp-2); }
.brand { display: flex; gap: var(--sp-3); align-items: center; min-width: 0; }
.brand > div { min-width: 0; }
.brand h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-2xl); }
.tag { margin: 0; font-size: var(--fs-xs); color: var(--muted); }
.totals { display: flex; flex: none; gap: var(--sp-4); text-align: right; font-weight: 700; }
body:has(#tab-dash.active) .totals { display: none; } /* the dashboard hero already shows both totals */
.totals .lbl { display: block; font-size: var(--fs-xs); font-weight: 500; color: var(--muted); }
#tot-recv { color: var(--recv); } #tot-pay { color: var(--pay); }

.tabs { display: flex; gap: var(--sp-1); padding: 0 var(--sp-3); border-bottom: 1px solid var(--line); position: sticky; top: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); z-index: 2; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { background: none; border: 0; min-height: var(--tap); padding: 0 var(--sp-3); color: var(--muted); font-weight: 600;
  border-bottom: 2px solid transparent; cursor: pointer; flex: none; white-space: nowrap; transition: color var(--dur-fast); }
.tabs button:hover { color: var(--ink); }
.tabs .ti { display: none; width: 20px; height: 20px; flex: none; }
.tabs button.active { color: var(--brand); border-color: var(--brand); }
main { padding: var(--sp-3) var(--sp-4); }
.tab { display: none; } .tab.active { display: block; animation: fade-in var(--dur) var(--ease); }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } }

/* Voice dock: the one always-present action */
.dock { position: fixed; left: 0; right: 0; bottom: 0; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom)); z-index: 5; }
.dock > * { max-width: 688px; margin-left: auto; margin-right: auto; }
.dock-row { display: flex; justify-content: center; align-items: center; gap: var(--sp-8); }
.round { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); cursor: pointer; transition: background var(--dur-fast), transform var(--dur-fast); }
.round:hover { background: var(--surface-2); }
.round svg { width: 24px; height: 24px; }
.mic { width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--brand) 40%, transparent); transition: transform var(--dur-fast) var(--ease), background var(--dur-fast); }
.mic:hover { background: var(--brand-hover); }
.mic svg { width: 34px; height: 34px; }
.mic:active, .round:active, .q:active { transform: scale(.96); }
.mic.rec { background: var(--danger); animation: pulse 1.2s infinite; }
.mic.busy { opacity: .6; pointer-events: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 50%, transparent); } 70% { box-shadow: 0 0 0 18px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.status { text-align: center; margin: var(--sp-2) 0 0; font-size: var(--fs-sm); color: var(--muted); min-height: 1.3em; }
.text-form { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.photo-strip { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-2); align-items: center; flex-wrap: wrap; }
.photo-strip img { width: 52px; height: 52px; object-fit: cover; border-radius: var(--r-sm); border: 1px solid var(--line); }

/* ---------- 4. Components ---------- */
/* Buttons: primary (one per view), ghost (secondary), ok / danger (money in / out), wa (WhatsApp) */
button.primary, button.ghost, button.ok, button.danger, .wa, a.small-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); min-height: var(--tap); padding: 0 var(--sp-4);
  border-radius: var(--r-md); border: 1px solid transparent; font-weight: 600; line-height: 1.2; cursor: pointer; text-decoration: none;
  transition: background var(--dur-fast), border-color var(--dur-fast), transform var(--dur-fast); }
button.primary { background: var(--brand); color: var(--on-brand); }
button.primary:hover { background: var(--brand-hover); }
button.ghost, a.small-btn { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
button.ghost:hover, a.small-btn:hover { background: var(--surface-2); }
button.ghost.danger, .small-btn.danger { color: var(--danger); background: var(--surface); border-color: var(--line-strong); }
button.ghost.danger:hover { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
button.ok { background: var(--ok); color: var(--on-brand); }
button.danger { background: var(--danger); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary:active, button.ghost:active, button.ok:active, button.danger:active { transform: scale(.98); }
.wa { background: var(--wa-500); color: var(--wa-950); font-size: var(--fs-sm); min-height: 36px; padding: 0 var(--sp-3); border-radius: var(--r-pill); }
.wa:hover { filter: brightness(.95); }
.small-btn { min-height: 36px !important; padding: 0 var(--sp-3) !important; font-size: var(--fs-sm); }
.icon-btn { background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md); min-width: var(--tap); height: var(--tap);
  display: grid; place-items: center; cursor: pointer; text-decoration: none; color: inherit; font-size: var(--fs-md); transition: background var(--dur-fast); }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.del { min-width: 32px; height: 32px; font-size: var(--fs-sm); color: var(--muted); border-color: transparent; background: transparent; }
.icon-btn.del:hover { color: var(--danger); background: var(--danger-soft); }

/* Fields */
input, select, textarea { width: 100%; min-height: var(--tap); padding: var(--sp-2) var(--sp-3); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); transition: border-color var(--dur-fast), box-shadow var(--dur-fast); }
input:hover, select:hover { border-color: var(--neutral-500); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus); }
input::placeholder { color: var(--muted); opacity: .8; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; min-height: 0; accent-color: var(--brand); }
input[type=file] { padding: var(--sp-2); }
label { font-size: var(--fs-sm); color: var(--muted); }
details summary { cursor: pointer; color: var(--brand); font-weight: 600; min-height: var(--tap); display: flex; align-items: center; }
fieldset { border: 0; padding: 0; margin: 0; }

/* Surfaces */
.card, .bench-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--sp-4); box-shadow: var(--e1); }
.form { display: grid; gap: var(--sp-3); margin: var(--sp-3) 0; }
.form label { display: grid; gap: var(--sp-1); font-weight: 500; }
.form.inline { grid-template-columns: 2fr 1fr 1fr auto auto; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.grid2 label { display: grid; gap: var(--sp-1); }
.banner { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-3);
  background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 55%, transparent); }

/* Lists and rows */
.list { list-style: none; padding: 0; margin: var(--sp-3) 0; display: grid; gap: var(--sp-2); }
.list li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4); box-shadow: var(--e1); }
.list.compact { gap: 0; margin: 0; }
.list.compact li { padding: var(--sp-3) 0; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; box-shadow: none; background: transparent; }
.list.compact li:last-child { border-bottom: 0; }
.party-row, .party-head { display: flex; align-items: center; gap: var(--sp-3); cursor: pointer; }
.party-head { justify-content: space-between; }
.list li:has(.party-row):hover { border-color: var(--line-strong); }
.party-name { font-weight: 600; }
.party-sub { font-size: var(--fs-sm); color: var(--muted); }
.party-body { margin-top: var(--sp-3); border-top: 1px dashed var(--line); padding-top: var(--sp-2); display: none; }
li.open .party-body { display: block; }
.party-actions { margin-top: var(--sp-2); flex-wrap: nowrap; } .party-actions input { flex: 1; }
.entry { display: flex; justify-content: space-between; font-size: var(--fs-sm); padding: var(--sp-1) 0; gap: var(--sp-2); }
.log li { font-size: var(--fs-sm); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--brand-tint); color: var(--brand); font-weight: 700; }
.amt { font-weight: 700; white-space: nowrap; text-align: right; }
.amt.big { font-size: var(--fs-3xl); display: block; line-height: var(--lh-tight); }
.amt.recv, .recv { color: var(--recv); } .amt.pay, .pay { color: var(--pay); }
.empty { color: var(--muted); text-align: center; padding: var(--sp-10) var(--sp-4); }
.empty em { color: var(--ink); font-style: normal; font-weight: 600; }

/* Tags */
.badge, .chip { display: inline-flex; align-items: center; font-size: var(--fs-xs); font-weight: 700; padding: 2px var(--sp-2); border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--ink); }
.badge { margin-bottom: var(--sp-1); }
.badge.warn, .chip.warn { background: var(--accent); color: var(--neutral-900); }
.count { font-size: var(--fs-xs); opacity: .8; margin-left: var(--sp-1); }

/* Segmented control */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: var(--r-md); padding: var(--sp-1); gap: var(--sp-1); }
.seg button { border: 0; background: transparent; min-height: 40px; border-radius: calc(var(--r-md) - 4px); cursor: pointer; color: var(--muted); font-weight: 600; transition: background var(--dur-fast); }
.seg button.active { background: var(--surface); color: var(--brand); box-shadow: var(--e1); }

/* Stats */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; margin: var(--sp-3) 0; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--e1); overflow: hidden; }
.kpis:empty { display: none; }
/* Hairlines on the right and bottom of each cell; the strip's overflow clips the outer ones */
.kpi { padding: var(--sp-3) var(--sp-4); box-shadow: 1px 0 0 var(--line), 0 1px 0 var(--line); min-width: 0; }
.kpi .lbl { display: block; font-size: var(--fs-xs); color: var(--muted); margin-bottom: 2px; }
.kpi strong { font-size: var(--fs-xl); }

/* Tables */
.table-wrap { overflow-x: auto; }
.results, .bill-lines { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.results th, .bill-lines th { text-align: left; font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  background: var(--surface-2); padding: var(--sp-2) var(--sp-3); }
.results td, .bill-lines td { text-align: left; padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--line); }
.results tbody tr:hover { background: var(--brand-soft); }
.bill-lines .r, .results .r { text-align: right; white-space: nowrap; }
#week-table td:nth-child(n+2), #week-table th:nth-child(n+2) { text-align: right; }

/* Overlays */
.sheet { position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: flex-end; justify-content: center; z-index: 10; animation: fade-in var(--dur) var(--ease); }
.sheet[hidden] { display: none; }
.sheet-body { background: var(--surface); width: 100%; max-width: 720px; border-radius: var(--r-xl) var(--r-xl) 0 0; padding: var(--sp-5) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom));
  max-height: 88vh; overflow: auto; box-shadow: var(--e3); animation: sheet-up var(--dur) var(--ease); }
@keyframes sheet-up { from { transform: translateY(24px); opacity: .6; } }
.toast { position: fixed; top: var(--sp-4); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md); z-index: 60; max-width: 90vw; box-shadow: var(--e2); font-weight: 500; }

/* ---------- 5. Screens ---------- */
/* Dashboard */
.hero { display: grid; grid-template-columns: auto auto 1fr; gap: var(--sp-10); align-items: end; margin-bottom: var(--sp-4); padding: var(--sp-6); }
.hero #d-report { justify-self: end; grid-row: 1; grid-column: 3; }
/* Get-vs-give bar: green track (you will give), red fill (you will get) */
.hero-ratio { grid-column: 1 / -1; height: 6px; border-radius: var(--r-pill); background: var(--pay); overflow: hidden; }
.hero-ratio span { display: block; height: 100%; width: 0; background: var(--recv); transition: width var(--dur) var(--ease); }
.hero-ratio.is-empty { background: var(--line); }
/* Avatar circles shrink a little inside compact dashboard lists */
.list.compact .avatar { width: 36px; height: 36px; font-size: var(--fs-sm); }
.hero-cell { display: grid; gap: 2px; }
.hero-cell .lbl::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: var(--sp-2); vertical-align: middle; background: var(--recv); }
.hero-cell + .hero-cell .lbl::before { background: var(--pay); }
.hero #d-report { border-color: transparent; background: transparent; color: var(--brand); padding: 0 var(--sp-2); }
.hero #d-report:hover { background: var(--brand-soft); }
.hero-cell strong { font-size: var(--fs-4xl); line-height: var(--lh-tight); letter-spacing: -.02em; }
.hero-cell .lbl { font-weight: 600; font-size: var(--fs-sm); }
html[lang="en"] .hero-cell .muted.small { display: none; } /* the English hint repeats the label */
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-3); margin-bottom: var(--sp-4); }
.q { display: grid; justify-items: center; align-content: center; gap: var(--sp-2); min-height: 104px; padding: var(--sp-3) var(--sp-2); border-radius: var(--r-lg);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; font-weight: 600; box-shadow: var(--e1);
  transition: border-color var(--dur-fast), transform var(--dur-fast), box-shadow var(--dur-fast); }
.q:hover { border-color: var(--line-strong); box-shadow: var(--e2); }
.q .qi { display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--r-md); background: var(--brand-soft); color: var(--brand); }
.q .qi svg { width: 24px; height: 24px; }
.q.primary-q { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.q.primary-q .qi { background: transparent; color: var(--on-brand); }
.q.primary-q .qi svg { width: 30px; height: 30px; }
.q.primary-q:hover { background: var(--brand-hover); }
.dash-grid { display: grid; grid-template-columns: 1fr; gap: var(--sp-4); margin-top: var(--sp-4); }
.dash-grid h3 { margin: 0 0 var(--sp-3); }
.bars { display: flex; align-items: flex-end; justify-content: space-between; height: 150px; gap: var(--sp-2); padding-top: var(--sp-2); }
.bar-day { flex: 1; display: grid; justify-items: center; align-content: end; gap: var(--sp-1); height: 100%; }
.bar-pair { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.bar { width: 12px; border-radius: 4px 4px 0 0; }
.bar.gave, .lg.gave { background: color-mix(in srgb, var(--recv) 80%, transparent); }
.bar.got, .lg.got { background: color-mix(in srgb, var(--pay) 80%, transparent); }
.bar-lbl { font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; }
.legend { display: flex; gap: var(--sp-4); font-size: var(--fs-xs); color: var(--muted); margin-top: var(--sp-2); }
.lg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: var(--sp-1); }

/* Khata */
#tab-khata > .row { margin-top: var(--sp-3); flex-wrap: nowrap; }
#filter, #sort { width: auto; }

/* Party ledger (full screen on phones, side panel on desktop) */
.party-view { position: fixed; inset: 0; background: var(--bg); z-index: 6; overflow: auto; padding: 0 var(--sp-4) 230px; max-width: 720px; margin: 0 auto; }
body.pv-open { overflow: hidden; }
.pv-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.pv-title { flex: 1; min-width: 0; }
.pv-title .party-name { font-size: var(--fs-lg); }
.pv-balance { display: grid; gap: var(--sp-3); }
.pv-balance .lbl { display: block; font-size: var(--fs-sm); color: var(--muted); }
.pv-balance strong { font-size: var(--fs-3xl); line-height: var(--lh-tight); }
.pv-phone { font-size: var(--fs-sm); color: var(--muted); display: grid; gap: var(--sp-1); }
.ledger { margin-top: var(--sp-3); }
.ledger td { vertical-align: top; }
.ledger .r { text-align: right; white-space: nowrap; }
th.gave { color: var(--recv); } th.got { color: var(--pay); }
.pv-form { position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; background: var(--surface); border-top: 1px solid var(--line); box-shadow: var(--e3);
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--sp-2); max-width: 720px; margin: 0 auto; }
.pv-btns { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.gave-btn, .got-btn { border: 0; border-radius: var(--r-md); min-height: 48px; font-weight: 700; color: #fff; cursor: pointer; transition: filter var(--dur-fast); }
.gave-btn { background: var(--red-600); } .got-btn { background: var(--green-700); }
.gave-btn:hover, .got-btn:hover { filter: brightness(1.08); }
body.pv-open .dock { display: none; }

/* Bills, items, cashbook, reports */
.bill-bar input { flex: 1; min-width: 180px; }
.bill-row .bill-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-2); }
.bill-row.cancelled { opacity: .55; }
.bill-row.cancelled .amt { text-decoration: line-through; }
.bill-body { max-width: 900px; }
.bill-lines input { min-height: 36px; padding: var(--sp-1) var(--sp-2); min-width: 60px; }
.bill-lines td:first-child input { min-width: 150px; }
.bill-totals { display: grid; gap: var(--sp-1); justify-items: end; }
.bill-totals div { display: flex; gap: var(--sp-4); }
.bill-totals .grand { font-size: var(--fs-xl); font-weight: 800; }
.cash-form { grid-template-columns: 1fr 2fr auto auto auto; }
.range-card { display: grid; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.range-card label { display: grid; gap: 2px; }
.range-card input[type=date] { width: auto; }

/* Confirm sheet (what Munshi understood) */
.transcript { font-style: italic; color: var(--muted); margin: 0 0 var(--sp-2); }
.readback { font-size: var(--fs-lg); font-weight: 700; margin: 0 0 var(--sp-3); }
.actions { list-style: none; padding: 0; margin: 0 0 var(--sp-3); display: grid; gap: var(--sp-2); }
.actions li { border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-3); display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2); align-items: start; }
.actions li.review { border-color: var(--accent); background: var(--accent-soft); }
.actions .fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: var(--sp-2); }
.actions .fields label { font-size: var(--fs-xs); color: var(--muted); }
.actions .fields input { min-height: 36px; padding: var(--sp-1) var(--sp-2); font-size: var(--fs-sm); }
.followup { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--r-md); padding: var(--sp-3); margin: 0 0 var(--sp-3);
  display: flex; gap: var(--sp-3); align-items: center; justify-content: space-between; flex-wrap: wrap; }
.followup .question { margin: 0; font-weight: 700; }

/* Speed test */
.bench-card { margin-top: var(--sp-3); }
.bench-head { display: flex; justify-content: space-between; font-weight: 600; }
.bench-line { font-size: var(--fs-lg); font-weight: 600; margin: var(--sp-3) 0 var(--sp-1); }
#b-judge { margin-top: var(--sp-3); }
.verdict { font-weight: 700; font-size: var(--fs-lg); }

/* Onboarding */
.onboard { position: fixed; inset: 0; z-index: 50; background: var(--green-800); color: #fff; display: flex; flex-direction: column; padding: var(--sp-6) var(--sp-5) calc(var(--sp-6) + env(safe-area-inset-bottom)); }
.ob-body { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; max-width: 480px; margin: 0 auto; width: 100%; }
.ob-icon { font-size: 56px; background: rgb(255 255 255 / .14); border-radius: 50%; width: 120px; height: 120px; display: grid; place-items: center; margin-bottom: var(--sp-6); }
.onboard h2 { font-size: var(--fs-3xl); margin: 0 0 var(--sp-3); }
.onboard p { font-size: var(--fs-lg); opacity: .88; line-height: var(--lh); }
.ob-langs { display: grid; gap: var(--sp-3); width: 100%; margin-top: var(--sp-2); }
.ob-langs button { min-height: 56px; padding: 0 var(--sp-4); border-radius: var(--r-lg); border: 0; font-size: var(--fs-xl); font-weight: 700; text-align: left;
  background: rgb(255 255 255 / .12); color: #fff; cursor: pointer; transition: background var(--dur-fast); }
.ob-langs button:hover { background: rgb(255 255 255 / .2); }
.ob-langs button.on { background: #fff; color: var(--green-800); }
.ob-dots { display: flex; justify-content: center; gap: 6px; margin: var(--sp-4) 0; }
.ob-dots i { width: 8px; height: 8px; border-radius: 8px; background: rgb(255 255 255 / .4); transition: width var(--dur) var(--ease); }
.ob-dots i.on { width: 22px; background: #fff; }
.ob-foot { display: flex; justify-content: space-between; align-items: center; max-width: 480px; margin: 0 auto; width: 100%; }
.ob-next { background: #fff; color: var(--green-800); border: 0; border-radius: var(--r-md); min-height: 52px; padding: 0 var(--sp-8); font-weight: 700; font-size: var(--fs-md); cursor: pointer; }
.ob-skip { background: none; border: 0; min-height: var(--tap); color: rgb(255 255 255 / .85); cursor: pointer; font-size: var(--fs-md); font-weight: 600; }
.onboard :focus-visible { outline-color: rgb(255 255 255 / .7); }

/* Login */
.login { position: fixed; inset: 0; z-index: 40; background: radial-gradient(120% 80% at 50% 0%, var(--green-700), var(--green-950)); display: grid; place-items: center; padding: var(--sp-5); }
.login-card { background: var(--surface); border-radius: var(--r-xl); padding: var(--sp-8) var(--sp-6); max-width: 400px; width: 100%; display: grid; gap: var(--sp-3); justify-items: center; text-align: center; box-shadow: var(--e3); }
.login-card h2 { margin: 0; font-size: var(--fs-3xl); color: var(--brand); }
.consent { display: flex; gap: var(--sp-2); text-align: left; font-size: var(--fs-sm); color: var(--muted); }
.consent input { width: auto; margin-top: 2px; }
.google-btn { min-height: var(--tap); }
.otp-form { width: 100%; display: grid; gap: var(--sp-3); text-align: left; }
.otp-form label { font-size: var(--fs-sm); color: var(--muted); display: grid; gap: var(--sp-1); }
.phone-row { display: flex; align-items: center; gap: var(--sp-2); }
.phone-row span { font-weight: 700; color: var(--ink); }
.wa-login { width: 100%; min-height: 48px; background: var(--wa-500); color: var(--wa-950); border: 0; border-radius: var(--r-pill); font-weight: 700; cursor: pointer; }
.wa-login:hover { filter: brightness(.95); }
.otp-code { text-align: center; letter-spacing: 10px; font-size: var(--fs-2xl); font-variant-numeric: tabular-nums; }
.dev-code { background: var(--amber-100); color: var(--neutral-900); border-radius: var(--r-sm); padding: var(--sp-2) var(--sp-3); margin: 0; }
#otp-step-code .primary { width: 100%; }
#account-box a { color: var(--brand); }

/* Business profile (legacy form) */
.profile { z-index: 30; }
.profile-body { display: grid; gap: var(--sp-3); max-width: 560px; border-radius: var(--r-xl); margin: auto; }
.profile-body label { font-size: var(--fs-sm); color: var(--muted); display: grid; gap: var(--sp-1); }
.pf-select { position: relative; }
.pf-select-btn { width: 100%; display: flex; justify-content: space-between; min-height: var(--tap); padding: 0 var(--sp-3); align-items: center; border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface); cursor: pointer; text-align: left; }
.pf-options { list-style: none; margin: var(--sp-1) 0 0; padding: var(--sp-1); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--e2); max-height: 280px; overflow: auto; }
.pf-options li { display: grid; grid-template-columns: 28px auto 1fr; gap: var(--sp-2); align-items: center; padding: var(--sp-3); border-radius: var(--r-sm); cursor: pointer; font-size: var(--fs-sm); }
.pf-options li:hover { background: var(--brand-soft); }
.pf-gst { display: flex; gap: var(--sp-5); align-items: center; flex-wrap: wrap; }
.pf-gst legend { font-size: var(--fs-sm); margin-bottom: var(--sp-1); }
.pf-gst label { display: flex; gap: var(--sp-2); align-items: center; color: var(--ink); min-height: var(--tap); }
.pf-gst input { width: auto; }
.pf-error { color: var(--danger); min-height: 1em; margin: 0; font-size: var(--fs-sm); font-weight: 500; }

/* Setup conversation (same flow as the Android app) */
.su { display: flex; flex-direction: column; max-width: 620px; height: min(88vh, 760px); padding: 0; overflow: hidden; border-radius: var(--r-xl); margin: auto; }
.su-head { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-3) var(--sp-2); }
.su-head h2 { flex: 1; margin: 0; font-size: var(--fs-lg); }
.su-head .icon-btn[hidden] { visibility: hidden; display: grid; }
.su-bar { height: 4px; background: var(--line); }
.su-bar span { display: block; height: 100%; width: 0; background: var(--brand); transition: width var(--dur) var(--ease); }
.su-chat { flex: 1; overflow: auto; padding: var(--sp-4) var(--sp-3) var(--sp-2); display: flex; flex-direction: column; gap: var(--sp-2); background: var(--bg); }
.su-chat > :first-child { margin-top: auto; }
.su-row { display: flex; align-items: flex-end; gap: var(--sp-2); animation: fade-in var(--dur) var(--ease); }
.su-row.me { justify-content: flex-end; }
.su-av { width: 28px; height: 28px; flex: none; border-radius: 50%; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; font-weight: 800; font-size: var(--fs-xs); }
.su-row.faded .su-av { opacity: .45; }
.su-bubble { max-width: min(78%, 420px); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-lg) var(--r-lg) var(--r-lg) 4px; background: var(--surface); box-shadow: var(--e1); line-height: 1.4; }
.su-row.faded .su-bubble { color: var(--muted); }
.su-row.me .su-bubble { border-radius: var(--r-lg) var(--r-lg) 4px var(--r-lg); background: var(--brand-tint); font-weight: 600; cursor: pointer; }
.su-row.me .su-bubble:hover, .su-row.me .su-bubble:focus-visible { outline: 2px solid var(--brand); }
.su-pen { color: var(--muted); font-size: var(--fs-xs); margin-left: var(--sp-1); }
.su-tip { margin: 0 var(--sp-6) var(--sp-1) 36px; font-size: var(--fs-sm); color: var(--muted); }
.su-summary { margin-left: 36px; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); display: grid; gap: var(--sp-1); }
.su-summary b { color: var(--brand); font-size: var(--fs-lg); }
.su-input { padding: var(--sp-3) var(--sp-3) var(--sp-4); display: grid; gap: var(--sp-3); }
.su .pf-error { padding: 0 var(--sp-4); }
.su-text { display: flex; gap: var(--sp-2); align-items: center; }
.su-text input { flex: 1; min-width: 0; border-radius: var(--r-pill); padding: 0 var(--sp-4); min-height: 48px; }
.su-text input::placeholder { font-style: italic; opacity: .6; }
.su-send { width: 48px; height: 48px; border-radius: 50% !important; padding: 0 !important; font-size: var(--fs-lg); flex: none; }
.su-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); }
.su-card { min-width: 0; overflow-wrap: anywhere; text-align: left; display: grid; gap: 2px; padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: inherit; cursor: pointer; font: inherit; transition: border-color var(--dur-fast), background var(--dur-fast); }
.su-card span { font-size: var(--fs-xs); color: var(--muted); }
.su-card:hover, .su-card.on { border-color: var(--brand); background: var(--brand-soft); }
.su-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.su .chip { font-size: var(--fs-sm); font-weight: 600; min-height: 40px; padding: 0 var(--sp-4); border-radius: var(--r-pill); border: 1px solid var(--line-strong); background: var(--surface); color: inherit; cursor: pointer; }
.su .chip.on { background: var(--brand-tint); border-color: var(--brand); color: var(--ink); }
.su .chip:disabled { opacity: .6; cursor: default; }
.su-two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
.su-two button, .su-wide { min-height: 52px; font-size: var(--fs-md); width: 100%; }
.su-list { display: grid; gap: var(--sp-2); }
.su-opt { display: grid; grid-template-columns: 28px 1fr auto; gap: var(--sp-3); align-items: center; text-align: left; padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: inherit; cursor: pointer; font: inherit; }
.su-opt small { display: block; color: var(--muted); }
.su-opt:hover { border-color: var(--brand); background: var(--brand-soft); }
.su-oi { font-size: var(--fs-xl); }
.su-voice { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3) 0; }
.su-voice[hidden] { display: none; }
.su-voice span { flex: 1; font-size: var(--fs-sm); color: var(--muted); }
.su-voice span.on { color: var(--brand); font-weight: 600; }
.su-mic { width: var(--tap); height: var(--tap); flex: none; border-radius: 50%; border: 0; background: var(--brand); color: var(--on-brand); font-size: var(--fs-lg); cursor: pointer; }
.su-mic.on { background: var(--danger); animation: su-pulse 1.2s ease-in-out infinite; }
@keyframes su-pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--danger) 25%, transparent); } }

/* ---------- 6. Responsive, print, motion ---------- */
.shop-card { display: none; } /* desktop sidebar only */
@media (max-width: 620px) { .cash-form { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .su { height: 100dvh; max-height: none; border-radius: 0; max-width: none; } .profile { align-items: stretch; } }
@media (max-width: 520px) {
  .form.inline { grid-template-columns: 1fr 1fr; } .form.inline #sf-item { grid-column: 1 / -1; }
  .pv-form { grid-template-columns: 1fr 1fr; } #pv-amt { grid-column: 1 / -1; }
  .hero { grid-template-columns: 1fr 1fr; gap: var(--sp-4); padding: var(--sp-4); } .hero #d-report { grid-row: auto; grid-column: 1 / -1; width: 100%; justify-self: stretch; }
  .brand h1 { font-size: var(--fs-xl); }
  .hero-cell strong { font-size: var(--fs-2xl); }
  .quick { gap: var(--sp-2); } .q { min-height: 84px; font-size: var(--fs-sm); }
  #tab-khata > .row { flex-wrap: wrap; } #search { flex: 1 1 100%; } #filter, #sort { flex: 1; min-width: 0; }
}
@media (max-width: 420px) { .totals { gap: var(--sp-2); } .grid2 { grid-template-columns: 1fr; } .dock-row { gap: var(--sp-6); } }

/* Desktop: sidebar navigation, wider content, ledger as a side panel (Khatabook-desktop style) */
@media (min-width: 960px) {
  body { max-width: none; padding-left: var(--sidebar); padding-bottom: 150px; }
  .tabs { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar); flex-direction: column; gap: 2px; padding: 84px var(--sp-3) var(--sp-3);
    border-bottom: 0; border-right: 1px solid var(--line); background: var(--surface); backdrop-filter: none; z-index: 4; }
  .tabs::before { content: "Munshi"; position: absolute; top: 24px; left: 20px; padding-left: 40px; line-height: 32px; font-weight: 800; font-size: var(--fs-xl);
    color: var(--brand); letter-spacing: -.01em; background: url(icon.svg) no-repeat left center / 32px; }
  .tabs button { display: flex; align-items: center; gap: var(--sp-3); text-align: left; border-bottom: 0; border-radius: var(--r-md); min-height: var(--tap);
    padding: 0 var(--sp-3); font-size: var(--fs-md); }
  .tabs .ti { display: block; }
  .tabs { padding-bottom: 84px; } /* room for the shop card */
  .shop-card { position: fixed; left: 0; bottom: 0; z-index: 5; width: var(--sidebar); display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4); min-height: 68px; background: var(--surface); border: 0; border-top: 1px solid var(--line); border-right: 1px solid var(--line);
    color: var(--ink); text-align: left; cursor: pointer; transition: background var(--dur-fast); }
  .shop-card:hover { background: var(--surface-2); }
  .shop-card .avatar { width: 36px; height: 36px; font-size: var(--fs-sm); }
  .sc-text { display: grid; min-width: 0; }
  .sc-name { font-weight: 700; font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sc-owner { font-size: var(--fs-xs); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabs button:hover { background: var(--surface-2); }
  .tabs button.active { background: var(--brand-soft); color: var(--brand); box-shadow: inset 3px 0 0 var(--brand); }
  .top, main { max-width: var(--content-max); margin: 0 auto; }
  .top { padding: var(--sp-6) var(--sp-6) var(--sp-2); }
  main { padding: var(--sp-3) var(--sp-6); }
  .dash-grid { grid-template-columns: 1fr 1fr; }
  /* The voice dock floats as a pill instead of a full-width bar, so content stays visible behind it */
  .dock { left: var(--sidebar); background: none; border: 0; backdrop-filter: none; pointer-events: none; padding-bottom: calc(var(--sp-5) + env(safe-area-inset-bottom)); }
  .dock > * { pointer-events: auto; }
  .dock-row { width: max-content; gap: var(--sp-5); padding: var(--sp-2) var(--sp-4); background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px); border: 1px solid var(--line); border-radius: var(--r-pill); box-shadow: var(--e3); }
  .mic { width: 60px; height: 60px; } .mic svg { width: 28px; height: 28px; }
  .round { width: 44px; height: 44px; } .round svg { width: 20px; height: 20px; }
  .status { width: max-content; max-width: 100%; margin: var(--sp-2) auto 0; padding: 2px var(--sp-3); border-radius: var(--r-pill); background: color-mix(in srgb, var(--surface) 92%, transparent); }
  .status:empty { display: none; }
  .text-form, .photo-strip, .followup { background: var(--surface); padding: var(--sp-2); border-radius: var(--r-lg); box-shadow: var(--e2); }
  .party-view { left: auto; right: 0; width: var(--panel); max-width: none; margin: 0; border-left: 1px solid var(--line); box-shadow: var(--e3); padding-bottom: 170px; }
  .pv-form { left: auto; right: 0; width: var(--panel); max-width: none; margin: 0; }
  body.pv-open { overflow: auto; }
  body.pv-open main, body.pv-open .top { margin-right: var(--panel); }
  body.pv-open #tab-khata > .row { flex-wrap: wrap; } body.pv-open #search { flex: 1 1 100%; } body.pv-open #filter, body.pv-open #sort { flex: 1; min-width: 0; }
  body.pv-open .dock { display: block; right: var(--panel); }
  .sheet { align-items: center; }
  .sheet-body { border-radius: var(--r-xl); max-height: 86vh; }
}

@media print {
  body { background: #fff; color: #000; padding: 0; }
  .top, .tabs, .shop-card, main, .dock, .pv-form, .pv-head .icon-btn, #pv-remind, #pv-share, #pv-print, .pv-phone, .del, .toast, .sheet, .quick, .hero { display: none !important; }
  .party-view { position: static; padding: 0; overflow: visible; box-shadow: none; border: 0; width: auto; }
  .card { box-shadow: none; }
  body.print-report .top, body.print-report .tabs, body.print-report .dock, body.print-report .tab:not(#tab-reports), body.print-report #tab-reports > :not(.range-card), body.print-report .range-card .row { display: none !important; }
  body.print-report main, body.print-report #tab-reports { display: block !important; }
  body.print-report { padding: 0 !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
