:root {
  --bg: #fbf6ee;
  --surface: #ffffff;
  --surface-2: #f4ede1;
  --ink: #1f2a24;
  --ink-2: #5b665f;
  --line: #e8dfd0;
  --green: #2f7d4f;
  --green-soft: #e3f1e7;
  --tomato: #e4572e;
  --tomato-soft: #fde7df;
  --mustard: #f2b134;
  --mustard-soft: #fdf1d6;
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 6px 20px rgba(60, 40, 10, .07);
  --radius: 18px;
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151a17;
    --surface: #1e2521;
    --surface-2: #26302a;
    --ink: #eef2ee;
    --ink-2: #a7b3aa;
    --line: #313c35;
    --green: #5cc185;
    --green-soft: #1f3a2a;
    --tomato: #ff7a52;
    --tomato-soft: #3d241c;
    --mustard: #f6c35c;
    --mustard-soft: #3a311c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px;
  line-height: 1.45; min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--green); }
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0; letter-spacing: -.01em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); font-weight: 800; }
h2 { font-size: 1.35rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; }
.muted { color: var(--ink-2); }
.small { font-size: .86rem; }
[hidden] { display: none !important; }

/* ---------- Estructura ---------- */
.shell { max-width: 1100px; margin: 0 auto; padding: 16px 16px 110px; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--display); font-weight: 800; font-size: 1.25rem; text-decoration: none; color: var(--ink); }
.brand-logo { width: 34px; height: 34px; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a {
  display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; text-decoration: none;
  color: var(--ink-2); font-weight: 700;
}
.nav a.active { background: var(--green-soft); color: var(--green); }
.nav .ico { font-size: 1.15rem; }
@media (max-width: 760px) {
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; margin: 0; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line); z-index: 30;
  }
  .nav a { flex-direction: column; gap: 0; font-size: .72rem; padding: 6px 10px; border-radius: 14px; }
  .nav .ico { font-size: 1.4rem; }
  .topbar .logout { margin-left: auto; }
}

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 8px 0 18px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* ---------- Controles ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 999px;
  padding: 10px 18px; font-weight: 800; background: var(--surface-2); color: var(--ink); text-decoration: none;
  transition: transform .08s ease, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--green); color: #fff; }
.btn.tomato { background: var(--tomato); color: #fff; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.small { padding: 6px 12px; font-size: .88rem; }
.btn.big { padding: 14px 26px; font-size: 1.08rem; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--surface-2); display: inline-grid;
  place-items: center; font-size: 1.05rem; flex: none;
}
.input, select.input, textarea.input {
  width: 100%; padding: 11px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface);
  outline: none;
}
.input:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
textarea.input { resize: vertical; min-height: 70px; }
label.field { display: block; font-weight: 700; font-size: .9rem; }
label.field > span { display: block; margin-bottom: 4px; color: var(--ink-2); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 999px; font-weight: 700; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; background: var(--surface-2);
  font-weight: 700; font-size: .88rem; white-space: nowrap;
}
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.tomato { background: var(--tomato-soft); color: var(--tomato); }
.chip.mustard { background: var(--mustard-soft); color: #8a5c00; }
@media (prefers-color-scheme: dark) { .chip.mustard { color: var(--mustard); } }
.badge { font-size: .7rem; font-weight: 800; padding: 2px 7px; border-radius: 6px; text-transform: uppercase; letter-spacing: .03em; }
.badge.est { background: var(--mustard-soft); color: #8a5c00; }
.badge.real { background: var(--green-soft); color: var(--green); }
.badge.manual { background: var(--surface-2); color: var(--ink-2); }
.empty { text-align: center; padding: 40px 16px; color: var(--ink-2); }
.empty .big-emoji { font-size: 3.2rem; display: block; margin-bottom: 8px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; }
.login .hero-emoji { font-size: 2.6rem; letter-spacing: 4px; text-align: center; }
.error { color: var(--tomato); font-weight: 700; min-height: 1.2em; }

/* ---------- Lista ---------- */
.search-wrap { position: relative; }
.search-wrap .input { padding-left: 44px; font-size: 1.05rem; padding-top: 14px; padding-bottom: 14px; border-radius: 18px; }
.search-wrap .lens { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); font-size: 1.15rem; }
.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 15; background: var(--surface);
  border-radius: 18px; box-shadow: 0 10px 40px rgba(0,0,0,.18); max-height: 60vh; overflow: auto; padding: 6px;
}
.result { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 12px; width: 100%; border: 0; background: none; text-align: left; }
.result:hover, .result.sel { background: var(--surface-2); }
.thumb {
  width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center;
  font-size: 1.6rem; flex: none; overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.result .price { margin-left: auto; text-align: right; font-weight: 800; white-space: nowrap; }
.cat-title { margin: 18px 4px 6px; font-weight: 800; color: var(--ink-2); font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow); margin-bottom: 8px;
}
.item.checked { opacity: .5; }
.item.checked .name { text-decoration: line-through; }
.check {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); background: none; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 900;
}
.item.checked .check { background: var(--green); border-color: var(--green); }
.item .name { font-weight: 700; }
.qty { display: inline-flex; align-items: center; background: var(--surface-2); border-radius: 999px; }
.qty button { border: 0; background: none; width: 30px; height: 30px; font-weight: 900; font-size: 1.05rem; }
.qty span { min-width: 22px; text-align: center; font-weight: 800; }
.cheapest { font-size: .8rem; font-weight: 700; }
.compare-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px; z-index: 25; width: min(680px, calc(100% - 32px));
  background: var(--ink); color: var(--bg); border-radius: 22px; padding: 12px 14px 12px 18px; display: flex; align-items: center;
  gap: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.compare-bar .btn { margin-left: auto; }
@media (max-width: 760px) { .compare-bar { bottom: calc(76px + env(safe-area-inset-bottom)); } }

/* ---------- Comparador ---------- */
.winner {
  position: relative; overflow: hidden; background: linear-gradient(135deg, var(--green), #1d5a37); color: #fff; padding: 22px;
}
.winner h1 { color: #fff; }
.winner .confetti { position: absolute; right: 14px; top: 8px; font-size: 3.4rem; opacity: .9; }
.ranking .bar-row { display: grid; grid-template-columns: 110px 1fr 86px; gap: 10px; align-items: center; padding: 7px 0; }
.bar-track { height: 26px; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.bar { height: 100%; border-radius: 8px; min-width: 4px; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.store-name { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.bar-row .total { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar-row .warn { grid-column: 2 / 4; font-size: .8rem; color: var(--tomato); font-weight: 700; margin-top: -4px; }
.tips { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.price-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.price-table th, .price-table td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.price-table th:first-child, .price-table td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
.price-table td.min { color: var(--green); font-weight: 900; }
.price-table td.est { color: var(--ink-2); }
.price-table tfoot td { font-weight: 900; border-bottom: 0; }

/* ---------- Productos ---------- */
.cat-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.cat-tabs button { border: 0; flex: none; }
.cat-tabs .chip.on { background: var(--ink); color: var(--bg); }
.prod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.prod { display: flex; gap: 12px; align-items: center; text-align: left; border: 0; width: 100%; }
.price-edit { display: grid; grid-template-columns: 1fr 120px; gap: 10px; align-items: center; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10, 15, 12, .45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { width: min(520px, 100%); max-height: 90vh; overflow: auto; }

/* ---------- Recetas ---------- */
.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.rcard { padding: 0; overflow: hidden; text-decoration: none; color: inherit; display: flex; flex-direction: column; transition: transform .15s; }
.rcard:hover { transform: translateY(-3px); }
.rcover { position: relative; aspect-ratio: 4 / 3; display: grid; place-items: center; overflow: hidden; }
.rcover img { width: 100%; height: 100%; object-fit: cover; }
.rcover .main-emoji { font-size: 4.4rem; filter: drop-shadow(0 6px 10px rgba(0,0,0,.18)); }
.orbit { position: absolute; inset: 0; pointer-events: none; }
.orbit span { position: absolute; font-size: 1.5rem; opacity: .9; }
.rcover .fav { position: absolute; top: 10px; right: 10px; font-size: 1.3rem; }
.rcard .body { padding: 12px 14px 14px; }
.ing-strip { display: flex; gap: 2px; flex-wrap: wrap; font-size: 1.2rem; margin-top: 6px; }
.g0 { background: linear-gradient(135deg, #ffe0b8, #ffc9a8); }
.g1 { background: linear-gradient(135deg, #d6f0d9, #b5e3c4); }
.g2 { background: linear-gradient(135deg, #ffe6a7, #ffd27a); }
.g3 { background: linear-gradient(135deg, #f9d2d8, #f6b4c0); }
.g4 { background: linear-gradient(135deg, #d7e6fb, #b9d3f6); }
.g5 { background: linear-gradient(135deg, #e9dcf8, #d4c0f2); }
@media (prefers-color-scheme: dark) {
  .g0, .g1, .g2, .g3, .g4, .g5 { filter: saturate(.8) brightness(.75); }
}

.hero { position: relative; border-radius: 26px; overflow: hidden; min-height: 240px; display: grid; place-items: center; box-shadow: var(--shadow); }
.hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero .main-emoji { font-size: 6.5rem; filter: drop-shadow(0 10px 14px rgba(0,0,0,.2)); }
.hero .orbit span { font-size: 2.1rem; }
.hero-actions { position: absolute; top: 12px; right: 12px; display: flex; gap: 8px; z-index: 2; }
.hero-actions .icon-btn { background: rgba(255,255,255,.9); color: #222; }
.recipe-layout { display: grid; grid-template-columns: 360px 1fr; gap: 22px; margin-top: 22px; align-items: start; }
@media (max-width: 860px) { .recipe-layout { grid-template-columns: 1fr; } }
.facts { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.servings { display: inline-flex; align-items: center; gap: 4px; }
.ing-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.ing-card {
  position: relative; background: var(--surface-2); border-radius: 16px; padding: 12px 10px 10px; text-align: center; border: 2px solid transparent;
  transition: opacity .15s, border-color .15s; cursor: pointer;
}
.ing-card .e { font-size: 2.2rem; line-height: 1.1; display: block; }
.ing-card .n { font-weight: 800; font-size: .92rem; display: block; margin-top: 4px; }
.ing-card .q { font-size: .85rem; color: var(--ink-2); font-weight: 700; }
.ing-card.done { opacity: .45; border-color: var(--green); }
.ing-card.pantry { background: transparent; border: 2px dashed var(--line); }
.ing-card.have { border-color: var(--green); background: var(--green-soft); }
.ing-card .tick { position: absolute; top: 6px; right: 8px; color: var(--green); font-weight: 900; }
.steps { counter-reset: step; }
.step { display: grid; grid-template-columns: 46px 1fr; gap: 12px; padding: 14px; margin-bottom: 12px; cursor: pointer; }
.step::before {
  counter-increment: step; content: counter(step); width: 40px; height: 40px; border-radius: 50%; background: var(--tomato); color: #fff;
  display: grid; place-items: center; font-family: var(--display); font-weight: 800; font-size: 1.2rem;
}
.step.done { opacity: .5; }
.step.done::before { content: "✓"; background: var(--green); }
.step p { margin: 0 0 8px; font-size: 1.04rem; }
.step mark { background: var(--mustard-soft); color: inherit; padding: 0 4px; border-radius: 6px; font-weight: 800; white-space: nowrap; }
.step .used { display: flex; gap: 6px; flex-wrap: wrap; }

/* Editor */
.ing-row { display: grid; grid-template-columns: 44px 1fr 80px 100px 38px; gap: 8px; align-items: center; margin-bottom: 8px; }
.ing-row .thumb { width: 44px; height: 44px; font-size: 1.4rem; }
@media (max-width: 560px) {
  .ing-row { grid-template-columns: 40px 1fr 38px; }
  .ing-row .q, .ing-row .u { grid-column: 2 / 3; }
  .ing-row .q { grid-row: 2; } .ing-row .u { grid-row: 3; }
}
.step-row { display: grid; grid-template-columns: 34px 1fr 38px; gap: 8px; align-items: start; margin-bottom: 8px; }
.step-row .num { width: 30px; height: 30px; border-radius: 50%; background: var(--tomato); color: #fff; display: grid; place-items: center; font-weight: 800; margin-top: 6px; }
.suggest { position: relative; }
.suggest .results { top: 100%; }

/* Generador */
.fridge {
  background: linear-gradient(160deg, #eaf6ef, #fdf3df); border-radius: 28px; padding: 22px; box-shadow: var(--shadow);
}
@media (prefers-color-scheme: dark) { .fridge { background: linear-gradient(160deg, #1d2c23, #2c2719); } }
.fridge-chips { display: flex; flex-wrap: wrap; gap: 8px; min-height: 52px; padding: 10px; border-radius: 18px; background: var(--surface); border: 2px dashed var(--line); align-items: center; }
.fchip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 8px 6px 12px; border-radius: 999px; background: var(--green-soft); font-weight: 800; animation: pop .25s ease; }
.fchip .e { font-size: 1.25rem; }
.fchip button { border: 0; background: rgba(0,0,0,.08); width: 22px; height: 22px; border-radius: 50%; font-size: .8rem; line-height: 1; }
.fchip-input { border: 0; outline: none; background: transparent; flex: 1; min-width: 160px; padding: 6px; font-size: 1.05rem; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.quick button { border: 0; background: var(--surface); border-radius: 999px; padding: 6px 11px; font-weight: 700; box-shadow: var(--shadow); }
.quick button:disabled { opacity: .35; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.gen-card { padding: 0; overflow: hidden; animation: rise .4s ease both; }
.gen-card .hero { border-radius: 0; min-height: 170px; box-shadow: none; }
.gen-card .content { padding: 16px; }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.match-meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; width: 120px; }
.match-meter div { height: 100%; background: var(--green); border-radius: 999px; }
.spinner { width: 22px; height: 22px; border: 3px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%) translateY(30px); opacity: 0; z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 700; transition: all .25s; pointer-events: none;
  max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Colores de cada supermercado (legibles también en modo oscuro) */
[style*="--c:"] { color: var(--c); }
@media (prefers-color-scheme: dark) { [style*="--c:"] { color: color-mix(in srgb, var(--c) 45%, white); } }

/* ---------- Ajustes móvil ---------- */
@media (max-width: 760px) {
  /* backdrop-filter crea un contenedor para los elementos fijos: sin él, la barra inferior queda abajo de verdad */
  .topbar { backdrop-filter: none; background: var(--bg); }
  .shell { padding-bottom: 200px; }
  .brand { font-size: 1.1rem; }
}
@media (max-width: 560px) {
  .item { gap: 9px; padding: 9px 10px; }
  .item .thumb { width: 38px; height: 38px; font-size: 1.35rem; }
  .item [data-a="del"] { display: none; }
  .item .name { font-size: .95rem; line-height: 1.2; }
  .qty button { width: 28px; }
  .ranking .bar-row { grid-template-columns: 96px 1fr 74px; gap: 8px; }
  .page-head { margin-top: 0; }
}
