:root {
  --bg: #f7f2ec; --card: #ffffff; --ink: #2b1d16; --muted: #7a6a60; --line: #e8ddd2;
  --brand: #6b3f26; --brand-dark: #3b2418; --accent: #c8792d; --soft: #f1e6da;
  --ok: #2f7d4f; --ok-bg: #e3f3e8; --mid: #9a6a12; --mid-bg: #fbf0d6; --bad: #b4412f; --bad-bg: #fbe5e0;
  --radius: 14px; --shadow: 0 1px 2px rgba(60, 35, 20, .08), 0 4px 14px rgba(60, 35, 20, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17110d; --card: #221a15; --ink: #f2e9e1; --muted: #b3a399; --line: #3a2d25;
    --brand: #e0a56f; --brand-dark: #120c09; --accent: #e8a35c; --soft: #2d221b;
    --ok: #7fd39f; --ok-bg: #1d3326; --mid: #f0c36a; --mid-bg: #3a2e14; --bad: #f19582; --bad-bg: #3d211b;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--brand-dark); color: #fbeee2; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; letter-spacing: .3px; }
.brand img { border-radius: 8px; }
.top-right { display: flex; align-items: center; gap: 10px; }
.net { font-size: .78rem; background: #8a3b2a; color: #fff; padding: 3px 8px; border-radius: 99px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; border: 2px solid #fbeee2; background: var(--accent); color: #fff; font-weight: 700; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
.loading, .empty { color: var(--muted); text-align: center; padding: 32px 8px; }
h2 { font-size: 1.15rem; margin: 6px 0 12px; }
h3 { font-size: 1rem; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { background: none; border: 0; padding: 8px 4px 10px; font-size: .75rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabs button span { font-size: 1.25rem; line-height: 1.2; }
.tabs button.on { color: var(--brand); font-weight: 700; }

/* Buscador */
.ask { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.ask label { font-weight: 700; display: block; margin-bottom: 8px; }
.ask textarea { width: 100%; min-height: 54px; resize: vertical; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { border: 1px solid var(--line); background: var(--soft); border-radius: 99px; padding: 4px 10px; font-size: .85rem; }
button.chip:hover { border-color: var(--accent); }
.understood { margin-top: 10px; font-size: .85rem; color: var(--muted); }
.understood .chip { background: transparent; border-color: var(--accent); color: var(--ink); padding: 2px 8px; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 14px 2px 10px; font-size: .9rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: 6px 12px; font-size: .85rem; }
.seg button.on { background: var(--brand); color: #fff; }
.switch { display: inline-flex; align-items: center; gap: 8px; }
.switch input { width: 18px; height: 18px; accent-color: var(--brand); }
.banner { background: var(--mid-bg); color: var(--mid); border-radius: 10px; padding: 8px 12px; font-size: .88rem; margin-bottom: 10px; }

/* Tarjetas de receta */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; overflow: hidden; border: 1px solid transparent; }
.card.open { border-color: var(--line); }
.card-head { width: 100%; text-align: left; background: none; border: 0; padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.card-title { font-weight: 700; font-size: 1.02rem; }
.card-title .star { color: var(--accent); }
.card-meta { grid-column: 1; font-size: .82rem; color: var(--muted); }
.card-scores { grid-row: 1 / span 2; grid-column: 2; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.meter { display: flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 700; }
.meter .bar { width: 64px; height: 7px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.meter .bar span { display: block; height: 100%; background: var(--accent); }
.pill { font-size: .8rem; font-weight: 700; border-radius: 99px; padding: 2px 8px; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.mid { background: var(--mid-bg); color: var(--mid); }
.pill.low { background: var(--bad-bg); color: var(--bad); }
.badge { display: inline-block; font-size: .72rem; background: var(--soft); border-radius: 6px; padding: 1px 6px; margin-left: 6px; color: var(--muted); font-weight: 600; vertical-align: middle; }

.detail { padding: 0 14px 14px; border-top: 1px solid var(--line); }
.detail .hero { width: calc(100% + 28px); margin: 0 -14px 10px; max-height: 260px; object-fit: cover; display: block; }
.detail p.desc { margin: 12px 0 8px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.serv { display: flex; align-items: center; gap: 10px; margin: 12px 0 4px; font-size: .9rem; }
.serv button { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: var(--soft); font-weight: 700; }
ul.ings { list-style: none; padding: 0; margin: 6px 0; }
ul.ings li { display: grid; grid-template-columns: 22px 1fr; gap: 2px 8px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
ul.ings li:last-child { border-bottom: 0; }
.mark { font-weight: 800; text-align: center; }
.mark.yes { color: var(--ok); } .mark.no { color: var(--bad); } .mark.neutral { color: var(--muted); }
.ing-line { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 10px; }
.ing-amt { color: var(--muted); font-size: .9rem; }
.ing-amt .alt { opacity: .8; }
.ing-sub { grid-column: 2; font-size: .83rem; color: var(--ok); }
.ing-sub.none { color: var(--muted); }
.ing-note { grid-column: 2; font-size: .8rem; color: var(--muted); }
ol.steps { padding-left: 22px; margin: 6px 0; }
ol.steps li { margin-bottom: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 12px; font-size: .9rem; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.btn.danger { color: var(--bad); border-color: var(--bad-bg); }
.btn.big { width: 100%; padding: 12px; font-size: 1rem; }
.btn:disabled { opacity: .5; cursor: default; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin-top: 6px; }
.photos figure { margin: 0; position: relative; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block; }
.photos figure button { position: absolute; top: 4px; right: 4px; border: 0; border-radius: 50%; width: 26px; height: 26px; background: rgba(0,0,0,.55); color: #fff; }
.byline { font-size: .78rem; color: var(--muted); margin-top: 10px; }
.outside { margin: 18px 0 8px; padding: 12px 14px; border-radius: var(--radius); border: 1px dashed var(--line); }
.outside .actions { margin-top: 8px; }

/* Almacén */
.pantry-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--card); }
.ing-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.ing-chip { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 6px 12px; font-size: .9rem; }
.ing-chip.on { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); font-weight: 700; }
.ing-chip.on::before { content: "✓ "; }

/* Importar */
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.panel textarea { min-height: 120px; resize: vertical; }
.found { display: grid; grid-template-columns: 26px 1fr; gap: 4px 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.found:last-child { border-bottom: 0; }
.found input { width: 20px; height: 20px; accent-color: var(--brand); margin-top: 2px; }
.preview-img { max-width: 100%; max-height: 240px; border-radius: 10px; display: block; margin-top: 10px; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--soft); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: middle; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Ventana emergente */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(20, 10, 5, .5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .modal { align-items: center; } .sheet { border-radius: 18px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sheet-head h2 { margin: 0; }
.x { border: 0; background: var(--soft); border-radius: 50%; width: 34px; height: 34px; font-size: 1.1rem; }
.field { margin: 12px 0; }
.field > span { display: block; font-size: .85rem; font-weight: 700; margin-bottom: 4px; }
.row { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.ing-row { display: grid; grid-template-columns: 1fr 70px 100px 34px; gap: 6px; margin-bottom: 6px; align-items: center; }
.ing-row .note { grid-column: 1 / span 2; }
.ing-row label { grid-column: 3 / span 2; font-size: .8rem; display: flex; align-items: center; gap: 4px; }
.ing-row .del { border: 0; background: var(--bad-bg); color: var(--bad); border-radius: 8px; height: 36px; }
.ing-row input, .ing-row select { padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); min-width: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: .9rem; }
.checks label { display: inline-flex; gap: 4px; align-items: center; }

/* Ingreso */
.login { max-width: 380px; margin: 30px auto; text-align: center; }
.login img { border-radius: 22px; }
.login h1 { margin: 10px 0 4px; }
.login form { text-align: left; margin-top: 18px; }
.or { margin: 18px 0 6px; color: var(--muted); font-size: .85rem; }
.google { display: flex; align-items: center; justify-content: center; gap: 10px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--brand-dark); color: #fbeee2; padding: 10px 16px; border-radius: 10px; max-width: 90vw; box-shadow: var(--shadow); font-size: .92rem; }
