:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #f1ede4;
  --text: #22201c;
  --muted: #6b665c;
  --line: #e2ddd2;
  --brand: #2f5d50;
  --brand-strong: #244a40;
  --brand-soft: #e3eee9;
  --accent: #c8642d;
  --accent-soft: #f8e6da;
  --danger: #b3261e;
  --danger-soft: #fbe5e3;
  --ok: #2f6f3a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(34, 32, 28, .06), 0 4px 14px rgba(34, 32, 28, .05);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161714;
    --surface: #1f201c;
    --surface-2: #272823;
    --text: #ecebe6;
    --muted: #a19f96;
    --line: #34352f;
    --brand: #7fb8a4;
    --brand-strong: #9fcdbb;
    --brand-soft: #23342e;
    --accent: #e89464;
    --accent-soft: #3a2a20;
    --danger: #f2a49d;
    --danger-soft: #3b2220;
    --ok: #8fd19b;
    --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(--text);
  font: 16px/1.5 var(--sans);
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-size: clamp(1.7rem, 4vw, 2.2rem); letter-spacing: -.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
a { color: var(--brand); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
pre { background: var(--surface-2); padding: 14px 16px; border-radius: var(--radius-sm); overflow-x: auto; line-height: 1.45; margin: 0; }
pre code { background: none; padding: 0; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
.mt { margin-top: 14px; }
.mt-sm { margin-top: 8px; }
.mt-xs { margin-top: 6px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font-family: var(--serif); font-size: 1.2rem; font-weight: 600; }
.brand-mark { width: 28px; height: 28px; color: var(--brand); }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 999px; }
.tabs a {
  text-decoration: none; color: var(--muted); font-size: .92rem; font-weight: 500;
  padding: 6px 14px; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px;
}
.tabs a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.badge { background: var(--accent); color: #fff; font-size: .72rem; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center; }

.banner { max-width: 1080px; margin: 12px auto 0; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); font-size: .92rem; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
@media (max-width: 1112px) { .banner { margin-left: 16px; margin-right: 16px; } }

main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 40px; outline: none; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { color: var(--muted); margin-top: 6px; max-width: 60ch; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-size: .92rem; font-weight: 550; padding: 8px 14px; border-radius: 999px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; line-height: 1.3;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #10201b; } }
.btn.primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 5px 11px; font-size: .85rem; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { appearance: none; border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }

/* ---------- Plan view ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.search {
  flex: 1 1 220px; min-width: 0; font: inherit; padding: 9px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  appearance: none; font: inherit; font-size: .85rem; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); padding: 5px 12px; border-radius: 999px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.category { margin-bottom: 28px; }
.category-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.category-head .count { color: var(--muted); font-size: .85rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }

.meal {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; transition: border-color .15s, box-shadow .15s;
}
.meal.selected { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.meal-top { display: flex; gap: 11px; align-items: flex-start; cursor: pointer; }
.meal-top input { position: absolute; opacity: 0; pointer-events: none; }
.tick {
  flex: none; width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line); margin-top: 1px;
  display: grid; place-items: center; background: var(--surface); transition: background .12s, border-color .12s;
}
.tick svg { width: 14px; height: 14px; color: #fff; opacity: 0; }
input:checked + .tick { background: var(--brand); border-color: var(--brand); }
input:checked + .tick svg { opacity: 1; }
input:focus-visible + .tick { outline: 2.5px solid var(--accent); outline-offset: 2px; }
@media (prefers-color-scheme: dark) { .tick svg { color: #10201b; } }
.meal-name { font-weight: 600; line-height: 1.3; }
.meal-meta { display: block; font-size: .8rem; color: var(--muted); margin-top: 2px; }
.pill { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-left: 4px; vertical-align: 1px; }

.meal details { font-size: .85rem; }
.meal summary { cursor: pointer; color: var(--muted); list-style: none; display: inline-flex; align-items: center; gap: 4px; user-select: none; }
.meal summary::-webkit-details-marker { display: none; }
.meal summary::before { content: "›"; display: inline-block; transition: transform .15s; font-size: 1.1em; }
.meal details[open] summary::before { transform: rotate(90deg); }
.ing { margin-top: 8px; display: grid; gap: 6px; }
.ing-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.tag { background: var(--surface-2); padding: 2px 8px; border-radius: 6px; font-size: .8rem; }
.tag.pantry { background: transparent; border: 1px dashed var(--line); }

.side-picker { border-top: 1px dashed var(--line); padding-top: 9px; }
.side-picker .ing-label { margin-bottom: 5px; display: block; }
.side-opts { display: flex; flex-wrap: wrap; gap: 5px; }
.side-opt {
  appearance: none; font: inherit; font-size: .8rem; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); padding: 3px 10px; border-radius: 999px; cursor: pointer;
}
.side-opt.suggested { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
.side-opt[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .side-opt[aria-pressed="true"] { color: #10201b; } }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; border: 1.5px dashed var(--line); border-radius: var(--radius); }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }

/* ---------- Selection bar ---------- */
.selection-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 0 12px calc(12px + env(safe-area-inset-bottom)); pointer-events: none; }
.selection-bar-inner {
  pointer-events: auto; max-width: 720px; margin: 0 auto; background: var(--text); color: var(--bg);
  border-radius: 999px; padding: 8px 8px 8px 20px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); font-size: .92rem;
}
.selection-bar .btn.ghost { color: var(--bg); }
.selection-bar .btn.ghost:hover { background: rgba(255, 255, 255, .12); }
.selection-actions { display: flex; gap: 4px; align-items: center; }

/* ---------- List view ---------- */
.list-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 820px) { .list-layout { grid-template-columns: 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 4px; flex-wrap: wrap; }
.panel-sub { color: var(--muted); font-size: .88rem; margin-bottom: 12px; }
.progress { height: 5px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 10px 0 6px; }
.progress span { display: block; height: 100%; background: var(--brand); width: 0; transition: width .2s; }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { border-top: 1px solid var(--line); }
.checklist li:first-child { border-top: 0; }
.check-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 2px; cursor: pointer; }
.check-row input { position: absolute; opacity: 0; pointer-events: none; }
.check-row .tick { width: 22px; height: 22px; border-radius: 50%; }
.item-name { display: block; font-weight: 550; }
.item-for { font-size: .8rem; color: var(--muted); }
.check-row.done .item-name { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.done-group summary { cursor: pointer; color: var(--muted); font-size: .88rem; padding: 10px 2px 4px; }

.menu-list { list-style: none; margin: 0; padding: 0; }
.menu-list li { display: grid; grid-template-columns: 124px 1fr; gap: 10px; align-items: start; padding: 9px 0; border-top: 1px solid var(--line); }
.menu-list li:first-child { border-top: 0; }
.menu-list select, .date-input { font: inherit; font-size: .85rem; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); width: 100%; }
.menu-dish { font-weight: 600; }
.menu-sides { font-size: .85rem; color: var(--muted); }

/* ---------- Pantry view ---------- */
.staples { columns: 2 300px; column-gap: 20px; }
.staples .panel { break-inside: avoid; margin: 0 0 20px; }
.staples .panel + .panel { margin-top: 0; }

/* ---------- Data view ---------- */
.data-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 820px) { .data-grid { grid-template-columns: 1fr; } }
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px 16px; text-align: center; color: var(--muted);
  transition: border-color .15s, background .15s; cursor: pointer; margin: 12px 0;
}
.dropzone.over { border-color: var(--brand); background: var(--brand-soft); color: var(--text); }
.dropzone strong { color: var(--text); }
.status { padding: 10px 12px; border-radius: var(--radius-sm); font-size: .9rem; margin-top: 12px; }
.status.ok { background: var(--brand-soft); }
.status.err { background: var(--danger-soft); }
.status ul { margin: 6px 0 0; padding-left: 20px; }
.schema-table { width: 100%; border-collapse: collapse; font-size: .88rem; margin: 10px 0 4px; }
.schema-table th, .schema-table td { text-align: left; padding: 7px 8px; border-top: 1px solid var(--line); vertical-align: top; }
.schema-table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-top: 0; }
.schema-table td:first-child { white-space: nowrap; }
.req { color: var(--accent); font-weight: 600; font-size: .78rem; }
.prose h3 { margin: 22px 0 6px; }
.prose p, .prose ul { margin: 6px 0; }
.prose ul { padding-left: 20px; }
.stat-row { display: flex; gap: 18px; flex-wrap: wrap; margin: 6px 0 14px; }
.stat strong { display: block; font-size: 1.4rem; font-family: var(--serif); }
.stat span { font-size: .8rem; color: var(--muted); }

/* ---------- Dialog ---------- */
.dialog { border: 0; border-radius: 18px; padding: 0; background: var(--surface); color: var(--text); width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.dialog::backdrop { background: rgba(20, 20, 18, .5); }
.dialog-inner { padding: 18px 20px 20px; display: grid; gap: 14px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog .muted { font-size: .9rem; }
.qr-wrap { display: grid; place-items: center; background: #fff; border-radius: 12px; padding: 14px; min-height: 120px; }
.qr-wrap img { width: 100%; max-width: 280px; height: auto; image-rendering: pixelated; }
.qr-wrap p { color: #555; font-size: .9rem; text-align: center; }
.link-row { display: flex; gap: 8px; }
.link-row input { flex: 1; min-width: 0; font: inherit; font-size: .85rem; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); }
.dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: .9rem; z-index: 50;
  transition: opacity .2s, transform .2s; pointer-events: none; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Print (menu / list) ---------- */
.print-root { display: none; }
@media print {
  @page { margin: 18mm; }
  body { background: #fff; color: #000; padding: 0; }
  body > *:not(.print-root) { display: none !important; }
  .print-root { display: block; font-family: var(--serif); }
  .print-root h1 { font-size: 28pt; margin-bottom: 4pt; }
  .print-root .print-sub { font-family: var(--sans); color: #555; font-size: 10pt; margin-bottom: 18pt; }
  .print-root .print-day { display: grid; grid-template-columns: 34mm 1fr; padding: 9pt 0; border-top: .5pt solid #bbb; break-inside: avoid; }
  .print-root .print-day:first-of-type { border-top: 0; }
  .print-root .print-day-label { font-family: var(--sans); font-size: 9pt; text-transform: uppercase; letter-spacing: .08em; color: #666; padding-top: 4pt; }
  .print-root .print-dish { font-size: 16pt; }
  .print-root .print-sides { font-size: 11pt; color: #444; font-style: italic; }
  .print-root h2 { font-size: 14pt; margin: 16pt 0 6pt; }
  .print-root ul { font-family: var(--sans); font-size: 10.5pt; columns: 2; padding-left: 14pt; }
  .print-root li { break-inside: avoid; margin-bottom: 2pt; }
}

@media (max-width: 560px) {
  .topbar-inner { padding: 8px 12px; }
  .tabs { width: 100%; justify-content: space-between; }
  .tabs a { flex: 1; justify-content: center; padding: 6px 8px; }
  main { padding-top: 18px; }
  .menu-list li { grid-template-columns: 112px 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- v2 additions ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.hint { font-size: .82rem; color: var(--muted); }
.text-input {
  width: 100%; font: inherit; font-size: .92rem; padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
textarea.text-input { resize: vertical; min-height: 44px; line-height: 1.4; }
.pill.soft { background: var(--surface-2); color: var(--muted); font-weight: 600; }
.icon-btn.small { width: 28px; height: 28px; font-size: .85rem; flex: none; }

/* Random picker */
.random-box {
  display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 5px 5px 16px; box-shadow: var(--shadow); flex-wrap: wrap;
}
.random-label { font-size: .9rem; color: var(--muted); }
.num-input {
  width: 58px; font: inherit; font-weight: 600; text-align: center; padding: 4px 6px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
}

/* Toast with action */
.toast { display: flex; align-items: center; gap: 12px; }
.toast.has-action { pointer-events: auto; padding-right: 8px; }
.toast-action { appearance: none; border: 0; background: rgba(255,255,255,.16); color: inherit; font: inherit; font-weight: 600; padding: 4px 12px; border-radius: 999px; cursor: pointer; }
@media (prefers-color-scheme: dark) { .toast-action { background: rgba(0,0,0,.12); } }

/* Checklist rows with an extra button */
.check-li { display: flex; align-items: center; gap: 8px; }
.check-li .check-row { flex: 1; min-width: 0; }
.check-li.note .item-name { font-style: italic; }
.check-li.moved .item-name { color: var(--muted); }
.move-btn { flex: none; font-size: .8rem; padding: 4px 10px; }
.move-btn.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.note-form { display: flex; gap: 8px; margin-top: 10px; padding-top: 12px; border-top: 1px dashed var(--line); }
.note-form .text-input { border-radius: 999px; }

/* Menu */
.assign-box { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 8px; }
.assign-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .88rem; font-weight: 550; }
.assign-row .date-input { width: auto; background: var(--surface); }
.assign-box .hint { margin-top: 6px; }
.menu-night { font-size: .85rem; padding-top: 2px; }

/* Customise: builder */
.seg { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 999px; margin: 14px 0 12px; }
.seg-btn { flex: 1; appearance: none; border: 0; background: transparent; font: inherit; font-size: .88rem; font-weight: 550; color: var(--muted); padding: 6px 10px; border-radius: 999px; cursor: pointer; }
.seg-btn[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.builder-form { display: grid; gap: 12px; }
.builder-form > .btn { justify-self: start; }
.field { display: grid; gap: 5px; }
.field > label { font-size: .82rem; font-weight: 600; }
.inline-check { display: flex; align-items: center; gap: 8px; font-size: .9rem; cursor: pointer; }
.inline-check input { width: 18px; height: 18px; accent-color: var(--brand); }
.tags.preview:empty { display: none; }
.tag.clash { background: var(--accent-soft); color: var(--accent); }
.status.warn { background: var(--accent-soft); }
.additions { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.additions h3 { margin-bottom: 8px; }
.add-list { list-style: none; margin: 0; padding: 0; }
.add-list li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.add-list li:first-child { border-top: 0; }
.add-text { flex: 1; min-width: 0; display: grid; }
.add-text .item-for { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Customise: docs */
.docs { margin-top: 20px; }
.docs > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
.docs > summary::-webkit-details-marker { display: none; }
.docs > summary::after { content: "Show"; font-family: var(--sans); font-size: .85rem; color: var(--brand); font-weight: 600; margin-left: auto; }
.docs[open] > summary::after { content: "Hide"; }
.docs-body { margin-top: 8px; }
.table-wrap { overflow-x: auto; }
@media (max-width: 560px) {
  .random-box { width: 100%; justify-content: space-between; }
  .check-li { flex-wrap: wrap; gap: 0 8px; }
  .move-btn { margin-left: 34px; margin-bottom: 8px; }
}
