:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1f2a24;
  --muted: #6b746f;
  --line: #e4e0d6;
  --primary: #2f6b4f;
  --primary-ink: #ffffff;
  --primary-soft: #e3efe8;
  --danger: #b4432f;
  --warn-bg: #fdf0e6;
  --warn-line: #e8b58f;
  --radius: 14px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131815;
    --surface: #1c231f;
    --text: #e8ece9;
    --muted: #9aa59f;
    --line: #2c3530;
    --primary: #5fb388;
    --primary-ink: #0d1a13;
    --primary-soft: #1f3329;
    --danger: #e0806c;
    --warn-bg: #2e231b;
    --warn-line: #6b4a33;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
}
body.login { padding-bottom: 24px; }
a { color: var(--primary); }
code { font-size: .9em; background: var(--primary-soft); padding: 1px 5px; border-radius: 6px; }

/* ---------- barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 1.25rem; display: flex; align-items: center; gap: 6px; }
.back { text-decoration: none; font-size: 1.8rem; line-height: 1; padding: 0 8px 0 0; color: var(--text); }
.top-link { font-weight: 600; text-decoration: none; padding: 8px 4px; }
.counter {
  min-width: 32px; height: 32px; padding: 0 10px; border-radius: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: var(--primary-ink); font-weight: 700;
}

.page { max-width: 720px; margin: 0 auto; padding: 16px; }

/* ---------- barra de pestañas inferior ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: .75rem; font-weight: 600;
}
.tabbar a.on { color: var(--primary); }
.tabbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- elementos básicos ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 0 0 14px;
}
.card h3 { margin: 0 0 10px; font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; display: block; }
.prewrap { white-space: pre-wrap; margin: 0; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }

label { display: block; font-weight: 600; margin: 0 0 14px; }
input, select, textarea {
  width: 100%; font: inherit; color: inherit;
  min-height: 48px; padding: 10px 14px; margin-top: 6px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 18px; font: inherit; font-weight: 600;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .85rem; }
.btn.round { width: 48px; padding: 0; font-size: 1.5rem; border-radius: 50%; }
.btn:active { transform: scale(.98); }
.danger-text { color: var(--danger); }

.alert {
  background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 12px;
  padding: 12px 14px; margin: 0 0 14px;
}
.alert.info { background: var(--primary-soft); border-color: var(--primary); }
.inline { display: inline; margin-left: 6px; }

.empty { text-align: center; padding: 40px 16px; }
.empty-icon { font-size: 3rem; }
.pill { background: var(--primary); color: var(--primary-ink); border-radius: 10px; padding: 1px 8px; font-size: .75rem; }

/* ---------- lista de la compra ---------- */
.addbar { display: flex; gap: 8px; margin: 0 0 18px; position: sticky; top: 62px; z-index: 5; }
.addbar input { margin: 0; min-height: 52px; background: var(--surface); font-size: 1.05rem; }
.addbar .btn { width: 52px; min-height: 52px; flex: none; }

.group h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 8px; }
.items { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.item { display: flex; align-items: center; gap: 4px; min-height: 58px; padding: 0 4px 0 6px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.check {
  flex: none; width: 48px; height: 48px; border: 0; background: none; cursor: pointer; position: relative;
}
.check::before {
  content: ""; position: absolute; inset: 12px; border: 2px solid var(--muted); border-radius: 8px;
}
.item.done .check::before { background: var(--primary); border-color: var(--primary); }
.item.done .check::after {
  content: ""; position: absolute; left: 20px; top: 15px; width: 8px; height: 14px;
  border: solid var(--primary-ink); border-width: 0 3px 3px 0; transform: rotate(45deg);
}
.item-text { flex: 1; padding: 10px 0; cursor: pointer; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.item .name { font-size: 1.05rem; }
.qty { color: var(--muted); font-size: .9rem; }
.item.done .name { text-decoration: line-through; color: var(--muted); }

.item-menu { position: relative; }
.item-menu > summary {
  list-style: none; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; color: var(--muted); cursor: pointer; border-radius: 50%;
}
.item-menu > summary::-webkit-details-marker { display: none; }
.item-menu[open] > summary { background: var(--primary-soft); }
.sheet { display: grid; gap: 10px; }
.item-menu .sheet {
  position: absolute; right: 0; top: 46px; z-index: 30; width: min(280px, 80vw);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
}
.item-menu .sheet label { margin: 0; }
.list-actions { margin-top: 18px; }

/* ---------- recetas ---------- */
.import-card label { font-size: 1.05rem; margin-bottom: 2px; }
.import-card p { margin: 0 0 10px; }
.import-card .row input { margin: 0; }
.import-card .btn.primary { margin-top: 10px; }
.search input { margin: 0 0 14px; background: var(--surface); }

.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 600px) { .cards { grid-template-columns: repeat(3, 1fr); } }
.recipe-card {
  display: flex; flex-direction: column; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.thumb { position: relative; aspect-ratio: 3 / 4; background: var(--primary-soft); display: flex; align-items: center; justify-content: center; font-size: 2.4rem; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.badge { position: absolute; left: 8px; bottom: 8px; font-size: .75rem; font-weight: 700; padding: 3px 8px; border-radius: 8px; color: #fff; }
.badge.working { background: var(--primary); }
.badge.err { background: var(--danger); }
.recipe-card-body { padding: 10px 12px 12px; display: grid; gap: 2px; }
.recipe-card-body strong { font-size: .95rem; line-height: 1.25; }

.hero { margin: -16px -16px 14px; max-height: 46vh; overflow: hidden; }
.hero img { width: 100%; height: 100%; max-height: 46vh; object-fit: cover; display: block; }
.recipe-title { margin: 0 0 4px; font-size: 1.5rem; line-height: 1.2; }
.recipe-title + p { margin: 0 0 16px; }

.working-card { display: flex; gap: 14px; align-items: center; }
.working-card p { margin: 2px 0 0; }
.spinner { flex: none; width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--primary-soft); border-top-color: var(--primary); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.ing-list { list-style: none; padding: 0; margin: 0 0 12px; }
.ing-list li { border-bottom: 1px solid var(--line); }
.ing-list li:last-child { border-bottom: 0; }
.ing-list label { display: flex; align-items: center; gap: 12px; min-height: 52px; margin: 0; font-weight: 400; cursor: pointer; }
.ing-list input { width: 24px; height: 24px; min-height: 0; margin: 0; flex: none; accent-color: var(--primary); }

.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; }
.steps li { counter-increment: step; position: relative; padding: 0 0 16px 46px; min-height: 34px; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: -2px;
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  font-weight: 700; display: flex; align-items: center; justify-content: center;
}

.menu-pick { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.menu-pick select { margin: 0; }
.raw summary { font-weight: 600; cursor: pointer; }
.raw h4 { margin: 14px 0 4px; }
.danger-zone { display: grid; gap: 8px; margin-top: 8px; }
.logout { margin-top: 24px; text-align: center; }

/* ---------- menú semanal ---------- */
.weeknav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.weeknav .center { display: grid; }
.day.today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.meal { display: grid; grid-template-columns: 92px 1fr; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.meal-name { font-weight: 600; font-size: .9rem; padding-top: 10px; }
.meal-items { display: grid; gap: 6px; }
.meal-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--primary-soft); border-radius: 10px; padding: 4px 4px 4px 12px; min-height: 44px; }
.meal-item a { text-decoration: none; font-weight: 600; }
.x { width: 36px; height: 36px; border: 0; background: none; font-size: 1.3rem; color: var(--muted); cursor: pointer; }
.meal-add > summary { list-style: none; color: var(--primary); font-weight: 600; padding: 10px 0; cursor: pointer; }
.meal-add > summary::-webkit-details-marker { display: none; }
.meal-add .sheet input, .meal-add .sheet select { margin: 0; }

/* ---------- Mercadona en la lista ---------- */
.addbar { flex-wrap: wrap; }
.addbar input#add-input { flex: 1; }
.suggest {
  position: absolute; top: 58px; left: 0; right: 0; z-index: 40; list-style: none; margin: 0; padding: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .2); max-height: 60vh; overflow-y: auto;
}
.suggest li { display: flex; align-items: center; gap: 10px; padding: 8px; min-height: 56px; border-radius: 10px; cursor: pointer; }
.suggest li:active, .suggest li:hover { background: var(--primary-soft); }
.suggest img { width: 44px; height: 44px; object-fit: contain; border-radius: 8px; background: #fff; flex: none; }
.suggest li div { display: grid; }
.suggest strong { font-weight: 600; font-size: .95rem; }
.suggest-plain { color: var(--primary); font-weight: 600; }
.total { margin: -6px 4px 6px; }
.price { color: var(--primary); font-weight: 600; font-size: .85rem; }
.pthumb { flex: none; width: 44px; height: 44px; border-radius: 8px; overflow: hidden; background: #fff; display: flex; align-items: center; justify-content: center; text-decoration: none; }
.pthumb img { width: 100%; height: 100%; object-fit: contain; }
.item-menu .sheet .btn { text-decoration: none; }
.item-menu .sheet .row input { margin: 0; }

.plist { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.plist li { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.plist-img { flex: none; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; background: #fff; }
.plist-img img { width: 100%; height: 100%; object-fit: contain; }
.plist-text { flex: 1; display: grid; gap: 1px; }
.plist-text strong { font-size: .95rem; font-weight: 600; }

.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; margin: -16px -16px 8px; padding: 16px; background: #fff; }
.gallery img { flex: none; width: 82%; max-width: 420px; aspect-ratio: 1; object-fit: contain; scroll-snap-align: center; border-radius: 12px; }
.price-card { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.big-price { font-size: 2rem; font-weight: 800; color: var(--primary); }
.facts p { margin: 0 0 6px; }

/* ---------- recetas: extras ---------- */
.title-row { display: flex; align-items: flex-start; gap: 8px; }
.title-row .recipe-title { flex: 1; }
.fav { flex: none; width: 48px; height: 48px; border: 0; background: none; font-size: 1.8rem; color: var(--line); cursor: pointer; line-height: 1; }
.fav.on { color: #e3a008; }
.fav-badge { left: auto; right: 8px; top: 8px; bottom: auto; background: #e3a008; }
.chips { display: flex; gap: 8px; margin: 0 0 14px; }
.chip { padding: 8px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: var(--text); font-weight: 600; font-size: .9rem; }
.chip.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.cook-btn { margin: 0 0 14px; min-height: 56px; font-size: 1.05rem; }
.ing-list.plain li { padding: 12px 0; }
#compartir .row input { margin: 0; font-size: .85rem; }

/* ---------- modo cocina ---------- */
body.cook { padding-bottom: 24px; }
body.cook .tabbar { display: none; }
.cook-step { min-height: 52vh; }
.cook-count { color: var(--primary); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; font-size: .85rem; }
.cook-text { font-size: 1.5rem; line-height: 1.45; }
.cook-ings { list-style: none; padding: 0; margin: 0; font-size: 1.2rem; }
.cook-ings li { border-bottom: 1px solid var(--line); }
.cook-ings label { display: flex; align-items: center; gap: 14px; min-height: 58px; margin: 0; font-weight: 400; }
.cook-ings input { width: 26px; height: 26px; min-height: 0; margin: 0; accent-color: var(--primary); flex: none; }
.cook-ings input:checked + span { text-decoration: line-through; color: var(--muted); }
.cook-nav { position: sticky; bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--bg); padding: 8px 0; }
.cook-nav .btn { min-width: 120px; min-height: 56px; }
.cook-nav .btn:disabled { opacity: .4; }
.cook-dots { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; }
.cook-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.cook-dots span.on { background: var(--primary); }

/* ---------- dieta ---------- */
.pill.goal { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.diet-card h3 { margin: 8px 0 4px; }
.diet-card form { margin-top: 10px; }
.diet-head label { margin-bottom: 8px; }
.diet-head p { margin: 6px 0; }
.diet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 4px; }
.diet-actions form { margin: 0; }
.diet-actions .btn:disabled { opacity: .45; }
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.day-head h3 { margin: 0; }
.gym { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 20px; padding: 6px 12px; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; min-height: 36px; }
.gym.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.dslot { border-top: 1px solid var(--line); padding: 10px 0; }
.dslot-name { font-weight: 700; font-size: .9rem; margin-bottom: 4px; }
.dslot select { margin: 0; font-size: .95rem; }
.dslot select.empty { color: var(--muted); }
.dslot-items { margin: 6px 2px 0; font-size: .85rem; color: var(--muted); }
.choice label { display: flex; align-items: center; gap: 8px; margin: 6px 0 0; font-size: .85rem; font-weight: 600; }
.choice select { min-height: 40px; padding: 6px 10px; }
.day-list { margin-top: 6px; }
.diet-option { border-top: 1px solid var(--line); padding: 10px 0; }
.diet-option:first-of-type { border-top: 0; }
.diet-option p { margin: 4px 0 0; }

/* ---------- usuarios ---------- */
.users { list-style: none; padding: 0; margin: 0 0 14px; }
.users > li { border-bottom: 1px solid var(--line); padding: 10px 0; }
.users > li:last-child { border-bottom: 0; }
.user-row { display: flex; align-items: center; gap: 12px; }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 800; display: flex; align-items: center; justify-content: center; }
.user-name { display: grid; }
.user-actions > summary { list-style: none; color: var(--primary); font-weight: 600; padding: 8px 0 0 52px; cursor: pointer; }
.user-actions > summary::-webkit-details-marker { display: none; }
.user-actions[open] { display: grid; gap: 8px; }
.user-actions .sheet { margin-top: 6px; }
.user-actions .sheet input { margin: 0; }
.new-user > summary, details > summary.btn { list-style: none; }
.new-user > summary::-webkit-details-marker, details > summary.btn::-webkit-details-marker { display: none; }
.new-user[open] > summary { display: none; }
.check-label { display: flex; align-items: center; gap: 10px; font-weight: 400; }
.check-label input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--primary); }

/* ---------- login ---------- */
.login-card { max-width: 420px; margin: 8vh auto 0; }
.login .topbar { justify-content: center; border: 0; background: none; }
