:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --ink: #1d2420;
  --muted: #5f6b64;
  --line: #e2ddd1;
  --brand: #0f5c4a;
  --brand-ink: #ffffff;
  --brand-soft: #e3efe9;
  --gold: #b8860b;
  --gold-soft: #fbf1d6;
  --in: #1f7a46;      /* received / they owe me */
  --out: #b4432d;     /* given / I owe */
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Malayalam", sans-serif;
  --ml: "Noto Sans Malayalam", "Manjari", "Kartika", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --surface: #1b211e; --ink: #e9ede9; --muted: #9aa69f; --line: #2c3530;
    --brand: #3fb08f; --brand-ink: #08130f; --brand-soft: #1d3029; --gold: #e2b54b; --gold-soft: #2e2716;
    --in: #57c486; --out: #ef8a74;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.45; }
body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
.ml { font-family: var(--ml); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: .75rem; }
.grow { flex: 1 1 auto; min-width: 0; }
[hidden] { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center;
  padding: .65rem 1rem; background: var(--brand); color: var(--brand-ink); }
.brand { color: inherit; text-decoration: none; display: flex; flex-direction: column; line-height: 1.1; }
.brand-ml { font-family: var(--ml); font-weight: 700; font-size: 1.15rem; }
.brand-en { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; opacity: .85; }
.topbar-link { color: inherit; font-size: .9rem; }

main { max-width: 760px; margin: 0 auto; padding: 1rem; }
.loading { padding: 3rem 0; text-align: center; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card + .card { margin-top: .9rem; }
.card h2 { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
@media (min-width: 620px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .85rem; }
.stat .label { font-size: .78rem; color: var(--muted); }
.stat .value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.in .value { color: var(--in); } .stat.out .value { color: var(--out); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: .7rem 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.item-link { display: flex; justify-content: space-between; gap: .75rem; color: inherit; text-decoration: none; align-items: center; }
.amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.amt.in { color: var(--in); } .amt.out { color: var(--out); }
.voided { opacity: .5; text-decoration: line-through; }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .12rem .5rem; border-radius: 99px;
  background: var(--brand-soft); color: var(--brand); text-transform: uppercase; letter-spacing: .04em; }
.badge.draft { background: var(--gold-soft); color: var(--gold); }
.badge.closed { background: var(--line); color: var(--muted); }
.badge.mode { text-transform: none; letter-spacing: 0; font-weight: 500; }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.field { margin-bottom: .7rem; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 .7rem; }
@media (min-width: 520px) { .grid2 { grid-template-columns: 1fr 1fr; } }
input.big { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-weight: 600;
  border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); border-radius: 10px;
  padding: .6rem 1rem; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn.secondary { background: transparent; color: var(--brand); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.danger { background: transparent; border-color: var(--out); color: var(--out); }
.btn.small { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.seg { display: flex; flex-wrap: wrap; gap: .4rem; }
.seg button { font: inherit; padding: .45rem .8rem; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.seg button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.picker { border: 1px solid var(--line); border-radius: 10px; margin-top: .3rem; overflow: hidden; }
.picker button { display: block; width: 100%; text-align: left; font: inherit; color: var(--ink); background: var(--surface);
  border: 0; border-top: 1px solid var(--line); padding: .55rem .7rem; cursor: pointer; }
.picker button:first-child { border-top: 0; }
.picker button:hover, .picker button:focus { background: var(--brand-soft); }
.chosen { display: flex; justify-content: space-between; align-items: center; background: var(--brand-soft); border-radius: 10px; padding: .55rem .7rem; }

.invite { text-align: center; background: linear-gradient(180deg, var(--gold-soft), var(--surface) 55%); border: 1px solid var(--line);
  border-radius: 20px; padding: 1.5rem 1rem; box-shadow: var(--shadow); }
.invite .ml-title { font-family: var(--ml); font-size: 1.55rem; font-weight: 700; color: var(--brand); }
.invite .ornament { color: var(--gold); letter-spacing: .4em; }
.qr { display: inline-block; background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--line); }
.qr img, .qr svg { display: block; width: 220px; height: 220px; image-rendering: pixelated; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .4rem .35rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
td input, td select { padding: .35rem .4rem; min-width: 90px; }
.err { color: var(--out); }
.notice { background: var(--gold-soft); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem; font-size: .9rem; }

.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.bottomnav a { flex: 1; text-align: center; padding: .8rem 0; font-size: .82rem; font-weight: 600; color: var(--muted); text-decoration: none; }
.bottomnav a.on { color: var(--brand); box-shadow: inset 0 3px 0 var(--brand); }

.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; z-index: 30; max-width: 90vw; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.modal-card { background: var(--surface); width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 1rem; }
@media (min-width: 620px) { .modal { align-items: center; } .modal-card { border-radius: 18px; } }

.tabs { display: flex; gap: .3rem; margin-bottom: .8rem; border-bottom: 1px solid var(--line); }
.tabs button { font: inherit; background: none; border: 0; padding: .55rem .8rem; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; }
.tabs button.on { color: var(--brand); border-color: var(--brand); font-weight: 600; }
