/* ═══════════════════════════════════════════
   RESPONSIVE — Mobile First
   Breakpoints: 480 / 768 / 1024 / 1280
═══════════════════════════════════════════ */

/* ══════════════════════════════════════════
   MOBILE BASE (< 480px)
══════════════════════════════════════════ */
@media (max-width: 479px) {
  :root {
    --font-size-2xl: 1.375rem;
    --font-size-xl:  1.125rem;
  }

  .view { padding: 12px; }

  /* Quick-add más compacto */
  .quick-add__input { height: 46px; font-size: 15px; }
  .quick-add__btn   { width: 46px; height: 46px; }

  /* KPI grid 2 columnas compactas */
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi-card { padding: 12px; }
  .kpi-card__value { font-size: 1.1rem; }

  /* Frequent grid 2 col */
  .frequent-grid { grid-template-columns: repeat(2, 1fr); }

  /* Categories grid 3 col */
  .categories-grid { grid-template-columns: repeat(3, 1fr); }

  /* Form en una columna */
  .form-row { grid-template-columns: 1fr; gap: 12px; }

  /* List header compacto */
  .list-header__actions .btn--sm { padding: 5px 8px; font-size: 11px; }

  /* AI banner compacto */
  .ai-banner { padding: 10px 12px; }
  .ai-banner__text { font-size: 12px; }

  /* History card compact */
  .history-card { gap: 10px; padding: 12px; }
  .history-card__date-block { width: 40px; height: 46px; }
  .history-card__day { font-size: 18px; }
}

/* ══════════════════════════════════════════
   MOBILE MEDIUM (480–767px)
══════════════════════════════════════════ */
@media (min-width: 480px) and (max-width: 767px) {
  .frequent-grid    { grid-template-columns: repeat(3, 1fr); }
  .categories-grid  { grid-template-columns: repeat(4, 1fr); }
  .kpi-grid         { grid-template-columns: repeat(2, 1fr); }
}

/* ══════════════════════════════════════════
   TABLET / DESKTOP (≥768px)
   Layout principal definido en layout.css
══════════════════════════════════════════ */
@media (min-width: 768px) {
  /* Filters: en desktop no necesita scroll, mostrar todos los chips */
  .filters { flex-wrap: wrap; overflow-x: visible; }

  /* KPI full row */
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }

  /* Frequent más grande */
  .frequent-grid    { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .categories-grid  { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

  /* Items: botones de acción siempre visibles (sobreescrito por hover media) */
  /* ya gestionado con @media (hover:hover) en components.css */

  /* Topbar menu button oculto */
  .topbar__menu { display: none; }

  /* View header sin wrapping */
  .view__header { flex-wrap: nowrap; }

  /* Settings buttons en fila */
  .setting-btn { width: auto; display: inline-flex; }
}

/* ══════════════════════════════════════════
   LARGE DESKTOP (≥1024px)
══════════════════════════════════════════ */
@media (min-width: 1024px) {
  .frequent-grid   { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .categories-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .kpi-grid        { gap: var(--space-md); }
  .kpi-card__value { font-size: 1.4rem; }
}

/* ══════════════════════════════════════════
   LANDSCAPE MÓVIL
══════════════════════════════════════════ */
@media (max-height: 500px) and (orientation: landscape) and (max-width: 900px) {
  :root { --bottom-nav-height: 52px; }
  .bottom-nav { height: calc(52px + env(safe-area-inset-bottom, 0px)); }
  .view-container { padding-bottom: calc(52px + env(safe-area-inset-bottom, 0px) + 60px); }
  .fab { bottom: calc(52px + env(safe-area-inset-bottom, 0px) + 8px); }
}

/* ══════════════════════════════════════════
   ACCESIBILIDAD — Sin animaciones
══════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration:   0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration:  0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ══════════════════════════════════════════
   IMPRESIÓN
══════════════════════════════════════════ */
@media print {
  .sidebar, .bottom-nav, .topbar,
  .fab, .total-bar, .ai-banner,
  .filters-wrap, .quick-add { display: none !important; }
  .main       { margin: 0 !important; }
  .view       { display: block !important; padding: 0 !important; }
  body        { background: white; color: black; overflow: visible; }
  .list-item  { break-inside: avoid; border: 1px solid #ccc; }
}

/* ══════════════════════════════════════════
   SUPERMARKET PANELS — Responsive
══════════════════════════════════════════ */

/* 320px: compare price font smaller */
@media (max-width: 380px) {
  .compare-card__price { font-size: 20px; }
  .compare-panel__body { gap: 8px; }
  .compare-card { padding: 10px 8px; }
  .merca-panel__logo-img { height: 22px; }
}

/* Desktop: cap panel width + center overlay */
@media (min-width: 768px) {
  .merca-overlay {
    justify-content: center;
    align-items: center;
  }
  .merca-panel {
    max-width: 600px;
    margin: auto;
    border-radius: 16px;
    transform: translateY(0) scale(0.95);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
  }
  .merca-overlay.visible .merca-panel {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* Dark mode — compare panel */
[data-theme="dark"] .compare-panel {
  background: var(--bg-surface);
  border-color: var(--border);
}
[data-theme="dark"] .compare-card {
  background: var(--bg-secondary);
  border-color: var(--border);
}
[data-theme="dark"] .compare-panel__skip {
  color: var(--text-secondary);
}
