/* ==========================================================================
   Sistema de Filtros — Dropdowns + Bottom Sheet, Mobile First
   Diseño moderno tipo e-commerce: chips activos sólidos, sheet con footer
   ========================================================================== */

/* ── Tokens locales ─────────────────────────────────────────────────────── */
:root {
  --fdd-navbar-h: var(--navbar-h);
  --fdd-radius-pill: 100px;
  --fdd-radius-panel: 14px;
  --fdd-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.07);
  --fdd-shadow-md: 0 8px 28px rgba(0, 0, 0, 0.11), 0 2px 8px rgba(0, 0, 0, 0.06);
  --fdd-shadow-stuck: 0 4px 20px rgba(0, 0, 0, 0.12);
  --fdd-primary-sub: rgba(var(--primary-rgb), 0.09);
  --fdd-primary-mid: rgba(var(--primary-rgb), 0.16);
  --fdd-ease-spring: cubic-bezier(0.34, 1.2, 0.64, 1);
  --fdd-ease-out: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ═══════════════════════════════════════════════════════════════════════════
   BARRA DE FILTROS
   ═══════════════════════════════════════════════════════════════════════════ */

.filter-bar {
  position: sticky;
  top: var(--fdd-navbar-h);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--color-surface);
  border-radius: var(--fdd-radius-panel);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--fdd-shadow-sm);
  transition:
    box-shadow 0.2s ease,
    border-color 0.2s ease;
}

.filter-bar.is-stuck {
  box-shadow: var(--fdd-shadow-stuck);
  border-color: rgba(0, 0, 0, 0.05);
}

/* Etiqueta "Filtrar" */
.filter-bar-label {
  display: none;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  flex-shrink: 0;
  user-select: none;
  white-space: nowrap;
  padding-right: 0.375rem;
  border-right: 1px solid rgba(0, 0, 0, 0.1);
}

/* ── Scroll con fade lateral ────────────────────────────────────────────── */
.filter-bar-scroll-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.filter-bar-scroll-wrap::after,
.filter-bar-scroll-wrap::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 32px;
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.2s ease;
}
.filter-bar-scroll-wrap::after {
  right: 0;
  background: linear-gradient(to right, transparent, var(--color-surface));
}
.filter-bar-scroll-wrap::before {
  left: 0;
  background: linear-gradient(to left, transparent, var(--color-surface));
  opacity: 0;
}

.filter-bar-scroll-wrap.scroll-end::after {
  opacity: 0;
}
.filter-bar-scroll-wrap.scroll-middle::before {
  opacity: 1;
}
.filter-bar-scroll-wrap.scroll-start::before {
  opacity: 0;
}

/* ── Zona scrollable ────────────────────────────────────────────────────── */
.filter-bar-scroll {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  padding: 3px 4px;
}
.filter-bar-scroll::-webkit-scrollbar {
  display: none;
}

/* ── Acciones ───────────────────────────────────────────────────────────── */
.filter-bar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.filter-count {
  display: none;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  padding: 0.2rem 0.65rem;
  background: rgba(0, 0, 0, 0.04);
  border-radius: var(--fdd-radius-pill);
}

.filter-clear-all {
  display: inline-flex;
  align-items: center;
  gap: 0.275rem;
  padding: 0.3rem 0.8rem;
  font-size: 0.775rem;
  font-weight: 600;
  line-height: 1;
  color: var(--color-danger);
  background: rgba(var(--color-danger-rgb), 0.07);
  border: 1.5px solid rgba(var(--color-danger-rgb), 0.25);
  border-radius: var(--fdd-radius-pill);
  cursor: pointer;
  white-space: nowrap;
  min-height: 34px;
  touch-action: manipulation;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease;
}
.filter-clear-all:hover,
.filter-clear-all:focus-visible {
  background: rgba(var(--color-danger-rgb), 0.14);
  border-color: rgba(var(--color-danger-rgb), 0.5);
  outline: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   CHIP — BOTÓN TOGGLE (desktop y mobile)
   ═══════════════════════════════════════════════════════════════════════════ */

.fdd {
  position: relative;
  flex-shrink: 0;
  scroll-snap-align: start;
}

/* Estado base */
.fdd__toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0 0.9rem;
  height: 44px;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-main);
  background: transparent;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--fdd-radius-pill);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition:
    border-color 0.15s ease,
    background 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease;
}

/* Hover */
.fdd__toggle:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
  box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.12);
}

/* Focus teclado */
.fdd__toggle:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 3px;
}

/* Press */
.fdd__toggle:active {
  transform: scale(0.97);
}

/* Estado activo (filtro seleccionado) */
.fdd__toggle--active {
  background: rgba(var(--primary-rgb), 0.08);
  border-color: var(--primary-color);
  color: var(--primary-color);
  font-weight: 600;
}

/* Abierto (dropdown visible) */
.fdd--open .fdd__toggle:not(.fdd__toggle--active) {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

/* Flecha */
.fdd__arrow {
  font-size: 0.625rem;
  flex-shrink: 0;
  transition: transform 0.22s var(--fdd-ease-spring);
}
.fdd--open .fdd__arrow {
  transform: rotate(180deg);
}

/* Badge de conteo */
.fdd__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  font-size: 0.625rem;
  font-weight: 700;
  background: var(--primary-color);
  color: white;
  border-radius: var(--fdd-radius-pill);
  line-height: 1;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   DROPDOWN (desktop)
   ═══════════════════════════════════════════════════════════════════════════ */

.fdd__menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 200px;
  z-index: 1050;
  background: var(--color-dropdown);
  border: 1px solid var(--border-subtle);
  border-radius: var(--fdd-radius-panel);
  box-shadow: var(--fdd-shadow-md);
  overflow: hidden;
  transform-origin: top left;
}
.fdd--open .fdd__menu {
  display: block;
  animation: ddReveal 0.18s ease both;
}

@keyframes ddReveal {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Lista */
.fdd__list {
  list-style: none;
  margin: 0;
  padding: 0.4rem 0;
  max-height: 240px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}
.fdd__list::-webkit-scrollbar {
  width: 4px;
}
.fdd__list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 2px;
}

/* Opción */
.fdd__item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0 1rem;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  min-height: 44px;
  user-select: none;
  transition:
    background 0.1s ease,
    color 0.1s ease;
}
.fdd__item:hover {
  background: var(--fdd-primary-sub);
  color: var(--primary-color);
}

/* Item seleccionado */
.fdd__item--selected {
  color: var(--primary-color);
  font-weight: 600;
}
.fdd__item--selected:hover {
  background: rgba(var(--primary-rgb), 0.07);
}

/* ── Checkbox visual ──────────────────────────────────────────────────────── */
.fdd__check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border: 1.5px solid var(--color-checkbox-border);
  border-radius: 5px;
  background: var(--color-surface);
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.12s ease;
}

.fdd__item--selected .fdd__check,
.fdd-sheet__item--selected .fdd__check {
  background: var(--primary-color);
  border-color: var(--primary-color);
  transform: scale(1.05);
}

.fdd__item--selected .fdd__check::after,
.fdd-sheet__item--selected .fdd__check::after {
  content: "";
  display: block;
  width: 10px;
  height: 5px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translate(0, -1px);
}

/* ═══════════════════════════════════════════════════════════════════════════
   BACKDROP (mobile)
   ═══════════════════════════════════════════════════════════════════════════ */

.fdd-backdrop {
  position: fixed;
  inset: 0;
  background: transparent;
  z-index: 1040;
  pointer-events: none;
  transition: background 0.28s var(--fdd-ease-out);
}
.fdd-backdrop--visible {
  background: rgba(0, 0, 0, 0.5);
  pointer-events: all;
}

/* ═══════════════════════════════════════════════════════════════════════════
   BOTTOM SHEET (mobile)
   ═══════════════════════════════════════════════════════════════════════════ */

.fdd-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1045;
  background: var(--color-surface);
  border-radius: 20px 20px 0 0;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.32s var(--fdd-ease-out);
  box-shadow: 0 -6px 40px rgba(0, 0, 0, 0.18);
  will-change: transform;
}
.fdd-sheet--open {
  transform: translateY(0);
}

/* Handle de arrastre */
.fdd-sheet__handle {
  width: 44px;
  height: 5px;
  background: rgba(0, 0, 0, 0.12);
  border-radius: var(--fdd-radius-pill);
  margin: 10px auto 8px;
  flex-shrink: 0;
  cursor: grab;
}

/* Header */
.fdd-sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.25rem 0.75rem;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}

.fdd-sheet__header-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.fdd-sheet__title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.fdd-sheet__subtitle {
  font-size: 0.775rem;
  font-weight: 500;
  color: var(--primary-color);
  min-height: 1em;
}

.fdd-sheet__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-main);
  touch-action: manipulation;
  transition: background 0.15s ease;
}
.fdd-sheet__close:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* Lista de opciones */
.fdd-sheet__list {
  list-style: none;
  margin: 0;
  padding: 0.375rem 0;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

/* Opción del sheet */
.fdd-sheet__item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  min-height: 56px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
  transition: background 0.1s ease;
}
.fdd-sheet__item:last-child {
  border-bottom: none;
}
.fdd-sheet__item:active {
  background: var(--fdd-primary-sub);
}

/* ★ Item seleccionado en sheet con fondo persistente */
.fdd-sheet__item--selected {
  background: var(--fdd-primary-sub);
  color: var(--primary-color);
  font-weight: 600;
}
.fdd-sheet__item--selected:active {
  background: var(--fdd-primary-mid);
}

/* ── Footer del sheet ────────────────────────────────────────────────────── */
.fdd-sheet__footer {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 0.625rem;
  padding: 0.875rem 1.25rem;
  padding-bottom: calc(0.875rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
  background: var(--color-surface);
}

.fdd-sheet__clear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 1rem;
  height: 48px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 1.5px solid rgba(0, 0, 0, 0.15);
  border-radius: var(--fdd-radius-pill);
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background 0.15s ease,
    color 0.15s ease,
    border-color 0.15s ease;
  white-space: nowrap;
}
.fdd-sheet__clear-btn:hover,
.fdd-sheet__clear-btn:active {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.25);
  color: var(--text-main);
}
.fdd-sheet__clear-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.fdd-sheet__apply-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 1.25rem;
  height: 48px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  background: var(--primary-color);
  border: none;
  border-radius: var(--fdd-radius-pill);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 4px 14px rgba(var(--primary-rgb), 0.35);
  transition:
    opacity 0.15s ease,
    box-shadow 0.15s ease;
  white-space: nowrap;
}
.fdd-sheet__apply-btn:hover,
.fdd-sheet__apply-btn:active {
  opacity: 0.9;
  box-shadow: 0 4px 18px rgba(var(--primary-rgb), 0.45);
}

/* ═══════════════════════════════════════════════════════════════════════════
   UTILIDADES
   ═══════════════════════════════════════════════════════════════════════════ */

/* Scroll lock del body (gestionado por JS) */

/* Sentinel del sticky (IntersectionObserver) */
.filter-sentinel {
  height: 1px;
  margin-top: -1px;
  visibility: hidden;
  pointer-events: none;
}

/* Animación de tarjetas al filtrar */
@keyframes cardReveal {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.products-grid .col {
  animation: cardReveal 0.28s ease both;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TABLET (≥ 576px)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (min-width: 576px) {
  .filter-bar {
    padding: 0.5rem 1rem;
  }

  .filter-bar-label {
    display: inline-flex;
  }

  .filter-bar-scroll {
    overflow-x: visible;
    flex-wrap: wrap;
    scroll-snap-type: none;
    row-gap: 0.375rem;
    padding: 2px;
  }

  .filter-bar-scroll-wrap::after,
  .filter-bar-scroll-wrap::before {
    display: none;
  }

  .filter-count {
    display: inline-flex;
    align-items: center;
  }

  .fdd__toggle {
    height: 36px;
    padding: 0 0.875rem;
    font-size: 0.8rem;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   DESKTOP (≥ 1280px)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (min-width: 1280px) {
  .filter-bar {
    padding: 0.625rem 1.25rem;
  }
}


/* Responsive: filter bar touch targets */
@media (min-width: 576px) and (max-width: 1279px) {
  .fdd__toggle {
    height: 44px !important;
    padding: 0 1rem !important;
    font-size: 0.875rem !important;
  }

  .filter-bar {
    padding: 0.625rem 1rem !important;
    gap: 0.625rem !important;
    margin-bottom: 1.25rem !important;
  }

  .filter-bar-scroll {
    gap: 0.5rem !important;
    row-gap: 0.5rem !important;
  }

  .filter-clear-all {
    min-height: 40px !important;
    padding: 0.4rem 0.9rem !important;
  }
}

/* ==========================================================================
   Dark Mode — Sistema de Filtros
   filter-bar, fdd__menu, fdd__check, fdd-sheet y fdd-sheet__footer usan
   --color-surface, --color-dropdown y --border-* que se adaptan automáticamente.
   Solo quedan aquí overrides para sombras, scrollbars y efectos específicos.
   ========================================================================== */

/* Tokens locales del filtro para modo oscuro */
[data-theme="dark"] {
  --fdd-shadow-sm:    0 2px 8px rgba(0, 0, 0, 0.35);
  --fdd-shadow-md:    0 8px 28px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.25);
  --fdd-shadow-stuck: 0 4px 20px rgba(0, 0, 0, 0.45);
  --fdd-primary-sub:  rgba(var(--primary-rgb), 0.10);
  --fdd-primary-mid:  rgba(var(--primary-rgb), 0.18);
}

/* ── Barra de filtros — bg+border auto via variables ────────────────────── */
[data-theme="dark"] .filter-bar-label {
  border-right-color: var(--border-component);
}

[data-theme="dark"] .filter-count {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

/* ── Botón limpiar filtros — color+bg+border auto via --color-danger-rgb ── */

/* ── Chip toggle — border+color auto via --border-strong + --text-main ─── */
[data-theme="dark"] .fdd__toggle:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
  box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.20);
}

[data-theme="dark"] .fdd__toggle--active {
  background: rgba(var(--primary-rgb), 0.12);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

[data-theme="dark"] .fdd--open .fdd__toggle:not(.fdd__toggle--active) {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

/* ── Dropdown desktop — sombra + scrollbar (bg+border auto via variables) ── */
[data-theme="dark"] .fdd__menu {
  box-shadow: var(--fdd-shadow-md);
}

[data-theme="dark"] .fdd__list {
  scrollbar-color: rgba(255, 255, 255, 0.20) transparent;
}

[data-theme="dark"] .fdd__list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.20);
}

[data-theme="dark"] .fdd__item:hover {
  background: var(--fdd-primary-sub);
  color: var(--primary-color);
}

[data-theme="dark"] .fdd__item--selected {
  color: var(--primary-color);
}

[data-theme="dark"] .fdd__item--selected:hover {
  background: rgba(var(--primary-rgb), 0.08);
}

/* ── Bottom sheet — sombra específica (bg auto via --color-surface) ──────── */
[data-theme="dark"] .fdd-sheet {
  box-shadow: 0 -6px 40px rgba(0, 0, 0, 0.55);
}

[data-theme="dark"] .fdd-sheet__handle {
  background: rgba(255, 255, 255, 0.18);
}

[data-theme="dark"] .fdd-sheet__close {
  background: rgba(255, 255, 255, 0.10);
  color: var(--text-main);
}

[data-theme="dark"] .fdd-sheet__close:hover {
  background: rgba(255, 255, 255, 0.16);
}

[data-theme="dark"] .fdd-sheet__item {
  border-bottom-color: var(--border-subtle);
}

[data-theme="dark"] .fdd-sheet__item:active {
  background: var(--fdd-primary-sub);
}

[data-theme="dark"] .fdd-sheet__item--selected {
  background: var(--fdd-primary-sub);
  color: var(--primary-color);
}

[data-theme="dark"] .fdd-sheet__item--selected:active {
  background: var(--fdd-primary-mid);
}

/* ── Footer del sheet — border auto via variables (bg auto via --color-surface) */
[data-theme="dark"] .fdd-sheet__clear-btn {
  color: var(--text-muted);
  border-color: var(--border-component);
}

[data-theme="dark"] .fdd-sheet__clear-btn:hover,
[data-theme="dark"] .fdd-sheet__clear-btn:active {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--border-strong);
  color: var(--text-main);
}

/* El botón aplicar ya usa --primary-color y color: #fff ✓ */
