:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef1ee;
  --text: #17201d;
  --muted: #64706b;
  --line: #e2e7e3;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #ccfbf1;
  --pos: #15803d;
  --pos-soft: #dcfce7;
  --neg: #c2410c;
  --neg-soft: #ffedd5;
  --warn-soft: #fef3c7;
  --warn-ink: #92400e;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 6px 20px rgb(0 0 0 / .05);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --surface: #161e1b;
    --surface-2: #1f2925;
    --text: #e8eeeb;
    --muted: #94a39c;
    --line: #26322d;
    --accent: #2dd4bf;
    --accent-ink: #062521;
    --accent-soft: #123b36;
    --pos: #4ade80;
    --pos-soft: #12301f;
    --neg: #fb923c;
    --neg-soft: #3a2111;
    --warn-soft: #3a2f10;
    --warn-ink: #fcd34d;
    --danger: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }

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

/* top bar */
.bar { display: flex; align-items: center; gap: 8px; padding: 14px 0 10px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.bar h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn svg { width: 20px; height: 20px; }

.brand { display: flex; align-items: center; gap: 10px; padding: 28px 0 8px; }
.brand img { width: 40px; height: 40px; border-radius: 11px; }
.brand b { font-size: 24px; letter-spacing: -.02em; }
.lede { color: var(--muted); margin: 4px 0 22px; }

/* cards & lists */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-top: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; cursor: pointer; text-decoration: none; color: inherit; }
.row:first-child { border-top: 0; }
.row:active { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { text-align: right; font-weight: 650; white-space: nowrap; }
.row .amt small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.static { cursor: default; }
.static:active { background: none; }

.cat { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); font-size: 20px; flex: none; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; color: #fff; }

.day { font-size: 13px; color: var(--muted); font-weight: 600; margin: 16px 4px 6px; }

/* hero */
.hero { background: var(--accent); color: var(--accent-ink); border-radius: 22px; padding: 18px; margin-bottom: 12px; }
.hero .top { display: flex; align-items: center; gap: 10px; }
.hero .emoji { font-size: 30px; }
.hero .label { opacity: .8; font-size: 13px; }
.hero .big { font-size: 30px; font-weight: 750; letter-spacing: -.02em; }
.hero .meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 5px 10px; border-radius: 999px; background: rgb(255 255 255 / .18); border: 0; color: inherit; cursor: pointer; }
.pill.solid { background: var(--accent-ink); color: var(--accent); }

.notice { background: var(--warn-soft); color: var(--warn-ink); border-radius: 14px; padding: 11px 14px; font-size: 14px; display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.notice button { margin-left: auto; }

.install { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1.5px solid var(--accent-soft); border-radius: 16px; padding: 12px; margin-bottom: 12px; box-shadow: var(--shadow); }
.install img { width: 42px; height: 42px; border-radius: 10px; flex: none; }
.install .grow { flex: 1; min-width: 0; font-size: 15px; }
.install .btn { flex: none; }
.install .x { border: 0; background: none; color: var(--muted); font-size: 16px; padding: 6px; cursor: pointer; flex: none; }

.me-card { display: flex; align-items: center; gap: 12px; }
.me-card .big { font-size: 19px; font-weight: 750; }
.me-card .btn { white-space: nowrap; flex: none; }
.me-card .grow { flex: 1; min-width: 0; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* tabs / segmented */
.tabs { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; margin: 6px 0 12px; }
.tabs button { flex: 1; border: 0; background: none; padding: 9px 6px; border-radius: 10px; font-weight: 600; color: var(--muted); cursor: pointer; font-size: 15px; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* balance bars */
.bal-row { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 0; padding: 10px 16px; border-top: 1px solid var(--line); }
.bal-row:first-child { border-top: 0; }
.bal-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bal-name span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.bar-track { position: relative; height: 30px; }
.bar-fill { position: absolute; top: 3px; bottom: 3px; border-radius: 8px; }
.bar-fill.pos { left: 0; background: var(--pos-soft); }
.bar-fill.neg { right: 0; background: var(--neg-soft); }
.bar-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: flex-end; padding: 0 8px; font-weight: 650; font-size: 14px; }
.bar-label.neg { justify-content: flex-start; }
.bal-row .bal-name { grid-column: 1; }

.settle { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.settle:first-child { border-top: 0; }
.settle .who { flex: 1; min-width: 0; font-size: 15px; }
.settle .who b { font-weight: 650; }

/* forms */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px 2px; }
.input, select.input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); outline: none; min-height: 48px; }
.input:focus { border-color: var(--accent); }
.input.amount { font-size: 28px; font-weight: 700; padding: 10px 14px; }
.input-row { display: flex; gap: 8px; }
.input-row > * { flex: 1; min-width: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: var(--surface); padding: 7px 12px; border-radius: 999px; cursor: pointer; font-size: 14px; font-weight: 600; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }

.split-row { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-top: 1px solid var(--line); }
.split-row:first-child { border-top: 0; }
.split-row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.split-row .nm { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.split-row .val { width: 96px; text-align: right; padding: 8px 10px; min-height: 40px; }
.split-row .owed { width: 92px; text-align: right; color: var(--muted); font-size: 14px; }
.split-foot { padding: 10px 14px; font-size: 14px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; color: var(--muted); }
.split-foot.err { color: var(--danger); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 650; cursor: pointer; min-height: 48px; text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: none; color: var(--danger); border: 1.5px solid var(--line); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.stack { display: grid; gap: 10px; }

.fab { position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(20px + env(safe-area-inset-bottom)); height: 58px; padding: 0 22px; border-radius: 20px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px; box-shadow: 0 10px 30px rgb(15 118 110 / .35); text-decoration: none; display: flex; align-items: center; gap: 8px; cursor: pointer; z-index: 10; }
.fab svg { width: 22px; height: 22px; }

.empty { text-align: center; color: var(--muted); padding: 34px 16px; }
.empty .e { font-size: 40px; }

.toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); color: #fff; }

.err-text { color: var(--danger); font-size: 14px; margin: -4px 0 12px 2px; min-height: 1em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.mt { margin-top: 16px; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

.member-edit { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); }
.member-edit:first-child { border-top: 0; }
.member-edit .input { min-height: 40px; padding: 8px 12px; }
.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }

.code-box { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; font-size: 14px; word-break: break-all; }
.spinner { display: grid; place-items: center; min-height: 50vh; color: var(--muted); }
