/*
 * Supervision : feuille unique, sans bibliothèque (CSP : style-src 'self').
 * Principe : la page dit d'abord si tout va bien (bandeau d'état), puis montre les serveurs et leurs applications
 * dans un tableau dense qui tient dans la largeur de l'écran. La couleur ne porte jamais seule un état : chaque
 * état a aussi une forme (rond, carré, losange, cercle vide) et un libellé.
 */

/* Un élément masqué (attribut hidden) reste masqué, quel que soit son affichage ailleurs. */
[hidden] {
  display: none !important;
}

:root {
  color-scheme: light dark;
  --fond: #eceff3;
  --surface: #ffffff;
  --encre: #162031;
  --encre-2: #475467;
  --encre-3: #5d6677;
  --trait: #d5dbe3;
  --trait-fort: #b9c2ce;
  --serie: #2048c7;
  --piste: #e3e8ef;
  --bon: #137a4a;
  --attention: #9b5a00;
  --critique: #b42318;
  --survol: #eef2fa;
  --fond-bon: #e7f4ec;
  --fond-attention: #fdf1df;
  --fond-critique: #fbe9e7;
  --sur-aplat: #ffffff;
  --rayon: 8px;
  --gouttiere: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #0f141a;
    --surface: #171e27;
    --encre: #e6ebf2;
    --encre-2: #b2bccb;
    --encre-3: #8a96a7;
    --trait: #2a3441;
    --trait-fort: #3a4656;
    --serie: #7ea6ff;
    --piste: #26303c;
    --bon: #5fd39a;
    --attention: #f2b55a;
    --critique: #ff8f84;
    --survol: #1f2834;
    --fond-bon: #12271d;
    --fond-attention: #2b2112;
    --fond-critique: #2e1716;
    --sur-aplat: #0f141a;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--fond);
  color: var(--encre);
  font: 14px/1.45 'Segoe UI Variable Text', 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* Largeur : toute la fenêtre, avec une gouttière ; au-delà de 1680 px, centré. */
main,
.bandeau,
.etat-general {
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding-left: var(--gouttiere);
  padding-right: var(--gouttiere);
}

@media (max-width: 700px) {
  :root {
    --gouttiere: 12px;
  }
}

h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

h2 {
  margin: 26px 0 10px;
  font-size: 16px;
  font-weight: 650;
}

h3 {
  margin: 20px 0 6px;
  font-size: 14px;
  font-weight: 650;
}

.discret {
  margin: 4px 0;
  color: var(--encre-3);
  font-size: 12.5px;
}

a {
  color: var(--serie);
}

:focus-visible {
  outline: 2px solid var(--serie);
  outline-offset: 2px;
}

/* --- Boutons ------------------------------------------------------------------------------------------------- */
button {
  font: inherit;
  cursor: pointer;
  padding: 7px 13px;
  border: 1px solid var(--serie);
  border-radius: var(--rayon);
  background: var(--serie);
  color: var(--sur-aplat);
}

.bouton-discret {
  border-color: var(--trait-fort);
  background: var(--surface);
  color: var(--encre-2);
}

.bouton-discret:hover {
  border-color: var(--encre-3);
  color: var(--encre);
}

.lien-bouton {
  padding: 0;
  border: 0;
  background: none;
  color: var(--serie);
  font-size: 12.5px;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

/* --- En-tête : nom, écrans, heure du relevé ---------------------------------------------------------------- */
.bandeau {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 28px;
  padding-top: 18px;
  border-bottom: 1px solid var(--trait);
}

.bandeau .marque {
  padding-bottom: 10px;
}

.bandeau .marque .discret {
  margin: 2px 0 0;
}

.onglets {
  display: flex;
  gap: 2px;
  align-self: flex-end;
}

.onglets a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 12px 10px;
  border-bottom: 3px solid transparent;
  color: var(--encre-2);
  font-weight: 550;
  text-decoration: none;
}

.onglets a:hover {
  color: var(--encre);
}

.onglets a[aria-current='page'] {
  border-bottom-color: var(--serie);
  color: var(--encre);
}

.bandeau .sortie {
  margin-left: auto;
  padding-bottom: 10px;
}

.pastille {
  min-width: 1.5em;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--critique);
  color: var(--sur-aplat);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.6;
  text-align: center;
}

.pastille.attention {
  background: var(--attention);
}

/* --- Bandeau d'état : la première chose à lire ------------------------------------------------------------- */
.etat-general {
  margin-top: 16px;
}

.etat-general > div {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  padding: 12px 16px;
  border: 1px solid var(--trait);
  border-left: 6px solid var(--bon);
  border-radius: var(--rayon);
  background: var(--fond-bon);
}

.etat-general strong {
  font-size: 17px;
  font-weight: 650;
}

.etat-general .detail-etat {
  color: var(--encre-2);
}

.etat-general.attention > div {
  border-left-color: var(--attention);
  background: var(--fond-attention);
}

.etat-general.critique > div {
  border-left-color: var(--critique);
  background: var(--fond-critique);
}

.etat-general a {
  margin-left: auto;
  font-weight: 550;
}

.alerte {
  margin: 12px 0 0;
  padding: 10px 14px;
  border: 1px solid var(--critique);
  border-radius: var(--rayon);
  background: var(--fond-critique);
}

/* --- Tuiles ------------------------------------------------------------------------------------------------ */
.tuiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.tuile {
  padding: 11px 14px 12px;
  border: 1px solid var(--trait);
  border-radius: var(--rayon);
  background: var(--surface);
}

.tuile .libelle {
  color: var(--encre-2);
  font-size: 12.5px;
}

.tuile .valeur {
  margin-top: 1px;
  font-size: 22px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.tuile .precision {
  color: var(--encre-3);
  font-size: 12px;
}

/* --- Serveurs : un bloc par machine ------------------------------------------------------------------------ */
.serveurs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 10px;
}

.carte-serveur {
  padding: 12px 14px 14px;
  border: 1px solid var(--trait);
  border-radius: var(--rayon);
  background: var(--surface);
}

.carte-serveur.indisponible {
  border-style: dashed;
}

.carte-serveur header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--trait);
}

.carte-serveur h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.carte-serveur header span {
  color: var(--encre-3);
  font-size: 12.5px;
}

.carte-serveur dl {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px 16px;
  margin: 0;
}

.carte-serveur .mesure.large {
  grid-column: 1 / -1;
}

.carte-serveur dt {
  color: var(--encre-2);
  font-size: 12px;
}

.carte-serveur dd {
  margin: 1px 0 0;
}

.carte-serveur dd .valeur {
  font-size: 16px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.carte-serveur dd small {
  display: block;
  color: var(--encre-3);
  font-size: 12px;
  line-height: 1.35;
}

.carte-serveur .jauge {
  display: block;
  width: 100%;
  max-width: 180px;
  margin: 4px 0 2px;
}

/* --- Tableaux ---------------------------------------------------------------------------------------------- */
.defilement {
  container-type: inline-size;
  overflow-x: auto;
  border: 1px solid var(--trait);
  border-radius: var(--rayon);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 7px 10px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--trait);
}

thead th {
  background: var(--surface);
  color: var(--encre-3);
  font-size: 12px;
  font-weight: 600;
}

tbody tr:last-child > td,
tbody tr:last-child > th {
  border-bottom: 0;
}

.num {
  text-align: right;
}

.nom {
  font-weight: 600;
}

.nom small {
  margin-left: 6px;
  color: var(--encre-3);
  font-weight: 400;
}

.vide {
  color: var(--encre-3);
}

td.lent {
  color: var(--attention);
  font-weight: 600;
}

.alloue {
  color: var(--encre-3);
  font-size: 12px;
  font-weight: 400;
}

/* Lignes d'application : cliquables, la ligne ouverte porte un trait bleu à gauche */
#apps tbody tr[data-nom] {
  cursor: pointer;
}

#apps tbody tr[data-nom]:hover {
  background: var(--survol);
}

#apps tbody tr[aria-selected='true'] {
  background: var(--survol);
}

#apps tbody tr[aria-selected='true'] > td:first-child {
  box-shadow: inset 3px 0 0 var(--serie);
}

#apps tbody tr.hors-ligne > td {
  color: var(--encre-3);
}

/* En-tête de serveur : une bande qui sépare les groupes */
tr.groupe-serveur > th {
  padding: 14px 10px 7px;
  border-bottom: 1px solid var(--trait-fort);
  background: var(--fond);
  color: var(--encre-3);
  font-size: 12.5px;
  font-weight: 400;
  text-align: left;
}

tbody tr.groupe-serveur:first-child > th {
  padding-top: 10px;
}

tr.groupe-serveur .nom-serveur {
  margin-right: 10px;
  color: var(--encre);
  font-size: 14.5px;
  font-weight: 700;
}

tr.groupe-serveur .renommer {
  margin-left: 10px;
}

/* Détail ouvert sous la ligne de l'application */
#apps tbody tr.ligne-detail > td {
  padding: 0;
  border-bottom: 2px solid var(--serie);
  background: var(--fond);
  white-space: normal;
}

#apps tbody tr.ligne-detail #detail {
  position: sticky;
  left: 0;
  max-width: calc(100vw - 2 * var(--gouttiere) - 2px);
  max-width: 100cqw;
  padding: 14px 16px 18px;
  border-left: 3px solid var(--serie);
}

/* --- États : forme + couleur + libellé ----------------------------------------------------------------------- */
.etat {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--encre-2);
}

.etat::before {
  content: '';
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--encre-3);
}

.etat.actif::before {
  background: var(--bon);
}

.etat.ecoute::before {
  border-radius: 2px;
  background: var(--attention);
}

.etat.arrete::before {
  border-radius: 0;
  background: var(--critique);
  transform: rotate(45deg);
}

.etat.releve::before {
  border: 2px dashed var(--encre-3);
  background: transparent;
}

#apps tbody tr.veille .etat::before {
  border: 2px solid var(--encre-3);
  border-radius: 50%;
  background: transparent;
  transform: none;
}

.alerte-texte {
  color: var(--critique);
  font-weight: 600;
}

/* Jauge de mémoire : la valeur est écrite, la barre l'appuie */
.jauge {
  display: inline-block;
  width: 52px;
  height: 5px;
  margin-left: 8px;
  border-radius: 3px;
  background: var(--piste);
  vertical-align: middle;
  overflow: hidden;
}

.jauge span {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--serie);
}

.jauge.haute span {
  background: var(--attention);
}

.jauge.pleine span {
  background: var(--critique);
}

/* --- Détail d'une application ------------------------------------------------------------------------------ */
.entete-detail {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}

.entete-detail h2 {
  margin: 0;
}

#detail-ressources {
  max-width: 120ch;
  margin-top: 6px;
  line-height: 1.5;
}

.periodes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 4px;
}

.periodes button {
  padding: 5px 11px;
}

.periodes button[aria-pressed='true'] {
  border-color: var(--serie);
  background: var(--survol);
  color: var(--encre);
  font-weight: 600;
}

.graphiques {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.graphique {
  padding: 10px 12px 8px;
  border: 1px solid var(--trait);
  border-radius: var(--rayon);
  background: var(--surface);
}

.graphique .titre {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--encre-2);
  font-size: 12.5px;
}

.graphique .titre strong {
  color: var(--encre);
  font-variant-numeric: tabular-nums;
}

.graphique .zone {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px;
  margin-top: 8px;
}

.graphique .axe {
  position: relative;
  height: 90px;
  min-width: 3.2em;
  color: var(--encre-3);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.graphique .axe span {
  position: absolute;
  right: 0;
  transform: translateY(-50%);
  white-space: nowrap;
}

.graphique svg {
  display: block;
  width: 100%;
  height: 90px;
}

.graphique .grille {
  stroke: var(--trait);
  stroke-width: 1;
  stroke-dasharray: 2 3;
  vector-effect: non-scaling-stroke;
}

.graphique .trace {
  fill: none;
  stroke: var(--serie);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.graphique .base,
.graphique .repere {
  stroke: var(--trait);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.graphique .repere {
  stroke: var(--encre-3);
}

.graphique .bornes {
  display: flex;
  justify-content: space-between;
  color: var(--encre-3);
  font-size: 11.5px;
}

.bulle {
  position: fixed;
  z-index: 10;
  padding: 5px 9px;
  border: 1px solid var(--trait);
  border-radius: 6px;
  background: var(--surface);
  color: var(--encre);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  box-shadow: 0 2px 8px rgb(0 0 0 / 15%);
}

/* Modification des ressources (seulement si elle est installée et admise depuis cette adresse) */
.reglage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 10px 0 14px;
}

.reglage select,
.reglage input {
  font: inherit;
  padding: 6px 9px;
  border: 1px solid var(--trait-fort);
  border-radius: var(--rayon);
  background: var(--surface);
  color: var(--encre);
}

.reglage input {
  width: 8em;
}

.reglage button:disabled {
  opacity: 0.5;
  cursor: default;
}

.reglage .unite {
  color: var(--encre-2);
}

.reglage p {
  flex-basis: 100%;
  margin: 0;
}

/* --- Alertes : les colonnes de texte libre passent à la ligne ------------------------------------------------ */
@media (min-width: 701px) {
  #table-en-cours td:nth-child(3),
  #table-en-cours td:nth-child(4),
  #table-historique td:nth-child(6),
  #table-historique td:nth-child(7) {
    min-width: 16ch;
    white-space: normal;
  }
}

/* --- Statistiques ------------------------------------------------------------------------------------------ */
.lien-csv {
  display: inline-block;
  padding: 5px 11px;
  border: 1px solid var(--trait-fort);
  border-radius: var(--rayon);
  background: var(--surface);
  color: var(--encre-2);
  text-decoration: none;
}

.lien-csv:hover {
  color: var(--encre);
}

#table-stats tbody tr[data-nom] {
  cursor: pointer;
}

#table-stats tbody tr[data-nom]:hover,
#table-stats tbody tr[aria-expanded='true'] {
  background: var(--survol);
}

#table-stats tbody tr.jours-stats > td {
  padding: 0 0 12px 24px;
  background: var(--fond);
}

#table-stats tbody tr.jours-stats table {
  width: auto;
  min-width: 60%;
}

#table-stats tbody tr.jours-stats thead th {
  background: transparent;
}

/* --- Connexion --------------------------------------------------------------------------------------------- */
.page-connexion {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.carte-connexion {
  width: min(360px, calc(100vw - 32px));
  margin: 0;
  padding: 28px;
  border: 1px solid var(--trait);
  border-radius: 12px;
  background: var(--surface);
}

.carte-connexion form {
  display: grid;
  gap: 10px;
  margin: 18px 0 10px;
}

.carte-connexion input {
  font: inherit;
  padding: 9px 11px;
  border: 1px solid var(--trait-fort);
  border-radius: var(--rayon);
  background: var(--fond);
  color: var(--encre);
}

a.bouton {
  display: block;
  margin: 18px 0 10px;
  padding: 9px 14px;
  border: 1px solid var(--serie);
  border-radius: var(--rayon);
  background: var(--serie);
  color: var(--sur-aplat);
  text-align: center;
  text-decoration: none;
}

.carte-connexion .secours {
  margin: 22px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--trait);
  color: var(--encre-2);
  font-size: 0.85rem;
  font-weight: 600;
}

/* Message montré seulement si le script ne s'exécute pas (il le retire dès le premier relevé) */
.indice-chargement {
  visibility: hidden;
  animation: indice-apparait 0s linear 6s forwards;
}

@keyframes indice-apparait {
  to {
    visibility: visible;
  }
}

/* --- Téléphone : en-tête compact, tableaux en fiches ------------------------------------------------------ */
@media (max-width: 700px) {
  body {
    font-size: 14.5px;
  }

  .bandeau {
    gap: 0 12px;
    padding-top: 12px;
  }

  .bandeau .marque {
    flex: 1 1 auto;
    padding-bottom: 6px;
  }

  .bandeau .sortie {
    order: 2;
    padding-bottom: 6px;
  }

  .bandeau .sortie button {
    padding: 5px 10px;
    font-size: 13px;
  }

  .onglets {
    order: 3;
    flex: 1 0 100%;
    overflow-x: auto;
  }

  .onglets a {
    flex: 1 0 auto;
    justify-content: center;
    padding: 9px 8px 10px;
  }

  .onglets a:focus-visible {
    outline-offset: -3px;
  }

  .etat-general > div {
    padding: 10px 12px;
  }

  .etat-general strong {
    font-size: 16px;
  }

  .etat-general a {
    margin-left: 0;
  }

  .tuiles {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .tuile {
    padding: 9px 11px 10px;
  }

  .tuile .valeur {
    font-size: 19px;
  }

  .defilement {
    overflow-x: visible;
  }

  /* Chaque ligne devient une fiche : nom en tête, puis les valeurs deux par deux avec leur titre */
  table.fiches > thead {
    display: none;
  }

  table.fiches,
  table.fiches > tbody {
    display: block;
  }

  table.fiches > tbody > tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 14px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--trait);
  }

  table.fiches > tbody > tr > td {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
    padding: 0;
    border: 0;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  table.fiches > tbody > tr > td[data-libelle]::before {
    content: attr(data-libelle);
    color: var(--encre-3);
    font-size: 11.5px;
  }

  table.fiches > tbody > tr > td:first-child {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: baseline;
    font-size: 15px;
  }

  table.fiches > tbody > tr > td:first-child::before {
    content: none;
  }

  #apps > tbody > tr[data-nom] > td:nth-child(2) {
    grid-column: 1 / -1;
  }

  #apps > tbody > tr[data-nom] > td:nth-child(2)::before {
    content: none;
  }

  #apps > tbody > tr[aria-selected='true'] {
    box-shadow: inset 3px 0 0 var(--serie);
  }

  #apps > tbody > tr[aria-selected='true'] > td:first-child {
    box-shadow: none;
  }

  .jauge {
    width: 100%;
    max-width: 120px;
    margin: 3px 0 0;
  }

  /* En-têtes de serveur, détail et jours dépliés : sur toute la largeur, sans fiche */
  table.fiches > tbody > tr.groupe-serveur,
  table.fiches > tbody > tr.ligne-detail,
  table.fiches > tbody > tr.jours-stats {
    display: block;
    padding: 0;
  }

  table.fiches > tbody > tr.groupe-serveur > th {
    display: block;
    padding: 12px 12px 6px;
    white-space: normal;
  }

  table.fiches > tbody > tr.ligne-detail > td,
  table.fiches > tbody > tr.jours-stats > td {
    display: block;
    padding: 0;
  }

  #apps tbody tr.ligne-detail #detail {
    position: static;
    max-width: none;
    padding: 12px;
  }

  .graphiques {
    grid-template-columns: 1fr;
  }

  #table-stats tbody tr.jours-stats > td {
    padding: 0 0 10px;
    overflow-x: auto;
  }

  .periodes button,
  .lien-csv {
    padding: 6px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
