:root {
  --bg: #f6f3ee;
  --card: #fffdf9;
  --ink: #1d1b18;
  --muted: #77716a;
  --line: #e6e0d6;
  --accent: #1f6f5c;
  --accent-ink: #f6f3ee;
  --owed: #1f7a4d;
  --owe: #c2492f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(29, 27, 24, 0.06), 0 4px 16px rgba(29, 27, 24, 0.05);
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311;
    --card: #1d1b18;
    --ink: #f1ece4;
    --muted: #9c958b;
    --line: #2e2b27;
    --accent: #5cc3a3;
    --accent-ink: #10201b;
    --owed: #5cc38a;
    --owe: #ef8a6f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

#app { max-width: 600px; margin: 0 auto; padding: max(20px, env(safe-area-inset-top)) 16px calc(110px + env(safe-area-inset-bottom)); }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -0.01em; color: var(--muted); text-decoration: none; font-size: 14px; }
.brand .dot { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); position: relative; }
.brand .dot::after { content: ""; position: absolute; left: 8px; top: 0; bottom: 0; width: 2px; background: var(--bg); }

h1 { font-size: 30px; line-height: 1.1; letter-spacing: -0.025em; margin: 18px 0 6px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 28px 0 10px; font-weight: 600; }
.sub { color: var(--muted); margin: 0 0 20px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
input[type="text"], input[type="date"], input[inputmode], select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); outline: none; min-height: 44px;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.amount-input { font-size: 28px !important; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.row > .shrink { flex: 0 0 auto; }

.btn { white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); padding: 10px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; min-height: 44px; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--owe); }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 14px; }
.btn.block { width: 100%; }
.icon-btn { border: none; background: none; cursor: pointer; color: var(--muted); padding: 8px; border-radius: 8px; min-width: 40px; min-height: 40px; }
.icon-btn:hover { background: var(--line); }

.people-list .person-row { display: flex; gap: 8px; margin-bottom: 8px; }
.people-list .person-row input { flex: 1; }

.header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.header h1 { margin-top: 14px; word-break: break-word; }

.summary { padding: 18px 16px; margin: 16px 0 6px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.summary .label { color: var(--muted); font-size: 14px; }
.summary .big { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.pos { color: var(--owed); }
.neg { color: var(--owe); }
.zero { color: var(--muted); }

.whoami { padding: 14px 16px; margin: 16px 0; }
.whoami p { margin: 0 0 10px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--bg); padding: 7px 12px; border-radius: 999px; cursor: pointer; font-weight: 550; }
.chip:hover, .chip.on { border-color: var(--accent); color: var(--accent); }

.tabs { display: flex; gap: 4px; background: var(--line); padding: 3px; border-radius: 11px; margin: 18px 0 12px; }
.tabs button { flex: 1; border: none; background: none; padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); font-size: 15px; }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: none; }
.list > li.click { cursor: pointer; }
.list > li.click:hover { background: color-mix(in srgb, var(--line) 40%, transparent); }
.date-badge { flex: 0 0 40px; text-align: center; line-height: 1.05; color: var(--muted); }
.date-badge .m { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.date-badge .d { font-size: 19px; font-weight: 650; color: var(--ink); }
.grow { flex: 1; min-width: 0; }
.title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { font-size: 13px; color: var(--muted); }
.right { text-align: right; flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.right .meta { font-size: 12px; }
.right .amt { font-weight: 650; }
.month { padding: 14px 16px 6px; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); }
.pay-icon { flex: 0 0 40px; height: 40px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); display: grid; place-items: center; font-size: 18px; }

.bal-row .bar { height: 6px; border-radius: 3px; background: var(--line); margin-top: 6px; overflow: hidden; position: relative; }
.bal-row .bar i { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.empty { text-align: center; color: var(--muted); padding: 34px 20px; }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

.fab { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom)); display: flex; gap: 8px; z-index: 5; }
.fab .btn { box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18); padding: 12px 18px; border-radius: 999px; }

dialog#sheet { border: none; padding: 0; background: var(--card); color: var(--ink); width: min(560px, 100%); max-height: 92vh; border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog#sheet::backdrop { background: rgba(20, 18, 16, 0.45); }
@media (max-width: 600px) {
  dialog#sheet { margin: auto 0 0; max-width: 100%; border-radius: 18px 18px 0 0; max-height: 94vh; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 4px 18px; position: sticky; top: 0; background: var(--card); z-index: 1; }
.sheet-head h3 { margin: 0; font-size: 18px; }
.sheet-body { padding: 8px 18px 18px; }
.sheet-foot { position: sticky; bottom: 0; background: var(--card); padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }

.seg { display: flex; background: var(--line); padding: 3px; border-radius: 10px; gap: 3px; margin-bottom: 10px; }
.seg button { flex: 1; border: none; background: none; padding: 7px 4px; border-radius: 7px; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.split-rows .srow { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.split-rows .srow:last-child { border-bottom: none; }
.split-rows .srow .nm { flex: 1; font-weight: 550; }
.split-rows .srow input[inputmode] { width: 110px; flex: 0 0 110px; text-align: right; min-height: 38px; padding: 7px 10px; }
.split-rows .srow .share { width: 84px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; }
.split-rows input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.split-status { font-size: 14px; margin-top: 8px; min-height: 20px; }
.split-status.err { color: var(--owe); }
.split-status.ok { color: var(--muted); }
.form-error { color: var(--owe); font-size: 14px; flex: 1; }

#toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 550; opacity: 0; pointer-events: none; transition: all 0.2s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.muted { color: var(--muted); }
.link-btn { background: none; border: none; color: var(--accent); font-weight: 600; cursor: pointer; padding: 0; }
.spacer { height: 10px; }
.loading { text-align: center; padding: 80px 0; color: var(--muted); }
