:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #1d2522;
  --muted: #66716c;
  --line: #e4e0d6;
  --primary: #1f5f55;
  --primary-ink: #ffffff;
  --primary-soft: #e2efeb;
  --plus: #24744a;
  --plus-soft: #e3f2e8;
  --minus: #b4462f;
  --minus-soft: #f8e7e1;
  --warn-soft: #fff3d6;
  --radius: 16px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Roboto, system-ui, -apple-system, "Segoe UI", "Noto Sans", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }

.num { font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */

.screen {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
}

.screen.center {
  display: grid;
  place-items: center;
  padding: 24px;
}

.app-shell { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 24px); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  color: var(--primary-ink);
  padding: 12px 16px 14px;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand { font-weight: 700; font-size: 18px; letter-spacing: .2px; }

.who {
  font-size: 13px;
  opacity: .85;
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.month-switch {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, .12);
  border-radius: 12px;
}

.month-switch button {
  background: none;
  border: 0;
  color: inherit;
  width: 48px;
  height: 44px;
  font-size: 22px;
  cursor: pointer;
  border-radius: 12px;
}

.month-switch button:disabled { opacity: .3; }

.month-switch .label { font-weight: 600; }

main { padding: 16px; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin: 22px 4px 8px;
}

.section-title:first-child { margin-top: 4px; }

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.card + .card { margin-top: 12px; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat .k { font-size: 13px; color: var(--muted); }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 2px; }
.stat .s { font-size: 12px; color: var(--muted); }
.stat.big { grid-column: 1 / -1; }
.stat.big .v { font-size: 34px; }

.list { list-style: none; margin: 0; padding: 0; }

.list > li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  min-height: 56px;
}

.list > li:first-child { border-top: 0; padding-top: 0; }
.list > li:last-child { padding-bottom: 0; }

.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow-wrap: anywhere; }
.list .sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.list .amt { font-weight: 700; text-align: right; white-space: nowrap; }

.list button.row {
  all: unset;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  cursor: pointer;
}

.avatar {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: var(--primary-soft);
  color: var(--primary);
}

.avatar.off { background: #eceae4; color: var(--muted); }

.cat-dot {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.cat-Grocery { background: #3f7d3a; }
.cat-Room-Rent { background: #1f5f55; }
.cat-Electricity { background: #c18a12; }
.cat-Gas { background: #c0532f; }
.cat-Other { background: #6b6f7a; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.plus { background: var(--plus-soft); color: var(--plus); }
.pill.minus { background: var(--minus-soft); color: var(--minus); }
.pill.even { background: #eceae4; color: var(--muted); }

.settle {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.settle .arrow { color: var(--muted); }

.bar {
  height: 8px;
  border-radius: 99px;
  background: #eceae4;
  overflow: hidden;
  margin-top: 6px;
}

.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 20px 8px;
}

.note {
  background: var(--warn-soft);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Forms ---------- */

label.field { display: block; margin-bottom: 18px; }
label.field > span, .field-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

input[type="text"], input[type="number"], input[type="date"], input[type="month"], textarea, select {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px; /* prevents zoom on focus */
  outline: none;
}

input:focus, textarea:focus, select:focus { border-color: var(--primary); }

.amount-input {
  font-size: 28px !important;
  font-weight: 700;
  padding-left: 40px !important;
}

.amount-wrap { position: relative; }

.amount-wrap::before {
  content: "₹";
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 24px;
  font-weight: 700;
  color: var(--muted);
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }

.chip {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
}

.chip[aria-pressed="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  border-radius: 12px;
  border: 0;
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}

.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--primary); border: 1.5px solid var(--line); }
.btn.danger { background: var(--minus); }
.btn.ghost.danger { background: transparent; color: var(--minus); }
.btn.sm { min-height: 40px; padding: 8px 14px; font-size: 14px; }
.btn:disabled { opacity: .55; cursor: default; }

.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; }

/* ---------- Bottom navigation ---------- */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}

.bottom-nav .inner {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
}

.bottom-nav button {
  flex: 1;
  height: var(--nav-h);
  border: 0;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  position: relative;
}

.bottom-nav button svg { width: 24px; height: 24px; }

.bottom-nav button[aria-current="page"] { color: var(--primary); }

.bottom-nav button[aria-current="page"] .ico {
  background: var(--primary-soft);
}

.bottom-nav .ico {
  width: 56px;
  height: 30px;
  border-radius: 99px;
  display: grid;
  place-items: center;
}

.badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 26px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--minus);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
}

/* ---------- Gate screens ---------- */

.gate { width: 100%; max-width: 420px; }
.gate h1 { font-size: 24px; margin: 12px 0 8px; }
.gate p { margin: 0 0 14px; }
.gate .logo { width: 56px; height: 56px; }
.gate .card { margin-bottom: 14px; }

.code {
  font-family: ui-monospace, "Roboto Mono", monospace;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 3px;
}

.uid {
  font-family: ui-monospace, "Roboto Mono", monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
  background: #f1efe9;
  border-radius: 8px;
  padding: 8px 10px;
}

.checklist { padding-left: 20px; margin: 0; }
.checklist li { margin: 6px 0; }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 28, 25, .45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 20px 16px calc(20px + var(--safe-b));
  max-height: 90vh;
  overflow-y: auto;
  animation: up .18s ease-out;
}

.modal h2 { margin: 0 0 6px; font-size: 20px; }
.modal p { margin: 0 0 16px; color: var(--muted); }

@keyframes up { from { transform: translateY(30px); opacity: 0; } }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 14px);
  z-index: 60;
  max-width: 528px;
  margin: 0 auto;
  background: #22302c;
  color: #fff;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 15px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
}

#toast.error { background: var(--minus); }

/* ---------- Misc ---------- */

.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty .spinner { margin: 0 auto 12px; }

.noscript { padding: 24px; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .modal, .spinner { animation: none; }
}
