/**
 * HatSearch - panneau de recherche.
 *
 * Le panneau est centre au-dessus de la page, dans un calque a lui : il ne
 * depend donc ni de la largeur du bloc de recherche du theme, ni de sa
 * position dans l'en-tete.
 *
 * Aucune police distante, aucune image : le panneau doit s'afficher
 * instantanement au premier clic.
 */

.hatsearch-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px 16px;
  overflow-y: auto;
}

.hatsearch-overlay[hidden] {
  display: none;
}

/* Empeche la page de defiler derriere le panneau ouvert. */
body.hatsearch-locked {
  overflow: hidden;
}

.hatsearch-panel {
  width: 100%;
  /* Large, comme le panneau de Motive : les vignettes respirent et la
     colonne de filtres ne mange plus la moitie de la place utile. */
  max-width: 1400px;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  animation: hatsearch-in 0.14s ease-out;
}

@keyframes hatsearch-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hatsearch-panel {
    animation: none;
  }
}

/* --- Champ de saisie ------------------------------------------------- */

.hatsearch-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

/* Le logo occupe exactement la largeur du volet de filtres : il se pose
   ainsi au-dessus de la colonne, pas a cote du champ de saisie. */
.hatsearch-brand {
  flex: 0 0 220px;
  display: flex;
  align-items: center;
  max-height: 56px;
}

/*
 * Un logo dessine en blanc ou en dore disparait sur le fond blanc du
 * panneau. Le module mesure l'encre du logo a l'installation et pose ce
 * fond sombre quand il le faut -- pas de reglage a faire boutique par
 * boutique.
 */
.hatsearch-brand--sombre {
  background: #1c1c1c;
  border-radius: 4px;
  padding: 6px 10px;
  box-sizing: border-box;
}

.hatsearch-brand img {
  max-width: 100%;
  max-height: 56px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.hatsearch-brand--sombre img {
  max-height: 44px;
}

.hatsearch-icon {
  display: flex;
  opacity: 0.5;
  flex: 0 0 auto;
}

.hatsearch-input {
  flex: 1 1 auto;
  border: 0;
  outline: none;
  font-size: 22px;
  line-height: 1.4;
  padding: 6px 0;
  background: transparent;
  color: inherit;
  min-width: 0;
}

/*
 * Le navigateur ajoute sa propre croix de vidage sur un champ de type
 * « search ». A cote de notre bouton de fermeture, cela faisait deux croix
 * voisines qui ne font pas la meme chose. On garde la notre : refermer le
 * panneau importe plus que vider le champ, qu'on vide en selectionnant.
 */
.hatsearch-input::-webkit-search-cancel-button,
.hatsearch-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

.hatsearch-close {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  font-size: 30px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  opacity: 0.45;
}

.hatsearch-close:hover,
.hatsearch-close:focus-visible {
  opacity: 1;
}

/* --- Deux colonnes : filtres a gauche, resultats a droite -------------- */

.hatsearch-content {
  display: flex;
  align-items: flex-start;
}

.hatsearch-filters {
  flex: 0 0 226px;
  padding: 16px 14px 20px 18px;
  border-right: 1px solid rgba(0, 0, 0, 0.1);
  align-self: stretch;
}

.hatsearch-filters:empty {
  display: none;
}

.hatsearch-results {
  flex: 1 1 auto;
  min-width: 0;
  padding: 16px 18px 20px;
  transition: opacity 0.12s;
}

.hatsearch-results.is-loading {
  opacity: 0.45;
}

.hatsearch-filter {
  margin-bottom: 20px;
}

.hatsearch-filter:last-child {
  margin-bottom: 0;
}

.hatsearch-filter-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.7;
}

/* --- Cases a cocher : marques et disponibilite -------------------------- */

.hatsearch-checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
}

.hatsearch-checklist li {
  margin-bottom: 2px;
}

.hatsearch-checklist label {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 3px 0;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  line-height: 1.3;
}

.hatsearch-checklist input {
  margin: 0;
  flex: 0 0 auto;
}

.hatsearch-check-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hatsearch-check-count {
  flex: 0 0 auto;
  font-size: 11px;
  opacity: 0.55;
}

.hatsearch-toggle-brands {
  margin-top: 6px;
  border: 0;
  background: none;
  padding: 0;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  color: inherit;
  opacity: 0.75;
}

.hatsearch-hint,
.hatsearch-corrected,
.hatsearch-count {
  margin: 0 0 12px;
  font-size: 14px;
  opacity: 0.75;
}

.hatsearch-count {
  font-weight: 600;
  opacity: 1;
}

/* --- Suggestions de termes -------------------------------------------- */

.hatsearch-suggestions {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 16px;
  padding: 0;
}

.hatsearch-chip {
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: transparent;
  border-radius: 16px;
  padding: 5px 14px;
  font-size: 13px;
  cursor: pointer;
  color: inherit;
}

.hatsearch-chip:hover,
.hatsearch-chip:focus-visible {
  background: rgba(0, 0, 0, 0.06);
}

.hatsearch-chip mark {
  background: transparent;
  font-weight: 700;
  color: inherit;
}

/* --- Curseur de prix -------------------------------------------------- */

.hatsearch-price-values {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
}

/* Relief du catalogue : ou se concentre l'offre. */
.hatsearch-histogram {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 34px;
  padding: 0 9px;
}

.hatsearch-histogram span {
  flex: 1 1 0;
  background: currentColor;
  opacity: 0.16;
  border-radius: 1px 1px 0 0;
  min-height: 2px;
}

.hatsearch-track {
  position: relative;
  height: 26px;
  padding: 0 9px;
}

.hatsearch-track::before {
  content: '';
  position: absolute;
  left: 9px;
  right: 9px;
  top: 11px;
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.12);
}

.hatsearch-range {
  position: absolute;
  top: 11px;
  height: 4px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.75;
  pointer-events: none;
}

/*
 * Les deux curseurs sont superposes et transparents : seule la poignee
 * reste cliquable, sinon celui du dessus intercepte tous les clics et la
 * poignee du dessous devient inatteignable.
 */
.hatsearch-thumb {
  position: absolute;
  left: 9px;
  right: 9px;
  top: 3px;
  width: calc(100% - 18px);
  height: 20px;
  margin: 0;
  background: none;
  appearance: none;
  -webkit-appearance: none;
  pointer-events: none;
}

.hatsearch-thumb:focus {
  outline: none;
}

.hatsearch-thumb::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid currentColor;
  cursor: grab;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
}

.hatsearch-thumb::-moz-range-thumb {
  pointer-events: auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid currentColor;
  cursor: grab;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
}

.hatsearch-thumb:focus-visible::-webkit-slider-thumb {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.hatsearch-thumb:focus-visible::-moz-range-thumb {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.hatsearch-thumb::-webkit-slider-runnable-track,
.hatsearch-thumb::-moz-range-track {
  background: none;
  border: none;
}

/* --- Champ greffe en tete du menu mobile ------------------------------ */

/*
 * Ces regles vivent hors du panneau : elles habillent un element pose dans
 * le menu du theme. D'ou les selecteurs prudents et les valeurs neutres --
 * chaque theme a ses couleurs, on ne fait qu'un cadre discret.
 */
/*
 * Masque par defaut : le meme menu sert de barre horizontale sur ordinateur,
 * ou le champ du theme reste accessible. Le champ greffe ne se montre que
 * sur les largeurs ou le menu devient un volet deroulant.
 */
.hatsearch-menu-search {
  display: none;
  list-style: none;
  padding: 12px 14px;
}

@media (max-width: 991px) {
  .hatsearch-menu-search {
    display: block;
  }
}

.hatsearch-menu-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid rgba(128, 128, 128, 0.45);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.9);
  color: #444;
  font-size: 15px;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
}

.hatsearch-menu-btn:hover,
.hatsearch-menu-btn:focus-visible {
  border-color: rgba(0, 0, 0, 0.55);
}

.hatsearch-menu-btn svg {
  flex: 0 0 auto;
  opacity: 0.6;
}

/* --- Produits : deux lignes de cinq ----------------------------------- */

.hatsearch-products {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin: 0;
  padding: 0;
}

.hatsearch-product a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  /* Peu de marge laterale : l'image doit remplir son encart. */
  padding: 8px 7px 11px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  text-align: center;
  text-decoration: none;
  color: inherit;
  height: 100%;
}

.hatsearch-product a:hover,
.hatsearch-product.is-active a {
  border-color: rgba(0, 0, 0, 0.25);
  background: rgba(0, 0, 0, 0.02);
}

/* Le cadre qui borne le zoom. Sans lui, l'image agrandie deborderait sur
   ses voisines et la grille sauterait au passage de la souris. */
.hatsearch-media {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  /* Filet pour les navigateurs sans aspect-ratio. */
  min-height: 96px;
  overflow: hidden;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.03);
  flex: 0 0 auto;
}

.hatsearch-product img,
.hatsearch-noimage {
  display: block;
  width: 100%;
  height: 100%;
  /* contain, pas cover : une carabine rognee n'est plus reconnaissable. */
  object-fit: contain;
}

/* Le zoom n'a de sens qu'avec un vrai survol. Sur mobile, un :hover reste
   colle au dernier element touche. */
@media (hover: hover) and (pointer: fine) {
  .hatsearch-product img {
    transition: transform 0.18s ease-out;
  }

  .hatsearch-product a:hover img,
  .hatsearch-product.is-active img {
    transform: scale(1.14);
  }
}

@media (prefers-reduced-motion: reduce) {
  .hatsearch-product img {
    transition: none;
  }
}

.hatsearch-name {
  font-size: 14px;
  line-height: 1.4;
  /* Deux lignes maximum : au-dela, les vignettes se desalignent. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- Pastille de disponibilite ---------------------------------------- */

/*
 * « badge » et non « stock » : la section du volet de filtres porte deja la
 * classe .hatsearch-stock, et lui appliquer ce display: inline-flex mettait
 * son titre et ses options cote a cote.
 */
.hatsearch-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  line-height: 1.2;
  margin-top: auto;
  padding-top: 3px;
  opacity: 0.85;
}

.hatsearch-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
  /* Un liseré : sur fond blanc, le jaune-orange manque de contraste. */
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.hatsearch-badge--in .hatsearch-dot {
  background: #2e9e4f;
}

.hatsearch-badge--order .hatsearch-dot {
  background: #e8901c;
}

.hatsearch-badge--out .hatsearch-dot {
  background: #d0342c;
}

.hatsearch-price-tag {
  font-size: 16px;
  font-weight: 700;
  margin-top: 2px;
}

/* --- Voir plus -------------------------------------------------------- */

.hatsearch-more {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.hatsearch-more-btn {
  border: 1px solid rgba(0, 0, 0, 0.2);
  background: transparent;
  border-radius: 3px;
  padding: 9px 26px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: inherit;
}

.hatsearch-more-btn:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.05);
}

.hatsearch-more-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* --- Lecteurs d'ecran -------------------------------------------------- */

.hatsearch-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Ecrans etroits ---------------------------------------------------- */

@media (max-width: 991px) {
  /* Le volet passe au-dessus des resultats : cote a cote, il ne reste
     plus assez de largeur pour cinq vignettes. */
  .hatsearch-content {
    flex-direction: column;
  }

  .hatsearch-filters {
    flex: 1 1 auto;
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding: 14px 18px;
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
  }

  .hatsearch-filter {
    flex: 1 1 200px;
    margin-bottom: 0;
  }

  .hatsearch-checklist {
    max-height: 150px;
  }

  .hatsearch-results {
    width: 100%;
  }
}

@media (max-width: 767px) {
  .hatsearch-overlay {
    padding: 0;
  }

  .hatsearch-panel {
    max-width: none;
    min-height: 100%;
    border-radius: 0;
  }

  .hatsearch-input {
    font-size: 16px; /* en dessous, iOS zoome sur le champ */
  }

  /* Sur telephone, la largeur va au champ de saisie. */
  .hatsearch-brand {
    display: none;
  }

  /* Sur telephone, ce qu'on vient chercher, ce sont les produits. Empiles
     au-dessus, prix + marques + disponibilite remplissent tout l'ecran et
     il faut defiler longtemps avant d'apercevoir le premier resultat. */
  .hatsearch-results {
    order: 1;
  }

  .hatsearch-filters {
    order: 2;
    border-bottom: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
  }

  /* Cinq colonnes deviennent illisibles : on defile horizontalement.
     Une seule rangee, quel que soit le nombre de produits : deux rangees
     qui defilent chacune dans son sens sont impraticables au pouce. */
  .hatsearch-products {
    grid-template-columns: none;
    grid-auto-flow: column;
    /* En vw, pas en % : dans une grille qui deborde horizontalement, un
       pourcentage se calcule sur la largeur du contenu, pas sur l ecran. */
    grid-auto-columns: minmax(150px, 44vw);
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
  }

  .hatsearch-product {
    scroll-snap-align: start;
  }
}
