/* ============================================================
 * carte-search.css — Omnibox de recherche de la carte /carte
 * Module "Recherche" (search.js). Mobile-first, mode sombre auto.
 * Se greffe sur #sm-search (input) et #sm-search-results (dropdown).
 * Ne style QUE ses propres elements (prefixe .sm-search / .sm-res).
 * ============================================================ */

:root {
  --sm-green: #16a34a;
  --sm-green-dark: #15803d;
  --sm-search-bg: #ffffff;
  --sm-search-fg: #1f2937;
  --sm-search-sub: #6b7280;
  --sm-search-border: #e5e7eb;
  --sm-search-hover: #f3f4f6;
  --sm-search-active: #dcfce7;
  --sm-search-shadow: 0 10px 30px rgba(0, 0, 0, .12);
  --sm-search-radius: 14px;
}

/* ---------- Hero flottant (accroche) ----------
   Barre de recherche mise en avant, flottant en haut de la carte.
   Centree sur desktop ; pleine largeur sur mobile. z-index au-dessus
   des couches (.sm-layers z:30) et du bouton locate. */
.sm-search-wrap {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 24px));
  z-index: 45;
}
/* Ancre le dropdown de resultats sous la barre (et non sous les puces). */
.sm-search-field { position: relative; }

/* La barre : "pill" proeminente (loupe + input + effacer + micro). */
.sm-search-box {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 4px 6px 4px 14px;
  background: var(--sm-search-bg);
  border: 1.5px solid var(--sm-search-border);
  border-radius: var(--sm-search-radius);
  box-shadow: var(--sm-search-shadow);
  transition: border-color .2s ease, box-shadow .2s ease;
}
.sm-search-box:focus-within {
  border-color: var(--sm-green);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, .18), var(--sm-search-shadow);
}

/* Icone loupe (element statique dans la barre). */
.sm-search-icon {
  flex: 0 0 auto;
  width: 20px;
  text-align: center;
  color: var(--sm-green);
  font-size: 17px;
  pointer-events: none;
}

/* Champ de saisie : sans bordure, il herite du cadre de la barre. */
#sm-search,
.sm-search-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  min-height: 44px;             /* zone tactile */
  padding: 0;
  font-size: 16px;              /* evite le zoom iOS */
  line-height: 1.3;
  color: var(--sm-search-fg);
  background: transparent;
  border: none;
  box-shadow: none;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
}
#sm-search::placeholder { color: var(--sm-search-sub); opacity: 1; }
/* neutralise la croix native du type=search (on gere notre bouton) */
#sm-search::-webkit-search-cancel-button,
#sm-search::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }

/* Boutons ronds "effacer" et "micro" (le micro est injecte par le JS). */
.sm-search-clear,
.sm-search-mic {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  min-width: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--sm-search-sub);
  cursor: pointer;
  font-size: 15px;
  transition: background .2s ease, color .2s ease;
}
.sm-search-clear[hidden] { display: none; }
.sm-search-clear:hover,
.sm-search-mic:hover { background: var(--sm-search-hover); color: var(--sm-green); }
.sm-search-clear:focus-visible,
.sm-search-mic:focus-visible {
  outline: 2px solid var(--sm-green);
  outline-offset: 2px;
}
.sm-search-mic.is-listening {
  color: #ef4444;
  animation: sm-mic-pulse 1.2s infinite;
}
@keyframes sm-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .4); }
  50%      { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* ---------- Puces d'exemples (accroche cliquable) ---------- */
.sm-search-hints {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 2px 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.sm-search-hints::-webkit-scrollbar { display: none; }
.sm-hint {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  border: 1px solid var(--sm-search-border);
  border-radius: 999px;
  background: var(--sm-search-bg);
  color: var(--sm-search-fg);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .14);
  transition: background .15s ease, color .15s ease, border-color .15s ease, transform .1s ease;
}
.sm-hint i { font-size: 12px; color: var(--sm-green); }
.sm-hint:hover { transform: translateY(-1px); border-color: var(--sm-green); }
.sm-hint:active { transform: translateY(0); }
.sm-hint:focus-visible { outline: 2px solid var(--sm-green); outline-offset: 2px; }

/* ---------- Responsive du hero (evite le chevauchement avec .sm-layers) ---------- */
/* Bande intermediaire : les couches restent en haut a gauche ; on ancre la
   barre a droite pour ne pas les recouvrir. */
@media (min-width: 521px) and (max-width: 767px) {
  .sm-search-wrap {
    left: auto;
    right: 12px;
    transform: none;
    width: min(400px, calc(100% - 176px));
  }
}
/* Mobile : barre pleine largeur en haut ; les puces passent SOUS la rangee
   de filtres (.sm-layers repositionnee a top:64px par carte-core.css). */
@media (max-width: 520px) {
  .sm-search-wrap {
    top: 10px;
    left: 10px;
    right: 10px;
    width: auto;
    transform: none;
  }
  .sm-search-hints { margin-top: 52px; }
}

/* ---------- Dropdown des resultats ---------- */
#sm-search-results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 1200;
  max-height: min(60vh, 420px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--sm-search-bg);
  border: 1px solid var(--sm-search-border);
  border-radius: var(--sm-search-radius);
  box-shadow: var(--sm-search-shadow);
  padding: 6px;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
#sm-search-results.is-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
#sm-search-results[hidden] { display: none; }

/* Groupes categorises */
.sm-search-group + .sm-search-group {
  margin-top: 2px;
  border-top: 1px solid var(--sm-search-border);
  padding-top: 4px;
}
.sm-search-group-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--sm-search-sub);
  padding: 6px 10px 4px;
}

/* Un resultat */
.sm-search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 7px 10px;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  transition: background .15s ease;
}
.sm-search-item.is-active,
.sm-search-item:hover {
  background: var(--sm-search-hover);
}
.sm-search-item.is-active {
  box-shadow: inset 0 0 0 1.5px rgba(22, 163, 74, .35);
}

/* Pastille de ligne (badge colore) */
.sm-res-badge {
  flex: 0 0 auto;
  min-width: 30px;
  height: 26px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  font-weight: 800;
  font-size: 13px;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .15);
}

/* Icone ronde pour arrets / lieux / communes */
.sm-res-icon {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, .04);
  font-size: 14px;
}

.sm-res-text {
  display: flex;
  flex-direction: column;
  min-width: 0; /* pour l'ellipse */
  flex: 1 1 auto;
}
.sm-res-label {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--sm-search-fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sm-res-sub {
  font-size: 12px;
  color: var(--sm-search-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Etat vide */
.sm-search-empty {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px;
  color: var(--sm-search-sub);
  font-size: 13.5px;
}

/* Scrollbar discrete */
#sm-search-results::-webkit-scrollbar { width: 8px; }
#sm-search-results::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, .18);
  border-radius: 8px;
}

/* ---------- Mode sombre ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --sm-search-bg: #1f2430;
    --sm-search-fg: #f3f4f6;
    --sm-search-sub: #9ca3af;
    --sm-search-border: #374151;
    --sm-search-hover: #2b3242;
    --sm-search-active: #14532d;
    --sm-search-shadow: 0 12px 34px rgba(0, 0, 0, .5);
  }
  .sm-hint { box-shadow: 0 2px 10px rgba(0, 0, 0, .5); }
  .sm-res-icon { background: rgba(255, 255, 255, .06); }
  #sm-search-results::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .18); }
}

/* Support d'un theme force par attribut (coherence avec le reste du site) */
:root[data-theme="dark"] {
  --sm-search-bg: #1f2430;
  --sm-search-fg: #f3f4f6;
  --sm-search-sub: #9ca3af;
  --sm-search-border: #374151;
  --sm-search-hover: #2b3242;
  --sm-search-active: #14532d;
  --sm-search-shadow: 0 12px 34px rgba(0, 0, 0, .5);
}

/* Reduit les animations si l'utilisateur le demande */
@media (prefers-reduced-motion: reduce) {
  #sm-search,
  #sm-search-results,
  .sm-search-item,
  .sm-search-box,
  .sm-search-clear,
  .sm-hint,
  .sm-search-mic {
    transition: none;
  }
  .sm-hint:hover { transform: none; }
  .sm-search-mic.is-listening { animation: none; }
}

/* Petits ecrans : dropdown un peu plus dense */
@media (max-width: 480px) {
  #sm-search-results { max-height: 55vh; }
  .sm-res-label { font-size: 14px; }
}
