:root {
  --bg: #f4f6f5; --card: #ffffff; --ink: #14201d; --muted: #5d6b67; --line: #dfe5e2;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #e1f2ef;
  --warn: #b45309; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2; --good: #15803d; --good-soft: #dcfce7;
  --shadow: 0 1px 2px rgba(20, 32, 29, .06), 0 2px 8px rgba(20, 32, 29, .04);
  --nav-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1513; --card: #17211e; --ink: #e8efec; --muted: #9aaaa5; --line: #27342f;
    --brand: #2dd4bf; --brand-ink: #04211d; --brand-soft: #12332e;
    --warn: #fbbf24; --warn-soft: #3a2c0b; --bad: #f87171; --bad-soft: #3b1414; --good: #4ade80; --good-soft: #10301b;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Tamil", "Latha", sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
h1 { font-size: 1.35rem; margin: 0 0 .75rem; }
h2 { font-size: 1.05rem; margin: 0; }
h3 { font-size: .8rem; margin: 1.1rem 0 .4rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: .6rem; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: .75rem; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: var(--brand-ink);
  display: flex; align-items: center; gap: .5rem; padding: .6rem 1rem; padding-top: calc(.6rem + env(safe-area-inset-top));
}
.topbar .title { font-weight: 650; flex: 1; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar button { background: rgba(255,255,255,.18); color: inherit; border: 0; border-radius: 8px; padding: .4rem .7rem; min-height: 36px; cursor: pointer; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .topbar button { background: rgba(0,0,0,.2); } }

main { max-width: 1000px; margin: 0 auto; padding: 1rem; }

/* bottom navigation */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; min-height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; font-weight: 600;
}
.nav a svg { width: 24px; height: 24px; }
.nav a.on { color: var(--brand); }

/* cards and tiles */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1rem; box-shadow: var(--shadow); }
.card + .card { margin-top: .75rem; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: .8rem .9rem; box-shadow: var(--shadow); display: block; color: inherit; }
.tile .k { font-size: .78rem; color: var(--muted); }
.tile .v { font-size: 1.3rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .s { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.tile.warn .v { color: var(--warn); }
.tile.bad .v { color: var(--bad); }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: 1rem; }
.actions a, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; text-align: center; border: 0; cursor: pointer;
  background: var(--brand); color: var(--brand-ink); border-radius: 12px; padding: .7rem .8rem; min-height: 46px; font-weight: 650;
}
.actions a { flex-direction: column; font-size: .85rem; padding: .7rem .3rem; }
.btn.secondary { background: var(--brand-soft); color: var(--brand); }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { min-height: 36px; padding: .35rem .7rem; font-size: .88rem; border-radius: 9px; }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .55; cursor: wait; }
.icon-btn { background: none; border: 0; font-size: 1.6rem; line-height: 1; cursor: pointer; padding: .2rem .5rem; color: var(--muted); }

/* lists */
.list { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.li { display: flex; gap: .75rem; align-items: center; padding: .8rem 1rem; border-top: 1px solid var(--line); color: inherit; min-height: 56px; }
.li:first-child { border-top: 0; }
a.li:active, .li.tap:active { background: var(--brand-soft); }
.li .main { flex: 1; min-width: 0; }
.li .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.li .sub { font-size: .83rem; color: var(--muted); }
.li .amt { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.li .amt small { display: block; font-weight: 500; color: var(--muted); font-size: .76rem; }
.empty { padding: 1.5rem 1rem; text-align: center; color: var(--muted); }

.badge { display: inline-block; font-size: .72rem; font-weight: 650; padding: .1rem .5rem; border-radius: 99px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.good { background: var(--good-soft); color: var(--good); }
.pos { color: var(--bad); }  /* money owed to you is shown in the attention colour */
.neg { color: var(--good); }

/* forms */
label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 16px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
input[type="checkbox"] { width: 22px; min-height: 22px; }
.field + .field { margin-top: .7rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: .5rem 1rem; min-height: 44px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.searchbar { position: sticky; top: 52px; z-index: 5; background: var(--bg); padding: .4rem 0 .6rem; }

/* bill lines */
.line { border: 1px solid var(--line); border-radius: 12px; padding: .7rem; background: var(--card); margin-bottom: .6rem; }
.line .info { font-size: .8rem; margin-top: .3rem; }
.line .amt-out { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; padding-top: .55rem; }
.line .rm { float: right; }
.totals { background: var(--brand-soft); border-radius: 12px; padding: .8rem 1rem; }
.totals .tr { display: flex; justify-content: space-between; padding: 2px 0; font-variant-numeric: tabular-nums; }
.totals .tr.big { font-size: 1.25rem; font-weight: 750; border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .4rem; }
.savebar { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); background: var(--bg); padding: .6rem 0; z-index: 4; }

/* tables */
.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; font-variant-numeric: tabular-nums; }
th, td { padding: .5rem .7rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-size: .75rem; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; background: var(--bg); }
td.r, th.r { text-align: right; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; background: var(--bg); }

/* modal and toast */
.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 720px) { .modal-wrap { align-items: center; } }
.modal { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 0 1rem 1rem; }
@media (min-width: 720px) { .modal { border-radius: 18px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--card); padding: .8rem 0; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px); transform: translate(-50%, 20px); background: #14201d; color: #fff; padding: .7rem 1rem; border-radius: 12px; opacity: 0; transition: .25s; z-index: 60; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--bad); color: #fff; }

.notice { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: .6rem .8rem; font-size: .9rem; }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.login { max-width: 380px; margin: 12vh auto 0; padding: 1rem; }

/* printable bill */
.bill { background: #fff; color: #000; border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }
.bill h1 { text-align: center; margin: 0; letter-spacing: .03em; }
.bill .c { text-align: center; font-size: .85rem; }
.bill table { color: #000; }
.bill th { background: #f1f1f1; color: #000; }
/* the bill is always black on white, like the paper copy, in light or dark mode */
.bill .tablewrap { background: #fff; border-color: #ccc; border-radius: 6px; }
.bill td, .bill tfoot td { background: #fff; color: #000; border-color: #ddd; white-space: normal; padding: .35rem .45rem; }
.bill th { border-color: #ddd; white-space: normal; padding: .35rem .45rem; }
.bill table { font-size: .82rem; }
.bill .muted { color: #555; }
.bill .pos { color: #b91c1c; }
.bill .btot { margin: .5rem 0 0 auto; max-width: 16rem; font-variant-numeric: tabular-nums; }
.bill .btot > div { display: flex; justify-content: space-between; padding: 2px .45rem; }
.bill .btot .net { font-weight: 750; font-size: 1.1rem; border-top: 1px solid #000; margin-top: 3px; padding-top: 4px; }
@media (max-width: 520px) { .bill .hide-sm { display: none; } }
@media print {
  body { background: #fff; padding: 0; }
  .topbar, .nav, .no-print, .toast { display: none !important; }
  main { max-width: none; padding: 0; }
  .bill { border: 0; }
}
