:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #efede6;
  --text: #1c2420;
  --muted: #66706b;
  --line: #e2dfd6;
  --brand: #1d6b52;
  --brand-ink: #ffffff;
  --brand-soft: #dcefe6;
  /* People: Ryan is blue, Carissa is pink, Split is purple. --me / --partner
     point at one of them; supa.js swaps them on Carissa's phone. */
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --pink: #db2777;
  --pink-soft: #fce7f3;
  --split: #7c4dbd;
  --split-soft: #ede4f8;
  --me: var(--blue);
  --me-soft: var(--blue-soft);
  --partner: var(--pink);
  --partner-soft: var(--pink-soft);
  --danger: #b3362c;
  --danger-soft: #fbe5e2;
  --warn-soft: #fff3d1;
  --warn-ink: #7a5a00;
  --radius: 0;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 14px rgb(0 0 0 / .05);
  --tabbar-h: 68px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1714;
    --surface: #17211d;
    --surface-2: #1f2b26;
    --text: #e7ece9;
    --muted: #93a29b;
    --line: #2a3832;
    --brand: #4fbf93;
    --brand-ink: #08130f;
    --brand-soft: #18362b;
    --blue: #60a5fa;
    --blue-soft: #172a46;
    --pink: #f472b6;
    --pink-soft: #3d1a2e;
    --split: #b896ec;
    --split-soft: #2a2140;
    --danger: #f08a80;
    --danger-soft: #3d1f1c;
    --warn-soft: #3a3115;
    --warn-ink: #f1d47a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1714; --surface: #17211d; --surface-2: #1f2b26; --text: #e7ece9; --muted: #93a29b;
  --line: #2a3832; --brand: #4fbf93; --brand-ink: #08130f; --brand-soft: #18362b;
  --blue: #60a5fa; --blue-soft: #172a46; --pink: #f472b6; --pink-soft: #3d1a2e;
  --split: #b896ec; --split-soft: #2a2140; --danger: #f08a80; --danger-soft: #3d1f1c;
  --warn-soft: #3a3115; --warn-ink: #f1d47a; --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: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
body.page-login { padding-bottom: 32px; }
a { color: var(--brand); }
img { max-width: 100%; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

.container { max-width: 640px; margin: 0 auto; padding: 16px; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 0;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
/* Show the moon in light mode (tap for dark) and the sun in dark mode. */
.icon-btn .sun { display: none; }
:root[data-theme="dark"] .icon-btn .sun { display: block; }
:root[data-theme="dark"] .icon-btn .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-btn .sun { display: block; }
  :root:not([data-theme="light"]) .icon-btn .moon { display: none; }
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
/* The tab you're on: reversed, a solid brand-colour block with light icon and word. */
.tab.active { background: var(--brand); color: var(--brand-ink); }
.tab.active span { font-weight: 700; }
.unit-toggle { display: inline-flex; margin-left: 8px; vertical-align: middle; border: 1px solid var(--line); border-radius: 0; overflow: hidden; }
.unit-toggle button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: .8rem; font-weight: 700; padding: 3px 10px; cursor: pointer; }
.unit-toggle button[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 0;
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card-tight { padding: 0; overflow: hidden; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 0; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 650;
  cursor: pointer; text-decoration: none; touch-action: manipulation;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 1.05rem; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .85rem; border-radius: 0; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 0;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.field { margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-2 > .field { margin-bottom: 0; }

/* Balance hero */
.balance { text-align: center; padding: 22px 16px; }
.balance-amount { font-size: 2.4rem; font-weight: 800; letter-spacing: -.02em; margin: 4px 0; }
.balance-label { color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 0; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 1.05rem; }
.stat span { font-size: .75rem; color: var(--muted); }
/* Prices: lowest green, average yellow, highest red. */
.stat-low { background: var(--brand-soft); color: var(--brand); }
.stat-avg { background: var(--warn-soft); color: var(--warn-ink); }
.stat-high { background: var(--danger-soft); color: var(--danger); }
/* Home: each person in their colour, together in the split purple. */
.stat-me { background: var(--me-soft); color: var(--me); }
.stats .stat-partner { background: var(--partner-soft); color: var(--partner); }
.stat-together { background: var(--split-soft); color: var(--split); }
.stat-low span, .stat-avg span, .stat-high span,
.stat-me span, .stats .stat-partner span, .stat-together span { color: inherit; opacity: .85; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-top: 1px solid var(--line); color: inherit; text-decoration: none;
}
.list-item:first-child { border-top: 0; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub { font-size: .8rem; color: var(--muted); }
.list-amount { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 0; font-size: .72rem; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.pill-me { background: var(--me-soft); color: var(--me); }
.pill-partner { background: var(--partner-soft); color: var(--partner); }

/* Capture */
.capture { text-align: center; padding: 28px 16px; }
.search-field { position: relative; }
.search-field svg { position: absolute; left: 12px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.search-field input { padding-left: 42px; }
.stat-icon { display: block; width: 40px; height: 40px; margin: -4px auto 0; font-size: 30px; font-style: normal; line-height: 40px; }
.btn-stack { display: grid; gap: 10px; }
.btn-stack .btn { gap: 10px; }
.btn-emoji { width: 42px; height: 42px; flex: none; }.thumbs { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; }
.thumb { position: relative; flex: 0 0 auto; }
.thumb img { width: 84px; height: 112px; object-fit: cover; border-radius: 0; border: 1px solid var(--line); display: block; }
.thumb button {
  position: absolute; top: -6px; right: -6px; width: 26px; height: 26px; border-radius: 0;
  border: 0; background: var(--text); color: var(--bg); font-weight: 800; cursor: pointer; line-height: 1;
}
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.spinner {
  width: 42px; height: 42px; margin: 6px auto 12px; border-radius: 50%;
  border: 4px solid var(--brand-soft); border-top-color: var(--brand); animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* Item assignment */
.bulk { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.bulk span { font-size: .85rem; color: var(--muted); font-weight: 600; margin-right: auto; }
.item { padding: 12px 16px; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item-row { display: flex; gap: 8px; align-items: center; }
.item-desc { flex: 1; min-width: 0; border-color: transparent; background: transparent; padding-left: 4px; font-weight: 600; }
.item-desc:hover { border-color: var(--line); }
.item-amount { width: 96px; flex: 0 0 96px; text-align: right; font-variant-numeric: tabular-nums; }
.item-raw { font-size: .75rem; color: var(--muted); margin: 2px 4px 8px; font-family: ui-monospace, monospace; }
.item-del { flex: 0 0 auto; width: 36px; min-height: 36px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 1.3rem; cursor: pointer; border-radius: 0; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.seg button {
  min-height: 38px; border-radius: 0; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font: inherit; font-size: .85rem; font-weight: 650; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px; touch-action: manipulation;
}
.seg button[aria-pressed="true"][data-who="me"] { background: var(--me-soft); border-color: var(--me); color: var(--me); }
.seg button[aria-pressed="true"][data-who="partner"] { background: var(--partner-soft); border-color: var(--partner); color: var(--partner); }
.seg button[aria-pressed="true"][data-who="split"] { background: var(--split-soft); border-color: var(--split); color: var(--split); }
.item[data-who="me"] { border-left: 4px solid var(--me); }
.item[data-who="partner"] { border-left: 4px solid var(--partner); }
.item[data-who="split"] { border-left: 4px solid var(--split); }

/* Every list entry, and every item on a receipt, sits in its own box. */
.card-tight:has(> .list), .item-boxes { background: transparent; border: 0; box-shadow: none; overflow: visible; }
.list > li, .item-boxes > .bulk, .item-boxes .item, .item-boxes > .add-row {
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); margin-bottom: 8px;
}
.list > li:last-child { margin-bottom: 0; }
/* The box draws the border now, so drop the old row dividers. */
.list > li > .list-item, .list > li > .list-button { border-top: 0; }
.list > li.list-item, .list > li.list-item:first-child, .item-boxes .item:first-of-type { border-top: 1px solid var(--line); }
.item-boxes > .bulk { background: var(--surface-2); }
.item-boxes > .add-row { padding: 10px 16px; margin-bottom: 0; }
/* Prices screen */
.list-button { width: 100%; border: 0; border-top: 1px solid var(--line); background: transparent; font: inherit; text-align: left; cursor: pointer; }
li:first-child > .list-button { border-top: 0; }
.check-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 64px 84px; gap: 8px; align-items: center; }
.check-row input { font-size: 1.25rem; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; min-width: 0; }
.check-for { color: var(--muted); font-weight: 600; }
.verdict { margin-top: 12px; padding: 12px 14px; border-radius: 0; background: var(--surface-2); }
.verdict b { display: block; font-size: 1.05rem; }
.verdict span { font-size: .85rem; opacity: .85; }
.verdict-best, .verdict-good { background: var(--brand-soft); color: var(--brand); }
.verdict-high, .verdict-worst { background: var(--danger-soft); color: var(--danger); }

/* Price-tracking row under each item: product name, amount, unit. */
.track-row { display: grid; grid-template-columns: minmax(0, 1fr) 64px 64px; gap: 6px; align-items: center; margin: 6px 0 2px; }
/* Product icons (OpenMoji, or a plain tag when there's no emoji yet). */
.emoji { display: block; width: 100%; height: 100%; }
.emoji-tag { padding: 18%; box-sizing: border-box; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linejoin: round; }
.track-icon, .product-icon { display: inline-grid; place-items: center; flex: none; line-height: 1; }
.track-icon { width: 30px; height: 30px; font-size: 24px; }
.product-icon { width: 36px; height: 36px; font-size: 28px; margin-right: 10px; }
h1 .product-icon { width: 44px; height: 44px; font-size: 34px; vertical-align: middle; }.track-row input, .track-row select { min-height: 34px; padding: 4px 8px; font-size: .85rem; border-radius: 0; color: var(--muted); }
.track-row input:focus, .track-row select:focus { color: var(--text); }
.track-row input[type="number"] { text-align: right; }

/* On Carissa's phone, put Ryan's (the partner's) tiles and buttons first. */
.swap-people .summary .partner,
.swap-people .stat-partner { order: -1; }
.swap-people .stats .stat-me { order: 1; } /* Ryan · Together · Carissa */
.swap-people #bulk-partner { order: 1; }
.swap-people [data-bulk="split"] { order: 2; }
.swap-people #bulk-me { order: 3; }
.split-row { display: grid; grid-template-columns: auto 1fr 1fr; gap: 8px; align-items: end; margin-top: 8px; }
.split-row [data-even] { min-height: 40px; }
.split-row [data-even][aria-pressed="true"] { background: var(--split-soft); border-color: var(--split); color: var(--split); }
.split-field { margin: 0; font-size: .75rem; }
.split-field span { display: block; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.split-field input { min-height: 40px; text-align: right; font-variant-numeric: tabular-nums; }

.totals .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; }
.totals .row input { width: 110px; text-align: right; min-height: 40px; }
.totals .row.total { font-weight: 800; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.alert { padding: 10px 12px; border-radius: 0; font-size: .9rem; margin-bottom: 12px; }
.alert-warn { background: var(--warn-soft); color: var(--warn-ink); }
.alert-error { background: var(--danger-soft); color: var(--danger); }

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.summary div { border-radius: 0; padding: 10px 12px; }
.summary .me { background: var(--me-soft); color: var(--me); }
.summary .partner { background: var(--partner-soft); color: var(--partner); }
.summary b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.summary span { font-size: .8rem; font-weight: 600; }

.sticky-actions {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
  padding-top: 14px; background: linear-gradient(transparent, var(--bg) 14px);
}

.receipt-photos { display: flex; gap: 8px; overflow-x: auto; }
.receipt-photos img { height: 160px; border-radius: 0; border: 1px solid var(--line); }

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


.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 0;
  font-weight: 600; font-size: .9rem; transition: .2s; max-width: calc(100% - 32px); text-align: center; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

dialog {
  border: 0; border-radius: 0; padding: 20px; width: min(420px, calc(100% - 32px));
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
