/* TripCash — mobile-first, number-first. Zero layout shift while typing:
   every row is fixed-height and amounts use tabular numerals. */

/* Manrope: geometric + rounded, matches the app icon. Self-hosted so the
   offline guarantee holds (files are precached by the service worker). */
@font-face {
  font-family: "Manrope";
  src: url("./fonts/manrope-latin.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2212;
}
@font-face {
  font-family: "Manrope";
  src: url("./fonts/manrope-latin-ext.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0100-02BA, U+1E00-1EFF, U+20A0-20C0;
}

:root {
  --bg: #eef2f1;
  --bg-glow: #e0efec;
  --card: #ffffff;
  --card-2: #f7faf9;
  --text: #101b18;
  --muted: #5f7370;
  --accent: #0d9488;
  --accent-ink: #0b7a70;
  --accent-strong: #0a6b62; /* filled controls: AA contrast with --on-accent */
  --accent-soft: #d5ece9;
  --accent-glow: rgba(13, 148, 136, 0.14);
  --on-accent: #ffffff;
  --border: #e3e9e7;
  --border-strong: #7c8f8b; /* 3.25:1 vs the cards — boundaries that must be SEEN */
  --live: #16a34a;
  --live-ink: #15803d; /* 5.02:1 on white — --live is a dot colour, not a text one */
  --warn: #b45309;
  --warn-bg: #fdf2df;
  --shadow: 0 1px 2px rgba(16, 27, 24, 0.05), 0 4px 16px rgba(16, 27, 24, 0.05);
  --radius: 18px;
}
/* Dark palette. Applied two ways: forced via data-theme="dark", or by system
   preference unless the user forced light. Keep both blocks identical. */
:root[data-theme="dark"] {
  --bg: #0b1210;
  --bg-glow: #0e1a17;
  --card: #151f1c;
  --card-2: #1a2622;
  --text: #e9efed;
  --muted: #7e948f;
  --accent: #2dd4bf;
  --accent-ink: #5eead4;
  --accent-strong: #2dd4bf;
  --accent-soft: #12403a;
  --accent-glow: rgba(45, 212, 191, 0.12);
  --on-accent: #04211d;
  --border: #23312d;
  --border-strong: #5b706a; /* 3:1 vs the dark cards */
  --live: #4ade80;
  --live-ink: #4ade80; /* already ~10:1 on the dark card */
  --warn: #fbbf24;
  --warn-bg: #33290f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1210;
    --bg-glow: #0e1a17;
    --card: #151f1c;
    --card-2: #1a2622;
    --text: #e9efed;
    --muted: #7e948f;
    --accent: #2dd4bf;
    --accent-ink: #5eead4;
    --accent-strong: #2dd4bf;
    --accent-soft: #12403a;
    --accent-glow: rgba(45, 212, 191, 0.12);
    --on-accent: #04211d;
    --border: #23312d;
    --border-strong: #5b706a;
    --live: #4ade80;
    --live-ink: #4ade80;
    --warn: #fbbf24;
    --warn-bg: #33290f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
  /* Kill the OS tap flash: it paints a rectangle that ignores border-radius.
     Every control carries its own :active state instead. */
  -webkit-tap-highlight-color: transparent;
}
/* A press state for EVERY control, not just the ones that were given one
   by hand. Roughly half of them — member chips, type chips, segment
   buttons, tabs, expense rows, Mark paid, the bell — had no :active rule
   at all, so tapping them looked identical to not tapping them.
   Specific rules below still win; this is only the floor. */
button:active:not(:disabled),
label.s-name:active,
summary:active {
  opacity: 0.62;
  transition: none;
}
button:disabled:active { opacity: inherit; }

/* display rules below must never resurrect [hidden] elements or closed dialogs */
[hidden] { display: none !important; }
dialog:not([open]) { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0 auto;
  font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(120% 50% at 50% -10%, var(--bg-glow) 0%, var(--bg) 60%)
    var(--bg);
  color: var(--text);
  max-width: 480px;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px calc(28px + env(safe-area-inset-bottom));
}
button { font-family: inherit; }

/* ---------- Top bar + brand ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text);
}
.brand:active { opacity: 0.7; }
.brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  box-shadow: var(--shadow);
  flex: none;
}
.brand-name {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.brand-name em, .about-card em { font-style: normal; color: var(--accent-ink); }
.brand-ver {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0;
  align-self: flex-end;
  padding-bottom: 3px;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.icon-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 10px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  box-shadow: var(--shadow);
  transition: transform 0.12s, color 0.12s;
}
.icon-btn:active { color: var(--accent); transform: scale(0.92); }

/* ---------- Trip search + filters ---------- */
#trip-tools { margin-bottom: 12px; }
#trip-tools .input-wrap input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem; /* <16px makes iOS Safari zoom the page on focus */
  font-weight: 600;
  /* Right padding only while the clear button is present. Reserving it
     permanently on BOTH sides clipped the placeholder to "Search trips
     — name, member, curre" — cutting off the very feature it advertises. */
  padding: 12px 12px 12px 38px;
  transition: border-color 0.15s;
}
#trip-tools .input-wrap:has(.input-clear:not([hidden])) input { padding-right: 44px; }
#trip-tools .input-wrap input:focus { border-color: var(--accent); }
#trip-tools .input-wrap input::placeholder { font-weight: 500; color: var(--muted); opacity: 0.7; }
#trip-tools .input-wrap input::-webkit-search-cancel-button { display: none; }
#trip-tools .input-wrap .input-icon { top: 15px; }
#trip-tools .input-clear { top: 3px; }
.chip-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 2px 2px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.f-chip {
  flex: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}
.f-chip:active { border-color: var(--accent); }
.f-chip.on { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }

/* ---------- Trip cards (accordion) ---------- */
.trips { display: flex; flex-direction: column; gap: 10px; }
.trip-slot { position: relative; }
.swipe-action {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 22px;
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  opacity: 0;
}
.trip-slot.swiping .swipe-action { opacity: 1; }
.trip-card { position: relative; z-index: 1; }
.trip-card.swiping { transition: none; }
.trip-card.archived .trip-name-text { color: var(--muted); }
.no-trips-match {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 28px 12px;
}
.trip-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: border-color 0.18s;
}
.trip-card.open { border-color: var(--accent); }
/* pan-y: vertical touch scrolling stays with the browser, horizontal is
   ours — without this the browser fires pointercancel and swipes die. */
.trip-card-head { display: flex; align-items: stretch; touch-action: pan-y; }
.trip-head-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 15px 4px 15px 16px;
  cursor: pointer;
  border-radius: var(--radius);
}
.trip-head-main:active { background: var(--accent-glow); }
.trip-head-meta { min-width: 0; }
.trip-name-text {
  /* A long unbroken name used to push the card wide rather than wrap. */
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
/* Who's on the trip, on the collapsed card. A tick means a real signed-in
   account holds that row — i.e. they will actually receive the trip. */
.trip-members { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.tm {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  max-width: 11ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.tm-self { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent-ink); }
.tm-linked { color: var(--text); border-color: var(--border-strong); }
.tm-tick { color: var(--live-ink); font-weight: 900; }
/* Invited-but-not-joined reads as provisional, on purpose. */
.tm-invited { border-style: dashed; }
.tm-more { color: var(--muted); }

.trip-curr {
  display: block;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trip-chev { color: var(--accent); flex: none; transition: transform 0.2s; }
.trip-card.open .trip-chev { transform: rotate(180deg); }
.trip-edit {
  align-self: center;
  margin-right: 8px;
}
.trip-pin { align-self: center; }
.trip-pin.pinned { color: var(--accent); opacity: 1; }
.trip-drag {
  align-self: stretch;
  display: flex;
  align-items: center;
  padding: 0 14px 0 10px; /* ≥44pt grab zone */
  color: var(--muted);
  opacity: 0.7;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.trip-card { will-change: transform; }
.trip-card.dragging {
  z-index: 10;
  transition: none;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
  border-color: var(--accent);
  position: relative;
}
.trip-card:not(.dragging) { transition: border-color 0.18s, transform 0.18s; }
.primary:disabled { opacity: 0.45; cursor: default; transform: none; }
.trip-card-body { padding: 0; }
.trip-card.open .trip-card-body { padding: 2px 12px 14px; }
.mini {
  background: none;
  border: none;
  color: var(--muted);
  display: flex;
  align-items: center;
  padding: 13px 12px;
  cursor: pointer;
  border-radius: 9px;
}
.mini:active { background: var(--accent-soft); color: var(--text); }

/* ---------- Rates status chip ---------- */
.status-row { margin: 10px 0 16px; }
.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 12px 9px 9px;
  min-height: 38px;
  cursor: pointer;
}
.status:active { border-color: var(--accent); color: var(--text); }
.status-refresh { color: var(--accent); flex: none; }
.status.busy .status-refresh { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.status-stamp {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  padding: 5px 4px 0 10px;
  font-variant-numeric: tabular-nums;
}
.status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live);
  flex: none;
}
.status.offline { color: var(--warn); border-color: var(--warn); }
.status.offline::before { background: var(--warn); }
.status .dot { display: none; } /* superseded by ::before */

/* ---------- "You're here" strip ---------- */
.place-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 9px 9px 9px 13px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}
.place-strip span { flex: 1; min-width: 0; }
.place-act {
  background: var(--accent-strong);
  color: var(--on-accent);
  border: none;
  border-radius: 9px;
  font-weight: 800;
  font-size: 0.8rem;
  padding: 9px 14px;
  cursor: pointer;
}
.place-x {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 9px 8px;
  cursor: pointer;
}
.here-badge {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--on-accent);
  background: var(--accent-strong);
  border-radius: 5px;
  padding: 2px 5px;
}

/* ---------- Decimal-slip guard ---------- */
.slip-warn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 11px 13px;
  background: var(--warn-bg);
  border: 1px solid var(--warn);
  border-radius: 12px;
  color: var(--warn);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.4;
}

/* ---------- Currency fields ---------- */
.fields { display: flex; flex-direction: column; gap: 10px; }
.field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 10px 10px 12px;
  height: 74px; /* fixed → zero layout shift while typing */
  box-shadow: var(--shadow);
  overflow: hidden; /* row overflow is what fitAmount() measures against */
  position: relative;
  transition: border-color 0.18s, background-color 0.18s, box-shadow 0.18s, transform 0.18s;
}
/* Match the drag-handle gutter (34px handle + 8px gap + 10px pad) so every
   amount shares one right-align axis */
.field.home { padding-right: 52px; }
/* The last-edited field is the source of truth — mark it. */
.field.source {
  border-color: var(--accent);
  background: linear-gradient(90deg, var(--accent-glow), transparent 45%) var(--card);
}
.field.source::before {
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow), var(--shadow);
}
/* Row being dragged floats above the rest; siblings animate out of the way. */
.field.dragging {
  z-index: 10;
  transition: none;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
  border-color: var(--accent);
}
.field-label {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  padding: 6px 2px;
  cursor: pointer;
  color: var(--text);
  text-align: left;
  /* Natural width, but when a huge number needs room the label (which can
     ellipsize) yields before the amount does. */
  /* Shrinks so a long currency name ellipsizes, but never past the code and
     its badge — past that point fitAmount() shrinks the number instead. */
  flex: 0 4 auto;
  min-width: min-content;
  max-width: 54%;
  border-radius: 10px;
}
.field-label:active { background: var(--accent-soft); }
.field-flag { font-size: 1.6rem; line-height: 1; }
.field-meta { min-width: 0; }
.field-code {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 0.98rem;
  letter-spacing: 0.01em;
  overflow: hidden;
}
.chart-hint {
  display: inline-flex;
  color: var(--accent);
  opacity: 0.65;
}
.home-badge {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 2px 5px;
}
.field-name {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.field input {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  color: var(--text);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding: 8px 0;
  /* no font-size transition: fitAmount() measures overflow synchronously */
}
.field input.long { font-size: 1.25rem; }
.field input.xlong { font-size: 1rem; }
.field input.xxlong { font-size: 0.82rem; }
.field input::placeholder { color: var(--muted); opacity: 0.4; }

/* Currency symbol hugging the amount (₹ 1,234.56). Needs content-sized
   inputs; browsers without field-sizing keep the plain right-aligned number. */
.cur-sym { display: none; }
/* A locked member chip is still tappable — it has something to say. */
.chip.locked { opacity: 0.75; }

@supports (field-sizing: content) {
  .cur-sym {
    display: block;
    margin-left: auto; /* pushes symbol + input to the right edge */
    flex: none;
    color: var(--muted);
    font-size: 1.05rem;
    font-weight: 700;
    padding-right: 7px;
  }
  .field input {
    /* Never squeeze the number — the label yields, then fitAmount() steps
       the font down when the row itself overflows. */
    flex: 0 0 auto;
    field-sizing: content;
    /* 1.5ch collapsed the app's primary input to a 21px sliver wedged
       between the rate-sheet button and the drag handle, so both likely
       mis-taps navigated somewhere else. */
    min-width: 4.5ch;
  }
  /* dim the symbol when the field is empty (placeholder showing) */
  .field:has(input:placeholder-shown) .cur-sym { opacity: 0.35; }
}

/* Drag grip (non-home rows) */
.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 44px;
  align-self: stretch;
  color: var(--muted);
  opacity: 0.7;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 10px;
}
.dragging .drag-handle { cursor: grabbing; color: var(--accent); opacity: 1; }

/* Narrow phones (iPhone SE, small Androids): shed the row's secondary
   adornments before fitAmount() has to crush the number. */
@media (max-width: 374px) {
  .field-name { display: none; }
  .chart-hint { display: none; }
  .drag-handle { width: 36px; }
  .field-flag { font-size: 1.3rem; }
}

/* ---------- Street-rate switch ---------- */
.markup-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap; /* Expense/Clear drop to their own line below ~430px */
  row-gap: 2px;
  gap: 10px;
  margin-top: 16px;
  padding: 4px 8px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  user-select: none;
}
.markup-switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.markup-switch input {
  appearance: none;
  -webkit-appearance: none;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  cursor: pointer;
  transition: background-color 0.2s;
  margin: 0;
  flex: none;
}
.markup-switch input::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}
.markup-switch input:checked { background: var(--accent); }
.markup-switch input:checked::after { transform: translateX(18px); }
.markup-pct input {
  width: 2.6em;
  border: none;
  border-bottom: 2px solid var(--border);
  background: none;
  color: var(--text);
  font-size: 1rem; /* <16px makes iOS Safari zoom the page on focus */
  font-weight: 700;
  text-align: center;
  padding: 10px 2px;
  transition: border-color 0.15s;
}
.markup-pct input:focus { border-color: var(--accent); }
/* Percent is inert until the switch is on — don't let it read as active */
.markup-row.off .markup-pct { opacity: 0.4; }
.clear-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 9px 14px;
  cursor: pointer;
}
.clear-btn:active { color: var(--warn); border-color: var(--warn); }
.clear-btn.accent { color: var(--accent-ink); border-color: var(--accent); margin-left: auto; margin-right: 6px; }
.clear-btn.accent:active { color: var(--on-accent); background: var(--accent-strong); }
#clear-all { margin-left: 0; }
.markup-row #to-expense + #clear-all { margin-left: 0; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 56px 12px 24px; color: var(--muted); }
.empty-emoji {
  font-size: 3.4rem;
  margin: 0 auto 14px;
  width: 108px;
  height: 108px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: var(--shadow);
}
.empty p { margin: 6px 0 18px; font-size: 1rem; font-weight: 600; }

/* ---------- Buttons ---------- */
.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: var(--accent-strong);
  color: var(--on-accent);
  border: none;
  border-radius: 14px;
  padding: 15px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  margin-top: 12px;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: transform 0.1s;
}
.primary:active { transform: scale(0.985); }
.ghost {
  display: block;
  width: 100%;
  background: none;
  color: var(--muted);
  border: none;
  padding: 13px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 2px;
}

/* ---------- Bottom sheets ---------- */
.sheet {
  border: none;
  border-radius: 22px 22px 0 0;
  background: var(--card);
  color: var(--text);
  width: 100%;
  max-width: 480px;
  margin: auto auto 0;
  padding: 0 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 88dvh;
  will-change: transform;
  /* The sheet itself never scrolls — its .sheet-scroll middle does. That
     keeps the close button reachable and stops a scroll running off the
     end of the sheet and carrying on down the page behind it. */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: contain;
}
.sheet.tall { height: 88dvh; }
.sheet[open] { animation: sheet-up 0.28s cubic-bezier(0.32, 0.72, 0.33, 1); }
@keyframes sheet-up {
  from { transform: translateY(48px); opacity: 0.4; }
}
.sheet::backdrop {
  background: rgba(4, 12, 10, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
/* Wide, forgiving pull-down zone */
/* A real exit from every sheet. 44px, thumb-reachable, above the
   scrolling body so it can't scroll away. */
.sheet-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  z-index: 2;
}
.sheet-close:active { background: var(--card-2); }
/* Titles must not run under it. */
.sheet h2 { padding-right: 44px; }

/* Placeholder text was clipped ("Search trips — name, member, curre")
   because padding for the clear button was reserved on both sides even
   when the field was empty and the button hidden. */
input::placeholder { text-overflow: ellipsis; }

/* A disabled .manage-btn was pixel-identical to an enabled one and
   swallowed taps with no press state — it just looked broken. The
   primary buttons say what they're waiting for; these can at least look
   unavailable. */
.manage-btn:disabled {
  opacity: 0.6;
  cursor: default;
  border-style: dashed;
}

/* The disabled primary IS the error message ("Enter an amount"), so it
   cannot be the least legible text on the sheet. 0.45 alpha measured
   2.07:1; this keeps the button visibly inert via a muted fill while
   the label stays readable. */
.primary:disabled {
  opacity: 1;
  background: var(--card-2);
  border: 1.5px solid var(--border-strong);
  color: var(--muted);
  box-shadow: none;
}

/* Long member names turned one settle-up row into five wrapped lines.
   Expense rows already ellipsise; these now do too. */
.sum-transfer > span:first-child,
.sum-pay > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The native chevron overlapped the selected label ("🇰🇿 KZT —
   Kazakhstan⌄"). Room for the arrow, and room to shrink. */
.setting-row select { padding-right: 30px; max-width: 62%; text-overflow: ellipsis; }

/* ---------- Touch targets (audit, v1.46) ----------
   Almost nothing here met the 44px minimum: a 19px split checkbox, 26px
   toggles, 35px chips. These raise the SMALL ones; a few (chips in a
   scrolling row) stay compact by design but gain vertical padding. */
.toast-act { min-height: 44px; min-width: 44px; padding: 4px 10px; }
.icon-btn, .avatar-btn { min-width: 44px; min-height: 44px; }
.trip-drag { background: none; border: none; padding: 0 4px; color: inherit; cursor: grab; }
.place-x { min-width: 44px; min-height: 44px; }
.member-chip, .type-chip, .f-chip { min-height: 44px; }
.seg > button { min-height: 44px; }
.place-act { min-height: 44px; }
.trip-pin, .trip-edit { min-width: 44px; min-height: 44px; }
.trip-tabs button { min-height: 44px; }
.chip-x, .picked-chip { min-height: 40px; }
.split-row input[type="text"] { min-height: 44px; }

/* Focus was removed with outline:none and replaced by a 0.14-alpha glow
   that composites to ~1.17:1 — invisible. Restore a real, visible ring
   for keyboard users without bringing back the mouse-click outline. */
:focus-visible {
  outline: 3px solid var(--accent-strong);
  outline-offset: 2px;
  border-radius: 6px;
}
/* …but never for a mouse or a finger, which is what `outline: none` on
   each control was really trying to say. */
:focus:not(:focus-visible) { outline: none; }

.grab-zone {
  padding: 12px 0 10px;
  margin: 0 -18px;
  cursor: grab;
  touch-action: none;
  flex: none;
}
.grab {
  width: 42px;
  height: 4.5px;
  border-radius: 999px;
  background: var(--border);
  margin: 0 auto;
}
.sheet h2 { margin: 0 0 14px; font-size: 1.15rem; font-weight: 800; letter-spacing: -0.01em; }
.input-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 2px 2px 6px;
}
.sheet input[type="text"], .sheet input[type="search"], .sheet input[type="datetime-local"],
.sheet input[type="email"], .sheet input[type="password"], .sheet input[type="tel"] {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--card-2);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 13px;
  margin-bottom: 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.sheet input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
/* Placeholders are hints, not values: dimmer and tighter than real text,
   or an empty form reads as if it's full of grey junk. (Size stays 16px —
   shrinking it re-triggers iOS focus-zoom.) */
.sheet input::placeholder {
  font-weight: 500;
  color: var(--muted);
  opacity: 0.55;
  letter-spacing: -0.01em;
}
.sheet input[type="search"]::-webkit-search-cancel-button { display: none; }

/* Search box with leading icon + clear button. Selector must out-rank
   `.sheet input[type="search"]` or the padding silently loses. */
.input-wrap { position: relative; }
.input-wrap .input-icon {
  position: absolute;
  left: 13px;
  top: 16px;
  color: var(--muted);
  pointer-events: none;
}
.sheet .input-wrap input[type="search"] { padding-left: 38px; padding-right: 38px; }
.input-clear {
  position: absolute;
  right: 4px;
  top: 3px;
  background: var(--border);
  border: none;
  color: var(--muted);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.input-clear:active { color: var(--text); }

/* ---------- Editor manage actions ---------- */
.editor-manage { display: flex; gap: 8px; margin-top: 8px; }
.manage-btn {
  flex: 1;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 13px 10px;
  cursor: pointer;
}
.manage-btn:active { border-color: var(--accent); }
.manage-btn.danger { color: var(--warn); }
.manage-btn.danger.confirming { background: var(--warn-bg); border-color: var(--warn); }

/* ---------- Currency picker ---------- */
.picked {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-bottom: 10px;
  min-height: 38px;
}
.picked .chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-strong);
  color: var(--on-accent);
  border: none;
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
}
/* Results grow naturally; the editor's ONE outer .sheet-scroll scrolls —
   nested scrollers inside a bottom sheet are a trap on touch screens
   (and squeezed this list down to a single visible row). */
.results {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}
/* Keep the currency search reachable while the results scroll under it. */
.editor-search-wrap {
  position: sticky;
  top: -4px; /* cancels .sheet-scroll's top padding */
  z-index: 2;
  background: var(--card);
  padding-bottom: 6px;
}
.results button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 0.95rem;
  padding: 13px 6px;
  cursor: pointer;
}
.results button:active { background: var(--accent-glow); }
.results .r-flag { font-size: 1.45rem; flex: none; }
.results .r-meta { min-width: 0; flex: 1; }
.results .r-code { font-weight: 800; }
.results .r-detail {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  display: block;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.results .r-sym {
  flex: none;
  min-width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 0 6px;
}
.results .picked-mark { color: var(--accent); font-weight: 800; font-size: 1.1rem; flex: none; }
.results .no-results {
  padding: 28px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}
.sheet-actions { padding-top: 10px; }

/* ---------- Settings ---------- */
.setting-card {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 14px;
  margin-bottom: 12px;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0;
}
.setting-row + .setting-row { border-top: 1px solid var(--border); }
.setting-label { font-size: 0.92rem; font-weight: 700; }
.setting-label span {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: 2px;
}
.seg {
  display: flex;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
  gap: 2px;
  flex: none;
}
.seg button {
  border: none;
  background: none;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.78rem;
  padding: 11px 11px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.seg button.on { background: var(--accent-strong); color: var(--on-accent); }
.setting-row select {
  font-family: inherit;
  font-size: 1rem; /* <16px makes iOS Safari zoom the page on focus */
  font-weight: 700;
  padding: 11px 8px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  max-width: 58%;
}
/* The one button in the app that destroys other people's data must not
   be the same colour as Save. `.primary.danger` had no rule, so it
   inherited the mint fill — full width, at thumb height, with "Keep it"
   a faint grey row above. */
.primary.danger {
  background: var(--warn);
  color: #fff;
  border-color: var(--warn);
  box-shadow: none;
}
.primary.danger:active { opacity: 0.85; }

/* Settle-up is the app's headline output, and the name column was the
   only thing allowed to shrink — at 320px it rendered "You …" with no
   way to see who was owed. Give it the room and let the button shrink. */
.sum-transfer > span:first-child { flex: 1 1 auto; }
.sum-transfer .amt { flex: none; }
.sum-transfer .mark-paid { flex: none; padding: 11px 10px; }
@media (max-width: 380px) {
  .sum-transfer { flex-wrap: wrap; }
  .sum-transfer > span:first-child { flex: 1 0 100%; white-space: normal; }
}

/* Notification bell + unread badge. */
#bell-btn { position: relative; }
.bell-count {
  position: absolute;
  top: 1px;
  right: 1px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--warn);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  border: 2px solid var(--bg);
  line-height: 1;
}
.notice {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  padding: 13px 4px;
  min-height: 44px;
  cursor: pointer;
}
.notice .n-icon { font-size: 1.1rem; flex: none; line-height: 1.3; }
.notice .n-body { min-width: 0; flex: 1; }
.notice .n-text { display: block; font-size: 0.9rem; font-weight: 700; }
.notice.unread .n-text::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 7px;
  vertical-align: middle;
}
.notice .n-when { display: block; font-size: 0.72rem; font-weight: 600; color: var(--muted); margin-top: 3px; }
.notice:active { background: var(--card-2); }

/* Notification switch. `.on` is the registered state. */
#push-toggle.on {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--on-accent);
}
#push-row { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 12px; }
#push-note { margin: 8px 0 12px; }

/* Reassign-and-remove: the way out of "already in some expenses". */
#mx-reassign { margin-top: 14px; }
#mx-reassign select {
  width: 100%;
  font-family: inherit;
  font-size: 1rem; /* <16px makes iOS Safari zoom the page on focus */
  font-weight: 700;
  padding: 12px 10px;
  min-height: 44px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  margin-bottom: 8px;
}

.about-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 4px;
}
.about-card strong { display: block; font-size: 0.95rem; letter-spacing: -0.01em; }
.about-card > div > span { display: block; font-size: 0.74rem; font-weight: 600; color: var(--muted); margin-top: 2px; }
.hint { font-size: 0.75rem; color: var(--muted); line-height: 1.5; font-weight: 500; }
.hint.bad { color: var(--warn); font-weight: 700; }

/* Sync / account card in Settings */
.sync-card { margin-top: 12px; }
.sync-card .setting-label { margin-bottom: 12px; }
.sync-card .primary { margin-top: 0; }
.sync-card .manage-btn { width: 100%; margin-top: 8px; }
.sync-card input { margin-top: 10px; margin-bottom: 0 !important; }
.sync-actions { display: flex; gap: 8px; margin-top: 10px; }
.sync-actions .primary, .sync-actions .manage-btn { flex: 1; margin-top: 0; }
#sync-note { margin-top: 10px; }
.sync-recommend { margin: 6px 2px 2px; text-align: center; }
.join-prompt {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.5;
}
.sync-warn {
  margin: 12px 0 4px;
  padding: 10px 12px;
  border-radius: 11px;
  background: var(--card-2);
  border: 1px solid var(--border);
}
.sync-when { display: block; font-size: 0.7rem; opacity: 0.8; margin-top: 2px; }

/* Members list — every row opens that person */
.m-row { border-bottom: 1px solid var(--border); padding: 0; }
.m-open {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  text-align: left;
  padding: 12px 4px;
  cursor: pointer;
}
.m-open .m-meta { flex: 1; min-width: 0; }
.m-open .m-name { display: block; font-size: 0.92rem; font-weight: 700; }
.m-open .m-status {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m-badge {
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 2px 5px;
  margin-left: 6px;
  vertical-align: 1px;
}
.member-chip.static.linked { border-color: var(--accent); }
#mx-remove { width: 100%; margin-top: 8px; }
#mx-send { width: 100%; margin-top: 4px; }
#mx-email:disabled { opacity: 0.6; }

/* Invite sheet — one row per person, each sends its own link */
#invite-list { padding-top: 10px; }
.invite-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 8px 8px 13px;
  margin-bottom: 8px;
}
.invite-row .iv-email {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.invite-row .iv-send {
  flex: none;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 8px 15px;
  cursor: pointer;
}
.invite-row .iv-send:active { background: var(--accent-soft); }
.invite-row .mini { padding: 9px; }
#invite-note.bad { color: var(--warn); font-weight: 700; }
.sync-card.busy { opacity: 0.6; pointer-events: none; }
.hint a { color: var(--accent-ink); }

/* ---------- Trip tabs + expense ledger ---------- */
.trip-tabs {
  display: flex;
  gap: 4px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  margin-bottom: 12px;
}
.trip-tabs button {
  flex: 1;
  border: none;
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  padding: 10px;
  border-radius: 9px;
  cursor: pointer;
}
.trip-tabs button.on { background: var(--accent-strong); color: var(--on-accent); }

.ledger-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 10px;
}
.ledger-total { min-width: 0; }
.ledger-total > span:first-child {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.member-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-bottom: 10px;
}
.member-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 8px 13px;
  cursor: pointer;
}
.member-chip.on { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }
.member-chip.add { color: var(--accent-ink); border-style: dashed; }
.member-chip.static { cursor: default; } /* label, not a button — don't promise a tap */

.expense-list { list-style: none; margin: 0 0 4px; padding: 0; }
.expense-list button {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  padding: 11px 2px;
  cursor: pointer;
  font-family: inherit;
}
.expense-list .x-emoji { font-size: 1.35rem; flex: none; }
.expense-list .x-meta { flex: 1; min-width: 0; }
.expense-list .x-name {
  /* An inline box ignores all three of the properties below, so a long
     expense name drew straight through its own amount — 193px of overlap
     at 375px, on the ledger's main screen. Its sibling .x-sub already
     declared display:block, which is why only the name misbehaved. */
  display: block;
  font-size: 0.92rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.expense-list .x-sub { display: block; font-size: 0.72rem; font-weight: 600; color: var(--muted); margin-top: 2px; }
.expense-list .x-amts { text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.expense-list .x-local { display: block; font-size: 0.92rem; font-weight: 800; }
.expense-list .x-home { display: block; font-size: 0.72rem; font-weight: 600; color: var(--muted); margin-top: 2px; }
.expense-list .x-chev { color: var(--muted); opacity: 0.6; flex: none; }
.expense-empty { text-align: center; color: var(--muted); font-size: 0.85rem; font-weight: 600; padding: 22px 8px; }

/* Expense sheet */
/* Horizontal padding + matching negative margin: focus rings/glows on
   flush-edge controls (e.g. the currency select) would otherwise be
   clipped by this container's overflow. */
.sheet-scroll { overflow-y: auto; flex: 1; min-height: 0; padding: 4px 5px 6px; margin: 0 -5px; overscroll-behavior: contain; }
/* showModal() focuses the scroller (scrollable divs are focusable) and
   Chrome paints a default ring around the whole body — pure noise here. */
.sheet-scroll:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: -2px; }
.type-row { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 12px; }
.type-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 9px 12px;
  cursor: pointer;
}
.type-chip.on { border-color: var(--accent); background: var(--accent-glow); }
.e-amount-row { display: flex; gap: 8px; }
.e-amount-row input { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; }
.e-amount-row select {
  font-family: inherit;
  font-size: 1rem; /* <16px makes iOS Safari zoom the page on focus */
  font-weight: 800;
  padding: 0 12px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  margin-bottom: 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.e-amount-row select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
/* datetime-local: keep the native picker but match our text fields */
.sheet input[type="datetime-local"] {
  -webkit-appearance: none;
  appearance: none;
  min-height: 48px;
}
.sheet input[type="datetime-local"]::-webkit-calendar-picker-indicator { opacity: 0.6; }

/* Receipt / attachment row in the expense sheet */
.attach-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.attach-add {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 11px 14px;
  cursor: pointer;
}
.attach-thumb {
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card-2);
  padding: 6px;
  max-width: 75%;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
}
.attach-thumb img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; display: block; }
.attach-thumb .a-file { font-size: 1.5rem; padding: 6px 4px; }
.attach-thumb .a-name {
  font-size: 0.78rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  padding-right: 4px;
}
.attach-remove { padding: 9px 11px; }
.attach-busy { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.attach-body { display: flex; flex-direction: column; gap: 10px; }
.attach-body img { max-width: 100%; border-radius: 12px; }
.x-clip { display: inline-flex; vertical-align: -2px; margin-left: 5px; opacity: 0.65; }
.x-clip svg { width: 12px; height: 12px; }
#e-home-preview { margin: -6px 2px 12px; font-weight: 700; min-height: 1.2em; }
.split-rows { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; }
.split-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 9px 13px;
}
.split-row.off { opacity: 0.5; }
.split-row .s-name { flex: 1; min-width: 0; font-size: 0.88rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.split-row .s-owes {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
  flex: none;
}
/* What you hand over, then what it costs you at home. */
.split-row .s-home { display: block; font-weight: 500; opacity: 0.72; }
/* Deciding who was at a dinner is the core gesture here. It used to be a
   19px checkbox in a div — under half the 44px minimum, with no
   forgiving hit area. The row is now the target. */
.split-row .s-name { cursor: pointer; padding: 6px 0; }
.split-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  margin: 0;
  flex: none;
}
.split-row:has(input[type="checkbox"]) { padding: 4px 13px; min-height: 46px; }
.split-row input[type="text"] {
  width: 4.2em;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem; /* <16px makes iOS Safari zoom the page on focus */
  font-weight: 700;
  text-align: center;
  padding: 7px 4px;
  margin: 0;
}
.split-row input[type="text"]:focus { border-color: var(--accent); }
#e-split-note { margin: 8px 2px 0; font-weight: 700; }
#e-split-note.bad, #p-note.bad { color: var(--warn); }

/* Members sheet */
.m-add-row { display: flex; gap: 8px; align-items: stretch; }
.m-add-row input { flex: 1; margin-bottom: 0 !important; }
.m-add-row .place-act { align-self: center; }
/* The add-member input drops its bottom margin, so the member chips would
   sit flush against its border and read as overlapping it. */
.m-add-row + .picked { margin-top: 10px; }
.m-list { list-style: none; margin: 12px 0 8px; padding: 0; }
.m-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  padding: 11px 4px;
  font-size: 0.92rem;
  font-weight: 700;
}
.m-list .mini { padding: 8px 10px; }

/* Summary sheet */
.sum-section { margin-bottom: 16px; }
.sum-head {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 2px 8px;
}
.sum-transfer {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-2);
  /* 1.05:1 against the sheet behind it, so the cards grouping each
     transfer were invisible. The border is what separates them. */
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 6px;
  font-size: 0.92rem;
  font-weight: 700;
}
.sum-transfer .amt { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; }
.sum-transfer .mark-paid {
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  background: transparent;
  /* --accent measures 3.57:1 as 11.5px text on the card — this is read
     outdoors, on a bright phone, while people divide cash. */
  color: var(--accent-strong);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 11px 14px;   /* 44px tall with the font metrics */
  min-height: 44px;
  cursor: pointer;
  white-space: nowrap;
}
.sum-add-pay {
  display: block;
  width: 100%;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 10px;
  cursor: pointer;
  margin-top: 2px;
}
.sum-pay {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  font-weight: 700;
}
.sum-pay .sp-when { font-size: 0.7rem; font-weight: 600; color: var(--muted); }
.sum-pay .amt { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; }
.sum-pay .mini { padding: 11px; }
.sum-settled { text-align: center; color: var(--live-ink); font-weight: 800; padding: 10px; }
/* Collapsible summary sections — progressive disclosure keeps the sheet calm */
.sum-fold { margin-bottom: 16px; }
.sum-fold > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  -webkit-tap-highlight-color: transparent;
}
.sum-fold > summary::-webkit-details-marker { display: none; }
.sum-fold > summary .sum-head { margin: 0; flex: 1; }
.sum-fold .fold-chev { color: var(--muted); transition: transform 0.15s; flex: none; }
.sum-fold[open] .fold-chev { transform: rotate(180deg); }
.sum-fold > *:not(summary) { margin-top: 4px; }
/* Expandable balance rows: tap a person to see their expenses + payments */
.bal-details { border-bottom: 1px solid var(--border); }
.bal-details > summary { list-style: none; cursor: pointer; }
.bal-details > summary::-webkit-details-marker { display: none; }
.bal-details .bal-row { border-bottom: none; }
.bal-details .bal-chev { transition: transform 0.15s; align-self: center; color: var(--muted); flex: none; }
.bal-details[open] .bal-chev { transform: rotate(180deg); }
.bal-exp { padding: 0 2px 10px; }
.bd-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}
.bd-row .bd-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bd-row .bd-amts { margin-left: auto; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bal-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  font-weight: 700;
}
.bal-row .b-sub { font-size: 0.72rem; font-weight: 600; color: var(--muted); }
.bal-row .b-net { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; }
.bal-row .b-net.pos { color: var(--live-ink); }
.bal-row .b-net.neg { color: var(--warn); }
.bar-row { display: grid; grid-template-columns: 86px 1fr auto; align-items: center; gap: 8px; padding: 4px 0; }
.bar-row .br-label { font-size: 0.8rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .br-track { height: 10px; border-radius: 999px; background: var(--card-2); overflow: hidden; }
.bar-row .br-fill { height: 100%; border-radius: 999px; background: var(--chart-line); min-width: 2px; }
.bar-row .br-amt { font-size: 0.78rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); }
.sum-note { font-size: 0.7rem; color: var(--muted); font-weight: 600; margin-top: 4px; }

/* ---------- Currency detail + rate chart ---------- */
:root { --chart-line: #0d9488; } /* validated vs light card */
:root[data-theme="dark"] { --chart-line: #2aa79a; } /* validated vs dark card */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --chart-line: #2aa79a; }
}
.detail-rate {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  padding: 0 2px 12px;
}
.chg {
  font-size: 0.75rem;
  font-weight: 800;
  border-radius: 7px;
  padding: 3px 8px;
}
.chg.up { color: var(--live-ink); background: color-mix(in srgb, var(--live) 14%, transparent); }
.chg.down { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.chart-box {
  position: relative;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 10px 6px;
  min-height: 152px; /* fixed → no shift when the chart loads in */
  margin-bottom: 10px;
}
.chart-box .loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 136px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}
.chart-box .chart-fail { flex-direction: column; gap: 12px; text-align: center; }
.rate-chart { display: block; width: 100%; height: auto; touch-action: none; }
.rate-chart .grid { stroke: var(--border); stroke-width: 1; }
.rate-chart .line { stroke: var(--chart-line); stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.rate-chart .area { fill: var(--chart-line); opacity: 0.1; }
.rate-chart .dot-end { fill: var(--chart-line); }
.rate-chart .cross { stroke: var(--chart-line); stroke-width: 1.5; opacity: 0.8; }
.rate-chart .dot-hover { fill: var(--chart-line); stroke: var(--card-2); stroke-width: 2.5; r: 5; }
.rate-chart .ax { fill: var(--muted); font-size: 10px; font-weight: 600; font-family: inherit; }
.rate-chart .ax.end { text-anchor: end; }
.chart-tip {
  position: absolute;
  top: 2px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 4px 9px;
  border-radius: 7px;
  pointer-events: none;
  white-space: nowrap;
}
#detail-note { min-height: 1.2em; margin: 0 2px 4px; }
.avg-line { margin: 0 2px 10px; font-weight: 700; min-height: 1.2em; }
.avg-line.up { color: var(--live-ink); }
.avg-line.down { color: var(--warn); }
.range-seg { justify-content: center; margin-bottom: 10px; }
.range-seg button { flex: 1; }

/* ---------- Pocket rule ---------- */
.pocket-rule {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.pocket-rule .pr-head {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.pocket-rule .pr-rule {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
}
.pocket-rule .pr-ex {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.pocket-rule .pr-err { font-size: 0.72rem; font-weight: 600; color: var(--muted); margin-top: 7px; }

/* ---------- QR scanner ---------- */
.scan-box {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 52dvh;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 12px;
}
.scan-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute;
  inset: 18%;
  border: 3px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35);
}

/* ---------- Toast ---------- */
.toast.has-action { pointer-events: auto; display: flex; align-items: center; gap: 12px; }
.toast-act {
  background: none;
  border: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  padding: 4px 2px;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(30px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 11px 20px;
  border-radius: 18px;
  z-index: 50;
  pointer-events: none;
  max-width: calc(100vw - 32px); /* long messages wrap, never clip */
  width: max-content;
  text-align: center;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in {
  from { transform: translate(-50%, 8px); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Profile: who you are, visible without opening anything ---------- */
/* The button must carry its own size: its old size came from the 20px
   gear inside it, so once that became an <img> there was nothing left to
   size it and the picture rendered at its natural size. 40px matches the
   scan button beside it (20px glyph + 10px padding each side). */
.avatar-btn {
  position: relative;
  padding: 0;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  overflow: visible;
}
.avatar-btn img,
.avatar-btn .avatar-initials {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
/* `display: block` lived in the rule above and out-specified the
   `display: grid` below, so place-items had nothing to centre and the
   initials sat top-left. The image needs block; the initials need grid. */
.avatar-btn img { display: block; }
.avatar-btn .avatar-anon { width: 20px; height: 20px; }
.avatar-initials {
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 800;
  /* Letter-spacing is added AFTER the last glyph too, so centred text
     sits half a space left of true centre. Pull it back by the same
     amount — visible on two letters in a 44px circle. */
  letter-spacing: 0.02em;
  text-indent: 0.02em;
  background: var(--accent-soft);
  color: var(--accent-ink);
  line-height: 1;
}
/* Signed out is a state you should never have to go looking for. */
.avatar-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--warn);
  border: 2px solid var(--bg);
}
.signed-out-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 16px 10px;
  padding: 11px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.45;
}
.signed-out-strip span { flex: 1; min-width: 0; }
.signed-out-strip .place-act { flex: none; }

.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.avatar-big {
  position: relative;
  flex: none;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--card-2);
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}
.avatar-big img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar-big > span:not(.avatar-edit-hint) {
  /* Same treatment as the header avatar: grid centring rather than
     relying on the parent, and a baseline that doesn't drift. */
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  line-height: 1;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--accent-ink);
}
.avatar-big .avatar-edit-hint {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.62rem;
  display: grid;
  place-items: center;
  border: 2px solid var(--card);
}
.profile-who { min-width: 0; }
.profile-who strong { display: block; font-size: 1rem; font-weight: 800; }
.profile-who .hint { display: block; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Signed-out badge: accent means "there's something here", amber means
   something actually went wrong. It survives dismissing the prompt. */
.avatar-dot { background: var(--accent); }
.avatar-dot.warn { background: var(--warn); }
.signed-out-strip .place-x { flex: none; }

