/* ============================================================================
   CreArtisite v4 — theme.css — Palette partagee clair / sombre  (lot 36)
   ============================================================================
   A charger EN PREMIER sur toutes les pages applicatives, avant auth.css.

   Convention (partagee avec l'editeur, lot 35) :
     - attribut  data-theme  sur <html> : "dark" (defaut) | "light"
     - cle localStorage      : cas-editor-theme  -> "dark" | "light" | "auto"
     - "auto" est resolu en dark/light par le script anti-flash avant le rendu ;
       la regle [data-theme="auto"] ci-dessous n'est qu'un filet de securite.

   Le mode sombre reproduit a l'identique les valeurs historiques de auth.css
   (dont le bloc :root a ete deplace ici) : aucune couleur calculee ne change.

   Trois familles de jetons :
     1. --xxx-rgb  : canaux RGB, pour les voiles rgba(var(--xxx-rgb), alpha)
     2. --xxx      : couleurs pleines, lisibles sur le fond du mode courant
     3. --sd-xxx   : jeu commun avec studio.css (editeur) : fond, carte,
                     bordure, texte, accent, succes, danger, alerte, ombres
   ============================================================================ */

/* ---------------------------------------------------------------------------
   MODE SOMBRE (defaut — valeurs historiques, ne pas modifier sans mesurer)
   --------------------------------------------------------------------------- */
:root {
    color-scheme: dark;

    /* --- canaux RGB (voiles et teintes) --- */
    --cyan-rgb: 0, 229, 255;
    --purple-rgb: 179, 136, 255;
    --gold-rgb: 255, 215, 64;
    --pink-rgb: 255, 94, 126;
    --green-rgb: 0, 229, 175;
    --orange-rgb: 255, 159, 10;
    /* voile pose SUR le fond : blanc en sombre, encre en clair */
    --surface-rgb: 255, 255, 255;
    /* couleur des panneaux opaques (menus, toasts, popovers) */
    --panel-rgb: 10, 18, 36;
    /* barres fixes et voiles poses sur une photo */
    --header-rgb: 6, 11, 24;
    /* boutons flottants au-dessus d'une vignette */
    --shade-rgb: 8, 12, 24;
    /* feuilles glissantes mobiles */
    --sheet-rgb: 8, 14, 30;
    /* overlay plein ecran du parcours de creation */
    --overlay-rgb: 2, 10, 19;
    /* ombres portees et voiles de modale */
    --shadow-rgb: 0, 0, 0;
    --scrim-rgb: 2, 6, 16;

    /* --- fonds --- */
    --bg-1: #060b18;
    --bg-2: #020a13;
    --bg-app: linear-gradient(160deg, var(--bg-1), var(--bg-2));
    --bg-glow-1: rgba(0, 229, 255, 0.18);
    --bg-glow-2: rgba(179, 136, 255, 0.22);
    --grid-line: rgba(0, 229, 255, 0.04);

    /* --- couleurs de marque, lisibles comme texte sur le fond courant --- */
    --cyan: #00e5ff;
    --purple: #b388ff;
    --gold: #ffd740;
    --pink: #ff5e7e;
    --green: #00e9b5;
    --orange: #ff9f0a;
    /* variantes pastel employees comme texte sur pastille teintee (sombre) */
    --green-soft: #00e5af;
    --purple-soft: #d4baff;
    --gold-soft: #ffe17a;
    --pink-soft: #ffd0d8;

    /* --- couleurs de marque decoratives (remplissages vifs, invariantes) --- */
    --cyan-vivid: #00e5ff;
    --gold-vivid: #ffd740;
    --orange-vivid: #ff9f0a;
    --purple-vivid: #b388ff;

    /* --- texte --- */
    --ink: #e7ecff;
    --ink-rgb: 231, 236, 255;
    --muted: #8aa0c8;
    --dim: #5a6f95;
    /* texte pose sur un aplat de couleur d'accent */
    --on-accent: #020a13;
    --on-cyan: #001a22;
    --on-gold: #1a1200;

    /* --- surfaces --- */
    --card-bg: rgba(10, 18, 36, 0.65);
    --card-border: rgba(0, 229, 255, 0.18);
    --panel-bg: rgba(10, 18, 36, 0.97);
    --panel-bg-soft: rgba(10, 18, 36, 0.85);
    --header-bg: rgba(6, 11, 24, 0.85);
    --input-bg: rgba(255, 255, 255, 0.04);
    --input-border: rgba(255, 255, 255, 0.12);
    --input-focus: rgba(179, 136, 255, 0.5);
    /* fond des vignettes / apercus d'images */
    --thumb-bg: #0a1020;

    /* --- ombres (retravaillees en clair : plus courtes, moins opaques) --- */
    --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 12px 36px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 40px 100px rgba(0, 0, 0, 0.5);
    --shadow-card: 0 30px 80px rgba(0, 0, 0, 0.5);
    --shadow-sheet: 0 -20px 60px rgba(0, 0, 0, 0.6);
    --scrim: rgba(0, 0, 0, 0.6);
    --scrim-soft: rgba(2, 6, 16, 0.7);

    /* --- jeu commun avec studio.css (editeur) --- */
    --sd-bg: #0B0F1A;
    --sd-bg-elevated: #141A2A;
    --sd-bg-card: #1A2137;
    --sd-bg-hover: #232B45;
    --sd-border: #2A3454;
    --sd-border-light: #3A4670;
    --sd-text: #F1F5FB;
    --sd-text-muted: #8894B5;
    --sd-accent: #7C3AED;
    --sd-accent-hover: #8B4FFF;
    --sd-accent-glow: rgba(124, 58, 237, 0.3);
    --sd-success: #10B981;
    --sd-danger: #EF4444;
    --sd-warning: #F59E0B;
    --sd-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    --sd-shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
}

/* ---------------------------------------------------------------------------
   MODE CLAIR
   Contrastes verifies par calcul (WCAG 2.1) sur les trois fonds de reference
   #fdfdfe (carte), #f4f7fc (--bg-1) et #e9eef7 (--bg-2) :
     ink #101828      17,5 / 16,5 / 15,2
     muted #4b5a75     6,8 /  6,5 /  6,0
     dim #58677f       5,6 /  5,3 /  4,9
     cyan #0b6d80      5,9 /  5,6 /  5,1
     purple #6d28d9    7,0 /  6,6 /  6,1
     gold #705400      6,6 /  6,2 /  5,7
     pink #b3203f      6,4 /  6,0 /  5,6
     green #046048     7,6 /  7,2 /  6,6
     orange #a34a08    5,8 /  5,5 /  5,1
   Les couleurs de marque servent aussi de texte SUR leur propre teinte a 15-22 %
   (pastilles « Publie », « Premium », « approved »...). Ce cas, le plus dur, a
   ete calibre en dernier : green 5,2  gold 5,0  purple 4,8  cyan 4,7  pink 4,8.
   Blanc sur aplat d'accent : cyan 6,0  purple 7,1  green 5,5  pink 5,6.
   Bordure de champ rgba(16,24,40,.5) sur blanc : 3,4:1 (WCAG 1.4.11).
   --------------------------------------------------------------------------- */
:root[data-theme="light"] {
    color-scheme: light;

    --cyan-rgb: 11, 109, 128;
    --purple-rgb: 109, 40, 217;
    --gold-rgb: 112, 84, 0;
    --pink-rgb: 179, 32, 63;
    --green-rgb: 4, 96, 72;
    --orange-rgb: 163, 74, 8;
    /* le voile devient sombre : il assombrit au lieu d'eclaircir */
    --surface-rgb: 16, 24, 40;
    --panel-rgb: 255, 255, 255;
    --header-rgb: 255, 255, 255;
    --shade-rgb: 255, 255, 255;
    --sheet-rgb: 255, 255, 255;
    --overlay-rgb: 30, 41, 59;
    /* ardoise plutot qu'encre : une ombre a 50 % reste douce en clair */
    --shadow-rgb: 100, 116, 139;
    --scrim-rgb: 30, 41, 59;

    --bg-1: #f4f7fc;
    --bg-2: #e9eef7;
    --bg-app: linear-gradient(160deg, var(--bg-1), var(--bg-2));
    --bg-glow-1: rgba(0, 229, 255, 0.16);
    --bg-glow-2: rgba(179, 136, 255, 0.16);
    --grid-line: rgba(16, 24, 40, 0.045);

    --cyan: #0b6d80;
    --purple: #6d28d9;
    --gold: #705400;
    --pink: #b3203f;
    --green: #046048;
    --orange: #a34a08;
    --green-soft: #046048;
    --purple-soft: #6d28d9;
    --gold-soft: #705400;
    --pink-soft: #b3203f;

    /* remplissages vifs conserves (texte fonce dessus, contraste 11,7 et 13,3) */
    --cyan-vivid: #00e5ff;
    --gold-vivid: #ffd740;
    --orange-vivid: #ff9f0a;
    --purple-vivid: #7c3aed;

    --ink: #101828;
    --ink-rgb: 16, 24, 40;
    --muted: #4b5a75;
    --dim: #58677f;
    --on-accent: #ffffff;
    --on-cyan: #ffffff;
    --on-gold: #1a1200;

    --card-bg: rgba(255, 255, 255, 0.92);
    --card-border: rgba(11, 109, 128, 0.38);
    --panel-bg: rgba(255, 255, 255, 0.98);
    --panel-bg-soft: rgba(255, 255, 255, 0.9);
    --header-bg: rgba(255, 255, 255, 0.88);
    --input-bg: #ffffff;
    /* 3,4:1 contre le blanc : contraste non-textuel WCAG 1.4.11 respecte */
    --input-border: rgba(16, 24, 40, 0.5);
    --input-focus: rgba(109, 40, 217, 0.55);
    --thumb-bg: #e6eaf2;

    --shadow-sm: 0 2px 6px rgba(16, 24, 40, 0.08);
    --shadow-md: 0 8px 22px rgba(16, 24, 40, 0.10);
    --shadow-lg: 0 14px 34px rgba(16, 24, 40, 0.12);
    --shadow-xl: 0 22px 56px rgba(16, 24, 40, 0.14);
    --shadow-card: 0 16px 44px rgba(16, 24, 40, 0.10);
    --shadow-sheet: 0 -12px 34px rgba(16, 24, 40, 0.14);
    --scrim: rgba(16, 24, 40, 0.45);
    --scrim-soft: rgba(16, 24, 40, 0.35);

    --sd-bg: #F5F7FB;
    --sd-bg-elevated: #FFFFFF;
    --sd-bg-card: #FFFFFF;
    --sd-bg-hover: #EDF1F8;
    --sd-border: #D6DEEC;
    --sd-border-light: #BFCADE;
    --sd-text: #101828;
    --sd-text-muted: #4b5a75;
    --sd-accent: #6D28D9;
    --sd-accent-hover: #5B21B6;
    --sd-accent-glow: rgba(109, 40, 217, 0.22);
    --sd-success: #047857;
    --sd-danger: #B91C1C;
    --sd-warning: #A34A08;
    --sd-shadow: 0 2px 6px rgba(16, 24, 40, 0.08);
    --sd-shadow-lg: 0 14px 34px rgba(16, 24, 40, 0.12);
}

/* Filet de securite : si data-theme="auto" reste en place (JS desactive
   apres un choix "auto"), on suit la preference systeme. */
@media (prefers-color-scheme: light) {
    :root[data-theme="auto"] {
        color-scheme: light;

        --cyan-rgb: 11, 109, 128;
        --purple-rgb: 109, 40, 217;
        --gold-rgb: 112, 84, 0;
        --pink-rgb: 179, 32, 63;
        --green-rgb: 4, 96, 72;
        --orange-rgb: 163, 74, 8;
        --surface-rgb: 16, 24, 40;
        --panel-rgb: 255, 255, 255;
        --header-rgb: 255, 255, 255;
        --shade-rgb: 255, 255, 255;
        --sheet-rgb: 255, 255, 255;
        --overlay-rgb: 30, 41, 59;
        --shadow-rgb: 100, 116, 139;
        --scrim-rgb: 30, 41, 59;

        --bg-1: #f4f7fc;
        --bg-2: #e9eef7;
        --bg-glow-1: rgba(0, 229, 255, 0.16);
        --bg-glow-2: rgba(179, 136, 255, 0.16);
        --grid-line: rgba(16, 24, 40, 0.045);

        --cyan: #0b6d80;
        --purple: #6d28d9;
        --gold: #705400;
        --pink: #b3203f;
        --green: #046048;
        --orange: #a34a08;
        --green-soft: #046048;
        --purple-soft: #6d28d9;
        --gold-soft: #705400;
        --pink-soft: #b3203f;
        --orange-vivid: #ff9f0a;
        --purple-vivid: #7c3aed;

        --ink: #101828;
        --ink-rgb: 16, 24, 40;
        --muted: #4b5a75;
        --dim: #58677f;
        --on-accent: #ffffff;
        --on-cyan: #ffffff;

        --card-bg: rgba(255, 255, 255, 0.92);
        --card-border: rgba(11, 109, 128, 0.38);
        --panel-bg: rgba(255, 255, 255, 0.98);
        --panel-bg-soft: rgba(255, 255, 255, 0.9);
        --header-bg: rgba(255, 255, 255, 0.88);
        --input-bg: #ffffff;
        /* 3,4:1 contre le blanc : contraste non-textuel WCAG 1.4.11 respecte */
    --input-border: rgba(16, 24, 40, 0.5);
        --input-focus: rgba(109, 40, 217, 0.55);
        --thumb-bg: #e6eaf2;

        --shadow-sm: 0 2px 6px rgba(16, 24, 40, 0.08);
        --shadow-md: 0 8px 22px rgba(16, 24, 40, 0.10);
        --shadow-lg: 0 14px 34px rgba(16, 24, 40, 0.12);
        --shadow-xl: 0 22px 56px rgba(16, 24, 40, 0.14);
        --shadow-card: 0 16px 44px rgba(16, 24, 40, 0.10);
        --shadow-sheet: 0 -12px 34px rgba(16, 24, 40, 0.14);
        --scrim: rgba(16, 24, 40, 0.45);
        --scrim-soft: rgba(16, 24, 40, 0.35);

        --sd-bg: #F5F7FB;
        --sd-bg-elevated: #FFFFFF;
        --sd-bg-card: #FFFFFF;
        --sd-bg-hover: #EDF1F8;
        --sd-border: #D6DEEC;
        --sd-border-light: #BFCADE;
        --sd-text: #101828;
        --sd-text-muted: #4b5a75;
        --sd-accent: #6D28D9;
        --sd-accent-hover: #5B21B6;
        --sd-accent-glow: rgba(109, 40, 217, 0.22);
        --sd-success: #047857;
        --sd-danger: #B91C1C;
        --sd-warning: #A34A08;
        --sd-shadow: 0 2px 6px rgba(16, 24, 40, 0.08);
        --sd-shadow-lg: 0 14px 34px rgba(16, 24, 40, 0.12);
    }
}

/* ---------------------------------------------------------------------------
   BASCULE CLAIR / SOMBRE (bouton pose par theme-toggle.js)
   --------------------------------------------------------------------------- */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    padding: 0;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    background: var(--input-bg);
    color: var(--ink);
    cursor: pointer;
    transition: background 0.18s, border-color 0.18s, color 0.18s;
    -webkit-appearance: none;
    appearance: none;
}

.theme-toggle:hover {
    background: rgba(var(--cyan-rgb), 0.10);
    border-color: rgba(var(--cyan-rgb), 0.4);
    color: var(--cyan);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
    display: block;
    pointer-events: none;
}

/* une seule icone visible a la fois */
.theme-toggle .tt-moon { display: none; }
.theme-toggle .tt-sun { display: block; }
:root[data-theme="light"] .theme-toggle .tt-sun { display: none; }
:root[data-theme="light"] .theme-toggle .tt-moon { display: block; }

/* Variante « ligne de menu » (menu ⋯ mobile, preferences du profil) */
.theme-toggle-row {
    width: 100%;
    height: auto;
    min-height: 44px;
    justify-content: flex-start;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 10px;
    font: inherit;
    font-size: 0.94rem;
    text-align: left;
}

.theme-toggle-row .tt-label { display: inline; }
.theme-toggle .tt-label { display: none; }

/* Le basculement ne doit pas declencher les transitions de toute la page */
:root.theme-switching *,
:root.theme-switching *::before,
:root.theme-switching *::after {
    transition: none !important;
}

/* Cible tactile : 44 px sous 1024 px (mobile et tablette) */
@media (max-width: 1023px) {
    .theme-toggle { width: 44px; height: 44px; }
}
