:root {
  --green: #2f7d4f;
  --green-dark: #246340;
  --bg: #f6f7f5;
  --card: #ffffff;
  --line: #e2e5e0;
  --text: #1f2421;
  --muted: #6b726c;
  --danger: #b3261e;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--green); color: #fff;
  padding: max(env(safe-area-inset-top), 12px) 16px 0;
}
.topbar h1 { margin: 0 0 8px; font-size: 1.25rem; }
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; color: #dfeede; border: 0;
  padding: 10px 14px; font-size: .95rem; cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tab.is-active { color: #fff; border-bottom-color: #fff; font-weight: 600; }

main { padding: 16px; max-width: 1000px; margin: 0 auto; }
.view { display: none; }
.view.is-active { display: block; }

.toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type="search"] { flex: 1 1 180px; }

/* Multi-select filter dropdowns (Tags / Status) */
.tag-filter { position: relative; }
.tag-filter > button { white-space: nowrap; }
.tag-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 15;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 10px 12px;
  max-height: 320px; overflow-y: auto; min-width: 200px; display: grid; gap: 12px;
}
.tag-group-head { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 4px; }
.tag-opt { display: flex; align-items: center; gap: 6px; font-size: .85rem; padding: 2px 0; cursor: pointer; }
.tag-opt input { width: auto; margin: 0; }
input, select, textarea, button { font: inherit; }
input, select, textarea {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; width: 100%;
}
button {
  padding: 9px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; cursor: pointer;
}
button.primary { background: var(--green); color: #fff; border-color: var(--green); font-weight: 600; }
button.primary:hover { background: var(--green-dark); }
button.danger { color: var(--danger); border-color: #e7c3c0; }
button.icon { border: 0; background: transparent; font-size: 1.1rem; }

.recipe-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; cursor: pointer; transition: box-shadow .15s, transform .15s;
}
.card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.08); transform: translateY(-1px); }
.card h3 { margin: 0 0 6px; font-size: 1.02rem; }
.card .macros { color: var(--muted); font-size: .82rem; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  font-size: .72rem; padding: 2px 8px; border-radius: 999px;
  background: #eef3ee; color: var(--green-dark); border: 1px solid #dbe7db;
}
.chip.diet { background: #fdf3e7; color: #8a5a1a; border-color: #f0ddc2; }
.chip.version { background: #eef0fb; color: #3b3f8f; border-color: #dcdff2; }
.chip.untried { background: #fff3e0; color: #b25e00; border-color: #f3d3a3; font-weight: 600; }
.chip.tried { background: #edf5ee; color: var(--green-dark); border-color: #cfe6d5; }
.chip.rating-favorite { background: #fff6da; color: #8a6d1a; border-color: #f0e0a8; font-weight: 600; }
.chip.rating-ok { background: #eef0f2; color: #55606a; border-color: #d9dde1; }
.chip.rating-avoid { background: #fdeceb; color: var(--danger); border-color: #f3c9c6; font-weight: 600; }
.card.is-variant { border-left: 3px solid #c7cdf0; }

/* Print-only binder copy */
#print-area { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area {
    display: block; position: absolute; inset: 0 auto auto 0; width: 100%;
    padding: 0 6px; color: #000; font-size: 12pt;
  }
  .topbar, .backdrop, main { display: none !important; }
  #print-area h1 { font-size: 20pt; margin: 0 0 2px; }
  #print-area h2 { font-size: 13pt; margin: 14px 0 4px; border-bottom: 1px solid #999; }
  #print-area h3 { font-size: 12pt; margin: 10px 0 2px; }
  #print-area .print-version { font-style: italic; margin-bottom: 6px; }
  #print-area .print-meta { color: #333; margin: 2px 0; }
  #print-area .print-source { margin-top: 12px; font-size: 10pt; color: #333; word-break: break-all; }
  #print-area .print-flag { color: #555; font-size: 10pt; font-style: italic; }
  #print-area .print-note { margin: 6px 0; font-size: 10pt; color: #555; font-style: italic; }
  #print-area ul, #print-area ol { margin: 4px 0 4px 18px; padding: 0; }
  #print-area li, #print-area p { margin: 2px 0; }
}

.empty, .placeholder { color: var(--muted); }
.placeholder { background: var(--card); border: 1px dashed var(--line); border-radius: 12px; padding: 28px; text-align: center; }
.hidden { display: none !important; }

/* Editor modal */
.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 12px; overflow-y: auto; z-index: 20;
}
.editor {
  background: #fff; border-radius: 14px; width: min(680px, 100%);
  display: flex; flex-direction: column; max-height: calc(100vh - 48px);
}
.editor-head, .editor-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
/* Wrap the footer actions on narrow screens so Save (first) and the rest stay on
   screen instead of overflowing the modal on mobile. */
.editor-foot { border-bottom: 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.editor-head h2 { margin: 0; font-size: 1.1rem; flex: 1; }
.editor-body { padding: 16px 18px; overflow-y: auto; display: grid; gap: 14px; }
.editor-body label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.editor-body label input, .editor-body label textarea { color: var(--text); }
.editor-body label.check-row { display: flex; align-items: center; gap: 8px; color: var(--text); }
.editor-body label.check-row input { width: auto; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
legend { font-size: .82rem; color: var(--muted); padding: 0 6px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.row4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 10px; }
.row5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.nutri { display: grid; grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); gap: 8px; }
.netcarbs { font-size: .8rem; color: var(--muted); margin: 6px 2px 0; }
.calc-detail { margin-top: 8px; font-size: .82rem; }
.calc-detail summary { cursor: pointer; color: var(--green-dark); }
.calc-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.calc-table td { padding: 2px 6px; border-bottom: 1px solid var(--line, #eee); vertical-align: top; }
.calc-table td.num { text-align: right; white-space: nowrap; color: var(--muted); }
.calc-detail .approx { color: var(--muted); }
.calc-warn { display: block; color: #b25e00; margin-bottom: 4px; }
.calc-miss { margin: 6px 2px 0; color: var(--muted); }
.calc-weight { margin: 4px 2px 6px; font-weight: 600; }
.g { color: var(--muted); font-weight: 400; font-size: .92em; }
.spacer { flex: 1; }
.ing-preview { font-size: .8rem; color: var(--muted); }
.ing-preview .aisle { margin-top: 6px; }
.ing-preview .aisle b { color: var(--green-dark); }

/* Ingredient transparency flags (nothing silently missed). */
.flag-dot { cursor: help; font-weight: 700; }
.flag-dot.flag-attention, .flag-attention { color: #b25e00; }
.flag-dot.flag-estimate, .flag-estimate { color: var(--muted); }
.flag-dot.flag-optional, .flag-optional { color: #3b3f8f; }
.ing-flags { font-size: .8rem; margin-top: 8px; }
.ing-flags .flags-summary { display: flex; flex-wrap: wrap; gap: 10px; font-weight: 600; margin-bottom: 4px; }
.ing-flags .flags-group { margin-top: 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfbfa; }
.ing-flags .flags-attention { border-color: #f0d6b3; background: #fdf6ec; }
.ing-flags .flags-optional { border-color: #dcdff2; background: #f2f3fb; }
.ing-flags .flags-group b { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-bottom: 4px; }
.ing-flags ul { margin: 0; padding-left: 18px; }
.ing-flags li { margin: 2px 0; color: var(--text); }
.ing-flags .flag-why { color: var(--muted); }
.ing-flags label { display: inline; color: var(--text); cursor: pointer; }
.ing-flags .opt-include { margin-right: 4px; vertical-align: middle; }
.chip.flag-attention { background: #fdf6ec; color: #b25e00; border-color: #f0d6b3; font-weight: 600; }

/* Ingredient provenance chip + change-match picker (M2 — ingredient-matching
   correction UI; docs/ingredient-matching-and-consolidation.md §3-4). */
.match-chip {
  display: inline-block; margin-left: 4px; padding: 1px 8px; border-radius: 999px;
  font-size: .72rem; font-weight: 600; line-height: 1.5;
  background: #eef3ee; color: var(--green-dark); border: 1px solid #dbe7db; cursor: pointer;
}
.match-chip:hover { background: #e0efe4; }
.match-chip.match-chip-none {
  background: #f3f3f1; color: var(--muted); border-color: var(--line); font-weight: 400;
}
.match-chip.match-chip-none:hover { background: #ececeb; }

.match-dialog { width: min(480px, 100%); }
.match-item { font-weight: 600; color: var(--text); margin: 0; }
.match-current { font-size: .88rem; color: var(--text); }
.match-current b { color: var(--green-dark); }
.match-badge {
  display: inline-block; margin-left: 2px; padding: 1px 7px; border-radius: 999px;
  font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .02em;
  background: #eef0fb; color: #3b3f8f; border: 1px solid #dcdff2;
}
.match-badge.match-via-user-override { background: #edf5ee; color: var(--green-dark); border-color: #cfe6d5; }
.match-badge.match-via-table { background: #eef0fb; color: #3b3f8f; border-color: #dcdff2; }
.match-badge.match-via-llm { background: #fdf3e7; color: #8a5a1a; border-color: #f0ddc2; }
.match-dialog label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.match-candidates { display: grid; gap: 6px; max-height: 220px; overflow-y: auto; }
.match-candidate {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; text-align: left; padding: 8px 10px; font-size: .88rem;
}
.match-candidate:hover { background: #f4f7f4; border-color: var(--green); }
.match-candidate-aisle { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.match-empty { color: var(--muted); font-size: .85rem; margin: 4px 2px; }
.match-status { font-size: .82rem; color: var(--muted); min-height: 1.2em; margin: 0; }

/* Editor: import bar, verify, images */
.import-bar { display: flex; gap: 8px; }
.import-bar input { flex: 1; }
.ocr-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.model-pick { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.model-pick select { width: auto; padding: 6px 8px; }
.ai-fill { display: flex; flex-direction: column; gap: 8px; }
.ai-fill-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ai-fill-line button { min-width: 172px; }
.ai-fill button { border-color: var(--green); color: var(--green); background: #fff; font-weight: 600; }
.ai-fill button:hover:not(:disabled) { background: #f4f7f4; }
.ai-fill button:disabled { opacity: .5; cursor: not-allowed; border-color: var(--line); color: var(--muted); }
#f-suggest-tags-ai { min-width: 0; font-weight: 500; font-size: .82rem; color: var(--muted); border-color: var(--line); }
.linkbtn { border: 0; background: transparent; color: var(--green-dark); text-decoration: underline; cursor: pointer; padding: 0 2px; font: inherit; }
.fill-status { font-size: .85rem; color: var(--muted); background: #f4f7f4; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0 0 12px; }
.shop-add-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.shop-add-bar input { flex: 1; }
#add-meal-recipe { flex: 1; min-width: 140px; }
#add-meal-date { flex: 0 0 auto; }
.file-btn.ghost { background: #fff; color: var(--green); }
.file-btn.ghost:hover { background: #f4f7f4; }
.ocr-status { font-size: .82rem; color: var(--muted); flex: 1; min-width: 160px; }
.verify-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #f4f7f4; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.verify-row span { flex: 1; font-size: .82rem; color: var(--muted); min-width: 180px; }
.img-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.thumb { position: relative; width: 84px; height: 84px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #f0f0f0; cursor: zoom-in; }
.thumb-rm {
  position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; padding: 0;
  border-radius: 999px; background: #fff; color: var(--danger); border: 1px solid var(--line);
  font-size: .8rem; line-height: 1; cursor: pointer;
}
.img-add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.img-add input[type="url"] { flex: 1; min-width: 160px; }
.file-btn {
  display: inline-block; padding: 9px 12px; border: 1px solid var(--green); color: #fff;
  background: var(--green); border-radius: 8px; cursor: pointer; font-size: .9rem; white-space: nowrap;
}
.file-btn:hover { background: var(--green-dark); }
.hint { font-size: .78rem; color: var(--muted); margin: 8px 0 0; }
.card-thumb { width: 100%; height: 130px; object-fit: cover; border-radius: 8px; margin-bottom: 8px; background: #f0f0f0; cursor: zoom-in; }

/* Full-size image viewer (lightbox) */
.lightbox {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center; padding: 24px; cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: 0 6px 30px rgba(0,0,0,.5); }

/* Weekly plan */
.week-pick { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); white-space: nowrap; }
.week-pick input { width: auto; }
.plan-summary {
  background: #eef3ee; border: 1px solid #dbe7db; color: var(--green-dark);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: .85rem;
}
.plan-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.plan-card { cursor: default; display: flex; flex-direction: column; gap: 8px; }
.plan-card:hover { box-shadow: none; transform: none; }
.plan-day { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--green-dark); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.plan-day .muted { color: var(--muted); font-weight: 400; }
.plan-remove { margin-left: auto; color: var(--danger); font-size: .9rem; line-height: 1; }
.plan-recipe { margin: 0; font-size: 1.02rem; cursor: pointer; }
.plan-recipe:hover { color: var(--green-dark); text-decoration: underline; }
.plan-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.plan-actions label.pa { display: flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--muted); }
.plan-actions .move-date, .plan-actions .ready-time { padding: 5px 6px; font-size: .8rem; }
.plan-actions .reroll, .plan-actions .insert-day { padding: 6px 10px; font-size: .82rem; }
.plan-reminder { font-size: .76rem; color: var(--muted); line-height: 1.4; }
/* Quick "Made it" tap + its "last made" context. */
.plan-made-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.plan-made {
  padding: 6px 12px; font-size: .82rem; font-weight: 600;
  color: var(--green-dark); background: #edf5ee; border-color: #cfe6d5;
}
.plan-made:hover { background: #e0efe4; }
.plan-made-info { font-size: .76rem; color: var(--muted); }
/* Placeholder nights (eating out, leftovers, …) read as a lighter, dashed card. */
.plan-ph-card { background: #fbfcfb; border-style: dashed; }
.plan-ph { margin: 0; font-size: 1.02rem; color: var(--green-dark); }
.ph-note { padding: 6px 8px; font-size: .82rem; border: 1px solid var(--line); border-radius: 8px; width: 100%; }
.ph-note::placeholder { color: var(--muted); }
.reminders-status {
  background: #fff; border: 1px dashed var(--line); border-radius: 10px;
  padding: 8px 12px; margin-bottom: 14px; font-size: .82rem; color: var(--muted);
}
.reminders-status a { color: var(--green-dark); }

/* Shopping list */
.aisle-head {
  margin: 16px 0 6px; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .04em; color: var(--green-dark); font-weight: 600;
}
.aisle-head:first-child { margin-top: 0; }
.shop-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; margin-bottom: 6px;
}
.shop-main { display: flex; align-items: center; gap: 10px; flex: 1; margin: 0; cursor: pointer; }
.shop-row input[type="checkbox"] { width: 18px; height: 18px; flex: 0 0 auto; }
.shop-qty { color: var(--muted); font-size: .85rem; min-width: 62px; }
.shop-name { flex: 1; }
.shop-row.is-checked .shop-name, .shop-row.is-checked .shop-qty { text-decoration: line-through; color: var(--muted); }
.shop-remove { color: var(--danger); flex: 0 0 auto; }

/* Store split: group headers + per-item controls */
.store-head {
  margin: 22px 0 4px; font-size: .95rem; font-weight: 700; color: var(--text);
  border-bottom: 2px solid var(--green); padding-bottom: 4px;
}
.store-head:first-child { margin-top: 0; }
.store-head.store-unassigned { border-color: var(--danger); }
.store-head.store-staples { border-color: #b8860b; }
.store-hint { font-weight: 400; font-size: .78rem; color: var(--muted); }
.shop-controls { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.shop-note { width: 68px; font-size: .8rem; padding: 4px 6px; }
.shop-store { font-size: .8rem; padding: 4px 6px; max-width: 130px; }
.shop-staple { color: var(--muted); }
.shop-staple.on { color: #d4a017; }
.shop-bump { color: var(--green-dark); }

/* Mini choice dialog (combine/replace) */
.mini-dialog {
  background: #fff; border-radius: 14px; width: min(420px, 100%);
  padding: 18px 20px; display: grid; gap: 12px; align-self: center;
}
.mini-dialog h2 { margin: 0; font-size: 1.05rem; }
.mini-dialog p { margin: 0; color: var(--muted); font-size: .9rem; }
.mini-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.made-date-row label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }

/* Store aisle-order list */
.order-list { list-style: decimal; padding-left: 26px; margin: 0; display: grid; gap: 4px; }
.order-item { display: flex; align-items: center; gap: 8px; }
.order-item span:first-child { flex: 1; }
.order-btns { display: flex; gap: 2px; flex: 0 0 auto; }
.order-btns .icon:disabled { opacity: .3; cursor: default; }

@media (max-width: 560px) {
  .row3, .row4, .row5 { grid-template-columns: 1fr 1fr; }
  .shop-row { flex-wrap: wrap; }
  .shop-controls { width: 100%; justify-content: flex-end; }
  .shop-store { max-width: none; flex: 1; }
}
