/* ═══════════════════════════════════════════════════════════════════════
   JJ-DS v1.0 — COUCHE 3 : COMPOSANTS DE BASE (.jj-*)
   Univers J-Juice Design System. Dépend de jj-primitives.css + jj-themes.css.

   RÈGLES OPPOSABLES (A3) :
   • 100 % namespacé .jj-* : aucun sélecteur d'élément nu, aucun *{}, aucun reset,
     aucune règle sur html/:root/body. Les custom properties de composant sont
     déclarées sur les blocs .jj-* concernés, jamais sur :root.
   • Couleurs UNIQUEMENT via tokens sémantiques (var(--jj-…)), jamais de primitive
     --jj-p-* en direct, jamais de couleur brute (#hex/rgb/hsl).
   • Cibles tactiles interactives ≥ 46 px. Champs à 16 px (anti-zoom iOS).
   • Focus BI-ANNEAU (--jj-focus + --jj-focus-contrast), jamais l'accent seul.
   • Désactivé : tokens explicites (pas d'opacité globale aveugle), reste lisible.
   • prefers-reduced-motion : transitions/scale/spinner neutralisés, feedback conservé.
   • Accent d'univers = décor (liseré) activé explicitement ; états = sémantique.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── FOCUS PARTAGÉ (bi-anneau) — anneau intérieur contrasté avec le composant
   (--jj-focus-contrast) + anneau extérieur contrasté avec la page (--jj-focus).
   Outline non rognable pour l'anneau extérieur ; box-shadow pour l'intérieur. ── */
.jj-btn:focus-visible,
.jj-chip:focus-visible,
.jj-input:focus-visible,
.jj-select:focus-visible,
.jj-textarea:focus-visible,
a.jj-row:focus-visible,
button.jj-row:focus-visible {
  outline: 2px solid var(--jj-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--jj-focus-contrast);
}

/* ── BUTTON ──────────────────────────────────────────────────────────────── */
.jj-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--jj-space-sm);
  min-height: 46px; padding: 0 var(--jj-space-lg);
  border: 1px solid transparent; border-radius: var(--jj-radius-sm);
  font-family: var(--jj-font-body); font-size: var(--jj-font-size-label);
  font-weight: var(--jj-font-weight-bold); line-height: var(--jj-line-tight);
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: transform var(--jj-dur-fast) var(--jj-ease), filter var(--jj-dur-fast) var(--jj-ease);
}
.jj-btn:active { transform: scale(.97); filter: brightness(.94); }
.jj-btn--sm { min-height: 46px; padding: 0 var(--jj-space-md); font-size: var(--jj-font-size-caption); }
.jj-btn--lg { min-height: 52px; padding: 0 var(--jj-space-xl); font-size: var(--jj-font-size-body); }
.jj-btn--primary   { background: var(--jj-brand-500); color: var(--jj-brand-on); }
.jj-btn--secondary { background: var(--jj-surface-2); color: var(--jj-text-1); border-color: var(--jj-border-2); }
.jj-btn--ghost     { background: transparent; color: var(--jj-text-1); }
.jj-btn--danger    { background: var(--jj-state-danger); color: var(--jj-state-fg); }
/* désactivé : UNIQUEMENT l'attribut natif [disabled] (non focusable, non activable).
   aria-disabled n'est PAS pris en charge visuellement ici : il ne neutralise ni le
   focus ni le clavier et créerait une fausse désactivation. Tokens explicites,
   texte lisible (text-3 AA sur surface-2), pas d'opacité aveugle. */
.jj-btn:disabled {
  background: var(--jj-surface-2); color: var(--jj-text-3);
  border-color: var(--jj-border-1); cursor: not-allowed; filter: none;
}
.jj-btn:disabled:active { transform: none; }
/* chargement : CONTRAT = disabled + aria-busy="true" (le natif [disabled] neutralise
   réellement souris ET clavier ; aria-busy annonce l'état). Le visuel de chargement
   n'existe QUE pour cette combinaison : un aria-busy sans disabled n'affiche aucun
   faux état bloqué. Le nom accessible reste présent (label masqué visuellement). */
.jj-btn:disabled[aria-busy="true"] .jj-btn__label { opacity: 0; }
.jj-btn:disabled[aria-busy="true"]::after {
  content: ""; position: absolute; width: 18px; height: 18px;
  border-radius: var(--jj-radius-full);
  border: 2px solid currentColor; border-right-color: transparent;
  animation: jj-spin .7s linear infinite;
}

/* ── CARD ────────────────────────────────────────────────────────────────── */
.jj-card {
  background: var(--jj-surface-1); color: var(--jj-text-1);
  border: 1px solid var(--jj-border-1); border-radius: var(--jj-radius-md);
  padding: var(--jj-space-lg);
}
.jj-card--raised { box-shadow: var(--jj-e1); border-color: transparent; }
/* liseré d'accent : décor, activé EXPLICITEMENT (data-jj-accent fixe la valeur) */
.jj-card--accent { border-left: 3px solid var(--jj-accent); }

/* ── FIELD (Input / Select / Textarea) ───────────────────────────────────── */
.jj-field { display: flex; flex-direction: column; gap: var(--jj-space-xs); }
.jj-field__label { font-size: var(--jj-font-size-label); font-weight: var(--jj-font-weight-semibold); color: var(--jj-text-2); }
.jj-field__hint  { font-size: var(--jj-font-size-caption); color: var(--jj-text-3); }
.jj-field__error { font-size: var(--jj-font-size-caption); font-weight: var(--jj-font-weight-semibold); color: var(--jj-state-danger); }

.jj-input, .jj-select, .jj-textarea {
  /* token de composant (couche 3), NON une primitive globale : 16px anti-zoom iOS */
  --jj-field-font-size: 16px;
  width: 100%; box-sizing: border-box; min-height: 46px;
  padding: 0 var(--jj-space-md);
  border: 1px solid var(--jj-border-2); border-radius: var(--jj-radius-sm);
  background: var(--jj-surface-2); color: var(--jj-text-1);
  font-family: var(--jj-font-body); font-size: var(--jj-field-font-size);
}
.jj-textarea { min-height: 92px; padding: var(--jj-space-md); line-height: var(--jj-line-body); resize: vertical; }
.jj-input::placeholder, .jj-textarea::placeholder { color: var(--jj-text-3); }
.jj-input:focus-visible, .jj-select:focus-visible, .jj-textarea:focus-visible { border-color: var(--jj-accent); }
.jj-input[aria-invalid="true"], .jj-select[aria-invalid="true"], .jj-textarea[aria-invalid="true"] { border-color: var(--jj-state-danger); }
.jj-input:disabled, .jj-select:disabled, .jj-textarea:disabled {
  background: var(--jj-surface-1); color: var(--jj-text-3);
  border-color: var(--jj-border-1); cursor: not-allowed;
}

/* ── CHIP ────────────────────────────────────────────────────────────────── */
.jj-chip {
  display: inline-flex; align-items: center; gap: var(--jj-space-xs);
  min-height: 32px; padding: 0 var(--jj-space-md);
  border: 1px solid var(--jj-border-2); border-radius: var(--jj-radius-full);
  background: var(--jj-surface-2); color: var(--jj-text-1);
  font-family: var(--jj-font-body); font-size: var(--jj-font-size-label); font-weight: var(--jj-font-weight-semibold);
}
button.jj-chip { min-height: 46px; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform var(--jj-dur-fast) var(--jj-ease); }
button.jj-chip:active { transform: scale(.97); }
/* sélection : SEULE source = [aria-pressed="true"] (pas de classe concurrente).
   Repère NON CHROMATIQUE obligatoire (✓) + renfort chromatique (fond/liseré).
   L'accent reste décoratif ; le texte reste neutre (AA). */
.jj-chip__check {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1em; flex: 0 0 auto;
  visibility: hidden;                 /* espace RÉSERVÉ à false → aucun saut de largeur */
}
.jj-chip[aria-pressed="true"] { background: var(--jj-surface-3); border-color: var(--jj-accent); color: var(--jj-text-1); }
.jj-chip[aria-pressed="true"] .jj-chip__check { visibility: visible; } /* ✓ visible = repère non chromatique */

/* ── BADGE (informatif, non interactif ; libellé textuel obligatoire) ─────── */
.jj-badge {
  display: inline-flex; align-items: center; gap: var(--jj-space-xs);
  min-height: 20px; padding: 0 var(--jj-space-sm);
  border-radius: var(--jj-radius-full);
  background: var(--jj-surface-2); color: var(--jj-text-2);
  font-family: var(--jj-font-mono); font-size: var(--jj-font-size-micro); font-weight: var(--jj-font-weight-bold);
}
.jj-badge--success { background: var(--jj-state-success); color: var(--jj-state-fg); }
.jj-badge--warning { background: var(--jj-state-warning); color: var(--jj-state-fg); }
.jj-badge--danger  { background: var(--jj-state-danger);  color: var(--jj-state-fg); }
.jj-badge--info    { background: var(--jj-state-info);    color: var(--jj-state-fg); }

/* ── STAT TILE ───────────────────────────────────────────────────────────── */
.jj-stat {
  display: flex; flex-direction: column; gap: var(--jj-space-xs);
  padding: var(--jj-space-md); background: var(--jj-surface-1);
  border: 1px solid var(--jj-border-1); border-radius: var(--jj-radius-md);
}
.jj-stat__value { font-family: var(--jj-font-mono); font-size: var(--jj-font-size-h1); font-weight: var(--jj-font-weight-bold); color: var(--jj-text-1); }
.jj-stat__label { font-size: var(--jj-font-size-caption); color: var(--jj-text-2); }
/* tendance : couleur + libellé textuel accessible obligatoire (jamais couleur/flèche seule) */
.jj-stat__trend { display: inline-flex; align-items: center; gap: var(--jj-space-xs); font-size: var(--jj-font-size-caption); font-weight: var(--jj-font-weight-semibold); }
.jj-stat__trend--up   { color: var(--jj-state-success); }
.jj-stat__trend--down { color: var(--jj-state-danger); }
.jj-stat__trend--flat { color: var(--jj-text-2); }

/* ── LIST ROW ────────────────────────────────────────────────────────────── */
.jj-row {
  display: flex; align-items: center; gap: var(--jj-space-md);
  min-height: 46px; padding: var(--jj-space-sm) var(--jj-space-md);
  background: var(--jj-surface-1); color: var(--jj-text-1);
  border-bottom: 1px solid var(--jj-border-1); text-decoration: none;
}
.jj-row__lead  { flex: 0 0 auto; display: inline-flex; color: var(--jj-text-2); }
.jj-row__title { flex: 1 1 auto; font-size: var(--jj-font-size-body); font-weight: var(--jj-font-weight-semibold); }
.jj-row__meta  { flex: 0 0 auto; font-size: var(--jj-font-size-caption); color: var(--jj-text-2); }
.jj-row__trail { flex: 0 0 auto; font-family: var(--jj-font-mono); color: var(--jj-text-2); }
/* actionnable = élément natif <a>/<button> (pas de div rendu interactif à la main) */
a.jj-row, button.jj-row {
  width: 100%; cursor: pointer; text-align: left; font: inherit;
  border: 0; border-bottom: 1px solid var(--jj-border-1);
  -webkit-tap-highlight-color: transparent;
  transition: background var(--jj-dur-fast) var(--jj-ease), transform var(--jj-dur-fast) var(--jj-ease);
}
a.jj-row:hover, button.jj-row:hover { background: var(--jj-surface-2); }
a.jj-row:active, button.jj-row:active { transform: scale(.99); }

/* ═══════════════════════════════════════════════════════════════════════════
   DS-NAV — motifs transversaux promus (onglets, en-tête de section, segment, tuile).
   État = ARIA natif ([aria-selected]/[aria-pressed]), aucune classe d'état concurrente.
   Repère d'identité = --jj-accent-strong (marque lisible, non textuelle). Deux usages
   documentés pour .jj-tabs : (1) vrais panneaux même page → role="tablist/tab/tabpanel" ;
   (2) navigation entre pages → <a class="jj-tab"> natifs, SANS rôle tab (visuel identique).
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── TABS ────────────────────────────────────────────────────────────────── */
.jj-tabs {
  display: flex; gap: 0; overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch; border-bottom: 1px solid var(--jj-border-1);
}
.jj-tabs::-webkit-scrollbar { display: none; }
.jj-tab {
  flex: 1 0 auto;                       /* remplit ; ne rétrécit pas → défile si trop d'onglets */
  display: inline-flex; align-items: center; justify-content: center; gap: var(--jj-space-sm);
  min-height: 46px; padding: 0 var(--jj-space-md);
  border: 0; border-bottom: 3px solid transparent; background: transparent;
  font-family: var(--jj-font-body); font-size: var(--jj-font-size-label); font-weight: var(--jj-font-weight-bold);
  color: var(--jj-text-3); white-space: nowrap; text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: color var(--jj-dur-fast) var(--jj-ease), background var(--jj-dur-fast) var(--jj-ease);
}
/* actif : plusieurs signaux (souligné accent-strong + fond discret + graisse + libellé neutre),
   jamais la seule couleur. Source unique = [aria-selected="true"]. */
.jj-tab[aria-selected="true"] {
  color: var(--jj-text-1);
  border-bottom-color: var(--jj-accent-strong);
  background: color-mix(in srgb, var(--jj-accent) 12%, transparent);
}
.jj-tab:disabled { color: var(--jj-text-3); cursor: not-allowed; }   /* token, pas d'opacité aveugle */
.jj-tab:focus-visible {
  outline: 2px solid var(--jj-focus); outline-offset: -3px;
  box-shadow: inset 0 0 0 2px var(--jj-focus-contrast);
}

/* ── SECTION HEAD ────────────────────────────────────────────────────────── */
.jj-section-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--jj-space-md);
  margin: var(--jj-space-lg) 0 var(--jj-space-sm);
}
.jj-section-head__title {
  display: flex; align-items: center; gap: var(--jj-space-sm); margin: 0;
  font-family: var(--jj-font-body); font-size: var(--jj-font-size-caption); font-weight: var(--jj-font-weight-bold);
  color: var(--jj-text-2); letter-spacing: .12em; text-transform: uppercase;
}
/* tick d'accent : repère NON textuel (marque lisible) ; le titre reste neutre (AA) */
.jj-section-head__title::before {
  content: ""; flex: 0 0 auto; width: 3px; height: .9em; border-radius: 2px; background: var(--jj-accent-strong);
}
.jj-section-head__meta { flex: 0 0 auto; display: inline-flex; align-items: center; gap: var(--jj-space-sm); color: var(--jj-text-2); }

/* ── SEGMENT (choix exclusif court ; ex. Nuit/Jour/Auto) ──────────────────── */
.jj-segment {
  display: inline-flex; gap: 3px; padding: 3px; border-radius: var(--jj-radius-full);
  background: var(--jj-surface-2); border: 1px solid var(--jj-border-1);
}
.jj-segment__item {
  min-height: 46px; padding: 0 var(--jj-space-md); border: 0; border-radius: var(--jj-radius-full);
  background: transparent; color: var(--jj-text-2);
  font-family: var(--jj-font-body); font-size: var(--jj-font-size-caption); font-weight: var(--jj-font-weight-bold);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: color var(--jj-dur-fast) var(--jj-ease), background var(--jj-dur-fast) var(--jj-ease);
}
/* sélectionné : remplissage de MARQUE (repère non chromatique = pastille pleine), texte contrasté.
   La marque signale la sélection du contrôle, PAS un accent d'univers ni un état. */
.jj-segment__item[aria-pressed="true"] { background: var(--jj-brand-500); color: var(--jj-brand-on); }
.jj-segment__item:disabled { color: var(--jj-text-3); cursor: not-allowed; }
.jj-segment__item:focus-visible {
  outline: 2px solid var(--jj-focus); outline-offset: 2px; box-shadow: 0 0 0 2px var(--jj-focus-contrast);
}

/* ── TILE (accès / raccourci / univers) ───────────────────────────────────── */
.jj-tile {
  position: relative; display: flex; flex-direction: column; gap: var(--jj-space-xs); overflow: hidden;
  padding: var(--jj-space-lg);
  background: var(--jj-surface-1); color: var(--jj-text-1);
  border: 1px solid var(--jj-border-2); border-left: 3px solid var(--jj-accent);
  border-radius: var(--jj-radius-md); box-shadow: var(--jj-e1); text-decoration: none;
}
/* halo d'accent discret (identité) — dérivé du token, décoratif */
.jj-tile::before {
  content: ""; position: absolute; top: -30%; right: -20%; width: 60%; height: 120%; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--jj-accent) 16%, transparent), transparent 70%);
  opacity: .5; pointer-events: none;
}
.jj-tile__icon  { font-size: 28px; line-height: 1; }
.jj-tile__title { font-size: var(--jj-font-size-body); font-weight: var(--jj-font-weight-black); color: var(--jj-text-1); }
.jj-tile__desc  { font-size: var(--jj-font-size-caption); color: var(--jj-text-3); line-height: var(--jj-line-body); }
.jj-tile__meta  { position: absolute; top: var(--jj-space-md); right: var(--jj-space-md); }
/* actionnable = élément natif <a>/<button> */
a.jj-tile, button.jj-tile {
  width: 100%; min-height: 46px; text-align: left; font: inherit; cursor: pointer;
  -webkit-tap-highlight-color: transparent; transition: transform var(--jj-dur-fast) var(--jj-ease);
}
a.jj-tile:active, button.jj-tile:active { transform: scale(.99); }
a.jj-tile:focus-visible, button.jj-tile:focus-visible {
  outline: 2px solid var(--jj-focus); outline-offset: 2px; box-shadow: 0 0 0 2px var(--jj-focus-contrast);
}

/* ── ANIMATION ───────────────────────────────────────────────────────────── */
@keyframes jj-spin { to { transform: rotate(360deg); } }

/* ── PREFERS-REDUCED-MOTION (scopé .jj-*, jamais global) ──────────────────── */
@media (prefers-reduced-motion: reduce) {
  .jj-btn, button.jj-chip, a.jj-row, button.jj-row,
  .jj-input, .jj-select, .jj-textarea,
  .jj-tab, .jj-segment__item, a.jj-tile, button.jj-tile { transition: none; }
  .jj-btn:active, button.jj-chip:active, a.jj-row:active, button.jj-row:active,
  a.jj-tile:active, button.jj-tile:active { transform: none; }
  .jj-btn:disabled[aria-busy="true"]::after { animation: none; } /* indicateur statique, jamais supprimé */
}
