/* Aboigramme — dashboard.
 *
 * Les valeurs sombres sont déclarées DEUX FOIS, volontairement :
 *   • sous la requête média, pour suivre le réglage du système ;
 *   • sous [data-theme="dark"], pour que le bouton gagne.
 * Le garde `:where(:not([data-theme="light"]))` permet à un choix « clair »
 * de battre un système en sombre. Une seule des deux portées donnerait un
 * thème qui ne se laisse pas contredire.
 *
 * Aucune couleur codée en dur dans le JS : les canvas relisent ces variables.
 */

:root {
  color-scheme: light;

  --plane:    #f9f9f7;
  --surface:  #fcfcfb;
  --ink:      #0b0b0b;
  --ink-2:    #52514e;
  --muted:    #898781;
  --grid:     #e1e0d9;
  --axis:     #c3c2b7;
  --border:   rgba(11, 11, 11, 0.10);

  --series:   #2a78d6;
  --accent:   #2a78d6;
  --danger:   #d03b3b;

  /* Rampe séquentielle, UNE SEULE teinte, du plus proche du fond (1) au plus
     soutenu (6). Jamais d'arc-en-ciel : il n'encode aucune magnitude. */
  --seq-1: #cde2fb;
  --seq-2: #9ec5f4;
  --seq-3: #6da7ec;
  --seq-4: #3987e5;
  --seq-5: #256abf;
  --seq-6: #104281;

  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:   #0d0d0d;
    --surface: #1a1a19;
    --ink:     #ffffff;
    --ink-2:   #c3c2b7;
    --muted:   #898781;
    --grid:    #2c2c2a;
    --axis:    #383835;
    --border:  rgba(255, 255, 255, 0.10);
    --series:  #3987e5;
    --accent:  #3987e5;
    --danger:  #e66767;
    /* La rampe s'INVERSE : sur fond sombre, « proche de zéro » doit être
       proche du fond, donc sombre. Ce n'est pas un Flip automatique du clair,
       c'est un jeu d'étapes choisi pour cette surface. */
    --seq-1: #184f95;
    --seq-2: #256abf;
    --seq-3: #3987e5;
    --seq-4: #6da7ec;
    --seq-5: #9ec5f4;
    --seq-6: #cde2fb;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:   #0d0d0d;
  --surface: #1a1a19;
  --ink:     #ffffff;
  --ink-2:   #c3c2b7;
  --muted:   #898781;
  --grid:    #2c2c2a;
  --axis:    #383835;
  --border:  rgba(255, 255, 255, 0.10);
  --series:  #3987e5;
  --accent:  #3987e5;
  --danger:  #e66767;
  --seq-1: #184f95;
  --seq-2: #256abf;
  --seq-3: #3987e5;
  --seq-4: #6da7ec;
  --seq-5: #9ec5f4;
  --seq-6: #cde2fb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 16px 48px;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header {
  max-width: 1040px; margin: 0 auto;
  padding: 24px 0 12px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
}
h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
h2 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.sub { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }

header nav { display: flex; align-items: center; gap: 12px; }
header nav a { color: var(--accent); font-size: 14px; text-decoration: none; }

button {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--axis); }
button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

main { max-width: 1040px; margin: 0 auto; display: grid; gap: 14px; }

/* --------------------------------------------------------------- filtres */

.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.custom { display: flex; align-items: center; gap: 6px; margin-left: auto;
          color: var(--ink-2); font-size: 13px; }
.custom input {
  font: inherit; font-size: 13px; color: var(--ink);
  background: var(--plane); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 7px;
}

.status { margin: 0; font-size: 13px; color: var(--ink-2); }
.status--error { color: var(--danger); }

/* ----------------------------------------------------------------- cartes */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: opacity 140ms ease;
}
.card-sub { margin: 0 0 12px; font-size: 13px; color: var(--ink-2); }

/* Titre à gauche, export CSV à droite, alignés sur la ligne de base : le
   bouton est un accessoire du titre, il ne doit pas créer sa propre ligne. */
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 4px;
}
.card-head h2 { margin: 0; }
button.export { padding: 3px 9px; font-size: 12px; color: var(--ink-2); }
button.export:hover { color: var(--ink); }

/* -------------------------------------------------------- actualisation */

/* Le voyant d'actualisation. Comme les pastilles de la page de capture : un
   point coloré ET un texte. La couleur seule serait illisible pour un
   daltonien et ambiguë sur une capture d'écran. */
.direct {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
}
.direct-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.direct[data-etat="direct"] .direct-dot,
.direct[data-etat="nouveau"] .direct-dot { background: var(--accent); }
.direct[data-etat="erreur"] { color: var(--danger); }
.direct[data-etat="erreur"] .direct-dot { background: var(--danger); }
.direct[data-etat="pause"] { color: var(--muted); }

/* Deux pulsations à l'arrivée d'un événement : assez pour attirer l'œil,
   assez court pour ne pas clignoter en permanence un soir d'aboiements. */
@media (prefers-reduced-motion: no-preference) {
  .direct[data-etat="nouveau"] .direct-dot { animation: direct-pouls 700ms ease-out 2; }
}
@keyframes direct-pouls {
  from { box-shadow: 0 0 0 0 var(--accent); }
  to   { box-shadow: 0 0 0 7px transparent; }
}

/* Pas de squelette au rechargement : on garde le rendu précédent, simplement
   en retrait. Un squelette ferait sauter la mise en page à chaque filtre. */
body[data-loading="oui"] .card { opacity: 0.55; }

/* Le chiffre héros. Chiffres PROPORTIONNELS : tabular-nums à cette taille fait
   paraître « 121 » distendu. tabular-nums est réservé aux colonnes qui doivent
   s'aligner verticalement (tableaux, graduations). */
.hero-label { margin: 0; font-size: 12px; text-transform: uppercase;
              letter-spacing: 0.06em; color: var(--muted); }
.hero-number { margin: 2px 0 0; font-size: 56px; font-weight: 600; line-height: 1.05; }
.hero-sub { margin: 4px 0 16px; font-size: 13px; color: var(--ink-2); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.tile {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 12px; background: var(--plane); border-radius: 8px;
}
.tile-label { font-size: 11px; text-transform: uppercase;
              letter-spacing: 0.05em; color: var(--muted); }
.tile-value { font-size: 20px; font-weight: 600; }

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

/* La hauteur inclut la bande des étiquettes de l'axe : trop juste, la carte
   se doterait d'une barre de défilement interne pour deux malheureux pixels. */
.plot { position: relative; height: 280px; }
.plot canvas { width: 100% !important; height: 100% !important; }

.empty {
  margin: 0; padding: 32px 12px; text-align: center;
  color: var(--muted); font-size: 14px;
  border: 1px dashed var(--axis); border-radius: 8px;
}

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

details { margin-top: 12px; }
summary { cursor: pointer; font-size: 13px; color: var(--ink-2); }
summary:hover { color: var(--ink); }
.table-scroll { overflow-x: auto; margin-top: 8px; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 4px 8px; text-align: right; border-bottom: 1px solid var(--grid); }
thead th { color: var(--muted); font-weight: 600; font-size: 11px;
           text-transform: uppercase; letter-spacing: 0.04em; }
tbody th { text-align: left; font-weight: 500; }
/* tabular-nums ICI, et pas sur le chiffre héros : ces colonnes doivent
   s'aligner verticalement. */
tbody td, thead th { font-variant-numeric: tabular-nums; }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: none; }

button.lien {
  border: none; background: none; padding: 0;
  color: var(--accent); text-decoration: underline; font-size: 13px;
}

/* ---------------------------------------------------------------- heatmap */

.heatmap { font-size: 12px; }
.heatmap th, .heatmap td {
  text-align: center; padding: 3px 5px;
  border-bottom: 1px solid transparent;
  font-variant-numeric: tabular-nums;
}
.heatmap thead th { font-size: 10px; }
.heatmap tbody th { text-align: left; white-space: nowrap; padding-right: 10px; }
.heatmap td { border-radius: 3px; min-width: 22px; }
.heatmap .total { font-weight: 600; padding-left: 10px; color: var(--ink-2); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

audio { width: 100%; }

footer { max-width: 1040px; margin: 20px auto 0; text-align: center; }
footer p { margin: 0; font-size: 12px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
