:root {
  --bg: #FAF8F3;
  --surface: #FFFFFF;
  --surface-2: #F2EFE7;
  --ink: #1B211E;
  --muted: #6B716D;
  --line: #E7E2D6;
  --accent: #1F6B4A;
  --accent-soft: #E3EFE8;
  --on-accent: #FFFFFF;
  --danger: #B3402F;
  --c-desayuno: #E59A2F;
  --c-almuerzo: #2F8F5B;
  --c-merienda: #D0577F;
  --c-cena: #4C5FC9;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(27, 33, 30, .04), 0 6px 20px rgba(27, 33, 30, .05);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --surface: #1A201D;
    --surface-2: #222925;
    --ink: #EEF1EE;
    --muted: #9BA39E;
    --line: #2C3430;
    --accent: #5FC08F;
    --accent-soft: #1F3329;
    --on-accent: #0D1410;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface);
  padding: 11px 16px; border-radius: 999px; font-weight: 600; font-size: 15px;
  transition: transform .1s ease, background .2s ease;
  text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.whatsapp { background: #25D366; color: #08321B; border-color: transparent; }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px;
  border-radius: 50%; border: 0; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 24px; padding: 32px 24px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-logo { margin: 0 auto 4px; border-radius: 16px; }
.login-card h1 { font-size: 22px; letter-spacing: -.01em; }
.login-card label { text-align: left; font-size: 13px; font-weight: 600; color: var(--muted); display: grid; gap: 6px; }
.login-card input {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.error { color: var(--danger); font-size: 14px; min-height: 1em; }

/* ---------- Estructura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  max-width: 760px; margin: 0 auto;
}
.eyebrow { font-size: 13px; color: var(--muted); }
.eyebrow::first-letter { text-transform: uppercase; }
.topbar h1 { font-size: 28px; letter-spacing: -.02em; line-height: 1.15; }
.view { max-width: 760px; margin: 0 auto; padding: 4px 16px calc(100px + var(--safe-b)); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  padding: 8px 12px calc(8px + var(--safe-b));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; max-width: 120px; border: 0; background: none; color: var(--muted);
  display: grid; justify-items: center; gap: 2px; padding: 6px 4px; border-radius: 12px;
  font-size: 12px; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar button.active { color: var(--accent); }

/* ---------- Selector de días ---------- */
.days {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 4px 0 18px;
}
.day {
  border: 1px solid var(--line); background: var(--surface); border-radius: 14px;
  padding: 8px 0 7px; display: grid; justify-items: center; gap: 1px; position: relative;
}
.day b { font-size: 15px; }
.day small { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.day.today::after {
  content: ""; position: absolute; bottom: 4px; width: 4px; height: 4px; border-radius: 50%; background: var(--accent);
}
.day.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.day.active small { color: inherit; opacity: .7; }
.day.active.today::after { background: var(--bg); }

/* ---------- Resumen del día ---------- */
.summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.summary h2 { font-size: 22px; letter-spacing: -.01em; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink);
}
.pill.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Tarjetas de comida ---------- */
.meals { display: grid; gap: 12px; }
@media (min-width: 640px) { .meals { grid-template-columns: 1fr 1fr; } }
.meal {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.meal-head {
  width: 100%; border: 0; background: none; text-align: left; padding: 16px;
  display: grid; gap: 6px;
}
.slot { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.meal h3 { font-size: 17px; line-height: 1.3; letter-spacing: -.005em; }
.meal ul.brief { margin: 2px 0 0; padding: 0; list-style: none; color: var(--muted); font-size: 14px; display: grid; gap: 2px; }
.meal-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 16px 14px; }
.chip { white-space: nowrap; font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 3px 9px; border-radius: 999px; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 14px; padding: 4px 0; }

/* ---------- Detalle de receta ---------- */
.recipe h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 0 10px; }
.ing { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ing li { display: flex; gap: 10px; align-items: flex-start; }
.ing li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c, var(--accent)); margin-top: 9px; flex: none; }
.ing .var { display: block; color: var(--muted); font-size: 14px; }
.ing .var b { color: var(--ink); font-weight: 600; }
.ing .var.on b { color: var(--accent); }
.steps { list-style: none; counter-reset: s; margin: 0; padding: 0; display: grid; gap: 14px; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 28px 1fr; gap: 12px; }
.steps li::before {
  content: counter(s); width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 14px;
  display: grid; place-items: center;
}
.recipe-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.actions .btn { flex: 1 1 150px; }
a.share-opt { text-decoration: none; color: inherit; }

/* ---------- Listas genéricas ---------- */
.filters { display: flex; gap: 6px; overflow-x: auto; margin: 4px -16px 16px; padding: 0 16px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 7px 14px; font-size: 14px; font-weight: 600; color: var(--muted);
}
.filters button.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.list { display: grid; gap: 10px; }
.row {
  width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px 16px; display: grid; gap: 4px;
}
.row h3 { font-size: 16px; }
.row p { font-size: 13px; color: var(--muted); }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }

/* ---------- Compras ---------- */
.progress { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 8px; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 10px 0 8px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .3s ease; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.item {
  width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 14px;
  padding: 12px 14px; display: grid; grid-template-columns: 24px 1fr auto; gap: 12px; align-items: start;
}
.check { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line); display: grid; place-items: center; margin-top: 1px; }
.check svg { width: 14px; height: 14px; opacity: 0; }
.item[data-s="comprado"] .check { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.item[data-s="casa"] .check { background: var(--surface-2); border-color: var(--muted); color: var(--muted); }
.item[data-s="comprado"] .check svg, .item[data-s="casa"] .check svg { opacity: 1; }
.item[data-s="comprado"] strong, .item[data-s="casa"] strong { text-decoration: line-through; color: var(--muted); }
.item strong { font-size: 15px; font-weight: 600; display: block; }
.item small { font-size: 13px; color: var(--muted); display: block; }
.item .qty { font-size: 13px; color: var(--muted); text-align: right; max-width: 120px; }
.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

/* ---------- Prep ---------- */
.prep-step { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: grid; gap: 6px; }
.prep-step .top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.prep-step h3 { font-size: 16px; display: flex; align-items: center; gap: 10px; }
.num { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 13px; font-weight: 700; flex: none; }
.prep-step p { font-size: 14px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface); border-radius: 16px; overflow: hidden; border: 1px solid var(--line); }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.table td.n { text-align: right; font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: 0; font-weight: 700; }

/* ---------- Hoja inferior ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(10, 14, 12, .45); animation: fade .2s ease; }
.sheet-panel {
  position: relative; width: 100%; max-width: 640px; max-height: 92dvh; overflow: auto;
  background: var(--bg); border-radius: 24px 24px 0 0; padding: 8px 16px calc(24px + var(--safe-b));
  animation: up .25s cubic-bezier(.2, .8, .2, 1);
}
@media (min-width: 700px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 24px; max-height: 88dvh; }
}
.sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; position: sticky; top: -8px; background: var(--bg); padding: 4px 0 8px; z-index: 1; }
.sheet-head h2 { font-size: 20px; letter-spacing: -.01em; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.share-opts { display: grid; gap: 10px; }
.share-opt {
  width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 16px;
  padding: 14px 16px; display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: center;
}
.share-opt .ico { width: 40px; height: 40px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.share-opt .ico svg { width: 20px; height: 20px; }
.share-opt strong { display: block; font-size: 15px; }
.share-opt small { color: var(--muted); font-size: 13px; }
.previews { display: flex; gap: 10px; overflow-x: auto; padding: 4px 0 12px; scroll-snap-type: x mandatory; }
.previews img {
  flex: none; width: min(78%, 300px); height: auto; border-radius: 14px; border: 1px solid var(--line);
  scroll-snap-align: start; background: #fff;
}
.previews img:only-child { width: min(100%, 360px); margin: 0 auto; }
.hint { font-size: 13px; color: var(--muted); margin-top: 10px; text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 60; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Ajustar con IA ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; margin-bottom: 14px; }
.card-title { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.card p.muted { font-size: 14px; }
.textarea {
  width: 100%; min-height: 110px; resize: vertical; font: inherit; font-size: 15px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none;
}
.textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea.code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; min-height: 130px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 1px dashed var(--line); background: none; border-radius: 999px; padding: 6px 12px; font-size: 13px; color: var(--muted); }
.chips button:hover { border-color: var(--accent); color: var(--accent); }
.ai-links { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; }
.ai-links a { color: var(--accent); font-weight: 600; text-decoration: none; }
.result { border-radius: 14px; padding: 14px; font-size: 14px; display: grid; gap: 10px; }
.result.ok { background: var(--accent-soft); }
.result.bad { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--ink); }
.result h4 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.result ul { margin: 4px 0 0; padding-left: 18px; display: grid; gap: 2px; }
.history { display: grid; gap: 8px; }
.history-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.history-row:first-child { border-top: 0; }
.history-row small { display: block; color: var(--muted); font-size: 12px; }
.btn.small { padding: 7px 12px; font-size: 13px; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.skeleton { height: 120px; border-radius: var(--radius); background: var(--surface-2); animation: pulse 1.2s ease infinite; margin-bottom: 12px; }
@keyframes pulse { 50% { opacity: .5; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
