/* Pilotage Tope : la palette de l'app (mobile/theme.ts) pour l'interface,
   une palette validée daltonisme pour les données (graphiques.js). */
:root {
  color-scheme: light;
  --fond: #FAF7F0;
  --bloc: #FFFFFF;
  --surface: #EDEEEB;
  --surface-active: #E2E4E0;
  --texte: #101210;
  --sous-texte: #64676E;
  --discret: #898781;
  --grille: #E9E8E2;
  --axe: #C3C2B7;
  --sauge: #8FB36A;
  --sauge-lisible: #5E7C43;
  --prod: #B4462F;
  --hausse: #3E7A2A;
  --baisse: #B4462F;
  --serie-1: #2a78d6; --serie-2: #eb6834; --serie-3: #1baf7a; --serie-4: #eda100; --serie-5: #e87ba4;
  --seq-0: #F2F6FC; --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95;
  --ombre: 0 1px 2px rgba(16, 18, 16, 0.04), 0 4px 16px rgba(16, 18, 16, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --fond: #050506; --bloc: #17181A; --surface: #26282B; --surface-active: #303236;
    --texte: #FAF7F0; --sous-texte: #AAA3AB; --discret: #898781; --grille: #26282B; --axe: #383835;
    --sauge-lisible: #A9C98A; --prod: #E8806A; --hausse: #8FCB6E; --baisse: #EE8B78;
    --serie-1: #3987e5; --serie-2: #d95926; --serie-3: #199e70; --serie-4: #c98500; --serie-5: #d55181;
    --seq-0: #1E2023; --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #9ec5f4;
    --ombre: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --fond: #050506; --bloc: #17181A; --surface: #26282B; --surface-active: #303236;
  --texte: #FAF7F0; --sous-texte: #AAA3AB; --discret: #898781; --grille: #26282B; --axe: #383835;
  --sauge-lisible: #A9C98A; --prod: #E8806A; --hausse: #8FCB6E; --baisse: #EE8B78;
  --serie-1: #3987e5; --serie-2: #d95926; --serie-3: #199e70; --serie-4: #c98500; --serie-5: #d55181;
  --seq-0: #1E2023; --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #9ec5f4;
  --ombre: none;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--fond); color: var(--texte);
  font: 15px/1.45 Nunito, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, .marque, .valeur, .hero .valeur { font-family: "Familjen Grotesk", Nunito, system-ui, sans-serif; }
button, input { font: inherit; color: inherit; }

/* En-tête et navigation */
.entete {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 24px 10px; max-width: 1240px; margin: 0 auto;
}
.marque { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.marque img { border-radius: 8px; }
.filtres { display: flex; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.segments { display: inline-flex; background: var(--surface); border-radius: 999px; padding: 3px; }
.segments a {
  text-decoration: none; padding: 5px 14px; border-radius: 999px; font-weight: 600; font-size: 14px; color: var(--sous-texte);
}
.segments a.actif { background: var(--bloc); color: var(--texte); box-shadow: var(--ombre); }
.segments a.prod.actif { color: var(--prod); }
.sortie button { background: none; border: 0; color: var(--sous-texte); cursor: pointer; font-weight: 600; padding: 6px 4px; }
.sortie button:hover { color: var(--texte); }

.onglets {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  padding: 0 24px; max-width: 1240px; margin: 0 auto; border-bottom: 1px solid var(--grille);
}
.onglets::-webkit-scrollbar { display: none; }
.onglets a {
  text-decoration: none; white-space: nowrap; padding: 10px 12px; font-weight: 600; color: var(--sous-texte);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.onglets a:hover { color: var(--texte); }
.onglets a.actif { color: var(--texte); border-bottom-color: var(--sauge); }

/* Page */
.page { max-width: 1240px; margin: 0 auto; padding: 20px 24px 64px; }
.titre-page { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
h1 { font-size: 26px; margin: 0; letter-spacing: -0.02em; }
.maj { margin: 0; color: var(--discret); font-size: 13px; }
.maj a { color: var(--sous-texte); }
.alerte { background: var(--bloc); border-left: 3px solid var(--prod); padding: 12px 16px; border-radius: 10px; }
.vide { color: var(--sous-texte); }

.grille { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.bloc { background: var(--bloc); border-radius: 18px; padding: 18px 20px; box-shadow: var(--ombre); min-width: 0; }
.bloc.pleine, .bloc.tuiles { grid-column: 1 / -1; }
.bloc.tuiles { background: none; box-shadow: none; padding: 0; }
.bloc-entete { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
h2 { font-size: 16px; margin: 0; letter-spacing: -0.01em; }
.aide { color: var(--sous-texte); font-size: 13px; margin: 2px 0 0; }
.bascule {
  background: none; border: 0; color: var(--sous-texte); font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 2px 0; white-space: nowrap;
}
.bascule:hover { color: var(--texte); }

/* Tuiles */
.rangee-tuiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tuile { background: var(--bloc); border-radius: 16px; padding: 14px 16px; box-shadow: var(--ombre); }
.tuile .libelle { color: var(--sous-texte); font-size: 13px; font-weight: 600; margin: 0; }
.tuile .valeur { font-size: 26px; font-weight: 700; margin: 2px 0 0; letter-spacing: -0.02em; }
.tuile .aide { margin-top: 4px; font-size: 12px; }
.tuile.hero { grid-row: span 2; display: flex; flex-direction: column; justify-content: center; }
.tuile.hero .valeur { font-size: 52px; line-height: 1.05; }
.delta { font-size: 13px; font-weight: 700; margin: 4px 0 0; }
.delta .ref { font-weight: 400; color: var(--discret); }
.delta.bon { color: var(--hausse); }
.delta.mauvais { color: var(--baisse); }
.delta.neutre { color: var(--sous-texte); }

/* Graphiques */
.graphique { position: relative; }
.graphique svg { display: block; width: 100%; height: auto; overflow: visible; }
.graphique text { fill: var(--discret); font-size: 11px; font-family: Nunito, system-ui, sans-serif; }
.graphique .grille-ligne { stroke: var(--grille); stroke-width: 1; }
.graphique .axe { stroke: var(--axe); stroke-width: 1; }
.graphique .curseur { stroke: var(--axe); stroke-width: 1; }
.legende { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0 0 10px; padding: 0; list-style: none; font-size: 13px; color: var(--sous-texte); }
.legende li { display: inline-flex; align-items: center; gap: 6px; }
.legende i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.barres { display: grid; gap: 8px; }
.barre { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.barre .nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--texte); }
.barre .piste { height: 14px; }
.barre .remplissage { height: 100%; background: var(--serie-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.barre .nombre { font-variant-numeric: tabular-nums; color: var(--sous-texte); min-width: 3ch; text-align: right; }

.entonnoir { display: grid; gap: 10px; }
.etape { display: grid; grid-template-columns: minmax(110px, 30%) 1fr; gap: 12px; align-items: center; }
.etape .nom { font-size: 14px; font-weight: 600; }
.etape .piste { position: relative; height: 30px; }
.etape .remplissage { height: 100%; background: var(--seq-4); border-radius: 0 4px 4px 0; min-width: 2px; }
.etape .chiffres { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-size: 13px; font-weight: 700; color: #fff; white-space: nowrap; }
.etape .chiffres.dehors { color: var(--texte); }
.etape .chiffres span { font-weight: 400; opacity: 0.85; }

/* Tables */
.defile { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--sous-texte); font-weight: 600; font-size: 12px; padding: 6px 10px 8px 0; border-bottom: 1px solid var(--grille); white-space: nowrap; }
td { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--grille); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.cohortes td.cellule { text-align: center; font-variant-numeric: tabular-nums; font-size: 13px; padding: 0; border: 2px solid var(--bloc); border-radius: 6px; }
.cohortes td.cellule span { display: block; padding: 7px 4px; border-radius: 6px; }
.cohortes th { text-align: center; }
.cohortes th:first-child, .cohortes th:nth-child(2) { text-align: left; }

.infobulle {
  position: fixed; z-index: 10; pointer-events: none; background: var(--texte); color: var(--fond);
  border-radius: 10px; padding: 8px 10px; font-size: 13px; line-height: 1.35; max-width: 260px; box-shadow: 0 6px 20px rgba(0,0,0,0.18);
}
.infobulle b { font-weight: 700; }
.infobulle .ligne-info { display: flex; align-items: center; gap: 6px; }
.infobulle i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* Connexion */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.carte-connexion { background: var(--bloc); border-radius: 22px; padding: 28px; width: min(360px, 100%); display: grid; gap: 14px; box-shadow: var(--ombre); }
.carte-connexion .marque { margin-bottom: 6px; }
.carte-connexion label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--sous-texte); }
.carte-connexion input { background: var(--surface); border: 1px solid transparent; border-radius: 12px; padding: 11px 12px; color: var(--texte); font-size: 16px; }
.carte-connexion input:focus { outline: 2px solid var(--sauge); outline-offset: 1px; }
.carte-connexion button { background: var(--sauge); color: #101210; border: 0; border-radius: 999px; padding: 12px; font-weight: 700; cursor: pointer; margin-top: 4px; }

@media (max-width: 760px) {
  .entete, .onglets, .page { padding-left: 16px; padding-right: 16px; }
  .filtres { margin-left: 0; order: 3; width: 100%; }
  .grille { grid-template-columns: minmax(0, 1fr); }
  .tuile.hero { grid-column: 1 / -1; grid-row: auto; }
  .tuile.hero .valeur { font-size: 44px; }
  .rangee-tuiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .barre { grid-template-columns: minmax(80px, 40%) 1fr auto; }
}
@media (prefers-reduced-motion: no-preference) {
  .remplissage { transition: width 0.4s ease; }
}

/* Texte des cellules de cohorte, selon la clarté du fond. */
.cohortes .s0, .cohortes .s1, .cohortes .s2, .cohortes .s3 { color: #101210; }
.cohortes .s0 { color: var(--sous-texte); }
.cohortes .s4, .cohortes .s5, .cohortes .s6 { color: #FFFFFF; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cohortes .s1, :root:not([data-theme="light"]) .cohortes .s2,
  :root:not([data-theme="light"]) .cohortes .s3, :root:not([data-theme="light"]) .cohortes .s4 { color: #FAF7F0; }
  :root:not([data-theme="light"]) .cohortes .s5, :root:not([data-theme="light"]) .cohortes .s6 { color: #101210; }
}
:root[data-theme="dark"] .cohortes .s1, :root[data-theme="dark"] .cohortes .s2,
:root[data-theme="dark"] .cohortes .s3, :root[data-theme="dark"] .cohortes .s4 { color: #FAF7F0; }
:root[data-theme="dark"] .cohortes .s5, :root[data-theme="dark"] .cohortes .s6 { color: #101210; }
@media (max-width: 760px) { .sortie { margin-left: auto; } }

/* Prompts */
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.92em; background: var(--surface); padding: 1px 5px; border-radius: 6px; }
.lien-fort { font-weight: 700; text-decoration: none; }
.lien-fort:hover { text-decoration: underline; }
.etiquette { font-size: 12px; color: var(--sous-texte); background: var(--surface); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.fil { margin: 0 0 4px; font-size: 13px; color: var(--sous-texte); }
.fil a { color: var(--sous-texte); }
.version { font-size: 16px; color: var(--sous-texte); font-weight: 600; margin-left: 6px; }
.bouton, .actions button { background: var(--sauge); color: #101210; border: 0; border-radius: 999px; padding: 9px 18px; font-weight: 700; cursor: pointer; text-decoration: none; font-size: 14px; }
.actions button.secondaire { background: var(--surface); color: var(--texte); }
.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.actions a { color: var(--sous-texte); font-weight: 600; }
.succes { background: var(--bloc); border-left: 3px solid var(--sauge); padding: 12px 16px; border-radius: 10px; }
pre.prompt { margin: 0; white-space: pre-wrap; word-break: break-word; font: 13.5px/1.6 ui-monospace, "SF Mono", Menlo, monospace; color: var(--texte); max-height: 70vh; overflow: auto; }
.capacites { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 8px 14px; font-size: 14px; }
.capacites dt { margin: 0; }
.capacites dd { margin: 0; color: var(--sous-texte); }
.historique { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 14px; }
.historique time { color: var(--discret); font-size: 12px; margin-left: 4px; }
.edition { display: grid; gap: 14px; }
.champ { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--sous-texte); }
.champ textarea, .champ input { background: var(--bloc); border: 1px solid var(--grille); border-radius: 14px; padding: 12px 14px; color: var(--texte); font-weight: 400; }
.champ textarea { font: 13.5px/1.6 ui-monospace, "SF Mono", Menlo, monospace; resize: vertical; min-height: 360px; }
.champ input { font-size: 15px; }
.champ textarea:focus, .champ input:focus { outline: 2px solid var(--sauge); outline-offset: 1px; }
.diff { font: 13px/1.55 ui-monospace, "SF Mono", Menlo, monospace; white-space: pre-wrap; word-break: break-word; max-height: 50vh; overflow: auto; border-radius: 10px; }
.diff > div { padding: 0 10px; }
.diff .signe { display: inline-block; width: 1.4em; color: var(--discret); user-select: none; }
.diff .ajout { background: color-mix(in srgb, var(--hausse) 14%, transparent); }
.diff .retrait { background: color-mix(in srgb, var(--baisse) 14%, transparent); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--baisse) 50%, transparent); }
.diff .saut { color: var(--discret); padding: 4px 10px; }
@media (max-width: 760px) { .capacites { grid-template-columns: 1fr; } .capacites dd { margin-bottom: 6px; } }
