/**
 * SPEC-043: Стилі попап-пошуку Meilisearch (Оригінальний макет Multisearch)
 * Точна геометрія, шрифти, відступи, кольори та поведінка віджета Multisearch.io.
 * Класи ізольовані префіксом .sp-*
 */

:root {
  --sp-primary: #C8102E;
  --sp-primary-hover: #A00D25;
  --sp-primary-light: #FDF2F3;
  --sp-text: rgba(0, 0, 0, 0.9);
  --sp-text-muted: rgba(0, 0, 0, 0.45);
  --sp-border: #E6E6E6;
  --sp-border-light: #EEEEEE;
  --sp-bg-overlay: hsla(0, 0%, 95%, 0.97);
  --sp-shadow: 0 1px 4px rgba(62, 57, 107, 0.35);
  --sp-radius: 3px;
  --sp-blue-link: rgba(100, 119, 136, 0.85);
}

/* 1. Оверлей на весь екран */
.sp-overlay {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 2147483647; /* вище за віджет чату, як у Multisearch */
  background: var(--sp-bg-overlay);
  -webkit-overflow-scrolling: touch;
  overflow-y: scroll;
  font-family: 'Gilroy', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  color: var(--sp-text);
  font-size: 16px;
  line-height: 20px;
  text-rendering: optimizeLegibility;
  text-align: left;
  box-sizing: border-box;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sp-overlay.sp-active {
  display: block;
  opacity: 1;
}

/* 2. Обгортка та картка макета (Multisearch .multi-theme-compact) */
.sp-wrapper {
  margin: 2% auto;
  max-width: 1420px;
  box-sizing: border-box;
  width: 100%;
}

.sp-layout {
  margin: 0 2%;
  background: #ffffff;
  border-radius: var(--sp-radius);
  box-shadow: var(--sp-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

/* 3. Шапка пошуку: 90px інпут з великою лупою та хрестиком */
.sp-header {
  background: #ffffff;
  position: relative;
  z-index: 10;
  height: 90px;
  display: flex;
  align-items: center;
  box-sizing: border-box;
}

.sp-form {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
}

.sp-icon-search {
  position: absolute;
  top: 20px;
  left: 37px;
  width: 50px;
  height: 50px;
  fill: #adb9c5;
  opacity: 0.5;
  pointer-events: none;
}

.sp-input {
  font-family: inherit;
  font-size: 34px;
  font-weight: 400;
  font-style: normal;
  position: relative;
  background: transparent;
  border: none !important;
  outline: none !important;
  color: #000000;
  height: 90px;
  line-height: 40px;
  margin: 0;
  padding: 6px 55px 9px 101px;
  width: 100%;
  box-sizing: border-box;
}

.sp-input:focus {
  outline: 0;
  border: 0;
  box-shadow: none !important;
}

.sp-input::placeholder {
  color: #000000 !important;
  opacity: 0.2 !important;
  font-size: 27px;
  padding-top: 10px;
}

/* Як у Multisearch — у шапці лише «закрити»; JS ставить inline display, тому !important */
.sp-btn-clear {
  display: none !important;
  position: absolute;
  right: 74px;
  top: 26px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  color: #888888;
  font-size: 28px;
  line-height: 1;
  transition: color 0.15s;
  z-index: 2;
}

.sp-btn-clear:hover {
  color: var(--sp-primary);
}

.sp-spinner {
  display: none;
  position: absolute;
  right: 76px;
  top: 34px;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(200, 16, 46, 0.2);
  border-top-color: var(--sp-primary);
  border-radius: 50%;
  animation: spSpin 0.6s linear infinite;
  z-index: 2;
}

@keyframes spSpin {
  to { transform: rotate(360deg); }
}

.sp-btn-close {
  position: absolute;
  top: 23px;
  right: 37px;
  width: 43px;
  height: 43px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  opacity: 0.85;
  transition: opacity 0.15s;
}

.sp-btn-close:hover {
  opacity: 1;
}

.sp-icon-close {
  width: 43px;
  height: 43px;
  fill: #000000;
}

/* 4. Тіло результатів */
.sp-body {
  position: relative;
  background: #ffffff;
  display: flex;
  flex-direction: column;
}

/* 4. Чипи підказок при наборі (SPEC-044) */
.sp-suggest-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 0 37px 18px;
  background: #ffffff;
  box-sizing: border-box;
}

.sp-suggest-chip {
  /* inline-block, не flex: інакше текст і <mark> стають окремими flex-елементами з проміжками */
  display: inline-block;
  padding: 5px 12px;
  background: #FFFFFF;
  border: 1px solid var(--sp-border-light);
  border-radius: 5px;
  font-size: 15px;
  line-height: 20px;
  font-weight: 400;
  color: var(--sp-text);
  cursor: pointer;
  outline: none;
  font-family: inherit;
  transition: all 0.15s ease;
  user-select: none;
  text-align: left;
}

.sp-suggest-chip:hover {
  border-color: #cccccc;
  color: var(--sp-primary);
}

.sp-suggest-chip.sp-keyboard-selected,
.sp-suggest-chip[aria-selected="true"] {
  border-color: var(--sp-primary);
  color: var(--sp-primary);
}

.sp-suggest-match {
  padding: 0; /* bootstrap дає mark padding .2em */
  background: transparent;
  color: inherit;
  font-weight: 400;
  opacity: 0.55;
}

.sp-suggest-chip:hover .sp-suggest-match,
.sp-suggest-chip.sp-keyboard-selected .sp-suggest-match {
  color: var(--sp-primary-hover);
}

/* 4.1. Банери корекції запиту: 3 стани (SPEC-044) */
.sp-layout-hint {
  padding: 12px 40px;
  font-size: 14px;
  line-height: 20px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.sp-banner-layout {
  background: #FFF9E6;
  border-bottom: 1px solid #FFE58F;
  color: #594000;
}

.sp-banner-term {
  background: #EFF6FF;
  border-bottom: 1px solid #BFDBFE;
  color: #1E40AF;
}

.sp-banner-kept {
  background: #F9FAFB;
  border-bottom: 1px solid #E5E7EB;
  color: #374151;
}

.sp-banner-text {
  font-weight: 500;
}

.sp-banner-action {
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  color: inherit;
  transition: opacity 0.15s;
}

.sp-banner-action:hover {
  opacity: 0.8;
}

/* 5. Стан 1: Порожнє поле (Ви шукали / Популярні запити) */
.sp-idle-container {
  padding: 10px 37px 40px;
}

.sp-suggest-section {
  margin-bottom: 24px;
}

.sp-suggest-section:last-child {
  margin-bottom: 0;
}

.sp-suggest-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.sp-suggest-title {
  font-size: 16px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.55);
}

.sp-btn-clear-history {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: #888888;
  text-decoration: underline;
  padding: 0;
}

.sp-btn-clear-history:hover {
  color: var(--sp-primary);
}

.sp-suggest-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.sp-suggest-tag {
  display: inline-block;
  font-size: 15px;
  color: rgba(0, 0, 0, 0.75);
  margin-right: 22px;
  margin-bottom: 8px;
  text-decoration: underline;
  cursor: pointer;
  transition: color 0.15s ease;
}

.sp-suggest-tag:hover {
  color: var(--sp-primary);
}

/* 6. Стан 2: Результати пошуку (Сайдбар + Списки груп) */
.sp-results-layout {
  display: flex;
  margin: 0;
  padding: 0 37px;
  box-sizing: border-box;
  width: 100%;
}

/* Ліва колонка: категорії (Multisearch .multi-sidebar) */
.sp-sidebar {
  flex: 0 0 260px;
  width: 260px;
  padding: 5px 0 85px;
  box-sizing: border-box;
}

/* Перемикач категорій — лише на мобільному */
.sp-filter-toggle {
  display: none;
}

.sp-taxons {
  margin: 0;
  padding: 0;
}

.sp-category-item {
  border-bottom: 1px solid var(--sp-border);
  padding: 16px 5px 16px 2px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  line-height: 22px;
  font-weight: 400;
  cursor: pointer;
  color: var(--sp-text);
  transition: all 0.15s ease;
  user-select: none;
}

.sp-category-item:first-child {
  border-top: 1px solid var(--sp-border);
}

.sp-category-item:hover {
  color: var(--sp-primary);
}

/* Активна категорія — лише червоний бейдж, текст звичайний (як у Multisearch) */
.sp-category-item.sp-cat-active {
  color: var(--sp-text);
}

.sp-cat-count,
.sp-cat-badge-all {
  flex: 0 0 auto;
  line-height: 22px;
  padding: 0 4px;
  text-align: center;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 400;
  border: 1px solid var(--sp-border-light);
  min-width: 21px;
  margin-left: 5px;
  width: auto;
  background: #ffffff;
  color: var(--sp-text);
  transition: all 0.15s ease;
}

.sp-category-item:hover .sp-cat-count {
  border-color: #cccccc;
}

.sp-category-item.sp-cat-active .sp-cat-count,
.sp-cat-badge-all {
  background: var(--sp-primary);
  border-color: var(--sp-primary);
  color: #ffffff;
}

.sp-btn-toggle-cats {
  display: block;
  width: 100%;
  border: none;
  background: none;
  padding: 16px 2px;
  font-size: 16px;
  font-weight: 400;
  color: rgba(100, 119, 136, 0.7);
  cursor: pointer;
  text-align: left;
  transition: color 0.15s;
}

.sp-btn-toggle-cats:hover {
  color: var(--sp-primary);
}

/* Права частина: групи товарів (Multisearch .multi-lists) */
.sp-main {
  flex: 1;
  padding: 12px 0 60px 60px;
  box-sizing: border-box;
  min-width: 0;
  position: relative;
}

/* Сітка з 3 колонок для груп на десктопі */
.sp-groups-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 60px;
}

.sp-group-block {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Заголовок групи: 22px з лінією та стрілочкою вправо */
.sp-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--sp-border);
  padding-bottom: 6px;
  margin-bottom: 0;
  cursor: pointer;
  color: var(--sp-text);
  text-decoration: none;
  transition: color 0.15s;
}

.sp-group-title {
  font-size: 26px;
  line-height: 29px;
  font-weight: 400;
}

/* У Multisearch стрілки біля заголовка нема */
.sp-title-arrow {
  display: none;
  width: 20px;
  height: 20px;
  fill: var(--sp-blue-link);
  flex-shrink: 0;
  margin-left: 8px;
  transition: transform 0.15s ease, fill 0.15s ease;
}

.sp-group-header:hover .sp-group-title {
  color: var(--sp-primary);
}

.sp-group-header:hover .sp-title-arrow {
  fill: var(--sp-primary);
  transform: translateX(3px);
}

.sp-group-products {
  display: flex;
  flex-direction: column;
}

/* Картка товару в групі (Multisearch .multi-item) */
.sp-card {
  display: flex;
  align-items: flex-start;
  margin-top: 18px;
  text-decoration: none;
  color: var(--sp-text);
  cursor: pointer;
}

.sp-card:hover,
.sp-card.sp-keyboard-selected {
  color: var(--sp-primary);
}

.sp-card.sp-keyboard-selected .sp-card-thumb {
  border-color: var(--sp-primary);
}

/* Прев'ю товару 80×80px у рамці */
.sp-card-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--sp-border-light);
  margin-right: 15px;
  width: 82px;
  height: 82px;
  flex-shrink: 0;
  background: #ffffff;
  border-radius: 0;
  box-sizing: border-box;
}

.sp-card-img {
  color: transparent; /* без alt-тексту в битій картинці */
  font-size: 0;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.sp-card-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.sp-card-name {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 15px;
  line-height: 20px;
  color: var(--sp-text);
  margin-bottom: 5px;
  font-weight: 400;
  transition: color 0.15s;
}

.sp-card:hover .sp-card-name {
  color: var(--sp-primary);
}

/* Ціни як у Multisearch: стара закреслена сіра зліва, нова — приглушений текст, без жирного */
.sp-card-prices {
  display: flex;
  align-items: baseline;
  font-size: 15px;
  line-height: 20px;
  font-weight: 400;
}

.sp-price-special,
.sp-price-main {
  color: rgba(0, 0, 0, 0.55);
  font-weight: 400;
}

.sp-price-old {
  order: -1;
  padding-right: 5px;
  color: #bbbbbb;
  text-decoration: line-through;
}

/* Посилання «ще N …» у групі */
.sp-btn-more {
  display: inline-block;
  margin-top: 15px;
  color: rgba(100, 119, 136, 0.7);
  font-size: 16px;
  line-height: 20px;
  font-weight: 400;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  transition: color 0.15s ease;
  width: auto;
}

.sp-btn-more:hover {
  color: var(--sp-primary);
}

/* 7. Плоский список (All results або окрема категорія) */
.sp-flat-container {
  display: flex;
  flex-direction: column;
}

.sp-flat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--sp-border);
  padding-bottom: 12px;
  margin-bottom: 24px;
}

.sp-flat-title {
  font-size: 26px;
  line-height: 29px;
  font-weight: 400;
  color: var(--sp-text);
}

.sp-flat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
}

.sp-flat-card {
  border: 1px solid var(--sp-border-light);
  border-radius: 3px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-decoration: none;
  color: inherit;
  background: #ffffff;
  transition: all 0.15s ease;
}

.sp-flat-card:hover,
.sp-flat-card.sp-keyboard-selected {
  border-color: #d0d0d0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.sp-flat-thumb {
  width: 100%;
  height: 150px;
  object-fit: contain;
  margin-bottom: 12px;
  background: #ffffff;
}

.sp-flat-name {
  font-size: 15px;
  line-height: 20px;
  color: var(--sp-text);
  font-weight: 400;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
  min-height: 40px;
}

.sp-flat-card:hover .sp-flat-name {
  color: var(--sp-primary);
}

.sp-btn-load-more {
  align-self: center;
  margin: 32px auto 10px;
  background: #ffffff;
  border: 1px solid #adb9c5;
  border-radius: 24px;
  padding: 10px 36px;
  font-size: 16px;
  font-weight: 400;
  color: rgba(100, 119, 136, 0.9);
  cursor: pointer;
  transition: all 0.15s;
}

.sp-btn-load-more:hover {
  border-color: var(--sp-primary);
  color: var(--sp-primary);
  background: var(--sp-primary-light);
}

/* 8. Стан 3: Нічого не знайдено */
.sp-empty-box {
  text-align: center;
  padding: 50px 20px;
}

.sp-empty-title {
  font-size: 26px;
  line-height: 29px;
  font-weight: 400;
  color: var(--sp-text);
  margin-bottom: 8px;
}

.sp-empty-desc {
  font-size: 15px;
  color: #777777;
  margin-bottom: 24px;
}

/* 9. Адаптація для планшетів (800px – 1260px) */
@media (min-width: 800px) and (max-width: 960px) {
  .sp-sidebar {
    flex: 0 0 240px;
    width: 240px;
  }
}

@media (min-width: 961px) and (max-width: 1260px) {
  .sp-groups-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .sp-flat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* 10. Мобільна версія (< 685px, як Multisearch) */
@media (max-width: 685px) {
  .sp-wrapper {
    margin: 0;
    max-width: none;
  }

  .sp-layout {
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
  }

  .sp-header {
    height: 60px;
  }

  .sp-input {
    font-size: 20px !important;
    line-height: 20px !important;
    padding: 5px 41px 5px 63px !important;
    height: 60px !important;
  }

  .sp-input::placeholder {
    font-size: 17px !important;
    padding-top: 0 !important;
  }

  .sp-icon-search {
    top: 10px !important;
    left: 20px !important;
    width: 40px !important;
    height: 40px !important;
  }

  .sp-btn-close {
    top: 14px !important;
    right: 20px !important;
    width: 32px !important;
    height: 32px !important;
  }

  .sp-icon-close {
    width: 32px;
    height: 32px;
  }

  .sp-spinner {
    right: 60px !important;
    top: 19px !important;
  }

  .sp-idle-container {
    padding: 10px 24px 35px;
  }

  .sp-suggest-chips {
    padding: 0 24px 12px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
  }

  .sp-suggest-chips::-webkit-scrollbar {
    display: none;
  }

  .sp-suggest-chip {
    flex-shrink: 0;
    white-space: nowrap;
  }

  .sp-layout-hint {
    padding: 10px 24px;
    font-size: 13px;
  }

  .sp-results-layout {
    flex-direction: column;
    padding: 0 24px;
  }

  /* Категорії згорнуті в «Фільтр по категорії ▾» */
  .sp-sidebar {
    width: 100%;
    flex: 0 0 auto;
    padding: 0;
    border-top: 1px solid var(--sp-border);
    border-bottom: 1px solid var(--sp-border);
  }

  .sp-filter-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 22px 5px 22px 2px;
    background: none;
    border: none;
    font-family: inherit;
    font-size: 16px;
    line-height: 22px;
    font-weight: 400;
    color: var(--sp-text);
    text-align: left;
    cursor: pointer;
  }

  .sp-filter-label::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    margin: 0 0 3px 9px;
    border-right: 1px solid rgba(0, 0, 0, 0.55);
    border-bottom: 1px solid rgba(0, 0, 0, 0.55);
    transform: rotate(45deg);
  }

  .sp-sidebar-open .sp-filter-label::after {
    margin-bottom: -1px;
    transform: rotate(-135deg);
  }

  .sp-taxons {
    display: none;
    padding-bottom: 10px;
  }

  .sp-sidebar-open .sp-taxons {
    display: block;
  }

  .sp-category-item:first-child {
    border-top: 1px solid var(--sp-border);
  }

  .sp-main {
    padding: 40px 0 40px 0;
  }

  .sp-groups-grid {
    grid-template-columns: 1fr;
    gap: 50px;
  }

  .sp-group-title {
    font-size: 28px;
    line-height: 33px;
  }

  .sp-group-header {
    padding-bottom: 8px;
  }

  .sp-card-thumb {
    margin-right: 20px;
  }

  .sp-card-name {
    line-height: 21px;
    -webkit-line-clamp: 4;
  }

  /* «ще N …» — кругла кнопка зі стрілкою */
  .sp-btn-more {
    display: block;
    width: 50px;
    height: 50px;
    margin: 30px auto 0;
    border: 1px solid #adb9c5;
    border-radius: 50%;
    font-size: 0;
    color: transparent;
    background: #ffffff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23adb9c5' stroke-width='1.6'%3E%3Cpath d='M4 12h15M13 6l6 6-6 6'/%3E%3C/svg%3E") center / 24px no-repeat;
  }

  .sp-flat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .sp-flat-title {
    font-size: 28px;
    line-height: 33px;
  }
}
