/* ═══════════════════════════════════════════════════════════════════════
   NPsearch — Smart AJAX Search by Neuroplugin
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Instant hide native search (CSS loads before JS = no flash) ───── */
#search_widget,
.search-widgets:not(:has(.vp-search-widget)),
#ps_searchbar {
  visibility: hidden !important;
  height: 0 !important;
  overflow: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
}
/* Once JS moves our widget before native, native gets display:none.
   Meanwhile CSS hides it visually without removing from flow. */

:root {
  --vps-bg: #f7f7f7;
  --vps-card: #ffffff;
  --vps-text: var(--color-primary, #0f0f0f);
  --vps-muted: #6b7280;
  --vps-accent: var(--color-accent, #c8102e);
  --vps-border: rgba(0, 0, 0, 0.1);
  --vps-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --vps-radius: var(--radius-md, 8px);
  --vps-radius-lg: var(--radius-lg, 12px);
  --vps-radius-pill: 999px;
  --vps-transition: var(--transition-fast, 150ms ease);
}

.vp-search-overlay,
.vp-search-overlay *,
.vp-search-widget,
.vp-search-widget * {
  box-sizing: border-box;
}

/* ── Search widget (header) ─────────────────────────────────────────── */

.vp-search-widget {
  flex: 1;
  max-width: 480px;
}

.vp-search__form {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--vps-card);
  border: 1px solid var(--vps-border);
  border-radius: var(--vps-radius-pill);
  padding: 2px 4px 2px 12px;
  transition: border-color var(--vps-transition), box-shadow var(--vps-transition);
}

.vp-search__form:focus-within {
  border-color: var(--vps-accent);
  box-shadow: 0 0 0 2px rgba(200, 16, 46, 0.2);
}

.vp-search__input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 4px;
  font-size: 16px; /* Must be >=16px to prevent iOS Safari auto-zoom on focus */
  min-width: 0;
  color: var(--vps-text);
  outline: none;
  border-radius: inherit;
}

/* Evitar outline cuadrado del tema :focus-visible; el anillo sigue la píldora del .vp-search__form */
.vp-search__input:focus-visible,
.vp-search__btn:focus-visible {
  outline: none !important;
}

.vp-search__btn:focus-visible {
  box-shadow: 0 0 0 2px rgba(200, 16, 46, 0.35);
}

.vp-search__input::placeholder {
  color: var(--vps-muted);
}

.vp-search__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  background: var(--vps-accent);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--vps-transition);
}

.vp-search__btn:hover {
  background: #a00d24;
}

.vp-search__btn-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ── Overlay ────────────────────────────────────────────────────────── */

.vp-search-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
}

.vp-search-overlay.is-open {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.vp-search-overlay__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: vps-fadeIn 200ms ease;
}

.vp-search-overlay__panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 960px;
  max-height: 90vh;
  margin-top: 32px;
  background: var(--vps-card);
  border-radius: var(--vps-radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: vps-slideDown 250ms ease;
}

.vp-search-overlay__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--vps-border);
  flex-shrink: 0;
}

.vp-search-overlay__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--vps-text);
}

.vp-search-overlay__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--vps-muted);
  border-radius: 50%;
  cursor: pointer;
  transition: background var(--vps-transition);
}

.vp-search-overlay__close:hover {
  background: rgba(0, 0, 0, 0.06);
}

.vp-search-overlay__close .material-icons {
  font-size: 20px;
}

.vp-search-overlay__slot {
  padding: 12px 16px;
  border-bottom: 1px solid var(--vps-border);
  flex-shrink: 0;
}

.vp-search-overlay__slot .vp-search__form {
  max-width: 100%;
}

.vp-search-overlay__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.vp-search-overlay__hint {
  padding: 8px 16px;
  border-top: 1px solid var(--vps-border);
  font-size: 12px;
  color: var(--vps-muted);
  text-align: center;
  flex-shrink: 0;
}

.vp-search__kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--vps-border);
  border-radius: 4px;
  font-size: 11px;
  font-family: monospace;
  background: var(--vps-bg);
  margin-left: 4px;
}

/* Hide body scroll when overlay open */
body.vp-search-overlay-open {
  overflow: hidden !important;
}

/* Placeholder to reserve space when form is reparented */
.vp-search__placeholder {
  display: inline-block;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* ── Summary ────────────────────────────────────────────────────────── */

.vp-search__summary {
  margin-bottom: 12px;
}

.vp-search__count {
  font-size: 14px;
  color: var(--vps-muted);
}

.vp-search__count strong {
  color: var(--vps-text);
}

.vp-search__active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.vp-search__active-filter {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 12px;
  background: var(--vps-accent);
  color: #fff;
  border-radius: var(--vps-radius-pill);
}

.vp-search__active-filter button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}

/* ── Facets (chips) ─────────────────────────────────────────────────── */

.vp-search__facets {
  margin-bottom: 16px;
}

.vp-search__facet-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

/* Mobile: compact facets — scroll + hide chips after 6 (expanded class shows all) */
@media (max-width: 1023px) {
  .vp-search__facet-group {
    max-height: 128px !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    align-content: flex-start !important;
    align-items: flex-start !important;
    padding-bottom: 4px;
    margin-right: -4px;
    padding-right: 4px;
  }

  /* When user taps "+N más", show full list (overrides rule below) */
  .vp-search__facet-group--expanded {
    max-height: none !important;
    overflow-y: visible !important;
  }

  /* Hide category/brand chips after the 6th (label is span; buttons count from 1) */
  .vp-search__facet-group:not(.vp-search__facet-group--expanded) > button.vp-search__chip:not(.vp-search__chip--toggle):not(.vp-search__chip--clear):not(.vp-search__chip--active):nth-of-type(n+7) {
    display: none !important;
  }
}

.vp-search__facet-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--vps-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 2px;
}

.vp-search__chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  font-size: 13px;
  background: var(--vps-bg);
  color: var(--vps-text);
  border: 1px solid var(--vps-border);
  border-radius: var(--vps-radius-pill);
  cursor: pointer;
  transition: all var(--vps-transition);
  white-space: nowrap;
}

.vp-search__chip:hover {
  border-color: var(--vps-accent);
  color: var(--vps-accent);
}

.vp-search__chip--active {
  background: var(--vps-accent);
  color: #fff;
  border-color: var(--vps-accent);
}

.vp-search__chip--active:hover {
  color: #fff;
  background: #a00d24;
}

.vp-search__chip--hidden {
  display: none;
}

.vp-search__chip--toggle {
  background: transparent;
  border-style: dashed;
  border-color: var(--vps-accent);
  color: var(--vps-accent);
  font-weight: 600;
  cursor: pointer;
}

.vp-search__chip--toggle:hover {
  background: rgba(200, 16, 46, 0.06);
}

.vp-search__chip--clear {
  background: transparent;
  border-style: dashed;
  color: var(--vps-muted);
}

.vp-search__chip-count {
  font-size: 11px;
  opacity: 0.7;
}

/* ── Product grid ───────────────────────────────────────────────────── */

.vp-search__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 640px) {
  .vp-search__grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 960px) {
  .vp-search__grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
  }
}

/* ── Product card ───────────────────────────────────────────────────── */

.vp-search__card {
  display: flex;
  flex-direction: column;
  background: var(--vps-card);
  border: 1px solid var(--vps-border);
  border-radius: var(--vps-radius);
  overflow: hidden;
  text-decoration: none;
  color: var(--vps-text);
  transition: transform var(--vps-transition), box-shadow var(--vps-transition);
}

.vp-search__card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.vp-search__card-img {
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--vps-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.vp-search__card-img img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.vp-search__card-noimg {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--vps-muted);
}

.vp-search__card-noimg .material-icons {
  font-size: 48px;
  opacity: 0.3;
}

.vp-search__card-body {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.vp-search__card-brand {
  font-size: 11px;
  font-weight: 600;
  color: var(--vps-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.vp-search__card-name {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.vp-search__card-name mark {
  background: rgba(200, 16, 46, 0.12);
  color: var(--vps-accent);
  padding: 0 1px;
  border-radius: 2px;
}

.vp-search__card-price {
  font-size: 15px;
  font-weight: 700;
  color: var(--vps-text);
  margin-top: 2px;
}

/* ── Stock badge ────────────────────────────────────────────────────── */

.vp-search__badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--vps-radius-pill);
  font-size: 11px;
  font-weight: 600;
  width: fit-content;
  margin-top: 4px;
}

.vp-search__stock--in {
  background: #ecfdf5;
  color: #047857;
}

.vp-search__stock--out {
  background: #fef2f2;
  color: #b91c1c;
}

/* ── Empty state ────────────────────────────────────────────────────── */

.vp-search__empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--vps-muted);
}

.vp-search__empty-icon {
  font-size: 48px;
  opacity: 0.4;
  display: block;
  margin-bottom: 12px;
}

.vp-search__empty p {
  margin: 4px 0;
}

.vp-search__empty strong {
  color: var(--vps-text);
}

.vp-search__empty-hint {
  font-size: 13px;
  margin-top: 8px;
}

/* ── Pagination ─────────────────────────────────────────────────────── */

.vp-search__pag {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 0 8px;
}

.vp-search__pag-btn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  background: var(--vps-bg);
  color: var(--vps-text);
  border: 1px solid var(--vps-border);
  border-radius: var(--vps-radius);
  cursor: pointer;
  transition: all var(--vps-transition);
}

.vp-search__pag-btn:hover {
  border-color: var(--vps-accent);
  color: var(--vps-accent);
}

.vp-search__pag-info {
  font-size: 13px;
  color: var(--vps-muted);
}

/* ── Quick panel ────────────────────────────────────────────────────── */

.vp-search__quick-section {
  margin-bottom: 20px;
}

.vp-search__quick-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--vps-muted);
  margin: 0 0 8px;
}

.vp-search__quick-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.vp-search__quick-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: var(--vps-text);
  border-radius: var(--vps-radius);
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  width: 100%;
  transition: background var(--vps-transition);
}

.vp-search__quick-item:hover {
  background: var(--vps-bg);
}

.vp-search__quick-icon {
  font-size: 18px;
  color: var(--vps-muted);
  flex-shrink: 0;
}

.vp-search__quick-remove {
  margin-left: auto;
  font-size: 16px;
  color: var(--vps-muted);
  opacity: 0;
  transition: opacity var(--vps-transition);
  padding: 0 4px;
}

.vp-search__quick-item:hover .vp-search__quick-remove {
  opacity: 1;
}

.vp-search__quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.vp-search__quick-empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--vps-muted);
}

.vp-search__quick-empty .material-icons {
  font-size: 48px;
  opacity: 0.3;
  display: block;
  margin-bottom: 8px;
}

/* ── Skeleton loading ───────────────────────────────────────────────── */

.vp-search__card--skeleton {
  pointer-events: none;
}

.vp-search__skeleton {
  background: linear-gradient(90deg, #eee 25%, #f5f5f5 50%, #eee 75%);
  background-size: 200% 100%;
  animation: vps-shimmer 1.5s infinite;
  border-radius: 4px;
}

.vp-search__skeleton--img {
  aspect-ratio: 1;
  width: 100%;
  border-radius: var(--vps-radius) var(--vps-radius) 0 0;
}

.vp-search__skeleton--line {
  height: 12px;
  width: 85%;
  margin: 8px 10px 0;
}

.vp-search__skeleton--short {
  width: 55%;
}

.vp-search__skeleton--price {
  height: 16px;
  width: 40%;
  margin: 6px 10px 10px;
}

.vp-search__skeleton-pills {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.vp-search__skeleton-pill {
  display: inline-block;
  width: 80px;
  height: 28px;
  border-radius: var(--vps-radius-pill);
  background: linear-gradient(90deg, #eee 25%, #f5f5f5 50%, #eee 75%);
  background-size: 200% 100%;
  animation: vps-shimmer 1.5s infinite;
}

/* ── Fuzzy fallback notice ──────────────────────────────────────────── */

.vp-search__fuzzy-notice {
  display: inline-flex;
  align-items: center;
  margin-top: 6px;
  padding: 4px 10px;
  font-size: 12px;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--vps-radius-pill);
}

/* ── Animations ─────────────────────────────────────────────────────── */

@keyframes vps-fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes vps-slideDown {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes vps-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Mobile ─────────────────────────────────────────────────────────── */

@media (max-width: 767px) {
  .vp-search-overlay__panel {
    margin-top: 0;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
  }

  .vp-search__grid {
    gap: 8px;
  }

  .vp-search__card-body {
    padding: 6px 8px 8px;
  }

  .vp-search__card-name {
    font-size: 12px;
  }

  .vp-search__card-price {
    font-size: 14px;
  }

  .vp-search-overlay__hint {
    display: none;
  }
}
