/* =========================================================================
   COMPATIBILITÉ DES THÈMES CLAIR / SOMBRE
   -------------------------------------------------------------------------
   Des gabarits posent des classes utilitaires Bootstrap pensées pour le mode
   clair (`bg-light`, `text-bg-light`, `text-dark`) ou une couleur de texte héritée
   des titres sur un fond de couleur fixe. Le contenu suit le thème, pas le fond :
   on obtient du texte clair sur fond clair en sombre, ou du texte noir sur un
   bandeau bleu en clair.

   Ce fichier est chargé par le site (base.html.twig) et par l'administration
   (DashboardController::configureAssets). Les jetons --ds-* n'existent pas dans
   l'administration, et y gardent leurs valeurs claires en mode sombre : on s'appuie
   donc sur les variables Bootstrap (--bs-body-color, --bs-tertiary-bg,
   --bs-secondary-color), que les deux mondes font suivre le thème.
   Dans l'administration, EasyAdmin pose data-bs-theme sur <body>, pas sur <html>, et
   range tout son CSS dans des couches (@layer) : pour des déclarations `!important`,
   une couche l'emporte sur du CSS hors couche, et la première couche l'emporte sur les
   suivantes. Les règles qui doivent battre celles d'EasyAdmin vivent donc dans sa couche
   prévue à cet effet, `ea-overrides`, déclarée en tête. Sur le site, la couche est sans
   effet fâcheux : elle ne fait que passer devant le CSS Bootstrap, lui aussi hors couche.
   ========================================================================= */

@layer ea-overrides {

/* --- Mode sombre : surfaces et textes posés en clair ------------------- */

[data-bs-theme='dark'] .bg-light,
[data-bs-theme='dark'] .text-bg-light {
  background-color: var(--bs-tertiary-bg, #1c2733) !important;
  color: var(--bs-body-color, #e9eff7) !important;
}

/* `text-dark` reste noir là où il pose du noir sur un aplat clair (pastilles jaunes, bleues, vertes). */
[data-bs-theme='dark'] .text-dark:not(.bg-warning):not(.bg-info):not(.bg-success):not(.bg-light):not(.text-bg-warning):not(.text-bg-info) {
  color: var(--bs-body-color, #e9eff7) !important;
}

/* --- Pastilles à fond de couleur vive : le texte doit contraster avec leur fond --- */

.badge.bg-warning,
.badge.bg-info {
  color: #1f2328 !important;
}

.badge.bg-success,
.badge.bg-danger,
.badge.bg-primary,
.badge.bg-secondary,
.badge.bg-dark {
  color: #fff !important;
}

/* Bootstrap 5.3 pose aussi ces couleurs par `text-bg-*` : en mode sombre le thème force tout <span> en texte clair
   (`[data-theme="dark"] span { color: var(--coul-claire) !important }`), ce qui donnait du clair sur jaune (1,4:1),
   sur vert (3,9:1), sur rouge (3,9:1) et sur bleu de marque (4,2:1). Chaque fond reçoit sa paire de texte. */
.text-bg-warning,
.text-bg-info {
  color: #1f2328 !important;
}

.text-bg-success {
  background-color: #146c43 !important;
  color: #ffffff !important;
}

.text-bg-danger {
  background-color: #b02a37 !important;
  color: #ffffff !important;
}

.text-bg-primary,
.text-bg-secondary,
.text-bg-dark {
  color: #ffffff !important;
}

/* Fiche de version du journal des modifications : le titre d'un panneau ouvert est un bleu sombre sur fond sombre. */
[data-bs-theme='dark'] .accordion-button:not(.collapsed) {
  color: #9ec5fe !important;
}

/* Le bleu de marque (#0077bd) ne contraste qu'à 3,5–4:1 sur les surfaces sombres : on l'éclaircit pour les textes. */
[data-bs-theme='dark'] .text-primary,
[data-bs-theme='dark'] a.text-primary {
  color: #5cb3e6 !important;
}

/* Pastille d'avatar et lien d'évitement : blanc sur le bleu de marque (le lien prenait un bleu clair, à 3,6:1). */
.app-topbar__avatar,
.ds-skip-link {
  color: #fff !important;
}

/* --- Textes « atténués » --------------------------------------------------- */

[data-bs-theme='dark'] :is(.text-muted, .text-body-secondary) {
  /* Valeur explicite : --bs-secondary-color vaut un gris (#737373) dans le thème sombre d'EasyAdmin. */
  color: #a3b4c6 !important;
}

/* Libellés propres à la page Planification et pagination désactivée : le gris d'EasyAdmin y tombe à ~4:1. */
[data-bs-theme='dark'] :is(.planning-panel__title, .planning-panel__hint, .planning-kpi-box__label, .planning-table th),
[data-bs-theme='dark'] .page-item.disabled .page-link,
[data-bs-theme='dark'] .page-item.disabled .page-link * {
  color: #a3b4c6 !important;
}

[data-bs-theme='dark'] .text-secondary { color: #b4c0cd !important; }
[data-bs-theme='dark'] .btn-outline-secondary:not(:hover) { color: #a3b4c6 !important; }
[data-bs-theme='dark'] .text-success { color: #5fd9a0 !important; }
[data-bs-theme='dark'] .text-danger { color: #ff8a95 !important; }

/* Mode clair : le gris d'EasyAdmin (#64748b) frôle 4:1 sur les cartes ; les textes des pastilles pâles passent à une teinte plus profonde. */
:root:not([data-bs-theme='dark']) body:not([data-bs-theme='dark']) :is(.text-muted, .text-body-secondary) { color: #566376 !important; }
:root:not([data-bs-theme='dark']) body:not([data-bs-theme='dark']) .badge.bg-success-subtle.text-success { color: #0f5132 !important; }
:root:not([data-bs-theme='dark']) body:not([data-bs-theme='dark']) .badge.bg-danger-subtle.text-danger { color: #a71d2a !important; }
:root:not([data-bs-theme='dark']) body:not([data-bs-theme='dark']) .badge.bg-secondary-subtle.text-secondary { color: #475569 !important; }

/* Intitulés de groupe du menu de l'administration : trop pâles sur le fond clair. */
:root:not([data-bs-theme='dark']) body:not([data-bs-theme='dark']) .ea-sidebar-group-label-text {
  color: #5b6b7f !important;
}

/* Pagination : une page indisponible reste lisible (elle n'est pas « absente »). */
.page-item.disabled .page-link {
  color: var(--bs-secondary-color) !important;
}


/* --- Bandeaux de notification : texte lisible sur chaque couleur d'alerte ---
   design-system.css impose `color: var(--ds-text) !important` à tous les bandeaux : un
   texte quasi noir sur le vert en clair (4,4:1), quasi blanc sur le vert en sombre
   (3,9:1). Chaque couleur reçoit ici sa paire, identique dans les deux thèmes. */
.alert-temporary.bg-success { background-color: #146c43 !important; color: #ffffff !important; }
.alert-temporary.bg-danger  { background-color: #b02a37 !important; color: #ffffff !important; }
.alert-temporary.bg-info    { background-color: #0dcaf0 !important; color: #032830 !important; }
.alert-temporary.bg-warning { background-color: #ffc107 !important; color: #2b2100 !important; }

}

/* --- Bandeaux de couleur fixe : le texte reste blanc dans les deux modes --- */

.login-panel :is(h1, h2, h3, h4, h5, h6),
#faq_block :is(h1, h2, h3, h4, h5, h6, p, label, li) {
  color: #fff;
}

/* --- Onglet « Feedback » : blanc sur la couleur de la plateforme --------- */

.feedback-button:not(:hover),
.feedback-button:not(:hover):visited {
  color: #fff !important;
}

/* =========================================================================
   FLASH ET BOUTONS CONTRASTÉS
   -------------------------------------------------------------------------
   Les boutons « contour » de Bootstrap tombent sous 4,5:1 au repos ou au survol
   selon le thème (gris sur gris : 3,1 à 4,3:1). On fixe ici leurs paires de
   couleurs par les variables --bs-btn-* que Bootstrap lit lui-même, donc sans
   toucher à sa structure. Hors administration : EasyAdmin a son propre système
   de boutons (`body.ea`).
   ========================================================================= */

:root:not([data-bs-theme='dark']) body:not(.ea) .btn-outline-secondary {
  --bs-btn-color: #495057;
  --bs-btn-border-color: #6c757d;
  --bs-btn-hover-color: #ffffff;
  --bs-btn-hover-bg: #495057;
  --bs-btn-hover-border-color: #495057;
  --bs-btn-active-color: #ffffff;
  --bs-btn-active-bg: #343a40;
  --bs-btn-active-border-color: #343a40;
}

:root:not([data-bs-theme='dark']) body:not(.ea) .btn-outline-danger {
  --bs-btn-color: #b02a37;
  --bs-btn-border-color: #b02a37;
  --bs-btn-hover-color: #ffffff;
  --bs-btn-hover-bg: #b02a37;
  --bs-btn-hover-border-color: #b02a37;
  --bs-btn-active-color: #ffffff;
  --bs-btn-active-bg: #842029;
  --bs-btn-active-border-color: #842029;
}

:root[data-bs-theme='dark'] body:not(.ea) .btn-outline-secondary {
  --bs-btn-color: #ced4da;
  --bs-btn-border-color: #8a939c;
  --bs-btn-hover-color: #14181d;
  --bs-btn-hover-bg: #dee2e6;
  --bs-btn-hover-border-color: #dee2e6;
  --bs-btn-active-color: #14181d;
  --bs-btn-active-bg: #f1f3f5;
  --bs-btn-active-border-color: #f1f3f5;
}

:root[data-bs-theme='dark'] body:not(.ea) .btn-outline-danger {
  --bs-btn-color: #ff8a95;
  --bs-btn-border-color: #ff8a95;
  --bs-btn-hover-color: #14181d;
  --bs-btn-hover-bg: #ff8a95;
  --bs-btn-hover-border-color: #ff8a95;
  --bs-btn-active-color: #14181d;
  --bs-btn-active-bg: #ffb3ba;
  --bs-btn-active-border-color: #ffb3ba;
}

:root[data-bs-theme='dark'] body:not(.ea) .btn-outline-primary {
  --bs-btn-color: #5cb3e6;
  --bs-btn-border-color: #5cb3e6;
  --bs-btn-hover-color: #0b1520;
  --bs-btn-hover-bg: #5cb3e6;
  --bs-btn-hover-border-color: #5cb3e6;
  --bs-btn-active-color: #0b1520;
  --bs-btn-active-bg: #8ccbf0;
  --bs-btn-active-border-color: #8ccbf0;
}

body:not(.ea) .btn-success {
  --bs-btn-bg: #146c43;
  --bs-btn-border-color: #146c43;
  --bs-btn-hover-bg: #0f5132;
  --bs-btn-hover-border-color: #0f5132;
  --bs-btn-active-bg: #0c4128;
  --bs-btn-active-border-color: #0c4128;
}

/* Un lien qui a l'apparence d'un bouton perdait la couleur de texte de son survol en mode sombre :
   design-system.css pose `[data-theme="dark"] a:hover { color: var(--ds-brand-200) }`, plus spécifique
   que `.btn:hover` de Bootstrap. Résultat : du bleu clair sur un fond plein clair (1,1 à 1,6:1). */
[data-theme='dark'] body:not(.ea) a.btn:hover,
[data-theme='dark'] body:not(.ea) a.btn:focus-visible,
[data-theme='dark'] body:not(.ea) a.btn:active {
  color: var(--bs-btn-hover-color);
}

[data-theme='dark'] body:not(.ea) a.btn:active {
  color: var(--bs-btn-active-color);
}

/* design-system.css fixe lui-même le survol des boutons « contour primaire » (fond de marque foncé) ; en
   sombre, le texte que nous leur donnons (foncé) y perdait tout contraste. On pose ici fond et texte ensemble. */
:root[data-bs-theme='dark'] body:not(.ea) .btn-outline-primary:hover,
:root[data-bs-theme='dark'] body:not(.ea) .btn-outline-primary:focus-visible {
  background-color: #5cb3e6;
  border-color: #5cb3e6;
  color: #0b1520;
}

/* Boutons-liens en mode sombre : au repos aussi, `[data-theme="dark"] a` (design-system.css) l'emporte sur
   `.btn` de Bootstrap et teinte le texte en bleu clair, y compris sur un fond plein (bouton « warning » : 1,2:1).
   Le texte reprend ce que le bouton déclare. */
[data-theme='dark'] body:not(.ea) a.btn:not(:hover):not(:focus-visible):not(:active) {
  color: var(--bs-btn-color);
}

body:not(.ea) .btn-warning {
  --bs-btn-color: #1f2328;
  --bs-btn-hover-color: #1f2328;
  --bs-btn-active-color: #1f2328;
}
