:root {
  --bg: #f4f7f5; --surface: #ffffff; --text: #17201c; --muted: #5d6b65; --line: #e2e8e5;
  --accent: #1aa37a; --accent-ink: #ffffff; --accent-soft: #e3f5ee;
  --owed: #12805f; --owe: #c2410c; --danger: #b91c1c; --warn-bg: #fff4e5;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1714; --surface: #18221e; --text: #e8efeb; --muted: #95a39d; --line: #26332d;
    --accent: #22b98b; --accent-ink: #06130e; --accent-soft: #163329;
    --owed: #4ade9f; --owe: #fb923c; --danger: #f87171; --warn-bg: #2b2114;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
a { color: inherit; }
.ic { width: 20px; height: 20px; flex: none; vertical-align: -4px; }

.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.bar h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; text-decoration: none; color: var(--accent); }
.bar-btn:active { background: var(--accent-soft); }

main { max-width: 640px; margin: 0 auto; padding: 16px; }

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; background: var(--accent-soft); }
.flash.error { background: var(--warn-bg); color: var(--owe); }

.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 8px; display: flex; gap: 6px; align-items: center; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bal { margin: 0; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bal-cur { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.bal-main { font-size: 14px; color: var(--muted); }
.bal-amt { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.bal.owed .bal-amt { color: var(--owed); }
.bal.owe .bal-amt { color: var(--owe); }
.card-link { margin-top: 6px; font-size: 14px; font-weight: 600; color: var(--accent); text-decoration: none; }

.tip { display: flex; gap: 8px; align-items: flex-start; margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; text-decoration: none; }

.tabs { display: flex; gap: 6px; margin: 18px 0 8px; }
.tab { padding: 6px 12px; border-radius: 999px; text-decoration: none; font-size: 14px; color: var(--muted); border: 1px solid var(--line); }
.tab.on { background: var(--text); color: var(--bg); border-color: var(--text); }

.list { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.mv { display: flex; gap: 12px; align-items: center; padding: 12px 14px; text-decoration: none; border-top: 1px solid var(--line); }
.mv:first-child { border-top: 0; }
.mv:active { background: var(--accent-soft); }
.mv-ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.mv.pay .mv-ic { background: var(--line); color: var(--muted); }
.mv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mv-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mv-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mv-amt { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; display: flex; flex-direction: column; }
.mv-amt small { font-size: 11px; font-weight: 500; color: var(--muted); }
.mv-amt.owed { color: var(--owed); }
.mv-amt.owe { color: var(--owe); }
.badge { align-self: flex-start; margin-top: 3px; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--warn-bg); color: var(--owe); }
.badge.pending { background: var(--line); color: var(--muted); }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); margin: 0; }

.fab-row {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 10px; justify-content: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 0 18px; border-radius: 12px; border: 0; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.link { background: transparent; color: var(--muted); }
.btn.block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .6; }
.fab-row .btn { flex: 1; max-width: 220px; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.row { display: flex; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }
input, select {
  font: inherit; font-size: 17px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; min-height: 46px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
fieldset.seg { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
fieldset.seg legend { font-size: 14px; color: var(--muted); margin-bottom: 6px; padding: 0; }
fieldset.seg label { flex: 1 1 0; }
fieldset.seg.split label { flex: 1 1 40%; }
fieldset.seg input { position: absolute; opacity: 0; pointer-events: none; }
fieldset.seg span {
  display: block; text-align: center; padding: 11px 8px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 15px;
}
fieldset.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
fieldset.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.preview { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
.preview:empty { display: none; }
.hint { font-size: 14px; color: var(--muted); margin: 4px 0; }

.detail-big { font-size: 26px; font-weight: 700; margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.detail-big.owed { color: var(--owed); }
.detail-big.owe { color: var(--owe); }
.kv { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 15px; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { text-align: right; overflow-wrap: anywhere; }
.err { color: var(--owe); }
.errs { padding-left: 18px; font-size: 13px; color: var(--owe); }
.actions { display: flex; gap: 10px; }
.actions > * { flex: 1; }
.actions form .btn { width: 100%; }

.login { text-align: center; padding: 32px 20px; margin-top: 10vh; }
.login img { border-radius: 22px; }
[hidden] { display: none !important; }
