/**
 * ScenTree — barre de recherche, résultats autocomplete (#barrederesultat),
 * sélecteur de carte (.changeMap) et overlay focus (#content.searchBarActiv).
 */

/* =============================================================================
   Conteneur principal
   ============================================================================= */

.searchBar {
    position: relative;
}

.searchBar > form,
.searchBar > .changeMap {
    box-sizing: border-box;
}

/* Masquage (ex. page login) */
.searchBar--hidden,
.searchBar--hidden .changeMap {
    display: none !important;
}

/* =============================================================================
   Champ de recherche
   ============================================================================= */

.searchBar form {
    background-color: white;
    border-radius: 60px;
    width: 100%;
    transition: all 0.5s ease-in-out;
}

.searchBar form.formCollapse {
    width: 45px;
    border-radius: 12px;
}

.searchBar .searchBarInput {
    height: 45px;
    min-width: 545px;
    border-radius: 60px;
    box-shadow: var(--shadow);
    border: 0;
    padding: 5px 16px;
    display: flex;
    align-items: center;
    line-height: 50px;
    z-index: 10;
    position: relative;
    background-color: transparent;
    cursor: pointer;
    color: var(--grey-dark);
}

.searchBar .searchBarInput::placeholder {
    margin-top: 4px;
}

.searchBar form.formCollapse .searchBarInput {
    border-radius: 12px;
    min-width: 45px;
}

.searchBar form.formCollapse .searchBarInput::placeholder {
    color: transparent;
}

.searchBar input::-webkit-search-cancel-button {
    margin-right: 30px;
    width: 18px;
    height: 18px;
}

.searchBar .searchBarIcon {
    position: absolute;
    top: 15px;
    right: 18px;
    transition: all 0.3s ease-in-out;
}

.searchBar form.formCollapse .searchBarIcon {
    right: 14px;
}

.searchBar input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    background-image: url("./images/icons/xmark-large.svg");
    cursor: pointer;
}

/* =============================================================================
   Résultats autocomplete (#barrederesultat — créé par bootstrap-5-autocomplete.js)
   ============================================================================= */

#barrederesultat {
    max-height: 80vh;
    overflow-x: hidden;
    overflow-y: auto;
    border-radius: 25px;
    background: rgba(255, 121, 91, 0.85);
    font-size: 14px;
    padding: 0;
    border: none;
    box-shadow: var(--shadow);
    inset: 4px auto auto 0 !important;
    box-sizing: border-box;
    max-width: 100%;
}

#barrederesultat .lignerecherche > a:first-child {
    color: var(--white);
    text-wrap: wrap;
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
}

/* Bouton carte uniquement — pas le lien produit quand il est seul (IFRA, etc.) */
#barrederesultat .lignerecherche > a:last-child:not(:first-child) {
    flex: 0 0 auto;
}

#barrederesultat .lignerecherche {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    border-bottom: 1px solid rgba(255, 255, 255, 0.4);
    padding: 20px 25px 20px 20px;
    cursor: pointer;
}

/* Ingrédients non cliquables : pas de <a>, les 3 blocs empilés comme dans un lien */
#barrederesultat .lignerecherche.disabled {
    flex-direction: column;
    align-items: stretch;
}

#barrederesultat .nom_de_l_ingredient,
#barrederesultat .synonymes,
#barrederesultat .numero_cas {
    overflow-wrap: anywhere;
}

#barrederesultat .lignerecherche.disabled .nom_de_l_ingredient,
#barrederesultat .lignerecherche.disabled .synonymes,
#barrederesultat .lignerecherche.disabled .numero_cas {
    color: var(--orange-dark) !important;
}

#barrederesultat .lignerecherche:hover,
#barrederesultat .lignerecherche.selected {
    background-color: var(--orange-hover-dark-bg);
}

#barrederesultat .nom_de_l_ingredient {
    font-family: 'Saira', sans-serif !important;
    font-size: 20px;
    font-weight: 400;
    padding-right: 20px;
    color: var(--white);
    text-wrap: wrap;
}

#barrederesultat .nom_de_l_ingredient .text-highlighted {
    font-size: 20px;
    font-weight: 700;
}

#barrederesultat .synonymes {
    font-weight: 400;
    padding: 5px 0 !important;
    font-size: 12px;
    font-style: italic;
}

#barrederesultat .numero_cas {
    font-weight: 500;
    color: var(--white);
    font-size: 12px;
}

#barrederesultat .lignerecherche a:has(.show-on-map-button),
#barrederesultat .lignerecherche .show-on-map-button {
    cursor: pointer;
}

#barrederesultat .lignerecherche > a:last-child:not(:first-child) {
    cursor: pointer;
}

/* =============================================================================
   Barre « Current map » + liste des cartes (dropdown)
   ============================================================================= */

.searchBar .changeMap {
    position: relative;
    z-index: 10;
    background-color: var(--orange-light);
    height: 40px;
    border-radius: 0 0 12px 12px;
    min-width: 513px;
    max-width: 100%;
    color: var(--grey-dark);
    transition: all 0.2s ease-in-out;
}

.searchBar .changeMap.hide {
    opacity: 0;
    visibility: hidden;
    max-height: 0;
    overflow: hidden;
}

.searchBar .changeMap .dropdown {
    position: static;
}

.searchBar .changeMap .dropdown-toggle {
    background-color: transparent;
    border: none;
    color: var(--orange-dark);
    text-decoration: underline;
    white-space: nowrap;
    height: 35px;
    min-width: 85px;
}

/* Une seule flèche : masquer le caret Bootstrap (::after), garder caret-down.svg */
.searchBar .changeMap .dropdown-toggle::after {
    display: none !important;
}

.searchBar .changeMap .dropdown-toggle img {
    transition: transform 0.3s ease;
}

.searchBar .changeMap .dropdown-toggle[aria-expanded="true"] img {
    transform: rotate(180deg);
}

.searchBar .changeMap .dropdown .dropdown-menu,
.searchBar .changeMap .dropdown-menu {
    border: none;
    border-radius: 12px;
    width: fit-content;
    max-width: 90vw;
    position: absolute !important;
    left: 50% !important;
    top: 100% !important;
    right: auto !important;
    bottom: auto !important;
    inset: auto !important;
    transform: translateX(-50%) !important;
    margin-top: 0 !important;
    font-size: 14px;
    padding: 20px;
    height: 0;
    display: block;
    visibility: hidden;
    overflow: hidden;
    opacity: 0;
    transition: height 0.3s ease-in-out, opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
}

.searchBar .changeMap .dropdown-menu.show {
    transform: translateX(-50%) !important;
    visibility: visible;
    height: auto;
    width: auto;
    opacity: 1;
    overflow: visible;
}

.searchBar .changeMap .dropdown-menu .suppliers-section {
    display: flex;
    flex-direction: column;
}

.searchBar .changeMap .dropdown-menu .suppliers-columns {
    gap: 20px;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.searchBar .changeMap .dropdown-menu .supplier-column {
    flex-shrink: 0;
    min-width: 200px;
    display: flex;
    flex-direction: column;
}

.searchBar .changeMap .dropdown-menu > .d-flex {
    gap: 30px;
    width: fit-content;
}

.searchBar .changeMap .dropdown-menu > .d-flex > .py-2:first-child {
    min-width: 220px;
    flex-shrink: 0;
}

.searchBar .changeMap .dropdown-menu .dropdown-item {
    padding: 8px;
    transition: 0.3s ease-in-out;
}

.searchBar .changeMap .dropdown-menu .dropdown-item:hover {
    background-color: var(--orange-light);
}

.searchBar .changeMap .dropdown-menu .dropdown-item .logoothermaps {
    flex-shrink: 0;
    object-fit: contain;
    height: 30px;
    margin-right: 1rem !important;
}

/* =============================================================================
   Overlay focus recherche (fond orange + flou)
   ============================================================================= */

#content::after,
a#logo,
button.openMenu,
#scentree_map,
.searchBar .changeMap {
    transition: all 0.2s ease-in-out;
}

.blur {
    filter: blur(6px);
    pointer-events: none;
}

#content {
    position: relative;
    z-index: 0;
}

#content::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(145deg, rgba(253, 158, 137, 0.6) 4.55%, rgba(255, 121, 91, 0.7) 96.78%);
    z-index: 400;
    opacity: 0;
    display: none;
}

#content.searchBarActiv::after {
    opacity: 1;
    display: block;
}

/* =============================================================================
   Responsive — tablette (651px – 800px)
   ============================================================================= */

@media screen and (max-width: 800px) and (min-width: 651px) {
    .searchBar .searchBarInput {
        min-width: 400px;
    }

    .searchBar .changeMap {
        min-width: 362px;
    }
}

/* =============================================================================
   Responsive — mobile (< 650px)
   ============================================================================= */

@media screen and (max-width: 650px) {
    .searchBar {
        position: fixed;
        left: 24px;
        right: 24px;
        bottom: 32px;
        display: flex;
        flex-direction: column;
        align-items: stretch;
        overflow: visible;
        box-sizing: border-box;
        z-index: 1100;
    }

    .searchBar > form,
    .searchBar > .changeMap {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        margin-left: 0;
        margin-right: 0;
        flex-shrink: 0;
    }

    .searchBar form {
        width: 100%;
    }

    .searchBar .searchBarInput {
        width: 100%;
        max-width: 100%;
        min-width: 0 !important;
        box-sizing: border-box;
    }

    .searchBar .changeMap {
        min-width: 0 !important;
        padding-left: 16px;
        padding-right: 16px;
        border-radius: 12px 12px 0 0;
        position: relative !important;
        z-index: 10 !important;
        overflow: visible;
    }

    .searchBar .changeMap > span.body2regular {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
        flex: 1 1 auto;
    }

    .searchBar .changeMap .dropdown-toggle {
        min-width: 0;
        flex-shrink: 0;
    }

    /* Liste des cartes : s'ouvre vers le haut (au-dessus de la barre orange) */
    .searchBar .changeMap .dropdown-menu.dropdown-map {
        width: 100% !important;
        position: absolute !important;
        top: auto !important;
        bottom: 100% !important;
        left: 0 !important;
        right: auto !important;
        transform: none !important;
        margin: 0 0 4px 0 !important;
        max-height: min(55vh, 420px);
        overflow-y: auto !important;
        max-width: 100% !important;
    }

    .searchBar .changeMap .dropdown-menu.dropdown-map.show {
        top: auto !important;
        bottom: 100% !important;
        left: 0 !important;
        right: auto !important;
        transform: none !important;
        display: block !important;
        visibility: visible !important;
        height: auto !important;
        opacity: 1 !important;
        overflow-y: auto !important;
        z-index: 1200 !important;
    }

    .searchBar .changeMap .dropdown-menu .dropdown-item .ingredientName {
        font-size: 14px;
        font-weight: 600;
        color: var(--grey-medium);
        padding-left: 50px;
        line-height: 1.2 !important;
    }

    .searchBar .changeMap .dropdown-menu > .d-flex {
        flex-direction: column-reverse;
        gap: 0 !important;
        width: 100% !important;
    }

    .searchBar .changeMap .dropdown-menu > .d-flex > .py-2 {
        width: 100% !important;
        flex-shrink: 1 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .searchBar .changeMap .dropdown-menu .suppliers-columns {
        flex-direction: column !important;
        flex-wrap: wrap !important;
        gap: 0 !important;
        overflow-x: visible !important;
        width: 100% !important;
    }

    .searchBar .changeMap .dropdown-menu .supplier-column {
        width: 100% !important;
        flex-shrink: 1 !important;
    }

    .searchBar .changeMap .dropdown-menu .logoothermaps,
    .searchBar .changeMap .dropdown-menu .nbrIngredient {
        display: none !important;
    }

    /* Ordre inversé uniquement quand la liste est ouverte (.show) — ne pas écraser display:none de Bootstrap */
    #barrederesultat.show {
        top: -66vh !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100%;
        min-width: 0;
        height: 75vh;
        max-height: 70vh;
        display: flex;
        flex-direction: column-reverse;
        justify-content: flex-start;
    }

    #barrederesultat.show .lignerecherche {
        border-bottom: none;
        border-top: 1px solid rgba(255, 255, 255, 0.4);
    }

    #barrederesultat.show .lignerecherche:first-child {
        border-top: none;
    }

    #barrederesultat.show .lignerecherche:last-child {
        border-top: none;
    }

    .leaflet-control-container > div:first-of-type {
        bottom: 130px;
    }
}

@media screen and (max-width: 400px) {
    .searchBar .changeMap .dropdown-toggle {
        justify-content: flex-end;
        padding-right: 8px !important;
    }

    .searchBar .changeMap .dropdown-toggle span {
        display: none;
    }
}
