:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1d2124;
  --muted: #6b7075;
  --line: #e6e2d9;
  --accent: #0f8f6c;
  --accent-ink: #ffffff;
  --accent-soft: #e2f4ec;
  --pos: #0f8f6c;
  --neg: #c4501f;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .05);
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181a;
    --card: #1f2225;
    --ink: #eceae6;
    --muted: #9aa0a5;
    --line: #2e3236;
    --accent: #3cc49b;
    --accent-ink: #0b1f18;
    --accent-soft: #1d3a31;
    --pos: #4fd1a6;
    --neg: #f08a5d;
    --danger: #ff8a80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }
a, button, select, label { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.pad { padding: 2rem 1rem; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { font-variant-numeric: tabular-nums; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 720px; margin: 0 auto; gap: 8px;
  padding: calc(14px + env(safe-area-inset-top)) var(--gutter-r) 14px var(--gutter-l);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; color: var(--ink); flex: none; }
#user-slot { display: flex; align-items: center; gap: 4px; font-size: .9rem; min-width: 0; }
.user-name { min-width: 0; flex-shrink: 1; }
.user-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

:root {
  --gutter-l: max(16px, env(safe-area-inset-left));
  --gutter-r: max(16px, env(safe-area-inset-right));
}
main { max-width: 720px; margin: 0 auto; padding: 0 var(--gutter-r) 48px var(--gutter-l); }
section { margin-top: 22px; }
section > h2 { margin-bottom: 10px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow);
}
.card.padded { padding: 16px; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  color: inherit; width: 100%; background: none; border: 0; font: inherit; text-align: left;
}
button.row, a.row { cursor: pointer; }
@media (hover: hover) {
  button.row:hover, a.row:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
}
button.row:active, a.row:active { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.row .grow { flex: 1; min-width: 0; }
.row .title {
  font-weight: 600; overflow: hidden; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
}
.row .right { text-align: right; font-size: .9rem; white-space: nowrap; }
.date-chip {
  width: 42px; flex: none; text-align: center; line-height: 1.1; font-size: .72rem;
  color: var(--muted); text-transform: uppercase;
}
.date-chip b { display: block; font-size: 1.15rem; color: var(--ink); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: .85rem;
  background: var(--accent-soft); color: var(--accent);
}
.icon-pay { background: color-mix(in srgb, var(--pos) 15%, transparent); color: var(--pos); }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 10px 18px; font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  white-space: nowrap;
}
@media (hover: hover) {
  .btn:hover { border-color: color-mix(in srgb, var(--ink) 25%, var(--line)); }
  .btn.primary:hover { filter: brightness(1.05); }
}
.btn:active:not(:disabled) { filter: brightness(.94); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row.stretch > .btn { flex: 1; }

.hero { padding: 6px 0 4px; }
.hero h1 { margin-bottom: 6px; }
.totals { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pill {
  border-radius: 999px; padding: 6px 12px; font-size: .9rem; font-weight: 600;
  background: var(--card); border: 1px solid var(--line);
}
.pill.pos { background: color-mix(in srgb, var(--pos) 12%, var(--card)); border-color: transparent; }
.pill.neg { background: color-mix(in srgb, var(--neg) 12%, var(--card)); border-color: transparent; }

.login {
  max-width: 380px; margin: 10vh auto 0; text-align: center; padding: 32px 24px;
}
.login img { margin-bottom: 12px; }
.login p { margin: 8px 0 24px; }
.login .btn.primary { width: 100%; }
.login .error:empty { display: none; }
.login form { margin-top: 4px; display: grid; gap: 10px; }
.login p strong { color: var(--ink); overflow-wrap: anywhere; }
input.otp { text-align: center; font-size: 1.6rem; font-weight: 700; letter-spacing: .35em; font-variant-numeric: tabular-nums; }

/* forms */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .row:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
@media (max-width: 440px) {
  .grid2 { grid-template-columns: minmax(0, 1fr); gap: 0; }
}
.grid2 label { margin-top: 14px; }
.amount-wrap { display: grid; grid-template-columns: 110px 1fr; gap: 8px; }
.amount-wrap input { font-size: 1.25rem; font-weight: 700; }
.inline-check { display: flex; align-items: center; gap: 10px; }
.inline-check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }

.seg {
  display: grid; grid-template-columns: repeat(5, 1fr); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px;
}
.seg button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  font-size: .85rem; border-radius: 9px; padding: 8px 0; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.split-rows { margin-top: 8px; }
.split-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.split-row:first-child { border-top: 0; }
.split-row .name { flex: 1; min-width: 0; }
.split-row input[type="number"], .split-row input[inputmode] { width: 96px; text-align: right; min-height: 38px; padding: 6px 10px; }
.split-row .share { width: 84px; text-align: right; font-size: .9rem; color: var(--muted); }
.split-status { font-size: .875rem; margin-top: 6px; }

.error { color: var(--danger); font-size: .9rem; margin-top: 12px; min-height: 1.2em; }

dialog {
  border: 0; padding: 0; background: var(--card); color: var(--ink);
  width: min(560px, 100vw); max-height: 92vh; max-height: 92dvh;
  border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(10, 12, 14, .45); }
.sheet {
  padding: 0 20px; overflow: auto; overscroll-behavior: contain;
  max-height: 92vh; max-height: 92dvh;
}
/* Title and action buttons stay pinned while a long form scrolls between them. */
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 1; background: var(--card);
  margin: 0 -20px 4px; padding: 16px 12px 8px 20px;
}
.sheet-foot {
  display: flex; gap: 10px; position: sticky; bottom: 0; z-index: 1; background: var(--card);
  margin: 20px -20px 0; padding: 12px 20px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.sheet-foot .btn.primary { flex: 1; }
@media (max-width: 600px) {
  dialog {
    margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 20px 20px 0 0;
  }
}

.group-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-top: 4px; }
.group-head h1 { overflow-wrap: anywhere; }
section > .group-head { align-items: center; }
.back { display: inline-block; font-size: .9rem; margin-bottom: 8px; padding: 6px 0; }
.copy-box { display: flex; gap: 8px; }
.copy-box input { min-width: 0; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: .9rem; font-weight: 600; z-index: 10; box-shadow: 0 6px 24px rgba(0,0,0,.2);
}

/* itemized split */
.items { display: grid; gap: 10px; margin-top: 10px; }
.item { border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.item-top { display: flex; gap: 8px; align-items: center; }
.item-top .item-name { flex: 1; min-width: 0; }
.item-top .item-amount { width: 96px; flex: none; text-align: right; }
.item-remove { flex: none; padding: 6px 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; font-size: .85rem;
  font-weight: 600; border-radius: 999px; padding: 6px 12px; min-height: 34px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip-all { border-style: dashed; }
.item-summary { margin-top: 12px; }
.item-summary .split-row .share { width: auto; color: var(--ink); font-weight: 600; }
.split-status .btn { vertical-align: middle; }

/* ---------- Go/htmx version: classes replacing the old inline styles ---------- */
.mt6 { margin-top: 6px; }
.mt10 { margin-top: 10px; }
.mt12 { margin-top: 12px; }
.mt16 { margin-top: 16px; }
.btn-row.centered { justify-content: center; margin-top: 12px; }
.invite-hint { margin: 4px 0 10px; }
.avatar.big { margin: 0 auto 12px; width: 56px; height: 56px; font-size: 1.2rem; }
.login > img { display: block; margin: 0 auto 12px; }
a.btn { color: var(--ink); }
a.btn.primary { color: var(--accent-ink); }
.split-row .unit { width: 1.4em; flex: none; }
label.split-row { margin: 0; color: inherit; font-weight: 400; font-size: 1rem; }

/* segmented control built from radio buttons */
.seg label {
  display: grid; place-items: center; margin: 0; cursor: pointer; border-radius: 9px; padding: 8px 0;
  color: var(--muted); font-size: .85rem; font-weight: 600;
}
.seg input, .chip input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.seg label:has(input:checked) { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.seg label:has(input:focus-visible), .chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }

/* item chips are checkbox labels */
label.chip { display: inline-flex; align-items: center; margin: 0; position: relative; }
.chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.htmx-request.btn, .htmx-request .btn[type=submit] { opacity: .7; }
