:root {
  --bg: #f4f5fa; --card: #ffffff; --ink: #14151f; --muted: #6b6f80; --line: #e6e8f0;
  --brand: #4f46e5; --brand-ink: #ffffff; --brand-soft: #eceafe;
  --pos: #0f9d63; --pos-soft: #e3f6ec; --neg: #e0453a; --neg-soft: #fde9e7;
  --shadow: 0 1px 2px rgba(20,21,31,.05), 0 8px 24px rgba(20,21,31,.06);
  --r: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1016; --card: #191b24; --ink: #eef0f7; --muted: #9a9fb2; --line: #2a2d3a;
    --brand: #7c74ff; --brand-ink: #ffffff; --brand-soft: #24224a;
    --pos: #35c98a; --pos-soft: #13301f; --neg: #ff6b5f; --neg-soft: #3a1714;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
#app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(110px + env(safe-area-inset-bottom)); }
#offline { position: sticky; top: 0; z-index: 30; background: #f59e0b; color: #1b1300; text-align: center; font-size: 14px; padding: 6px 12px; }

/* top bar */
.bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  margin: 0 -16px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; background: var(--bg); }
.bar h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 42px; height: 42px; border: 0; border-radius: 12px; background: transparent; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--card); }
.icon-btn svg { width: 22px; height: 22px; }

/* basics */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.ellip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-title { font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 22px 4px 8px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .big { font-size: 48px; margin-bottom: 8px; }

.btn { border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 650; cursor: pointer; background: var(--brand); color: var(--brand-ink); width: 100%; }
.btn.secondary { background: var(--brand-soft); color: var(--brand); }
.btn.danger { background: var(--neg-soft); color: var(--neg); }
.btn.ghost { background: transparent; color: var(--brand); padding: 10px; width: auto; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: grid; gap: 10px; margin-top: 18px; }

.fab { position: fixed; right: max(18px, calc(50% - 262px)); bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 15;
  height: 58px; padding: 0 22px 0 18px; border: 0; border-radius: 20px; background: var(--brand); color: var(--brand-ink);
  font-weight: 700; display: flex; align-items: center; gap: 8px; box-shadow: 0 10px 30px rgba(79,70,229,.4); cursor: pointer; }
.fab svg { width: 24px; height: 24px; }

/* home */
.group-item { display: flex; align-items: center; gap: 14px; padding: 14px; margin-bottom: 10px; cursor: pointer; }
.emoji-tile { width: 48px; height: 48px; border-radius: 14px; background: var(--brand-soft); display: grid; place-items: center; font-size: 26px; flex: none; }
.hero { padding: 26px 4px 6px; }
.hero h2 { font-size: 30px; margin: 0 0 6px; letter-spacing: -.02em; }

/* group summary */
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 14px; }
.summary .card { padding: 14px; }
.summary .k { font-size: 13px; color: var(--muted); }
.summary .v { font-size: 22px; font-weight: 750; margin-top: 2px; letter-spacing: -.01em; }

.tabs { display: flex; gap: 4px; background: var(--card); padding: 4px; border-radius: 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 10px 6px; border-radius: 10px; font-weight: 650; color: var(--muted); cursor: pointer; font-size: 15px; }
.tabs button.on { background: var(--brand); color: var(--brand-ink); }

.search { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 12px; margin-bottom: 4px; }

.list { overflow: hidden; }
.date-head { font-size: 13px; color: var(--muted); font-weight: 650; margin: 16px 4px 6px; }
.exp { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.exp:last-child { border-bottom: 0; }
.cat { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; background: var(--bg); flex: none; }
.exp .t { font-weight: 650; }
.exp .amt { text-align: right; flex: none; }
.exp .amt .a { font-weight: 700; }

/* balances */
.bal { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.bal:last-child { border-bottom: 0; }
.bal-bar { position: relative; height: 8px; background: var(--bg); border-radius: 6px; margin-top: 8px; overflow: hidden; }
.bal-bar i { position: absolute; top: 0; bottom: 0; border-radius: 6px; }
.settle { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.settle:last-child { border-bottom: 0; }
.chip-btn { border: 0; background: var(--brand-soft); color: var(--brand); padding: 8px 12px; border-radius: 10px; font-weight: 650; cursor: pointer; font-size: 14px; flex: none; }

/* stats */
.stat-row { padding: 10px 14px; }
.meter { height: 10px; border-radius: 6px; background: var(--bg); overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; background: var(--brand); border-radius: 6px; }

/* forms */
.form { padding: 4px 0; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; font-weight: 650; color: var(--muted); margin: 0 4px 6px; }
.input { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 14px; outline: none; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.amount-input { font-size: 30px; font-weight: 750; letter-spacing: -.01em; }
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 9px 4px; font-weight: 650; color: var(--muted); cursor: pointer; font-size: 14px; }
.seg button.on { background: var(--brand-soft); color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 12px; cursor: pointer; font-size: 14px; }
.chip.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 650; }
.split-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.split-row:last-child { border-bottom: 0; }
.split-row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.split-row .mini { width: 110px; text-align: right; padding: 8px 10px; }
.split-row .share { font-weight: 650; min-width: 84px; text-align: right; }
.split-foot { padding: 10px 12px; font-size: 14px; display: flex; justify-content: space-between; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.person-row { display: flex; gap: 8px; margin-bottom: 8px; }
.person-row .input { flex: 1; }

/* detail */
.detail-hero { text-align: center; padding: 18px 10px 8px; }
.detail-hero .cat { width: 64px; height: 64px; font-size: 32px; margin: 0 auto 10px; border-radius: 18px; background: var(--card); box-shadow: var(--shadow); }
.detail-hero .big { font-size: 36px; font-weight: 800; letter-spacing: -.02em; }
.kv { display: flex; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); gap: 12px; }
.kv:last-child { border-bottom: 0; }
.receipt-img { width: 100%; border-radius: 12px; display: block; }

/* sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(10,10,20,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--card); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 85vh; overflow: auto; animation: up .2s ease-out; }
.sheet h3 { margin: 4px 4px 12px; font-size: 19px; }
.pick { display: flex; align-items: center; gap: 12px; padding: 14px 12px; border-radius: 12px; cursor: pointer; border: 0; width: 100%; background: transparent; text-align: left; }
.pick:hover { background: var(--bg); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 750; color: #fff; flex: none; font-size: 15px; }
@keyframes up { from { transform: translateY(40px); opacity: .4 } to { transform: none; opacity: 1 } }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 600; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg) } }
