/**
 * Angal Filter Panel - estilos
 * Medidas tomadas del panel "Filtrar y ordenar" de referencia; la tipografía
 * se hereda del tema para respetar la identidad de la tienda.
 * Variables configurables desde el módulo: --afp-accent, --afp-width.
 */
:root {
  --afp-accent: #141617;
  --afp-accent-contrast: #ffffff;
  --afp-text: #141617;
  --afp-muted: #878b8f;
  --afp-border: #ebebeb;
  --afp-radio-border: #c3c5c7;
  --afp-hover: #e7e8e9;
  --afp-button-bg: #f7f7f7;
  --afp-bg: #ffffff;
  --afp-overlay: rgba(20, 22, 23, 0.5);
  --afp-width: 500px;
  --afp-radius: 16px;
  --afp-speed: 0.25s;
  --afp-z: 1060;
}

/* ---------- Integración con Warehouse: ocultamos los filtros del tema ---------- */
.afp-enabled #facets_search_wrapper,
.afp-enabled #facets_search_center,
.afp-enabled #facets_search_center_dropdown,
.afp-enabled #search_filter_toggler,
.afp-enabled #search_center_filter_toggler,
.afp-enabled #js-product-list-top .facated-toggler {
  display: none !important;
}

html.afp-lock,
html.afp-lock body {
  overflow: hidden !important;
}

/* ---------- Botón "Filtrar y ordenar" ---------- */
.afp-toolbar {
  display: flex;
  align-items: center;
}

.afp-toolbar--fallback {
  margin: 0 0 16px;
}

.afp-open-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--afp-button-bg);
  color: var(--afp-text);
  font: inherit;
  font-size: 14px;
  line-height: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.2s, border-color 0.2s;
}

.afp-open-btn:hover {
  background: var(--afp-hover);
}

.afp-open-btn:focus-visible {
  outline: 2px solid var(--afp-accent);
  outline-offset: 2px;
}

.afp-open-label--short { display: none; }

.afp-open-count:empty { display: none; }

.afp-icon { flex: none; }

@media (max-width: 575.98px) {
  .afp-open-label--short { display: inline; }
  .afp-open-label--long { display: none; }
}

/* ---------- Overlay ---------- */
.afp-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--afp-z);
  background: var(--afp-overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--afp-speed) ease-out, visibility 0s linear var(--afp-speed);
}

.afp-overlay.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--afp-speed) ease-out, visibility 0s;
}

/* ---------- Panel ---------- */
.afp-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  z-index: calc(var(--afp-z) + 1);
  display: flex;
  flex-direction: column;
  width: min(var(--afp-width), 100vw);
  max-width: 100vw;
  height: 100%;
  height: 100dvh;
  background: var(--afp-bg);
  color: var(--afp-text);
  border-radius: var(--afp-radius) 0 0 var(--afp-radius);
  box-shadow: none;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform var(--afp-speed) ease-out, visibility 0s linear var(--afp-speed);
  outline: none;
}

.afp-panel--left {
  right: auto;
  left: 0;
  border-radius: 0 var(--afp-radius) var(--afp-radius) 0;
  transform: translateX(-100%);
}

.afp-panel.is-open {
  transform: translateX(0);
  visibility: visible;
  transition: transform var(--afp-speed) ease-out, visibility 0s;
}

@media (max-width: 575.98px) {
  .afp-panel,
  .afp-panel--left {
    width: 100vw;
    border-radius: 0;
  }
}

.afp-header {
  position: relative;
  display: flex;
  align-items: center;
  flex: none;
  min-height: 59px;
  padding: 12px 64px 12px 24px;
  border-bottom: 1px solid var(--afp-border);
}

.afp-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
}

.afp-close {
  position: absolute;
  top: 50%;
  right: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-top: -16px;
  padding: 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--afp-text);
  cursor: pointer;
  transition: background-color 0.2s;
}

.afp-close:hover { background: var(--afp-hover); }

.afp-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 7px 12px 16px;
  transition: opacity 0.2s;
}

.afp-panel.is-loading .afp-body {
  opacity: 0.6;
  pointer-events: none;
}

/* Reseteo de estilos del tema sobre #search_filters */
.afp-panel #search_filters {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
}

/* ---------- Acordeones ---------- */
.afp-acc {
  display: block;
  margin: 0 0 10px;
  padding: 0;
  border: 0;
}

.afp-acc[hidden] { display: none; }

.afp-acc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 36px;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--afp-text);
  font: inherit;
  font-size: 14px;
  line-height: 20px;
  text-align: left;
  cursor: pointer;
}

.afp-acc-head:focus-visible {
  outline: 2px solid var(--afp-accent);
  outline-offset: -2px;
}

.afp-acc-heading {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.afp-acc-title {
  flex: none;
  font-size: 16px;
  font-weight: 600;
  line-height: 20px;
  text-transform: lowercase;
}

.afp-acc-title::first-letter { text-transform: uppercase; }

.afp-acc-selected {
  min-width: 0;
  overflow: hidden;
  color: var(--afp-muted);
  font-size: 14px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.afp-acc-selected:empty,
.afp-acc-values:empty { display: none; }

/* Icono + / - */
.afp-acc-icon {
  position: relative;
  flex: none;
  width: 16px;
  height: 16px;
}

.afp-acc-icon::before,
.afp-acc-icon::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  right: 2px;
  height: 1.5px;
  margin-top: -0.75px;
  border-radius: 1px;
  background: currentColor;
  transition: transform 0.3s ease-out;
}

.afp-acc-icon::after { transform: rotate(90deg); }

.afp-acc.is-open .afp-acc-icon::after { transform: rotate(0deg); }

/* Contenido desplegable con altura animada */
.afp-acc-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s ease-out;
}

.afp-acc.is-open > .afp-acc-body { grid-template-rows: 1fr; }

.afp-acc-inner {
  min-height: 0;
  overflow: hidden;
  visibility: hidden;
  transition: visibility 0s linear 0.3s;
}

.afp-acc.is-open > .afp-acc-body > .afp-acc-inner {
  visibility: visible;
  transition: visibility 0s;
}

.afp-no-anim .afp-acc-body,
.afp-no-anim .afp-acc-inner,
.afp-no-anim .afp-acc-icon::after {
  transition: none !important;
}

/* ---------- Chips (tallas, marcas, categorías, características...) ---------- */
.afp-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 25px 12px 12px;
}

.afp-panel .afp-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 45px;
  margin: 0;
  padding: 12px 10px;
  border: 1px solid var(--afp-border);
  border-radius: 24px;
  background: var(--afp-bg);
  color: #000;
  font-size: 12px;
  line-height: 14px;
  text-decoration: none;
  transition: background-color 0.3s, border-color 0.3s, color 0.3s;
}

.afp-panel .afp-chip:hover {
  background: var(--afp-hover);
  color: #000;
  text-decoration: none;
}

.afp-panel .afp-chip:focus-visible {
  outline: 2px solid var(--afp-accent);
  outline-offset: 2px;
}

.afp-panel .afp-chip.is-active,
.afp-panel .afp-chip.is-active:hover {
  border-color: var(--afp-accent);
  background: var(--afp-accent);
  color: var(--afp-accent-contrast);
}

.afp-chip-qty {
  opacity: 0.6;
}

/* Colores */
.afp-swatch {
  flex: none;
  width: 16px;
  height: 16px;
  margin-right: 4px;
  border: 1px solid var(--afp-text);
  border-radius: 50%;
  background-position: center;
  background-size: cover;
}

.afp-chip.is-active .afp-swatch {
  border-color: var(--afp-accent-contrast);
}

/* ---------- Ordenación (radios) ---------- */
.afp-radios {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 8px 25px 12px 12px;
}

.afp-panel .afp-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--afp-text);
  font-size: 14px;
  line-height: 20px;
  text-decoration: none;
}

.afp-panel .afp-radio:hover {
  color: var(--afp-text);
  text-decoration: none;
}

.afp-panel .afp-radio:focus-visible {
  outline: 2px solid var(--afp-accent);
  outline-offset: 2px;
}

.afp-radio-dot {
  flex: none;
  box-sizing: border-box;
  width: 20px;
  height: 20px;
  padding: 4px;
  border: 1px solid var(--afp-radio-border);
  border-radius: 50%;
  background: var(--afp-bg);
  background-clip: content-box;
  transition: border-color 0.2s, background-color 0.2s;
}

.afp-radio:hover .afp-radio-dot { border-color: var(--afp-text); }

.afp-radio.is-active .afp-radio-dot {
  border-color: var(--afp-accent);
  background-color: var(--afp-accent);
}

/* ---------- Slider de precio (noUiSlider de ps_facetedsearch) ---------- */
.afp-panel .afp-slider {
  margin: 0;
  padding: 8px 25px 16px 12px;
  list-style: none;
}

.afp-panel .afp-slider li {
  margin: 0;
  padding: 0;
  list-style: none;
}

.afp-panel .afp-slider-label {
  margin: 0 0 18px;
  color: var(--afp-text);
  font-size: 14px;
  line-height: 20px;
}

.afp-panel .afp-slider-range {
  margin: 0 10px 8px;
}

.afp-panel .noUi-target {
  height: 2px;
  border: 0;
  border-radius: 2px;
  background: var(--afp-border);
  box-shadow: none;
}

.afp-panel .noUi-connect {
  background: var(--afp-accent);
}

.afp-panel .noUi-horizontal .noUi-handle {
  top: -9px;
  right: -10px;
  width: 20px;
  height: 20px;
  border: 1px solid var(--afp-accent);
  border-radius: 50%;
  background: var(--afp-bg);
  box-shadow: none;
  cursor: grab;
}

.afp-panel .noUi-handle::before,
.afp-panel .noUi-handle::after {
  display: none;
}

.afp-panel .noUi-handle:focus-visible {
  outline: 2px solid var(--afp-accent);
  outline-offset: 2px;
}

/* ---------- Pie ---------- */
.afp-footer {
  display: flex;
  align-items: center;
  flex: none;
  gap: 16px;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--afp-border);
  background: var(--afp-bg);
}

.afp-clear {
  flex: none;
  height: 48px;
  margin: 0 0 0 16px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--afp-muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
  cursor: pointer;
  transition: color 0.3s;
}

.afp-clear:not([disabled]):hover { color: var(--afp-text); }

.afp-clear[disabled] {
  opacity: 0.5;
  cursor: default;
}

.afp-apply {
  position: relative;
  flex: 1 1 auto;
  height: 48px;
  padding: 16px 24px;
  border: 0;
  border-radius: 8px;
  background: var(--afp-accent);
  color: var(--afp-accent-contrast);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 16px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.3s;
}

.afp-apply:hover { opacity: 0.88; }

.afp-apply:focus-visible {
  outline: 2px solid var(--afp-accent);
  outline-offset: 2px;
}

.afp-spinner {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: afp-spin 0.7s linear infinite;
}

.afp-panel.is-loading .afp-apply-text { visibility: hidden; }

.afp-panel.is-loading .afp-spinner { display: block; }

@keyframes afp-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .afp-panel,
  .afp-overlay,
  .afp-acc-body,
  .afp-acc-inner,
  .afp-acc-icon::after {
    transition: none !important;
  }
}
