/* ULIS - contraste WCAG AA en theme clair ET sombre (texte 4,5:1, grand texte 3:1).
 *
 * Chargee par layouts/base.html juste apres ulis-console.css, donc apres app.min.css (theme HUD + Bootstrap) :
 * corrige a la source les couleurs du theme qui ne tiennent pas le contraste. Garde-fou :
 * tests/test_ui_contrast_all_pages.py (toutes les pages, Chrome headless) et tests/test_ui_code_blocks.py.
 *
 * Cause du retour du 06/11/2026 (/docs/api-partenaire en sombre, exemples de code invisibles) : `pre.bg-light`
 * prend `--bs-light-rgb` (gris clair, identique dans les deux themes) alors que le texte herite de la couleur
 * claire du theme sombre ; le theme HUD pose en plus `pre { background: #fff; color: #44555e }` dans les deux
 * themes. Les blocs de code ont desormais leur propre palette, par theme.
 *
 * Les couleurs semantiques (primary, success...) sont derivees des variables du theme par color-mix : la couleur
 * de marque blanche d'un revendeur (--bs-primary pose par layouts/base.html) est conservee, assombrie ou eclaircie
 * juste ce qu'il faut pour rester lisible.
 */

/* ─── Jetons ─────────────────────────────────────────────────────────────────────────────────────────────── */
[data-bs-theme="dark"] {
    /* texte pose sur l'accent jaune du theme (boutons, pastilles actives, avatar) : sombre, jamais blanc */
    --bs-theme-color: #1d2835;
    --bs-theme-color-rgb: 29, 40, 53;
    --uc-code-bg: #0d1117;
    --uc-code-fg: #e6edf3;
    --uc-code-border: rgba(255, 255, 255, 0.12);
    --uc-code-inline-bg: rgba(255, 255, 255, 0.08);
    --uc-muted-aa: #a9b6bd;
    /* texte colore sur fond sombre : la couleur du theme eclaircie */
    --uc-text-primary: color-mix(in srgb, var(--bs-primary) 65%, #fff);
    --uc-text-success: color-mix(in srgb, var(--bs-success) 85%, #fff);
    --uc-text-info: color-mix(in srgb, var(--bs-info) 80%, #fff);
    --uc-text-warning: color-mix(in srgb, var(--bs-warning) 80%, #fff);
    --uc-text-danger: color-mix(in srgb, var(--bs-danger) 60%, #fff);
    --uc-text-secondary: var(--uc-muted-aa);
}
[data-bs-theme="light"] {
    /* bleu primaire du theme (#0271ff : 4,37:1 sur blanc) assombri ; la marque blanche d'un revendeur
       (posee sur html[data-bs-theme="light"] par layouts/base.html, plus specifique) reste prioritaire */
    --bs-primary: #0057c8;
    --bs-primary-rgb: 0, 87, 200;
    --bs-link-color: #0057c8;
    --bs-link-color-rgb: 0, 87, 200;
    --bs-link-hover-color: #003f91;
    --bs-link-hover-color-rgb: 0, 63, 145;
    /* accent HUD : le jaune (#f9e80d, 1,3:1 sur blanc) n'est pas lisible en clair, la console le passe au primaire */
    --bs-theme: var(--bs-primary);
    --bs-theme-rgb: var(--bs-primary-rgb);
    --bs-theme-color: #fff;
    --bs-theme-color-rgb: 255, 255, 255;
    /* « light » du theme = #c0cacf (gris moyen) : un texte secondaire n'y tient pas 4,5:1 */
    --bs-light: #eef1f3;
    --bs-light-rgb: 238, 241, 243;
    --bs-secondary-bg-subtle: #e4e8ea;
    --uc-code-bg: #f6f8fa;
    --uc-code-fg: #1f2328;
    --uc-code-border: #d0d7de;
    --uc-code-inline-bg: rgba(0, 0, 0, 0.05);
    --uc-muted-aa: #4f5d65;
    /* texte colore sur fond clair (blanc, cartes, fonds « subtle ») : la couleur du theme assombrie */
    --uc-text-primary: color-mix(in srgb, var(--bs-primary) 90%, #000);
    --uc-text-success: color-mix(in srgb, var(--bs-success) 62%, #000);
    --uc-text-info: color-mix(in srgb, var(--bs-info) 62%, #000);
    --uc-text-warning: color-mix(in srgb, var(--bs-warning) 50%, #000);
    --uc-text-danger: color-mix(in srgb, var(--bs-danger) 72%, #000);
    --uc-text-secondary: var(--uc-muted-aa);
}
/* Surfaces pleines portant du texte blanc (boutons, badges, bg-*) : identiques dans les deux themes. */
:root, [data-bs-theme] {
    --uc-fill-primary: color-mix(in srgb, var(--bs-primary) 72%, #000);
    --uc-fill-success: color-mix(in srgb, var(--bs-success) 62%, #000);
    --uc-fill-info: color-mix(in srgb, var(--bs-info) 62%, #000);
    --uc-fill-danger: color-mix(in srgb, var(--bs-danger) 72%, #000);
    --uc-fill-secondary: color-mix(in srgb, var(--bs-secondary) 70%, #000);
    --uc-fill-dark: #35434a;
    --uc-on-fill: #fff;
    --uc-on-warning: #1d2835;
}

/* ─── Blocs de code, code en ligne, touches ──────────────────────────────────────────────────────────────── */
pre, pre[class] {   /* pre[class] : passe devant les utilitaires .bg-light / .text-light / .text-dark poses sur le bloc */
    background-color: var(--uc-code-bg) !important;
    color: var(--uc-code-fg) !important;
    border: 1px solid var(--uc-code-border);
    border-radius: 6px;
    padding: 0.75rem 1rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8125rem;
    line-height: 1.5;
    /* longues lignes (curl, JSON, cles) : defilement horizontal du bloc, jamais de la page */
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}
pre code, pre code[class*="language-"], pre > p, pre kbd {
    color: inherit !important;
    background: none !important;
    padding: 0;
    font-size: inherit;
    white-space: inherit;
    word-break: inherit;
    border: 0;
}
:not(pre) > code {
    color: var(--uc-code-fg);
    background-color: var(--uc-code-inline-bg);
    border-radius: 3px;
    padding: 0.08em 0.3em;
    word-break: break-word;
}
.ulis-console :not(pre) > code { color: var(--uc-code-fg); }
/* code pose dans un bandeau sombre / clair explicite (bg-dark, alerte, badge...) : il prend la couleur du bandeau */
:is(.text-light, .text-white, .bg-dark, .text-bg-dark, .alert, .badge, .btn) code:not(pre code) {
    color: inherit;
    background-color: color-mix(in srgb, currentColor 12%, transparent);
}
kbd {
    color: var(--uc-code-bg);
    background-color: var(--uc-code-fg);
}
/* Champs qui affichent du code / du JSON (configurations, cles, scripts) */
textarea.font-monospace, textarea.code, textarea[readonly], input[readonly].font-monospace,
.form-control[readonly], .form-control:read-only {
    color: var(--bs-body-color);
}
textarea.font-monospace, textarea.code {
    background-color: var(--uc-code-bg);
    color: var(--uc-code-fg);
    border-color: var(--uc-code-border);
}

/* ─── Surfaces « bg-light » / « bg-white » en sombre ─────────────────────────────────────────────────────── */
/* Gris clair fixe dans les deux themes : en sombre, texte clair sur fond clair. On garde la surface claire
   seulement quand la page impose un texte sombre (badge bg-light text-dark...). */
[data-bs-theme="dark"] .bg-light:not(.text-dark):not(.text-black):not(.text-body-emphasis),
[data-bs-theme="dark"] .bg-white:not(.text-dark):not(.text-black) {
    background-color: rgba(255, 255, 255, 0.06) !important;
    color: var(--bs-body-color);
}
[data-bs-theme="dark"] .bg-light.text-dark, [data-bs-theme="dark"] .bg-white.text-dark { color: #1d2835 !important; }

/* ─── Texte colore ───────────────────────────────────────────────────────────────────────────────────────── */
[data-bs-theme] .text-primary, [data-bs-theme] .link-primary { color: var(--uc-text-primary) !important; }
[data-bs-theme] .text-success, [data-bs-theme] .link-success { color: var(--uc-text-success) !important; }
[data-bs-theme] .text-info, [data-bs-theme] .link-info { color: var(--uc-text-info) !important; }
[data-bs-theme] .text-warning, [data-bs-theme] .link-warning { color: var(--uc-text-warning) !important; }
[data-bs-theme] .text-danger, [data-bs-theme] .link-danger { color: var(--uc-text-danger) !important; }
[data-bs-theme] .text-secondary, [data-bs-theme] .text-muted, [data-bs-theme] .link-secondary {
    color: var(--uc-muted-aa) !important;
}
/* texte a 50 % d'opacite (theme HUD : libelles secondaires) : 3,98:1 sur blanc ; remonte a 72 % */
[data-bs-theme] .text-opacity-50 { --bs-text-opacity: 0.72; }
[data-bs-theme] .text-body-secondary { color: var(--uc-muted-aa) !important; }
/* texte secondaire pose sur un bandeau noir / sombre explicite, quel que soit le theme */
[data-bs-theme] :is(.bg-black, .bg-dark, .text-bg-dark) :is(.text-muted, .text-secondary) { color: #a9b6bd !important; }
[data-bs-theme="light"] body { --bs-secondary-color: var(--uc-muted-aa); }
[data-bs-theme="dark"] body {
    --bs-secondary-color: var(--uc-muted-aa);
}
/* textes colores poses sur leur fond « subtle » (pastilles d'etat, alertes) */
[data-bs-theme] .bg-success-subtle.text-success, [data-bs-theme] .bg-danger-subtle.text-danger,
[data-bs-theme] .bg-warning-subtle.text-warning, [data-bs-theme] .bg-info-subtle.text-info,
[data-bs-theme] .bg-primary-subtle.text-primary { font-weight: 600; }
[data-bs-theme="light"] .bg-success-subtle.text-success { color: color-mix(in srgb, var(--bs-success) 50%, #000) !important; }
[data-bs-theme="light"] .bg-danger-subtle.text-danger { color: color-mix(in srgb, var(--bs-danger) 62%, #000) !important; }

/* ─── Surfaces pleines : badges, boutons, bg-* ───────────────────────────────────────────────────────────── */
[data-bs-theme] .bg-primary { background-color: color-mix(in srgb, var(--uc-fill-primary) calc(var(--bs-bg-opacity, 1) * 100%), transparent) !important; }
[data-bs-theme] .bg-success { background-color: color-mix(in srgb, var(--uc-fill-success) calc(var(--bs-bg-opacity, 1) * 100%), transparent) !important; }
[data-bs-theme] .bg-info { background-color: color-mix(in srgb, var(--uc-fill-info) calc(var(--bs-bg-opacity, 1) * 100%), transparent) !important; }
[data-bs-theme] .bg-danger { background-color: color-mix(in srgb, var(--uc-fill-danger) calc(var(--bs-bg-opacity, 1) * 100%), transparent) !important; }
[data-bs-theme] .bg-secondary { background-color: color-mix(in srgb, var(--uc-fill-secondary) calc(var(--bs-bg-opacity, 1) * 100%), transparent) !important; }
/* surface coloree + texte sombre impose (badge bg-info text-dark...) : teinte claire de la couleur, sous le texte sombre */
[data-bs-theme] :is(.bg-primary, .bg-success, .bg-info, .bg-danger, .bg-secondary):is(.text-dark, .text-black) {
    color: var(--uc-on-warning) !important;
}
[data-bs-theme] .bg-primary:is(.text-dark, .text-black) { background-color: color-mix(in srgb, var(--bs-primary) 45%, #fff) !important; }
[data-bs-theme] .bg-success:is(.text-dark, .text-black) { background-color: color-mix(in srgb, var(--bs-success) 45%, #fff) !important; }
[data-bs-theme] .bg-info:is(.text-dark, .text-black) { background-color: color-mix(in srgb, var(--bs-info) 45%, #fff) !important; }
[data-bs-theme] .bg-danger:is(.text-dark, .text-black) { background-color: color-mix(in srgb, var(--bs-danger) 45%, #fff) !important; }
[data-bs-theme] .bg-secondary:is(.text-dark, .text-black) { background-color: color-mix(in srgb, var(--bs-secondary) 45%, #fff) !important; }
[data-bs-theme] .badge.bg-warning, [data-bs-theme] .text-bg-warning, [data-bs-theme] .bg-warning.text-white,
[data-bs-theme] :is(.card-header, .modal-header).bg-warning, [data-bs-theme] :is(.card-header, .modal-header).bg-warning * { color: var(--uc-on-warning) !important; }
[data-bs-theme] .btn-warning {
    --bs-btn-color: var(--uc-on-warning);
    --bs-btn-hover-color: var(--uc-on-warning);
    --bs-btn-active-color: var(--uc-on-warning);
    --bs-btn-disabled-color: var(--uc-on-warning);
}
/* en-tetes de carte / de modale colores : texte blanc force (le theme y met parfois du noir sur le bleu) */
[data-bs-theme] :is(.card-header, .modal-header):is(.bg-primary, .bg-success, .bg-info, .bg-danger, .bg-secondary, .bg-dark):not([class*="bg-opacity"]),
[data-bs-theme] :is(.card-header, .modal-header):is(.bg-primary, .bg-success, .bg-info, .bg-danger, .bg-secondary, .bg-dark):not([class*="bg-opacity"]) :is(h1, h2, h3, h4, h5, h6) {
    color: var(--uc-on-fill) !important;
}
[data-bs-theme] .text-bg-primary { background-color: var(--uc-fill-primary) !important; color: var(--uc-on-fill) !important; }
[data-bs-theme] .text-bg-success { background-color: var(--uc-fill-success) !important; color: var(--uc-on-fill) !important; }
[data-bs-theme] .text-bg-info { background-color: var(--uc-fill-info) !important; color: var(--uc-on-fill) !important; }
[data-bs-theme] .text-bg-danger { background-color: var(--uc-fill-danger) !important; color: var(--uc-on-fill) !important; }
[data-bs-theme] .text-bg-secondary { background-color: var(--uc-fill-secondary) !important; color: var(--uc-on-fill) !important; }
/* fond theme (jaune HUD) : texte de la couleur prevue par le theme, jamais blanc */
[data-bs-theme] .bg-theme.text-white { color: var(--bs-theme-color) !important; }

[data-bs-theme] .btn-primary, [data-bs-theme] .btn-success, [data-bs-theme] .btn-info,
[data-bs-theme] .btn-danger, [data-bs-theme] .btn-secondary {
    --bs-btn-color: var(--uc-on-fill);
    --bs-btn-hover-color: var(--uc-on-fill);
    --bs-btn-active-color: var(--uc-on-fill);
    --bs-btn-bg: var(--uc-btn-fill);
    --bs-btn-border-color: var(--uc-btn-fill);
    --bs-btn-hover-bg: color-mix(in srgb, var(--uc-btn-fill) 85%, #000);
    --bs-btn-hover-border-color: color-mix(in srgb, var(--uc-btn-fill) 85%, #000);
    --bs-btn-active-bg: color-mix(in srgb, var(--uc-btn-fill) 78%, #000);
    --bs-btn-active-border-color: color-mix(in srgb, var(--uc-btn-fill) 78%, #000);
    --bs-btn-disabled-color: var(--uc-on-fill);
    --bs-btn-disabled-bg: var(--uc-btn-fill);
    --bs-btn-disabled-border-color: var(--uc-btn-fill);
}
[data-bs-theme] .btn-primary { --uc-btn-fill: var(--uc-fill-primary); }
[data-bs-theme] .btn-success { --uc-btn-fill: var(--uc-fill-success); }
[data-bs-theme] .btn-info { --uc-btn-fill: var(--uc-fill-info); }
[data-bs-theme] .btn-danger { --uc-btn-fill: var(--uc-fill-danger); }
[data-bs-theme] .btn-secondary { --uc-btn-fill: var(--uc-fill-secondary); }

[data-bs-theme] .btn-outline-primary, [data-bs-theme] .btn-outline-success, [data-bs-theme] .btn-outline-info,
[data-bs-theme] .btn-outline-warning, [data-bs-theme] .btn-outline-danger, [data-bs-theme] .btn-outline-secondary {
    --bs-btn-color: var(--uc-btn-text);
    --bs-btn-border-color: var(--uc-btn-text);
    --bs-btn-hover-color: var(--uc-on-fill);
    --bs-btn-hover-bg: var(--uc-btn-fill);
    --bs-btn-hover-border-color: var(--uc-btn-fill);
    --bs-btn-active-color: var(--uc-on-fill);
    --bs-btn-active-bg: var(--uc-btn-fill);
    --bs-btn-active-border-color: var(--uc-btn-fill);
    --bs-btn-disabled-color: var(--uc-btn-text);
    --bs-btn-disabled-border-color: var(--uc-btn-text);
}
[data-bs-theme] .btn-outline-primary { --uc-btn-text: var(--uc-text-primary); --uc-btn-fill: var(--uc-fill-primary); }
[data-bs-theme] .btn-outline-success { --uc-btn-text: var(--uc-text-success); --uc-btn-fill: var(--uc-fill-success); }
[data-bs-theme] .btn-outline-info { --uc-btn-text: var(--uc-text-info); --uc-btn-fill: var(--uc-fill-info); }
[data-bs-theme] .btn-outline-danger { --uc-btn-text: var(--uc-text-danger); --uc-btn-fill: var(--uc-fill-danger); }
[data-bs-theme] .btn-outline-secondary { --uc-btn-text: var(--uc-muted-aa); --uc-btn-fill: var(--uc-fill-secondary); }
[data-bs-theme] .btn-outline-warning { --uc-btn-text: var(--uc-text-warning); --uc-btn-fill: var(--bs-warning); }
[data-bs-theme] .btn-outline-warning:hover, [data-bs-theme] .btn-outline-warning:active { --bs-btn-hover-color: var(--uc-on-warning); --bs-btn-active-color: var(--uc-on-warning); }
[data-bs-theme] .btn-outline-default { --bs-btn-color: var(--uc-muted-aa); }
/* contour sombre / clair : suit le theme (un contour « dark » sur fond sombre etait invisible) */
[data-bs-theme="dark"] .btn-outline-dark { --bs-btn-color: var(--bs-body-color); --bs-btn-border-color: var(--uc-muted-aa); }
[data-bs-theme="light"] .btn-outline-light { --bs-btn-color: #35434a; --bs-btn-border-color: #90a2aa; }

/* elements actifs poses sur l'accent du theme (jaune en sombre, primaire en clair) */
[data-bs-theme] .list-group-item.active, [data-bs-theme] .list-group-item.active small,
[data-bs-theme] .list-group-item.active .text-white,
[data-bs-theme] .nav-pills .nav-link.active,
[data-bs-theme] .page-item.active .page-link { color: var(--bs-theme-color) !important; }
[data-bs-theme] .nav-pills .nav-link:not(.active) { color: var(--bs-body-color); }

/* aides de formulaire */
[data-bs-theme] .form-text { color: var(--uc-muted-aa); }
/* alerte secondaire en sombre : texte #90a2aa a 4,1:1 sur son fond */
[data-bs-theme="dark"] { --bs-secondary-text-emphasis: #b4c1c7; }

/* ─── Barre laterale et en-tete ──────────────────────────────────────────────────────────────────────────── */
[data-bs-theme="dark"] {
    --bs-app-sidebar-menu-header-color: rgba(255, 255, 255, 0.62);
    --bs-app-sidebar-menu-link-color: rgba(255, 255, 255, 0.72);
}
[data-bs-theme="light"] {
    --bs-app-sidebar-menu-header-color: #5d6a72;
    --bs-app-sidebar-menu-link-color: #4a555c;
}

/* ─── Tableaux ───────────────────────────────────────────────────────────────────────────────────────────── */
/* en-tete sombre (table-dark) : la console y posait son gris « muted » du theme clair */
.ulis-console .table > thead.table-dark th, .table-dark th { --uc-muted: #c0cacf; color: #c0cacf; }
[data-bs-theme="light"] .table-light { --bs-table-color: #1f2328; }

/* ─── Reference OpenAPI (Swagger UI) : composant clair, pose sur une feuille claire en theme sombre ─────── */
[data-bs-theme="dark"] .swagger-ui-host, [data-bs-theme="dark"] #partner-api-reference {
    background: #fff;
    color: #3b4151;
    border-radius: 6px;
    padding: 0.5rem 1rem;
}
.swagger-ui .opblock .opblock-summary-method { color: #000; text-shadow: none; }
.swagger-ui .btn.authorize { color: #136b45; border-color: #136b45; }
.swagger-ui .btn.authorize svg { fill: #136b45; }
