:root {
  --bg: #f6f3ec;
  --card: #ffffff;
  --ink: #1c1917;
  --muted: #6b645c;
  --line: #e7e1d6;
  --green: #14532d;
  --green-soft: #e3f1e6;
  --amber: #b45309;
  --amber-soft: #fdf0d9;
  --red: #b91c1c;
  --red-soft: #fde8e8;
  --radius: 18px;
}

* { box-sizing: border-box; }

html { font-size: 18px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(170px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

/* top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 0 12px;
}
.topbar h1 { font-size: 1.35rem; margin: 0; text-align: center; flex: 1; font-weight: 700; }
.navbtn {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 1.5rem;
  line-height: 1;
  flex: none;
}
.navbtn:active { background: var(--line); }
.today-link {
  display: block; margin: -4px auto 10px; background: none; border: none;
  color: var(--green); font-weight: 600; text-decoration: underline; padding: 6px 10px;
}

/* summary */
.summary {
  background: var(--green);
  color: #fff;
  border-radius: 24px;
  padding: 20px 20px 16px;
}
.summary.over { background: var(--red); }
.summary .label { opacity: .85; font-size: .9rem; }
.summary .big { font-size: 2.7rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; margin: 2px 0 12px; font-variant-numeric: tabular-nums; }
.bar { height: 10px; border-radius: 99px; background: rgba(255,255,255,.25); overflow: hidden; }
.bar > i { display: block; height: 100%; background: #fff; border-radius: 99px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stats div span { display: block; font-size: .78rem; opacity: .85; }
.stats div b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.split { margin-top: 12px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.25); font-size: .85rem; opacity: .95; display: flex; flex-wrap: wrap; gap: 4px 14px; }

/* lists */
.section-title {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 22px 4px 8px; font-size: .85rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
}
.section-title b { font-variant-numeric: tabular-nums; color: var(--ink); font-size: .95rem; }
.list { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.row { display: flex; align-items: stretch; border-top: 1px solid var(--line); }
.row:first-child { border-top: none; }
.tick {
  flex: none; width: 64px; border: none; background: none;
  display: grid; place-items: center; padding: 0;
}
.tick i {
  width: 34px; height: 34px; border-radius: 50%;
  border: 2.5px solid #b9b1a4; display: grid; place-items: center;
  font-style: normal; font-size: 1.15rem; color: transparent; font-weight: 800;
}
.row.paid .tick i { background: var(--green); border-color: var(--green); color: #fff; }
.rowmain {
  flex: 1; min-width: 0; border: none; background: none; text-align: left;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px 14px 0; min-height: 68px;
}
.rowmain:active { background: #faf7f1; }
.rowmain .name { font-weight: 600; font-size: 1.05rem; overflow-wrap: anywhere; }
.rowmain .sub { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.rowmain .amt { font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row:not(.paid) .amt { color: var(--amber); }
.row.zero .amt { color: #a8a093; font-weight: 500; }
.empty { text-align: center; color: var(--muted); padding: 34px 20px; }
.empty .btn { margin-top: 16px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 0 22px; border-radius: 16px; border: none;
  background: var(--green); color: #fff; font-weight: 700; font-size: 1.05rem;
}
.btn.wide { width: 100%; }
.btn.ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn:active { filter: brightness(.94); }

.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  width: min(528px, calc(100% - 32px));
  box-shadow: 0 8px 22px rgba(20, 83, 45, .35);
  z-index: 5;
}

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; max-width: 190px; border: none; background: none; padding: 10px 4px 12px;
  font-size: .82rem; font-weight: 600; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabs button span { font-size: 1.35rem; line-height: 1.2; }
.tabs button.on { color: var(--green); }

/* history */
.yearhead { margin: 24px 4px 10px; }
.yearhead h2 { margin: 0 0 2px; font-size: 1.5rem; }
.yearhead span { color: var(--muted); font-size: .88rem; display: block; }
.yearhead span b { color: var(--ink); }
.mrow { display: block; width: 100%; border: none; background: none; text-align: left; padding: 12px 16px; border-top: 1px solid var(--line); }
.mrow:first-child { border-top: none; }
.mrow .top { display: flex; justify-content: space-between; font-weight: 600; }
.mrow .top b { font-variant-numeric: tabular-nums; }
.mrow .track { height: 8px; border-radius: 99px; background: var(--line); margin-top: 8px; overflow: hidden; }
.mrow .track i { display: block; height: 100%; border-radius: 99px; background: var(--green); }
.mrow .track i.over { background: var(--red); }
.where { padding: 6px 16px 10px; }
.where div { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); font-size: .95rem; }
.where div:first-child { border-top: none; }
.where b { font-variant-numeric: tabular-nums; }

/* settings + form */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 14px; }
.card h3 { margin: 0 0 4px; font-size: 1.05rem; }
.card p { margin: 0 0 12px; color: var(--muted); font-size: .88rem; }
.card .btn + .btn { margin-top: 10px; }
label.field { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
input[type=text], input[type=number], input[type=date], input[inputmode] {
  width: 100%; min-height: 58px; border-radius: 14px; border: 2px solid var(--line);
  background: #fff; padding: 0 16px; font-size: 1.15rem;
}
input:focus { outline: none; border-color: var(--green); }
input.money { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg.two { grid-template-columns: repeat(2, 1fr); }
.seg button {
  min-height: 56px; border-radius: 14px; border: 2px solid var(--line); background: #fff; font-weight: 600;
}
.seg button.on { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; min-width: 0; }
.inline .btn { flex: none; }
.parts { color: var(--muted); font-size: .88rem; margin-top: 6px; font-variant-numeric: tabular-nums; }
.linkbtn { background: none; border: none; color: var(--green); font-weight: 600; padding: 10px 0; text-decoration: underline; }
.check { display: flex; align-items: center; gap: 12px; margin-top: 16px; font-weight: 600; }
.check input { width: 28px; height: 28px; accent-color: var(--green); flex: none; }

dialog#sheet {
  border: none; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 94vh;
  border-radius: 24px 24px 0 0; background: var(--bg); color: var(--ink);
}
dialog#sheet::backdrop { background: rgba(28, 25, 23, .5); }
.sheet-in { padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; }
.sheet-actions { display: grid; gap: 10px; margin-top: 22px; }
@media (min-width: 620px) {
  dialog#sheet { margin: auto; border-radius: 24px; }
}

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(156px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px;
  font-size: .95rem; display: none; align-items: center; gap: 14px; max-width: calc(100% - 32px);
}
#toast.show { display: flex; }
#toast button { background: none; border: none; color: #fcd34d; font-weight: 700; padding: 4px; }

.syncline { text-align: center; font-size: .82rem; color: var(--muted); margin: -2px 0 10px; min-height: 0; }
.syncline:empty { display: none; }
.syncline.ok { color: var(--green); font-weight: 600; }
.syncline.error, .syncline.badcode { color: var(--red); font-weight: 600; }
.syncline.pending, .syncline.busy { color: var(--amber); }
