:root {
  --bg: #f5f7f5;
  --card: #ffffff;
  --ink: #1c2421;
  --muted: #6b7770;
  --line: #e3e8e4;
  --green: #2e7d4f;
  --green-d: #245f3d;
  --blue: #2563aa;
  --amber: #8a5a12;
  --red: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--green-d); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 14px 20px; position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 18px; text-decoration: none; color: var(--ink); }
.topbar nav a { margin-left: 18px; text-decoration: none; color: var(--muted); font-weight: 600; }
.topbar nav a:hover { color: var(--green-d); }

.container { max-width: 880px; margin: 24px auto; padding: 0 16px; }
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 30px 16px; }

h1 { font-size: 26px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.cta { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.cta .big { font-size: 20px; font-weight: 700; }

.btn {
  display: inline-block; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-weight: 600; text-decoration: none; cursor: pointer;
  font-size: 15px;
}
.btn:hover { border-color: var(--green); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-d); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.disabled { opacity: .5; pointer-events: none; }
.big-btn { padding: 14px 22px; font-size: 17px; }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 600; }
.flash.ok { background: #e7f4ec; color: var(--green-d); }
.flash.error { background: #fbe9e7; color: var(--red); }

.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: 6px 0; }
.checklist li.done { color: var(--green-d); }
.checklist li.todo { color: var(--muted); }
.flow, ol.flow { margin: 0 0 16px; padding-left: 20px; }
.flow li { padding: 3px 0; }

form.stack label, .stack { display: block; margin-bottom: 12px; }
form label { font-weight: 600; font-size: 14px; }
form input {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 9px; font-size: 16px; /* 16px+ stops iOS auto-zoom */
}
form.inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
form.inline label { font-weight: 600; }
form.inline input { width: auto; }
code { background: #eef2ef; padding: 1px 6px; border-radius: 6px; font-size: 13px; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: #eef2ef; color: var(--muted); font-size: 12px; font-weight: 700; }
.pill.ok { background: #e7f4ec; color: var(--green-d); }

.storelist .store {
  display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line);
  border-radius: 10px; margin-bottom: 8px; font-weight: 400; cursor: pointer;
}
.storelist .store:hover { border-color: var(--green); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-bottom: 20px; }
.meal {
  display: flex; gap: 10px; padding: 14px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; cursor: pointer; box-shadow: var(--shadow);
}
.meal:hover { border-color: var(--green); }
.meal input { margin-top: 4px; }
.meal-name { font-weight: 700; }
.meal-meta { color: var(--muted); font-size: 13px; margin: 2px 0; }
.meal-note { font-size: 12.5px; }
.meal.is-pizza { outline: 2px solid #d9a922; }

.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 8px; }

.grocery { list-style: none; padding: 0; margin: 12px 0 0; }
.grocery li { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line); }
.grocery .qty { font-weight: 700; min-width: 32px; }
.grocery .gq { flex: 1; }
.grocery .src { font-size: 12px; }

.badge { padding: 3px 10px; border-radius: 999px; font-weight: 700; font-size: 13px; color: #fff; }
.badge.delivery { background: var(--blue); }
.badge.pickup { background: var(--amber); }
.method-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.toggle .chip {
  display: inline-block; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
  text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; margin-left: 6px;
}
.toggle .chip.on { background: var(--green); border-color: var(--green); color: #fff; }

.budget { margin: 6px 0 18px; }
.budget .bar { height: 10px; background: #eef2ef; border-radius: 999px; overflow: hidden; }
.budget .bar span { display: block; height: 100%; background: var(--green); }
.budget .bar span.near { background: var(--amber); }
.budget .bar span.over { background: var(--red); }
.budget-text { margin-top: 6px; }

table.items { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.items th, table.items td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.items th.r, table.items td.r { text-align: right; }
.tag { font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 6px; margin-left: 4px; }
.tag.sale { background: #e7f4ec; color: var(--green-d); }
.tag.warn { background: #fdf0e3; color: var(--amber); }
.warn-line { color: var(--amber); font-weight: 600; }

.timing p { margin: 6px 0; }
.success { text-align: center; }
.big-check { font-size: 46px; color: var(--green); line-height: 1; }

.tag.organic { background: #e7f4ec; color: var(--green-d); }
.note-organic { font-size: 13px; margin: -8px 0 16px; }

.grocery.edit li { gap: 12px; }
.qtybox { width: 62px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 16px; }
.grocery.edit .gq { flex: 1; }
.grocery.edit .rm { font-size: 12px; color: var(--muted); white-space: nowrap; font-weight: 600; }
.additem { display: flex; gap: 10px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.additem input[type=text] { flex: 1; min-width: 180px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; }

.confirm { border: 2px solid var(--green); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.rank { list-style: none; padding: 0; margin: 8px 0 0; }
.rank li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.rank .count { color: var(--muted); font-size: 13px; white-space: nowrap; }
.weeks { list-style: none; padding: 0; margin: 8px 0 0; }
.weeks li { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.weeks .wdate { font-weight: 700; min-width: 92px; }
@media (max-width: 560px) { .two-col { grid-template-columns: 1fr; } }

/* preferences form */
.card form label, form .card label { display: block; }
textarea { width: 100%; margin-top: 4px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 9px; font: inherit; font-size: 16px; resize: vertical; }
select { width: 100%; margin-top: 4px; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 9px; font: inherit; font-size: 16px; background: #fff; }
.hint { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin: 3px 0 14px; }
label.check { font-weight: 500; margin: 10px 0; display: flex; gap: 8px; align-items: center; }
label.check input { width: auto; margin: 0; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row label { flex: 1; min-width: 150px; }
.row .field { flex: 1; min-width: 150px; }
.field-label { display: block; font-weight: 600; font-size: 14px; }

/* stepper */
.stepper { display: flex; align-items: center; gap: 6px; margin: 2px 0 22px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.step a { color: inherit; text-decoration: none; }
.step .dot { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px;
  border-radius: 50%; background: #eef2ef; font-size: 12px; }
.step.on { color: var(--green-d); }
.step.on .dot { background: var(--green); color: #fff; }
.step.done { color: var(--green-d); }
.step.done .dot { background: #cde7d8; color: var(--green-d); }
.step-line { flex: 1; min-width: 14px; height: 2px; background: var(--line); border-radius: 2px; }
.step-line.done { background: #cde7d8; }

/* recipes */
.recipe-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.recipe-card h3 { font-size: 15px; margin: 0 0 8px; }
.ing-list { list-style: none; padding: 0; margin: 6px 0 0; }
.ing-list li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.ing-list .amt { font-weight: 700; margin-right: 6px; }
.steps-list { margin: 6px 0 0; padding-left: 22px; }
.steps-list li { padding: 7px 0; }
.steps-list.compact li { padding: 4px 0; font-size: 14.5px; }
.tip-card { background: #fdf7e8; border-color: #f0e3bb; }
.tip-line { background: #fdf7e8; border-radius: 9px; padding: 8px 12px; font-size: 14px; }
.recipe-link { font-weight: 700; }
.add-meal { border-style: dashed; text-decoration: none; color: var(--muted); align-items: center; }
.add-meal:hover { color: var(--green-d); }
.meal-link { text-decoration: none; color: inherit; align-items: center; }
.group-h { margin-top: 18px; text-transform: capitalize; }

/* meal editor */
.ing-grid, .ing-grid-head { display: grid; grid-template-columns: 64px 1fr 90px; gap: 10px; align-items: center; margin-bottom: 8px; }
.ing-grid-head { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; margin-bottom: 4px; }
.ing-grid .check { margin: 0; justify-content: center; }
.equip-row { display: flex; gap: 12px; flex-wrap: wrap; font-weight: 400; margin-top: 6px; }
.equip-row .check { margin: 0; }

/* phone access */
.phone-card { background: #eef4fb; border-color: #d4e3f5; }
.lan-url { font-size: 20px; font-weight: 800; margin: 4px 0 12px; word-break: break-all; }
.lan-url a { text-decoration: none; }
.share-links { margin-top: 14px; }
.share-links p { margin: 6px 0; word-break: break-all; }

/* login */
.login-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.login-card { max-width: 380px; width: 100%; text-align: center; }
.login-emoji { font-size: 44px; }
.login-input { width: 100%; padding: 13px 14px; font-size: 17px; border: 1px solid var(--line);
  border-radius: 10px; margin: 10px 0 14px; text-align: center; }
.login-btn { width: 100%; }

/* mobile + print */
@media (max-width: 640px) {
  .btn { padding: 12px 18px; font-size: 16px; }
  .topbar { flex-wrap: wrap; gap: 0; padding: 8px 12px; }
  .topbar nav { margin-left: -10px; }
  .topbar nav a { display: inline-block; padding: 10px; margin-left: 0; font-size: 14px; }
  .meal input[type=checkbox] { width: 22px; height: 22px; }
  .grocery.edit li { flex-wrap: wrap; }
  .grocery.edit .rm { font-size: 14px; padding: 8px 0; }
  .grocery.edit .rm input { width: 20px; height: 20px; }
  .two-col { grid-template-columns: 1fr; }
}
@media print {
  .topbar, .foot, .no-print, .actions, .stepper { display: none !important; }
  .card { box-shadow: none; border: none; padding: 8px 0; break-inside: avoid; }
  body { background: #fff; }
}

/* keyboard focus (equal specificity to hover rules; kept near end of file) */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.meal:focus-within, .store:focus-within {
  border-color: var(--green);
  outline: 2px solid var(--green);
  outline-offset: 2px;
}
.btn:focus-visible, a:focus-visible,
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--green-d);
  outline-offset: 2px;
}

.prefs-head { display: flex; justify-content: space-between; align-items: center; }
.prefs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; margin-top: 10px; }
.prefs-grid > div { display: flex; flex-direction: column; padding: 6px 0; border-bottom: 1px solid var(--line); }
.prefs-grid .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
@media (max-width: 560px) { .prefs-grid { grid-template-columns: 1fr; } .row label { min-width: 100%; } }
@media (max-width: 520px) {
  .cta { flex-direction: column; align-items: flex-start; }
  table.items td:nth-child(3) { display: none; }
}
