:root {
  --bg: #f4f5f2; --card: #fff; --text: #1c1f1e; --muted: #6b716e; --line: #e4e6e2;
  --accent: #0f766e; --accent-soft: #d8efe9; --pos: #12805c; --neg: #c2410c; --warn-bg: #fff4e0;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 10px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111413; --card: #1b1f1e; --text: #eef0ee; --muted: #9aa19d; --line: #2b302e;
    --accent: #2bb3a3; --accent-soft: #163a35; --pos: #3fcf95; --neg: #ff8a50; --warn-bg: #3a2c12;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
#app { max-width: 640px; margin: 0 auto; padding: 0 14px calc(110px + env(safe-area-inset-bottom)); }
.loading { padding: 40vh 0; text-align: center; color: var(--muted); }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; margin: 22px 4px 8px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hidden { display: none !important; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(10px + env(safe-area-inset-top)) 0 6px; }
.top .title { font-weight: 700; font-size: 1.25rem; }
.me-btn { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 12px; font-size: .85rem; cursor: pointer; white-space: nowrap; }
.tabs { display: flex; gap: 4px; background: var(--line); border-radius: 12px; padding: 3px; margin-top: 10px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* cards & lists */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 10px; }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); cursor: pointer; width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.item:first-child { border-top: 0; }
.item:active { background: var(--accent-soft); }
.item .amt { font-weight: 600; white-space: nowrap; }
.date-head { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin: 16px 6px 6px; }
.icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--accent-soft); flex: none; font-size: 1.1rem; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; font-size: .9rem; }
.c0{background:#0f766e}.c1{background:#7c3aed}.c2{background:#db2777}.c3{background:#ea580c}.c4{background:#2563eb}.c5{background:#65a30d}.c6{background:#0891b2}.c7{background:#a16207}
.badge { display: inline-block; font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); font-weight: 600; vertical-align: middle; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; white-space: nowrap; cursor: pointer; font-size: .9rem; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.warn { background: var(--warn-bg); border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; font-size: .9rem; }

.big-balance { text-align: center; padding: 18px 14px; }
.big-balance .n { font-size: 2rem; font-weight: 750; letter-spacing: -.02em; }
.settle { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); }
.settle:first-child { border-top: 0; }

/* buttons */
.btn { border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 600; cursor: pointer; background: var(--line); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: transparent; color: var(--neg); }
.btn.small { padding: 6px 12px; font-size: .85rem; border-radius: 9px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; padding: 4px; }
.fab { position: fixed; z-index: 6; right: max(18px, calc(50vw - 302px)); bottom: calc(22px + env(safe-area-inset-bottom));
  background: var(--accent); color: #fff; border: 0; border-radius: 999px; padding: 15px 22px; font-weight: 700; font-size: 1rem;
  box-shadow: 0 6px 20px rgba(15,118,110,.35); cursor: pointer; }

/* forms */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: .82rem; color: var(--muted); font-weight: 600; margin: 0 0 4px 2px; }
input[type=text], input[type=number], input[type=date], input[type=password], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 16px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 60px; resize: vertical; }
.amount-input { font-size: 1.6rem !important; font-weight: 700; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.amount-row { display: grid; grid-template-columns: 1fr 100px; gap: 10px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; background: var(--line); border-radius: 11px; padding: 3px; margin-bottom: 10px; }
.seg button { border: 0; background: transparent; border-radius: 8px; padding: 7px 2px; font-size: .8rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.split-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.split-row:first-child { border-top: 0; }
.split-row input[type=number], .split-row input.money { width: 96px; text-align: right; padding: 7px 9px; }
.split-row .share { min-width: 92px; text-align: right; font-variant-numeric: tabular-nums; }
.check { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.checks label { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); cursor: pointer; }
.checks label:first-child { border-top: 0; }
.hint { font-size: .82rem; color: var(--muted); margin: 4px 2px 10px; }
.rate-line { font-size: .85rem; color: var(--muted); margin: -4px 2px 12px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rate-line input { width: 110px; padding: 5px 8px; }

/* modal */
#modal .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
#modal .sheet { background: var(--card); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .18s ease-out; }
@media (min-width: 700px) { #modal .backdrop { align-items: center; } #modal .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h3 { margin: 0; font-size: 1.15rem; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn.primary { flex: 1; }

#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; pointer-events: none; }
#toast div { background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .9rem; max-width: 88vw; box-shadow: 0 4px 16px rgba(0,0,0,.25); animation: up .15s; }
#toast div.err { background: #b42318; }

.landing { padding-top: calc(36px + env(safe-area-inset-top)); }
.landing .logo { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 2rem; font-weight: 700; margin-bottom: 12px; }
.share-url { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; background: var(--bg); border-radius: 8px; padding: 8px 10px; word-break: break-all; margin: 6px 0 10px; }
a.item { color: inherit; text-decoration: none; }
a.btn { display: inline-block; text-decoration: none; color: inherit; }
a.btn.primary { color: #fff; }
