/*
 * SimplAI — design system : modes clair / sombre (repris de la 7.6.138, adapté à la 7.6.117 et au bleu de la marque #0057FF)
 *
 * PRINCIPE : le mode clair est le rendu historique, inchangé au pixel près. Chaque couleur claire des pages est écrite
 *   var(--sx-<rôle>, <couleur d'origine>)
 * Sans attribut data-theme="dark", les variables --sx-* n'existent pas : la couleur d'origine s'applique (aucune régression).
 * En mode sombre, ce fichier définit UNE SEULE FOIS toutes les couleurs sémantiques (aucune inversion automatique, aucun filtre).
 * Palette : bleu nuit + graphite + bleu officiel SIMPLAI (#0057FF, celui de la vitrine).
 *
 * Impression : les jetons ne sont pas définis à l'impression (@media not print) : factures, bulletins de paie et états gardent
 * leurs couleurs d'impression. Aperçus de documents à l'écran : classe .sx-keep-light (toujours clairs).
 */

@media not print {
  html[data-theme="dark"] {
    color-scheme: dark;

    /* Surfaces */
    --sx-bg: #0C1422;            /* fond de page */
    --sx-nav: #101A2B;           /* navigation, barres, éléments très sombres */
    --sx-card: #172439;          /* cartes, panneaux, modales */
    --sx-surface-2: #202F44;     /* surfaces secondaires : en-têtes de tableau, lignes alternées */
    --sx-surface-3: #283A52;     /* survol, pistes, séparateurs pleins */
    --sx-border: #304158;
    --sx-border-strong: #445A78;
    --sx-input-bg: #101A2B;
    --sx-input-border: #566F90;

    /* Textes (contrastes mesurés sur --sx-card : 14,5 / 9,5 / 7,0 / 5,6) */
    --sx-text: #F4F7FC;
    --sx-text-2: #BDCBDC;
    --sx-muted: #9DB0C6;
    --sx-faint: #8A9DB5;

    /* Bleu officiel SIMPLAI (#0057FF) pour les actions ; variante claire pour les textes et liens */
    --sx-accent: #0057FF;        /* texte blanc dessus : 5,5:1 */
    --sx-accent-hover: #1F6BFF;  /* texte blanc dessus : 4,6:1 */
    --sx-accent-text: #85B0FF;
    --sx-accent-soft: rgba(77, 139, 255, .16);
    --sx-accent-soft-2: rgba(77, 139, 255, .26);
    --sx-accent-border: rgba(122, 168, 255, .40);
    --sx-focus: #7AA8FF;

    /* Statuts */
    --sx-ok-fg: #5BD68F;   --sx-ok-bg: rgba(34, 197, 94, .14);   --sx-ok-bd: rgba(34, 197, 94, .40);
    --sx-err-fg: #FF8F8F;  --sx-err-bg: rgba(239, 68, 68, .16);  --sx-err-bd: rgba(239, 68, 68, .44);
    --sx-warn-fg: #F2B84B; --sx-warn-bg: rgba(245, 158, 11, .14); --sx-warn-bd: rgba(245, 158, 11, .42);
    --sx-or-fg: #FFA463;   --sx-or-bg: rgba(249, 115, 22, .15);  --sx-or-bd: rgba(249, 115, 22, .42);
    --sx-viol-fg: #B9A7FF; --sx-viol-bg: rgba(139, 92, 246, .18); --sx-viol-bd: rgba(139, 92, 246, .44);
    --sx-teal-fg: #4FD9C8; --sx-teal-bg: rgba(20, 184, 166, .15); --sx-teal-bd: rgba(20, 184, 166, .42);

    /* Teintes de survol, ombres, voile des fenêtres modales */
    --sx-tint: rgba(255, 255, 255, .05);
    --sx-tint-2: rgba(255, 255, 255, .09);
    --sx-shadow: 0 1px 2px rgba(0, 0, 0, .40), 0 8px 24px rgba(0, 0, 0, .32);
    --sx-overlay: rgba(4, 9, 19, .66);
    --sx-white: #FFFFFF;         /* texte blanc conservé (pages à fond sombre ou coloré) */

    /* Fonds pleins portant du texte blanc : variantes assombries (même teinte) pour atteindre 4,5:1 — table générée par scripts/design/applyThemeTokens.js */
    /* sx-solids:start */
    --sx-solid-059669: #048059;
    --sx-solid-0d9488: #0B7F75;
    --sx-solid-10b981: #0B815A;
    --sx-solid-159d62: #118251;
    --sx-solid-16a34a: #11813B;
    --sx-solid-b7791f: #9D681B;
    --sx-solid-b8860b: #946C09;
    --sx-solid-c9a84c: #886F29;
    --sx-solid-d97706: #AC5F05;
    --sx-solid-ef4444: #E21313;
    --sx-solid-f59e0b: #9E6506;
    /* sx-solids:end */
  }

  html[data-theme="light"] { color-scheme: light; }

  /* Aperçus de documents (modèles de facture, bulletin de paie, logos, cachets) : papier blanc et encre d'origine dans les deux thèmes */
  /* spécificité nulle : la couleur propre de chaque aperçu (blanc sur bleu, or sur noir…) reste prioritaire ; ceci ne remplace que le texte clair hérité de la page */
  :where(html[data-theme="dark"]) :where(.sx-keep-light,.tpl-preview,.template-preview,.payslip-page,.pay-brand-preview,.logo-preview) { color: #081640; }
  /* Variables de page déjà résolues en sombre au niveau de la page : remises à leur valeur d’impression dans les vignettes de modèles de facture (Facturation) */
  html[data-theme="dark"] .tpl-preview { --mut: #5D6C88; --bor: #E0E7F5; }

  /* Aperçus de documents officiels à l'écran : toujours en couleurs d'impression */
  html[data-theme="dark"] :is(.sx-keep-light,.tpl-preview,.template-preview,.payslip-page,.pay-brand-preview,.logo-preview),
  html[data-theme="dark"] :is(.sx-keep-light,.tpl-preview,.template-preview,.payslip-page,.pay-brand-preview,.logo-preview) * {
    --sx-white: initial;
    --sx-bg: initial; --sx-nav: initial; --sx-card: initial; --sx-surface-2: initial; --sx-surface-3: initial;
    --sx-border: initial; --sx-border-strong: initial; --sx-input-bg: initial; --sx-input-border: initial;
    --sx-text: initial; --sx-text-2: initial; --sx-muted: initial; --sx-faint: initial;
    --sx-accent: initial; --sx-accent-hover: initial; --sx-accent-text: initial; --sx-accent-soft: initial;
    --sx-accent-soft-2: initial; --sx-accent-border: initial; --sx-focus: initial;
    --sx-ok-fg: initial; --sx-ok-bg: initial; --sx-ok-bd: initial; --sx-err-fg: initial; --sx-err-bg: initial; --sx-err-bd: initial;
    --sx-warn-fg: initial; --sx-warn-bg: initial; --sx-warn-bd: initial; --sx-or-fg: initial; --sx-or-bg: initial; --sx-or-bd: initial;
    --sx-viol-fg: initial; --sx-viol-bg: initial; --sx-viol-bd: initial; --sx-teal-fg: initial; --sx-teal-bg: initial; --sx-teal-bd: initial;
    --sx-tint: initial; --sx-tint-2: initial; --sx-shadow: initial; --sx-overlay: initial;
    color-scheme: light;
  }
}

/* Contrôles natifs : fond et texte explicites (listes déroulantes, saisies sans style propre) — spécificité nulle : les styles des pages priment */
:where(html[data-theme="dark"]) :where(input, select, textarea):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="button"]):not([type="submit"]) {
  background-color: var(--sx-input-bg);
  color: var(--sx-text);
  border-color: var(--sx-input-border);
}
:where(html[data-theme="dark"]) :where(select option, select optgroup) { background-color: var(--sx-card); color: var(--sx-text); }
:where(html[data-theme="dark"]) ::placeholder { color: var(--sx-faint); opacity: 1; }
:where(html[data-theme="dark"]) ::selection { background: rgba(0, 87, 255, .45); color: #fff; }
:where(html[data-theme="dark"]) hr { border-color: var(--sx-border); }

/* Barres de défilement discrètes */
html[data-theme="dark"] { scrollbar-color: #3A4E6B #0C1422; }

/* Focus clavier visible dans les deux thèmes (spécificité nulle : un état de focus propre à un composant reste prioritaire) */
:where(a, button, [role="button"], [role="tab"], input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--sx-focus, #0057FF);
  outline-offset: 2px;
}

/* ── Bouton unique soleil / lune ───────────────────────────────────────────────────────────── */
.sx-theme-toggle {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 36px; height: 36px; padding: 0; margin: 0 4px;
  border-radius: 10px; border: 1px solid rgba(148, 163, 184, .38);
  background: rgba(255, 255, 255, .10); color: inherit;
  cursor: pointer; line-height: 1; font: inherit;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.sx-theme-toggle:hover { background: rgba(148, 163, 184, .22); border-color: rgba(148, 163, 184, .6); }
.sx-theme-toggle:active { transform: translateY(1px); }
.sx-theme-toggle svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.sx-theme-toggle .sx-sun { display: none; }
html[data-theme="dark"] .sx-theme-toggle .sx-sun { display: block; }
html[data-theme="dark"] .sx-theme-toggle .sx-moon { display: none; }
html[data-theme="dark"] .sx-theme-toggle { border-color: var(--sx-border-strong); background: var(--sx-tint); color: var(--sx-text); }
html[data-theme="dark"] .sx-theme-toggle:hover { background: var(--sx-tint-2); }
/* Repli : page sans en-tête reconnu → bouton flottant discret en haut à droite */
.sx-theme-toggle.sx-floating {
  position: fixed; top: calc(10px + env(safe-area-inset-top, 0px)); right: calc(12px + env(safe-area-inset-right, 0px)); z-index: 2147483000; margin: 0;
  background: #FFFFFF; color: #0F172A; border-color: #CBD5E1; box-shadow: 0 2px 8px rgba(15, 23, 42, .12);
}
html[data-theme="dark"] .sx-theme-toggle.sx-floating { background: var(--sx-card); color: var(--sx-text); border-color: var(--sx-border-strong); box-shadow: var(--sx-shadow); }
@media (max-width: 520px) { .sx-theme-toggle { width: 40px; height: 40px; } }
@media (prefers-reduced-motion: reduce) { .sx-theme-toggle { transition: none; } }
@media print { .sx-theme-toggle { display: none !important; } }
/* Téléphone et tablette, écrans de société : bande de 58 px déjà réservée en haut (bouton menu ☰ fixé à gauche).
   Le bouton de thème s’y place en symétrique, fixé à droite, au lieu d’ajouter une ligne dans l’en-tête de la page. */
@media (max-width: 760px), (hover: none), (pointer: coarse) {
  body.has-company-sidebar .sx-theme-toggle:not(.sx-floating) { position: fixed; top: 10px; right: 12px; z-index: 9105; width: 40px; height: 40px; margin: 0; border-radius: 12px;
    background: var(--sx-nav, #0B1F3A); border: 1px solid rgba(147, 197, 253, .35); color: #FFFFFF; box-shadow: 0 10px 24px rgba(15, 23, 42, .22); }
  body.has-company-sidebar .sx-theme-toggle.sx-floating { top: 10px; right: 12px; width: 40px; height: 40px; border-radius: 12px; }
}

/* ── Ajustements de composants (mode sombre) ───────────────────────────────────────────────────
 * Teintes propres à chaque solution (bleu, menthe, soleil, iris, corail…) : trop sombres en texte sur une carte sombre.
 * On éclaircit la teinte d'origine de 45 % vers le blanc (même famille de couleur, contraste ≥ 4,5:1 sur --sx-card). */
html[data-theme="dark"] .mod-card2-kicker { color: color-mix(in srgb, var(--module-tone, #2F6FF4) 55%, #fff); }
html[data-theme="dark"] body[data-simplai-theme] .choice .choice-number,
html[data-theme="dark"] body[data-simplai-screen="hub"] .choice .choice-number { color: color-mix(in srgb, var(--icon, #2F6FF4) 55%, #fff) !important; }
/* Texte atténué par opacité (carte « nouvelle société ») : opacité relevée pour garder 4,5:1 */
html[data-theme="dark"] .new-company-card [style*="opacity:.7"] { opacity: .9 !important; }

/* Pages publiques (tarifs, présentation, fonctionnalités…) : textes en blanc translucide relevés pour atteindre 4,5:1 sur fond nuit */
html[data-theme="dark"] .pub-footer-tagline, html[data-theme="dark"] .pub-footer-col-title,
html[data-theme="dark"] .pub-footer-copy, html[data-theme="dark"] .pub-footer-legal a,
html[data-theme="dark"] .pub-footer-links a, html[data-theme="dark"] .cta-trust-item,
html[data-theme="dark"] .hp-reas-i, html[data-theme="dark"] .about-num2-lbl,
html[data-theme="dark"] .hero-anchor, html[data-theme="dark"] .roi-vis > div, html[data-theme="dark"] .roi-vis > p { color: rgba(255, 255, 255, .64); }
html[data-theme="dark"] .pub-footer-tag { color: rgba(255, 255, 255, .7); }
html[data-theme="dark"] .fb-blue { color: #85B0FF; }
html[data-theme="dark"] .fb-grn { color: #5BD68F; }
html[data-theme="dark"] .fb-purple, html[data-theme="dark"] .eyebrow-purple { color: #B9A7FF; }
html[data-theme="dark"] li.off .pcx { color: #8A9DB5; }
html[data-theme="dark"] .pub-nav-link.current { color: #85B0FF !important; }
html[data-theme="dark"] .roi-vis > div, html[data-theme="dark"] .roi-vis > p, html[data-theme="dark"] .arch-vis2 > div, html[data-theme="dark"] .about-vis2 > div { color: rgba(255, 255, 255, .66) !important; }
/* Page « Ouverture prochainement » (fond nuit natif) : étiquettes en blanc translucide relevées */
html[data-theme="dark"] .desc-ar, html[data-theme="dark"] .cd-label { color: rgba(255, 255, 255, .66); }

/* Très petits écrans : l'en-tête du portefeuille (logo + bouton de thème + profil + déconnexion) doit tenir sur 375 px sans rogner « Déconnexion » */
@media (max-width: 420px) {
  .topbar > .topbar-nav .topbar-user { padding-right: 6px; gap: 4px; }
  .topbar > .topbar-nav .topbar-user > .sx-theme-toggle { width: 32px; height: 32px; margin: 0; }
  .topbar:has(> .topbar-nav .topbar-user > .sx-theme-toggle) { padding-left: 12px; padding-right: 12px; gap: 8px; }
  .topbar:has(> .topbar-nav .topbar-user > .sx-theme-toggle) .topbar-nav { gap: 6px; }
}
