:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --text: #1c1b19;
  --muted: #6d6a63;
  --line: #e3e1da;
  --accent: #0f766e;
  --accent-soft: #d6efe9;
  --accent-text: #ffffff;
  --pos: #0f7a4f;
  --neg: #c2410c;
  --warn-bg: #fff4d6;
  --warn-text: #8a5a00;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
  --radius: 16px;
  --tabbar: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312;
    --surface: #1d1d1b;
    --surface-2: #272724;
    --text: #f1efe9;
    --muted: #a19e96;
    --line: #33322e;
    --accent: #2dd4bf;
    --accent-soft: #123b37;
    --accent-text: #062b27;
    --pos: #4ade80;
    --neg: #fb923c;
    --warn-bg: #3a2f12;
    --warn-text: #fcd34d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Hiragino Sans", "Noto Sans CJK", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.screen { max-width: 640px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(var(--tabbar) + 90px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
}
.topbar h1 { font-size: 19px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; letter-spacing: -.01em; }
.topbar .sub { font-size: 12px; color: var(--muted); font-weight: 500; }
.icon-btn {
  text-decoration: none; color: inherit;
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent;
  display: inline-grid; place-items: center; font-size: 20px; flex: none;
}
.icon-btn:active { background: var(--surface-2); }
.content { padding: 4px 16px 16px; }

.section-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 22px 4px 8px; display: flex; justify-content: space-between; align-items: baseline; }
.section-title .num { text-transform: none; letter-spacing: 0; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.card + .card { margin-top: 10px; }
.pad { padding: 14px 16px; }
.list { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); min-height: 56px; }
.row:first-child { border-top: 0; }
.row.tap { cursor: pointer; }
.row.tap:active { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { text-align: right; font-weight: 600; white-space: nowrap; }
.row .amt .meta { font-weight: 400; }

/* ---------- tab bar & fab ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex; justify-content: center;
}
.tabbar .inner { display: flex; width: 100%; max-width: 640px; }
.tab { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600; text-decoration: none; }
.tab .ico { font-size: 21px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tab.active { color: var(--accent); }
.tab.active .ico { filter: none; opacity: 1; }
.fab {
  position: fixed; z-index: 31; right: max(18px, calc(50% - 320px + 18px)); bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom));
  height: 56px; padding: 0 22px 0 18px; border-radius: 28px; border: 0;
  background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 16px;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 40%, transparent);
  display: flex; align-items: center; gap: 8px;
}
.fab .plus { font-size: 26px; line-height: 1; margin-top: -2px; }
.fab:active { transform: scale(.97); }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--neg); }
.btn.block { width: 100%; }
.btn.sm { height: 36px; padding: 0 12px; border-radius: 10px; font-size: 14px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 2px 5px; }
.input, select.input, textarea.input {
  width: 100%; height: 48px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); outline: none;
  -webkit-appearance: none; appearance: none;
}
textarea.input { height: auto; min-height: 80px; padding: 12px 14px; resize: vertical; }
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 21px, calc(100% - 15px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.big { height: 60px; font-size: 26px; font-weight: 700; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 10px; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; height: 40px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* person chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 7px;
  height: 40px; padding: 0 14px 0 5px; border-radius: 20px;
  border: 1.5px solid var(--line); background: var(--surface); font-weight: 600; font-size: 14px;
}
.chip.on { border-color: var(--pc, var(--accent)); background: color-mix(in srgb, var(--pc, var(--accent)) 14%, var(--surface)); }
.chip.big { height: 52px; padding: 0 16px 0 6px; border-radius: 26px; font-size: 16px; }
.av {
  width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--pc, var(--accent)); color: #fff; font-size: 12px; font-weight: 700; flex: none; text-transform: uppercase;
}
.chip.big .av { width: 40px; height: 40px; font-size: 14px; }
.av.sm { width: 22px; height: 22px; font-size: 10px; }
.avs { display: inline-flex; }
.avs .av { margin-left: -6px; border: 2px solid var(--surface); }
.avs .av:first-child { margin-left: 0; }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }

.banner { padding: 12px 14px; border-radius: 12px; background: var(--warn-bg); color: var(--warn-text); font-size: 14px; margin: 10px 0; }
.banner.info { background: var(--accent-soft); color: var(--accent); }

/* hero numbers */
.hero { padding: 18px; }
.hero .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.hero .value { font-size: 34px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.hero .value small { font-size: 18px; font-weight: 700; color: var(--muted); }
.stats .card { margin-top: 0; }
.topbar a.icon-btn[aria-label="Back"] { font-size: 34px; font-weight: 300; padding-bottom: 4px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.stat { padding: 12px 14px; }
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 19px; font-weight: 700; }

.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

/* bill photo */
.photo-thumb { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; border: 1px solid var(--line); flex: none; background: var(--surface-2); }
.cat-ico { width: 42px; height: 42px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; font-size: 20px; flex: none; }

/* items editor */
.item-edit { padding: 12px 14px; border-top: 1px solid var(--line); }
.item-edit:first-child { border-top: 0; }
.item-edit .orig { font-size: 12px; color: var(--muted); margin: 2px 2px 6px; }
.item-edit .line { display: grid; grid-template-columns: 60px 1fr 1fr 36px; gap: 8px; align-items: end; }
.item-edit .line label span { font-size: 11px; color: var(--muted); display: block; margin: 0 2px 3px; }
.item-edit .input { height: 40px; padding: 0 10px; border-radius: 10px; }
.item-edit .name { font-weight: 600; }
.del { width: 36px; height: 40px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); font-size: 18px; }
.del:active { background: var(--surface-2); color: var(--neg); }

.totals { padding: 4px 16px 12px; }
.totals .t { display: flex; justify-content: space-between; padding: 6px 0; }
.totals .t.strong { font-weight: 700; font-size: 17px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; }

/* assign screen */
.assign-head { position: sticky; top: 61px; z-index: 15; background: var(--bg); padding: 8px 16px 10px; margin: 0 -16px; }
.assign-item {
  display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-top: 1px solid var(--line); cursor: pointer; user-select: none; min-height: 64px;
}
.assign-item:first-child { border-top: 0; }
.assign-item.mine { background: color-mix(in srgb, var(--pc) 12%, var(--surface)); }
.assign-item .check { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; flex: none; font-size: 15px; color: #fff; font-weight: 800; }
.assign-item.mine .check { background: var(--pc); border-color: var(--pc); }
.assign-item.unclaimed .grow .title::after { content: " • unclaimed"; color: var(--warn-text); font-weight: 600; font-size: 12px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.stepper button { width: 34px; height: 34px; border: 0; background: transparent; font-size: 18px; font-weight: 700; }
.stepper span { min-width: 26px; text-align: center; font-weight: 700; }

.sticky-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.sticky-foot .inner { max-width: 608px; margin: 0 auto; }
.person-totals { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 10px; scrollbar-width: none; }
.person-totals::-webkit-scrollbar { display: none; }
.pt { flex: none; display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 4px 10px 4px 4px; border-radius: 16px; background: var(--surface-2); }

/* add sheet / modal */
.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { width: 100%; max-width: 640px; background: var(--bg); border-radius: 22px 22px 0 0; padding: 10px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; animation: up .2s ease-out; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 12px; font-size: 19px; }
.add-opt { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); text-align: left; margin-bottom: 10px; }
.add-opt .big-ico { width: 48px; height: 48px; border-radius: 14px; background: var(--accent-soft); display: grid; place-items: center; font-size: 24px; flex: none; }
.add-opt b { display: block; font-size: 16px; }
.add-opt span { font-size: 13px; color: var(--muted); }
.photo-full { width: 100%; border-radius: 12px; display: block; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }

/* loading */
.loading { position: fixed; inset: 0; z-index: 60; background: color-mix(in srgb, var(--bg) 85%, transparent); display: grid; place-items: center; text-align: center; backdrop-filter: blur(4px); }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabbar) + 90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none; z-index: 70; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; transition: .2s; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 46px; margin-bottom: 8px; }
.empty b { color: var(--text); display: block; font-size: 17px; margin-bottom: 4px; }

details.archived > summary { list-style: none; cursor: pointer; }
details.archived > summary::-webkit-details-marker { display: none; }
.transfer { display: flex; align-items: center; gap: 10px; }
.transfer .arrow { color: var(--muted); }

.dot-spin { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; display: inline-block; animation: spin .8s linear infinite; }

/* category picker */
.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cat-tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 84px; padding: 8px 4px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); font-size: 12.5px; font-weight: 600; text-align: center; line-height: 1.2; }
.cat-tile span { font-size: 26px; line-height: 1; }
.cat-tile.on { border-color: var(--accent); background: var(--accent-soft); }

/* paste area */
.paste-zone { min-height: 190px; border: 2px dashed var(--line); border-radius: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 20px; background: var(--surface); outline: none; caret-color: transparent; -webkit-user-select: text; user-select: text; }
.paste-zone:focus { border-color: var(--accent); background: var(--accent-soft); }
