/* Layout: one narrow column like a notes page. Ledger of bills on top, the per-person tally under it, the household roster last. */
:root {
  --bg: #f2f5f3;
  --surface: #ffffff;
  --ink: #16211d;
  --muted: #5d6b65;
  --line: #d9e0dc;
  --accent: #17694f;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe7;
  --warn: #a4530a;
  --danger: #b3261e;
  --display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111715; --surface: #1a2320; --ink: #e8efeb; --muted: #9aa9a2; --line: #2c3833;
    --accent: #5fcfa6; --accent-ink: #0c1a15; --accent-soft: #1e3a30; --warn: #f0a85a; --danger: #ff8a80;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111715; --surface: #1a2320; --ink: #e8efeb; --muted: #9aa9a2; --line: #2c3833;
  --accent: #5fcfa6; --accent-ink: #0c1a15; --accent-soft: #1e3a30; --warn: #f0a85a; --danger: #ff8a80;
  color-scheme: dark;
}
* { box-sizing: border-box; }
/* The old sandbox supplied this. Without it, classes that set display (.viewer, form.add) beat the hidden attribute. */
[hidden] { display: none !important; }
body {
  margin: 0; /* also supplied by the old sandbox */
  background: var(--bg); color: var(--ink);
  font-family: var(--body); font-size: 16px; line-height: 1.45;
  padding-block: 28px 56px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.wrap { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 32px; }
h1, h2 { font-family: var(--display); margin: 0; text-wrap: balance; }
h1 { font-size: 2.1rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.top { display: flex; flex-direction: column; gap: 6px; }
.total { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.total b { font-family: var(--display); font-size: 1.5rem; font-weight: 600; color: var(--accent); }
.note { color: var(--warn); font-size: 0.85rem; }

section { display: flex; flex-direction: column; gap: 12px; }
.head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.empty { padding: 18px 14px; color: var(--muted); }

.bill-row {
  width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px;
  padding: 12px 14px; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.bill-row .name { font-weight: 500; overflow-wrap: anywhere; }
.bill-row .amt { font-weight: 600; text-align: right; }
.bill-row .meta { grid-column: 1 / -1; font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.bill-row .meta.bad { color: var(--warn); }

.editor { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 12px; }
.fields { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: 8px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); min-width: 0; }
input[type="text"] {
  width: 100%; min-width: 0; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: 0.9rem; padding: 6px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: transparent; color: var(--muted);
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 500; }
form.add .scan { grid-column: 1 / -1; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.thumb { width: 64px; height: 64px; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg); cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.viewer {
  position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; gap: 12px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px)); padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.viewer img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.chip.new { border-style: dashed; color: var(--accent); }
#lists { margin-bottom: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.link { font: inherit; font-size: 0.85rem; background: none; border: 0; padding: 4px 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link.danger { color: var(--danger); }
.btn {
  font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink); cursor: pointer; white-space: nowrap;
}
.btn.ghost { background: transparent; color: var(--accent); font-weight: 500; padding: 6px 12px; font-size: 0.85rem; }
form.add { display: grid; grid-template-columns: minmax(0, 1fr) 110px auto; gap: 8px; }
form.add.one { grid-template-columns: minmax(0, 1fr) auto; }
@media (max-width: 400px) { form.add { grid-template-columns: minmax(0, 1fr) 96px; } form.add .btn { grid-column: 1 / -1; } form.add.one { grid-template-columns: minmax(0, 1fr) auto; } form.add.one .btn { grid-column: auto; } }

.owe { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 12px 14px; }
.owe .who { font-weight: 500; overflow-wrap: anywhere; }
.owe .sum { font-family: var(--display); font-weight: 600; font-size: 1.1rem; color: var(--accent); text-align: right; }
.owe .parts { grid-column: 1 / -1; font-size: 0.82rem; color: var(--muted); overflow-wrap: anywhere; }
.owe .sum.settled { color: var(--muted); text-decoration: line-through; }
.owe .pays { grid-column: 1 / -1; margin-top: 8px; }
.owe .pays .chip { font-size: 0.82rem; padding: 5px 10px; }
.owe .payall { grid-column: 1 / -1; }
.pill { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; vertical-align: 2px; }

.person { display: inline-flex; align-items: center; gap: 4px; padding: 5px 6px 5px 12px; border-radius: 999px; background: var(--accent-soft); font-size: 0.9rem; }
.person button { font: inherit; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 999px; }
.person button.sure { color: var(--danger); font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
