:root {
  --fond-haut: #e6f4fb;
  --fond-bas: #f6efe4;
  --texte: #0d3047;
  --texte-doux: #4f6b7d;
  --eau: #23a3d6;

  --erreur-fond: #fde8e6;
  --erreur-texte: #9b2c1f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--texte);
  background: linear-gradient(180deg, var(--fond-haut), var(--fond-bas));
}

/* --- Scène en vue 3/4 (styles en ligne, repris de front/piscine-3q.html) --- */

/* Message d'erreur, entre l'en-tête et la scène, aligné sur leurs marges. */
.erreur-zone {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 32px 0;
}

.erreur-zone:has(.erreur[hidden]) {
  display: none;
}

.erreur {
  margin: 0;
  padding: 12px 16px;
  border-radius: 12px;
  color: var(--erreur-texte);
  background: var(--erreur-fond);
}

#refresh {
  cursor: pointer;
}

/* Deux dessins de la scène : vue 3/4 sur ordinateur, vue plus plongeante et
   tournée dans la longueur sur téléphone (moins de 700 px de large). */
.scene-telephone {
  display: none;
  width: 100%;
  height: auto;
}

@media (max-width: 700px) {
  .scene-ordinateur {
    display: none;
  }

  .scene-telephone {
    display: block;
  }
}

/* Cartes du SVG : un clic ouvre l'historique (le dessin n'est pas modifié). */
.carte-scene {
  cursor: pointer;
}

.carte-scene:focus {
  outline: none;
}

.carte-scene:focus-visible {
  outline: 3px solid #0e7bab;
  outline-offset: 4px;
}

/* --- Fenêtre d'historique --- */

.historique {
  width: min(980px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 24px 28px 18px;
  border: 0;
  border-radius: 24px;
  color: var(--texte);
  background: #fff;
  box-shadow: 0 30px 80px rgba(5, 40, 65, 0.35);
}

.historique::backdrop {
  background: rgba(8, 40, 62, 0.45);
  backdrop-filter: blur(3px);
}

.historique-entete {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.historique-entete h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.historique-entete h2:focus {
  outline: none;
}

.historique-periode {
  margin: 4px 0 0;
  font-size: 0.92rem;
  color: var(--texte-doux);
}

.fermer {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  color: var(--texte-doux);
  background: #eef3f6;
  cursor: pointer;
}

.fermer:hover {
  color: var(--texte);
  background: #e1e9ee;
}

.fermer svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

/* Choix de la période, sur une ligne au-dessus du graphe. */
.periode {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin: 20px 0 16px;
}

.mode {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: #eef3f6;
}

.mode input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode span {
  display: block;
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--texte-doux);
  cursor: pointer;
}

.mode input:checked + span {
  color: var(--texte);
  background: #fff;
  box-shadow: 0 1px 4px rgba(13, 48, 71, 0.15);
}

.mode input:focus-visible + span {
  outline: 2px solid var(--eau);
}

.choix {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}

.choix[hidden] {
  display: none;
}

.raccourcis {
  display: flex;
  gap: 6px;
}

.raccourcis button {
  padding: 6px 12px;
  border: 1px solid #d5e0e6;
  border-radius: 999px;
  font: inherit;
  font-size: 0.88rem;
  color: var(--texte-doux);
  background: #fff;
  cursor: pointer;
}

.raccourcis button:hover {
  border-color: #9fb3c0;
  color: var(--texte);
}

.raccourcis button.actif {
  border-color: var(--eau);
  color: #fff;
  background: var(--eau);
}

.champ {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  color: var(--texte-doux);
}

.champ input {
  padding: 6px 10px;
  border: 1px solid #d5e0e6;
  border-radius: 10px;
  font: inherit;
  color: var(--texte);
  background: #fff;
}

.champ input[type="number"] {
  width: 5.5em;
}

.champ input:focus {
  outline: 2px solid var(--eau);
  outline-offset: 1px;
  border-color: transparent;
}

/* Minimum, moyenne, maximum, nombre de relevés. */
.resume {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 32px;
  margin: 0 0 8px;
  min-height: 3em;
}

.resume dt {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--texte-doux);
}

.resume dd {
  margin: 2px 0 0;
  font-size: 1.15rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.graphe-zone {
  position: relative;
}

.graphe {
  height: min(440px, 55vh);
  transition: opacity 0.2s;
}

.graphe.chargement {
  opacity: 0.45;
}

.graphe-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--texte-doux);
}

/* Sans cette règle, display: grid l'emporterait sur l'attribut hidden : le
   message vide resterait posé sur le graphe et en capterait clics et molette. */
.graphe-message[hidden] {
  display: none;
}

.aide {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--texte-doux);
}

/* Infobulle du graphe : la valeur en évidence, le nom de la courbe ensuite. */
.infobulle-date {
  margin-bottom: 6px;
  font-size: 0.82rem;
  color: var(--texte-doux);
}

.infobulle-ligne {
  display: flex;
  align-items: center;
  gap: 8px;
}

.infobulle-trait {
  width: 14px;
  height: 3px;
  border-radius: 2px;
}

.infobulle-ligne span:last-child {
  color: var(--texte-doux);
}

/* Tableau des valeurs (bouton « Données » du graphe). */
.tableau-valeurs {
  width: 100%;
  border-collapse: collapse;
  font-family: "Outfit", system-ui, sans-serif;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.tableau-valeurs th,
.tableau-valeurs td {
  padding: 6px 12px;
  border-bottom: 1px solid #e3eaee;
  text-align: left;
}

.tableau-valeurs th {
  position: sticky;
  top: 0;
  color: var(--texte-doux);
  background: #fff;
}

/* --- Petits écrans --- */

@media (max-width: 480px) {
  .erreur-zone {
    padding: 12px 16px 0;
  }

  .historique {
    padding: 18px 16px 14px;
  }

  .resume {
    gap: 8px 20px;
  }
}
