/*
 * ACO Run Plan — feuille de style unique.
 *
 * Les couleurs de donnees viennent d'une palette validee (separation pour les
 * daltonismes, contraste sur les deux surfaces) : elles sont definies une fois
 * comme variables et utilisees par role, jamais en dur dans le corps du document.
 */

:root {
  color-scheme: light;

  /* surfaces et encre */
  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);

  /* series de donnees */
  --series-1: #2a78d6;
  --series-2: #eb6834;

  /* etats — toujours accompagnes d'un libelle, jamais la couleur seule */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-text: #006300;

  /* espacement, sur une echelle de 4 px */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-2: #d95926;
    --good-text: #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --series-1: #3987e5;
  --series-2: #d95926;
  --good-text: #0ca30c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--plane);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 19px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }

/* ------------------------------- en-tete ------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s4);
  padding: var(--s3) var(--s5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: baseline; gap: var(--s3); margin-right: auto; }
.brand .sub { color: var(--muted); font-size: 13px; }

.countdown {
  display: flex;
  align-items: baseline;
  gap: var(--s1);
  padding: var(--s1) var(--s3);
  background: var(--surface-2);
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink-2);
}
.countdown b { font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; }

/* --------------------------------- nav --------------------------------- */

.tabs {
  display: flex;
  gap: var(--s1);
  padding: 0 var(--s5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  appearance: none;
  border: 0;
  background: none;
  font: inherit;
  color: var(--ink-2);
  padding: var(--s3) var(--s3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--series-1); font-weight: 600; }

/* -------------------------------- layout -------------------------------- */

main { padding: var(--s5); max-width: 1180px; margin: 0 auto; }
.view[hidden] { display: none; }
.stack { display: flex; flex-direction: column; gap: var(--s5); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s5);
}
.card > header { margin-bottom: var(--s4); }
.card > header p { color: var(--ink-2); font-size: 13px; margin-top: var(--s1); }

.grid { display: grid; gap: var(--s4); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

/* ------------------------------ chiffres clefs ------------------------------ */

.figure { display: flex; flex-direction: column; gap: var(--s1); }
.figure .label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.figure .value { font-size: 34px; line-height: 1.1; font-weight: 600; }
.figure .value.sm { font-size: 24px; }
.figure .note { font-size: 13px; color: var(--ink-2); }
.figure .value.tabular { font-variant-numeric: tabular-nums; }

/* Un objectif se modifie : le chiffre est un bouton, et il le montre. */
.editable {
  appearance: none;
  border: 1px dashed var(--axis);
  background: none;
  font: inherit;
  font-size: 34px;
  font-weight: 600;
  color: var(--ink);
  padding: 0 var(--s2);
  margin-left: calc(var(--s2) * -1);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  /* Le cadre epouse le chiffre plutot que d'occuper toute la colonne. */
  align-self: flex-start;
}
.editable:hover { border-color: var(--series-1); color: var(--series-1); }
.editable::after { content: " ✎"; font-size: 15px; color: var(--muted); }

/* -------------------------------- badges -------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  padding: 2px var(--s2);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
}
/* La pastille de couleur ne porte jamais le sens seule : le libelle est toujours la. */
.badge .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.badge.good .dot { background: var(--good); }
.badge.stretch .dot { background: var(--warning); }
.badge.serious .dot { background: var(--serious); }
.badge.critical .dot { background: var(--critical); }
.badge.neutral .dot { background: var(--muted); }

/* ----------------------------- propositions ----------------------------- */

.proposal {
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius-sm);
  padding: var(--s4);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}
.proposal.alert { border-left-color: var(--critical); }
.proposal.caution { border-left-color: var(--serious); }
.proposal.info { border-left-color: var(--series-1); }
.proposal .evidence { color: var(--ink-2); font-size: 14px; }
.proposal .actions { display: flex; gap: var(--s2); margin-top: var(--s1); }

button.primary, button.ghost {
  appearance: none;
  font: inherit;
  font-size: 14px;
  padding: var(--s2) var(--s4);
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--border);
}
button.primary { background: var(--series-1); border-color: transparent; color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: var(--surface); color: var(--ink); }
button.ghost:hover { background: var(--surface-2); }
button:disabled { opacity: 0.5; cursor: default; }

/* -------------------------------- semaines -------------------------------- */

.week { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.week + .week { margin-top: var(--s4); }
.week > header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s3);
  padding: var(--s4) var(--s5);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.week > header .idx { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--muted); }
.week > header .role { font-weight: 600; }
.week > header .dates { color: var(--muted); font-size: 13px; }
.week > header .vol { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 14px; }
.week.current { border-color: var(--series-1); }
.week .focus { padding: var(--s3) var(--s5); color: var(--ink-2); font-size: 14px; border-bottom: 1px solid var(--border); }

.gate {
  padding: var(--s3) var(--s5);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.gate .q { font-weight: 600; }
.gate .miss { color: var(--ink-2); margin-top: var(--s1); }

.session { display: flex; gap: var(--s4); padding: var(--s4) var(--s5); }
.session + .session { border-top: 1px solid var(--grid); }
.session.past { opacity: 0.55; }
.session .day { min-width: 116px; font-size: 13px; color: var(--muted); }
.session .day b { display: block; color: var(--ink); font-size: 14px; }
.session .body { flex: 1; display: flex; flex-direction: column; gap: var(--s1); }
.session .head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s2); }
.session .title { font-weight: 600; }
.session .dist { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 14px; }
.session .structure { font-size: 14px; color: var(--ink-2); }
.session .why { font-size: 13px; color: var(--muted); font-style: italic; }
.session.race { background: var(--surface-2); }
.session.race .title { color: var(--series-1); }

/* -------------------------------- tableaux -------------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--grid); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
tr.emphasis td { font-weight: 600; }

/* ------------------------------ graphiques ------------------------------ */

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .legend { display: flex; flex-wrap: wrap; gap: var(--s4); margin-bottom: var(--s3); font-size: 13px; color: var(--ink-2); }
.chart .legend span { display: inline-flex; align-items: center; gap: var(--s2); }
.chart .legend i { width: 12px; height: 3px; border-radius: 2px; flex: none; }
.chart .empty { padding: var(--s6) 0; text-align: center; color: var(--muted); font-size: 14px; }

.tooltip {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%);
  background: var(--ink);
  color: var(--plane);
  padding: var(--s2) var(--s3);
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  transition: opacity 0.1s;
  z-index: 5;
}
.tooltip b { font-variant-numeric: tabular-nums; }

/* Chaque graphique offre ses valeurs en tableau : la couleur n'est jamais le seul canal. */
.values-toggle {
  appearance: none;
  border: 0;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--series-1);
  cursor: pointer;
  padding: var(--s2) 0 0;
}
.values-toggle:hover { text-decoration: underline; }

/* ------------------------------- scenarios ------------------------------- */

.scenario {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  background: var(--surface);
}
.scenario.current { border-color: var(--series-1); border-width: 2px; }
.scenario .time { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.scenario dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: var(--s1) var(--s3); font-size: 13px; }
.scenario dt { color: var(--muted); }
.scenario dd { margin: 0; font-variant-numeric: tabular-nums; }
.scenario .detail { font-size: 13px; color: var(--ink-2); }

/* ------------------------------- divers ------------------------------- */

.banner {
  padding: var(--s4) var(--s5);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  align-items: center;
}
.banner.attention { border-left: 3px solid var(--warning); }
.banner p { flex: 1; min-width: 260px; font-size: 14px; color: var(--ink-2); }
.banner code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  background: var(--surface-2);
  padding: 1px var(--s1);
  border-radius: 4px;
}
.banner ol { margin: var(--s2) 0 0; padding-left: var(--s5); color: var(--ink-2); font-size: 14px; }
.banner ol li + li { margin-top: var(--s1); }

.list-plain { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--s3); }
.list-plain.numbered { counter-reset: step; }
.list-plain.numbered li { display: flex; gap: var(--s3); }
.list-plain.numbered li::before {
  counter-increment: step;
  content: counter(step);
  flex: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  display: grid; place-items: center;
}

.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--s2) var(--s4); font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

.phase { border-left: 2px solid var(--series-1); padding-left: var(--s4); }
.phase + .phase { margin-top: var(--s4); }
.phase .range { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.phase .label { font-weight: 600; }
.phase .watch { font-size: 13px; color: var(--ink-2); margin-top: var(--s1); }

.missing { margin: 0; padding-left: var(--s5); color: var(--ink-2); font-size: 14px; }
.missing li + li { margin-top: var(--s1); }

.spinner { color: var(--muted); font-size: 14px; padding: var(--s6); text-align: center; }

@media (max-width: 620px) {
  main { padding: var(--s4); }
  .card { padding: var(--s4); }
  .topbar { padding: var(--s3) var(--s4); }
  .tabs { padding: 0 var(--s4); }
  .session { flex-direction: column; gap: var(--s2); }
  .session .day { min-width: 0; }
  .figure .value, .editable { font-size: 28px; }
}

/* Deplacement d'une seance dans sa semaine. */
.session .move {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  margin-top: var(--s1);
  font-size: 12px;
  color: var(--muted);
}
.session .move select {
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px var(--s2);
  cursor: pointer;
}
.session .move select:hover { border-color: var(--series-1); }

/* ------------------------------ realise ------------------------------ */

/*
 * Une seance realisee tient sur trois registres visuels : le jour, ce qui etait
 * prevu, et les mesures. Le statut passe par un liseré a gauche et par un
 * libelle : la couleur n'est jamais le seul canal.
 */
.exec-session { display: flex; gap: var(--s4); padding: var(--s4) var(--s5); border-left: 3px solid transparent; }
.exec-session + .exec-session { border-top: 1px solid var(--grid); }
.exec-session.done, .exec-session.moved { border-left-color: var(--good); }
.exec-session.partial { border-left-color: var(--warning); }
.exec-session.missed { border-left-color: var(--critical); background: color-mix(in srgb, var(--critical) 4%, transparent); }
.exec-session.extra { border-left-color: var(--axis); background: var(--surface-2); }

.exec-session .when { min-width: 116px; flex: none; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; }
.exec-session .when b { color: var(--ink); font-weight: 600; }
.exec-session .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--s2); }
.exec-session .head { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.exec-session .head .title { font-weight: 600; }

.metrics { display: flex; gap: var(--s5); flex-wrap: wrap; }
/* Valeur et unite sur une ligne, reference prescrite sur la suivante, en retrait. */
.metric { display: block; line-height: 1.25; }
.metric b { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric .unit { margin-left: 2px; font-size: 13px; color: var(--ink-2); }
.metric i { display: block; font-style: normal; font-size: 12px; color: var(--muted); }

.exec-session .readout { font-size: 14px; color: var(--ink-2); }
.exec-session .runs { font-size: 12px; color: var(--muted); }
.week .pending { padding: var(--s3) var(--s5); font-size: 13px; color: var(--muted); border-top: 1px solid var(--grid); }

/* Le realise accroche a une seance du plan : une seule ligne, dense. */
.session .actual {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
  margin-top: var(--s2);
  padding: var(--s2) var(--s3);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}
.session .actual.missed { background: color-mix(in srgb, var(--critical) 6%, transparent); }
.session.extra-run { background: var(--surface-2); }
.session.extra-run .day b { color: var(--ink-2); }

/* Les dernieres seances, sur le tableau de bord. */
.recent { display: flex; flex-direction: column; }
.recent-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) 0;
  font-size: 14px;
}
.recent-row + .recent-row { border-top: 1px solid var(--grid); }
.recent-row .date { min-width: 92px; color: var(--muted); font-size: 13px; }
.recent-row .what { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-row .verdict { display: flex; align-items: center; gap: var(--s2); flex: none; }
.recent-row .verdict .tabular { font-variant-numeric: tabular-nums; font-weight: 600; }

@media (max-width: 620px) {
  .exec-session { flex-direction: column; gap: var(--s2); }
  .exec-session .when { flex-direction: row; gap: var(--s2); }
  .metrics { gap: var(--s4); }
  .recent-row { flex-wrap: wrap; }
}

/* Phrase de contexte : elle qualifie un chiffre sans le contredire. */
.context {
  font-size: 13px;
  color: var(--ink-2);
  padding: var(--s3);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
/* Le deja-couru, en retrait du volume prescrit : deux nombres, pas un total. */
td .plus { font-style: normal; color: var(--muted); font-size: 13px; }

/* Composition du ratio de charge : les sports annexes se distinguent des courses. */
.load-note { margin-top: var(--s3); font-size: 13px; color: var(--ink-2); }
tr.other td { color: var(--ink-2); }
tr.other td:nth-child(2)::after { content: " (hors course)"; color: var(--muted); font-size: 12px; }

/* Lecture croisée allure × cardio : elle prolonge le constat d'exécution. */
.exec-session .readout.cardiac { padding-top: var(--s1); border-top: 1px solid var(--grid); }
.exec-session .readout.cardiac .basis { color: var(--muted); font-size: 13px; }

/* La séance théorique face au relevé. */
.intervals {
  margin-top: var(--s2);
  padding: var(--s3);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}
.intervals .versus { display: flex; gap: var(--s3); align-items: baseline; font-size: 14px; }
.intervals .versus .k {
  min-width: 62px;
  flex: none;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.intervals .versus .v { font-variant-numeric: tabular-nums; }
.intervals table { font-size: 13px; }
.intervals .readout { font-size: 13px; color: var(--ink-2); }

/* Le profil d'une séance : la courbe d'abord, les chiffres dépliables dessous. */
.intervals .profile { margin-top: var(--s2); }
.intervals .profile .chart { margin: 0; }
.intervals .profile table { font-size: 13px; }
