/* ============================================================
   CONTENEUR PRINCIPAL
   ============================================================ */

.custom-select {
    position: relative;
    width: 100%;
    min-width: 0;
    font-family: inherit;
}

/* Select natif : conservé pour les formulaires */
.custom-select-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ============================================================
   BOUTON PRINCIPAL
   ============================================================ */

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 5px;
    width: 100%;
    height: 33px;
    padding: 10px 5px;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    background: #fff;
    color: #1f2937;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color .2s, box-shadow .2s;
}

.custom-select-trigger:hover,
.custom-select.is-open .custom-select-trigger {
    border-color: #64748b;
}

.custom-select-trigger:focus-visible {
    outline: 2px solid #64748b;
    outline-offset: 2px;
}

.custom-select-value {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-select-value.is-placeholder {
    color: #9ca3af;
}

.custom-select-arrow {
    flex-shrink: 0;
    font-size: 19px;
    transition: transform .2s;
}

.custom-select.is-open .custom-select-arrow {
    transform: rotate(180deg);
}

/* ============================================================
   BOUTON D'EFFACEMENT
   ============================================================ */

.custom-select-clear {
    position: absolute;
    top: 50%;
    right: 35px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 25px;
    height: 25px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #f3f4f6;
    color: #6b7280;
    font-size: 19px;
    line-height: 1;
    cursor: pointer;
    transform: translateY(-50%);
}

.custom-select-clear:hover {
    background: #e5e7eb;
    color: #111827;
}

.custom-select-clear[hidden] {
    display: none;
}

/* ============================================================
   FOND DE PROTECTION DE LA PAGE
   ============================================================ */

.custom-select-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgb(15 23 42 / 18%);
    cursor: default;
}

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

/* Empêcher le défilement de la page pendant l'ouverture */
body.custom-select-popup-open {
    overflow: hidden;
}

/* ============================================================
   FENÊTRE POPUP
   ============================================================ */

.custom-select-dropdown {
    position: fixed;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: calc(100vw - 24px);
    max-height: 280px;
    padding: 7px;
    border: 1px solid #e5e7eb;
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 12px 35px rgb(0 0 0 / 20%);
    animation: custom-select-appear .15s ease-out;
}

.custom-select-dropdown[hidden] {
    display: none;
}

@keyframes custom-select-appear {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

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

/* ============================================================
   TITRE DE LA FENÊTRE
   ============================================================ */

.custom-select-title {
    flex-shrink: 0;
    padding: 9px 10px;
    margin-bottom: 6px;
    border-bottom: 1px solid #e5e7eb;
    color: #1f2937;
    font-size: 14px;
    font-weight: 600;
}

/* ============================================================
   CHAMP DE RECHERCHE
   ============================================================ */

.custom-select-search {
    flex-shrink: 0;
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    margin-bottom: 6px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #f9fafb;
    color: #1f2937;
    font: inherit;
    outline: none;
}

.custom-select-search:focus {
    border-color: #64748b;
}

.custom-select-search:disabled {
    opacity: .6;
    cursor: not-allowed;
}

/* ============================================================
   LISTE DES OPTIONS
   ============================================================ */

.custom-select-options {
    overflow-y: auto;
    min-height: 0;
    overscroll-behavior: contain;
}

.custom-select-option {
    display: block;
    width: 100%;
    padding: 10px 11px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #374151;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.custom-select-option:hover,
.custom-select-option:focus-visible {
    background: #f3f4f6;
    outline: none;
}

.custom-select-option.is-selected {
    background: #e8eef5;
    color: #1e3a5f;
    font-weight: 600;
}

.custom-select-option[hidden] {
    display: none;
}

.custom-select-option:disabled {
    opacity: .6;
    cursor: not-allowed;
}

/* ============================================================
   MESSAGES
   ============================================================ */

.custom-select-empty {
    padding: 13px 10px;
    color: #9ca3af;
    font-size: 13px;
    text-align: center;
}

/* ============================================================
   CHARGEMENT
   ============================================================ */

.custom-select-loading {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 15px;
    border-radius: 8px;
    background: rgb(255 255 255 / 94%);
    color: #374151;
    font-size: 13px;
    text-align: center;
}

.custom-select-loading[hidden] {
    display: none;
}

.custom-select-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #e5e7eb;
    border-top-color: #64748b;
    border-radius: 50%;
    animation: custom-select-spin .7s linear infinite;
}

.custom-select-loading-text {
    max-width: 100%;
    overflow-wrap: anywhere;
}

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

/* ============================================================
   ÉTAT DÉSACTIVÉ
   ============================================================ */

.custom-select-trigger:disabled {
    background: #f3f4f6;
    color: #9ca3af;
    cursor: not-allowed;
    opacity: .75;
}

/* ============================================================
   ACCESSIBILITÉ : RÉDUIRE LES ANIMATIONS
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    .custom-select-dropdown,
    .custom-select-spinner,
    .custom-select-arrow,
    .custom-select-trigger {
        animation: none;
        transition: none;
    }
}
