/* Athéna — design system « Pierre ». Tokens, base, animations.
   Le détail des composants est porté en JS (styles inline, fidèle au prototype). */

:root {
  /* Pierre · jour */
  --bg: #e6e3dc;
  --surface: #efebe2;
  --surface2: #faf8f1;
  --fg: #141312;
  --fg2: #4d4a45;
  --fg3: #615d56;
  --line: rgba(20, 19, 18, 0.08);
  --lineStrong: rgba(20, 19, 18, 0.14);
  --accent: #1e3a5f;
  --accentInk: #11253f;
  --accentSoft: #d6dde6;
  --pos: #3d6b3d;
  --warn: #9a7d1f;
  --alert: #a04a2f;

  /* Blocs de macroplan — palette de progression (jour). Chaque bloc a une
     teinte distincte pour la timeline et les charts de Préparation :
     ardoise → vert → marine → ocre → prune → terre cuite → grège. */
  --block-foundation: #6b7b8c;
  --block-base: #3d6b3d;
  --block-build: #2f5e8f;
  --block-peak: #9a7d1f;
  --block-taper: #7a5a8c;
  --block-race: #a04a2f;
  --block-recovery: #8c867c;

  --fDisp: "Geist", -apple-system, "Helvetica Neue", system-ui, sans-serif;
  --fBody: "Geist", -apple-system, "Helvetica Neue", system-ui, sans-serif;
  --fMono: "Geist Mono", ui-monospace, Menlo, monospace;
  --fDispLs: -0.035em;
  --fBodyLs: -0.005em;
}

[data-theme="dark"] {
  /* Pierre · nuit */
  --bg: #0d1117;
  --surface: #161c25;
  --surface2: #1d242f;
  --fg: #e8e4d8;
  --fg2: #a8a395;
  --fg3: #8b867c;
  --line: rgba(232, 228, 216, 0.07);
  --lineStrong: rgba(232, 228, 216, 0.14);
  --accent: #7aa7d4;
  --accentInk: #a6c4e0;
  --accentSoft: #1a2536;
  --pos: #7fa570;
  --warn: #d4b96a;
  --alert: #d68a6a;

  /* Blocs de macroplan — mêmes teintes, éclaircies pour le fond sombre. */
  --block-foundation: #8da3b5;
  --block-base: #7fa570;
  --block-build: #6f9fcf;
  --block-peak: #d4b96a;
  --block-taper: #b394c4;
  --block-race: #d68a6a;
  --block-recovery: #9a948a;
}

/* ─── Data labels qualitatifs ────────────────────────────────────────
 * Composant unique pour TOUS les labels dynamiques de la page Charge
 * (zone du ratio, qualification du delta 7 j, statut adhérence, tendance).
 * Style unifié : serif italique 13 px, casse Capitale initiale, jamais de
 * gras. La couleur est portée par un seul modifier (4 valeurs : neutral,
 * positive, warning, alert) — tous les tokens sont déclarés ci-dessus,
 * version sombre incluse. NE PAS dupliquer ces propriétés inline ailleurs.
 */
.ath-data-label {
  font-family: var(--fDisp);
  font-style: italic;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.01em;
}
.ath-data-label--neutral  { color: var(--fg3); }
.ath-data-label--positive { color: var(--pos); }
.ath-data-label--warning  { color: var(--warn); }
.ath-data-label--alert    { color: var(--alert); }

* { margin: 0; padding: 0; box-sizing: border-box; }
/* Hauteur viewport : `100%` sur html/body s'aligne sur le viewport layout
   d'iOS Safari, qui reste figé quand le clavier s'ouvre et laisse le composer
   masqué. `100dvh` (dynamic) se rétrécit avec le clavier sur iOS 15.4+, Chrome
   108+, Firefox 119+. Le @supports protège les vieux navigateurs. */
html, body { height: 100%; }
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

body {
  font-family: var(--fBody);
  letter-spacing: var(--fBodyLs);
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app { height: 100%; }
@supports (height: 100dvh) {
  #app { height: 100dvh; }
}

button { font-family: inherit; letter-spacing: var(--fBodyLs); }
textarea { font-family: inherit; }
input, textarea, button { color: inherit; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--lineStrong); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

@keyframes athDot {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}
@keyframes athCaret {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}
@keyframes athFade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.ath-fade { animation: athFade 0.24s ease both; }

/* Logo : point en orbite autour des cercles (variante « marque centrale »). */
.ath-orbit {
  transform-box: view-box;
  transform-origin: 50% 50%;
  animation: athOrbit 8s linear infinite;
}
@keyframes athOrbit {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Accessibilité — anneau de focus clavier visible sur tous les contrôles. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Lien d'évitement : caché, révélé au focus clavier. */
.ath-skip {
  position: fixed; top: 10px; left: 10px; z-index: 1000;
  background: var(--fg); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; text-decoration: none;
  font-family: var(--fMono); font-size: 13px;
  transform: translateY(-160%); transition: transform 0.18s ease;
}
.ath-skip:focus { transform: translateY(0); }

/* Retour visuel au clic sur les contrôles. */
button { transition: opacity 0.15s ease, transform 0.1s ease; }
button:active { transform: scale(0.97); }

/* Spinner de chargement du module Préparation (génération macroplan). */
@keyframes athena-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ─── Cartes KPI éditoriales (langage visuel comext-analysis) ─────────
 * Liseré coloré 3 px en haut (gradient sur tokens Athéna), pastille pulsée
 * dans le label, valeur en serif/display, sub avec chip ▲/▼ pour le delta,
 * mini-sparkline positionnée en absolu dans le coin bas-droite.
 *
 * Variantes par tone (accent / pos / warn / alert) : on assigne le liseré
 * et la pastille selon la metric, pas selon l'état dynamique.
 */
.ath-kpi-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px 14px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(20, 19, 18, 0.04), 0 1px 1px rgba(20, 19, 18, 0.02);
  transition: transform .25s cubic-bezier(0.22, 1, 0.36, 1),
              box-shadow .25s cubic-bezier(0.22, 1, 0.36, 1),
              border-color .2s;
  overflow: hidden;
  min-height: 110px;
}
.ath-kpi-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, transparent));
}
.ath-kpi-card--positive::before {
  background: linear-gradient(90deg, var(--pos), color-mix(in srgb, var(--pos) 60%, transparent));
}
.ath-kpi-card--warning::before {
  background: linear-gradient(90deg, var(--warn), color-mix(in srgb, var(--warn) 60%, transparent));
}
.ath-kpi-card--alert::before {
  background: linear-gradient(90deg, var(--alert), color-mix(in srgb, var(--alert) 60%, transparent));
}
.ath-kpi-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(20, 19, 18, 0.06), 0 1px 2px rgba(20, 19, 18, 0.04);
  border-color: var(--lineStrong);
}

.ath-kpi-card .ath-kpi-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--fg3);
  font-family: var(--fMono);
}
.ath-kpi-card .ath-kpi-label::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
  flex: 0 0 auto;
  animation: athKpiPulse 2.4s ease-in-out infinite;
}
.ath-kpi-card--positive .ath-kpi-label::before {
  background: var(--pos);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pos) 22%, transparent);
}
.ath-kpi-card--warning .ath-kpi-label::before {
  background: var(--warn);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 22%, transparent);
}
.ath-kpi-card--alert .ath-kpi-label::before {
  background: var(--alert);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--alert) 22%, transparent);
}

.ath-kpi-card .ath-kpi-value {
  font-family: var(--fDisp);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: var(--fDispLs);
  margin-top: 8px;
  color: var(--fg);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.ath-kpi-card .ath-kpi-value .unit {
  font-size: 12px;
  color: var(--fg3);
  font-family: var(--fMono);
  margin-left: 4px;
  font-weight: 400;
  letter-spacing: 0;
}

.ath-kpi-card .ath-kpi-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 11px;
  font-family: var(--fMono);
  color: var(--fg3);
  font-variant-numeric: tabular-nums;
  min-height: 1.2em;
  flex-wrap: wrap;
}

.ath-kpi-card .ath-kpi-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-family: var(--fMono);
  background: color-mix(in srgb, var(--pos) 14%, transparent);
  color: var(--pos);
}
.ath-kpi-chip--neg {
  background: color-mix(in srgb, var(--alert) 14%, transparent);
  color: var(--alert);
}
.ath-kpi-chip--neutral {
  background: color-mix(in srgb, var(--fg3) 12%, transparent);
  color: var(--fg2);
}
.ath-kpi-chip::before {
  font-size: 8px;
  line-height: 1;
}
.ath-kpi-chip--pos::before  { content: "\25B2"; }   /* ▲ */
.ath-kpi-chip--neg::before  { content: "\25BC"; }   /* ▼ */
.ath-kpi-chip--neutral::before { content: "\2014"; } /* — */

.ath-kpi-card .ath-kpi-spark {
  position: absolute;
  right: 14px;
  bottom: 12px;
  width: 84px;
  height: 26px;
  pointer-events: none;
  opacity: 0.85;
}

@keyframes athKpiPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.55; transform: scale(1.2); }
}

/* ─── Tooltip de chart interactif (langage comext) ────────────────────
 * Wrapper du lineChart : position relative pour positionner la tooltip
 * en absolu par-dessus le SVG. La tooltip est blanchâtre, ombre douce,
 * texte tabular-nums pour rester aligné quand la valeur change.
 */
.ath-chart-wrap {
  position: relative;
  width: 100%;
}
.ath-chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface2);
  border: 1px solid var(--lineStrong);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: var(--fMono);
  font-size: 11px;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 14px rgba(20, 19, 18, 0.08);
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px));
  transition: opacity .12s ease-out;
  z-index: 2;
}
.ath-chart-tooltip .tt-period {
  font-size: 10px;
  color: var(--fg3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}
.ath-chart-tooltip .tt-val {
  font-family: var(--fDisp);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: var(--fDispLs);
}

/* Overlay HTML pour les labels du chart (sortis du SVG pour ne pas être
 * déformés par preserveAspectRatio="none" du mode fluid). Positionnés en %. */
.ath-chart-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.ath-chart-annot {
  position: absolute;
  font-family: var(--fMono);
  font-size: 10px;
  font-weight: 600;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(20, 19, 18, 0.04);
}
.ath-chart-xlabel {
  position: absolute;
  bottom: 6px;
  font-family: var(--fMono);
  font-size: 10px;
  font-weight: 500;
  color: var(--fg2);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Respecte la préférence système « réduire les animations ». */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Réponses d'Athéna (markdown) : sur mobile, les longs liens/mots se cassent au
   lieu de déborder la bulle ; le code et les tableaux scrollent horizontalement
   plutôt que d'élargir la page. */
.ath-abody { overflow-wrap: break-word; }
.ath-abody pre,
.ath-abody table { display: block; max-width: 100%; overflow-x: auto; }
