/**
 * SwiftSearch Widget — Base CSS
 * Layout, structure, responsive behavior.
 * Override visuals with your client CSS (e.g. diamond-sky.css).
 *
 * Load order:
 *   <link rel="stylesheet" href="swiftsearch-base.css">
 *   <link rel="stylesheet" href="diamond-sky.css">
 */

/* ── Animacje ─────────────────────────────────────────────── */

@keyframes ss-spin {
  to { transform: rotate(360deg); }
}
@keyframes ss-fade {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Spinner ─────────────────────────────────────────────── */

.ss-spinner {
  display: inline-block; width: 22px; height: 22px;
  border: 2px solid #e5e7eb; border-top-color: #111827;
  border-radius: 50%; animation: ss-spin .7s linear infinite;
}
.ss-loading { padding: 32px 16px; text-align: center; }

/* ── Load more (infinite scroll) ────────────────────────────
   Niski sentinel obserwowany przez IntersectionObserver — gdy
   wjedzie w viewport, doczytujemy kolejną stronę wyników.
   Spinner jest w DOM od razu (żeby IO miało co obserwować),
   ale widoczny dopiero przy aktywnym doczytywaniu. */
.ss-load-more {
  grid-column: 1 / -1;
  height: 8px;
  display: flex; align-items: center; justify-content: center;
  overflow: visible;
}
.ss-load-more .ss-spinner {
  width: 16px; height: 16px; opacity: 0;
  transition: opacity .15s;
}
.ss-load-more.ss-load-more-active {
  height: auto; padding: 12px 0;
}
.ss-load-more.ss-load-more-active .ss-spinner {
  opacity: 1;
}

/* ── Sekcje ──────────────────────────────────────────────── */

.ss-section { padding: 16px 20px; border-bottom: 1px solid #f0f0f0; }
.ss-section:last-child { border-bottom: none; }

.ss-section-header {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 10px;
}
.ss-section-title {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em; color: #9ca3af;
}
.ss-clear-all {
  font-size: 11px; background: none; border: none; cursor: pointer; padding: 0;
}

/* ── Ostatnio wyszukiwane ────────────────────────────────── */

.ss-recent-list { display: flex; flex-direction: column; }
.ss-recent-item {
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid #f3f4f6;
}
.ss-recent-item:last-child { border-bottom: none; }
.ss-recent-term {
  font-size: 13px; background: none; border: none; cursor: pointer;
  text-align: left; flex: 1; padding: 8px 0;
}
.ss-recent-remove {
  font-size: 16px; line-height: 1; background: none; border: none;
  cursor: pointer; padding: 0 0 0 12px;
}

/* ── Suggestions row ─────────────────────────────────────── */

.ss-overlay-suggestions {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  padding: 10px 20px; border-bottom: 1px solid #f0f0f0; flex-shrink: 0;
}
.ss-suggestions-label { font-size: 11px; margin-right: 4px; white-space: nowrap; }
.ss-suggestion-chip {
  display: flex; align-items: center; gap: 4px;
  border: 1px solid #e5e7eb; padding: 3px 10px;
}
.ss-suggestion-text {
  font-size: 12px; background: none; border: none; cursor: pointer; padding: 0;
}
.ss-suggestion-remove {
  font-size: 13px; line-height: 1; background: none; border: none;
  cursor: pointer; padding: 0;
}
.ss-suggestions-clear {
  font-size: 11px; background: none; border: none;
  cursor: pointer; padding: 3px 0; margin-left: 4px;
}

/* ── Najczęściej wyszukiwane ─────────────────────────────── */

.ss-popular-list { display: flex; flex-direction: column; }
.ss-popular-item {
  font-size: 13px !important; line-height: 1.3 !important;
  padding: 8px 0 !important; background: none !important; border: none !important;
  border-bottom: 1px solid #f3f4f6 !important; text-align: left; cursor: pointer;
  width: 100%; display: block; min-height: unset !important; height: auto !important;
}
.ss-popular-item:last-child { border-bottom: none !important; }

/* ── Initial state: 2 kolumny ────────────────────────────── */

.ss-initial-grid { display: grid; grid-template-columns: 1fr; }

@media (min-width: 768px) {
  .ss-initial-grid { grid-template-columns: 280px 1fr; }
  .ss-initial-grid > .ss-section { min-width: 0; } /* Grid gotcha: bez tego 1fr rośnie do contentu */
  .ss-initial-grid > .ss-section:first-child {
    border-right: 1px solid #f0f0f0; border-bottom: none;
  }
}

/* ── Karuzela ────────────────────────────────────────────── */

/* section = kontekst pozycjonowania dla przycisków i fadu */
.ss-carousel-section { position: relative; margin-top: 12px; }

/* fade po prawej — na section, poza overflow:hidden */
.ss-carousel-section::after {
  content: ''; position: absolute;
  top: 0; right: 0; bottom: 4px; width: 64px;
  background: linear-gradient(to left, #fff 20%, transparent);
  pointer-events: none; z-index: 2;
}

/* wrap tylko clipuje — width:100% wymusza szerokość rodzica zamiast contentu */
.ss-carousel-wrap { overflow: hidden; width: 100%; }

.ss-carousel {
  display: flex; gap: 16px; overflow-x: auto;
  scroll-snap-type: x mandatory; scrollbar-width: none;
  -ms-overflow-style: none; padding-bottom: 4px;
}
.ss-carousel::-webkit-scrollbar { display: none; }

/* przyciski na section (poza overflow:hidden) */
.ss-carousel-btn {
  position: absolute; top: 40%; transform: translateY(-50%);
  z-index: 3; width: 34px !important; height: 34px !important;
  background: rgba(255,255,255,.96) !important; border: 1px solid #e5e7eb !important;
  box-shadow: 0 2px 8px rgba(0,0,0,.10);
  cursor: pointer; padding: 0 !important; line-height: 1 !important;
  display: flex !important; align-items: center; justify-content: center;
  min-height: unset !important;
}
.ss-carousel-btn.ss-prev { left: 6px; }
.ss-carousel-btn.ss-next { right: 6px; }
.ss-carousel-btn[hidden]  { display: none; }

.ss-card {
  flex-shrink: 0; scroll-snap-align: start;
  text-decoration: none; color: #111827; display: flex; flex-direction: column;
}
.ss-card-img { display: block; object-fit: contain; }
.ss-card-img-ph { }
.ss-card-name {
  font-size: 12px; line-height: 1.35; margin-top: 8px;
  overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.ss-card-prices { margin-top: 4px; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.ss-card-price      { font-size: 13px; font-weight: 600; }
.ss-card-sale-price { font-size: 13px; font-weight: 600; }
.ss-card-orig-price { font-size: 11px; text-decoration: line-through; }

/* ── Facety ──────────────────────────────────────────────── */

.ss-results-layout { display: flex; height: 100%; }

.ss-facets {
  width: 280px; flex-shrink: 0; border-right: 1px solid #f0f0f0;
  display: flex; flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  padding: 18px 16px 30px;
}
.ss-facets::-webkit-scrollbar { display: none; }
.ss-facet-section { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid #f3f4f6; }
.ss-facet-section:last-child { border-bottom: none; margin-bottom: 0; }
.ss-facet-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; color: #9ca3af; margin-bottom: 10px;
}
.ss-facet-list { display: flex; flex-direction: column; }
.ss-facets .ss-facet-item {
  display: flex; align-items: center; gap: 8px; padding: 3px 6px;
  border: none; background: none; cursor: pointer; width: 100%; text-align: left;
  line-height: 1.3 !important; font-size: 12px !important;
  min-height: unset !important; height: auto !important; box-sizing: content-box !important;
}
.ss-facet-check {
  width: 14px; height: 14px; flex-shrink: 0;
  border: 1px solid #d1d5db;
  display: flex; align-items: center; justify-content: center;
}
.ss-facet-check.ss-facet-checked { background: #111827; border-color: #111827; }
.ss-facet-check svg { width: 10px; height: 10px; color: #fff; display: block; }
.ss-facet-name {
  flex: 1; font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ss-facet-count { font-size: 10px; flex-shrink: 0; color: #9ca3af; }

/* ── Facet show more / less ──────────────────────────────── */

.ss-facet-extra { display: none; }
.ss-facet-extra--open { display: block; }

.ss-facet-toggle {
  display: inline-block; margin-top: 4px; padding: 0 !important;
  border: none !important; background: transparent !important; cursor: pointer;
  font-size: 11px !important; line-height: 1.3 !important;
  color: var(--ss-accent, #2563eb) !important;
}
.ss-facet-toggle:hover {
  text-decoration: underline;
  color: var(--ss-accent, #2563eb) !important;
  background: transparent !important;
}

/* ── Price range slider ──────────────────────────────────── */

.ss-price-display {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 4px;
}

.ss-price-track-wrap {
  position: relative;
  height: 4px;
  margin: 16px 4px 20px;
}

.ss-price-track-bg {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
}

.ss-price-track-fill {
  position: absolute;
  top: 0;
  height: 4px;
  background: var(--ss-accent, #2563eb);
  border-radius: 2px;
}

.ss-range-input {
  pointer-events: none;
  position: absolute;
  width: 100%;
  height: 4px;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  top: 0;
  left: 0;
  margin: 0;
}
.ss-range-input::-webkit-slider-thumb {
  pointer-events: all;
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--ss-accent, #2563eb);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.ss-range-input::-moz-range-thumb {
  pointer-events: all;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--ss-accent, #2563eb);
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}

.ss-results-area { flex: 1; min-width: 0; overflow-y: auto; scrollbar-width: none; }
.ss-results-area::-webkit-scrollbar { display: none; }

/* ── Wyniki ──────────────────────────────────────────────── */

.ss-results-count {
  font-size: 11px; padding: 8px 16px; color: #9ca3af;
}

.ss-results-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1px;
}

.ss-item {
  display: flex; flex-direction: column;
  padding: 14px 10px;
  cursor: pointer; text-decoration: none; color: #111827;
}
.ss-item-img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; }
.ss-item-img-ph { width: 100%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; }
.ss-item-img-ph svg { width: 32px; height: 32px; opacity: .2; }
.ss-item-body { flex: 1; min-width: 0; margin-top: 10px; }
.ss-item-name {
  font-size: 12px; font-weight: 400; line-height: 1.4;
  overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.ss-item-name mark { background: none; font-weight: 600; }
.ss-item-meta { display: flex; align-items: baseline; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.ss-item-price { font-size: 13px; font-weight: 600; }
.ss-item-sale  { font-size: 11px; text-decoration: line-through; }
.ss-item-brand { font-size: 11px; }
.ss-item-badge { font-size: 10px; font-weight: 600; padding: 1px 6px; text-transform: uppercase; }

/* ── Banner ──────────────────────────────────────────────── */

.ss-banner { display: block; overflow: hidden; }
.ss-banner img { width: 100%; height: auto; display: block; }

/* ── Footer ──────────────────────────────────────────────── */

.ss-footer {
  padding: 10px 20px; border-top: 1px solid #f0f0f0;
  display: flex; align-items: center; justify-content: space-between;
}
.ss-view-all {
  font-size: 12px; font-weight: 600; background: none; border: none; cursor: pointer; padding: 0;
}
.ss-powered { font-size: 10px; text-decoration: none; }
.ss-no-results { padding: 40px 24px; text-align: center; font-size: 14px; color: #9ca3af; }

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

.ss-backdrop {
  position: fixed; inset: 0; z-index: 999998;
  background: rgba(0,0,0,.5); backdrop-filter: blur(2px);
  animation: ss-fade .15s ease;
}
.ss-overlay {
  position: fixed; inset: 0; z-index: 999999;
  display: flex; flex-direction: column;
}
.ss-overlay-layer {
  background: #fff; width: 100%; height: 100%;
  display: flex; flex-direction: column; animation: ss-fade .15s ease;
}
.ss-overlay-header {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 24px; border-bottom: 1px solid #f0f0f0; flex-shrink: 0;
}
.ss-overlay-logo { height: 32px; width: auto; object-fit: contain; cursor: pointer; flex-shrink: 0; }
.ss-overlay-searchbox {
  flex: 1; display: flex; align-items: center; gap: 10px;
  background: #f9fafb; border: 1px solid #e5e7eb; padding: 0 14px;
}
.ss-overlay-searchbox svg { flex-shrink: 0; color: #9ca3af; }
.ss-overlay-input {
  flex: 1; border: none; background: transparent;
  /* 16px to nie estetyka — to próg, poniżej którego iOS Safari robi
     auto-zoom na focusie inputa. Overlay się wtedy nie ucina naprawdę,
     tylko cała strona zostaje wizualnie powiększona (zoom), więc prawa
     krawędź wychodzi poza widoczny obszar. 15px < 16px = auto-zoom. */
  font-size: 16px; padding: 11px 0; outline: none;
}
.ss-overlay-input::placeholder { color: #9ca3af; }
.ss-overlay-close {
  flex-shrink: 0; width: 36px; height: 36px; background: none; border: none;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 22px; line-height: 1;
}
.ss-overlay-body { flex: 1; overflow-y: auto; min-height: 0; }
.ss-overlay-body--facets { overflow: hidden; }

/* ── Dropdown ────────────────────────────────────────────── */

#ss-dd-wrapper { position: relative; display: inline-block; width: 100%; }
#ss-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  z-index: 99999; background: #fff; border: 1px solid #e5e7eb;
  display: none; max-height: 600px; overflow-y: auto;
}
#ss-dropdown.ss-open { display: block; animation: ss-fade .12s ease; }

/* ── Mobile (< 768px) ────────────────────────────────────── */

@media (max-width: 767px) {
  /* Initial: ukryj rekomendowane — całą sekcję (nagłówek + karuzela),
     nie tylko wewnętrzny wrapper, inaczej zostaje pusty pasek z tytułem. */
  .ss-initial-recommended-section { display: none; }
  .ss-initial-grid { grid-template-columns: 1fr; }
  .ss-initial-grid > .ss-section:first-child { border-right: none; border-bottom: 1px solid #f0f0f0; }

  /* Wyniki: ukryj facety */
  .ss-facets { display: none; }
  .ss-results-layout { display: block; }

  /* .ss-overlay-body--facets ma na desktopie overflow:hidden, bo scroll
     wyników jest delegowany do .ss-results-area (drugiej kolumny obok
     facetów, oba w kontekście flex o zadanej wysokości). Na mobile facety
     są ukryte, a .ss-results-layout traci display:flex (patrz wyżej), więc
     .ss-results-area nigdy nie dostaje policzonej wysokości i jego
     overflow-y:auto nie ma czego przewijać — wyniki wychodzą poza widoczny
     obszar bez możliwości scrolla. Oddajemy scroll z powrotem całemu
     .ss-overlay-body, tak jak w wariancie bez facetów. */
  .ss-overlay-body--facets { overflow-y: auto !important; overflow-x: hidden; }
  .ss-results-area { overflow: visible; height: auto; }

  /* Grid 2 kolumny na mobile */
  .ss-results-list { grid-template-columns: repeat(2, 1fr); }

  /* Mniejsze paddingi */
  .ss-overlay-header      { padding: 12px 14px; gap: 10px; }
  .ss-overlay-logo        { height: 24px; }
  .ss-overlay-suggestions { padding: 8px 14px; }
  .ss-section             { padding: 14px 14px; }
  .ss-footer              { padding: 8px 14px; }
  .ss-item                { padding: 10px 8px; }
}
