/* D807-CONTRAST-SAFE — Force WCAG AA contrast minimums (4.5:1 normal text, 3:1 large)
   À LA SOURCE: ce fichier est inclus dans send-cockpit + cockpits principaux pour
   prévenir la reproduction de contrastes blanc-sur-blanc OR dark-sur-dark.
   
   Approach: variables CSS forcing min contrast + safety net rules pour text + bg combo dangereux.
   
   Doctrine: D807-ULTIMATE-V2 + Council Supreme guidance "traiter à la source".
*/

/* === Forcing safe color tokens via CSS variables === */
:root {
  --safe-text-on-light: #0f172a;       /* slate-900 - 16:1 sur #fff */
  --safe-text-on-dark: #f1f5f9;        /* slate-100 - 14:1 sur #0f172a */
  --safe-bg-light: #ffffff;
  --safe-bg-dark: #0f172a;
  --safe-link-on-light: #2563eb;       /* blue-600 - 4.5:1 WCAG AA */
  --safe-link-on-dark: #93c5fd;        /* blue-300 - 4.5:1 on dark */
  --safe-muted-on-light: #475569;      /* slate-600 - 7:1 sur #fff */
  --safe-muted-on-dark: #94a3b8;       /* slate-400 - 4.5:1 sur dark */
  --safe-border-on-light: #cbd5e1;
  --safe-border-on-dark: #334155;
}

/* === Anti white-on-white safety net === */
/* Si bg est blanc explicite, force text dark */
[style*="background:#fff"]:not([style*="color:"]),
[style*="background: #fff"]:not([style*="color:"]),
[style*="background:#ffffff"]:not([style*="color:"]),
[style*="background: #ffffff"]:not([style*="color:"]),
[style*="background-color:#fff"]:not([style*="color:"]),
[style*="background-color: #fff"]:not([style*="color:"]),
[style*="background:white"]:not([style*="color:"]),
[style*="background: white"]:not([style*="color:"]) {
  color: var(--safe-text-on-light) !important;
}

/* Si text blanc sur bg non spécifié explicit dark, force fallback safe */
[style*="color:#fff"]:not([style*="background"]):not([style*="-gradient"]),
[style*="color: #fff"]:not([style*="background"]):not([style*="-gradient"]),
[style*="color:#ffffff"]:not([style*="background"]):not([style*="-gradient"]),
[style*="color: white"]:not([style*="background"]):not([style*="-gradient"]) {
  text-shadow: 0 0 2px rgba(0,0,0,0.5);  /* safety silhouette if invisible */
}

/* === Anti dark-on-dark safety net === */
/* Si text noir sur bg dark explicit, override text vers light */
[style*="background:#000"][style*="color:#000"],
[style*="background:#0f172a"][style*="color:#000"],
[style*="background:#1e293b"][style*="color:#000"],
[style*="background:#111"][style*="color:#0"] {
  color: var(--safe-text-on-dark) !important;
}

/* Auto-detection : if light text on light bg detected via filters */
body[data-theme="dark"] *[style*="color:#000"]:not([style*="background"]) {
  color: var(--safe-text-on-dark) !important;
}
body[data-theme="light"] *[style*="color:#fff"]:not([style*="background"]):not([style*="-gradient"]) {
  color: var(--safe-text-on-light) !important;
}

/* === Form fields safety net (textarea, input often dark text on dark bg) === */
input, textarea, select {
  color: var(--safe-text-on-light);
  background: var(--safe-bg-light);
  border: 1px solid var(--safe-border-on-light);
}

@media (prefers-color-scheme: dark) {
  input, textarea, select {
    color: var(--safe-text-on-dark);
    background: var(--safe-bg-dark);
    border-color: var(--safe-border-on-dark);
  }
}

input::placeholder, textarea::placeholder {
  color: var(--safe-muted-on-light);
  opacity: 1;
}

@media (prefers-color-scheme: dark) {
  input::placeholder, textarea::placeholder {
    color: var(--safe-muted-on-dark);
  }
}

/* === Buttons safety net === */
button:not([style*="color"]):not([style*="background"]) {
  color: var(--safe-text-on-light);
  background: var(--safe-bg-light);
  border: 1px solid var(--safe-border-on-light);
}

button:disabled {
  color: var(--safe-muted-on-light) !important;
  background: #f1f5f9 !important;
  cursor: not-allowed;
}

/* === Links safety net === */
a:not([style*="color"]) {
  color: var(--safe-link-on-light);
}

@media (prefers-color-scheme: dark) {
  a:not([style*="color"]) {
    color: var(--safe-link-on-dark);
  }
}

/* === Pre/code blocks safety net === */
pre, code {
  color: var(--safe-text-on-light);
  background: #f8fafc;
  border: 1px solid var(--safe-border-on-light);
}

body[data-theme="dark"] pre, body[data-theme="dark"] code {
  color: var(--safe-text-on-dark);
  background: #1e293b;
  border-color: var(--safe-border-on-dark);
}

/* === Dropdown/select option safety === */
option {
  color: var(--safe-text-on-light);
  background: var(--safe-bg-light);
}

/* === Modal/dialog safety: ensure backdrop has enough contrast === */
[role="dialog"], dialog, .modal {
  color: var(--safe-text-on-light);
  background: var(--safe-bg-light);
}

/* === ARIA tooltips/popups safety === */
[role="tooltip"], [role="status"] {
  color: var(--safe-text-on-dark);
  background: rgba(15, 23, 42, 0.95);
}

/* === Watermark for auditability === */
html::before {
  content: "D807-CONTRAST-SAFE";
  display: none;
  /* Marker pour scan automatique futur */
}

/* D1494 contraste cockpit a la source: --mute est override au runtime en #f5f7fa (near-white) => 78 textes blanc/blanc sur fond blanc (nuclear). On force --mute en gris sombre WCAG-AA (#475569 ~7:1) ici, fichier contraste dedie, !important pour battre l override. Un seul token corrige tous les var(--mute) (lbl/sub/pd/mt-desc...). */
:root { --mute:#475569 !important; }
/* D1507 --warn aussi blanchi par nuclear (#f5f7fa) -> amber lisible sur blanc (OANDA action requise, logs, kbd) */
:root { --warn:#b45309 !important; }

/* D1494c cockpit cellules PnL/KPI: le JS pose un color near-white inline qui masque le vert/rouge semantique. On restaure pos/neg + defaut sombre (bat inline non-important). */
.num.pos, .tr-pnl.pos { color:#15803d !important; }
.num.neg, .tr-pnl.neg { color:#b91c1c !important; }
#pnl-balance, .v, .num:not(.pos):not(.neg), .tr-pnl:not(.pos):not(.neg) { color:#0b1220 !important; }


/* D1494d — Multimodal Analysis panel (trading-cockpit): le NUCLEAR VERROUILLE le fond -> blanc (250,250,250), il bat meme !important sur background (piege D1483). Le garde lit le gradient inline sombre et pose texte clair #f5f7fa => clair-sur-blanc = 6 flags. Methode autre-Claude: flipper la propriete que le nuclear NE verrouille PAS = la COULEUR DU TEXTE -> sombre (le fond etant blanc verrouille). 1 regle ciblee, !important, bat le garde. */
#multimodal-panel { background-image:none !important; background-color:#f5f7fa !important; }
#multimodal-panel, #multimodal-panel * { color:#1e293b !important; -webkit-text-fill-color:#1e293b !important; }
#multimodal-panel input, #multimodal-panel textarea, #multimodal-panel select { background-color:#ffffff !important; border-color:#cbd5e1 !important; }
/* D1507b kbd badge + logs (#gpu-log/#feed) blanchis par nuclear -> lisibles */
kbd { color:#0b1220 !important; background:#e2e8f0 !important; border:1px solid #cbd5e1 !important; }
#gpu-log, #gpu-log div, #feed, #feed div { color:#1e293b !important; }
/* D1507c kbd+logs: battre le nuclear via specificite (html body) + -webkit-text-fill-color */
html body kbd { color:#0b1220 !important; -webkit-text-fill-color:#0b1220 !important; background:#e2e8f0 !important; }
html body #gpu-log, html body #gpu-log *, html body #feed, html body #feed * { color:#1e293b !important; -webkit-text-fill-color:#1e293b !important; }
