:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f1efe8;
  --text: #1f1f1d;
  --muted: #6b6a64;
  --border: #e2e0d8;
  --accent: #0f6e56;
  --accent-ink: #ffffff;
  --accent-soft: #e1f5ee;
  --pos: #1d7a4a;
  --neg: #b8442a;
  --warn-bg: #faeeda;
  --warn-ink: #633806;
  --danger-bg: #fcebeb;
  --danger-ink: #791f1f;
  --info-bg: #e6f1fb;
  --info-ink: #0c447c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #1f1f1d;
    --surface-2: #2a2a27;
    --text: #ecebe6;
    --muted: #a3a29b;
    --border: #34342f;
    --accent: #5dcaa5;
    --accent-ink: #04342c;
    --accent-soft: #0b3a2f;
    --pos: #6fd39a;
    --neg: #f0997b;
    --warn-bg: #412402;
    --warn-ink: #fac775;
    --danger-bg: #501313;
    --danger-ink: #f7c1c1;
    --info-bg: #042c53;
    --info-ink: #b5d4f4;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { font-weight: 600; margin: 0; }
h2 { font-size: 20px; }
h3 { font-size: 15px; margin-bottom: 8px; }
p { margin: 0; }
.hidden { display: none; }
.icon { width: 20px; height: 20px; flex: none; }

/* layout */
.page { max-width: 720px; margin: 0 auto; padding: 16px 16px 112px; display: flex; flex-direction: column; gap: 14px; }
.page.narrow { max-width: 520px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 12px; }
.gap { gap: 10px; }
.gap-s { gap: 8px; }
.wrap { flex-wrap: wrap; }
.center { justify-content: center; text-align: center; }
.grow { flex: 1; min-width: 0; }
.spacer { width: 40px; }

/* top bar + tabs */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; color: var(--text); }
.icon-btn:active { background: var(--surface-2); }
.tabs { position: sticky; top: calc(61px + env(safe-area-inset-top)); z-index: 4; display: flex; background: var(--bg); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 6px; font-size: 12px; color: var(--muted); border-bottom: 2px solid transparent; min-width: 72px; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; display: flex; gap: 10px; }
.card.danger { background: var(--danger-bg); color: var(--danger-ink); border-color: transparent; display: flex; gap: 10px; }
.card.danger p { margin-top: 4px; }
.card.info { background: var(--info-bg); color: var(--info-ink); border-color: transparent; display: flex; gap: 10px; align-items: flex-start; }
.summary { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.summary .big { font-size: 34px; font-weight: 650; letter-spacing: -0.5px; }
.summary.voided .big { text-decoration: line-through; color: var(--muted); }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 0; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.card.list { padding: 4px 16px; }
.records li, .activity li { display: flex; }
.record { display: flex; align-items: center; gap: 12px; width: 100%; color: inherit; }
.record.voided .rec-title, .record.voided .mono { text-decoration: line-through; color: var(--muted); }
.activity li { gap: 12px; align-items: flex-start; }
.activity li.ignored { opacity: 0.7; }
.rec-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); color: var(--muted); flex: none; }
.rec-icon.expense { background: var(--accent-soft); color: var(--accent); }
.rec-icon.payment { background: var(--info-bg); color: var(--info-ink); }
.rec-icon.fix { background: var(--warn-bg); color: var(--warn-ink); }
.rec-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rec-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-amt { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.history li { font-size: 14px; }

/* bits */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.amount { font-weight: 600; text-align: right; }
.badge { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 500; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.badge.danger { background: var(--danger-bg); color: var(--danger-ink); }
.verified { display: inline-flex; align-items: center; gap: 2px; color: var(--pos); }
.verified .icon { width: 13px; height: 13px; }
.note { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--muted); }
.note .icon { width: 16px; height: 16px; margin-top: 2px; }
.avatar { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; font-size: 12px; font-weight: 600; flex: none; }
.hue-purple { background: #eeedfe; color: #3c3489; }
.hue-teal { background: #e1f5ee; color: #085041; }
.hue-coral { background: #faece7; color: #712b13; }
.hue-pink { background: #fbeaf0; color: #72243e; }
.hue-blue { background: #e6f1fb; color: #0c447c; }
.hue-amber { background: #faeeda; color: #633806; }
.hue-green { background: #eaf3de; color: #27500a; }
.empty { text-align: center; padding: 40px 16px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty .icon { width: 40px; height: 40px; color: var(--accent); }
.group-card { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: inherit; }
.group-name { font-weight: 600; font-size: 17px; }
.join-head { display: flex; gap: 12px; align-items: center; }
.join-head .icon { width: 32px; height: 32px; color: var(--accent); }
.invite { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.invite h3 { align-self: flex-start; }
.qr { width: 232px; height: 232px; border-radius: 12px; image-rendering: pixelated; }

/* pill */
.pill { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 99px; padding: 4px 10px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.pill .icon { width: 14px; height: 14px; }
.pill.err { color: var(--neg); }
.pill.busy .icon { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .pill.busy .icon { animation: none; } }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--neg); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.small { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; }
.fab { position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); display: inline-flex; align-items: center; gap: 6px; padding: 14px 18px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-weight: 600; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); z-index: 6; }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.label { font-size: 13px; font-weight: 550; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type='checkbox'] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); flex: none; }
.amount-input { font-size: 22px; font-weight: 600; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button { border: 0; background: transparent; font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 8px; color: var(--muted); cursor: pointer; }
.segmented button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.split-rows { display: flex; flex-direction: column; }
.split-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.split-row:first-child { border-top: 0; }
.split-input { display: inline-flex; align-items: center; gap: 4px; width: 112px; }
.split-input input { padding: 6px 8px; min-height: 36px; text-align: right; }
.share-out { width: 72px; text-align: right; }
.split-foot:empty { display: none; }
.form-error { color: var(--neg); font-size: 14px; }
.form-error:empty { display: none; }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; transition: 0.2s; z-index: 20; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { background: var(--neg); color: #fff; }

/* live peer-to-peer status */
.pill.live { color: var(--pos); border-color: color-mix(in srgb, var(--pos) 40%, var(--border)); }
.badge.live { background: color-mix(in srgb, var(--pos) 16%, transparent); color: var(--pos); }
