/* Habillage des tableaux DataTables (thème neutre, pas de dépendance Bootstrap).
   Important : les règles globales @apply w-full sur input/select (dans base.html)
   s'appliquaient aussi aux contrôles internes de DataTables ("Afficher _MENU_
   éléments", "Rechercher :"), les forçant en 100% de largeur et les faisant
   passer à la ligne au lieu de rester sur une seule ligne — d'où l'effet
   "cassé"/trop serré. On les neutralise ci-dessous avec une largeur explicite. */
.dataTables_wrapper {
    font-size: 0.875rem;
    padding-top: 0.25rem;
}

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    margin-bottom: 0.75rem;
}

.dataTables_wrapper .dataTables_filter {
    text-align: right;
}

.dataTables_wrapper .dataTables_length select {
    width: auto !important;
    display: inline-block;
    margin: 0 0.4rem;
}

.dataTables_wrapper .dataTables_filter input {
    width: 16rem !important;
    display: inline-block;
    margin-left: 0.5rem;
}

.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid #cbd5e1;
    border-radius: 0.375rem;
    padding: 0.35rem 0.6rem;
    /* Un <select> et un <input> avec le même padding ne rendent PAS à la même
       hauteur par défaut (métriques de police natives différentes selon le
       navigateur) — hauteur explicite pour que "Show" (nombre de lignes) et
       "Rechercher" s'alignent toujours pile, y compris quand ils se
       retrouvent côte à côte dans une carte étroite (ex : tableaux de
       répartition à 2 colonnes du tableau de bord). */
    height: 2.25rem;
    box-sizing: border-box;
    line-height: 1.5rem;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.35rem 0.75rem;
    margin-left: 0.15rem;
    border-radius: 0.375rem;
    cursor: pointer;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: #1877F2;
    color: #fff !important;
    border-color: #1877F2 !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
    opacity: 0.4;
    cursor: default;
}

/* Un peu plus d'air dans les lignes des tableaux applicatifs (Utilisateurs, Matières...). */
table.min-w-full td, table.min-w-full th {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
}

/* ---------------------------------------------------------------------------
   Select2 (recherche dans les longues listes, ex : matière dans les
   formulaires d'entrée/de sortie). Le thème par défaut de Select2 ne reprend
   PAS le style des autres champs : la règle Tailwind sur `select` (base.html)
   ne s'applique qu'au <select> natif, que Select2 masque et remplace par sa
   propre div — recalé ici pour matcher l'apparence des autres champs
   (bordure/rayon/ombre/anneau de focus identiques à input[type=text] etc.).
   ------------------------------------------------------------------------ */
.select2-container {
    width: 100% !important;
}

.select2-container--default .select2-selection--single {
    height: auto;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    padding: 0.625rem 0.75rem;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 1.25rem;
    padding: 0;
    color: #0f172a;
    font-size: 0.875rem;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #64748b;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 100%;
    top: 0;
    right: 0.5rem;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
    border-color: #1877F2;
    box-shadow: 0 0 0 1px #1877F2;
}

/* Select2 en mode MULTIPLE (ex : "Magasin(s)" sur le formulaire Utilisateur) —
   un conteneur différent de --single ci-dessus (pas de <select> unique remplacé
   par un simple champ, mais une boîte à puces + champ de recherche interne),
   resté totalement sans style : recalé ici pour la même apparence que les
   autres champs, puces comprises (jusqu'ici blanches par défaut, illisibles
   en mode nuit — voir les règles html.dark plus bas). */
.select2-container--default .select2-selection--multiple {
    min-height: 2.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    padding: 0.3rem 0.5rem;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--multiple {
    border-color: #1877F2;
    box-shadow: 0 0 0 1px #1877F2;
}

.select2-container--default .select2-selection--multiple .select2-selection__rendered {
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice {
    background-color: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 0.375rem;
    color: #1e3a8a;
    margin: 0;
    padding: 0.125rem 0.5rem;
    font-size: 0.8125rem;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    color: #1e3a8a;
    border: none;
    margin-right: 0.375rem;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: #1877F2;
    background: transparent;
}

.select2-container--default .select2-selection--multiple .select2-search--inline .select2-search__field {
    color: #0f172a;
    font-size: 0.875rem;
    margin-top: 0.2rem;
}

.select2-dropdown {
    border-color: #cbd5e1;
    border-radius: 0.5rem;
    overflow: hidden;
}

.select2-search--dropdown .select2-search__field {
    border: 1px solid #cbd5e1;
    border-radius: 0.375rem;
    padding: 0.4rem 0.6rem;
}

.select2-results__option--highlighted[aria-selected] {
    background-color: #1877F2 !important;
}

/* ---------------------------------------------------------------------------
   Mode nuit (demande explicite) — DataTables et Select2 ont leur propre CSS
   non-Tailwind (ci-dessus), donc pas couverts par les classes dark: posées
   dans base.html : recalés ici en ciblant html.dark (classe posée sur <html>
   par static/js/app.js::basculerTheme, voir base.html pour le script anti-flash).
   ------------------------------------------------------------------------ */
html.dark .dataTables_wrapper .dataTables_length select,
html.dark .dataTables_wrapper .dataTables_filter input {
    background-color: #1e293b;
    border-color: #475569;
    color: #f1f5f9;
}

html.dark .dataTables_wrapper .dataTables_info,
html.dark .dataTables_wrapper .dataTables_length,
html.dark .dataTables_wrapper .dataTables_filter,
html.dark table.min-w-full {
    color: #e2e8f0;
}

html.dark .dataTables_wrapper .dataTables_paginate .paginate_button {
    color: #e2e8f0 !important;
}

html.dark .dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
    color: #64748b !important;
}

html.dark .select2-container--default .select2-selection--single {
    background-color: #1e293b;
    border-color: #475569;
}

html.dark .select2-container--default .select2-selection--single .select2-selection__rendered {
    color: #f1f5f9;
}

html.dark .select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #94a3b8;
}

html.dark .select2-dropdown {
    background-color: #1e293b;
    border-color: #475569;
    color: #f1f5f9;
}

html.dark .select2-search--dropdown .select2-search__field {
    background-color: #0f172a;
    border-color: #475569;
    color: #f1f5f9;
}

html.dark .select2-results__option {
    color: #f1f5f9;
}

/* Une option déjà sélectionnée (dans une liste MULTIPLE) reste listée par
   Select2, grisée par sa propre feuille de style par défaut (fond gris clair
   non recalé jusqu'ici) — sans cette règle, ce fond clair + le texte clair
   de la règle ci-dessus devenaient quasi illisibles en mode nuit. */
html.dark .select2-results__option[aria-selected="true"]:not(.select2-results__option--highlighted) {
    background-color: #334155;
    color: #94a3b8;
}

html.dark .select2-container--default .select2-selection--multiple {
    background-color: #1e293b;
    border-color: #475569;
}

html.dark .select2-container--default .select2-selection--multiple .select2-selection__choice {
    background-color: #334155;
    border-color: #475569;
    color: #e2e8f0;
}

html.dark .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    color: #cbd5e1;
}

html.dark .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: #f1f5f9;
}

html.dark .select2-container--default .select2-selection--multiple .select2-search--inline .select2-search__field {
    color: #f1f5f9;
    background-color: transparent;
}
