/* Barre de recherche et son panneau de suggestions.
 *
 * ce fichier ne suppose rien de home.css ni de header.css
 */

.recherche {
    position: relative;
    flex: 1 1 auto;
    max-width: 460px;
    min-width: 0;
}

/* le champ */

.recherche__form {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--background);
    padding: 10px 14px;
    border-radius: 24px;
    border: 1px solid transparent;
    transition: border-color 0.18s ease, background 0.18s ease,
                box-shadow 0.18s ease;
}

.recherche__form:focus-within {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgb(247 127 0 / 12%);
}

/* Coins du bas redressés quand le panneau est ouvert : le champ et la
   liste doivent lire comme une seule surface, pas deux pastilles. */
.recherche.est-ouverte .recherche__form {
    border-radius: 24px 24px 12px 12px;
}

.recherche__loupe {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--text-secondary);
    transition: color 0.18s ease;
}

.recherche__form:focus-within .recherche__loupe {
    color: var(--primary);
}

.recherche__input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-primary);
}

.recherche__input::placeholder {
    color: var(--text-secondary);
}

/* Le X natif de Safari/Chrome ferait doublon avec notre bouton. */
.recherche__input::-webkit-search-cancel-button {
    display: none;
}

.recherche__effacer,
.recherche__retour,
.recherche__valider {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.recherche__effacer:hover,
.recherche__retour:hover,
.recherche__valider:hover {
    background: var(--border);
    color: var(--text-primary);
}

.recherche__effacer .icon-lucide,
.recherche__retour .icon-lucide,
.recherche__valider .icon-lucide {
    width: 15px;
    height: 15px;
}

.recherche__effacer[hidden] {
    display: none;
}

.recherche__panneau {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 1200;
    max-height: min(70vh, 460px);
    /* `hidden auto` et pas seulement `auto` : un titre trop long créait
       un défilement horizontal qui décalait tout le panneau. */
    overflow: hidden auto;
    overscroll-behavior: contain;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 32px rgb(0 0 0 / 12%);
    animation: recherche-apparait 0.14s ease;
}

.recherche__panneau[hidden] {
    display: none;
}

@keyframes recherche-apparait {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Une animation d'entrée est un confort, pas une information : on la
   retire pour qui a demandé moins de mouvement. */
@media (prefers-reduced-motion: reduce) {
    .recherche__panneau { animation: none; }
    .recherche__form,
    .recherche__effacer,
    .recherche__ligne { transition: none; }
}

.recherche__section + .recherche__section {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid var(--border);
}

.recherche__titre-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.recherche__vider {
    padding: 0;
    background: none;
    border: none;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: normal;
    text-transform: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.recherche__vider:hover {
    color: var(--primary);
    text-decoration: underline;
}

.recherche__ligne {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.12s ease;
}

/* Une seule règle pour la souris et le clavier : sans ça, deux lignes
   peuvent sembler sélectionnées en même temps. */
.recherche__ligne:hover,
.recherche__ligne.est-active {
    background: var(--primary-light);
}

/* Une ligne « récente » porte un bouton de suppression. Un <button> à
   l'intérieur d'un <a> est du HTML invalide, donc le lien n'occupe que
   la partie cliquable et le bouton reste son voisin. */
.recherche__ligne-lien {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.recherche__ligne-icone {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
}

.recherche__ligne-icone .icon-lucide {
    width: 15px;
    height: 15px;
}

.recherche__ligne-texte {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
}

/* La portion déjà tapée reste en gris, le reste passe en gras : l'œil
   voit immédiatement ce que la suggestion ajoute à sa frappe. */
.recherche__ligne-texte strong {
    font-weight: 700;
}

.recherche__ligne-supprimer {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s ease, background 0.12s ease;
}

.recherche__ligne:hover .recherche__ligne-supprimer,
.recherche__ligne.est-active .recherche__ligne-supprimer,
.recherche__ligne-supprimer:focus-visible {
    opacity: 1;
}

.recherche__ligne-supprimer:hover {
    background: var(--border);
    color: var(--text-primary);
}

.recherche__ligne-supprimer .icon-lucide {
    width: 13px;
    height: 13px;
}

.recherche__ligne--produit {
    gap: 12px;
    padding: 7px 10px;
}

.recherche__vignette {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--background);
}

.recherche__vignette--vide {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 14px;
}

/* `display: block` sur les deux enfants, et pas seulement sur le
   conteneur : un enfant de flex est blockifié, mais ses propres enfants
   ne le sont pas. Tant qu'ils restent inline, le prix se colle au titre
   et `text-overflow: ellipsis` ne s'applique pas — le titre déborde
   alors du panneau et pousse tout le contenu de côté. */
.recherche__produit-infos {
    display: block;
    flex: 1;
    min-width: 0;
}

.recherche__produit-titre {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    line-height: 1.35;
}

.recherche__produit-prix {
    display: block;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--primary);
}

.recherche__pied {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 4px;
    padding: 9px 10px;
    border-top: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
}

.recherche__pied:hover,
.recherche__pied.est-active {
    background: var(--primary-light);
}

.recherche__etat {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 12px;
    font-size: 13px;
    color: var(--text-secondary);
}

.recherche__etat--vide,
.recherche__etat--erreur {
    flex-direction: column;
    gap: 6px;
    padding: 22px 16px;
    text-align: center;
}

.recherche__etat-titre {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.recherche__reessayer {
    margin-top: 4px;
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
}

.recherche__reessayer:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Trois barres qui pulsent plutôt qu'un spinner : elles occupent la
   place que les vraies lignes prendront, donc le panneau ne saute pas
   quand les résultats arrivent. */
.recherche__squelette {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 10px;
}

.recherche__squelette-bloc {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg,
        var(--background) 25%, var(--border) 50%, var(--background) 75%);
    background-size: 200% 100%;
    animation: recherche-pulse 1.2s ease-in-out infinite;
}

.recherche__squelette-bloc--vignette {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
}

.recherche__squelette-bloc--texte {
    flex: 1;
}

@keyframes recherche-pulse {
    from { background-position: 200% 0; }
    to   { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .recherche__squelette-bloc {
        animation: none;
        background: var(--border);
    }
}

/* Visible des lecteurs d'écran, invisible à l'œil. */
.recherche__annonce {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ── Variante mobile ──────────────────────────────────────────────── */

.recherche--mobile {
    max-width: none;
    width: 100%;
}

.recherche--mobile .recherche__form {
    background: var(--surface);
    border-color: var(--border);
    border-radius: var(--radius-md);
}

/* L'overlay mobile ne fait que 64px de haut : le panneau déborde
   par-dessus la page. Il lui faut donc sa propre surface et son ombre,
   contrairement au desktop où il prolonge visuellement l'en-tête. */
.recherche--mobile .recherche__panneau {
    max-height: calc(100dvh - 100px);
    box-shadow: 0 16px 40px rgb(0 0 0 / 16%);
}

.recherche--mobile.est-ouverte .recherche__form {
    border-radius: var(--radius-md);
}

/* Cibles tactiles : 44px est le minimum confortable au doigt. */
.recherche--mobile .recherche__ligne {
    padding: 11px 10px;
}

.recherche--mobile .recherche__ligne-supprimer {
    width: 32px;
    height: 32px;
    opacity: 1;
}

/* Reprend le palier que .header-search occupait avant : à cette
   largeur, la nav et les actions ont besoin de la place. */
@media (max-width: 1024px) {
    .recherche--header {
        max-width: 320px;
    }
}

@media (max-width: 768px) {
    .recherche--header {
        display: none;
    }
}
