/*
 * Публичные CSS-переменные.
 * Их можно переопределить в дочерней теме без редактирования файла плагина.
 */
:root {
  --waps-background: #fff;
  --waps-text: #171717;
  --waps-muted: #6b7280;
  --waps-border: #e5e7eb;
  --waps-surface: #f7f7f7;
  --waps-accent: #111827;
  --waps-container: 1120px;
  --waps-radius: 12px;
}

/* Блокируем прокрутку страницы, пока открыто полноэкранное окно. */
html.waps-is-open,
body.waps-is-open {
  overflow: hidden !important;
}

/* Атрибут hidden должен иметь приоритет над стилями темы. */
.waps-overlay[hidden] {
  display: none !important;
}

/* Полноэкранный scroll-контейнер поиска. */
.waps-overlay {
  position: fixed;
  inset: 0;
  z-index: 999999;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--waps-background);
  color: var(--waps-text);
}

.waps-dialog {
  min-height: 100%;
  position: relative;
}

.waps-container {
  width: min(calc(100% - 32px), var(--waps-container));
  margin: 0 auto;
  padding: clamp(72px, 10vw, 112px) 0 56px;
}

/* Кнопка закрытия закреплена независимо от прокрутки результатов. */
.waps-close {
  position: fixed;
  top: 20px;
  right: max(20px, calc((100vw - var(--waps-container)) / 2));
  z-index: 2;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: currentColor;
  cursor: pointer;
}

.waps-close:hover,
.waps-close:focus-visible,
.waps-clear:hover,
.waps-clear:focus-visible {
  background: var(--waps-surface);
}

.waps-close svg,
.waps-clear svg,
.waps-search-icon,
.waps-trigger svg {
  fill: currentColor;
}

.waps-search-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border-bottom: 2px solid var(--waps-text);
}

.waps-search-icon {
  color: var(--waps-muted);
}

.waps-input {
  width: 100%;
  min-width: 0;
  padding: 16px 0;
  border: 0 !important;
  outline: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  color: inherit;
  font: inherit;
  font-size: clamp(24px, 4vw, 46px);
  line-height: 1.15;
  -webkit-appearance: none;
  appearance: none;
}

/* Используем собственную кнопку очистки, одинаковую во всех браузерах. */
.waps-input::-webkit-search-cancel-button {
  display: none;
}

.waps-input::placeholder {
  color: #9ca3af;
  opacity: 1;
}

.waps-clear {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--waps-muted);
  cursor: pointer;
}

.waps-clear[hidden] {
  display: none;
}

.waps-meta {
  min-height: 24px;
  margin-top: 18px;
  color: var(--waps-muted);
  font-size: 14px;
}

.waps-status {
  padding: 28px 0 8px;
  color: var(--waps-muted);
  font-size: 18px;
}

.waps-status:empty {
  display: none;
}

.waps-results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.waps-product {
  min-width: 0;
  margin: 0;
}

.waps-product__link {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: center;
  gap: 20px;
  height: 100%;
  padding: 14px;
  border: 1px solid var(--waps-border);
  border-radius: var(--waps-radius);
  color: inherit;
  text-decoration: none;
  transition:
    border-color 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease;
}

.waps-product__link:hover,
.waps-product__link:focus-visible {
  border-color: #b8bec7;
  box-shadow: 0 10px 30px rgb(0 0 0 / 7%);
  transform: translateY(-1px);
  outline: none;
}

.waps-product__image-wrap {
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: calc(var(--waps-radius) - 4px);
  background: var(--waps-surface);
}

.waps-product__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.waps-product__content {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.waps-product__title {
  /* Ограничиваем длинное название тремя строками без обрезки самой карточки. */
  display: -webkit-box;
  overflow: hidden;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  line-clamp: 3;
  -webkit-line-clamp: 3;
}

.waps-product__price {
  color: var(--waps-muted);
  font-size: 16px;
  font-weight: 600;
}

.waps-product__price del {
  opacity: 0.55;
}

.waps-product__price ins {
  text-decoration: none;
}

.waps-sentinel {
  /* Невидимая точка, за которой следит IntersectionObserver в JavaScript. */
  height: 1px;
}

.waps-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 88px;
  color: var(--waps-muted);
}

.waps-loader[hidden] {
  display: none;
}

.waps-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--waps-border);
  border-top-color: var(--waps-accent);
  border-radius: 999px;
  animation: waps-spin 700ms linear infinite;
}

/* Базовый вид кнопки из shortcode. Кнопку темы можно стилизовать независимо. */
.waps-trigger {
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

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

@media (max-width: 767px) {
  /* На мобильном карточки переходят в одну колонку и становятся компактнее. */
  .waps-container {
    width: min(calc(100% - 24px), var(--waps-container));
    padding-top: 76px;
  }

  .waps-close {
    top: 10px;
    right: 10px;
  }

  .waps-results {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .waps-product__link {
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 14px;
    padding: 10px;
  }

  .waps-product__title {
    font-size: 15px;
  }
}

@media (prefers-reduced-motion: reduce) {
  /* Уважаем системную настройку уменьшения анимаций. */
  .waps-product__link,
  .waps-spinner {
    transition: none;
    animation-duration: 1.5s;
  }
}
