/* ══════════════════════════════════════════════════════════════════════
   LIDIA Design Tokens — single source of truth
   ══════════════════════════════════════════════════════════════════════
   Loaded by all layouts (admin, agency, lidia, lidia_auth).

   Architecture (2026-04-25 dual-mode refactor) :
   ─────────────────────────────────────────────
   - `:root` contient les BRAND tokens (cyan/accent + accents sémantiques
     constants peu importe le mode : pink, green, orange, etc.)
   - `body[data-mode="dark"]` (= défaut, aussi appliqué quand body n'a
     pas d'attribut data-mode) définit la palette sombre
   - `body[data-mode="light"]` redéfinit `--bg`, `--card`, `--text`, etc.
     pour le light mode
   - Une agence white-label choisit son `mode` + 2 couleurs (primary/accent)
     dans /agency/branding. Pas plus de pickers --bg arbitraires (qui
     créaient des contrastes catastrophiques quand les hardcoded color:#fff
     se retrouvaient sur fond clair).
   - Per-user toggle ☀️/🌙 (Phase D) override le choix agence via
     localStorage + sync DB.

   Si tu ajoutes un nouveau composant : utilise TOUJOURS les tokens
   sémantiques (`var(--text)`, `var(--card)`, `var(--text-on-primary)`).
   N'écris JAMAIS `color:#fff` ou `background:#0c1220` en dur — ça pète
   en light mode.
   ══════════════════════════════════════════════════════════════════════ */

:root {
  /* ─── Brand accents (overridable per agency) ─── */
  --cyan:    #00d4ff;          /* primary */
  --cyan2:   #00ffd0;          /* accent */
  --brand-primary: var(--cyan);
  --brand-accent:  var(--cyan2);

  /* ─── Semantic accents (constants — same hue in light & dark) ─── */
  --orange:  #ff6b2b;
  --green:   #00e676;
  --pink:    #ff4fa3;
  --yellow:  #ffc107;
  --blue:    #2979ff;
  --accent:  #6c5ce7;
}

/* ══════════════════════════════════════════════════════════════════════
   DARK MODE (default — applies to body without data-mode AND data-mode="dark")
   ══════════════════════════════════════════════════════════════════════
   Le selector `body, body[data-mode="dark"]` garantit que les pages qui
   n'ont pas encore migré vers data-mode (transition Phase A→B) bénéficient
   quand même de la palette dark. Pas de breakage.
   ══════════════════════════════════════════════════════════════════════ */
body,
body[data-mode="dark"] {
  /* Surfaces */
  --bg:        #101011;
  --surface:   #080d18;
  --card:      linear-gradient(0deg, #000, #16191e);
  --card-solid: #16191e;       /* version non-gradient pour les contextes
                                   qui ne supportent pas un gradient
                                   (ex. inputs, badges) */
  --card2:     #0e1528;

  /* Borders */
  --border:    rgba(0, 200, 230, 0.1);
  --border2:   rgba(255, 255, 255, 0.05);

  /* Text scale */
  --text:           #cdd8f0;   /* texte principal */
  --text-strong:    #ffffff;   /* titres importants — quasi blanc en dark */
  --text-on-card:   #cdd8f0;   /* texte sur .lidia-card / .stat-card */
  --text-on-primary: #05080f;  /* texte sur boutons cyan (contrast élevé) */
  --muted:          #646669;
  --muted2:         #2e3a52;

  /* Shadows */
  --shadow-card:    0 8px 30px rgba(0, 0, 0, .4);
  --shadow-modal:   0 20px 60px rgba(0, 0, 0, .6);

  /* Hover/active overlays — utilisent color-mix sur primary */
  --overlay-hover:  rgba(0, 212, 255, .06);
  --overlay-active: rgba(0, 212, 255, .14);
}

/* ══════════════════════════════════════════════════════════════════════
   LIGHT MODE
   ══════════════════════════════════════════════════════════════════════
   Activé par <body data-mode="light"> émis par les layouts quand l'agence
   a choisi le light mode (brand_theme_json.mode === "light") OU quand
   l'utilisateur a forcé le toggle via localStorage.
   ══════════════════════════════════════════════════════════════════════ */
body[data-mode="light"] {
  /* Surfaces */
  --bg:        #f5f7fa;
  --surface:   #ffffff;
  --card:      #ffffff;
  --card-solid: #ffffff;
  --card2:     #f0f3f8;

  /* Borders — plus contrastés sur fond clair */
  --border:    rgba(0, 0, 0, 0.08);
  --border2:   rgba(0, 0, 0, 0.06);

  /* Text scale */
  --text:           #1a1f2e;   /* texte principal — très sombre pour contraste */
  --text-strong:    #0a0e1a;   /* titres */
  --text-on-card:   #1a1f2e;
  --text-on-primary: #ffffff;  /* texte sur boutons primary — blanc sur fond
                                   coloré reste contrasté car les couleurs
                                   primaires sont saturées (cyan #00d4ff) */
  --muted:          #6b7280;
  --muted2:         #d1d5db;

  /* Shadows — beaucoup plus subtiles en light (pas d'ombres profondes) */
  --shadow-card:    0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-modal:   0 10px 40px rgba(0, 0, 0, .15);

  /* Hover/active overlays */
  --overlay-hover:  rgba(0, 212, 255, .08);
  --overlay-active: rgba(0, 212, 255, .16);
}

/* ─── Utility classes (loaded with tokens, available everywhere) ─── */
/* Screen-reader-only labels — used by auth forms for a11y compliance */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Spinning icon (used with mdi-loading) */
.mdi-spin { animation: lidia-spin 1.2s linear infinite; display: inline-block; }
@keyframes lidia-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ─── Empty state component (Round 1.9) ─── */
.empty-state {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
  font-size: .82rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.empty-state-icon {
  font-size: 2.6rem;
  opacity: .25;
  color: var(--cyan);
  line-height: 1;
}
.empty-state-title {
  font-family: 'Rajdhani', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: .04em;
}
.empty-state-help {
  max-width: 340px;
  line-height: 1.55;
  font-size: .8rem;
  color: var(--muted);
}
/* CTA wrapper. Supports a single button (margin-top only) OR a row of
   actions (flex+wrap+gap). The flex behaviour kicks in only when used as a
   container around multiple <a>/<button> children — single-child blocks render
   the same as before so existing single-CTA empty states aren't disturbed. */
.empty-state-cta {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
}
/* Conversational lead text shown above the CTAs ("3 façons de faire …"). */
.empty-state-lead {
  font-size: .8rem;
  color: var(--text);
  font-weight: 600;
  margin-top: 4px;
}

/* Loading skeleton — utilise les tokens pour s'adapter au mode */
.loading-skeleton {
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--text) 4%, transparent) 25%,
    color-mix(in srgb, var(--text) 8%, transparent) 37%,
    color-mix(in srgb, var(--text) 4%, transparent) 63%);
  background-size: 400% 100%;
  border-radius: 6px;
  animation: skeleton-shimmer 1.4s ease infinite;
  min-height: 14px;
}
@keyframes skeleton-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ══════════════════════════════════════════════════════════════════════
   body[data-mode="light"] overrides (Phase A — dual-mode refactor)
   ══════════════════════════════════════════════════════════════════════
   Ces rules s'appliquent quand body[data-mode="light"] est défini par
   le layout (à partir de brand_theme_json.mode ou pref user). Elles
   couvrent les cas où la cascade var(--text) ne suffit pas — par
   exemple les couleurs hardcodées qu'on ne peut pas éliminer dans
   l'immédiat (Phase B se chargera de la sweep).

   Différence avec body.theme-light ci-dessus : ces rules sont plus
   ciblées ET utilisent les NOUVEAUX tokens sémantiques
   (--text-on-card, --shadow-card, etc.) qui sont eux-mêmes
   automatiquement light-aware via la cascade body[data-mode="light"].
   ══════════════════════════════════════════════════════════════════════ */

/* Sidebar nav active item en light : on laisse les rules inline des layouts
   (admin/lidia/agency) gérer (color: var(--text-strong) !important). On NE
   force PAS var(--cyan) ici parce que le brand primary peut être très sombre
   (ex. CEA #241B33 dark purple) et serait alors invisible sur sidebar light.
   --text-strong = #0a0e1a en light → contraste garanti. */

/* Logo LIDIA (font weight 100 + thin stroke devient ghost en light) */
body[data-mode="light"] .lidia-logo-text {
  font-weight: 600 !important;
  color: var(--text) !important;
}
body[data-mode="light"] .lidia-logo-arc {
  background: linear-gradient(to right, transparent 0%, var(--cyan) 50%, transparent 100%) bottom / 100% 1px no-repeat !important;
  box-shadow: none !important;
  filter: none !important;
}

/* Stat cards — les ombres profondes du dark deviennent invisibles sur
   fond clair, on les remplace par des bordures subtiles. */
body[data-mode="light"] .stat-card,
body[data-mode="light"] .lidia-card,
body[data-mode="light"] .kpi-card {
  box-shadow: var(--shadow-card) !important;
}

/* Topbar chips */
body[data-mode="light"] .topbar-chat-chip,
body[data-mode="light"] .bug-rep-chip {
  border-width: 1.5px !important;
}

/* Sentient widget overlay — l'overlay sombre derrière le panel doit
   rester un voile sombre pour que le panel light se détache. */
body[data-mode="light"] .lidia-sentient-overlay {
  background: rgba(20, 24, 32, .35) !important;
}

/* Color picker swatches — bordures plus contrastées sur fond clair */
body[data-mode="light"] .theme-picker-swatch-wrap {
  border-color: rgba(0, 0, 0, 0.18) !important;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.8) !important;
}
body[data-mode="light"] .theme-picker-row {
  background: rgba(0, 0, 0, 0.02) !important;
}
body[data-mode="light"] .theme-picker-hex {
  background: rgba(0, 0, 0, 0.04) !important;
  border-color: rgba(0, 0, 0, 0.1) !important;
}

/* Sidebar gradient — le gradient noir → transparent → noir devient
   invisible sur fond light. On override avec un gradient subtil
   utilisant border2. */
body[data-mode="light"] #sidebar-desktop {
  background: var(--surface) !important;
  border-right: 1px solid var(--border2) !important;
}

/* Topbar — bg du topbar utilise --card qui est un gradient en dark.
   En light, --card devient solide blanc — pas besoin d'override. */

/* ══════════════════════════════════════════════════════════════════════
   Mass override : titres/labels hardcoded color:#fff dans view/* files
   (Phase B sweep n'a pas pu attraper toutes les vues — trop de surface).
   On force var(--text) pour toutes ces classes connues. Si un nouveau
   composant ship du color:#fff, l'idéal est qu'il use --text-strong
   directement, mais ce filet de sécurité couvre les cas existants.
   ══════════════════════════════════════════════════════════════════════ */
body[data-mode="light"] .page-title,
body[data-mode="light"] .page-sub,
body[data-mode="light"] .stat-big,
body[data-mode="light"] .lidia-logo-text,
body[data-mode="light"] .topbar-title,
body[data-mode="light"] .ag-hero-title,
body[data-mode="light"] .agency-badge-name,
body[data-mode="light"] .kpi-lbl,
body[data-mode="light"] .cfg-lbl,
body[data-mode="light"] .action-title,
body[data-mode="light"] .opp-rail-tab,
body[data-mode="light"] .crm-kcard-name,
body[data-mode="light"] .bug-rep-head-title,
body[data-mode="light"] .cv-profile-name,
body[data-mode="light"] .cv-modal-title,
body[data-mode="light"] .modal-title,
body[data-mode="light"] .em-result-title,
body[data-mode="light"] .lsp-head-title,
body[data-mode="light"] .lsp-empty-title,
body[data-mode="light"] .lsp-insight-title,
body[data-mode="light"] .sup-head-title,
body[data-mode="light"] .modal-content.modal-lidia .modal-title,
body[data-mode="light"] .onboarding-card-title,
body[data-mode="light"] .onboarding-step-title,
body[data-mode="light"] .stat-row-val,
body[data-mode="light"] .stat-label,
body[data-mode="light"] .lead-name,
body[data-mode="light"] .opp-section-title,
body[data-mode="light"] .nav-link-lidia,
body[data-mode="light"] .nav-text,
body[data-mode="light"] .chart-title,
body[data-mode="light"] .action-client,
body[data-mode="light"] .ag-report-md h3,
body[data-mode="light"] h1, body[data-mode="light"] h2, body[data-mode="light"] h3,
body[data-mode="light"] h4, body[data-mode="light"] h5, body[data-mode="light"] h6 {
  color: var(--text) !important;
}

/* ══════════════════════════════════════════════════════════════════════
   Chrome autofill — without this, autofilled inputs render with the
   browser's default light-blue background (rgb(232,240,254)) + black text,
   which is glaring on top of dark mode and sticks for several seconds before
   the user types. The 5000s transition is the canonical hack to defeat
   Chromium's autofill repaint. (Bug #119, 2026-04-27.)
   ══════════════════════════════════════════════════════════════════════ */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--surface) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text) !important;
  transition: background-color 5000s ease-in-out 0s, color 5000s ease-in-out 0s !important;
}

/* ══════════════════════════════════════════════════════════════════════
   Admin .cp-stat in light mode — the inline gradients use accent colors
   at .15 alpha which become near-invisible against #f5f7fa. The .val
   number colored with the same accent then disappears. We strengthen the
   gradient (alpha .15 → .22) and force the .lbl to lose its .65 opacity.
   (Bugs #123, #127, #137, 2026-04-27.)
   ══════════════════════════════════════════════════════════════════════ */
body[data-mode="light"] .cp-stat {
  background-color: var(--surface) !important;
  border-color: color-mix(in srgb, currentColor 22%, transparent) !important;
}
body[data-mode="light"] .cp-stat .lbl,
body[data-mode="light"] .stat-card .stat-lbl,
body[data-mode="light"] .stat-card .stat-sub,
body[data-mode="light"] .kpi-card .kpi-lbl {
  opacity: 1 !important;
  color: var(--muted) !important;
}

/* Stat cards en light — les ombres profondes deviennent invisibles, on
   les remplace par bordures subtiles. Et le bg passe de --card (gradient)
   à blanc solide via --card en light déjà = #ffffff. */
body[data-mode="light"] .stat-card,
body[data-mode="light"] .lidia-card,
body[data-mode="light"] .kpi-card,
body[data-mode="light"] .chart-card {
  box-shadow: var(--shadow-card) !important;
}

/* dash-insights-widget : le gradient hardcodé en cyan-faible peut
   disparaître en light. On force un fond plus visible. */
body[data-mode="light"] .dash-insights-widget {
  background: linear-gradient(135deg, color-mix(in srgb, var(--cyan) 8%, transparent), color-mix(in srgb, var(--cyan2) 4%, transparent)) !important;
  border-color: color-mix(in srgb, var(--cyan) 25%, transparent) !important;
}
body[data-mode="light"] .dash-insight-card {
  background: #ffffff !important;
  border-color: color-mix(in srgb, var(--text) 12%, transparent) !important;
}
body[data-mode="light"] .lsp-insight {
  background: #ffffff !important;
  border-color: color-mix(in srgb, var(--text) 10%, transparent) !important;
}
body[data-mode="light"] .lsp-head {
  border-bottom-color: color-mix(in srgb, var(--text) 10%, transparent) !important;
}

/* ══════════════════════════════════════════════════════════════════════
   DataTable headers + outline-primary buttons in light mode (Phase F).
   Admin layout hardcodes color:color-mix(brand-primary 70%, transparent)
   on table headers and btn-outline-primary, which renders as cyan
   #00d4ff/.7 — a 1.6:1 contrast ratio against white. The element-class
   selector beats the global .table thead th { color: var(--text) }
   override, so we need an equally-or-more specific light-mode rule.
   (Bugs #125, #126, #136, 2026-04-27.)
   ══════════════════════════════════════════════════════════════════════ */
body[data-mode="light"] table.dataTable thead th,
body[data-mode="light"] .table thead th,
body[data-mode="light"] .table th {
  color: var(--text) !important;
}
body[data-mode="light"] .btn-outline-primary {
  color: #0e7490 !important;
  border-color: rgba(14, 116, 144, .35) !important;
}
body[data-mode="light"] .btn-outline-primary:hover {
  background: rgba(14, 116, 144, .08) !important;
  color: #0e7490 !important;
}
