:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --text: #1c1b18;
  --muted: #6b6860;
  --line: #e2e0d8;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d8efec;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --good: #1a7f37;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  color-scheme: light;
}
/* Dark colours: when the person picks Dark mode in their profile (data-theme="dark"), or when
   their device is in dark mode and they haven't picked Light. Same values in both places. */
:root[data-theme="dark"] {
  --bg: #121311;
  --surface: #1b1d1a;
  --surface-2: #242622;
  --text: #ecebe6;
  --muted: #a09d94;
  --line: #2f322d;
  --accent: #2dd4bf;
  --accent-ink: #062a26;
  --accent-soft: #123b36;
  --danger: #ff8a7a;
  --danger-soft: #3a1915;
  --warn: #f5c451;
  --warn-soft: #3a2f12;
  --good: #5fd27a;
  --shadow: none;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121311;
    --surface: #1b1d1a;
    --surface-2: #242622;
    --text: #ecebe6;
    --muted: #a09d94;
    --line: #2f322d;
    --accent: #2dd4bf;
    --accent-ink: #062a26;
    --accent-soft: #123b36;
    --danger: #ff8a7a;
    --danger-soft: #3a1915;
    --warn: #f5c451;
    --warn-soft: #3a2f12;
    --good: #5fd27a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hidden, [hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.logo { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: 0.9rem; }
#topnav { display: flex; gap: 8px; align-items: center; }

main { max-width: 760px; margin: 0 auto; padding: 20px 16px 96px; display: grid; gap: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.right { text-align: right; }

button, .btn {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); padding: 8px 14px; min-height: 38px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
button:hover { border-color: color-mix(in srgb, var(--text) 30%, var(--line)); }
button:disabled { opacity: 0.55; cursor: default; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: var(--surface-2); }
button.danger { color: var(--danger); }
button.small { min-height: 30px; padding: 4px 10px; font-size: 0.85rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; min-height: 38px; width: 100%; min-width: 0;
}
/* Draw our own dropdown arrow so it sits a comfortable distance from the right edge. */
select {
  appearance: none; -webkit-appearance: none; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238f8c84' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center; background-size: 12px 8px;
}
textarea { min-height: 140px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }
label { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); }
label > span { font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; margin: 0; }
label.check > span { font-weight: 400; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.money { position: relative; }
.money input { padding-left: 22px; text-align: right; }
.money::before { content: attr(data-sym); position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 0.9rem; }

.auth { max-width: 400px; margin: 6vh auto 0; }
.auth h1 { font-size: 2rem; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; overflow-x: auto; }
.tabs button { flex: 1; border: 0; background: transparent; min-height: 34px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

.list { display: grid; gap: 0; }
.list > * { padding: 12px 0; border-top: 1px solid var(--line); }
.list > *:first-child { border-top: 0; }
.list-link { display: flex; align-items: center; gap: 12px; color: inherit; }
.list-link:hover { text-decoration: none; }
.list-link:hover .title { color: var(--accent); }
.title { font-weight: 600; }

.amount { font-weight: 600; white-space: nowrap; }
.pos { color: var(--good); }
.neg { color: var(--danger); }

.badge { display: inline-block; font-size: 0.72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.badge.draft { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--danger-soft); color: var(--danger); }

.avatar { --h: 170; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; flex: none; font-size: 0.78rem; font-weight: 700; background: hsl(var(--h) 55% 88%); color: hsl(var(--h) 60% 25%); }
[data-theme="dark"] .avatar { background: hsl(var(--h) 35% 26%); color: hsl(var(--h) 70% 85%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .avatar { background: hsl(var(--h) 35% 26%); color: hsl(var(--h) 70% 85%); } }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  --h: 170; min-height: 32px; padding: 3px 10px 3px 3px; border-radius: 999px; gap: 6px; font-size: 0.85rem;
  border: 1px dashed var(--line); background: transparent; color: var(--muted);
}
.chip .avatar { width: 24px; height: 24px; font-size: 0.68rem; filter: grayscale(1); opacity: 0.6; }
.chip[aria-pressed="true"] { border-style: solid; border-color: hsl(var(--h) 45% 60%); background: hsl(var(--h) 55% 95%); color: var(--text); }
.chip[aria-pressed="true"] .avatar { filter: none; opacity: 1; }
[data-theme="dark"] .chip[aria-pressed="true"] { background: hsl(var(--h) 30% 18%); border-color: hsl(var(--h) 40% 45%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip[aria-pressed="true"] { background: hsl(var(--h) 30% 18%); border-color: hsl(var(--h) 40% 45%); } }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; min-height: 28px; padding: 2px 10px; font-size: 0.82rem; color: var(--muted); border-radius: 8px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 10px; background: var(--surface); }
.item.unassigned { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.item.has-error { border-color: color-mix(in srgb, var(--danger) 55%, var(--line)); }
.item-head { display: flex; gap: 8px; align-items: baseline; }
.item-name { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.qty { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.alloc { display: grid; gap: 6px; }
.alloc-row { display: grid; grid-template-columns: 1fr 110px 84px; gap: 8px; align-items: center; font-size: 0.9rem; }
.alloc-row.equal { grid-template-columns: 1fr 84px; }
.alloc.invalid .amount { opacity: 0.45; }
.alloc-row .who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.alloc-row .who span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alloc-row input { min-height: 32px; padding: 4px 8px; text-align: right; }
.suffix { position: relative; }
.suffix input { padding-right: 26px; }
.suffix::after { content: attr(data-suffix); position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 0.82rem; }
.err { color: var(--danger); font-size: 0.85rem; }
.note { padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 0.88rem; white-space: pre-line; }
.note.info { background: var(--accent-soft); color: var(--accent); }

.summary-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.summary-row:first-child { border-top: 0; }
.breakdown { grid-column: 1 / -1; font-size: 0.8rem; color: var(--muted); padding-left: 38px; }

.stat { display: grid; gap: 2px; }
.stat .big { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; }

.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; letter-spacing: 0.12em; background: var(--surface-2); padding: 3px 8px; border-radius: 8px; }

.preview { width: 100%; max-height: 380px; object-fit: contain; border-radius: 10px; background: var(--surface-2); cursor: zoom-in; }
.preview.zoom { max-height: none; cursor: zoom-out; }
details > summary { cursor: pointer; color: var(--muted); font-size: 0.88rem; }
pre.source { white-space: pre-wrap; font-size: 0.8rem; max-height: 300px; overflow: auto; background: var(--surface-2); padding: 10px; border-radius: 10px; margin: 8px 0 0; }

.dropzone { border: 2px dashed var(--line); border-radius: 14px; padding: 28px 16px; text-align: center; display: grid; gap: 8px; place-items: center; cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }

.fab { position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 5; box-shadow: 0 6px 20px rgb(0 0 0 / 0.18); border-radius: 999px; padding: 12px 20px; }

dialog#sheet { border: 0; padding: 0; border-radius: 18px; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / 0.3); }
dialog#sheet::backdrop { background: rgb(0 0 0 / 0.4); }
.sheet-body { padding: 18px; display: grid; gap: 14px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: calc(100vw - 32px); font-size: 0.9rem; }
#toast.error { background: var(--danger); color: #fff; }

.empty { text-align: center; padding: 28px 12px; color: var(--muted); display: grid; gap: 10px; justify-items: center; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 520px) {
  main { padding-top: 14px; }
  h1 { font-size: 1.35rem; }
  .alloc-row { grid-template-columns: 1fr 92px 74px; }
  .alloc-row.equal { grid-template-columns: 1fr 74px; }
  .hide-sm { display: none; }
}

/* ---- sync + currency ------------------------------------------------------------------- */
.pill { min-height: 28px; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; gap: 6px; border: 0; background: var(--surface-2); color: var(--muted); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.offline { background: var(--warn-soft); color: var(--warn); }
.pill.syncing { background: var(--accent-soft); color: var(--accent); }
.pill.failed { background: var(--danger-soft); color: var(--danger); }
.badge.pending { background: var(--accent-soft); color: var(--accent); }
.fx-line { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 0.85rem; color: var(--muted); padding: 8px 10px; background: var(--surface-2); border-radius: 10px; }
.fx-line strong { color: var(--text); font-weight: 600; }
.approx { color: var(--muted); font-size: 0.8rem; font-weight: 500; white-space: nowrap; }
.item.pending-sync { border-style: dashed; }
.fab-group { position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 5; display: flex; gap: 8px; }
.fab-group .fab { position: static; }

/* Shopping list */
.shop-row { display: flex; align-items: flex-start; gap: 12px; }
.shop-main { all: unset; cursor: pointer; flex: 1; min-width: 0; display: grid; gap: 2px; }
.shop-main:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.shop-main:hover .title { color: var(--accent); }
.shop-row.bought .title { text-decoration: line-through; color: var(--muted); }
.tick { flex: none; width: 28px; height: 28px; min-height: 28px; padding: 0; border-radius: 50%; border: 2px solid var(--line); background: transparent; color: transparent; display: grid; place-items: center; font-weight: 700; font-size: 0.9rem; }
.tick:hover { border-color: var(--accent); color: var(--accent); }
.tick[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.match-row { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.match-row input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; margin: 2px 0 0; padding: 0; flex: none; accent-color: var(--accent); }

.list-tabs { justify-self: start; }
.list-tabs button { min-height: 34px; padding: 4px 14px; font-size: 0.9rem; }
.split-offer { display: flex; align-items: center; gap: 10px; margin: -4px 0 0 40px; padding: 8px 10px !important; border: 1px dashed var(--accent) !important; border-radius: 10px; background: var(--accent-soft); }
.nudge { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); width: min(420px, calc(100vw - 24px)); z-index: 30; display: grid; gap: 10px; box-shadow: 0 8px 30px rgb(0 0 0 / 0.25); border: 1px solid var(--accent); animation: nudge-in 0.25s ease-out; }
@keyframes nudge-in { from { opacity: 0; transform: translate(-50%, 12px); } }
@media (prefers-reduced-motion: reduce) { .nudge { animation: none; } }

/* ---- group screen: header, Expenses / Balances / Photos ---------------------------------------- */
.group-head { display: grid; justify-items: center; gap: 6px; text-align: center; margin-top: -4px; }
.group-emoji { font-size: 3.4rem; line-height: 1; }
.group-head h1 { font-size: 1.9rem; }
.group-tabs { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface-2); padding: 4px; border-radius: 999px; gap: 4px; }
.group-tabs button { border: 0; border-radius: 999px; background: transparent; color: var(--text); min-height: 40px; font-weight: 500; padding: 4px 6px; font-size: 0.92rem; }
.group-tabs button[aria-selected="true"] { background: color-mix(in srgb, var(--text) 18%, var(--surface)); font-weight: 600; }
.totals { display: grid; grid-template-columns: 1fr 1fr; text-align: center; gap: 8px; }
.totals .big { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photo-tile { display: grid; gap: 6px; color: inherit; }
.photo-tile:hover { text-decoration: none; }
.photo-tile .thumb { aspect-ratio: 3 / 4; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; display: grid; place-items: center; font-size: 2rem; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.group-avatar { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); font-size: 1.4rem; flex: none; }
.badge.guest { background: var(--surface-2); color: var(--muted); }

/* ---- create a group ---------------------------------------------------------------------------- */
.create { max-width: 520px; width: 100%; margin: 0 auto; display: grid; gap: 18px; }
.create h3 { font-size: 1rem; }
.title-row { display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: center; }
.emoji-btn { width: 56px; height: 56px; border-radius: 50%; font-size: 1.7rem; padding: 0; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.emoji-grid button { font-size: 1.6rem; min-height: 48px; padding: 0; }
.emoji-grid button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.grouped { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.grouped > * { border-top: 1px solid var(--line); }
.grouped > :first-child { border-top: 0; }
.grouped-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; min-height: 52px; }
.grouped-row input, .grouped-row select { border: 0; background: transparent; padding: 6px 0; }
.grouped-row select { width: auto; text-align: right; color: var(--muted); }
.grouped-row input:focus-visible, .grouped-row select:focus-visible { outline: none; }
.grouped-row:focus-within { background: var(--surface-2); }
.me-badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 2px 10px; font-size: 0.8rem; font-weight: 600; }
.link-btn { border: 0; background: transparent; color: var(--accent); justify-content: flex-start; padding: 10px 14px; min-height: 48px; width: 100%; border-radius: 0; }
.create .primary.big { min-height: 52px; border-radius: 999px; font-size: 1.05rem; }

/* ---- profile ----------------------------------------------------------------------------------- */
.profile-head { display: grid; justify-items: center; gap: 4px; text-align: center; }
.profile-head .avatar { width: 96px; height: 96px; font-size: 2.2rem; }
.profile-head h1 { margin-top: 8px; }
.setting { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 14px; min-height: 60px; border: 0; border-radius: 0; background: transparent; text-align: left; white-space: normal; }
button.setting:hover { background: var(--surface-2); }
.setting .icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; flex: none; font-size: 1.1rem; background: hsl(var(--h) 45% 88%); }
[data-theme="dark"] .setting .icon { background: hsl(var(--h) 35% 24%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .setting .icon { background: hsl(var(--h) 35% 24%); } }
.setting .label { flex: 1; min-width: 0; display: grid; }
.setting .label small { color: var(--muted); font-size: 0.8rem; }
.setting .label span { overflow-wrap: anywhere; }
.setting .value { color: var(--muted); }
.setting .chev { color: var(--muted); font-size: 1.2rem; }
.setting.danger-row { color: var(--danger); }
.choice { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.choice input { width: auto; min-height: 0; margin: 0; }

/* Shopping tab: "Whose list" selector */
.whose { display: flex; align-items: center; gap: 10px; color: var(--text); }
.whose > span { font-weight: 600; white-space: nowrap; }

/* Amounts on the right of a row stay on one line ("your share $2.00"). */
.list-link .right { flex: none; }
.list-link .right .small, .list-link .right .approx { white-space: nowrap; }

/* Shopping lists as cards, each opening its own page (2026-12-02). */
.list-card .list-emoji { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 12px; background: var(--accent-soft); font-size: 1.5rem; }
.list-card .title { display: block; }
.list-card .chev { color: var(--muted); font-size: 1.3rem; flex: none; }
.emoji-grid.small-grid { grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); }
.emoji-grid.small-grid button { min-height: 40px; font-size: 1.3rem; }
span.emoji-btn { display: grid; place-items: center; flex: none; border: 1px solid var(--border); }
#receipt-lists .chip { padding: 6px 12px; }
#add-entry .field-row { align-items: start; }
