:root {
  --ground: #EEF1F4;
  --card: #FFFFFF;
  --ink: #15191E;
  --muted: #4E5862;
  --line: #DDE2E8;
  --control: #CBD2D9;
  --accent: #3346C8;
  --ok: #13684F;
  --danger: #A3361F;
  --dark-label: #C9D0D7;
  --tab-off: #5F6872;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ground); color: var(--ink); }
body { font-family: 'Instrument Sans', system-ui, -apple-system, sans-serif; -webkit-text-size-adjust: 100%; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, .scan:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
input::placeholder { color: #8A939D; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#app {
  max-width: 560px; margin: 0 auto; height: 100%; height: 100dvh;
  display: flex; flex-direction: column; position: relative; overflow: hidden;
}

/* header */
.top { padding: calc(env(safe-area-inset-top) + 16px) 20px 12px; display: flex; flex-direction: column; gap: 6px; }
.top-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.trip { font-weight: 600; letter-spacing: 0.02em; }
h1 { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
h2 { margin: 10px 4px 0; font-size: 17px; font-weight: 700; }
.tally { display: flex; gap: 8px; margin: 8px -20px 0; padding: 0 20px 2px; overflow-x: auto; scrollbar-width: none; }
.tally::-webkit-scrollbar { display: none; }
.tcard { flex: 1 0 104px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tname { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; min-width: 0; }
.tamt { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.tlbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* main */
main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px 28px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.gap-lg { gap: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card.tight { padding: 4px 16px; gap: 0; }
.card.dark { background: var(--ink); color: #FFFFFF; border-color: var(--ink); }
.card.split { flex-direction: row; justify-content: space-between; align-items: flex-end; }
.card.center, .center { align-items: center; text-align: center; }
.row-compact { flex-direction: row; align-items: center; justify-content: space-between; padding: 12px 16px; }
.grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.right { text-align: right; align-items: flex-end; }
.strong { font-weight: 600; }
.big { font-size: 18px; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.pad { padding: 24px 4px; }
.pad-y { padding: 10px 0 12px; margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.hero { display: block; font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.mid { display: block; font-size: 22px; font-weight: 700; }
.lbl { font-size: 13px; font-weight: 600; color: var(--muted); }
.lbl-dark { display: block; font-size: 13px; color: var(--dark-label); }
.lbl-dark-soft { color: var(--dark-label); }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.section-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 4px 0; }
.section-head h2 { margin: 0; }
.lead { margin: 0; padding: 0 4px; font-size: 15px; color: #3F4852; }

/* buttons */
.btn { text-decoration: none; color: var(--ink); min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--control); background: var(--card); font-size: 15px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--ink); color: #FFFFFF; border-color: var(--ink); }
.btn.big { min-height: 54px; font-size: 16px; font-weight: 700; border-radius: 14px; }
.btn:disabled { background: #D5DAE0; color: var(--muted); border-color: #D5DAE0; cursor: not-allowed; }
.btn.danger { color: var(--danger); align-self: flex-start; }
.btn.ghost-dark { background: transparent; color: #FFFFFF; border-color: #8A939D; }
.link { background: none; border: 0; padding: 0 4px; min-height: 44px; color: var(--accent); font-weight: 600; font-size: 14px; }
.link.small { font-size: 13px; min-height: 32px; align-self: flex-start; padding: 0; }
.link.center { align-self: center; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--control); background: var(--card); font-size: 14px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.chip.on { background: var(--ink); color: #FFFFFF; border-color: var(--ink); }
.chip svg { width: 16px; height: 16px; stroke-width: 2.5; }
.grid3 .chip { border-radius: 12px; font-weight: 600; font-size: 15px; min-width: 0; padding: 0 8px; }
.wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--control); border-radius: 12px; overflow: hidden; background: var(--card); }
.seg button { min-height: 44px; border: 0; background: var(--card); font-weight: 600; font-size: 15px; }
.seg button.on { background: var(--ink); color: #FFFFFF; }

/* avatars */
.av { border-radius: 50%; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.av-xs { width: 18px; height: 18px; font-size: 10px; }
.av-sm { width: 24px; height: 24px; font-size: 11px; }
.av-md { width: 32px; height: 32px; font-size: 13px; }
.av-lg { width: 40px; height: 40px; font-size: 16px; }
.av-dot { width: 24px; height: 24px; font-size: 10px; border: 2px solid #FFFFFF; margin-left: -6px; }
.dots { display: flex; padding-left: 6px; }

/* add form */
.field { display: flex; flex-direction: column; gap: 6px; }
.field input { height: 48px; border: 1px solid var(--control); border-radius: 12px; background: var(--card); padding: 0 14px; font-size: 16px; width: 100%; }
.amount { gap: 4px; padding: 14px 16px; }
.amount-row { display: flex; align-items: baseline; gap: 6px; }
.cur { font-size: 30px; font-weight: 600; color: var(--muted); }
.amount input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; padding: 0; }
.exact-row { display: flex; align-items: center; gap: 12px; min-height: 56px; border-bottom: 1px solid var(--ground); }
.exact-row input { width: 112px; height: 40px; border: 1px solid var(--control); border-radius: 10px; padding: 0 10px; text-align: right; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.status { margin: 0; padding: 12px 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.status.ok { color: var(--ok); }
.receipt { flex-direction: row; align-items: center; gap: 14px; padding: 14px 16px; }
.thumb { width: 56px; height: 72px; border-radius: 8px; border: 1px solid var(--line); background: var(--ground); flex-shrink: 0; padding: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan { position: relative; flex-shrink: 0; font-size: 14px; }
.scan svg { width: 18px; height: 18px; stroke-width: 2; }
.scan input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

/* ledger */
.entry { padding: 0; gap: 0; overflow: hidden; }
.entry-head { width: 100%; border: 0; background: transparent; text-align: left; padding: 14px 16px; display: flex; gap: 12px; align-items: flex-start; }
.entry-head .strong { font-size: 16px; }
.entry-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.entry-body { border-top: 1px solid #E6EAEE; background: #F7F8FA; padding: 12px 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.with-thumb { display: flex; align-items: center; gap: 12px; align-self: flex-start; padding: 0; }
.with-thumb img { width: 44px; height: 58px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }

/* settle */
.transfer { display: flex; align-items: center; gap: 10px; }
.arrow svg { width: 28px; height: 20px; stroke: var(--muted); stroke-width: 2; }
.table { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, 1fr); gap: 8px; padding: 12px 0; font-size: 14px; border-bottom: 1px solid var(--ground); }
.table span:not(:first-child) { text-align: right; }
.table.head { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; padding: 10px 0; }
.summary { margin: 0; font-size: 14px; line-height: 1.5; white-space: pre-line; }
.ok-icon svg { width: 36px; height: 36px; stroke: #13806F; stroke-width: 2.4; }

/* nav */
.tabs { flex-shrink: 0; background: var(--card); border-top: 1px solid var(--line); display: flex; padding: 0 8px env(safe-area-inset-bottom); min-height: 68px; }
.tab { flex: 1; border: 0; background: transparent; font-size: 11px; font-weight: 600; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--tab-off); min-height: 64px; }
.tab.on { color: var(--ink); }
.addbubble { width: 36px; height: 36px; border-radius: 50%; background: var(--ink); color: #FFFFFF; display: flex; align-items: center; justify-content: center; }
.addbubble svg { width: 20px; height: 20px; stroke-width: 2.4; }

/* overlays */
.toast { position: absolute; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 84px); background: var(--ink); color: #FFFFFF; border-radius: 12px; padding: 14px 16px; font-size: 14px; font-weight: 600; z-index: 4; }
.viewer { position: absolute; inset: 0; z-index: 5; background: rgba(10, 12, 15, 0.94); padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 24px); display: flex; flex-direction: column; gap: 12px; }
.viewer-bar { display: flex; justify-content: flex-end; }
.viewer img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }

/* setup */
.setup { display: flex; flex-direction: column; gap: 16px; padding: calc(env(safe-area-inset-top) + 48px) 24px 24px; }
.setup p { margin: 0; font-size: 16px; line-height: 1.5; }

/* trips & people */
.trip-switch, .back { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; min-width: 0; max-width: 70%; padding: 0; border: 0; background: none; font-size: 15px; font-weight: 700; color: var(--ink); }
.trip-switch svg, .back svg { width: 20px; height: 20px; flex-shrink: 0; stroke-width: 2.2; }
.back { font-weight: 600; color: var(--accent); }
.top .seg { margin-top: 8px; }
.trip-card { padding: 0; gap: 0; overflow: hidden; }
.trip-card.current { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.trip-open { width: 100%; border: 0; background: none; text-align: left; padding: 16px 16px 8px; display: flex; gap: 12px; align-items: flex-start; }
.trip-foot { display: flex; justify-content: space-between; align-items: center; padding: 0 16px 4px; }
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; background: var(--ink); color: #FFFFFF; border-radius: 999px; padding: 4px 8px; }
.list-row { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 8px 0; border-bottom: 1px solid var(--ground); }
.list-row:last-child { border-bottom: 0; }
.list-row.as-button { width: 100%; border-left: 0; border-right: 0; border-top: 0; background: none; text-align: left; }
.small-btn { min-height: 40px; font-size: 14px; padding: 0 12px; }
.note { margin: -4px 4px 0; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--card); box-shadow: 0 0 0 1px var(--control); padding: 0; }
.swatch.on { box-shadow: 0 0 0 3px var(--ink); }
.picker { margin-top: 8px; gap: 12px; border-color: var(--ink); }
.newperson { display: flex; flex-direction: column; gap: 8px; }
.newperson input { height: 48px; border: 1px solid var(--control); border-radius: 12px; background: var(--card); padding: 0 14px; font-size: 16px; width: 100%; min-width: 0; }
.add-chip { border-style: dashed; min-height: 48px; color: var(--accent); }
.add-chip.on { border-style: solid; }
.add-chip svg { stroke-width: 2.2; }
.wrap .chip { min-height: 44px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.row-btns .btn { flex: 1 1 auto; }
.btn.danger { align-self: auto; }
.stack > .btn.danger { align-self: flex-start; }

/* sign-in & access */
.seg.seg3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.setup .field input { height: 52px; border: 1px solid var(--control); border-radius: 12px; background: var(--card); padding: 0 14px; font-size: 17px; width: 100%; }
.code-input { letter-spacing: 0.3em; font-variant-numeric: tabular-nums; font-weight: 700; }
.auth-msg { margin: 0; font-size: 14px; font-weight: 600; color: var(--danger); }
.setup .card .field { margin-top: 4px; }
.setup .row-btns { justify-content: space-between; }
