/* Select2 Bootstrap 5 Integration - Amélioration visuelle */
.select2-container {
    display: block;
    font-size: 1rem;
}

.select2-container .select2-selection--single {
    height: calc(2.25rem + 2px);
    padding: 0.375rem 0.75rem;
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    background-color: #fff;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.select2-container .select2-selection--single .select2-selection__rendered {
    padding-left: 0;
    padding-right: 20px;
    height: auto;
    margin-top: -1px;
}

.select2-container .select2-selection--single .select2-selection__arrow {
    height: calc(2.25rem);
    right: 3px;
}

.select2-container .select2-selection--multiple {
    min-height: calc(2.25rem + 2px);
    padding: 0;
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.select2-container .select2-selection--multiple .select2-selection__rendered {
    padding: 0.125rem 0 0.125rem 0.5rem;
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.125rem;
    margin: 0;
    list-style: none;
    flex: 1;
}

/* Masque le ul quand il est vide (pas d'options sélectionnées) */
.select2-container .select2-selection--multiple .select2-selection__rendered:empty {
    display: none;
}

/* Alternative : garde le conteneur mais sans hauteur quand vide */
.select2-container .select2-selection--multiple .select2-selection__rendered:not(:has(.select2-selection__choice)) {
    min-height: 0;
    padding: 0;
}

.select2-container .select2-selection--multiple .select2-selection__choice {
    background-color: #0d6efd;
    border: 1px solid #0d6efd;
    border-radius: 0.25rem;
    color: #fff;
    font-size: 0.875rem;
    margin: 0.125rem 0.25rem 0.125rem 0;
    padding: 0.25rem 0.5rem !important; /* Padding normal */
    position: relative;
    display: inline-block;
    min-height: 1.5rem;
    line-height: 1.2;
    /* Annule le padding par défaut de Select2 */
    padding-left: 0.5rem !important;
}

.select2-container .select2-selection--multiple .select2-selection__choice__display {
    display: inline-block;
    padding: 0 !important;
    margin: 0 !important;
    padding-left: 0 !important; /* Annule le padding par défaut */
    padding-right: 1.5rem !important; /* Espace pour la croix */
    cursor: default;
}

.select2-container .select2-selection--multiple .select2-selection__choice__remove {
    /* Annule tous les styles par défaut de Select2 */
    position: absolute !important;
    left: auto !important;
    right: 0.25rem !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    
    /* Nouveau style */
    color: #fff !important;
    background: transparent !important;
    border: none !important;
    padding: 0.125rem !important;
    margin: 0 !important;
    width: 1rem !important;
    height: 1rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    transition: all 0.15s ease !important;
    cursor: pointer !important;
    z-index: 2 !important;
    
    /* Annule complètement les styles Select2 par défaut */
    border-left: none !important;
    border-right: none !important;
    border-top: none !important;
    border-bottom: none !important;
    border-top-left-radius: 50% !important;
    border-bottom-left-radius: 50% !important;
    border-top-right-radius: 50% !important;
    border-bottom-right-radius: 50% !important;
    font-weight: normal !important;
    box-shadow: none !important;
}

.select2-container .select2-selection--multiple .select2-selection__choice__remove:hover,
.select2-container .select2-selection--multiple .select2-selection__choice__remove:focus {
    color: #fff !important;
    background-color: rgba(255, 255, 255, 0.2) !important;
    outline: none !important;
    border: none !important;
    border-radius: 50% !important;
    box-shadow: none !important;
    transform: translateY(-50%) scale(1.1) !important; /* Petit effet de zoom au survol */
}

/* Focus states - Version plus discrète */
.select2-container--focus .select2-selection,
.select2-container--open .select2-selection {
    border-color: #86b7fe !important;
    outline: 0 !important;
    box-shadow: none !important; /* Supprime complètement l'ombre */
}

/* Alternative : contour très discret si vous voulez garder une indication visuelle */
/* 
.select2-container--focus .select2-selection,
.select2-container--open .select2-selection {
    border-color: #86b7fe !important;
    outline: 0 !important;
    box-shadow: 0 0 0 1px rgba(13, 110, 253, 0.1) !important;
}
*/

/* Dropdown */
.select2-dropdown {
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.select2-search--dropdown .select2-search__field {
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
}

/* Amélioration du champ de recherche inline pour les tags */
.select2-search--inline .select2-search__field {
    height: calc(1.5rem) !important;
    line-height: 1.5 !important;
    margin: 0 !important;
    padding: 0.125rem 0.25rem !important;
    border: none !important;
    background: transparent !important;
    font-size: 1rem;
    box-sizing: border-box !important;
    display: block !important;
}

.select2-results__option {
    padding: 0.5rem 0.75rem;
}

.select2-results__option--highlighted {
    background-color: #0d6efd !important;
    color: #fff !important;
}

.select2-results__option--selected {
    background-color: #e9ecef !important;
    color: #495057 !important;
    font-weight: 600;
}

.select2-results__option--highlighted.select2-results__option--selected {
    background-color: #0a58ca !important;
    color: #fff !important;
}

/* AdminLTE Integration */
.content-wrapper .select2-container {
    width: 100% !important;
}

/* Dark mode support */
[data-bs-theme="dark"] .select2-container .select2-selection {
    background-color: #212529;
    border-color: #495057;
    color: #fff;
}

[data-bs-theme="dark"] .select2-dropdown {
    background-color: #212529;
    border-color: #495057;
    color: #fff;
}

[data-bs-theme="dark"] .select2-results__option {
    color: #fff;
}

[data-bs-theme="dark"] .select2-results__option--highlighted {
    background-color: #0d6efd;
}

/* Size variants */
.select2-container.select2-container--sm .select2-selection--single {
    height: calc(1.5rem + 2px);
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

.select2-container.select2-container--lg .select2-selection--single {
    height: calc(3rem + 2px);
    padding: 0.5rem 1rem;
    font-size: 1.25rem;
}

/* Error states */
.is-invalid ~ .select2-container .select2-selection {
    border-color: #dc3545;
}

.is-invalid ~ .select2-container--focus .select2-selection {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.25rem rgba(220, 53, 69, 0.25);
}

/* Loading state */
.select2-container .select2-selection__placeholder {
    color: #6c757d;
}

/* Amélioration spécifique pour les tags */
.select2-container .select2-selection--multiple .select2-selection__rendered .select2-search--inline {
    display: inline-flex;
    align-items: center;
    width: auto;
    min-width: 100px;
    flex: 1;
    margin: 0 !important;
    padding: 0 !important;
    vertical-align: top !important;
}

/* Conteneur de recherche inline au niveau du select2-selection */
.select2-container .select2-selection--multiple .select2-search--inline {
    display: inline-flex;
    align-items: center;
    margin: 0.125rem 0.5rem 0.125rem 0 !important;
    padding: 0 !important;
    vertical-align: top !important;
    flex-shrink: 0;
}

/* Correction du z-index pour éviter les conflits avec AdminLTE */
.select2-dropdown {
    z-index: 9999 !important;
}

.select2-container--disabled .select2-selection {
    background-color: #e9ecef;
    opacity: 1;
}

.select2-container--disabled .select2-selection__rendered {
    color: #6c757d;
}