/* Design tokens. Foreground colours meet 4.5:1 on their backgrounds;
   --line-strong (3.7:1) outlines inputs and other controls. */
:root {
  --canvas: #f4f6f3;
  --surface: #ffffff;
  --surface-subtle: #f0f3ef;
  --ink: #14201a;
  --muted: #4d5a52;
  --line: #dfe5df;
  --line-strong: #78877d;

  --green: #0b6e4f;
  --green-dark: #085a40;
  --green-soft: #e2f3ea;
  --amber: #8a4b08;
  --amber-soft: #fef3d7;
  --blue: #175cd3;
  --blue-soft: #e8f0ff;
  --red: #b42318;
  --red-soft: #fef3f2;
  --focus: #1570ef;

  --radius-control: 10px;
  --radius-container: 14px;
  --shadow-raised: 0 1px 2px rgb(16 32 24 / 0.06);
  --shadow-overlay: 0 8px 24px rgb(16 32 24 / 0.16), 0 2px 4px rgb(16 32 24 / 0.08);
  --touch: 44px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: #dfe5df;
  color: var(--ink);
  font: 1rem/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p, ul, ol, dl, dd { margin: 0; padding: 0; }
ul, ol { list-style: none; }
small { font-size: 0.8125rem; color: var(--muted); }
em { font-style: normal; font-weight: 400; color: var(--muted); }
svg { flex: none; }

#app {
  height: 100dvh; max-width: 480px; margin: 0 auto;
  display: flex; flex-direction: column;
  background: var(--canvas);
}

/* ---------- frame ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.titles { min-width: 0; }
.eyebrow { font-size: 0.75rem; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
h1 { font-size: 1.375rem; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
h1:focus { outline: none; }
.switch {
  flex: none; min-height: var(--touch); padding: 0 12px; display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface);
  font-size: 0.8125rem; font-weight: 600; text-transform: capitalize;
}

main {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
main > * { flex-shrink: 0; }
main.login { padding: calc(40px + env(safe-area-inset-top)) 20px 24px; gap: 20px; }

.tabs {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tab {
  min-height: 56px; border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 0.75rem; font-weight: 600;
}
.tab-icon { position: relative; display: flex; align-items: center; justify-content: center; width: 56px; height: 30px; border-radius: 999px; }
.tab.on { color: var(--green-dark); }
.tab.on .tab-icon { background: var(--green-soft); }
.badge {
  position: absolute; top: -2px; right: 6px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--red); color: #fff; font-size: 0.6875rem; font-weight: 700; line-height: 18px; text-align: center;
}

/* ---------- text ---------- */
.display { font-size: 1.75rem; }
.title { font-size: 1.25rem; line-height: 1.25; font-weight: 700; }
.lead { color: var(--muted); }
.section { margin-top: 8px; font-size: 0.8125rem; font-weight: 700; color: var(--muted); letter-spacing: 0.03em; text-transform: uppercase; }
.section-row { margin-top: 8px; flex-wrap: wrap; }
.section-row .section { margin-top: 0; }
.muted, .hint { font-size: 0.875rem; color: var(--muted); }
.hint { font-size: 0.8125rem; }
.num, .amount, .qty, .count { font-variant-numeric: tabular-nums; }
.num { font-weight: 700; white-space: nowrap; }
.owe { color: var(--amber); }
.amount { font-size: 1.375rem; font-weight: 700; white-space: nowrap; }
.qty { font-size: 1.25rem; font-weight: 700; }
.msg { font-size: 0.9375rem; }

/* ---------- layout helpers ---------- */
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.tight { gap: 4px; }
.col { display: flex; flex-direction: column; min-width: 0; }
.col.end { align-items: flex-end; text-align: right; }
.grow { flex: 1; min-width: 0; }
.split { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.split.top-align { align-items: flex-start; }
.split.rule { border-top: 1px solid var(--line); padding-top: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- surfaces ---------- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-container); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 10px 14px;
  background: transparent; border: 0; text-align: left;
}
.row.top { align-items: flex-start; }
button.row > svg:last-child { color: var(--muted); }
button.row:active, .banner:active { background: var(--surface-subtle); }
.row.picked { background: #f3faf6; }

.cards { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-container); padding: 14px; box-shadow: var(--shadow-raised); }
.card.request { background: #fffaf0; border-color: #f1d9a3; }
.card.attention { border-color: var(--amber); }
.card.off { background: var(--surface-subtle); box-shadow: none; }
.plain { display: flex; flex-direction: column; gap: 10px; }

.hero { background: var(--green); color: #fff; border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.hero h2 { font-size: 1.25rem; line-height: 1.25; }
.hero p { font-size: 0.875rem; }
.hero-kicker { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
.stats div { background: rgb(255 255 255 / 0.14); border-radius: var(--radius-control); padding: 8px 10px; }
.stats dt { font-size: 0.75rem; }
.stats dd { font-size: 1.125rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.banner {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 8px 8px 8px 14px; text-align: left;
  background: var(--amber-soft); color: var(--amber); border: 1px solid #f1d9a3; border-radius: var(--radius-container); font-weight: 600;
}
.banner-act { flex: none; min-height: 36px; display: inline-flex; align-items: center; padding: 0 12px; border-radius: var(--radius-control); background: var(--amber); color: #fff; font-size: 0.875rem; }

.note { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: var(--radius-control); font-size: 0.875rem; font-weight: 600; }
.note.green { background: var(--green-soft); color: var(--green-dark); }
.note.amber { background: var(--amber-soft); color: var(--amber); }
.note.grey { background: var(--surface-subtle); color: var(--muted); }

.money { background: var(--amber-soft); border: 1px solid #f1d9a3; border-radius: var(--radius-container); padding: 14px; display: flex; flex-direction: column; gap: 12px; color: var(--amber); }
.money .field span, .money .hint { color: var(--amber); }

.visit { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius-control); background: var(--green-soft); }
.visit small { color: var(--green-dark); }
.visit-icon { display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: var(--radius-control); background: var(--surface); color: var(--green-dark); }
.when { font-size: 1.0625rem; color: var(--green-dark); }

.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 32px 16px; text-align: center; }
.empty p { color: var(--muted); font-size: 0.875rem; max-width: 30ch; }

.orderbar {
  position: sticky; bottom: -16px; margin: auto -16px -16px; padding: 12px 16px;
  display: flex; align-items: center; gap: 12px; min-height: 68px;
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 12px rgb(16 32 24 / 0.08);
}

/* ---------- small parts ---------- */
.tile, .avatar { flex: none; width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
img.tile { object-fit: cover; }
.avatar { width: 40px; height: 40px; font-size: 0.875rem; font-weight: 700; }
.t-green { background: var(--green-soft); color: var(--green-dark); }
.t-amber { background: #fdebc8; color: #8a4b08; }
.t-lime { background: #e6f4d3; color: #3f6212; }
.t-clay { background: #fde4d8; color: #9a3412; }
.t-teal { background: #d7f1ee; color: #0f5f59; }
.t-blue { background: #e2ecff; color: #1849a9; }
.t-brown { background: #f1e4d6; color: #70451c; }
.t-pink { background: #fce4ee; color: #9d1f58; }
.t-grey { background: #e9ede9; color: var(--muted); }

.pill { flex: none; display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; white-space: nowrap; }
.pill.green { background: var(--green-soft); color: var(--green-dark); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.blue { background: var(--blue-soft); color: #1849a9; }
.pill.grey { background: #e9ede9; color: var(--muted); }

.stop-no { flex: none; width: 28px; height: 28px; border-radius: 999px; background: var(--green-soft); color: var(--green-dark); font-size: 0.875rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.meter { display: block; height: 6px; margin-top: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 999px; background: var(--green); }

.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 1.0625rem; }
.brand-mark { width: 52px; height: 52px; border-radius: 16px; background: var(--green); color: #fff; display: flex; align-items: center; justify-content: center; }

/* ---------- controls ---------- */
.btn {
  min-height: var(--touch); padding: 0 16px; border: 1px solid transparent; border-radius: var(--radius-control);
  font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center;
}
.btn.big { min-height: 50px; width: 100%; border-radius: 12px; }
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:active { background: var(--green-dark); }
.btn.quiet { background: #e9ede9; color: var(--ink); }
.btn.outline { background: var(--surface); color: var(--green-dark); border-color: var(--green); }
.btn.danger { background: var(--surface); color: var(--red); border-color: var(--red); }
.filebtn { position: relative; cursor: pointer; }
.filebtn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }

.textbtn { min-height: var(--touch); padding: 0 8px; border: 0; background: transparent; color: var(--green-dark); font-weight: 600; font-size: 0.875rem; text-decoration: underline; text-underline-offset: 3px; }
.textbtn.danger { color: var(--red); align-self: center; }
.backlink { align-self: flex-start; min-height: var(--touch); margin: -8px 0 -4px -8px; padding: 0 10px 0 4px; display: inline-flex; align-items: center; gap: 2px; border: 0; background: transparent; color: var(--green-dark); font-weight: 600; }
.account { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.8125rem; font-weight: 600; }
.field input, .field select {
  min-height: var(--touch); width: 100%; padding: 0 12px; font-size: 1rem; font-weight: 400;
  border: 1px solid var(--line-strong); border-radius: var(--radius-control); background: var(--surface); color: var(--ink);
}
.field input[type="file"] { padding: 9px 12px; font-size: 0.875rem; }
.inline { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.inline .field { flex: 1 1 140px; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--touch); font-weight: 600; font-size: 0.9375rem; }
.check input { width: 22px; height: 22px; accent-color: var(--green); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 4px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
.chip { flex: none; min-height: var(--touch); padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); color: var(--ink); font-size: 0.875rem; font-weight: 600; }
.chip.on { background: var(--green); border-color: var(--green); color: #fff; }

.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.day { min-height: var(--touch); padding: 0; border: 1px solid var(--line-strong); border-radius: var(--radius-control); background: var(--surface); font-size: 0.75rem; font-weight: 600; }
.day.on { background: var(--green); border-color: var(--green); color: #fff; }

.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 3px; border-radius: 12px; background: #e9ede9; }
.seg button { min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 0.875rem; font-weight: 600; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-raised); }

.stepper { flex: none; display: inline-flex; align-items: center; gap: 2px; }
.step { width: var(--touch); height: var(--touch); border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); font-size: 1.25rem; font-weight: 600; line-height: 1; }
.step.plus { background: var(--green); border-color: var(--green); color: #fff; }
.count { min-width: 34px; text-align: center; font-weight: 700; }

.toggle { flex: none; width: 52px; height: 32px; padding: 3px; border: 1px solid var(--line-strong); border-radius: 999px; background: #e9ede9; display: flex; }
.toggle span { width: 24px; height: 24px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow-raised); transition: transform 0.15s; }
.toggle.on { background: var(--green); border-color: var(--green); }
.toggle.on span { transform: translateX(20px); }

details.more { border-top: 1px solid var(--line); padding-top: 4px; }
main > details.more { border: 1px solid var(--line); border-radius: var(--radius-container); background: var(--surface); padding: 0 14px; }
details.more > summary { min-height: var(--touch); display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; color: var(--green-dark); font-weight: 600; font-size: 0.9375rem; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::after { content: ""; width: 8px; height: 8px; margin-left: auto; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform 0.15s; }
details.more[open] > summary::after { transform: rotate(-135deg); }
details.more > form, details.more > .hint { padding-bottom: 12px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(448px, calc(100% - 32px)); min-height: 48px; padding: 6px 6px 6px 14px;
  display: flex; align-items: center; gap: 12px;
  background: var(--ink); color: #fff; border-radius: 12px; box-shadow: var(--shadow-overlay);
  font-size: 0.9375rem; font-weight: 500; z-index: 10;
}
.toast[hidden] { display: none; }
.toast-text { flex: 1; padding: 6px 0; }
.toast button { flex: none; min-height: 36px; padding: 0 12px; border: 0; border-radius: 8px; background: rgb(255 255 255 / 0.16); color: #fff; font-weight: 700; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

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

/* Narrow phones: give the name room beside the quantity buttons. */
@media (max-width: 359px) {
  .row:has(.stepper) .tile { display: none; }
  .switch span { display: none; }
}
