/* Khata — design system
   Ledger ink indigo on cool paper. Red ink = you gave, green = you got, haldi = due.
   The party ledger is the one loud element: a ruled bahi page with a double red margin. */

:root {
  --paper: #F5F6FA;
  --sheet: #FFFFFF;
  --ink: #1E2A5A;
  --ink-soft: #3A4573;
  --text: #1B2033;
  --muted: #6B7391;
  --rule: #DCE1EC;
  --rule-soft: #EDF0F6;
  --gave: #C2362B;
  --gave-bg: #FBEDEB;
  --got: #1F8A55;
  --got-bg: #E6F4EC;
  --haldi: #B97A06;
  --haldi-fill: #E8A317;
  --haldi-bg: #FDF4DE;
  --margin-red: #E7A39D;
  --focus: #3D5AFE;
  --rail: #1E2A5A;
  --rail-text: #C9D1F0;
  --shadow-lift: 0 18px 50px -18px rgba(30, 42, 90, .45);
  --r-s: 6px;
  --r-m: 10px;
  --r-l: 18px;
  --f-ui: "Hanken Grotesk", "Noto Sans Devanagari", system-ui, sans-serif;
  --f-num: "Bricolage Grotesque", "Hanken Grotesk", system-ui, sans-serif;
  --rail-w: 236px;
  --tabs-h: 64px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #10131C;
  --sheet: #181C28;
  --ink: #AFC0FF;
  --ink-soft: #C6D1FF;
  --text: #E7EAF3;
  --muted: #929AB5;
  --rule: #2A3042;
  --rule-soft: #212636;
  --gave: #FF7A6E;
  --gave-bg: #3A1F1F;
  --got: #4FD08C;
  --got-bg: #173226;
  --haldi: #F5BE45;
  --haldi-fill: #E8A317;
  --haldi-bg: #3A2F14;
  --margin-red: #7A3A35;
  --rail: #0B0E16;
  --rail-text: #AEB7D6;
  --shadow-lift: 0 18px 50px -18px rgba(0, 0, 0, .8);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #10131C; --sheet: #181C28; --ink: #AFC0FF; --ink-soft: #C6D1FF; --text: #E7EAF3; --muted: #929AB5;
    --rule: #2A3042; --rule-soft: #212636; --gave: #FF7A6E; --gave-bg: #3A1F1F; --got: #4FD08C; --got-bg: #173226;
    --haldi: #F5BE45; --haldi-bg: #3A2F14; --margin-red: #7A3A35; --rail: #0B0E16; --rail-text: #AEB7D6;
    --shadow-lift: 0 18px 50px -18px rgba(0, 0, 0, .8); color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.5 var(--f-ui);
  background: var(--paper);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
svg[aria-hidden="true"] { width: 20px; height: 20px; flex: none; }
.row > svg { color: var(--muted); }
h1, h2, h3 { font-family: var(--f-num); color: var(--ink); line-height: 1.15; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.02rem; font-weight: 600; }
p { margin: 0 0 .75em; }
.num, .amt { font-family: var(--f-num); font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.gave { color: var(--gave); }
.got { color: var(--got); }
.due { color: var(--haldi); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* ───────── Boot ───────── */
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-mark { width: 56px; height: 56px; border-radius: 14px; background: var(--rail); color: #fff; display: grid; place-items: center; font: 700 28px var(--f-num); }

/* ───────── App frame ───────── */
.frame { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100vh; }
.rail {
  background: var(--rail); color: var(--rail-text);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; padding: 16px 12px;
}
.rail-biz { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: var(--r-m); background: transparent; border: 0; width: 100%; text-align: left; color: #fff; cursor: pointer; }
.rail-biz:hover { background: rgba(255,255,255,.06); }
.rail-biz .logo { width: 36px; height: 36px; border-radius: 9px; background: #fff; color: var(--rail); display: grid; place-items: center; font: 700 16px var(--f-num); flex: none; overflow: hidden; }
.rail-biz .logo img { width: 100%; height: 100%; object-fit: cover; }
.rail-biz .bn { font-weight: 700; line-height: 1.2; }
.rail-biz .bp { font-size: .78rem; color: var(--rail-text); opacity: .8; }
.rail nav { margin-top: 18px; display: flex; flex-direction: column; gap: 2px; }
.rail .group { margin: 16px 10px 6px; font-size: .78rem; opacity: .6; }
.rail a.nav {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 8px;
  color: var(--rail-text); text-decoration: none; font-weight: 500;
}
.rail a.nav svg { width: 19px; height: 19px; flex: none; }
.rail a.nav:hover { background: rgba(255,255,255,.06); color: #fff; }
.rail a.nav[aria-current="page"] { background: rgba(255,255,255,.12); color: #fff; }
.rail a.nav .lock { margin-left: auto; opacity: .55; width: 14px; height: 14px; }
.rail .spacer { flex: 1; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; gap: 12px; padding: 10px 28px; min-height: 60px;
}
.topbar .search { flex: 1; max-width: 520px; position: relative; }
.topbar .search input { width: 100%; padding: 9px 12px 9px 36px; border-radius: 999px; border: 1px solid var(--rule); background: var(--sheet); }
.topbar .search svg { position: absolute; left: 12px; top: 50%; translate: 0 -50%; width: 16px; color: var(--muted); }
.topbar .mob-biz { display: none; }
.topbar .mob-only-search { display: none; }
.view { padding: 24px 28px 64px; max-width: 1180px; width: 100%; }
.view.wide { max-width: 1400px; }

.tabs { display: none; }

@media (max-width: 900px) {
  .frame { grid-template-columns: 1fr; }
  .rail { display: none; }
  .topbar { padding: 8px 14px; padding-top: max(8px, env(safe-area-inset-top)); }
  .topbar .mob-biz { display: flex; align-items: center; gap: 8px; border: 0; background: none; padding: 0; font-weight: 700; color: var(--ink); max-width: 46vw; cursor: pointer; }
  .topbar .mob-biz span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .search { order: 3; flex-basis: 100%; max-width: none; display: none; }
  .topbar.searching .search { display: block; }
  .topbar .mob-only-search { display: inline-grid; }
  .view { padding: 16px 16px calc(var(--tabs-h) + 90px); }
  .tabs {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; z-index: 30; bottom: 0; left: 0; right: 0;
    background: var(--sheet); border-top: 1px solid var(--rule); height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: .72rem; color: var(--muted); text-decoration: none; font-weight: 600; }
  .tabs a svg { width: 22px; height: 22px; }
  .tabs a[aria-current="page"] { color: var(--ink); }
}

/* ───────── Page header ───────── */
.ph { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.ph .sub { color: var(--muted); margin-top: 4px; }
.ph .acts { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-weight: 600; margin-bottom: 8px; font-size: .9rem; }
.back:hover { color: var(--ink); }

/* ───────── Buttons ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--r-m); border: 1px solid var(--rule); background: var(--sheet);
  font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; min-height: 40px;
}
.btn:hover { border-color: var(--ink-soft); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--sheet); }
.btn-primary:hover { filter: brightness(1.12); border-color: var(--ink); }
.btn-gave { background: #C2362B; border-color: #C2362B; color: #fff; }
.btn-got { background: #1F8A55; border-color: #1F8A55; color: #fff; }
.btn-gave:hover, .btn-got:hover { filter: brightness(1.08); }
.btn-danger { color: var(--gave); }
.btn-danger:hover { border-color: var(--gave); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--rule-soft); border-color: transparent; }
.btn-sm { padding: 5px 11px; min-height: 32px; font-size: .88rem; border-radius: 8px; }
.btn-block { width: 100%; }
.icon-btn { border: 0; background: none; width: 38px; height: 38px; border-radius: 10px; display: inline-grid; place-items: center; cursor: pointer; color: var(--ink); position: relative; }
.icon-btn:hover { background: var(--rule-soft); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn .dot { position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; border-radius: 8px; background: var(--gave); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }
:root[data-theme="dark"] .btn-primary { color: #10131C; }

/* ───────── Forms ───────── */
.form { display: grid; gap: 14px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 560px) { .form .two, .form .three { grid-template-columns: 1fr; } }
.field { display: grid; gap: 5px; }
.field > span { font-size: .86rem; font-weight: 600; color: var(--ink-soft); }
.field .hint { font-size: .8rem; color: var(--muted); font-weight: 400; }
input[type=text], input[type=tel], input[type=number], input[type=email], input[type=date], input[type=month], input[type=search], input[type=password], input:not([type]), select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--rule); border-radius: var(--r-m); background: var(--sheet); min-height: 42px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
input.big { font: 700 2rem var(--f-num); padding: 8px 12px; letter-spacing: -.01em; }
.money-in { position: relative; }
.money-in::before { content: "₹"; position: absolute; left: 12px; top: 50%; translate: 0 -50%; font: 600 1rem var(--f-num); color: var(--muted); }
.money-in input { padding-left: 28px; }
.money-in.big::before { font-size: 1.6rem; }
.money-in.big input { padding-left: 34px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--ink); flex: none; }
.check .t { font-weight: 600; }
.check .d { font-size: .84rem; color: var(--muted); }

.seg { display: inline-flex; background: var(--rule-soft); padding: 3px; border-radius: 10px; gap: 2px; flex-wrap: wrap; }
.seg button, .seg label { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-weight: 600; cursor: pointer; color: var(--muted); font-size: .9rem; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg [aria-pressed="true"], .seg label:has(input:checked) { background: var(--sheet); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--rule); border-radius: 999px; padding: 4px 11px; font-size: .84rem; background: var(--sheet); cursor: pointer; font-weight: 600; color: var(--ink-soft); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--sheet); border-color: var(--ink); }
.chip .sw { width: 8px; height: 8px; border-radius: 50%; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type=search] { max-width: 280px; }
.filters select, .filters input[type=date], .filters input[type=month] { width: auto; min-height: 38px; padding: 7px 10px; }

/* ───────── Surfaces ───────── */
.sheet { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-l); }
.pad { padding: 18px 20px; }
.section { margin-top: 26px; }
.sh { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

/* Ruled list rows */
.rows { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-l); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--rule-soft); text-decoration: none; color: inherit; background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; cursor: pointer; }
.row:first-child { border-top: 0; }
a.row:hover, button.row:hover { background: color-mix(in srgb, var(--ink) 4%, var(--sheet)); }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .end { text-align: right; flex: none; }
.row .end .amt { font-size: 1.05rem; font-weight: 700; }
.row .end .lbl { font-size: .74rem; color: var(--muted); }
.av { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font: 700 15px var(--f-num); flex: none; background: var(--rule-soft); color: var(--ink); }
.av.sup { border-radius: 50%; }
.rows .more { padding: 12px; text-align: center; border-top: 1px solid var(--rule-soft); }

/* Summary strip: two halves of one ledger line */
.strip { display: grid; grid-template-columns: 1fr 1fr; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-l); overflow: hidden; }
.strip > div { padding: 16px 20px; }
.strip > div + div { border-left: 1px solid var(--rule); }
.strip .k { font-size: .85rem; color: var(--muted); font-weight: 600; }
.strip .v { font: 700 1.7rem var(--f-num); font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; }
.strip .x { font-size: .8rem; color: var(--muted); }
.strip.three { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 560px) { .strip .v { font-size: 1.3rem; } .strip > div { padding: 12px 14px; } .strip.three { grid-template-columns: 1fr 1fr; } .strip.three > div:nth-child(3) { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--rule); } }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-l); overflow: hidden; }
.kv > div { padding: 14px 16px; border-right: 1px solid var(--rule-soft); border-bottom: 1px solid var(--rule-soft); }
.kv .k { font-size: .8rem; color: var(--muted); font-weight: 600; }
.kv .v { font: 700 1.2rem var(--f-num); font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: .74rem; font-weight: 700; background: var(--rule-soft); color: var(--ink-soft); white-space: nowrap; }
.badge.gave { background: var(--gave-bg); color: var(--gave); }
.badge.got { background: var(--got-bg); color: var(--got); }
.badge.due { background: var(--haldi-bg); color: var(--haldi); }
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: .74rem; font-weight: 600; color: var(--muted); }
.tag .sw { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }

.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-m); background: var(--haldi-bg); color: var(--text); border: 1px solid color-mix(in srgb, var(--haldi-fill) 40%, transparent); }
.notice.info { background: color-mix(in srgb, var(--ink) 7%, var(--sheet)); border-color: var(--rule); }
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 2px; color: var(--haldi); }
.notice .grow { flex: 1; }

/* Tables (reports, invoices) */
.tbl-wrap { overflow-x: auto; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-l); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-weight: 700; color: var(--ink-soft); padding: 10px 12px; border-bottom: 1px solid var(--rule); background: color-mix(in srgb, var(--ink) 4%, var(--sheet)); white-space: nowrap; position: sticky; top: 0; }
.tbl td { padding: 9px 12px; border-top: 1px solid var(--rule-soft); vertical-align: top; }
.tbl td.n, .tbl th.n { text-align: right; font-family: var(--f-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tr.bold td { font-weight: 700; background: color-mix(in srgb, var(--ink) 3%, var(--sheet)); }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: color-mix(in srgb, var(--ink) 4%, var(--sheet)); }

/* ───────── The ledger page (signature element) ───────── */
.ledger-head { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: end; margin-bottom: 16px; }
.ledger-head .who { display: flex; align-items: center; gap: 14px; }
.ledger-head .who .av { width: 52px; height: 52px; font-size: 20px; border-radius: 14px; }
.ledger-head .bal { text-align: right; }
.ledger-head .bal .v { font: 800 2.4rem var(--f-num); font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1; }
.ledger-head .bal .k { font-size: .85rem; font-weight: 700; margin-bottom: 4px; }
@media (max-width: 600px) { .ledger-head { grid-template-columns: 1fr; } .ledger-head .bal { text-align: left; } .ledger-head .bal .v { font-size: 2rem; } }

.bahi {
  --mcol: 92px;
  background:
    linear-gradient(to right, transparent calc(var(--mcol) - 4px), var(--margin-red) calc(var(--mcol) - 4px), var(--margin-red) calc(var(--mcol) - 3px), transparent calc(var(--mcol) - 3px), transparent calc(var(--mcol) - 1px), var(--margin-red) calc(var(--mcol) - 1px), var(--margin-red) var(--mcol), transparent var(--mcol)),
    var(--sheet);
  border: 1px solid var(--rule); border-radius: var(--r-l); overflow: hidden;
}
.bahi .bh, .bahi .be { display: grid; grid-template-columns: var(--mcol) 1fr 130px 130px 130px; align-items: center; }
.bahi .bh { font-size: .8rem; font-weight: 700; color: var(--muted); border-bottom: 2px solid var(--rule); background: color-mix(in srgb, var(--paper) 50%, transparent); }
.bahi .bh > div, .bahi .be > div { padding: 10px 12px; }
.bahi .bh .c-gave { color: var(--gave); }
.bahi .bh .c-got { color: var(--got); }
.bahi .be { border-top: 1px solid var(--rule-soft); cursor: pointer; background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; padding: 0; }
.bahi .be:hover { background: color-mix(in srgb, var(--ink) 3%, transparent); }
.bahi .be .d { font-size: .82rem; color: var(--muted); line-height: 1.25; }
.bahi .be .d b { display: block; color: var(--text); font: 700 .95rem var(--f-num); }
.bahi .be .note .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bahi .be .note .s { font-size: .78rem; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.bahi .be .c-gave, .bahi .be .c-got, .bahi .be .c-bal { text-align: right; font-family: var(--f-num); font-variant-numeric: tabular-nums; font-weight: 700; }
.bahi .be .c-gave { color: var(--gave); background: color-mix(in srgb, var(--gave-bg) 55%, transparent); align-self: stretch; display: flex; align-items: center; justify-content: flex-end; }
.bahi .be .c-got { color: var(--got); background: color-mix(in srgb, var(--got-bg) 55%, transparent); align-self: stretch; display: flex; align-items: center; justify-content: flex-end; }
.bahi .be .c-bal { font-weight: 600; font-size: .9rem; color: var(--muted); }
.bahi .be.pending { opacity: .65; }
.bahi .be.deleted .note .t, .bahi .be.deleted .c-gave, .bahi .be.deleted .c-got { text-decoration: line-through; }
.bahi .bf { display: grid; grid-template-columns: var(--mcol) 1fr 130px 130px 130px; border-top: 2px solid var(--rule); font-weight: 700; }
.bahi .bf > div { padding: 12px; text-align: right; font-family: var(--f-num); font-variant-numeric: tabular-nums; }
.bahi .bf > div:nth-child(2) { text-align: left; font-family: var(--f-ui); color: var(--muted); }
@media (max-width: 720px) {
  .bahi { --mcol: 64px; }
  .bahi .bh, .bahi .be, .bahi .bf { grid-template-columns: var(--mcol) 1fr 92px 92px; }
  .bahi .c-bal { display: none !important; }
  .bahi .bh > div, .bahi .be > div, .bahi .bf > div { padding: 9px 8px; }
  .bahi .be .note .t { white-space: normal; }
}

.ledger-actions {
  position: sticky; bottom: 0; z-index: 15; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 0;
  background: linear-gradient(to top, var(--paper) 70%, transparent);
}
.ledger-actions .btn { min-height: 52px; font-size: 1.05rem; border-radius: 14px; }
@media (max-width: 900px) { .ledger-actions { bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding: 10px 0; } }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
@media (max-width: 640px) { .toolbar { flex-wrap: nowrap; overflow-x: auto; margin-left: -16px; margin-right: -16px; padding: 0 16px 4px; scrollbar-width: none; } .toolbar .btn { flex: none; } }

/* ───────── Overlays ───────── */
.scrim { position: fixed; inset: 0; background: rgba(15, 20, 40, .45); z-index: 100; display: grid; place-items: center; padding: 20px; animation: fade .15s ease-out; }
.dialog {
  background: var(--sheet); border-radius: var(--r-l); width: min(560px, 100%); max-height: calc(100vh - 40px);
  display: flex; flex-direction: column; box-shadow: var(--shadow-lift); animation: rise .18s ease-out;
}
.dialog.wide { width: min(880px, 100%); }
.dialog .dh { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 6px; gap: 10px; }
.dialog .db { padding: 10px 20px 18px; overflow-y: auto; }
.dialog .df { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px; border-top: 1px solid var(--rule-soft); flex-wrap: wrap; }
.dialog .df .left { margin-right: auto; }
.dialog.tone-gave .dh h2 { color: var(--gave); }
.dialog.tone-got .dh h2 { color: var(--got); }
@media (max-width: 640px) {
  .scrim { place-items: end center; padding: 0; }
  .dialog, .dialog.wide { width: 100%; border-radius: 20px 20px 0 0; max-height: 92vh; animation: up .2s ease-out; padding-bottom: env(safe-area-inset-bottom); }
  .dialog .dh::before { content: ""; position: absolute; left: 50%; translate: -50% 0; top: 8px; width: 40px; height: 4px; border-radius: 2px; background: var(--rule); }
  .dialog .dh { position: relative; padding-top: 22px; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes up { from { transform: translateY(100%); } }

#toasts { position: fixed; z-index: 200; left: 50%; translate: -50% 0; bottom: 24px; display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
@media (max-width: 900px) { #toasts { bottom: calc(var(--tabs-h) + 18px); } }
.toast { pointer-events: auto; background: var(--text); color: var(--sheet); padding: 11px 14px; border-radius: 12px; box-shadow: var(--shadow-lift); display: flex; gap: 10px; align-items: center; animation: rise .2s ease-out; font-weight: 500; }
.toast.err { background: #C2362B; color: #fff; }
.toast.ok { background: #1F8A55; color: #fff; }
.toast .grow { flex: 1; }
.toast a, .toast button { color: inherit; font-weight: 700; background: none; border: 0; cursor: pointer; text-decoration: underline; }

.menu { position: absolute; z-index: 120; background: var(--sheet); border: 1px solid var(--rule); border-radius: 12px; box-shadow: var(--shadow-lift); padding: 6px; min-width: 210px; animation: fade .1s; }
.menu button, .menu a { display: flex; width: 100%; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; border: 0; background: none; text-align: left; cursor: pointer; text-decoration: none; color: var(--text); font-weight: 500; }
.menu button:hover, .menu a:hover { background: var(--rule-soft); }
.menu .sep { height: 1px; background: var(--rule-soft); margin: 4px 0; }
.menu .danger { color: var(--gave); }
.menu svg { width: 17px; height: 17px; color: var(--muted); }

/* ───────── Empty / loading ───────── */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }
.skel { background: linear-gradient(90deg, var(--rule-soft), var(--rule), var(--rule-soft)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; border-radius: 8px; height: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.loading { padding: 18px; display: grid; gap: 12px; }

/* ───────── Auth ───────── */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-art { background: var(--rail); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-art .brand { font: 800 1.6rem var(--f-num); display: flex; gap: 10px; align-items: center; }
.auth-art .brand img { width: 36px; }
.auth-art .page {
  background: #F9FAFD; color: #1B2033; border-radius: 14px; padding: 0; max-width: 430px; box-shadow: 0 30px 60px -20px rgba(0,0,0,.5); rotate: -2deg;
  --mcol: 70px;
  background-image: linear-gradient(to right, transparent 66px, #E7A39D 66px, #E7A39D 67px, transparent 67px, transparent 69px, #E7A39D 69px, #E7A39D 70px, transparent 70px);
}
.auth-art .page .l { display: grid; grid-template-columns: 70px 1fr 90px 90px; border-top: 1px solid #E3E7F1; font-size: .88rem; }
.auth-art .page .l:first-child { border-top: 0; font-weight: 700; color: #6B7391; font-size: .78rem; }
.auth-art .page .l > div { padding: 9px 10px; }
.auth-art .page .r { text-align: right; font-family: var(--f-num); font-weight: 700; }
.auth-art h1 { color: #fff; font-size: 2.4rem; max-width: 14ch; font-weight: 800; margin-bottom: 14px; }
.auth-art p { color: #C9D1F0; max-width: 40ch; }
.auth-form { display: grid; place-items: center; padding: 32px 20px; }
.auth-form .box { width: min(380px, 100%); }
.auth-form h2 { font-size: 1.6rem; margin-bottom: 6px; }
.otp { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.otp input { text-align: center; font: 700 1.4rem var(--f-num); padding: 10px 0; }
@media (max-width: 900px) { .auth { grid-template-columns: 1fr; } .auth-art { padding: 28px 20px; gap: 22px; } .auth-art h1 { font-size: 1.7rem; } .auth-art .page { display: none; } }

.lock { min-height: 100vh; display: grid; place-items: center; background: var(--rail); color: #fff; padding: 20px; }
.lock .box { text-align: center; width: min(320px, 100%); }
.lock h2 { color: #fff; margin: 14px 0 18px; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin-bottom: 24px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #8FA0D8; }
.pin-dots span.on { background: #fff; border-color: #fff; }
.pad-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pad-keys button { height: 62px; border-radius: 16px; border: 0; background: rgba(255,255,255,.08); color: #fff; font: 600 1.4rem var(--f-num); cursor: pointer; }
.pad-keys button:hover { background: rgba(255,255,255,.16); }

/* ───────── Charts ───────── */
.chart { width: 100%; height: 220px; display: block; }
.chart .gl { stroke: var(--rule-soft); }
.chart .bar-got { fill: var(--got); }
.chart .bar-gave { fill: var(--gave); opacity: .85; }
.chart .bar-sale { fill: var(--ink); }
.chart .bar-exp { fill: var(--haldi-fill); }
.chart text { fill: var(--muted); font: 11px var(--f-ui); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* Invoice editor */
.lines .line { display: grid; grid-template-columns: 1fr 80px 120px 80px 120px 36px; gap: 8px; align-items: start; padding: 8px 0; border-top: 1px solid var(--rule-soft); }
.lines .line:first-child { border-top: 0; }
.lines .lh { display: grid; grid-template-columns: 1fr 80px 120px 80px 120px 36px; gap: 8px; font-size: .78rem; font-weight: 700; color: var(--muted); padding-bottom: 4px; }
.lines .line .amt { padding-top: 10px; text-align: right; font-weight: 700; }
@media (max-width: 720px) {
  .lines .lh { display: none; }
  .lines .line { grid-template-columns: 1fr 1fr 1fr; }
  .lines .line > :first-child { grid-column: 1 / -1; }
  .lines .line .amt { text-align: left; }
}
.totals { display: grid; gap: 6px; max-width: 340px; margin-left: auto; }
.totals > div { display: flex; justify-content: space-between; gap: 12px; }
.totals .grand { border-top: 2px solid var(--ink); padding-top: 8px; font: 800 1.3rem var(--f-num); color: var(--ink); }

/* Attendance */
.att { display: flex; gap: 4px; flex-wrap: wrap; }
.att button { border: 1px solid var(--rule); background: var(--sheet); border-radius: 8px; padding: 5px 9px; font-weight: 700; font-size: .78rem; cursor: pointer; color: var(--muted); min-width: 38px; }
.att button[aria-pressed="true"].P { background: var(--got); color: #fff; border-color: var(--got); }
.att button[aria-pressed="true"].A { background: var(--gave); color: #fff; border-color: var(--gave); }
.att button[aria-pressed="true"].H { background: var(--haldi-fill); color: #fff; border-color: var(--haldi-fill); }
.att button[aria-pressed="true"].L, .att button[aria-pressed="true"].PL, .att button[aria-pressed="true"].HO, .att button[aria-pressed="true"].WO { background: var(--ink); color: var(--sheet); border-color: var(--ink); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal div { aspect-ratio: 1; border-radius: 8px; display: grid; place-items: center; font-size: .8rem; font-weight: 700; background: var(--rule-soft); color: var(--muted); }
.cal .P { background: var(--got-bg); color: var(--got); }
.cal .A { background: var(--gave-bg); color: var(--gave); }
.cal .H { background: var(--haldi-bg); color: var(--haldi); }
.cal .L, .cal .PL, .cal .HO, .cal .WO { background: color-mix(in srgb, var(--ink) 12%, var(--sheet)); color: var(--ink); }
.cal .x { background: none; }

/* Settings layout */
.set-grid { display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: start; }
.set-nav { display: grid; gap: 2px; position: sticky; top: 80px; }
.set-nav a { padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--ink-soft); font-weight: 600; }
.set-nav a[aria-current="page"] { background: var(--sheet); color: var(--ink); box-shadow: inset 3px 0 0 var(--ink); }
@media (max-width: 900px) { .set-grid { grid-template-columns: 1fr; } .set-nav { position: static; display: flex; overflow-x: auto; gap: 4px; padding-bottom: 4px; } .set-nav a { white-space: nowrap; } }

.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rule); margin-bottom: 16px; overflow-x: auto; }
.subtabs a, .subtabs button { padding: 9px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border: 0; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap; }
.subtabs [aria-current="page"], .subtabs [aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }

.pill-plan { display: inline-flex; gap: 6px; align-items: center; font-size: .74rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--haldi-fill); color: #2B1E00; }

.calc { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.calc button { height: 40px; border-radius: 10px; border: 1px solid var(--rule); background: var(--paper); font: 600 1rem var(--f-num); cursor: pointer; }
.calc button.op { color: var(--ink); background: var(--rule-soft); }

.dropzone { border: 2px dashed var(--rule); border-radius: var(--r-m); padding: 16px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone:hover { border-color: var(--ink-soft); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.thumbs a { width: 64px; height: 64px; border-radius: 8px; overflow: hidden; border: 1px solid var(--rule); display: grid; place-items: center; font-size: .7rem; text-decoration: none; background: var(--paper); }
.thumbs img { width: 100%; height: 100%; object-fit: cover; }

.timeline { display: grid; gap: 0; }
.timeline .ti { display: grid; grid-template-columns: 14px 1fr; gap: 12px; padding-bottom: 14px; position: relative; }
.timeline .ti::before { content: ""; position: absolute; left: 6px; top: 16px; bottom: 0; width: 2px; background: var(--rule); }
.timeline .ti:last-child::before { display: none; }
.timeline .ti .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--ink); margin-top: 3px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media print {
  .rail, .topbar, .tabs, .ledger-actions, .toolbar, .ph .acts { display: none !important; }
  .frame { display: block; }
  .view { padding: 0; }
}

/* Grid children must be allowed to shrink below their content width (tables scroll inside instead) */
.grid2 > *, .grid3 > *, .set-grid > *, .form > *, .form .two > *, .form .three > *, .main, .view { min-width: 0; }
@media (max-width: 900px) { .set-grid, .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); } }

/* ───────── Setup wizard ───────── */
.setup .auth-art { justify-content: flex-start; gap: 36px; }
.setup-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.setup-steps li { display: flex; gap: 14px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; color: #AEB7D6; }
.setup-steps li .n { width: 28px; height: 28px; border-radius: 50%; border: 2px solid #5A6699; display: grid; place-items: center; font: 700 .85rem var(--f-num); flex: none; }
.setup-steps li .n svg { width: 15px; height: 15px; }
.setup-steps li .t { font-weight: 700; color: #fff; }
.setup-steps li .d { font-size: .82rem; opacity: .8; }
.setup-steps li.current { background: rgba(255,255,255,.1); }
.setup-steps li.current .n { border-color: #fff; background: #fff; color: #1E2A5A; }
.setup-steps li.done .n { border-color: #4FD08C; background: #4FD08C; color: #10131C; }
.setup-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.setup-progress { flex: 1; max-width: 260px; }
.setup-progress .bar { height: 6px; border-radius: 3px; background: var(--rule); margin-top: 6px; overflow: hidden; }
.setup-progress .bar i { display: block; height: 100%; background: var(--ink); border-radius: 3px; transition: width .3s ease; }
.setup-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 6px; }
.setup-actions .btn-primary { min-width: 180px; }
@media (max-width: 900px) {
  .setup .auth-art { padding: 20px; gap: 10px; }
  .setup .auth-art .setup-steps, .setup .auth-art p { display: none; }
  .setup .auth-art h1 { font-size: 1.4rem; }
  .setup .auth-form { place-items: start center; }
  .setup-actions .btn-primary { min-width: 0; flex: 1; }
}
