:root {
  --bg: #f8f9ff;
  --card: #ffffff;
  --ink: #0b1c30;
  --muted: #55615a;
  --muted-2: #7c8a86;
  --green: #22c55e;
  --green-d: #006e2f;
  --green-dd: #004b1e;
  --green-tint: #e7f4ec;
  --chip: #e5eeff;
  --chip-ink: #16324f;
  --field: #eef3fe;
  --red: #ba1a1a;
  --red-bg: #ffdad6;
  --amber-bg: #fff0d6;
  --amber-ink: #9a5b00;
  --line: #e8edf7;
  --shadow: 0 4px 20px rgba(15, 40, 70, 0.06);
  --shadow-fab: 0 10px 24px rgba(34, 197, 94, 0.35);
  --radius: 16px;
  --radius-lg: 22px;
  --nav-h: 76px;
  --sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 16px; }

/* ---------- Shell ---------- */
.app { max-width: 720px; margin: 0 auto; min-height: 100dvh; }
main {
  padding: 14px 20px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom));
}
.screen { display: none; animation: fade .25s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Cabecera ---------- */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 2px 6px; position: sticky; top: 0; z-index: 20;
  background: linear-gradient(var(--bg) 78%, rgba(248,249,255,0));
}
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: var(--green-tint); display: grid; place-items: center; font-size: 22px;
  border: 2px solid #fff; box-shadow: var(--shadow);
}
.top h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; color: var(--green-d); margin: 0; flex: 1; }
.bell {
  position: relative; width: 42px; height: 42px; border-radius: 50%; border: none;
  background: transparent; color: var(--green-d); display: grid; place-items: center;
}
.bell:active { background: var(--green-tint); }
.bell svg { width: 24px; height: 24px; }
.bell .badge {
  position: absolute; top: 4px; right: 5px; min-width: 18px; height: 18px; padding: 0 4px;
  background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700;
  display: grid; place-items: center; border: 2px solid var(--bg);
}
.bell .badge:empty, .bell .badge[data-n="0"] { display: none; }

/* ---------- Buscador ---------- */
.search {
  display: flex; align-items: center; gap: 10px; background: var(--field);
  border-radius: var(--radius); padding: 13px 16px; margin: 6px 0 16px;
}
.search svg { width: 20px; height: 20px; color: var(--muted-2); flex: none; }
.search input { border: none; background: transparent; outline: none; width: 100%; color: var(--ink); }

/* ---------- Chips de filtro ---------- */
.chips { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 4px; margin: 0 -2px 18px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: none; background: var(--chip); color: var(--chip-ink);
  padding: 9px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; white-space: nowrap;
  transition: transform .08s;
}
.chip:active { transform: scale(.96); }
.chip.on { background: var(--green); color: #fff; }

/* ---------- Tarjetas de producto (Despensa) ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px; animation: fade .25s ease;
}
.p-head { display: flex; align-items: flex-start; gap: 14px; }
.tile {
  width: 52px; height: 52px; border-radius: 14px; flex: none; display: grid; place-items: center;
  font-size: 26px; background: var(--green-tint);
}
.p-main { flex: 1; min-width: 0; }
.p-name { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.p-status { font-size: 14px; font-weight: 600; margin-top: 2px; }
.p-status.low { color: var(--red); }
.p-status.ok { color: var(--green-d); }
.p-status.out { color: var(--red); }
.cart-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none; flex: none;
  background: var(--green-tint); color: var(--green-d); display: grid; place-items: center;
}
.cart-btn svg { width: 22px; height: 22px; }
.cart-btn.in { background: var(--green); color: #fff; }
.cart-btn:active { transform: scale(.93); }

.bar { height: 8px; border-radius: 999px; background: #e9eef8; overflow: hidden; margin: 12px 0 2px; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--green); transition: width .3s ease; }
.bar.low > span { background: var(--red); }

.p-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.move { background: none; border: none; color: var(--muted); font-size: 14px; font-weight: 600; padding: 4px 0; }
.move:active { color: var(--green-d); }

.stepper { display: flex; align-items: center; gap: 2px; background: var(--field); border-radius: 12px; padding: 3px; }
.stepper button { border: none; background: transparent; color: var(--ink); width: 34px; height: 34px; font-size: 20px; border-radius: 9px; }
.stepper button:active { background: #dbe6ff; }
.stepper .v { min-width: 46px; text-align: center; font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }

/* ---------- Resumen semanal ---------- */
.summary {
  background: linear-gradient(150deg, var(--green-d), var(--green-dd));
  color: #fff; border-radius: var(--radius-lg); padding: 22px; margin: 20px 0 6px;
  box-shadow: 0 12px 30px -12px rgba(0, 75, 30, 0.6);
}
.summary h3 { margin: 0 0 8px; font-size: 20px; font-weight: 700; }
.summary p { margin: 0; color: #d7ecdd; font-size: 15px; }
.summary .stats { display: flex; gap: 26px; margin-top: 18px; }
.summary .stats .n { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; }
.summary .stats .l { font-size: 13px; color: #cfe7d6; margin-top: 4px; }
.summary .sep { width: 1px; background: rgba(255,255,255,.25); }
.summary .ai-line { margin-top: 16px; display: flex; align-items: center; gap: 8px; font-size: 14px; color: #eafff0; }
.ai-btn {
  margin-top: 14px; width: 100%; border: none; background: rgba(255,255,255,.16); color: #fff;
  padding: 12px; border-radius: 12px; font-weight: 700; font-size: 15px; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.ai-btn:active { background: rgba(255,255,255,.26); }

/* ---------- Lista de compra ---------- */
.group-h { display: flex; align-items: center; gap: 8px; margin: 24px 2px 12px; }
.group-h .ic { font-size: 18px; }
.group-h h2 { font-size: 14px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--green-d); margin: 0; }
.group-h .c { color: var(--muted-2); font-size: 13px; font-weight: 600; }

.li {
  display: flex; align-items: center; gap: 14px; background: var(--card);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 15px; margin-bottom: 12px;
}
.check {
  flex: none; width: 27px; height: 27px; border-radius: 50%; border: 2px solid #c3cfdd;
  background: transparent; display: grid; place-items: center; transition: all .15s;
}
.check svg { width: 15px; height: 15px; stroke: #fff; stroke-width: 3.2; fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 20; stroke-dashoffset: 20; transition: stroke-dashoffset .2s; }
.li.done .check { background: var(--green); border-color: var(--green); }
.li.done .check svg { stroke-dashoffset: 0; }
.li-main { flex: 1; min-width: 0; }
.li-name { font-size: 17px; font-weight: 600; }
.li.done .li-name { text-decoration: line-through; color: var(--muted-2); opacity: .7; }
.li-sub { font-size: 13.5px; color: var(--muted-2); margin-top: 1px; }
.tag { flex: none; font-size: 13px; font-weight: 700; padding: 7px 12px; border-radius: 999px; display: inline-flex; align-items: center; gap: 5px; }
.tag.fresh { background: var(--green-tint); color: var(--green-d); }
.tag.urgent { background: var(--red-bg); color: var(--red); }
.icon-btn { flex: none; border: none; background: transparent; color: var(--muted-2); width: 34px; height: 34px; border-radius: 8px; font-size: 20px; }
.icon-btn:active { background: var(--field); }

/* ---------- Categorías ---------- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cat {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 16px;
}
.cat:active { transform: scale(.98); }
.cat .tile { margin-bottom: 12px; }
.cat .n { font-size: 17px; font-weight: 700; }
.cat .c { font-size: 13px; color: var(--muted-2); margin-top: 2px; }
.cat.new { border: 2px dashed #b9cbe0; box-shadow: none; background: transparent; display: grid; place-items: center; text-align: center; color: var(--green-d); font-weight: 700; min-height: 132px; }
.cat.new .plus { font-size: 30px; }

/* ---------- Estado vacío ---------- */
.empty { text-align: center; color: var(--muted-2); padding: 44px 24px; }
.empty .big { font-size: 52px; }
.empty p { margin: 12px 0 20px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: max(20px, calc(50% - 360px + 20px));
  bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 20px; border: none; z-index: 30;
  background: var(--green); color: #fff; font-size: 30px; box-shadow: var(--shadow-fab);
  display: grid; place-items: center;
}
.fab:active { transform: scale(.93); }

/* ---------- Menú inferior fijo ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-inner { max-width: 720px; margin: 0 auto; display: flex; height: var(--nav-h); }
.nav button {
  flex: 1; border: none; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  color: var(--muted-2); font-size: 12px; font-weight: 600; padding-top: 6px;
}
.nav button svg { width: 25px; height: 25px; }
.nav button .lab { transition: color .15s; }
.nav button.on { color: var(--green-d); }
.nav button.on .ic-wrap { background: var(--green); color: #fff; }
.ic-wrap { width: 54px; height: 32px; border-radius: 999px; display: grid; place-items: center; transition: background .18s, color .18s; }

/* ---------- Hoja/modal (Añadir, Notificaciones, IA) ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(11,28,48,.45); z-index: 50; opacity: 0; pointer-events: none; transition: opacity .25s; }
.sheet-bg.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; max-width: 720px; margin: 0 auto;
  background: var(--bg); border-radius: 24px 24px 0 0; padding: 8px 20px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .3s cubic-bezier(.2,.8,.2,1); max-height: 92dvh; overflow-y: auto;
}
.sheet.show { transform: none; }
.grip { width: 44px; height: 5px; border-radius: 999px; background: #cdd6e4; margin: 10px auto 8px; }
.sheet h2 { font-size: 22px; font-weight: 700; color: var(--green-d); margin: 6px 2px 4px; letter-spacing: -0.01em; }
.sheet .lead { color: var(--muted); font-size: 15px; margin: 0 2px 18px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 15px; font-weight: 600; margin: 0 2px 7px; }
.field .box { display: flex; align-items: center; gap: 10px; background: var(--field); border-radius: 14px; padding: 4px 14px; border: 2px solid transparent; transition: border .15s; }
.field .box:focus-within { border-color: var(--green); }
.field .box svg { width: 20px; height: 20px; color: var(--muted-2); flex: none; }
.field input, .field textarea, .field select {
  border: none; background: transparent; outline: none; width: 100%; color: var(--ink); padding: 12px 0;
}
.field textarea { resize: none; min-height: 78px; padding: 12px 0; }
.field select { -webkit-appearance: none; appearance: none; }

.btn-primary {
  width: 100%; border: none; background: var(--green); color: #fff; font-size: 17px; font-weight: 700;
  padding: 16px; border-radius: 16px; display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: var(--shadow-fab); margin-top: 6px;
}
.btn-primary:active { transform: scale(.98); }
.btn-ghost { width: 100%; border: none; background: var(--green-tint); color: var(--green-d); font-weight: 700; padding: 14px; border-radius: 14px; margin-top: 10px; }

/* ---------- Notificaciones / IA contenido ---------- */
.note { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.note .ni { font-size: 22px; flex: none; }
.note .nt { font-size: 15px; }
.note.warn { background: var(--amber-bg); box-shadow: none; }
.note.warn .nt { color: var(--amber-ink); }
.note.err { background: var(--red-bg); box-shadow: none; }
.note.err .nt { color: var(--red); }
.ai-recipe { background: var(--green-tint); border-radius: 16px; padding: 16px; margin: 6px 0 12px; }
.ai-recipe h4 { margin: 0 0 6px; color: var(--green-d); font-size: 17px; }
.ai-recipe .pill { display: inline-block; background: #fff; border-radius: 999px; padding: 4px 10px; font-size: 12.5px; font-weight: 600; margin: 3px 4px 0 0; }
.ai-recipe .miss { color: var(--red); }
.ai-chip-add { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600; margin: 4px 6px 0 0; color: var(--ink); }
.ai-chip-add:active { background: var(--green-tint); }
.spinner { width: 30px; height: 30px; border: 3px solid var(--green-tint); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Ajustes ---------- */
.set-row { display: flex; align-items: center; gap: 14px; background: var(--card); border-radius: 14px; padding: 15px 16px; margin-bottom: 10px; box-shadow: var(--shadow); }
.set-row .si { font-size: 22px; }
.set-row .st { flex: 1; }
.set-row .st .t { font-weight: 600; }
.set-row .st .d { font-size: 13px; color: var(--muted-2); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: #ccd6e4; border-radius: 999px; transition: .2s; }
.switch .track::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::before { transform: translateX(20px); }
.copy-row { display: flex; gap: 8px; background: var(--field); border-radius: 12px; padding: 6px 6px 6px 14px; align-items: center; margin-top: 8px; }
.copy-row code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--muted); }
.copy-row button { border: none; background: var(--green); color: #fff; padding: 9px 14px; border-radius: 9px; font-weight: 700; font-size: 13px; }
.set-label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-2); margin: 24px 2px 10px; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 999px; font-size: 14.5px; font-weight: 600; opacity: 0; pointer-events: none; transition: all .25s; z-index: 80; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #c9c0ad; margin-left: 8px; vertical-align: middle; }
.live-dot.on { background: var(--green); box-shadow: 0 0 0 3px var(--green-tint); }
