/* Despensa Familiar - Mobile First */
:root {
  --teal: #0d9488; --teal-dark: #0f766e; --teal-light: #ccfbf1;
  --bg: #f8fafc; --card: #ffffff; --text: #1e293b; --muted: #64748b;
  --ok: #16a34a; --ok-bg: #dcfce7;
  --low: #d97706; --low-bg: #fef3c7;
  --out: #dc2626; --out-bg: #fee2e2;
  --radius: 16px;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: 92px; /* espacio para nav inferior */
}
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select { font-family: inherit; font-size: 1rem; }

/* ---------- Header ---------- */
header {
  position: sticky; top: 0; z-index: 50;
  background: var(--teal); color: #fff;
  padding: 14px 16px 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
header h1 { font-size: 1.25rem; display: flex; align-items: center; gap: 8px; }
header .subtitle { font-size: .75rem; opacity: .85; margin-top: 2px; }
#syncBadge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .72rem; background: rgba(255,255,255,.18);
  padding: 4px 10px; border-radius: 999px; margin-top: 8px;
}
#syncBadge .dot { width: 8px; height: 8px; border-radius: 50%; background: #fbbf24; }
#syncBadge.online .dot { background: #4ade80; }

/* ---------- Vistas ---------- */
.view { display: none; padding: 14px; max-width: 720px; margin: 0 auto; animation: fadeIn .2s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Categorías / grupos ---------- */
.category-title {
  font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin: 18px 4px 8px; display: flex; align-items: center; gap: 8px;
}
.category-title .count {
  background: var(--teal-light); color: var(--teal-dark);
  border-radius: 999px; padding: 1px 9px; font-size: .72rem;
}

/* ---------- Tarjetas de producto ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
  border-left: 5px solid transparent;
}
.card.st-suficiente { border-left-color: var(--ok); }
.card.st-poco { border-left-color: var(--low); }
.card.st-agotado { border-left-color: var(--out); background: #fff5f5; }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-name { font-weight: 600; font-size: 1.05rem; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  font-size: .72rem; padding: 3px 9px; border-radius: 999px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px;
}
.tag.freq { background: #e0e7ff; color: #4338ca; }
.tag.store { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }

/* Badge de estado grande y táctil */
.status-btn {
  min-width: 110px; min-height: 44px;
  border-radius: 12px; font-weight: 700; font-size: .82rem;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .1s;
}
.status-btn:active { transform: scale(.95); }
.status-btn.st-suficiente { background: var(--ok-bg); color: var(--ok); }
.status-btn.st-poco { background: var(--low-bg); color: var(--low); }
.status-btn.st-agotado { background: var(--out-bg); color: var(--out); }

.card-actions { display: flex; gap: 8px; margin-top: 12px; }
.big-btn {
  flex: 1; min-height: 52px; border-radius: 12px;
  font-size: .95rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .1s, background .15s;
}
.big-btn:active { transform: scale(.96); }
.big-btn.primary { background: var(--teal); color: #fff; }
.big-btn.primary.on { background: var(--teal-dark); }
.big-btn.ghost { background: #f1f5f9; color: var(--muted); border: 1px solid #e2e8f0; }
.big-btn.small { flex: 0 0 auto; min-width: 52px; flex-basis: 52px; }

/* ---------- FAB añadir ---------- */
#fab {
  position: fixed; right: 18px; bottom: 106px; z-index: 60;
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--teal); color: #fff; font-size: 1.8rem;
  box-shadow: 0 4px 14px rgba(13,148,136,.45);
  display: flex; align-items: center; justify-content: center;
}
#fab:active { transform: scale(.92); }

/* ---------- Nav inferior ---------- */
nav.bottom {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 55;
  background: var(--card); border-top: 1px solid #e2e8f0;
  display: flex; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
}
nav.bottom button {
  flex: 1; min-height: 60px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: .68rem; font-weight: 600;
}
nav.bottom button.active { color: var(--teal); background: var(--teal-light); }
nav.bottom .icon { font-size: 1.35rem; line-height: 1; }

/* ---------- Lista de compras ---------- */
.store-group { margin-bottom: 20px; }
.store-header {
  background: var(--teal-dark); color: #fff;
  padding: 12px 16px; border-radius: var(--radius) var(--radius) 0 0;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 700;
}
.store-body { background: var(--card); border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.shop-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid #f1f5f9;
  min-height: 60px;
}
.shop-item:last-child { border-bottom: none; }
.shop-item .check {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  border: 2.5px solid #cbd5e1; display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem; color: transparent; transition: all .15s;
}
.shop-item.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.shop-item.done .name { text-decoration: line-through; color: var(--muted); }
.shop-item .name { font-weight: 600; flex: 1; }
.shop-item .reason { font-size: .72rem; color: var(--muted); }
.badge-out { background: var(--out-bg); color: var(--out); font-size: .65rem; padding: 2px 7px; border-radius: 999px; font-weight: 700; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state .emoji { font-size: 3rem; margin-bottom: 10px; }

/* ---------- Cronograma ---------- */
.legend { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 16px; }
.legend .tag { cursor: pointer; border: 2px solid transparent; min-height: 36px; }
.legend .tag.selected { border-color: var(--text); }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-head { text-align: center; font-size: .72rem; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-day {
  aspect-ratio: 1; border-radius: 10px; background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: .85rem; font-weight: 600; border: 2px solid transparent;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); min-height: 48px;
}
.cal-day .label { font-size: .55rem; font-weight: 700; }
.cal-day.t-libre { background: var(--ok-bg); } .cal-day.t-libre .label { color: var(--ok); }
.cal-day.t-turno { background: var(--low-bg); } .cal-day.t-turno .label { color: var(--low); }
.cal-day.t-manana { background: #dbeafe; } .cal-day.t-manana .label { color: #1d4ed8; }
.cal-day.t-noche { background: #e0e7ff; } .cal-day.t-noche .label { color: #4338ca; }
.cal-day.today { border-color: var(--teal); }
.cal-day.past { opacity: .4; }
.plan-card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.plan-card h3 { font-size: .95rem; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }
.plan-card ul { list-style: none; }
.plan-card li { padding: 8px 0; border-bottom: 1px dashed #e2e8f0; font-size: .9rem; display: flex; gap: 8px; align-items: flex-start; }
.plan-card li:last-child { border-bottom: none; }
.plan-card li .time { font-weight: 700; color: var(--teal-dark); flex-shrink: 0; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 100;
  display: none; align-items: flex-end; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--card); width: 100%; max-width: 520px;
  border-radius: 24px 24px 0 0; padding: 22px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto; animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(60px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h2 { font-size: 1.15rem; margin-bottom: 16px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .78rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .03em; }
.field input, .field select {
  width: 100%; min-height: 52px; padding: 10px 14px;
  border: 2px solid #e2e8f0; border-radius: 12px; background: #f8fafc;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--teal); background: #fff; }
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1; min-height: 48px; border-radius: 10px; font-weight: 700; font-size: .8rem;
  background: #f1f5f9; color: var(--muted); border: 2px solid transparent;
}
.seg button.sel { background: var(--teal-light); color: var(--teal-dark); border-color: var(--teal); }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }

/* ---------- Banner modo local ---------- */
#localBanner {
  background: #fef3c7; color: #92400e; font-size: .78rem;
  padding: 8px 14px; text-align: center; font-weight: 600;
}

.filter-bar { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 12px; -webkit-overflow-scrolling: touch; }
.filter-bar button {
  flex-shrink: 0; min-height: 44px; padding: 0 16px; border-radius: 999px;
  background: var(--card); color: var(--muted); font-weight: 700; font-size: .82rem;
  border: 1.5px solid #e2e8f0;
}
.filter-bar button.sel { background: var(--teal); color: #fff; border-color: var(--teal); }

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 24px; margin-bottom: 40px; }
}
