/**
 * Select2 Dark Theme - Intranet DTISI
 *
 * Styles centralis pour tous les Select2 multi-select du projet.
 * Compatible avec le theme Bootstrap 5.
 *
 * @author Claude Code
 * @version 1.0
 */

/* ============================================
   VARIABLES CSS
   ============================================ */
:root {
    /* Couleurs principales */
    --select2-bg: #000050;
    --select2-bg-hover: #000070;
    --select2-bg-dropdown: #000050;

    /* Bordures */
    --select2-border: rgba(255, 255, 255, 0.15);
    --select2-border-focus: #3b82f6;
    --select2-border-radius: 6px;

    /* Textes */
    --select2-text: #e2e8f0;
    --select2-text-muted: #94a3b8;
    --select2-placeholder: #64748b;

    /* Tags (elements selectionnes) */
    --select2-tag-bg: #3b82f6;
    --select2-tag-text: #ffffff;
    --select2-tag-remove-hover: rgba(255, 255, 255, 0.2);

    /* Options */
    --select2-highlight: #3b82f6;
    --select2-selected-bg: rgba(59, 130, 246, 0.25);
    --select2-selected-hover-bg: rgba(59, 130, 246, 0.4);

    /* Effets */
    --select2-dropdown-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    --select2-focus-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
    --select2-z-index: 9999;

    /* Checkbox */
    --select2-checkbox-size: 16px;
    --select2-checkbox-border: rgba(255, 255, 255, 0.4);
    --select2-checkbox-checked: #3b82f6;
}

/* ============================================
   CONTAINER PRINCIPAL - MULTI-SELECT
   ============================================ */
.select2-container--bootstrap-5 .select2-selection--multiple,
.select2-container--default .select2-selection--multiple {
    background: var(--select2-bg) !important;
    border: 1px solid var(--select2-border) !important;
    border-radius: var(--select2-border-radius) !important;
    min-height: 38px !important;
    padding: 2px 4px !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease !important;
}

/* Etat focus */
.select2-container--bootstrap-5.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--bootstrap-5.select2-container--open .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--multiple {
    border-color: var(--select2-border-focus) !important;
    box-shadow: var(--select2-focus-shadow) !important;
    outline: none !important;
}

/* Zone de rendu */
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__rendered,
.select2-container--default .select2-selection--multiple .select2-selection__rendered {
    padding: 0 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 4px !important;
}

/* ============================================
   TAGS SELECTIONNES
   ============================================ */
.select2-container--bootstrap-5 .select2-selection__choice,
.select2-container--default .select2-selection__choice {
    background: var(--select2-tag-bg) !important;
    border: none !important;
    color: var(--select2-tag-text) !important;
    border-radius: 4px !important;
    padding: 4px 10px 4px 28px !important;
    margin: 2px !important;
    font-size: 0.8rem !important;
    font-weight: 500 !important;
    line-height: 1.4 !important;
    display: inline-flex !important;
    align-items: center !important;
    position: relative !important;
    max-width: 200px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
}

/* Bouton X pour supprimer le tag */
.select2-container--bootstrap-5 .select2-selection__choice__remove,
.select2-container--default .select2-selection__choice__remove {
    color: rgba(255, 255, 255, 0.7) !important;
    background: transparent !important;
    border: none !important;
    font-size: 1rem !important;
    font-weight: bold !important;
    position: absolute !important;
    left: 6px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: 18px !important;
    height: 18px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 3px !important;
    transition: all 0.15s ease !important;
    cursor: pointer !important;
}

.select2-container--bootstrap-5 .select2-selection__choice__remove:hover,
.select2-container--default .select2-selection__choice__remove:hover {
    color: var(--select2-tag-text) !important;
    background: var(--select2-tag-remove-hover) !important;
}

/* Champ de recherche dans le container */
.select2-container--bootstrap-5 .select2-selection--multiple .select2-search__field,
.select2-container--default .select2-selection--multiple .select2-search__field {
    color: var(--select2-text) !important;
    background: transparent !important;
    border: none !important;
    outline: none !important;
    margin: 4px !important;
    padding: 2px 4px !important;
    font-size: 0.875rem !important;
    min-width: 100px !important;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-search__field::placeholder,
.select2-container--default .select2-selection--multiple .select2-search__field::placeholder {
    color: var(--select2-placeholder) !important;
    opacity: 1 !important;
}

/* Placeholder quand rien n'est selectionne */
.select2-container--bootstrap-5 .select2-selection__placeholder,
.select2-container--default .select2-selection__placeholder {
    color: var(--select2-placeholder) !important;
}

/* ============================================
   DROPDOWN (LISTE DEROULANTE)
   ============================================ */
.select2-container--bootstrap-5 .select2-dropdown,
.select2-container--default .select2-dropdown {
    background: var(--select2-bg-dropdown) !important;
    border: 1px solid var(--select2-border) !important;
    border-radius: var(--select2-border-radius) !important;
    box-shadow: var(--select2-dropdown-shadow) !important;
    z-index: var(--select2-z-index) !important;
    overflow: hidden !important;
}

/* Animation d'ouverture - Fade + Slide */
.select2-container--open .select2-dropdown {
    animation: select2DropdownOpen 0.15s ease-out;
}

@keyframes select2DropdownOpen {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Champ de recherche dans le dropdown */
.select2-container--bootstrap-5 .select2-search--dropdown,
.select2-container--default .select2-search--dropdown {
    padding: 8px !important;
    background: rgba(0, 0, 0, 0.2) !important;
}

.select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field,
.select2-container--default .select2-search--dropdown .select2-search__field {
    background: var(--select2-bg-hover) !important;
    border: 1px solid var(--select2-border) !important;
    color: var(--select2-text) !important;
    border-radius: 4px !important;
    padding: 8px 12px !important;
    font-size: 0.875rem !important;
    width: 100% !important;
    transition: border-color 0.15s ease !important;
}

.select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field:focus,
.select2-container--default .select2-search--dropdown .select2-search__field:focus {
    border-color: var(--select2-border-focus) !important;
    outline: none !important;
}

.select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field::placeholder,
.select2-container--default .select2-search--dropdown .select2-search__field::placeholder {
    color: var(--select2-text-muted) !important;
}

/* ============================================
   OPTIONS AVEC CHECKBOXES
   ============================================ */
.select2-container--bootstrap-5 .select2-results__option,
.select2-container--default .select2-results__option {
    color: var(--select2-text) !important;
    padding: 10px 14px 10px 40px !important;
    font-size: 0.875rem !important;
    cursor: pointer !important;
    position: relative !important;
    transition: background 0.15s ease !important;
}

/* Checkbox avant chaque option */
.select2-container--bootstrap-5 .select2-results__option::before,
.select2-container--default .select2-results__option::before {
    content: '' !important;
    position: absolute !important;
    left: 12px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: var(--select2-checkbox-size) !important;
    height: var(--select2-checkbox-size) !important;
    border: 2px solid var(--select2-checkbox-border) !important;
    border-radius: 3px !important;
    background: transparent !important;
    transition: all 0.15s ease !important;
}

/* Checkbox cochee (option selectionnee) */
.select2-container--bootstrap-5 .select2-results__option[aria-selected="true"]::before,
.select2-container--default .select2-results__option[aria-selected="true"]::before {
    background: var(--select2-checkbox-checked) !important;
    border-color: var(--select2-checkbox-checked) !important;
    /* Icone check en SVG inline */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E") !important;
    background-size: 10px !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
}

/* Option survolee */
.select2-container--bootstrap-5 .select2-results__option--highlighted,
.select2-container--bootstrap-5 .select2-results__option--highlighted[aria-selected],
.select2-container--default .select2-results__option--highlighted,
.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background: var(--select2-highlight) !important;
    color: white !important;
}

.select2-container--bootstrap-5 .select2-results__option--highlighted::before,
.select2-container--default .select2-results__option--highlighted::before {
    border-color: rgba(255, 255, 255, 0.7) !important;
}

/* Option selectionnee (non survolee) */
.select2-container--bootstrap-5 .select2-results__option--selected,
.select2-container--bootstrap-5 .select2-results__option[aria-selected="true"],
.select2-container--default .select2-results__option--selected,
.select2-container--default .select2-results__option[aria-selected="true"] {
    background: var(--select2-selected-bg) !important;
}

/* Option selectionnee ET survolee */
.select2-container--bootstrap-5 .select2-results__option--selected.select2-results__option--highlighted,
.select2-container--bootstrap-5 .select2-results__option[aria-selected="true"].select2-results__option--highlighted,
.select2-container--default .select2-results__option--selected.select2-results__option--highlighted,
.select2-container--default .select2-results__option[aria-selected="true"].select2-results__option--highlighted {
    background: var(--select2-selected-hover-bg) !important;
}

/* Option selectionnee survolee - garder la checkbox visible */
.select2-container--bootstrap-5 .select2-results__option[aria-selected="true"].select2-results__option--highlighted::before,
.select2-container--default .select2-results__option[aria-selected="true"].select2-results__option--highlighted::before {
    border-color: white !important;
}

/* Message "Aucun resultat" */
.select2-container--bootstrap-5 .select2-results__message,
.select2-container--default .select2-results__message {
    color: var(--select2-text-muted) !important;
    padding: 12px 14px !important;
    font-style: italic !important;
    text-align: center !important;
}

/* Desactiver checkbox sur le message */
.select2-container--bootstrap-5 .select2-results__message::before,
.select2-container--default .select2-results__message::before {
    display: none !important;
}

/* ============================================
   BOUTON CLEAR (TOUT EFFACER)
   ============================================ */
.select2-container--bootstrap-5 .select2-selection__clear,
.select2-container--default .select2-selection__clear {
    color: var(--select2-text-muted) !important;
    font-size: 1.2rem !important;
    font-weight: normal !important;
    margin-right: 8px !important;
    cursor: pointer !important;
    transition: color 0.15s ease !important;
}

.select2-container--bootstrap-5 .select2-selection__clear:hover,
.select2-container--default .select2-selection__clear:hover {
    color: #ef4444 !important;
}

/* ============================================
   ETAT DISABLED
   ============================================ */
.select2-container--bootstrap-5.select2-container--disabled .select2-selection--multiple,
.select2-container--default.select2-container--disabled .select2-selection--multiple {
    background: rgba(0, 0, 80, 0.5) !important;
    opacity: 0.6 !important;
    cursor: not-allowed !important;
}

.select2-container--bootstrap-5.select2-container--disabled .select2-selection__choice,
.select2-container--default.select2-container--disabled .select2-selection__choice {
    opacity: 0.7 !important;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    /* Container plus grand pour le touch */
    .select2-container--bootstrap-5 .select2-selection--multiple,
    .select2-container--default .select2-selection--multiple {
        min-height: 44px !important;
    }

    /* Tags plus compacts */
    .select2-container--bootstrap-5 .select2-selection__choice,
    .select2-container--default .select2-selection__choice {
        max-width: calc(100% - 20px) !important;
        font-size: 0.75rem !important;
    }

    /* Options plus grandes pour le touch */
    .select2-container--bootstrap-5 .select2-results__option,
    .select2-container--default .select2-results__option {
        padding: 14px 14px 14px 44px !important;
        min-height: 44px !important;
    }

    /* Checkbox plus grande */
    .select2-container--bootstrap-5 .select2-results__option::before,
    .select2-container--default .select2-results__option::before {
        width: 18px !important;
        height: 18px !important;
    }

    /* Champ de recherche plus grand */
    .select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field,
    .select2-container--default .select2-search--dropdown .select2-search__field {
        padding: 12px 14px !important;
        font-size: 1rem !important;
    }
}

/* ============================================
   FIXES SPECIFIQUES
   ============================================ */

/* Fix pour les modals Bootstrap */
.modal .select2-container--open .select2-dropdown {
    z-index: 10060 !important;
}

/* Fix largeur 100% */
.select2-container {
    width: 100% !important;
}

/* Fix pour eviter les sauts visuels */
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__rendered li:last-child,
.select2-container--default .select2-selection--multiple .select2-selection__rendered li:last-child {
    margin-right: 0 !important;
}

/* Fix pour le groupe d'options (optgroup) */
.select2-container--bootstrap-5 .select2-results__group,
.select2-container--default .select2-results__group {
    color: var(--select2-text-muted) !important;
    font-weight: 600 !important;
    font-size: 0.75rem !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    padding: 10px 14px 6px !important;
    cursor: default !important;
}

.select2-container--bootstrap-5 .select2-results__group::before,
.select2-container--default .select2-results__group::before {
    display: none !important;
}
