/* MealSolo styles — mobile-first, light/dark via prefers-color-scheme */
:root {
  --bg: #f7f8f5; --surface: #ffffff; --surface-2: #eef2ec; --text: #1b1f1a; --muted: #4f5a4d;
  --primary: #2e7d32; --primary-text: #ffffff; --accent: #b45309; --border: #d5dbd2;
  --danger: #b3261e; --focus: #1565c0; --radius: 14px; --shadow: 0 1px 3px rgb(0 0 0 / .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121512; --surface: #1b1f1b; --surface-2: #252b25; --text: #e8ece6; --muted: #a9b4a6;
    --primary: #81c784; --primary-text: #0d1f0e; --accent: #fbbf24; --border: #343c33; --danger: #ffb4ab; --focus: #90caf9;
    --shadow: none; }
}
* { box-sizing: border-box; }
/* Ensure the hidden attribute always wins over component display rules. */
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; padding-bottom: env(safe-area-inset-bottom); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.25rem; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.skip-link:focus { left: .5rem; }

.app-header { padding: 1rem 1rem .5rem; max-width: 760px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: .5rem; font-size: 1.5rem; }
.brand img { border-radius: 8px; }
.tagline { margin: .15rem 0 0; color: var(--muted); font-size: .95rem; }

.tabs { position: sticky; top: 0; z-index: 5; display: flex; gap: .25rem; padding: .5rem 1rem; background: var(--bg);
  border-bottom: 1px solid var(--border); max-width: 760px; margin: 0 auto; }
.tabs button { flex: 1; padding: .65rem .5rem; border: 0; border-radius: 10px; background: transparent; font-weight: 600; color: var(--muted); cursor: pointer; min-height: 44px; }
.tabs button[aria-selected="true"] { background: var(--primary); color: var(--primary-text); }
.badge { display: inline-block; min-width: 1.4em; padding: 0 .35em; border-radius: 99px; background: var(--surface-2); color: var(--text); font-size: .8rem; }

main { max-width: 760px; margin: 0 auto; padding: 1rem; outline: none; }
section > h2 { margin-bottom: .75rem; }
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .75rem; }

.toolbar { display: grid; gap: .75rem; }
input[type="search"], input[type="text"], select, textarea { width: 100%; padding: .7rem .9rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); min-height: 44px; }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .25rem; }
.chip { flex: none; padding: .4rem .8rem; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: .9rem; min-height: 36px; text-transform: capitalize; }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.fav-toggle { display: inline-flex; align-items: center; gap: .4rem; font-size: .95rem; }
.fav-toggle input { width: 1.1rem; height: 1.1rem; accent-color: var(--primary); }
.result-count { color: var(--muted); font-size: .9rem; margin: .75rem 0 .5rem; }

ul { list-style: none; margin: 0; padding: 0; }
.meal-list, .plan-list { display: grid; gap: .75rem; }
@media (min-width: 640px) { .meal-list { grid-template-columns: 1fr 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card-top { display: flex; justify-content: space-between; gap: .5rem; align-items: start; }
.card h3 { font-size: 1.05rem; }
.meta { color: var(--muted); font-size: .88rem; margin: .25rem 0 .5rem; }
.tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .75rem; }
.tag { font-size: .75rem; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); text-transform: capitalize; }
details summary { cursor: pointer; font-weight: 600; color: var(--primary); padding: .25rem 0; }
details ul, details ol { margin: .4rem 0 .6rem; padding-left: 1.2rem; font-size: .93rem; }
details ul { list-style: disc; }
.card-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .55rem 1rem; min-height: 44px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { min-height: 36px; padding: .35rem .75rem; font-size: .9rem; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 1.35rem; width: 44px; height: 44px; border-radius: 50%; color: var(--accent); flex: none; }
.icon-btn:hover { background: var(--surface-2); }
.link { border: 0; background: none; padding: 0; color: var(--primary); text-decoration: underline; cursor: pointer; }

.plan-item { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }

.add-row { display: flex; gap: .5rem; margin-bottom: 1rem; }
.grocery-list { display: grid; gap: .75rem; }
.grocery-list:empty { display: none; }
.aisle { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.aisle-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; padding: .55rem .75rem; background: var(--surface-2); color: var(--muted); }
.aisle-count { font-weight: 400; letter-spacing: 0; }
.grocery-item { display: flex; align-items: center; gap: .5rem; padding: .35rem .5rem .35rem .75rem; border-bottom: 1px solid var(--border); }
.grocery-item:last-child { border-bottom: 0; }
.grocery-item input[type="checkbox"] { width: 1.3rem; height: 1.3rem; accent-color: var(--primary); flex: none; }
.grocery-item .item-text { flex: 1; border: 1px solid transparent; background: transparent; padding: .45rem .5rem; min-height: 40px; border-radius: 8px; }
.grocery-item .item-text:hover, .grocery-item .item-text:focus { border-color: var(--border); background: var(--bg); }
.grocery-item.checked .item-text { text-decoration: line-through; color: var(--muted); }
.grocery-actions { display: flex; justify-content: flex-end; margin-top: .75rem; }

.empty { text-align: center; padding: 2.5rem 1rem; border: 2px dashed var(--border); border-radius: var(--radius); color: var(--muted); }
.empty-title { font-weight: 700; color: var(--text); font-size: 1.1rem; margin: 0 0 .25rem; }

.toast { position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: .75rem;
  background: var(--text); color: var(--bg); padding: .65rem .9rem; border-radius: 12px; box-shadow: 0 4px 16px rgb(0 0 0 / .25); max-width: calc(100% - 2rem); z-index: 20; }
.toast .btn { background: var(--primary); color: var(--primary-text); border: 0; }
@media (prefers-reduced-motion: no-preference) { .card, .btn { transition: background .15s, filter .15s; } }

/* ---------- Weekly planner ---------- */
.head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: .9rem; margin: 0 0 .75rem; }
.week { display: grid; gap: .75rem; }
@media (min-width: 640px) { .week { grid-template-columns: 1fr 1fr; } }
.day { padding: .75rem; }
.day h3 { font-size: 1rem; display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.day.today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.today-pill { font-size: .7rem; padding: .05rem .5rem; border-radius: 99px; background: var(--primary); color: var(--primary-text); }
.slots { display: grid; gap: .35rem; }
.slot { display: grid; grid-template-columns: 5.5rem 1fr; align-items: center; gap: .5rem; min-height: 44px; }
.slot-label { font-size: .8rem; text-transform: capitalize; color: var(--muted); font-weight: 600; }
.slot-meal { display: flex; align-items: center; gap: .25rem; min-width: 0; }
.slot-btn { flex: 1; min-width: 0; text-align: left; min-height: 40px; padding: .4rem .6rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-btn.empty-slot { background: transparent; border-style: dashed; color: var(--muted); }
.slot-btn:hover { border-color: var(--primary); }
.icon-btn.small { width: 36px; height: 36px; font-size: 1.15rem; color: var(--muted); }
.in-week { align-self: center; color: var(--primary); font-weight: 600; font-size: .9rem; }

/* ---------- Notes ---------- */
.note-label { display: block; font-weight: 600; font-size: .9rem; margin-top: .5rem; }
textarea.note { resize: vertical; min-height: 3.5rem; margin-top: .25rem; }
.note-preview { margin: .25rem 0 .5rem; font-size: .88rem; color: var(--muted); white-space: pre-wrap; border-left: 3px solid var(--accent); padding-left: .5rem; }

/* ---------- Dialogs ---------- */
dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text);
  width: min(92vw, 440px); box-shadow: 0 10px 40px rgb(0 0 0 / .3); }
dialog::backdrop { background: rgb(0 0 0 / .5); }
.dialog-body { padding: 1.25rem; display: grid; gap: .75rem; }
.dialog-body h2 { font-size: 1.15rem; }
.dialog-body p { margin: 0; }
.field { display: grid; gap: .25rem; flex: 1; }
.field label { font-weight: 600; font-size: .9rem; }
.field-row { display: flex; gap: .75rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .25rem; }
.onb-step { color: var(--primary); font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
select { appearance: auto; }

/* ---------- Dark-mode polish ---------- */
@media (prefers-color-scheme: dark) {
  .card, .aisle, dialog { background: var(--surface); }
  .btn:hover { background: #2e352e; }
  .tag, .badge { background: #2c342c; color: var(--text); }
  .tabs button[aria-selected="true"] .badge { background: #0d1f0e; color: #e8ece6; }
  .toast { background: #e8ece6; color: #121512; }
  .toast .btn { background: #2e7d32; color: #fff; }
  ::placeholder { color: #8f9a8c; }
  dialog::backdrop { background: rgb(0 0 0 / .7); }
}

/* ===================== v1.3: signature features ===================== */
:root { --art-bg: #eef4e8; --art-dish: #ffffff; --art-dish-in: #f4f1ea; --good: #2e7d32; --warn: #b3261e; --ease: cubic-bezier(.2, .8, .2, 1); }
@media (prefers-color-scheme: dark) { :root { --art-bg: #243024; --art-dish: #d9ddd6; --art-dish-in: #bfc6bc; --good: #81c784; --warn: #ffb4ab; } }

/* Recipe illustrations (inline SVG from art.js) */
.meal-art { display: block; width: 100%; height: 96px; margin: -.25rem 0 .5rem; }
.meal-art .art-bg { fill: var(--art-bg); }
.meal-art .art-dish { fill: var(--art-dish); }
.meal-art .art-dish-in { fill: var(--art-dish-in); }
.cook-head .meal-art { width: 72px; height: 48px; margin: 0; flex: none; }

/* Cost + batch */
.cost { margin: -.25rem 0 .5rem; font-size: .9rem; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; }
.cost-value { font-weight: 700; color: var(--text); }
.est { font-size: .8rem; }
.batch-pill, .leftover-pill { display: inline-block; font-size: .72rem; font-weight: 700; padding: .05rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--primary); border: 1px solid var(--border); }
.leftover-pill { margin-right: .35rem; }
.slot.leftover .slot-btn { border-style: dashed; }
.ing-cost, .est-note { color: var(--muted); font-size: .8rem; }
.est-note { margin: .25rem 0 .5rem; }
.tip { font-size: .9rem; background: var(--surface-2); border-radius: 10px; padding: .5rem .7rem; margin: .25rem 0 .5rem; }

/* Cook picker */
.sub { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: .75rem 0 .4rem; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0 0 .5rem; padding: 0; list-style: none; }
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.cook-results { display: grid; gap: .75rem; }
@media (min-width: 640px) { .cook-results { grid-template-columns: 1fr 1fr; } }
.cook-head { display: flex; align-items: center; gap: .75rem; }
.cook-head > div { flex: 1; min-width: 0; }
.match { font-weight: 800; font-size: 1.05rem; padding: .25rem .6rem; border-radius: 10px; background: var(--surface-2); color: var(--text); }
.match.full { background: var(--primary); color: var(--primary-text); }
.have, .missing, .have-all { margin: .4rem 0 0; font-size: .92rem; }
.missing strong { color: var(--warn); }
.have-all { color: var(--good); font-weight: 600; }

/* Starter banner + budget */
.banner { border: 1px solid var(--primary); background: var(--surface-2); border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: .75rem; }
.banner p { margin: 0 0 .6rem; }
.banner-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.budget { margin-bottom: .75rem; }
.budget-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.budget-head h3 { font-size: 1rem; }
.budget-input { display: inline-flex; align-items: center; gap: .4rem; font-size: .9rem; font-weight: 600; }
.budget-input input { width: 5.5rem; min-height: 40px; padding: .35rem .5rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.budget-line { margin: .4rem 0 .3rem; color: var(--muted); }
.budget-spend { font-size: 1.6rem; font-weight: 800; color: var(--text); margin-right: .25rem; }
.budget meter { width: 100%; height: 14px; }
.budget-status { margin: .25rem 0 0; font-weight: 700; color: var(--good); }
.budget.over .budget-status { color: var(--warn); }
.grocery-actions { gap: .5rem; flex-wrap: wrap; }

/* ===================== Motion (only when the user hasn't asked for less) ===================== */
@media (prefers-reduced-motion: no-preference) {
  @keyframes sp-fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
  @keyframes sp-pop { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
  [role="tabpanel"]:not([hidden]) { animation: sp-fade-up .28s var(--ease); }
  .meal-list.anim > li, .cook-results.anim > li { animation: sp-fade-up .35s var(--ease) both; }
  .meal-list.anim > li:nth-child(2), .cook-results.anim > li:nth-child(2) { animation-delay: .04s; }
  .meal-list.anim > li:nth-child(3), .cook-results.anim > li:nth-child(3) { animation-delay: .08s; }
  .meal-list.anim > li:nth-child(4), .cook-results.anim > li:nth-child(4) { animation-delay: .12s; }
  dialog[open] { animation: sp-pop .22s var(--ease); }
  dialog[open]::backdrop { animation: sp-fade-up .2s ease-out; }
  .toast:not([hidden]) { animation: sp-pop .25s var(--ease); }
  .card { transition: transform .18s var(--ease), box-shadow .18s var(--ease), background .15s; }
  .meal-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgb(0 0 0 / .1); }
  .btn, .chip, .slot-btn { transition: background .15s, color .15s, transform .12s var(--ease), filter .15s, border-color .15s; }
  .btn:active, .chip:active, .slot-btn:active { transform: scale(.97); }
  .grocery-item { transition: opacity .2s; }
  .grocery-item.checked { opacity: .7; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
/* Four tabs on a 360-390px phone: keep label + badge on one line. */
.tabs { gap: .15rem; padding-left: .5rem; padding-right: .5rem; }
.tabs button { white-space: nowrap; padding: .6rem .3rem; font-size: .92rem; }
.tabs .badge { font-size: .72rem; }

/* ===================== v1.4: footer, settings & data ===================== */
.app-footer { max-width: 760px; margin: 1.5rem auto 0; padding: 1rem; border-top: 1px solid var(--border); text-align: center; font-size: .92rem; }
.app-footer nav { display: flex; justify-content: center; flex-wrap: wrap; gap: .25rem 1.25rem; }
.app-footer a, .app-footer .link, .legal-links a { color: var(--primary); min-height: 44px; display: inline-flex; align-items: center; }
.data-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.file-btn { cursor: pointer; }
#restore-file:focus-visible + .file-btn, .file-btn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.data-status { min-height: 1.5em; font-weight: 600; color: var(--primary); margin: 0; }
.data-status.error { color: var(--danger); }
