/* Layout: shopping list and cart on the left, receipt-style total on the right (above the lists on phones) */
:root {
  --bg: #eef2ec;
  --surface: #ffffff;
  --ink: #1b2a21;
  --muted: #5d6e63;
  --line: #d5ddd4;
  --accent: #2e7a4c;
  --accent-ink: #ffffff;
  --paper: #fbfcf7;
  --danger: #b4412a;
  --warn-bg: #fbeee0;
  --warn-ink: #7a4513;
  --focus: #2e7a4c55;
  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111814; --surface: #19221d; --ink: #e4ece6; --muted: #93a499;
    --line: #2b3830; --accent: #5cc187; --accent-ink: #0d1a12; --paper: #1d2721;
    --danger: #ef8a72; --warn-bg: #3a2a18; --warn-ink: #f3c48e; --focus: #5cc18766;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 15px; line-height: 1.5;
  padding-top: calc(env(safe-area-inset-top, 0px) + 20px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 32px);
  padding-left: calc(env(safe-area-inset-left, 0px) + 16px);
  padding-right: calc(env(safe-area-inset-right, 0px) + 16px);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.right { text-align: right; }

h1 {
  font-family: var(--font-display); font-weight: 800; font-size: clamp(28px, 5vw, 40px);
  letter-spacing: -0.02em; line-height: 1; margin: 0; text-wrap: balance;
}
h1 span { color: var(--accent); }

/* 16px inputs stop iOS from zooming the page on focus */
select, input {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
button {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px;
  border: 1px solid transparent; padding: 10px 16px; color: inherit;
}
button:disabled { opacity: .55; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); }
.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.danger { background: var(--danger); color: var(--surface); }
.wide { width: 100%; }
.link { background: none; border: 0; padding: 4px 0; color: var(--muted); font-weight: 500; text-decoration: underline; }
.form-msg { grid-column: 1 / -1; margin: 0; font-size: 14px; color: var(--danger); }
@media (hover: hover) {
  .primary:hover { filter: brightness(1.07); }
  .ghost:hover { color: var(--ink); }
}

/* Sign-in and name screens */
.center-screen { min-height: 70vh; display: grid; place-items: center; }
.gate {
  width: 100%; max-width: 380px; display: grid; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px;
}
.gate h1 { font-size: 32px; }
.gate p { margin: 0; }
.field-label { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips:empty { display: none; }
.chip-btn {
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; font-weight: 600; font-size: 14px;
}

/* App shell */
.wrap { max-width: 1040px; margin: 0 auto; display: grid; gap: 20px; }
.top { display: flex; align-items: end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sub { margin: 6px 0 0; color: var(--muted); }
.top-tools { display: flex; align-items: center; gap: 8px; }
.top-tools select { padding: 6px 10px; }
.offline { margin: 0; padding: 10px 14px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-ink); font-weight: 500; }

.main { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.col { display: grid; gap: 20px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 14px 16px 10px; }
.card-head h2 { font-family: var(--font-display); font-weight: 600; font-size: 19px; margin: 0; }
.count { font-size: 12px; color: var(--muted); }
.by { font-size: 12px; font-weight: 500; color: var(--muted); }

/* Shopping list */
.shop-add { display: flex; gap: 8px; padding: 0 16px 14px; }
.shop-add input { flex: 1; }
.shop-empty { margin: 0; padding: 4px 16px 18px; color: var(--muted); font-size: 14px; }
.srow { border-top: 1px solid var(--line); }
.srow-top { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; }
.found {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left;
  background: transparent; padding: 10px; font-weight: 600;
}
.found .box { flex: none; width: 22px; height: 22px; border: 2px solid var(--muted); border-radius: 6px; }
.found .nm { min-width: 0; overflow-wrap: anywhere; display: grid; }
.found .hint { margin-left: auto; flex: none; font-size: 12px; font-weight: 500; color: var(--muted); }
.srow.open { background: var(--paper); }
.srow.open .found .box { border-color: var(--accent); background: var(--accent); }
.x { padding: 8px; background: transparent; color: var(--muted); line-height: 0; border-radius: 6px; }
.x svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
@media (hover: hover) {
  .found:hover { background: var(--bg); }
  .found:hover .box { border-color: var(--accent); }
  .x:hover { color: var(--danger); background: var(--bg); }
}
.found-form {
  display: grid; grid-template-columns: 90px 140px auto; gap: 10px; align-items: end;
  padding: 0 16px 14px 50px;
}
.found-form .btns { display: flex; gap: 8px; }

/* Cart */
.add {
  display: grid; gap: 10px; padding: 0 16px 14px;
  grid-template-columns: minmax(0, 1fr) 90px 140px auto; align-items: end;
  border-bottom: 1px solid var(--line);
}
.field { display: grid; gap: 4px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.field input { width: 100%; }
.add-actions { display: flex; gap: 8px; }

.list-head, .row {
  display: grid; grid-template-columns: minmax(0, 1fr) 118px 104px 108px 128px;
  gap: 12px; align-items: center; padding: 10px 16px;
}
.list-head {
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid var(--line);
}
.list-head:has(+ #rows:empty) { display: none; }
.row + .row { border-top: 1px solid var(--line); }
.row.editing { background: var(--paper); }
.name { font-weight: 600; overflow-wrap: anywhere; }
.name .by { display: block; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; }
.stepper button { padding: 6px 12px; background: transparent; font-size: 17px; line-height: 1; }
.stepper span { min-width: 30px; text-align: center; }
.line-total { font-weight: 600; }
.row-actions { display: flex; justify-content: end; align-items: center; gap: 4px; }
.icon { padding: 7px; background: transparent; color: var(--muted); border-radius: 6px; line-height: 0; }
.icon svg, .remove svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon svg { width: 18px; height: 18px; }
.remove {
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 10px; font-size: 13px;
  background: transparent; color: var(--danger); border: 1px solid var(--line); border-radius: 6px;
}
.remove svg { width: 15px; height: 15px; }
@media (hover: hover) {
  .stepper button:hover { color: var(--accent); }
  .icon:hover { color: var(--ink); background: var(--bg); }
  .remove:hover { border-color: var(--danger); background: var(--bg); }
}
.each { display: none; }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-family: var(--font-display); font-size: 20px; margin-bottom: 4px; }

/* Receipt */
.receipt {
  background: var(--paper); border: 1px solid var(--line); border-radius: 4px;
  padding: 20px 20px 26px; font-family: var(--font-mono); font-size: 13px;
  position: sticky; top: calc(env(safe-area-inset-top, 0px) + 16px);
  -webkit-mask: radial-gradient(circle at 50% 100%, transparent 4px, #000 4.5px) bottom / 8px 8px repeat-x,
                linear-gradient(#000, #000) top / 100% calc(100% - 7px) no-repeat;
          mask: radial-gradient(circle at 50% 100%, transparent 4px, #000 4.5px) bottom / 8px 8px repeat-x,
                linear-gradient(#000, #000) top / 100% calc(100% - 7px) no-repeat;
}
.receipt h2 { font-family: var(--font-mono); font-size: 13px; font-weight: 600; letter-spacing: 0.2em; text-align: center; margin: 0 0 4px; }
.receipt .stamp { text-align: center; color: var(--muted); margin: 0 0 12px; }
.rule { border: 0; border-top: 1px dashed var(--muted); margin: 10px 0; opacity: 0.6; }
.rline { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.rline span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.rlines { display: grid; gap: 2px; max-height: 260px; overflow-y: auto; }
.grand { font-size: 20px; font-weight: 600; margin-top: 4px; }
.grand span:last-child { color: var(--accent); }
.receipt .meta { color: var(--muted); }
.clear { margin-top: 14px; width: 100%; font-family: var(--font-body); font-size: 13px; }
.confirm { margin-top: 12px; font-family: var(--font-body); font-size: 13px; display: grid; gap: 8px; }
.confirm p { margin: 0; }
.confirm div { display: flex; gap: 8px; }
.confirm button { flex: 1; padding: 8px; }

.foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.status { font-size: 13px; color: var(--muted); margin: 0; }

@media (max-width: 760px) {
  .main { grid-template-columns: 1fr; }
  .receipt { position: static; order: -1; }
  .add { grid-template-columns: 1fr 1fr; }
  .add .field:first-child { grid-column: 1 / -1; }
  .add-actions { grid-column: 1 / -1; }
  .add-actions .primary { flex: 1; }
  .found-form { grid-template-columns: 1fr 1fr; padding-left: 16px; }
  .found-form .btns { grid-column: 1 / -1; }
  .found-form .btns .primary { flex: 1; }
  .found .hint { display: none; }
  .list-head { display: none; }
  .row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name total" "qty actions";
    row-gap: 8px;
  }
  .row .c-name { grid-area: name; }
  .row .c-qty { grid-area: qty; display: flex; align-items: center; gap: 10px; }
  .row .c-price { display: none; }
  .row .c-total { grid-area: total; }
  .row .c-actions { grid-area: actions; }
  .each { display: inline; color: var(--muted); font-size: 13px; white-space: nowrap; }
}
@media (prefers-reduced-motion: no-preference) {
  .row, .srow { transition: background-color .2s; }
}
