/* ==========================================
   TOMSELECT - CONFIGURATION ET INTEGRATION
   ========================================== */

/* Sécurité pour masquer le select HTML d'origine */
.tomselected {
    display: none !important;
}

/* Base du conteneur TomSelect */
.ts-wrapper {
    width: 100%;
    position: relative !important; /* <--- CRUCIAL : Donne le repère de largeur au dropdown */
}

/* Champ de contrôle principal (S'aligne sur tes inputs natifs) */
.ts-wrapper.single .ts-control {
    display: flex !important;
    align-items: center !important;
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    font-size: 15px;
    font-family: inherit;
    background-color: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    box-sizing: border-box;
    box-shadow: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    position: relative; /* Ajouté pour fiabiliser le positionnement absolu de l'input masqué */
}

/* État Focus */
.ts-wrapper.focus .ts-control {
    border-color: var(--color-border-hover);
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.15);
}

/* ==========================================
   GESTION DU TEXTE SELECTIONNE & INPUT
   ========================================== */

/* Force l'élément sélectionné à rester sur une ligne avec "..." si trop long */
.ts-wrapper .ts-control > .item,
.ts-wrapper .ts-control > .item.full-client-name {
    display: block !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: inherit !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Input de recherche interne */
.ts-control input {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    height: auto !important;
    min-height: unset !important;
    font-size: 15px;
    font-family: inherit;
    width: 100% !important;
}

/* Style du Placeholder quand AUCUN client n'est sélectionné */
.ts-control input::placeholder {
    color: var(--color-text-muted, #94a3b8); /* S'assure que le placeholder a une couleur discrète */
    opacity: 1;
}

.ts-control input:focus {
    outline: none !important;
}

/* CORRECT : Quand un élément est sélectionné, on neutralise l'input ET son placeholder pour laisser toute la place à l'item */
.ts-wrapper.has-items .ts-control > input {
    opacity: 0 !important;
    width: 0px !important;
    position: absolute !important;
    pointer-events: none; /* Évite de cliquer dessus par erreur */
}

/* ==========================================
   FENÊTRE DEROULANTE (DROPDOWN)
   ========================================== */

.ts-dropdown {
    position: absolute !important;
    z-index: 9999 !important;
    margin-top: 4px;
    
    /* --- AJOUTS POUR LA LARGEUR --- */
    left: 0 !important;
    right: 0 !important;
    width: 100% !important; /* <--- Force à prendre 100% du .ts-wrapper */
    box-sizing: border-box !important; /* Évite que les bordures fassent déborder le menu */
    
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    overflow: hidden;
}

/* Style des lignes d'options */
.ts-dropdown .option {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 15px;
}

/* Effet Hover / Option active au clavier */
.ts-dropdown .option.active {
    background-color: rgba(240, 114, 118, 0.08); 
    color: var(--color-text-dark);
}
/* CORRECT : On ne cache l'input QUE si un vrai choix (un item visible) est présent à côté de lui */
.ts-wrapper.has-items .ts-control > .item + input {
    opacity: 0 !important;
    width: 0px !important;
    position: absolute !important;
    pointer-events: none;
}

/* Quand il n'y a pas d'item sélectionné, on force l'input à occuper l'espace pour afficher le placeholder */
.ts-wrapper:not(.has-items) .ts-control > input,
.ts-wrapper.has-items .ts-control > input:only-child,
.ts-control input {
    opacity: 1 !important;
    width: 100% !important;
    position: relative !important;
}

.ts-dropdown .optgroup-header {
    font-weight: bold;
    color: var(--color-text-dark);
    background-color: #f8fafc; /* Léger fond gris pour bien séparer les catégories */
    padding: 6px 14px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}