/* ═══════════════════════════════════════════════════
   DESPENSA · Kitchen Inventory App
   Palette: warm earthy tones, cozy kitchen feel
   ═══════════════════════════════════════════════════ */

:root {
  /* Warm kitchen palette */
  --bg:           #1e1612;
  --bg-2:         #261d17;
  --bg-3:         #2f231b;
  --surface:      rgba(255,255,255,0.05);
  --surface-2:    rgba(255,255,255,0.09);
  --border:       rgba(255,210,170,0.1);
  --border-2:     rgba(255,210,170,0.2);

  --accent:       #f4a261;
  --accent-2:     #e76f51;
  --accent-glow:  rgba(244,162,97,0.18);
  --accent-green: #52b788;
  --accent-orange: #f77f00;
  --accent-blue:  #90e0ef;
  --accent-red:   #e63946;

  --text-strong:  #fdf0e3;
  --text-body:    #c9a98b;
  --text-muted:   rgba(201,169,139,0.5);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --transition: 180ms ease;

  --header-h: 58px;
  --tab-h:    54px;
  --toolbar-h: 96px;
  --fab-size: 56px;

  /* Category colors */
  --cat-frutas:      #52b788;
  --cat-lacteos:     #90e0ef;
  --cat-carnes:      #e76f51;
  --cat-conservas:   #f4a261;
  --cat-granos:      #d4a373;
  --cat-condimentos: #f9c74f;
  --cat-bebidas:     #74c69d;
  --cat-pan:         #d4956a;
  --cat-precocinados:#a8dadc;
  --cat-otros:       #adb5bd;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text-body);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 40% at 50% -10%, rgba(244,162,97,0.12) 0%, transparent 70%),
    repeating-linear-gradient(
      135deg,
      rgba(255,210,170,0.025) 0px,
      rgba(255,210,170,0.025) 1px,
      transparent 1px,
      transparent 12px
    );
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--fab-size) + 2rem);
}

/* ── Header ── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: rgba(30, 22, 18, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.header__inner {
  max-width: 820px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
}

.header__back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text-body);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.header__back svg { width: 20px; height: 20px; }
.header__back:hover { background: var(--surface-2); color: var(--text-strong); }

.header__brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}
.header__icon { font-size: 1.4rem; line-height: 1; }
.header__title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-strong);
  letter-spacing: -0.01em;
}

.btn--icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-body);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.btn--icon svg { width: 18px; height: 18px; }
.btn--icon:hover { background: var(--surface-2); color: var(--accent); }
.btn--icon.active { background: var(--accent-glow); color: var(--accent); }

/* ── Zone Tabs ── */
.zone-tabs {
  position: sticky;
  top: var(--header-h);
  z-index: 90;
  display: flex;
  background: rgba(30, 22, 18, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.zone-tabs::-webkit-scrollbar { display: none; }

.zone-tab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  min-width: 80px;
  padding: 0 0.75rem;
  height: var(--tab-h);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
  white-space: nowrap;
  justify-content: center;
}
.zone-tab__icon { font-size: 1.1rem; }
.zone-tab:hover { color: var(--text-body); }
.zone-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.zone-tab--lista .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-2);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 4px;
  margin-left: 2px;
}

/* ── Main ── */
.main {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ── Toolbar ── */
.toolbar {
  position: sticky;
  top: calc(var(--header-h) + var(--tab-h));
  z-index: 80;
  background: rgba(30, 22, 18, 0.97);
  padding: 0.75rem 0 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.search-wrap {
  position: relative;
  width: 100%;
}
.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 0.55rem 0.75rem 0.55rem 2.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-strong);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color var(--transition), background var(--transition);
  outline: none;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--accent); background: var(--surface-2); }

.toolbar__filters {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.toolbar__filters::-webkit-scrollbar { display: none; }

.filter-chip {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.filter-chip:hover { background: var(--surface-2); color: var(--text-body); }
.filter-chip.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Panels ── */
.panels { position: relative; }
.panel { display: none; }
.panel.active { display: block; }

/* ── Category sections ── */
.category-section {
  margin-bottom: 1.5rem;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.category-header__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.category-header__name {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-body);
  flex: 1;
}
.category-header__count {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.category-header__chevron {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  transition: transform var(--transition);
  flex-shrink: 0;
}
.category-section.collapsed .category-header__chevron {
  transform: rotate(-90deg);
}
.category-section.collapsed .product-grid { display: none; }

/* ── Product Grid ── */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.625rem;
}

/* ── Product Card ── */
.product-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.875rem 0.75rem 0.75rem;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.product-card:hover {
  background: var(--surface-2);
  border-color: var(--border-2);
  transform: translateY(-1px);
}
.product-card:active { transform: translateY(0); }

.product-card--missing {
  opacity: 0.55;
  border-style: dashed;
}
.product-card--low { border-color: rgba(247,127,0,0.35); }
.product-card--expiring { border-color: rgba(230,57,70,0.45); }

.product-card__status {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.75rem;
  line-height: 1;
}
.product-card__emoji {
  font-size: 1.5rem;
  line-height: 1.2;
  display: block;
}
.product-card__name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-strong);
  line-height: 1.3;
  word-break: break-word;
}
.product-card--missing .product-card__name {
  color: var(--text-muted);
}
.product-card__qty {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.product-card__expiry {
  font-size: 0.68rem;
  color: var(--accent);
  margin-top: 2px;
}
.product-card__expiry--danger { color: var(--accent-red); font-weight: 600; }
.product-card__expiry--warn  { color: var(--accent-orange); font-weight: 600; }

/* Quick-add button on card (for missing products) */
.product-card__quick-add {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  padding: 0;
}
.product-card__quick-add:hover { background: var(--accent); color: var(--bg); }

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 3rem 1rem;
  color: var(--text-muted);
  text-align: center;
}
.empty-state__icon { font-size: 3rem; }

/* ── Lista de la compra ── */
.lista-toolbar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.shopping-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.shopping-list__empty {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 1rem;
  font-size: 0.875rem;
}

.shopping-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background var(--transition), opacity var(--transition);
}
.shopping-item:hover { background: var(--surface-2); }

.shopping-item__check {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-2);
  border-radius: 6px;
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
  transition: background var(--transition), border-color var(--transition);
}
.shopping-item__check:checked {
  background: var(--accent-green);
  border-color: var(--accent-green);
}
.shopping-item__check:checked::after {
  content: '';
  position: absolute;
  inset: 3px;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 6l3 3 5-5' stroke='white' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
  background-color: transparent;
}
.shopping-item__check:checked + .shopping-item__text {
  text-decoration: line-through;
  color: var(--text-muted);
}

.shopping-item__text {
  flex: 1;
  font-size: 0.875rem;
  color: var(--text-strong);
  line-height: 1.3;
}
.shopping-item__qty {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.shopping-item__delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 0.9rem;
  line-height: 1;
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
}
.shopping-item__delete:hover { color: var(--accent-red); background: rgba(230,57,70,0.1); }

.shopping-item--checked {
  opacity: 0.5;
}

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(244,162,97,0.4), 0 2px 8px rgba(0,0,0,0.3);
  transition: transform 200ms cubic-bezier(.34,1.56,.64,1), box-shadow var(--transition);
  z-index: 200;
}
.fab svg { width: 24px; height: 24px; }
.fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(244,162,97,0.5), 0 3px 12px rgba(0,0,0,0.35);
}
.fab:active { transform: scale(0.95); }

/* Shopping mode: FAB becomes add-to-list */
.fab.shopping { background: linear-gradient(135deg, #52b788, #2d6a4f); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: overlay-in 200ms ease forwards;
}
.modal-overlay[hidden] { display: none !important; }

@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
  animation: modal-up 280ms cubic-bezier(.34,1.3,.64,1) forwards;
}
.modal--sm { max-width: 420px; }

@keyframes modal-up {
  from { transform: translateY(60px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

@media (min-width: 600px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius-lg); }
}

.modal__header {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
  position: sticky;
  top: 0;
  background: var(--bg-3);
  z-index: 2;
}
.modal__title {
  flex: 1;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-strong);
}
.modal__close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  line-height: 0;
  transition: color var(--transition), background var(--transition);
}
.modal__close:hover { color: var(--text-strong); background: var(--surface); }
.modal__close svg { width: 18px; height: 18px; }

.modal__body {
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.modal__footer {
  display: flex;
  align-items: center;
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--border);
  gap: 0.5rem;
  position: sticky;
  bottom: 0;
  background: var(--bg-3);
}
.modal__footer-right {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

/* ── Form Fields ── */
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.field__label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.field__input {
  padding: 0.55rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-strong);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color var(--transition), background var(--transition);
  outline: none;
  width: 100%;
}
.field__input:focus { border-color: var(--accent); background: var(--surface-2); }
.field__input::placeholder { color: var(--text-muted); }

.field__select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23c9a98b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 12px;
  padding-right: 2rem;
  cursor: pointer;
}

/* color the option backgrounds in dark selects */
.field__select option { background: var(--bg-3); }

/* ── Qty stepper ── */
.qty-wrap {
  display: flex;
  align-items: center;
  gap: 0;
}
.qty-btn {
  width: 32px;
  height: 36px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-body);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.qty-btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); border-right: none; }
.qty-btn:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-left: none; }
.qty-btn:hover { background: var(--accent-glow); color: var(--accent); }
.qty-input { text-align: center; border-radius: 0 !important; border-left: none; border-right: none; width: 60px; }
.qty-input::-webkit-inner-spin-button,
.qty-input::-webkit-outer-spin-button { appearance: none; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform 100ms;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn--primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--bg);
  border-color: transparent;
}
.btn--primary:hover { filter: brightness(1.08); }

.btn--outline {
  background: transparent;
  border-color: var(--border-2);
  color: var(--text-body);
}
.btn--outline:hover { background: var(--surface); color: var(--text-strong); }

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn--ghost:hover { color: var(--text-body); background: var(--surface); }

.btn--danger {
  background: transparent;
  border-color: rgba(230,57,70,0.3);
  color: var(--accent-red);
}
.btn--danger:hover { background: rgba(230,57,70,0.1); }

.btn--sm { padding: 0.35rem 0.75rem; font-size: 0.78rem; }

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: calc(var(--fab-size) + 2rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  pointer-events: none;
}

.toast {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: 100px;
  color: var(--text-strong);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.5rem 1.1rem;
  white-space: nowrap;
  animation: toast-in 220ms ease forwards;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.toast--ok      { border-color: rgba(82,183,136,0.5); }
.toast--warn    { border-color: rgba(244,162,97,0.5); }
.toast--error   { border-color: rgba(230,57,70,0.5);  }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-6px); }
}

/* ── Shopping mode strip ── */
.shopping-mode-banner {
  background: rgba(82,183,136,0.12);
  border-bottom: 1px solid rgba(82,183,136,0.3);
  color: var(--accent-green);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  padding: 0.4rem;
  letter-spacing: 0.04em;
}

/* ── Expiry indicator bar ── */
.product-card__expiry-bar {
  height: 2px;
  border-radius: 1px;
  margin-top: 4px;
  background: var(--surface-2);
  overflow: hidden;
}
.product-card__expiry-bar-fill {
  height: 100%;
  border-radius: 1px;
  transition: width 600ms ease;
}

/* ── Stats bar ── */
.stats-bar {
  display: flex;
  gap: 1rem;
  padding: 0.6rem 0;
  margin-bottom: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.stats-bar::-webkit-scrollbar { display: none; }

.stat-pill {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 0.3rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.stat-pill__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .field-row { grid-template-columns: 1fr; }
}

@media (min-width: 768px) {
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
