/* header-search.css
   Редизайн поля пошуку та випадаючого списку товарів у хедері.
   Використовує токени з styles.css: --accent, --accent-dark, --dark, --muted.
   Підключати ПІСЛЯ header.css (щоб перекрити старі .header-search / .search-dropdown).
*/

/* ============================================
   ПОЛЕ ПОШУКУ
============================================ */
.header-search {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 20px;
  position: relative;
}

.search-field {
  position: relative;
  display: flex;
  align-items: center;
}

.search-field .search-icon {
  position: absolute;
  left: 16px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}

.header-search input {
  width: 100%;
  height: 46px;
  padding: 0 44px;
  border: 1px solid #e5e9f0;
  border-radius: 14px;
  background: #f8fafc;
  font-family: inherit;
  font-size: 15px;
  color: var(--dark);
  transition: border-color .2s, box-shadow .2s, background .2s;
}

.header-search input::placeholder { color: #9aa4b2; }

.header-search input:focus {
  outline: none;
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(0, 195, 255, 0.12);
}

/* кнопка очищення */
.search-clear {
  position: absolute;
  right: 12px;
  width: 26px;
  height: 26px;
  display: none;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: #e5e9f0;
  color: var(--dark);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background .2s;
}
.search-clear:hover { background: #d3d9e3; }
/* показуємо хрестик лише коли в полі є текст */
.header-search input:not(:placeholder-shown) ~ .search-clear { display: flex; }

/* ============================================
   ВИПАДАЮЧИЙ СПИСОК
============================================ */
.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 20px;
  right: 20px;
  z-index: 3000;

  display: none;
  max-height: min(70vh, 520px);
  overflow-y: auto;
  overscroll-behavior: contain;

  background: #fff;
  border: 1px solid #eef1f6;
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.16);
  padding: 8px;
}

.search-dropdown::-webkit-scrollbar { width: 10px; }
.search-dropdown::-webkit-scrollbar-thumb {
  background: #d9dfe8;
  border-radius: 999px;
  border: 3px solid #fff;
}

/* ============================================
   ЕЛЕМЕНТ РЕЗУЛЬТАТУ
============================================ */
.search-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 14px;
  color: var(--dark);
  text-decoration: none;
  transition: background .15s;
}

.search-item:hover,
.search-item.is-active {
  background: rgba(0, 195, 255, 0.08);
}

.search-thumb {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: #f1f5f9;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.search-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.search-body {
  flex: 1 1 auto;
  min-width: 0;
}

.search-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--dark);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.search-sku {
  font-size: 12px;
  color: var(--muted);
}

.search-stock {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.search-stock.in  { color: #0a7d3c; background: rgba(16, 185, 129, 0.12); }
.search-stock.out { color: #92600a; background: rgba(245, 158, 11, 0.14); }

.search-side {
  flex: 0 0 auto;
  text-align: right;
}
.search-price {
  font-size: 15px;
  font-weight: 800;
  color: var(--dark);
  white-space: nowrap;
}

/* підсвічування збігу */
.search-item mark {
  background: rgba(0, 195, 255, 0.18);
  color: var(--accent-dark);
  border-radius: 3px;
  padding: 0 1px;
}

/* ============================================
   ФУТЕР / СТАНИ
============================================ */
.search-footer {
  display: block;
  margin-top: 4px;
  padding: 12px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-dark);
  border-top: 1px solid #eef1f6;
  transition: background .15s;
}
.search-footer:hover { background: rgba(0, 195, 255, 0.06); }

.search-state {
  padding: 22px 16px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

/* скелетон завантаження */
.search-loading { padding: 4px; }
.search-skeleton {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
}
.sk-thumb {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  flex: 0 0 auto;
}
.sk-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sk-line { height: 12px; border-radius: 6px; }
.sk-line.short { width: 45%; }

.sk-thumb,
.sk-line {
  background: linear-gradient(90deg, #eef1f6 25%, #e2e8f0 37%, #eef1f6 63%);
  background-size: 400% 100%;
  animation: sk-shimmer 1.3s ease-in-out infinite;
}
@keyframes sk-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* ============================================
   МОБІЛЬНІ
============================================ */
@media (max-width: 800px) {
  .header-search { padding: 8px 12px; }

  .header-search input {
    height: 42px;
    padding: 0 40px;
    font-size: 16px;   /* ≥16px — iOS Safari не зумить сторінку при фокусі */
    border-radius: 12px;
  }

  .search-field .search-icon { left: 14px; width: 16px; height: 16px; }

  /* Дропдаун на всю ширину екрана, «приклеєний» до низу хедера,
     висота — до краю в'юпорта з відступом (dvh враховує панелі браузера) */
  .search-dropdown {
    left: -12px;                /* компенсуємо padding .header-search */
    right: -12px;
    top: calc(100% + 9px);      /* впритул до нижньої межі рядка пошуку */

    max-height: calc(100dvh - 140px);

    border-left: 0;
    border-right: 0;
    border-radius: 0 0 16px 16px;
    padding: 6px;
  }

  /* більші тач-цілі */
  .search-item { padding: 12px 10px; gap: 12px; }
  .search-thumb { width: 46px; height: 46px; }
  .search-title { font-size: 13px; }
  .search-price { font-size: 14px; }
  .search-footer { padding: 14px 12px; }
}