/**
 * Buscador predictivo/dinámico para Only Vapez (WooCommerce) - Estilos CSS.
 *
 * Adaptado de la referencia de Shopify Dawn (component-predictive-search.css).
 * Reemplaza las variables propietarias de Dawn (--color-foreground, --popup-*, etc.)
 * por variables limpias, neutras y concretas (--ovc-search-*) ajustadas al diseño
 * y tipografía real de onlyvapez.com (fondo blanco, texto #121212, bordes sutiles).
 *
 * Estructura de distribución (Layout):
 * - Columna izquierda (240px): Brands (máx. 5) y Pages (máx. 4).
 * - Zona derecha fluida: Products (hasta 10 en auto-fill grid).
 * - En Mobile (<750px): Apilamiento vertical ordenado: Brands > Products > Pages.
 */

:root {
  --ovc-search-bg: #ffffff;
  --ovc-search-fg: rgb(18, 18, 18);
  --ovc-search-fg-rgb: 18, 18, 18;
  --ovc-search-muted: #666666;
  --ovc-search-border: #e8e8e8;
  --ovc-search-border-subtle: rgba(18, 18, 18, 0.08);
  --ovc-search-hover-bg: rgba(18, 18, 18, 0.04);
  --ovc-search-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  --ovc-search-radius: 6px;
  --ovc-search-link: rgb(18, 18, 18);
  --ovc-search-accent: #1156e8;
  --ovc-search-font-family: 'Assistant', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* =========================================================================
   1. CONTENEDOR PRINCIPAL Y POSICIONAMIENTO
   ========================================================================= */

.ovc-predictive-search-wrapper {
  position: relative;
  display: block;
}

/* Fix (2026-09-23, encontrado y verificado en staging): .site-search tiene un
   transform propio (usado por el toggle de expandir/colapsar la lupa, ya
   existente en el sitio) que crea su propio contexto de apilamiento CSS. Sin
   esto, nuestro z-index:1001 del dropdown queda atrapado DENTRO de ese
   contexto y pierde contra el mega-menu del header (.ovmm-host,
   z-index:998) al compararse un nivel más arriba, en .site-header — el
   mega-menu terminaba tapando los resultados del buscador al pasar el mouse
   por la barra de navegación. Elevar .site-search en sí (no solo el
   dropdown anidado) para que su contexto completo gane esa comparación. */
.site-search {
  z-index: 1002;
}

.predictive-search {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 780px;
  max-width: calc(100vw - 40px);
  border: 1px solid var(--ovc-search-border);
  background-color: var(--ovc-search-bg);
  z-index: 1001; /* Superior al z-index del sticky header de Storefront (999) */
  border-radius: var(--ovc-search-radius);
  box-shadow: var(--ovc-search-shadow);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-family: var(--ovc-search-font-family);
  box-sizing: border-box;
}

.predictive-search * {
  box-sizing: border-box;
}

/* Despliegue condicional por atributos del Web Component */
predictive-search[open] .predictive-search,
predictive-search[loading] .predictive-search {
  display: block;
}

/* Adaptación responsive para pantallas pequeñas */
@media screen and (max-width: 800px) {
  .predictive-search {
    width: calc(100vw - 32px);
    max-width: 480px;
    left: 0;
    top: calc(100% + 6px);
  }
}

/* =========================================================================
   2. DISTRIBUCIÓN EN REJILLA (GRID LAYOUT: BRANDS, PAGES & PRODUCTS)
   ========================================================================= */

/* Base Mobile: Columna vertical con orden de apilamiento explícito */
.predictive-search__results-groups-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border-bottom: 1px solid var(--ovc-search-border-subtle);
  padding-bottom: 0.75rem;
}

.predictive-search__group--brands   { order: 1; }
.predictive-search__group--products { order: 2; }
.predictive-search__group--pages    { order: 3; }

/* Desktop (>= 750px): CSS Grid con áreas nombradas */
@media screen and (min-width: 750px) {
  .predictive-search__results-groups-wrapper {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    grid-template-areas:
      'brands products'
      'pages  products';
    gap: 1rem 1.75rem;
    align-items: start;
    padding: 0.5rem 0;
  }

  /* Asignación de áreas */
  .predictive-search__group--brands   { grid-area: brands; }
  .predictive-search__group--pages    { grid-area: pages; }
  .predictive-search__group--products { grid-area: products; }

  /* Sin productos: la barra lateral ocupa el ancho completo */
  .predictive-search__results-groups-wrapper--no-products {
    grid-template-columns: 1fr;
    grid-template-areas:
      'brands'
      'pages';
  }

  /* Sin marcas ni páginas: los productos ocupan el ancho completo */
  .predictive-search__results-groups-wrapper--no-sidebar {
    grid-template-columns: 1fr;
    grid-template-areas: 'products';
  }

  /* Grilla de productos en la zona derecha */
  .predictive-search__products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    column-gap: 1.25rem;
    row-gap: 0.5rem;
  }
}

/* =========================================================================
   3. ENCABEZADOS Y LISTAS
   ========================================================================= */

.predictive-search__heading {
  border-bottom: 1px solid var(--ovc-search-border-subtle);
  margin: 0 1.25rem;
  padding: 1rem 0 0.5rem;
  color: var(--ovc-search-muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.predictive-search__heading--no-results {
  text-align: center;
  border-bottom: none;
  padding: 2rem 1.25rem;
  font-size: 0.95rem;
  text-transform: none;
  letter-spacing: normal;
  color: var(--ovc-search-fg);
}

.predictive-search__results-list {
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
}

/* =========================================================================
   4. ELEMENTOS Y TARJETAS DE RESULTADO (ITEMS)
   ========================================================================= */

.predictive-search__item {
  display: flex;
  padding: 0.65rem 1.25rem;
  text-align: left;
  text-decoration: none;
  color: var(--ovc-search-fg);
  width: 100%;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.predictive-search__item:hover,
.predictive-search__list-item:hover > *,
.predictive-search__list-item[aria-selected='true'] > *,
.predictive-search__item[aria-selected='true'] {
  color: var(--ovc-search-fg);
  background-color: var(--ovc-search-hover-bg);
}

.predictive-search__list-item[aria-selected='true'] .predictive-search__item-heading,
.predictive-search__list-item:hover .predictive-search__item-heading {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Tarjeta con miniatura (Productos) */
.predictive-search__item--link-with-thumbnail {
  display: grid;
  grid-template-columns: 50px 1fr;
  grid-column-gap: 1rem;
  grid-template-areas: 'product-image product-content';
  overflow: hidden;
  align-items: center;
}

.predictive-search__image {
  grid-area: product-image;
  width: 50px;
  height: 50px;
  object-fit: contain;
  background-color: #f7f7f7;
  border-radius: 4px;
  display: block;
}

.predictive-search__item-content {
  grid-area: product-content;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Para truncamiento o contención de texto */
}

.predictive-search__item-content--centered {
  justify-content: center;
}

.predictive-search__item-vendor {
  font-size: 0.75rem;
  color: var(--ovc-search-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
  line-height: 1.2;
}

.predictive-search__item-heading {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.35;
  color: var(--ovc-search-fg);
}

.predictive-search .price {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ovc-search-fg);
  margin-top: 4px;
}

.predictive-search .price del {
  color: var(--ovc-search-muted);
  font-weight: 400;
  font-size: 0.8rem;
  margin-right: 4px;
}

.predictive-search .price ins {
  text-decoration: none;
  color: #d32f2f; /* Rojo oferta standard */
}

/* =========================================================================
   5. BOTÓN INFERIOR: "SEARCH FOR [TÉRMINO]"
   ========================================================================= */

.predictive-search__search-for-button {
  border-top: 1px solid var(--ovc-search-border-subtle);
  background: #fafafa;
}

.predictive-search__item--term {
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.25rem;
  background: transparent;
  border: none;
  cursor: pointer;
  width: 100%;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ovc-search-link);
}

.predictive-search__item--term .svg-wrapper {
  display: inline-flex;
  align-items: center;
  margin-left: 0.75rem;
  transition: transform 0.2s ease;
}

.predictive-search__item--term:hover .svg-wrapper,
.predictive-search__item--term[aria-selected='true'] .svg-wrapper {
  transform: translateX(4px);
}

.predictive-search__item--term .icon-arrow {
  width: 14px;
  height: 10px;
  fill: currentColor;
}

/* =========================================================================
   6. ESTADOS DE CARGA Y SPINNER
   ========================================================================= */

predictive-search:not([loading]) .predictive-search__loading-state {
  display: none;
}

predictive-search[loading] .predictive-search__loading-state {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
}

predictive-search[loading] .predictive-search__results-groups-wrapper ~ .predictive-search__loading-state {
  display: none;
}

predictive-search[loading] .predictive-search__search-for-button {
  display: none;
}

predictive-search[loading] .predictive-search__results-groups-wrapper ~ .predictive-search__search-for-button {
  display: block;
}

.predictive-search .spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--ovc-search-border);
  border-top-color: var(--ovc-search-fg);
  border-radius: 50%;
  animation: ovc-spinner-rotate 0.65s linear infinite;
}

@keyframes ovc-spinner-rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* =========================================================================
   7. UTILIDADES ACCESIBLES Y SUPRESIÓN DE BADGES EXTERNAS
   ========================================================================= */

.visually-hidden,
.predictive-search .visually-hidden {
  position: absolute !important;
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.list-unstyled {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Supresión de badges de apps externas inyectadas en las tarjetas del popup */
.predictive-search .badge,
.predictive-search .badge-stack-ov,
.predictive-search .badge-item-ov,
.predictive-search [class*='product-badge'],
.predictive-search [class*='ProductBadge'],
.predictive-search [class*='productBadge'],
.predictive-search [class*='new-badge'],
.predictive-search [class*='label-badge'],
.predictive-search__item .card__badge {
  display: none !important;
}
