:root {
  --accent2-rgb: 34, 211, 238;
  --accent3-rgb: 251, 191, 36;
}
body.light-theme,
body.bento-theme {
  --accent2-rgb: 8, 145, 178;
  --accent3-rgb: 217, 119, 6;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Initial app boot — single source of truth for the cinematic lifecycle.

   The contract :
     - `<body>` starts with class `ct-loading`. The class STAYS forever ;
       it's a permanent state marker. `ct-ready` is added on top when the
       SPA shell is ready (see app.js → _ctMarkReady).
     - Until `ct-ready` is set : #ctInitLoader visible at full opacity,
       and TIER 2 wheels (per-section .ct-loader without --brand) are
       muted so they don't pop in underneath the overlay.
     - Once `ct-ready` is set : #ctInitLoader fades out over 480 ms, and
       the TIER 2 muting rule lifts (no longer matches the selector). The
       fade covers the moment per-section wheels appear, so the user sees
       a single continuous visual.

   This is intentionally NOT a 2-class combo like `ct-loading.ct-ready`.
   That combo broke previously when something removed `ct-loading` after
   the fade — the selector stopped matching and the loader fell back to
   its default `opacity:1`, popping back into view indefinitely.
   ═══════════════════════════════════════════════════════════════════════════ */

/* Landing + mainApp are invisible during the pre-ready phase to prevent
   the auth-check flash where a page renders before refreshMe() resolves. */
body.ct-loading #landing,
body.ct-loading #mainApp { opacity: 0; transition: opacity var(--duration-fast) var(--ease-default); }
body.ct-ready #landing,
body.ct-ready #mainApp { opacity: 1; }
/* If the user was authed in a previous session, skip the landing fade and
   hide it immediately ; the SPA shell is what they're expecting. */
body.ct-was-authed.ct-loading #landing { display: none; }

/* #ctInitLoader — visible from first paint, fades out when ct-ready fires.
   Animation : 480 ms opacity, with visibility queued to flip after the
   fade so the element no longer captures pointer events. */
#ctInitLoader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4, 16px);
  z-index: var(--z-spotlight, 99999);
  background: color-mix(in srgb, var(--bg0, #050810) 62%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  backdrop-filter: blur(14px) saturate(120%);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 480ms ease, visibility 0s linear 480ms;
}
body.ct-ready #ctInitLoader {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Mute TIER 2 wheels (default .ct-loader instances without --brand /
   --in-overlay) until ct-ready fires. The brand loaders inside the
   centralised overlay (.ct-loader--in-overlay) and the redirect/init
   overlays (.ct-loader--brand) stay visible — they ARE the visual that
   covers the boot. */
body:not(.ct-ready) .ct-loader:not(.ct-loader--brand):not(.ct-loader--in-overlay) {
  opacity: 0 !important;
  visibility: hidden !important;
}
#ctInitLoader__caption {
  max-width: 320px;
  text-align: center;
  font-size: var(--text-lg, 16px);
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text, #f1f5f9);
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
  padding: 0 var(--space-4, 16px);
  opacity: 0.92;
}
/* The first-paint snippet at top of <body> can't set a localStorage-driven
   theme class on #ctInitLoader, so reuse :root tokens directly via the
   transparent backdrop above — picks up Bento warm-lavande or Obsidian
   dark automatically. */
@media (prefers-reduced-motion: reduce) {
  #ctInitLoader { transition: none; }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; max-width: 100%; overflow-x: hidden; }
html { background-color: var(--bg0, #050810); }
body { background-color: var(--bg0, #050810); }
body.light-theme { background-color: var(--bg0); }
body.bento-theme { background-color: var(--bg0); }
body.atsiq-theme { background-color: var(--bg0); }

body {
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(ellipse 1200px 600px at 20% 5%, rgba(var(--primary-rgb),0.18), transparent 55%),
    radial-gradient(ellipse 900px 450px at 80% 15%, rgba(var(--accent2-rgb),0.10), transparent 50%),
    radial-gradient(ellipse 700px 350px at 50% 85%, rgba(var(--accent3-rgb),0.06), transparent 50%),
    linear-gradient(170deg, var(--bg2) 0%, var(--bg1) 35%, var(--bg0) 100%);
  background-attachment: fixed;
  background-size: 100% 100%;
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* Skip navigation link (accessibility) */
.skip-nav {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: var(--text-inverse);
  padding: var(--space-2) var(--space-4);
  z-index: var(--z-spotlight);
  transition: top var(--duration-base);
  text-decoration: none;
  font-weight: 600;
  font-size: var(--text-base);
}
.skip-nav:focus { top: 0; }

/* Focus ring standardization */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
/* Custom interactive components — ensure keyboard focus ring */
.assistant-shell-choice:focus-visible,
.tag-filter-btn:focus-visible,
.kanbanCard:focus-visible,
.bento-tile:focus-visible,
.tool-card:focus-visible,
.statCard:focus-visible,
[role="button"]:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ══════════════════════════════════════════════════════════════════════════════════════════
   🟠 `C48` — `color-scheme` ÉTAIT DÉCLARÉ « dark » GLOBALEMENT, SUR LES CONTRÔLES
   ──────────────────────────────────────────────────────────────────────────────────────────
   Ce qui était écrit ici :  `select, input, textarea { color-scheme: dark; }`
   Deux défauts en une ligne, et ils sont TRANSVERSES — d'où l'escalade de FIX-R L2/L4/L5
   (« ⛔ une passe de lot ne doit pas repeindre les contrôles de tout le produit en
   catimini », §5 n°4) :

   ① LA VALEUR EST UNE CONSTANTE DANS UN PRODUIT À QUATRE THÈMES (`G3` — la contradiction).
     Trois d'entre eux sont CLAIRS. Chacun a donc dû écrire sa CONTRE-déclaration pour
     défaire celle-ci — `atsiq-theme.css:412` (« force UA light rendering — évite dark-mode
     OS sur form elements ») et `variables.css:971` pour Slate Mist et Ink & Gold. Une règle
     fausse en global + deux règles pour l'annuler : c'est `G4`, le doublon, dans sa forme
     la plus coûteuse — la prochaine feuille de thème devra elle aussi se souvenir d'annuler.

   ② ELLE EST POSÉE SUR LES CONTRÔLES, PAS SUR LE DOCUMENT (`G5` — mesuré). `color-scheme`
     est une propriété HÉRITÉE dont la portée est la PAGE : elle gouverne aussi la barre de
     défilement du document, le fond des menus `<option>`, les sélecteurs de date, le
     remplissage automatique et le rendu par défaut de toute la surface. Posée sur trois
     sélecteurs, elle ne gouverne que ces trois-là. Mesuré sur la pile AVANT correctif
     (sonde `--mode fiche`, surface 05) :
         Obsidian     racine `normal` · corps `normal` · `<select>`/`<input>` `dark`
         Sage & Forest racine `light`  · corps `light`  · `<select>`/`<input>` `light`
     ⇒ en Obsidian la PAGE n'a pas de schéma : l'agent utilisateur peint la barre de
       défilement du document et les surfaces natives en CLAIR sur un produit noir.

   ⇒ On déclare le schéma UNE fois, à la RACINE, par thème — là où il gouverne tout ce qu'il
     doit gouverner. Obsidian est le thème `:root` (aucune classe), les trois thèmes clairs
     portent leur classe sur `html` ET sur `body` selon les coques : les deux sont visés.
     `atsiq-theme.css:19` posait DÉJÀ le bon geste pour Sage & Forest — c'est lui qu'on
     généralise, ⛔ on n'invente pas une grammaire.
   ══════════════════════════════════════════════════════════════════════════════════════════ */
:root { color-scheme: dark; }
html.light-theme, body.light-theme,
html.bento-theme, body.bento-theme,
html.atsiq-theme, body.atsiq-theme,
html[data-theme="bento"], body[data-theme="bento"] { color-scheme: light; }

/* iOS Safari: remove native form styling */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
select,
textarea {
  -webkit-appearance: none;
  appearance: none;
}

/* Screen reader only - visually hidden but accessible */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
/* === Typography utilities === */
.heading-xl { font-size: var(--text-2xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.heading-lg { font-size: var(--text-xl); font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; }
.heading-md { font-size: var(--text-lg); font-weight: 600; line-height: 1.3; }
.heading-sm { font-size: var(--text-md); font-weight: 600; line-height: 1.4; }
.text-body   { font-size: var(--text-base); }
.text-small  { font-size: var(--text-sm); }
.text-xs     { font-size: var(--text-xs); }
.text-muted-sm { color: var(--text-secondary); font-size: var(--text-sm); }

/* === Utilities === */
.hidden { display: none !important; }
.w100 { width: 100%; }


/* ============================================
   ACCESSIBILITY: Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .toast {
    animation: none !important;
  }

  .spinner {
    animation: none !important;
  }

  .journeyStepCircle,
  .kanbanCard,
  .btn,
  .tab,
  .menuItem {
    transition: none !important;
  }
}

/* Ensure minimum readable font sizes on mobile */
@media (max-width: 600px) {
  .badge, .badge-new, .badge-count, .rec-badge,
  .metricCard .metricLabel, .metricCard .metricDetail,
  .rec-score, .stageLabel, .hint {
    font-size: max(12px, inherit);
  }
  /* Ensure touch targets meet 44px minimum on mobile (WCAG AA) */
  .btn--help {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
  /* grincheux-R-01 / persona-R-01 (re-gate P2-Z) — CAUSE AMONT de la « bouillie » à 390 px :
     cette règle imposait une boîte CARRÉE FIXE de 44×44 à TOUS les `.btn--xs`, y compris ceux
     qui portent un LIBELLÉ (« Lancer maintenant », « Voir l'historique », « Réessayer »,
     pagination admin… — 149 usages au grep, très majoritairement textuels). Combinée au
     `white-space: nowrap` + `overflow: visible` de `.btn.btn--xs` (components.css), la largeur
     fixe faisait DÉBORDER le libellé hors de sa boîte : dans une rangée flex, trois boutons de
     44 px peignaient leurs textes de 119 / 88 / 79 px les uns PAR-DESSUS les autres, et
     `flex-wrap` ne pouvait pas se déclencher (chaque enfant « mesurait » 44 px).
     La cible tactile est un PLANCHER, pas une taille : `min-*` seuls. Un `--xs` qui ne contient
     qu'un picto reste 44×44 (son contenu est plus petit que le plancher) ; un `--xs` textuel
     s'élargit à son libellé et la rangée peut enfin se replier. Même écriture que la règle
     canonique déjà en place dans components.css (`@media (max-width:768px)`), dont celle-ci
     était une divergence. WCAG 2.5.5 respecté dans les deux cas. */
  .btn.btn--xs {
    min-width: 44px;
    min-height: 44px;
  }
  /* Checkboxes: ensure 44px tap target even if visual is smaller */
  .checkboxField {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: var(--space-1) 0;
  }
  .dropdown-feedback-item {
    min-height: 40px;
  }
}

/* Spacing utilities */
.mt-8 { margin-top: var(--space-2); }
.mt-12 { margin-top: var(--space-3); }
.mt-14 { margin-top: 14px; }
.mt-16 { margin-top: var(--space-4); }
.mb-12 { margin-bottom: var(--space-3); }
.mb-16 { margin-bottom: var(--space-4); }
.my-8 { margin: var(--space-2) 0; }
.my-12 { margin: var(--space-3) 0; }
.my-16 { margin: var(--space-4) 0; }
.mr-8 { margin-right: var(--space-2); }
.mx-12 { margin: 0 var(--space-3); }
.py-8 { padding: var(--space-2) 0; }
.flex-1 { flex: 1; min-width: 0; }
.w-full { width: 100%; }
.w100 { width: 100%; }
.gap-4 { gap: var(--space-1); }
.gap-6 { gap: 6px; }
.gap-8 { gap: var(--space-2); }
.gap-10 { gap: 10px; }
.gap-12 { gap: var(--space-3); }
.gap-16 { gap: var(--space-4); }
.gap-24 { gap: var(--space-6); }
.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-5 { padding: var(--space-5); }
.p-6 { padding: var(--space-6); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }
.mt-4 { margin-top: var(--space-1); }
.mt-20 { margin-top: var(--space-5); }
.mt-24 { margin-top: var(--space-6); }
.mt-32 { margin-top: var(--space-7); }
.mb-4 { margin-bottom: var(--space-1); }
.mb-8 { margin-bottom: var(--space-2); }
.mb-24 { margin-bottom: var(--space-6); }
.ml-auto { margin-left: auto; }
.mr-4 { margin-right: var(--space-1); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-col { display: flex; flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.inline-flex { display: inline-flex; align-items: center; }
.relative { position: relative; }
.cursor-pointer { cursor: pointer; }
.overflow-x-auto { overflow-x: auto; }
.overflow-y-auto { overflow-y: auto; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-auto { width: auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.hidden { display: none; }

/* Avatar image utilities — consistent aspect-ratio and fallback */
.avatar-img, img[class*="avatar"] {
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 50%;
}

/* Print styles */
@media print {
  /* Hide UI chrome */
  .sidebar, .topbar, #messagingPanel, .modal:not(.hidden),
  .toast-container, .spotlight-overlay, .assistant-shell-widget,
  .skip-nav, .proactive-tip, .bulkActionsBar,
  .mockInterviewBulkActions, #cookieBanner { display: none !important; }

  /* Only hide action buttons, keep view buttons */
  .btn.btn--primary,
  .btn.btn--danger,
  .btn.btn--ai, .cardHead .actions { display: none !important; }

  /* Clean base */
  body { background: var(--on-primary) !important; color: var(--text) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .main-content, .app-main { margin: 0 !important; padding: 20px !important; }
  a { color: inherit; text-decoration: underline; }

  /* Cards — clean borders, no shadows */
  .card, .card-glass, .bento-tile, .statCard, .modalCard {
    box-shadow: none !important;
    border: 1px solid var(--line) !important;
    background: var(--on-primary) !important;
    break-inside: avoid;
  }

  /* Tables — proper page breaks */
  table, .tableWrap { break-inside: auto; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }


  /* Charts — prevent breaking */
  canvas { break-inside: avoid; max-width: 100%; }

  /* Page margins */
  @page { margin: 1.5cm; }
}

/* Global responsive tables — prevent overflow on small screens */
@media (max-width: 768px) {
  .tableWrap,
  .admin-table-wrap,
  .bi-table-wrap,
  .crm-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    padding-right: var(--space-4);
    /* Scroll fade indicators — hint there's more content (padding prevents text clipping) */
    -webkit-mask-image: linear-gradient(to right, transparent 0, black 16px, black calc(100% - 16px), transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, black 16px, black calc(100% - 16px), transparent 100%);
  }
  .section-pane table,
  .card table,
  .candidate-pane table,
  .admin-content table,
  .tabPane table {
    min-width: 0;
  }
}

/* Global mobile refinements */
@media (max-width: 480px) {
  .h1 { font-size: var(--text-xl); }
  .h2 { font-size: var(--text-md); }
  .h3 { font-size: var(--text-base); }
  .btn { padding: 8px 14px; font-size: var(--text-sm); }
  .btn.btn--primary { padding: 10px 16px; }
  .btn.btn--small { padding: 6px 10px; font-size: var(--text-xs); }
}
@media (max-width: 400px) {
  body { font-size: var(--text-base); }
  .wrap { padding: 0 8px 8px; }
}

/* ── Mobile tap targets — form inputs & checkboxes ── */
@media (max-width: 768px) {
  input[type="text"],
  input[type="search"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="date"],
  input[type="time"],
  input[type="password"],
  input[type="url"],
  select,
  textarea {
    min-height: 36px;
  }
  input[type="checkbox"] {
    position: relative;
    min-width: 20px;
    min-height: 20px;
  }
  input[type="checkbox"]::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
  }
}

/* ── Coarse pointer (touch devices) — enlarge checkbox visual ── */
@media (pointer: coarse) {
  input[type="checkbox"] { min-width: 24px; min-height: 24px; }
}
