:root {
  --bg: #f8f6f3;
  --card: #ffffff;
  --fg: #1a1613;
  --muted: #6b6259;
  --border: #eae4dc;
  --accent: #c2410c;
  --accent-fg: #ffffff;
  --accent-soft: #fdead7;
  --protein: #2563eb;
  --carbs: #d97706;
  --fat: #9333ea;
  --money: #15803d;
  --danger: #b42318;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110e;
    --card: #1e1a16;
    --fg: #f4f1ed;
    --muted: #a89e93;
    --border: #302922;
    --accent: #fb923c;
    --accent-fg: #2a1206;
    --accent-soft: #3a2413;
    --protein: #60a5fa;
    --carbs: #fbbf24;
    --fat: #c084fc;
    --money: #4ade80;
    --danger: #f97066;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 96px;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 44rem; margin: 0 auto; padding: 16px; }

header.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
header.top .wrap { display: flex; align-items: center; gap: 10px; padding: 12px 16px; }
header.top h1 { font-size: 1.15rem; margin: 0; letter-spacing: -.02em; flex: 1; }
header.top h1 a { color: inherit; text-decoration: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.muted { color: var(--muted); font-size: .875rem; }

/* ─── Navegador de día ─── */
.daynav { display: flex; align-items: center; gap: 8px; justify-content: center; margin-bottom: 12px; }
.daynav .label { flex: 1; text-align: center; font-weight: 600; }

/* ─── Resumen del día ─── */
.summary { display: flex; gap: 18px; align-items: center; }
.ring { flex: none; width: 108px; height: 108px; }
.ring text.big { font-size: 26px; font-weight: 700; fill: var(--fg); }
.ring text.small { font-size: 11px; fill: var(--muted); }
.macros { flex: 1; display: grid; gap: 9px; min-width: 0; }
.macro .top { display: flex; justify-content: space-between; font-size: .8rem; }
.macro .top b { font-weight: 600; }
.macro .bar { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: 3px; }
.macro .bar > i { display: block; height: 100%; border-radius: 999px; transition: width .3s; }
.macro.p .bar > i { background: var(--protein); }
.macro.c .bar > i { background: var(--carbs); }
.macro.f .bar > i { background: var(--fat); }
.macro.m .bar > i { background: var(--money); }

.stats { display: flex; gap: 10px; margin-top: 14px; }
.stat { flex: 1; text-align: center; padding: 10px 6px; border-radius: 10px; background: var(--bg); }
.stat b { display: block; font-size: 1.2rem; }
.stat span { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat.done { background: var(--accent-soft); }

/* ─── Recetas ─── */
.cat { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 20px 0 6px; display: flex; justify-content: space-between; }
.item { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: none; }
.item .name { flex: 1; min-width: 0; }
.item .name span { display: block; font-size: .75rem; color: var(--muted); }
.item .kcal { font-weight: 600; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--accent); }

button, .btn {
  font: inherit; cursor: pointer; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card); color: var(--fg);
  padding: 10px 14px; min-height: 44px;
}
button.primary, .btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
button.ghost { border: none; background: none; padding: 8px; min-height: 44px; }
button.danger { color: var(--danger); }
button.small { min-height: 34px; padding: 4px 10px; font-size: .8rem; }
button:disabled { opacity: .55; cursor: default; }

textarea {
  font: inherit; width: 100%; padding: 11px 12px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--fg); resize: vertical;
}

input, select {
  font: inherit; width: 100%; padding: 11px 12px; min-height: 44px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--fg);
}
label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.fab {
  position: fixed; right: max(16px, calc(50vw - 21rem)); bottom: 24px;
  border-radius: 999px; padding: 14px 20px; font-weight: 600;
  background: var(--accent); color: var(--accent-fg); border: none;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
}

dialog {
  border: none; border-radius: 18px; padding: 0; width: min(30rem, 92vw);
  background: var(--card); color: var(--fg);
}
dialog::backdrop { background: rgba(6,12,8,.55); }
dialog .body { padding: 20px; max-height: 84dvh; overflow-y: auto; }
dialog h2 { margin: 0 0 4px; font-size: 1.1rem; }

.results { max-height: 42dvh; overflow-y: auto; margin-top: 8px; }
.result { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: none; border-bottom: 1px solid var(--border); background: none; border-radius: 0; padding: 10px 4px; }
.result .name { flex: 1; }
.result.sel { background: var(--accent-soft); border-radius: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); color: var(--fg); font-size: .82rem; min-height: 0; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.offline { background: var(--danger); color: #fff; text-align: center; font-size: .8rem; padding: 6px; display: none; }
body.is-offline .offline { display: block; }
.token { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; word-break: break-all; background: var(--bg); padding: 10px; border-radius: 8px; }


/* ─── Tarjeta de receta ─── */
a.card { display: block; color: inherit; text-decoration: none; }
a.card:active { transform: scale(.995); }
.recipe-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.recipe-head strong { font-size: 1.05rem; }
.price { font-weight: 700; color: var(--money); font-variant-numeric: tabular-nums; white-space: nowrap; }
.price.partial { color: var(--muted); font-weight: 600; }
.facts { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; font-size: .8rem; color: var(--muted); }
.facts b { color: var(--fg); font-weight: 600; }

.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: .75rem; font-weight: 600;
}
@media (prefers-color-scheme: dark) { .chip { color: var(--fg); } }

/* ─── Detalle de receta ─── */
.totals { display: flex; gap: 10px; margin: 4px 0 8px; }
.totals .stat { flex: 1; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tabs button { flex: 1; min-height: 38px; padding: 6px; font-size: .85rem; }
.tabs button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
.steps { white-space: pre-wrap; line-height: 1.65; }

/* ─── Diario de cocina ─── */
.dayhead { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 20px 0 6px; }

/* ─── Despensa ─── */
.pantry-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.pantry-row:last-child { border-bottom: none; }
.pantry-row .name { flex: 1; min-width: 0; }
.pantry-row .name span { display: block; font-size: .72rem; color: var(--muted); }
.no-price { color: var(--muted); font-style: italic; font-size: .8rem; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login .card { max-width: 24rem; text-align: center; }
.login h1 { font-size: 2rem; margin: 0 0 4px; }
