/**
 * Besearch — panneau de recherche plein écran.
 *
 * Le champ de recherche du thème n'est pas touché : il garde son apparence et
 * ne sert plus que de déclencheur. Seul le panneau est habillé.
 *
 * L'aspect reprend celui de Besearch Lite : cartes blanches à angles droits,
 * prix en bleu suivi d'une pastille fléchée, étiquette de promotion rouge.
 * Deux largeurs cohabitent volontairement — la barre de recherche est centrée
 * dans une colonne lisible, les résultats occupent tout l'écran.
 *
 * Sur téléphone, le panneau ne cherche pas à ressembler à sa version bureau :
 * la croix devient « Annuler », les effets de survol disparaissent au profit
 * d'un retour au toucher, et le clavier se retire dès qu'on fait défiler.
 */

.besearch-locked {
    overflow: hidden;
}

.besearch-overlay {
    position: fixed;
    inset: 0;
    /* dvh suit la barre d'outils mobile, qui se rétracte au défilement ;
       sans cela le bas du panneau passe sous elle sur iOS. */
    height: 100dvh;
    overflow: hidden;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    background: #fff;
    font-size: 15px;
    line-height: 1.45;
    color: #1f2937;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    animation: besearch-in 0.14s ease-out;
}

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

@keyframes besearch-in {
    from {
        opacity: 0;
    }
}

/* ------------------------------------------------------------------ entête */

.besearch-head {
    position: relative;
    flex: 0 0 auto;
    padding: 20px 20px 14px;
    /* Une encoche d'écran ne doit pas rogner la barre de recherche. */
    padding-top: max(20px, env(safe-area-inset-top));
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
}

/* La colonne centrée : logo, champ et fermeture restent groupés au milieu,
   quelle que soit la largeur de l'écran. */
.besearch-head-inner {
    box-sizing: border-box;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

.besearch-bar {
    display: flex;
    align-items: center;
    gap: 15px;
}

.besearch-logo {
    max-height: 40px;
    width: auto;
    flex: 0 0 auto;
}

.besearch-field {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    border-radius: 4px;
    background: #f9fafb;
    transition: background 0.2s, box-shadow 0.2s;
}

.besearch-field:focus-within {
    background: #fff;
    box-shadow: 0 0 0 2px #e5e7eb;
}

.besearch-icon {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    color: #9ca3af;
}

.besearch-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 16px 0;
    border: 0;
    background: none;
    font: inherit;
    /* 16 px minimum : en dessous, iOS agrandit la page à la mise au point. */
    font-size: 16px;
    color: inherit;
    outline: none;
    -webkit-appearance: none;
}

.besearch-input::placeholder {
    color: #9ca3af;
    opacity: 1;
}

.besearch-input::-webkit-search-cancel-button {
    display: none;
}

.besearch-close {
    display: flex;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    background: transparent;
    color: #000;
    font: inherit;
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
}

.besearch-close:hover {
    color: #ef4444;
    transform: rotate(90deg);
}

.besearch-close:focus-visible {
    outline: 2px solid var(--besearch-accent, #3b82f6);
    outline-offset: 2px;
    border-radius: 6px;
}

.besearch-close svg {
    width: 28px;
    height: 28px;
}

/* Le mot « Annuler » ne sert qu'au téléphone. */
.besearch-cancel {
    display: none;
}

.besearch-stats {
    max-width: 1200px;
    margin: 12px auto 0;
    color: #6b7280;
    font-size: 13px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    min-height: 18px;
}

/* Fine barre de progression sous l'entête.
   Elle remplace l'assombrissement des résultats, qui donnait l'impression que
   la page s'éteignait à chaque frappe. */
.besearch-progress {
    position: absolute;
    right: 0;
    bottom: -1px;
    left: 0;
    height: 2px;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.15s;
}

.besearch-overlay.is-loading .besearch-progress {
    opacity: 1;
}

.besearch-progress::after {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 40%;
    background: var(--besearch-accent, #3b82f6);
    content: '';
    animation: besearch-slide 1s ease-in-out infinite;
}

@keyframes besearch-slide {
    from {
        left: -40%;
    }
    to {
        left: 100%;
    }
}

/* -------------------------------------------------------------------- corps */

.besearch-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: #fff;
}

/* Les résultats prennent tout l'écran : aucune limite de largeur. */
.besearch-grid {
    display: grid;
    box-sizing: border-box;
    width: 100%;
    padding: 30px 20px 8px;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}

/* -------------------------------------------------------------------- carte */

.besearch-card {
    display: flex;
    /* Sans cela, un titre sans espace impose sa largeur à la colonne et fait
       déborder toute la grille — visible sur téléphone. */
    min-width: 0;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    background: #fff;
    color: inherit;
    text-decoration: none;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.besearch-card:hover,
.besearch-card.is-active {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
}

.besearch-card:focus-visible {
    outline: 2px solid var(--besearch-accent, #3b82f6);
    outline-offset: 2px;
}

.besearch-media {
    position: relative;
    display: block;
    overflow: hidden;
    /* Sans cela, la vignette s'étire pour combler la hauteur de la rangée et
       décale le titre d'une carte à l'autre. */
    flex: 0 0 auto;
    /* Rapport constant : la grille ne saute pas pendant le chargement des images. */
    aspect-ratio: 1 / 1;
    /* min-height: auto, valeur par défaut d'un élément flexible, laissait une
       image plus haute que large repousser le bas de la vignette : mesuré à
       259 px au lieu de 207, et le titre de cette carte tombait plus bas que
       celui de ses voisines. */
    min-height: 0;
    background: #fff;
}

/* Hors du flux : l'image ne peut plus imposer sa hauteur à la vignette. */
.besearch-media img,
.besearch-media--empty {
    position: absolute;
    inset: 15px;
    display: block;
    width: calc(100% - 30px);
    height: calc(100% - 30px);
    object-fit: contain;
}

.besearch-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 1;
    padding: 4px 12px;
    border-radius: 6px;
    background: #ef4444;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
}

.besearch-card-body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 4px;
    padding: 12px 16px 16px;
}

.besearch-card-meta {
    overflow: hidden;
    color: #9ca3af;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.besearch-card-title {
    display: -webkit-box;
    overflow: hidden;
    /* Deux lignes maximum : les titres produits sont souvent interminables. */
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    color: #1f2937;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.3;
}

.besearch-card-price {
    display: flex;
    margin-top: auto;
    padding-top: 10px;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.besearch-price {
    min-width: 0;
    color: var(--besearch-accent, #3b82f6);
    font-size: 16px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.besearch-price s {
    margin-right: 6px;
    color: #9ca3af;
    font-size: 14px;
    font-weight: 400;
}

.besearch-arrow {
    display: flex;
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--besearch-accent, #3b82f6);
    color: #fff;
    transition: background 0.3s ease, transform 0.3s ease;
}

.besearch-arrow svg {
    width: 16px;
    height: 16px;
}

.besearch-card:hover .besearch-arrow {
    filter: brightness(0.9);
    transform: translateX(4px);
}

.besearch-empty {
    grid-column: 1 / -1;
    margin: 0;
    padding: 60px 20px;
    color: #6b7280;
    font-size: 18px;
    text-align: center;
}

/* ----------------------------------------------------------- gabarits d'attente */

/* Une page blanche pendant deux cents millisecondes paraît plus longue qu'une
   page déjà structurée : l'œil n'a rien à quoi se raccrocher. */
.besearch-card--ghost {
    pointer-events: none;
    animation: besearch-pulse 1.1s ease-in-out infinite;
}

.besearch-card--ghost:hover {
    transform: none;
    box-shadow: none;
}

.besearch-card--ghost .besearch-media {
    background: #f3f4f6;
}

.besearch-ghost-line {
    height: 12px;
    border-radius: 3px;
    background: #f3f4f6;
}

.besearch-ghost-line--short {
    width: 55%;
    margin-top: 4px;
}

@keyframes besearch-pulse {
    50% {
        opacity: 0.55;
    }
}

/* --------------------------------------------------- chargement progressif */

.besearch-more {
    display: flex;
    justify-content: center;
    padding: 24px 0 56px;
}

.besearch-more[hidden] {
    display: none;
}

.besearch-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e5e7eb;
    border-top-color: var(--besearch-accent, #3b82f6);
    border-radius: 50%;
    animation: besearch-spin 1s linear infinite;
}

@keyframes besearch-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ------------------------------------------------------------ grand écran */

@media (min-width: 1440px) {
    .besearch-grid {
        grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    }
}

@media (min-width: 1920px) {
    .besearch-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

/* ------------------------------------------------------------------ mobile */

@media (max-width: 768px) {
    /* Le logo mange la moitié d'une barre déjà étroite ; le champ prime. */
    .besearch-logo {
        display: none;
    }

    .besearch-head {
        padding: 10px 12px 8px;
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .besearch-bar {
        gap: 4px;
    }

    .besearch-field {
        padding: 0 14px;
        /* La pastille arrondie des recherches natives d'iOS et d'Android. */
        border-radius: 10px;
        background: #eef0f3;
    }

    .besearch-input {
        padding: 11px 0;
    }

    /* La croix cède la place au mot : cible plus large, intention plus claire. */
    .besearch-close {
        width: auto;
        height: auto;
        padding: 10px 4px 10px 12px;
        color: var(--besearch-accent, #3b82f6);
        font-size: 16px;
    }

    .besearch-close:hover {
        transform: none;
        color: var(--besearch-accent, #3b82f6);
    }

    .besearch-close svg {
        display: none;
    }

    .besearch-cancel {
        display: inline;
        white-space: nowrap;
    }

    .besearch-stats {
        margin-top: 8px;
        font-size: 12px;
    }

    .besearch-grid {
        /* minmax(0, 1fr) et non 1fr : sinon le contenu peut élargir la colonne. */
        grid-template-columns: repeat(2, minmax(0, 1fr));
        padding: 12px 12px 8px;
        gap: 12px;
        /* Barre de navigation gestuelle : la dernière rangée reste atteignable. */
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Le survol n'existe pas au doigt ; ce qui compte est le retour au toucher. */
    .besearch-card:hover {
        transform: none;
        box-shadow: none;
    }

    .besearch-card:active {
        transform: scale(0.97);
        transition-duration: 0.06s;
    }

    .besearch-card:hover .besearch-arrow {
        transform: none;
        filter: none;
    }

    .besearch-media img,
    .besearch-media--empty {
        inset: 10px;
        width: calc(100% - 20px);
        height: calc(100% - 20px);
    }

    .besearch-card-body {
        padding: 10px 12px 12px;
    }

    .besearch-card-title {
        font-size: 13px;
    }

    .besearch-price {
        font-size: 15px;
    }

    .besearch-arrow {
        width: 28px;
        height: 28px;
    }

    .besearch-arrow svg {
        width: 14px;
        height: 14px;
    }

    .besearch-badge {
        top: 8px;
        right: 8px;
        padding: 3px 9px;
        font-size: 11px;
    }

    .besearch-more {
        padding: 16px 0 40px;
    }

    .besearch-spinner {
        width: 30px;
        height: 30px;
        border-width: 3px;
    }
}

/* Au-delà du téléphone mais avant l'écran large : trois colonnes valent mieux
   que deux étirées. */
@media (min-width: 521px) and (max-width: 768px) {
    .besearch-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (prefers-reduced-motion: reduce) {
    .besearch-overlay,
    .besearch-card,
    .besearch-arrow,
    .besearch-card--ghost {
        animation: none !important;
        transition: none !important;
    }

    .besearch-card:hover,
    .besearch-card.is-active {
        transform: none;
    }

    .besearch-progress::after {
        animation-duration: 3s;
    }

    .besearch-spinner {
        animation-duration: 2s;
    }
}
