:root {
  color-scheme: light;
  --fond: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --bord: #e3e2de;
  --texte: #0b0b0b;
  --texte-2: #52514e;
  --texte-3: #7a7974;
  --grille: #ebeae6;
  --accent: #2a78d6;
  --accent-texte: #ffffff;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --autres: #a3a29c;
  --critique: #c62f2e;
  --critique-fond: #fdecec;
  --bon: #0f7a3d;
  --q1: #cde2fb; --q2: #9ec5f4; --q3: #6da7ec; --q4: #3987e5; --q5: #256abf; --q6: #184f95;
  --rayon: 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --fond: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --bord: #2e2e2b;
    --texte: #f0efec;
    --texte-2: #c3c2b7;
    --texte-3: #8f8e86;
    --grille: #2a2a27;
    --accent: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
    --autres: #6b6a64;
    --critique: #f07a7a;
    --critique-fond: #3a1d1d;
    --bon: #4cc47e;
    --q1: #1e2f45; --q2: #184f95; --q3: #1c5cab; --q4: #256abf; --q5: #3987e5; --q6: #86b6ef;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--fond); color: var(--texte); }
body { font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.chargement { padding: 48px 16px; text-align: center; color: var(--texte-3); }

/* ───── En-tête ───── */
.entete {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--bord);
}
.marque { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; margin-right: 8px; }
.marque img { width: 22px; height: 22px; }
.apps { display: flex; gap: 4px; flex-wrap: wrap; }
.puce {
  border: 1px solid var(--bord); background: transparent; border-radius: 999px;
  padding: 4px 12px; cursor: pointer; font-size: 13px; color: var(--texte-2);
  display: inline-flex; align-items: center; gap: 6px;
}
.puce:hover { background: var(--surface-2); }
.puce[aria-pressed="true"] { background: var(--texte); color: var(--surface); border-color: var(--texte); }
.badge { font-size: 10px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--texte-3); }
.puce[aria-pressed="true"] .badge { background: transparent; color: inherit; opacity: .7; }
.espace { flex: 1; }
.lien { background: none; border: 0; color: var(--texte-3); cursor: pointer; font-size: 13px; padding: 4px 6px; }
.lien:hover { color: var(--texte); }

.onglets { display: flex; gap: 2px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--bord); }
.onglet {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 12px; cursor: pointer;
  color: var(--texte-2); font-weight: 550;
}
.onglet[aria-selected="true"] { color: var(--texte); border-bottom-color: var(--accent); }

main { max-width: 1240px; margin: 0 auto; padding: 20px; display: grid; gap: 16px; }
.grille-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr)); gap: 16px; }
.tuiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

.carte { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 16px; min-width: 0; }
.carte h2 { margin: 0; font-size: 15px; font-weight: 650; }
.carte-tete { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.sous { color: var(--texte-3); font-size: 12px; }
.tuile .etiquette { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; color: var(--texte-3); }
.tuile .valeur { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tuile .detail { font-size: 12px; color: var(--texte-3); }
.vide { color: var(--texte-3); font-size: 13px; margin: 0; }

/* ───── Graphiques ───── */
.graphe { position: relative; }
.graphe svg { display: block; width: 100%; overflow: visible; }
.graphe .axe { fill: var(--texte-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.graphe .grille { stroke: var(--grille); stroke-width: 1; }
.graphe .base { stroke: var(--bord); stroke-width: 1; }
.graphe .curseur { stroke: var(--texte-3); stroke-width: 1; stroke-dasharray: 3 3; }
.bulle {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--bord); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.12); padding: 8px 10px; font-size: 12px; min-width: 150px;
}
.bulle .titre { font-weight: 650; margin-bottom: 4px; }
.bulle .ligne { display: flex; align-items: center; gap: 6px; }
.bulle .ligne .n { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; font-weight: 600; }
.pastille { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
.legende { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; font-size: 12px; color: var(--texte-2); }
.legende span { display: inline-flex; align-items: center; gap: 6px; }

/* ───── Tableaux ───── */
.tableau-defile { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--texte-3); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding: 6px 8px; border-bottom: 1px solid var(--bord); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--grille); vertical-align: top; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.coupe { max-width: 420px; overflow: hidden; text-overflow: ellipsis; }

/* Barres horizontales (top, entonnoirs) */
.barres { display: grid; gap: 8px; }
.barre-ligne { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; font-size: 13px; }
.barre-ligne .nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barre-ligne .n { font-variant-numeric: tabular-nums; color: var(--texte-2); }
.piste { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.piste > div { height: 100%; background: var(--s1); border-radius: 4px; min-width: 2px; }
.entonnoir + .entonnoir { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--grille); }
.entonnoir h3 { margin: 0 0 8px; font-size: 14px; font-weight: 600; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.perte { font-size: 11px; color: var(--texte-3); grid-column: 1 / -1; }

/* Erreurs */
.statut-critique { display: inline-flex; align-items: center; gap: 4px; color: var(--critique); background: var(--critique-fond); font-size: 11px; font-weight: 650; padding: 1px 6px; border-radius: 4px; }
pre.pile { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); padding: 10px; border-radius: 6px; font-size: 11px; max-height: 280px; overflow: auto; margin: 6px 0 0; }

/* Carte de chaleur (rétention) */
.chaleur td.c { text-align: center; font-variant-numeric: tabular-nums; font-size: 12px; min-width: 46px; border: 2px solid var(--surface); border-radius: 4px; }

/* ───── Formulaires ───── */
.controles { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.champ { display: grid; gap: 4px; font-size: 12px; color: var(--texte-3); min-width: 0; }
.champ input, .champ select {
  background: var(--surface); border: 1px solid var(--bord); border-radius: 8px; padding: 7px 10px; color: var(--texte); min-width: 0;
}
.champ input:focus, .champ select:focus, .bouton:focus-visible, .puce:focus-visible, .onglet:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.champ-large { flex: 1 1 260px; }
.bouton { background: var(--accent); color: var(--accent-texte); border: 0; border-radius: 8px; padding: 8px 14px; font-weight: 600; cursor: pointer; }
.bouton.second { background: var(--surface-2); color: var(--texte); }
.bouton.danger { background: transparent; color: var(--critique); border: 1px solid var(--bord); }
.bouton:disabled { opacity: .5; cursor: default; }
.erreur { color: var(--critique); font-size: 13px; margin: 8px 0 0; }
.etapes { display: grid; gap: 6px; }
.etape { display: flex; gap: 6px; align-items: center; }
.etape span { width: 20px; color: var(--texte-3); font-size: 12px; text-align: right; }
.etape input { flex: 1; }

/* Connexion */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.connexion form { width: min(360px, 100%); display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--bord); border-radius: 14px; padding: 28px; }
.connexion h1 { margin: 0; font-size: 20px; display: flex; gap: 10px; align-items: center; }
.connexion h1 img { width: 28px; height: 28px; }

@media (max-width: 640px) {
  .entete, .onglets { padding-left: 16px; padding-right: 16px; }
  main { padding: 16px; }
  .tuile .valeur { font-size: 22px; }
}
