:root {
  color-scheme: light;
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fb; --border: #e3e6eb; --border-strong: #cfd4dc;
  --text: #111418; --text-2: #4b5260; --muted: #7a8190;
  --primary: #1d4ed8; --primary-2: #1e40af; --primary-soft: #e8eefc; --on-primary: #fff;
  --pos: #12804a; --pos-soft: #e5f5ec; --neg: #c62828; --neg-soft: #fdecec; --warn: #a15c00; --warn-soft: #fff4e0;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948; --s-other: #9aa0a6;
  --grid: #eceef1; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 14px; --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1115; --surface: #181b21; --surface-2: #1f232b; --border: #2a2f39; --border-strong: #3a404c;
    --text: #eef0f3; --text-2: #b9bfca; --muted: #8b92a0;
    --primary: #5b8def; --primary-2: #7aa3f5; --primary-soft: #1d2a45; --on-primary: #0b1020;
    --pos: #4ccb86; --pos-soft: #13301f; --neg: #ff7b7b; --neg-soft: #3a1717; --warn: #f0b04a; --warn-soft: #3a2a10;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767; --s-other: #6b7280;
    --grid: #262a33; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115; --surface: #181b21; --surface-2: #1f232b; --border: #2a2f39; --border-strong: #3a404c;
  --text: #eef0f3; --text-2: #b9bfca; --muted: #8b92a0;
  --primary: #5b8def; --primary-2: #7aa3f5; --primary-soft: #1d2a45; --on-primary: #0b1020;
  --pos: #4ccb86; --pos-soft: #13301f; --neg: #ff7b7b; --neg-soft: #3a1717; --warn: #f0b04a; --warn-soft: #3a2a10;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767; --s-other: #6b7280;
  --grid: #262a33; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; -webkit-text-size-adjust: 100%; }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: .98rem; }
.boot { padding: 40vh 0 0; text-align: center; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .tiny { font-size: .75rem; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }
.right { text-align: right; } .center { text-align: center; } .nowrap { white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; } .wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; } .between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- layout */
.shell { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); display: flex; align-items: center; gap: 10px; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand img { width: 26px; height: 26px; }
.main { padding: 16px; padding-bottom: calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); max-width: 1280px; margin: 0 auto; }
.sidenav { display: none; }
.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(5, 1fr); }
.bottomnav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: .72rem; }
.bottomnav a .ico { font-size: 1.25rem; line-height: 1; }
.bottomnav a.active { color: var(--primary); font-weight: 600; }
.bottomnav a.add .ico { width: 48px; height: 48px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-size: 1.7rem; margin-top: -22px; box-shadow: 0 4px 12px rgba(29,78,216,.35); }
@media (min-width: 960px) {
  .shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); }
  .topbar { grid-column: 1 / -1; }
  .sidenav { display: block; position: sticky; top: 57px; height: calc(100vh - 57px); overflow: auto; border-right: 1px solid var(--border); background: var(--surface); padding: 12px 10px; }
  .sidenav a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 10px; color: var(--text-2); }
  .sidenav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
  .sidenav a:hover { background: var(--surface-2); }
  .sidenav .sep { height: 1px; background: var(--border); margin: 10px 4px; }
  .bottomnav { display: none; }
  .main { padding: 24px; padding-bottom: 40px; width: 100%; min-width: 0; }
}

/* ---------- surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.tight { padding: 12px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-h h2, .card-h h3 { min-width: 0; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi .label { color: var(--text-2); font-size: .8rem; display: flex; gap: 6px; align-items: center; }
.kpi .value { font-size: 1.25rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .sub { font-size: .76rem; color: var(--muted); margin-top: 2px; }
.kpi.clickable { cursor: pointer; } .kpi.clickable:hover { border-color: var(--primary); }
.hero { background: linear-gradient(135deg, #1d4ed8, #3b2fb0); color: #fff; border: 0; }
.hero .label, .hero .sub { color: rgba(255,255,255,.82); }
.page-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

/* ---------- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: 10px; padding: 8px 14px; cursor: pointer; min-height: 40px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--neg); border-color: var(--neg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; min-height: 32px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn.lg { min-height: 52px; font-size: 1.05rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.iconbtn { border: 0; background: transparent; cursor: pointer; padding: 6px 8px; border-radius: 8px; color: var(--text-2); min-width: 36px; min-height: 36px; }
.iconbtn:hover { background: var(--surface-2); }
label.f { display: block; }
label.f > span { display: block; font-size: .8rem; color: var(--text-2); margin-bottom: 4px; font-weight: 500; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 10px; padding: 9px 11px; min-height: 42px; }
textarea.input { min-height: 70px; resize: vertical; }
.input:focus, .btn:focus-visible, .chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 18px; height: 18px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 7px 13px; cursor: pointer; white-space: nowrap; font-size: .9rem; min-height: 38px; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 3px; gap: 2px; max-width: 100%; overflow-x: auto; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.pos { background: var(--pos-soft); color: var(--pos); border-color: transparent; }
.badge.neg { background: var(--neg-soft); color: var(--neg); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.info { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: .88rem; }
.notice.info { background: var(--primary-soft); color: var(--primary); }
.notice.err { background: var(--neg-soft); color: var(--neg); }

/* ---------- lists & tables */
.list { list-style: none; margin: 0; padding: 0; }
.li { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--border); cursor: pointer; min-width: 0; }
.li:last-child { border-bottom: 0; }
.li:hover { background: var(--surface-2); }
.li .avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); font-size: 1.2rem; flex: none; }
.li .main-t { font-weight: 600; } .li .sub-t { font-size: .8rem; color: var(--muted); }
.li .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.daygroup { margin-top: 14px; }
.daygroup .dh { display: flex; justify-content: space-between; font-size: .8rem; color: var(--text-2); padding: 6px 4px; border-bottom: 1px solid var(--border); font-weight: 600; }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
table.t { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.t th { text-align: left; font-weight: 600; color: var(--text-2); font-size: .78rem; padding: 8px; border-bottom: 1px solid var(--border-strong); white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
table.t td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: var(--surface-2); }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t .input { min-height: 34px; padding: 5px 8px; font-size: .85rem; }
tr.dup td { opacity: .55; } tr.possible td { background: var(--warn-soft); }

/* ---------- modal & toast */
.overlay { position: fixed; inset: 0; background: rgba(10,12,16,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 720px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.modal.wide { max-width: 1000px; }
.modal-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 8px; }
.modal-f { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
@media (min-width: 720px) { .overlay { align-items: center; } .modal { border-radius: 18px; padding: 22px; } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); background: #111827; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 60; font-size: .92rem; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: calc(100vw - 32px); }
.toast.err { background: #b91c1c; }
@media (min-width: 960px) { .toast { bottom: 24px; } }

/* ---------- quick add */
.qa { max-width: 640px; margin: 0 auto; }
.amount-in { font-size: 2.2rem; font-weight: 700; border: 0; border-bottom: 2px solid var(--border-strong); background: transparent; width: 100%; padding: 6px 0 6px 34px; font-variant-numeric: tabular-nums; border-radius: 0; }
.amount-in:focus { outline: none; border-color: var(--primary); }
.amount-wrap { position: relative; }
.amount-wrap::before { content: "₹"; position: absolute; left: 4px; top: 50%; transform: translateY(-50%); font-size: 1.6rem; color: var(--muted); }
.catgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.cat { border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 10px 4px; cursor: pointer; text-align: center; font-size: .76rem; line-height: 1.2; min-height: 74px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; overflow-wrap: anywhere; }
.cat .e { font-size: 1.5rem; }
.cat.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; box-shadow: inset 0 0 0 1px var(--primary); }
.section-t { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; margin: 16px 0 8px; }
.sticky-save { position: sticky; bottom: calc(var(--nav-h) + 8px + env(safe-area-inset-bottom)); margin-top: 16px; z-index: 5; }
@media (min-width: 960px) { .sticky-save { bottom: 12px; } }

/* ---------- charts */
.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 150px; } .chart-box.lg { height: 320px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; color: var(--text-2); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 6px 0; cursor: pointer; }
.bar-row .track { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 4px; }
.delta { font-size: .8rem; font-weight: 600; white-space: nowrap; }
.avatar-img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; }
.member-switch { max-width: 46vw; }
.login { max-width: 400px; margin: 10vh auto; padding: 16px; }
details.more > summary { cursor: pointer; color: var(--primary); font-weight: 600; padding: 8px 0; list-style: none; }
details.more > summary::-webkit-details-marker { display: none; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.progress { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); border-radius: 4px; }
.progress.over > div { background: var(--neg); }
table.t select.input { min-width: 130px; }

/* ---------- Easy mode: larger text and touch targets for older / non-technical users */
body.easy { font-size: 18px; }
body.easy h1 { font-size: 1.55rem; }
body.easy .chip { min-height: 52px; font-size: 1.05rem; padding: 10px 18px; }
body.easy .catgrid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
body.easy .cat { min-height: 100px; font-size: 1rem; border-width: 2px; }
body.easy .cat .e { font-size: 2.3rem; }
body.easy .cat.on { box-shadow: inset 0 0 0 2px var(--primary); }
body.easy .btn { min-height: 52px; font-size: 1.05rem; }
body.easy .btn.lg { min-height: 64px; font-size: 1.25rem; }
body.easy .input { min-height: 52px; font-size: 1.1rem; }
body.easy .amount-in { font-size: 2.8rem; }
body.easy .section-t { font-size: 1.1rem; text-transform: none; letter-spacing: 0; color: var(--text); margin: 22px 0 10px; }
body.easy .li { padding: 14px 4px; }
body.easy .li .main-t { font-size: 1.08rem; }
body.easy .li .avatar { width: 46px; height: 46px; font-size: 1.5rem; }
body.easy { --nav-h: 76px; }
body.easy .bottomnav a { font-size: .9rem; }
body.easy .bottomnav a .ico { font-size: 1.6rem; }
body.easy .toast { font-size: 1.1rem; padding: 14px 20px; }
.done-screen { text-align: center; padding: 40px 16px; }
.done-screen .big { font-size: 5rem; line-height: 1; }

/* ---------- Monthly summary "paper" (always light, so the PDF is printer-friendly) */
.paper { background: #fff; color: #111; border: 1px solid #ddd; border-radius: 12px; padding: 20px; font-size: 15px; }
.paper-h { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #1d4ed8; padding-bottom: 10px; margin-bottom: 14px; }
.paper-title { font-size: 1.3rem; font-weight: 700; color: #1d4ed8; }
.paper-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 16px; }
.paper-kpis > div { background: #f3f6fd; border-radius: 10px; padding: 10px 12px; }
.paper-kpis .k { font-size: .82rem; color: #444; } .paper-kpis .v { font-size: 1.3rem; font-weight: 700; }
.paper-sec { font-weight: 700; font-size: 1.05rem; margin: 18px 0 8px; border-bottom: 1px solid #ddd; padding-bottom: 4px; }
.paper-group { margin-bottom: 12px; }
.paper-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.paper-row.b { font-weight: 700; font-size: 1.05rem; }
.paper-row.sub { padding-left: 22px; color: #333; }
.paper-row small, .paper-table small { color: #666; }
.paper-bar { height: 8px; background: #eef1f5; border-radius: 4px; overflow: hidden; margin: 2px 0 4px; }
.paper-bar > div { height: 100%; border-radius: 4px; }
.paper-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.paper-table th { text-align: left; border-bottom: 1px solid #bbb; padding: 6px 4px; }
.paper-table td { border-bottom: 1px solid #eee; padding: 6px 4px; vertical-align: top; }
.paper-foot { margin-top: 16px; font-size: .78rem; color: #777; text-align: center; }
.paper-logo { width: 40px; height: 40px; border-radius: 10px; background: #1d4ed8; color: #fff; font-weight: 700; font-size: 1.4rem; display: flex; align-items: center; justify-content: center; flex: none; }
.last4 { font-variant-numeric: tabular-nums; letter-spacing: .04em; color: var(--text); }
