:root {
  --bg: #f3f5f4; --card: #ffffff; --text: #17201c; --muted: #6b7772; --line: #e4e8e6;
  --accent: #1f7a5c; --accent-soft: #e3f2ec; --warn: #b4541a; --warn-soft: #fbeee4; --danger: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101413; --card: #1a201e; --text: #edf2ef; --muted: #96a39d; --line: #2a322f;
    --accent: #4cc39a; --accent-soft: #1d3a30; --warn: #f0a36b; --warn-soft: #3a2a1d; --danger: #ff8a80;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h1, h2, p { margin: 0; }

/* sign in */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; align-items: stretch; }
.auth-card img { align-self: center; border-radius: 18px; }
.auth-card h1 { font-size: 28px; }
.auth-card p { color: var(--muted); font-size: 15px; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; }

input, select {
  font: inherit; font-size: 16px; color: var(--text); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 13px 14px; width: 100%;
  appearance: none; -webkit-appearance: none; min-height: 50px;
}
input:focus { outline: none; border-color: var(--accent); }
.btn { border-radius: 12px; padding: 14px 16px; font-weight: 600; width: 100%; background: var(--line); }
.btn.primary { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0c1512; } }
.btn.danger { background: none; color: var(--danger); }
.btn:disabled { opacity: .6; }
.link { color: var(--accent); font-size: 15px; padding: 8px 0 8px 8px; }

/* layout */
#app { max-width: 520px; margin: 0 auto; padding: 0 14px calc(150px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; justify-content: space-between; padding: calc(14px + env(safe-area-inset-top)) 2px 6px; }
.top h1 { font-size: 26px; letter-spacing: -.3px; }
.card { background: var(--card); border-radius: 16px; padding: 10px; }

.monthnav { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 10px; }
.monthnav button { height: 44px; min-width: 44px; border-radius: 12px; font-size: 28px; line-height: 1; color: var(--accent); }
.monthnav .month-label { font-size: 19px; font-weight: 700; color: var(--text); padding: 0 12px; }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.tile { background: var(--card); border-radius: 14px; padding: 10px 10px 11px; min-width: 0; }
.tile small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile b { display: block; font-size: 17px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.tile.accent b { color: var(--accent); }

/* calendar */
.dow, .grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dow span { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0 6px; }
.day { height: 52px; border-radius: 11px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 6px; gap: 3px; min-width: 0; }
.day .n { font-size: 15px; line-height: 20px; width: 26px; height: 20px; text-align: center; border-radius: 10px; }
.day.today .n { background: var(--accent); color: #fff; font-weight: 700; }
@media (prefers-color-scheme: dark) { .day.today .n { color: #0c1512; } }
.day .amt { font-size: 10.5px; line-height: 15px; padding: 0 4px; border-radius: 8px; max-width: 100%; white-space: nowrap; overflow: hidden; font-weight: 600; font-variant-numeric: tabular-nums; }
.day .amt.due { background: var(--warn-soft); color: var(--warn); }
.day .amt.paid { background: var(--accent-soft); color: var(--accent); }
.day.sel { background: var(--line); }
.day.blank { visibility: hidden; }

/* lists */
.list-head { display: flex; align-items: center; justify-content: space-between; margin: 16px 4px 8px; min-height: 30px; }
.list-head h2 { font-size: 17px; }
.list { padding: 2px 12px; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-date { width: 40px; flex: none; text-align: center; background: var(--bg); border-radius: 10px; padding: 5px 0; }
.row-date b { display: block; font-size: 17px; line-height: 19px; }
.row-date small { display: block; font-size: 11px; color: var(--muted); }
.row-main { flex: 1; min-width: 0; }
.row-name { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-amt { flex: none; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.row-amt small { display: block; font-size: 12px; font-weight: 600; }
.paid { color: var(--accent); } .due { color: var(--warn); } .skip { color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 22px 8px; font-size: 15px; }
.empty .link { display: block; margin: 6px auto 0; padding: 8px; }

/* bottom */
.fab {
  position: fixed; right: max(16px, calc(50vw - 246px)); bottom: calc(74px + env(safe-area-inset-bottom));
  background: var(--accent); color: #fff; font-weight: 700; border-radius: 26px; padding: 14px 20px;
  box-shadow: 0 6px 18px rgba(0,0,0,.22); z-index: 5;
}
@media (prefers-color-scheme: dark) { .fab { color: #0c1512; } }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 4;
}
.tabs button { flex: 1; height: 58px; font-weight: 600; color: var(--muted); }
.tabs button.on { color: var(--accent); }

/* sheet */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet-card {
  background: var(--bg); width: 100%; max-width: 520px; max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 21px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
label small, .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
.money { position: relative; }
.money span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money input { padding-left: 30px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { padding: 11px 4px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); }
.facts { background: var(--card); border-radius: 14px; padding: 4px 14px; }
.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.facts div:last-child { border-bottom: 0; }
.facts span { color: var(--muted); }
.facts b { text-align: right; font-variant-numeric: tabular-nums; }
.inline { display: flex; gap: 8px; }
.inline .btn { width: auto; flex: none; padding: 0 18px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(140px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 20px; font-size: 14px; z-index: 20; max-width: 90vw; text-align: center; }
.grow { flex: 1; }
#allList .row-sub { white-space: normal; }
