:root {
  --fond: #f4f6f8;
  --surface: #ffffff;
  --texte: #1c2430;
  --texte-2: #5b6776;
  --bord: #dde3ea;
  --grille: #e8edf2;
  --accent: #1f5f99;
  --accent-texte: #ffffff;
  --serie: #1f6fb5;
  --serie-fond: rgba(31, 111, 181, 0.15);
  --ok: #2e8b57;
  --ok-fond: rgba(46, 139, 87, 0.08);
  --attention: #c27c0e;
  --attention-fond: #fff6e5;
  --alerte: #c62f2f;
  --alerte-fond: #fdecec;
  --neutre: #8a96a3;
  --rayon: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #11161c;
    --surface: #1a2129;
    --texte: #e6ebf0;
    --texte-2: #9aa7b4;
    --bord: #2b3440;
    --grille: #25303b;
    --accent: #4d95d6;
    --accent-texte: #0d1620;
    --serie: #5aa5e8;
    --serie-fond: rgba(90, 165, 232, 0.18);
    --ok: #4cbf7e;
    --ok-fond: rgba(76, 191, 126, 0.10);
    --attention: #e0a33c;
    --attention-fond: #33290f;
    --alerte: #ee6b6b;
    --alerte-fond: #3a1c1c;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--fond); color: var(--texte);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1.05rem; margin: 0; }
code { font-size: .9em; }
.discret { color: var(--texte-2); font-weight: normal; }
.petit { font-size: .85em; }
.rouge { color: var(--alerte); font-weight: 600; }

/* barre de navigation */
.barre {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--bord);
}
.marque { font-weight: 700; color: var(--texte); font-size: 1.05rem; }
.flocon { color: var(--accent); }
.barre nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.barre nav a { padding: .4rem .7rem; border-radius: 6px; color: var(--texte-2); }
.barre nav a.actif, .barre nav a:hover { background: var(--fond); color: var(--texte); text-decoration: none; }
.compte { display: flex; gap: .75rem; align-items: center; }
.compte form { margin: 0; }

main { max-width: 1200px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
main.centre { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; }
.entete { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }

.carte {
  background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon);
  padding: 1rem 1.1rem; margin-bottom: 1rem;
}
.carte.vide { text-align: center; padding: 2rem; }
.attention-bord { border-left: 4px solid var(--attention); }

/* boutons et formulaires */
button, .bouton {
  display: inline-block; font: inherit; cursor: pointer; padding: .5rem .9rem; border-radius: 7px;
  border: 1px solid var(--bord); background: var(--surface); color: var(--texte); text-decoration: none; line-height: 1.2;
}
button:hover, .bouton:hover { border-color: var(--texte-2); text-decoration: none; }
.principal { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); font-weight: 600; }
.principal:hover { filter: brightness(1.08); border-color: var(--accent); }
.danger { color: var(--alerte); border-color: var(--alerte); }
button.lien { border: 0; background: none; color: var(--accent); padding: 0; }
.bouton.petit, button.petit { padding: .3rem .6rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; margin-bottom: .9rem; }
label.case { flex-direction: row; align-items: center; gap: .5rem; }
input, select, textarea {
  font: inherit; font-weight: normal; padding: .5rem .6rem; border-radius: 7px;
  border: 1px solid var(--bord); background: var(--surface); color: var(--texte); width: 100%;
}
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
small { font-weight: normal; }
.formulaire { max-width: 640px; }
fieldset.ligne { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
fieldset.ligne legend { font-weight: 600; margin-bottom: .3rem; }
fieldset.ligne label { margin-bottom: .3rem; font-weight: normal; }
.boutons { display: flex; gap: .6rem; margin-top: .5rem; }
form.enligne { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: 0 0 .6rem; }
form.enligne input, form.enligne select { width: auto; }
.connexion { width: 100%; max-width: 380px; }
.connexion h1 { margin-bottom: .25rem; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: var(--ok-fond); border-color: var(--ok); }
.flash.erreur { background: var(--alerte-fond); border-color: var(--alerte); }

/* tableau de bord */
h2.groupe { margin: 1.25rem 0 .6rem; color: var(--texte-2); font-size: 1rem; text-transform: uppercase; letter-spacing: .04em; }
.grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.chambre { border-top: 4px solid var(--neutre); margin: 0; display: flex; flex-direction: column; }
.chambre.etat-ok { border-top-color: var(--ok); }
.chambre.etat-attention { border-top-color: var(--attention); }
.chambre.etat-alerte { border-top-color: var(--alerte); background: var(--alerte-fond); }
.chambre-haut { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.chambre-haut a { color: var(--texte); }
.pastille { font-size: .8rem; white-space: nowrap; padding: .15rem .5rem; border-radius: 99px; background: var(--fond); color: var(--texte-2); border: 1px solid var(--bord); }
.temp { font-size: 2.3rem; font-weight: 700; margin: .4rem 0 .1rem; font-variant-numeric: tabular-nums; }
.etat { display: flex; align-items: center; gap: .45rem; font-weight: 600; }
.point { width: .6rem; height: .6rem; border-radius: 50%; background: var(--neutre); flex: none; }
.etat-ok .point { background: var(--ok); }
.etat-attention .point { background: var(--attention); }
.etat-alerte .point { background: var(--alerte); }
.etat-alerte .etat { color: var(--alerte); }
.etat-attention .etat { color: var(--attention); }
.details { margin: .8rem 0; display: grid; gap: .2rem; }
.details div { display: flex; justify-content: space-between; gap: 1rem; }
.details dt { color: var(--texte-2); }
.details dd { margin: 0; }
.actions { margin-top: auto; display: flex; gap: 1rem; padding-top: .6rem; border-top: 1px solid var(--bord); }

/* historique */
.filtres { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0 1rem; align-items: end; }
.filtres label { margin-bottom: .6rem; }
.raccourcis { grid-column: 1 / -1; display: flex; gap: .5rem; flex-wrap: wrap; }
.resume { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; }
.chiffre { display: flex; flex-direction: column; gap: .2rem; }
.chiffre span { color: var(--texte-2); font-size: .85rem; }
.chiffre strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.entete-graph { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.graph-conteneur { position: relative; height: 360px; }
.deux-colonnes { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.deux-colonnes .carte { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--bord); vertical-align: middle; }
th { color: var(--texte-2); font-weight: 600; font-size: .85rem; }
tr.en-cours td { color: var(--alerte); font-weight: 600; }
tr.hors td { background: var(--alerte-fond); }
tr.inactif td { color: var(--texte-2); }
.defile { overflow-x: auto; }
table.capteurs td.num { font-weight: 700; width: 3rem; }
table.capteurs form.enligne { margin: 0; flex-wrap: nowrap; }
input.deveui { font-family: ui-monospace, Consolas, monospace; width: 12.5rem; }
input.note { width: 7rem; }

@media (max-width: 760px) {
  .barre { gap: .6rem; padding: .6rem 16px; }
  .barre nav { order: 3; flex-basis: 100%; }
  .filtres { grid-template-columns: 1fr 1fr; }
  .filtres label:first-child { grid-column: 1 / -1; }
  .deux-colonnes { grid-template-columns: 1fr; }
  .graph-conteneur { height: 280px; }
  fieldset.ligne { grid-template-columns: 1fr 1fr; }
}

/* éviter les débordements dans les grilles (mobile) */
.filtres > *, .resume > *, .deux-colonnes > *, .grille > * { min-width: 0; }
select, input { max-width: 100%; min-width: 0; }
td { white-space: nowrap; }
td:first-child { white-space: normal; }
@media (max-width: 760px) {
  .raccourcis button { flex: 1; }
}

.boutons-graph { display: flex; gap: .5rem; flex-wrap: wrap; }

/* mini-graphe 4 jours et dernière alerte (tableau de bord) */
.graphe { display: block; margin: .7rem 0 .1rem; border-radius: 6px; }
.graphe:hover { text-decoration: none; background: var(--fond); }
.spark { display: block; width: 100%; height: auto; overflow: visible; }
.spark-plage { fill: var(--ok-fond); }
.spark-seuil { stroke: var(--ok); stroke-width: 1; stroke-dasharray: 4 3; }
.spark-jour { stroke: var(--grille); stroke-width: 1; }
.spark-ligne { fill: none; stroke: var(--serie); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.spark-point { fill: var(--serie); }
.spark-hors { fill: var(--alerte); }
.spark-txt { fill: var(--texte-2); font-size: 9px; font-family: inherit; }
.spark-vide { fill: var(--texte-2); font-size: 11px; font-family: inherit; }
.minmax { margin-bottom: .2rem; }
.derniere-alerte { display: flex; flex-direction: column; gap: .1rem; padding: .5rem .6rem; margin-bottom: .6rem; border-radius: 7px; background: var(--fond); font-size: .9rem; }
.derniere-alerte .libelle { color: var(--texte-2); font-size: .8rem; }
.derniere-alerte.en-cours { background: var(--alerte-fond); color: var(--alerte); }
.derniere-alerte.en-cours .libelle { color: var(--alerte); }
.note-conservation { grid-column: 1 / -1; margin: .6rem 0 0; }

/* qualité radio (page Capteurs) */
.sig { display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; }
.sig .pt { width: .6rem; height: .6rem; border-radius: 50%; background: var(--neutre); flex: none; }
.sig-vert .pt { background: var(--ok); }
.sig-orange .pt { background: var(--attention); }
.sig-rouge .pt { background: var(--alerte); }
td.signal .sig-orange { color: var(--attention); font-weight: 600; }
td.signal .sig-rouge { color: var(--alerte); font-weight: 600; }
.bilan-signal { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center; margin: .2rem 0 .6rem; }
.bilan-signal a { padding: .15rem .5rem; border-radius: 99px; border: 1px solid transparent; }
.bilan-signal a.actif { border-color: var(--bord); background: var(--fond); text-decoration: none; }
.legende-signal { margin-bottom: .8rem; }
.legende-signal summary { cursor: pointer; }
.legende-signal ul { margin: .3rem 0; padding-left: 1.2rem; }
.sig-detail { display: block; white-space: nowrap; margin-top: .1rem; }
table.capteurs form.enligne input.deveui { width: 11.5rem; }
table.capteurs form.enligne input.note { width: 6.5rem; }
