:root {
  --bg: #f6f4f0; --card: #ffffff; --ink: #16202b; --muted: #667085; --line: #e3dfd8;
  --accent: #1f3a5f; --accent-ink: #ffffff; --chip: #efece6; --good: #1a7f4b; --bad: #b3261e;
  --warn-bg: #fff3cd; --warn-ink: #6b4e00;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151c; --card: #18212b; --ink: #e8edf2; --muted: #94a3b3; --line: #2a3644;
    --accent: #8dbcf0; --accent-ink: #0f151c; --chip: #223040; --good: #5fd08f; --bad: #ff8a80;
    --warn-bg: #3d3212; --warn-ink: #ffe08a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

header {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--accent); color: var(--accent-ink);
}
header h1 { font-size: 18px; line-height: 1.2; }
.sync { font-size: 12px; opacity: .8; min-height: 17px; }
.sync.warn { opacity: 1; font-weight: 600; }
.me { border: 1px solid currentColor; background: none; color: inherit; border-radius: 999px; padding: 6px 12px; font-size: 14px; white-space: nowrap; }

main { max-width: 560px; margin: 0 auto; padding: 16px; }
h2 { font-size: 20px; margin-bottom: 4px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 4px 8px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
h3 span { text-transform: none; letter-spacing: 0; font-weight: 600; }
.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; padding: 28px 0; }
.pad { padding: 0 4px; }
.tally { padding: 0 4px; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.error { color: var(--bad); font-weight: 600; font-size: 15px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.center-card { margin-top: 24px; }
.center-card .muted { margin-bottom: 8px; }
.stack { display: grid; gap: 10px; margin-top: 12px; }

.form { display: grid; gap: 16px; }
.form label > span, .field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
input:not([type="checkbox"]), select {
  width: 100%; min-height: 48px; padding: 10px 12px; font-size: 17px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  -webkit-appearance: none; appearance: none;
}
input[type="date"] { display: block; text-align: left; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.amount-box { display: flex; align-items: center; gap: 8px; }
.amount-box input { font-size: 30px; font-weight: 700; min-height: 64px; font-variant-numeric: tabular-nums; }
.amount-box b { font-size: 26px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips { gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--chip); border-radius: 999px; padding: 7px 12px; font-size: 14px; min-height: 38px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

.check { display: flex; align-items: flex-start; gap: 12px; }
.check input { width: 26px; height: 26px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.form .check > span { margin: 0; font-size: 16px; color: var(--ink); }
.check small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }

.primary, .secondary, .danger { width: 100%; min-height: 52px; border-radius: 12px; border: 1px solid transparent; font-size: 17px; font-weight: 700; }
.primary { background: var(--accent); color: var(--accent-ink); }
.secondary { background: var(--chip); border-color: var(--line); }
.danger { background: none; border-color: var(--bad); color: var(--bad); }
.danger.armed { background: var(--bad); color: #fff; }
.small { border: 1px solid var(--line); background: var(--chip); border-radius: 10px; padding: 8px 12px; font-size: 14px; font-weight: 600; white-space: nowrap; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 14px; font-weight: 600; text-transform: none; letter-spacing: 0; text-decoration: underline; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.list { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.item { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; }
.item:last-child { border-bottom: 0; }
.item-main { min-width: 0; }
.item-main b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item small { display: block; color: var(--muted); font-size: 13px; }
.item-amt { text-align: right; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.item-amt small { font-weight: 400; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.filters input { grid-column: 1 / -1; }
.filters select { background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23888' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 12px center; padding-right: 32px; font-size: 16px; }
.filters input { background: var(--card); }

.total small { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }
.total strong { display: block; font-size: 38px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.person, .pay { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.person:first-child, .pay:first-child { padding-top: 0; }
.person:last-child, .pay:last-child { border-bottom: 0; padding-bottom: 0; }
.person small { display: block; color: var(--muted); font-size: 13px; }
.person > b { text-align: right; white-space: nowrap; }
.pay strong { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.bar { margin-bottom: 12px; }
.bar:last-child { margin-bottom: 0; }
.bar-top { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; margin-bottom: 4px; }
.bar-top b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-track { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; }
.bar-track i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.editor .muted { margin-bottom: 10px; }
.edit-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.edit-row:last-child { margin-bottom: 0; }
.x { flex: none; width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: none; font-size: 22px; line-height: 1; color: var(--bad); }
.x:disabled { color: var(--muted); opacity: .35; }
.meta { font-size: 13px; }

nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
nav button { border: 0; background: none; padding: 16px 4px; font-size: 15px; font-weight: 600; color: var(--muted); border-top: 3px solid transparent; }
nav button.on { color: var(--accent); border-top-color: var(--accent); }

dialog { width: min(560px, 100vw - 24px); max-height: calc(100dvh - 24px); border: 0; border-radius: 16px; padding: 0; background: var(--card); color: var(--ink); overflow-y: auto; }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog .form { padding: 18px 16px; }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 15px;
  max-width: calc(100vw - 32px); text-align: center; box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}
