:root {
  --bg: #f6f8f8;
  --surface: #ffffff;
  --text: #11201f;
  --muted: #5b6b6a;
  --line: #e2e8e7;
  --primary: #0f766e;
  --on-primary: #ffffff;
  --soft: #e6f3f1;
  --good: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --radius: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1514;
    --surface: #162120;
    --text: #e6efee;
    --muted: #9fb1af;
    --line: #26332f;
    --primary: #2dd4bf;
    --on-primary: #06201d;
    --soft: #133330;
    --good: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45; }
.app { max-width: 920px; margin: 0 auto; padding: 16px 16px 48px; }
/* Hindi second line (P3-8, as on the QR page). In buttons and pills it sits on the same line. */
.hi { display: block; color: var(--muted); font-size: 0.85em; font-weight: normal; }
button .hi, .btn .hi, .pill .hi { display: inline; margin-left: 6px; color: inherit; opacity: 0.85; }
.loading, .notice { color: var(--muted); text-align: center; padding: 48px 0; }

header.top { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; }
.mark { width: 44px; height: 44px; border-radius: 13px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-weight: 800; font-size: 20px; flex: none; }
.top h1 { font-size: 20px; margin: 0; line-height: 1.2; }
.top p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.top .spacer { flex: 1; }

button, .btn { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 12px; padding: 9px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }
button:hover, .btn:hover { border-color: var(--primary); }
button:focus-visible, .btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.btn.primary, button.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); font-weight: 600; }
button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.chips button { white-space: nowrap; border-radius: 999px; min-height: 40px; }
.toolbar { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: 4px 0 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; min-height: 40px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.total { display: flex; gap: 24px; flex-wrap: wrap; }
.total .big { font-size: 28px; font-weight: 800; }
.total .label { color: var(--muted); font-size: 13px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.tile .name { color: var(--muted); font-size: 14px; }
.tile .qty { font-size: 22px; font-weight: 800; }
.tile .amt { font-size: 13px; color: var(--muted); }

h2 { font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 22px 0 10px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { padding: 10px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--soft); }
tfoot td { font-weight: 700; border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

.invoice { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.invoice .no { font-weight: 700; }
.invoice .meta { color: var(--muted); font-size: 14px; }
.pill { display: inline-block; border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 600; }
.pill.due { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.pill.part { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.pill.paid { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

dialog { border: 0; border-radius: 20px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: 86vh; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet { padding: 18px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.sheet-head h3 { margin: 0; font-size: 18px; }
.entry { padding: 10px 0; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.entry .time { font-weight: 700; }
.entry .items { color: var(--muted); }

.error { text-align: center; padding: 56px 16px; }
.error h1 { font-size: 20px; }
.error p { color: var(--muted); }
.foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: 28px; }

/* Printable invoice */
.inv { font-size: 14px; }
.inv h3 { margin: 0 0 4px; }
.inv .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.inv table th, .inv table td { font-size: 13px; padding: 6px 8px; }
.inv .sum td { border: 0; padding: 3px 8px; }
.inv .grand td { font-weight: 800; font-size: 15px; border-top: 2px solid var(--text); }

@media (max-width: 520px) {
  .inv .two { grid-template-columns: 1fr; }
  .total .big { font-size: 24px; }
}

@media print {
  body { background: #fff; color: #000; }
  .app, dialog::backdrop, .no-print { display: none !important; }
  dialog { position: static; width: auto; max-height: none; box-shadow: none; }
  dialog[open] { display: block; }
}
.error .mark { margin: 0 auto 12px; }
/* The newest months are chips; anything older sits in the `.more` picker next to them, because a
   sideways-scrolling strip hid the older months and could leave the chosen one off-screen. Three
   chips plus the picker fit the narrowest phone, and wrap instead of scrolling if they ever don't.
   The browser's own select never matches a chip, so it is drawn as one: its arrow is removed and
   a chevron painted in, which also keeps the arrow the right colour when the picker is selected. */
.more {
  appearance: none;
  -webkit-appearance: none;
  height: 40px;
  padding: 0 30px 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  color: inherit;
  font: inherit;
  line-height: 38px;
  cursor: pointer;
}
/* An older month is showing: the picker carries the selection, so it looks like a chosen chip. */
.chips .more:not(:has(option[value=""]:checked)) {
  background-color: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
}
/* The list itself is the browser's, so its text needs a colour of its own, not the chip's. */
.more option { background: var(--surface); color: var(--text); }

/* ---- khata page only (the office portal does not use these) ---------------------------- */

/* The four-digit gate: one card, centred, nothing else on screen to distract. */
.gate { max-width: 22rem; margin: 10vh auto 0; text-align: center; }
.gate .mark { margin: 0 auto 12px; }
.gate h1 { margin: 0 0 2px; }
.gate label { display: block; margin: 18px 0 8px; font-weight: 600; }
.gate .label { color: var(--muted); margin: 0; }
.gate button { width: 100%; margin-top: 14px; }

/* Big and widely spaced: this is typed on a phone, often by someone who finds typing hard. */
.code {
  width: 100%;
  text-align: center;
  font-size: 30px;
  letter-spacing: 0.4em;
  /* The spacing pushes the text right; this pulls it back to centre. */
  text-indent: 0.4em;
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
}
.code:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Entry by entry: what was taken, what was paid. */
.list .row { display: flex; gap: 12px; align-items: baseline; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list .row:last-child { border-bottom: 0; }
.list .what { flex: 1; min-width: 0; }
.list .name { font-weight: 600; }
.list .meta { color: var(--muted); font-size: 13px; }
.list .amt { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.list .amt.took { color: var(--bad); }
.list .amt.paid { color: var(--good); }
