:root {
  --teal: #0f766e;
  --teal-dark: #0b5852;
  --teal-light: #ccfbf1;
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --danger: #dc2626;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

body {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(48px + env(safe-area-inset-bottom)) 16px;
}

.app-header {
  text-align: center;
  padding: 24px 0 8px;
}
.app-header h1 { margin: 0; font-size: 2rem; letter-spacing: -0.02em; }
.tagline { margin: 4px 0 0; color: var(--muted); font-size: 0.95rem; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin-top: 16px;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 10px;
}
.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: var(--teal);
  color: #fff;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 700;
  flex: none;
}

/* Buttons */
button { font: inherit; cursor: pointer; }
.btn-primary {
  background: var(--teal);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-primary:active { background: var(--teal-dark); }
.btn-secondary {
  background: var(--teal-light);
  color: var(--teal-dark);
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-ghost {
  background: transparent;
  color: var(--teal-dark);
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 600;
}

/* People */
.people-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.person-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--teal-light);
  color: var(--teal-dark);
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  font-weight: 600;
  font-size: 0.95rem;
}
.person-chip .remove {
  border: none;
  background: rgba(15, 118, 110, 0.18);
  color: var(--teal-dark);
  width: 22px; height: 22px;
  border-radius: 50%;
  line-height: 1;
  font-size: 1rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.add-person { display: flex; gap: 8px; }
.add-person input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
}

/* Grouping into couples */
.grouping { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.grouping-label { margin: 0 0 10px; color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.grouping-rows { display: flex; flex-direction: column; gap: 8px; }
.grouping-row { display: flex; align-items: center; gap: 10px; }
.grouping-row .who { flex: 1; font-weight: 600; font-size: 0.95rem; }
.grouping-row select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.9rem;
  background: #fff;
  color: var(--ink);
  max-width: 60%;
}

.group-names { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.group-name-row { display: flex; align-items: center; gap: 8px; }
.group-name-row .gn-label { font-size: 1.1rem; flex: none; }
.group-name-row input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.95rem;
}
.group-name-row input:focus { outline: none; border-color: var(--teal); }

/* Group-clustered assignment chips */
.assign-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--teal-light);
  border-radius: 999px;
  background: #f0fdfa;
}
.assign-group.all-on {
  background: var(--teal-light);
  border-color: var(--teal);
}
.assign-group .group-tag {
  font-size: 1rem;
  line-height: 1;
  padding: 6px 6px 6px 8px;
  border: none;
  background: transparent;
  border-radius: 999px;
}
.assign-group .group-tag:active { transform: scale(0.92); }

/* Scan */
.scan-row { display: flex; gap: 8px; margin-bottom: 8px; }
.scan-row .scan-btn { flex: 1; }
.scan-row .btn-ghost { flex: 1; }
.scan-status[hidden] { display: none; }
.ai-settings {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}
.ai-settings summary { cursor: pointer; padding: 4px 0; }
.ai-settings-hint { margin: 6px 0 8px; line-height: 1.4; }
.ai-settings-hint a { color: var(--teal); }
.ai-settings-row { display: flex; gap: 6px; }
.ai-settings-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--ink);
}
.scan-status {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 8px 0;
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.receipt-preview {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  cursor: zoom-in;
}

/* Items */
.empty-hint { color: var(--muted); font-size: 0.9rem; text-align: center; padding: 8px 0; }
.item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}
.item-top { display: flex; gap: 8px; align-items: center; }
.item-name {
  flex: 1;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 4px 2px;
  font-size: 1rem;
  font-weight: 600;
  background: transparent;
}
.item-name:focus { outline: none; border-bottom-color: var(--teal); }
.item-price {
  width: 84px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 1rem;
  text-align: right;
}
.item-del {
  border: none;
  background: transparent;
  color: var(--danger);
  font-size: 1.2rem;
  padding: 4px 6px;
  flex: none;
}
.item-assign { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.assign-chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.12s;
}
.assign-chip.on {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.assign-all {
  border: none;
  background: transparent;
  color: var(--teal-dark);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: underline;
  padding: 5px 4px;
}
.assign-hint { color: var(--muted); font-size: 0.8rem; margin-top: 6px; }

/* Per-item split mode (shown when an item is shared across 2+ groups) */
.split-mode { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.sm-label { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.sm-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 600;
}
.sm-btn.on { background: var(--teal); border-color: var(--teal); color: #fff; }

/* Extras */
.extras-grid { display: flex; gap: 12px; }
.field { flex: 1; display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.money-input {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
}
.money-input .prefix { color: var(--muted); }
.money-input input {
  flex: 1;
  border: none;
  padding: 12px 6px;
  font-size: 1rem;
  width: 100%;
  background: transparent;
}
.money-input input:focus, .add-person input:focus, .item-price:focus { outline: none; }
.needs-input {
  outline: 2px solid #f59e0b;
  outline-offset: 2px;
  border-radius: 8px;
  background: #fffbeb;
  animation: pulse-amber 1.1s ease-in-out 3;
}
@keyframes pulse-amber {
  0%, 100% { outline-color: #f59e0b; }
  50% { outline-color: #fde68a; }
}
.tip-quick { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.tip-quick-label { color: var(--muted); font-size: 0.85rem; }
.tip-quick button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--teal-dark);
}

/* Results */
.results { margin-bottom: 8px; }
.result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.result-row .who { font-weight: 700; }
.result-row .amt { font-weight: 700; font-size: 1.15rem; color: var(--teal-dark); }
.result-row .breakdown { display: block; color: var(--muted); font-size: 0.78rem; font-weight: 400; }
.result-row.group .who { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.group-badge {
  font-size: 0.62rem;
  background: var(--teal-light);
  color: var(--teal-dark);
  border-radius: 999px;
  padding: 2px 7px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.member-lines { margin-top: 4px; }
.member-line {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 1px 0 1px 14px;
}
.member-line .ml-note { font-style: italic; opacity: 0.8; }
.totals-row {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 4px 0;
}
.totals-row.grand {
  color: var(--ink);
  font-weight: 800;
  font-size: 1.05rem;
  border-top: 2px solid var(--line);
  margin-top: 6px;
  padding-top: 10px;
}
.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions .btn-primary, .actions .btn-secondary { flex: 1; }
.actions .btn-ghost { flex: 1; }
.autosave-note { text-align: center; color: var(--muted); font-size: 0.78rem; margin: 12px 0 0; }

/* Temporary padding so the snapshot has clean margins */
#share-capture.capturing { background: #fff; padding: 24px; border-radius: 16px; }

/* Offscreen itemized card (Share details image) — styled like the live results */
.detail-capture {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 480px;
  box-sizing: border-box;
  background: #fff;
  padding: 24px;
  border-radius: 16px;
  color: var(--ink);
}
.detail-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2px 0;
}
.detail-item.under-shared { padding-left: 4px; }
.detail-item.under-member { padding-left: 14px; }
.detail-item .di-name { font-size: 0.9rem; }
.detail-item .di-note { display: block; color: var(--muted); font-size: 0.72rem; margin-top: 1px; }
.detail-item .di-amt { font-size: 0.9rem; font-weight: 600; white-space: nowrap; padding-left: 10px; }
.detail-item.di-calc .di-name { color: var(--muted); font-style: italic; font-weight: 500; }
.detail-item.di-calc .di-amt { color: var(--muted); }
.member-block {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}
.member-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 700;
  font-size: 0.98rem;
}
.member-head .mh-name::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
  margin-right: 7px;
}

/* Save / load group sets */
.party-actions { display: flex; gap: 8px; margin-top: 14px; }
.party-actions .btn-ghost { flex: 1; font-size: 0.9rem; padding: 10px; }

.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}
.modal-sheet {
  background: var(--card);
  width: 100%;
  max-width: 480px;
  border-radius: 18px;
  padding: 18px 16px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.35);
  animation: modal-pop 0.16s ease;
}
@keyframes modal-pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 1.1rem; }
.modal-close { border: none; background: var(--bg); width: 32px; height: 32px; border-radius: 50%; font-size: 1.3rem; line-height: 1; color: var(--muted); }
.parties-list { display: flex; flex-direction: column; gap: 8px; }
.party-row { display: flex; align-items: stretch; gap: 8px; }
.party-load {
  flex: 1;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.party-load:active { background: var(--teal-light); }
.party-name { font-weight: 700; }
.party-meta { color: var(--muted); font-size: 0.8rem; }
.party-del {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  width: 48px;
  font-size: 1.1rem;
  color: var(--danger);
  flex: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Full-screen receipt viewer */
.lightbox[hidden] { display: none; }
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: zoom-in;
}
.lightbox.zoomed { display: block; }
.lightbox.zoomed img {
  max-width: none;
  max-height: none;
  width: 200%;
  cursor: zoom-out;
}
.lightbox-close {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: 14px;
  z-index: 101;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

/* Unstack a ×N quantity item into single rows */
.item-unstack {
  border: none;
  background: transparent;
  color: var(--teal-dark);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: underline;
  padding: 6px 2px 0;
}

/* Details card: logo + at-a-glance summary above the itemized breakdown */
.detail-logo {
  display: block;
  width: 250px;
  margin: 0 auto 14px;
}
.detail-summary {
  border-bottom: 2px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 4px;
}
.detail-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 700;
  font-size: 1.02rem;
  padding: 3px 0;
}
.detail-summary-row span:last-child { color: var(--teal-dark); }
.detail-summary-row.grand {
  border-top: 1px solid var(--line);
  margin-top: 6px;
  padding-top: 8px;
  font-size: 1.15rem;
}
.detail-summary-row.grand span:last-child { color: var(--ink); }

/* ── Accounts, staged photo sections, receipt library (2026-08-14) ────────── */
/* The header is centred dark text on the light page background — NOT a coloured bar.
   An earlier version styled this white-on-translucent-white and was invisible. */
.app-header { position: relative; }
.account-btn {
  position: absolute; top: 16px; right: 14px;
  background: var(--card); color: var(--teal); border: 1px solid var(--line);
  border-radius: 999px; padding: 7px 15px; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; box-shadow: var(--shadow);
  max-width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.account-btn:hover { background: var(--teal-light); border-color: var(--teal); }

/* Scan row: two photo buttons side by side on their own line, then the secondary
   actions. Four equal flex children squeezed "Upload photo" onto two lines. */
.scan-row { flex-wrap: wrap; }
.scan-row .scan-btn { flex: 1 1 calc(50% - 4px); min-width: 0; white-space: nowrap; }
.scan-row .btn-ghost { flex: 1 1 calc(50% - 4px); white-space: nowrap; }

.pages { margin: 10px 0 4px; }
.pages-hint { font-size: 13px; color: var(--muted, #667); margin: 0 0 8px; }
.pages-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.page-thumb { position: relative; flex: 0 0 auto; width: 68px; height: 96px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border, #dde); }
.page-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.page-num {
  position: absolute; bottom: 3px; left: 3px; background: rgba(0,0,0,0.66); color: #fff;
  font-size: 11px; font-weight: 700; border-radius: 4px; padding: 1px 5px;
}
.page-x {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; line-height: 18px;
  border-radius: 50%; border: none; background: rgba(0,0,0,0.66); color: #fff;
  font-size: 14px; cursor: pointer; padding: 0;
}
.pages-actions { display: flex; gap: 8px; margin-top: 10px; }
.pages-actions .btn-primary { flex: 1; }

.account-error { color: #b3261e; font-size: 13px; margin: 6px 0 0; }
#account-form input { width: 100%; margin-bottom: 8px; }

.receipts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.receipt-card { border: 1px solid var(--border, #dde); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.receipt-card img { width: 100%; height: 130px; object-fit: cover; background: #f2f2f4; display: block; }
.receipt-meta { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted, #667); }
.receipt-meta strong { font-size: 15px; color: var(--text, #111); }
.receipt-actions { display: flex; gap: 6px; padding: 0 10px 10px; }
.receipt-actions button { flex: 1; font-size: 12px; padding: 6px 8px; }

/* Modals default to display:flex via .modal, so [hidden] needs an explicit override —
   the same gotcha already documented for the existing modals and #scan-status. */
.modal[hidden], .pages[hidden], .account-btn[hidden] { display: none; }

/* ---- Fixes found by actually looking at the rendered page at phone width ---- */

/* Inputs in this app are styled per-container (.add-person input, .money-input
   input, …), so the account fields inherited nothing and rendered as raw browser
   defaults. 16px is deliberate, not cosmetic: iOS Safari zooms the whole page
   when you focus a field smaller than 16px. */
#account-form input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  margin-bottom: 8px;
}
#account-form input:focus { outline: none; border-color: var(--teal); }

/* The quick-tip row needed 332px inside a 326px card, which orphaned "25%" onto
   a line of its own. 6px gaps bring it to 324. */
.tip-quick { gap: 6px; }

/* Half-width action buttons were wrapping to two lines at phone width. */
.actions .btn-primary,
.actions .btn-secondary,
.actions .btn-ghost {
  white-space: nowrap;
  font-size: 0.95rem;
  padding-left: 8px;
  padding-right: 8px;
}
