/* =====================================================================
   Veripassure — feuille de style
   ---------------------------------------------------------------------
   1. Couleurs et tailles (variables)
   2. Base de la page
   3. Écran de connexion
   4. Structure de l'application (en-tête, onglets)
   5. Accueil : champ d'état + jauge de seuil
   6. Listes, réglages, formulaires
   7. Administration
   8. Message en bas d'écran
   ===================================================================== */

/* ---------- 1. Couleurs et tailles ---------- */
:root {
  --fond: #F6F5F1;          /* fond clair légèrement chaud */
  --surface: #FFFFFF;       /* cartes et listes */
  --trait: #E3DFD6;         /* séparateurs */
  --texte: #17232A;         /* texte principal */
  --texte-doux: #56626A;    /* texte secondaire (contraste AA sur le fond) */
  --marque: #C1121F;        /* rouge cramoisi du logo Veripassure */
  --marque-fonce: #9B0E19;
  --marque-clair: #FBE3E5;
  --danger: #B3141F;        /* textes d'erreur et actions destructrices */

  /* couleurs d'état de l'alarme */
  --etat-repos: #E8E2D4;      /* désactivée : sable */
  --etat-repos-texte: #2B2A25;
  --etat-arme: #C1121F;       /* activée : rouge de la marque */
  --etat-intrusion: #17191B;  /* intrusion : noir, avec un battement rouge */
  --ambre: #8A5300;           /* capteur hors ligne */
  --ambre-fond: #FBEFD6;
  --vert: #1F6B4A;
  --vert-fond: #E1F0E8;

  --rayon: 14px;
  --ombre: 0 1px 2px rgb(23 35 42 / 6%), 0 6px 18px -8px rgb(23 35 42 / 18%);
  --police: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --hauteur-onglets: 64px;
}

/* ---------- 2. Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.5 var(--police);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--marque-clair); color: var(--marque-fonce); }
input, select, textarea { caret-color: var(--marque); }
:focus-visible { outline: 2.5px solid var(--marque); outline-offset: 2px; border-radius: 6px; }
h1, h2 { margin: 0; text-wrap: balance; }
[hidden] { display: none !important; }
svg { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.visuellement-cache { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
html { scrollbar-color: #C9C3B6 transparent; }

/* Boutons */
.bouton {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border: 1px solid var(--trait); border-radius: 12px;
  background: var(--surface); color: var(--texte);
  font: 600 16px var(--police); cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.bouton:hover { border-color: #CFC9BC; }
.bouton:active { transform: scale(.98); }
.bouton:disabled { opacity: .55; cursor: default; transform: none; }
.bouton-principal { width: 100%; background: var(--marque); border-color: var(--marque); color: #fff; }
.bouton-principal:hover { background: var(--marque-fonce); border-color: var(--marque-fonce); }
.bouton-petit { min-height: 40px; padding: 0 14px; font-size: 14px; }
.bouton-petit svg { width: 18px; height: 18px; }
.bouton-danger { color: var(--danger); }

/* Formulaires */
.formulaire { display: grid; gap: 6px; }
.formulaire label { font-size: 14px; font-weight: 600; margin-top: 8px; }
input, select {
  width: 100%; min-height: 48px; padding: 0 14px;
  border: 1px solid var(--trait); border-radius: 12px;
  background: var(--surface); color: var(--texte); font: 16px var(--police);
}
input:focus, select:focus { border-color: var(--marque); }
.formulaire .bouton-principal { margin-top: 16px; }
.erreur { margin: 8px 0 0; color: var(--danger); font-size: 14px; }
fieldset { margin: 8px 0 0; padding: 10px 14px 12px; border: 1px solid var(--trait); border-radius: 12px; }
legend { padding: 0 6px; font-size: 14px; font-weight: 600; }
.cases { display: grid; gap: 2px; }
.cases label { display: flex; align-items: center; gap: 10px; margin: 0; min-height: 40px; font-weight: 400; font-size: 15px; }
.cases input { width: 20px; min-height: 20px; height: 20px; accent-color: var(--marque); }

/* ---------- 2 bis. Écran de chargement ---------- */
.chargement {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: var(--fond);
  transition: opacity .45s ease, visibility .45s;
}
.chargement.fini { opacity: 0; visibility: hidden; }
.chargement-porte { width: 88px; height: 88px; fill: var(--marque); stroke: none; }
.chargement-porte .porte-cadre { fill: none; stroke: var(--marque); stroke-width: 3; }
/* le battant pivote autour de ses gonds (bord droit) : la porte s'ouvre puis se referme */
.porte-battant { transform-box: view-box; transform-origin: 35px 26px; animation: porte 1.8s cubic-bezier(.65, 0, .35, 1) infinite; }
@keyframes porte { 0%, 100% { transform: scaleX(1.5); } 45%, 60% { transform: scaleX(1); } }
.chargement-mot { height: 30px; width: auto; animation: apparait .6s .15s both cubic-bezier(.16, 1, .3, 1); }
.chargement-barre { width: 140px; height: 3px; border-radius: 99px; background: var(--trait); overflow: hidden; }
.chargement-barre span { display: block; width: 40%; height: 100%; border-radius: inherit; background: var(--marque); animation: barre 1.1s ease-in-out infinite; }
.chargement-texte { margin: 0; min-height: 21px; font-size: 14px; color: var(--texte-doux); }
@keyframes barre { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
@keyframes apparait { from { opacity: 0; transform: translateY(6px); } }

/* ---------- 3. Écran de connexion ---------- */
.connexion {
  min-height: 100dvh; max-width: 420px; margin: 0 auto;
  padding: max(48px, env(safe-area-inset-top)) 24px 32px;
  display: flex; flex-direction: column; justify-content: center; gap: 40px;
}
.connexion-marque { color: var(--marque); }
.connexion-logo { width: 64px; height: 64px; stroke: none; }
.connexion-mot { display: block; height: 40px; width: auto; }
.connexion-marque h1 { margin-top: 16px; line-height: 1; }
.connexion-marque p { margin: 4px 0 0; color: var(--texte-doux); font-size: 17px; }

/* ---------- 4. Structure de l'application ---------- */
.application { max-width: 520px; margin: 0 auto; min-height: 100dvh; padding-bottom: calc(var(--hauteur-onglets) + env(safe-area-inset-bottom) + 24px); }
.entete {
  display: flex; align-items: center; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 20px 14px;
}
.entete-marque { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; letter-spacing: -0.02em; color: var(--marque); }
.entete-logo { width: 28px; height: 28px; stroke: none; }
.entete-mot { display: block; height: 18px; width: auto; }
.nom-systeme, .choix-systeme { margin-left: auto; font-size: 14px; color: var(--texte-doux); max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.choix-systeme select { min-height: 36px; padding: 0 10px; font-size: 14px; border-radius: 10px; }
.vue { padding: 0 20px; }
.titre-vue { font-size: 28px; letter-spacing: -0.03em; margin: 8px 0 20px; }

.onglets {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: rgb(246 245 241 / 92%); backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--trait);
}
.onglets a {
  flex: 1; max-width: 130px; height: var(--hauteur-onglets);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--texte-doux); text-decoration: none; font-size: 12px; font-weight: 600;
}
.onglets a[aria-current="page"] { color: var(--marque); }
.onglets a[aria-current="page"] svg { stroke-width: 2.2; }

/* ---------- 5. Accueil : champ d'état ---------- */
.champ-etat {
  --encre: var(--etat-repos-texte);
  --piste: rgb(43 42 37 / 14%);
  --zone: rgb(3 78 102 / 22%);
  position: relative; overflow: hidden;
  margin: 0 -20px; padding: 28px 24px 26px;
  min-height: 44vh; display: flex; flex-direction: column;
  background: var(--etat-repos); color: var(--encre);
  border-radius: 0 0 28px 28px;
  transition: background-color .5s cubic-bezier(.2, .8, .2, 1);
}
.champ-etat[data-etat="arme"] { background: var(--etat-arme); --encre: #fff; --piste: rgb(255 255 255 / 18%); --zone: rgb(255 255 255 / 34%); }
.champ-etat[data-etat="intrusion"] { background: var(--etat-intrusion); --encre: #fff; --piste: rgb(255 255 255 / 20%); --zone: rgb(255 255 255 / 34%); animation: pulsation 1.6s ease-in-out infinite; }
@keyframes pulsation { 50% { background-color: #4A0A10; } }
.champ-etat[data-etat="hors-ligne"] { background: var(--ambre-fond); --encre: #4A3200; --piste: rgb(74 50 0 / 14%); --zone: rgb(138 83 0 / 24%); }

.etat-icone { width: 44px; height: 44px; stroke-width: 1.6; }
.etat-titre { font-size: clamp(30px, 8.5vw, 38px); line-height: 1.1; letter-spacing: -0.035em; margin-top: 18px; }
.etat-phrase { margin: 8px 0 0; font-size: 16px; opacity: .88; max-width: 34ch; }

/* Animations quand l'état change (la classe « change » est ajoutée par affichage.js) */
.champ-etat.change .etat-icone { animation: rebond .55s cubic-bezier(.16, 1, .3, 1); }
.champ-etat.change .etat-titre { animation: glisse .5s cubic-bezier(.16, 1, .3, 1) both; }
.champ-etat.change .etat-phrase { animation: glisse .5s .06s cubic-bezier(.16, 1, .3, 1) both; }
.champ-etat[data-etat="intrusion"].change .etat-icone { animation: secousse .6s cubic-bezier(.36, .07, .19, .97); }
@keyframes rebond { from { transform: scale(.4) rotate(-14deg); opacity: 0; } }
@keyframes glisse { from { transform: translateY(12px); opacity: 0; } }
@keyframes secousse { 15%, 55% { transform: translateX(-6px) rotate(-8deg); } 35%, 75% { transform: translateX(6px) rotate(8deg); } }

/* Signature : la jauge de seuil */
.zone-jauge { margin-top: auto; }
.jauge { margin-top: auto; padding-top: 28px; }
.jauge-entete { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 14px; }
.jauge-distance { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.jauge-piste { position: relative; height: 10px; margin: 12px 0 8px; border-radius: 99px; background: var(--piste); }
.jauge-zone { position: absolute; top: 0; bottom: 0; border-radius: 99px; background: var(--zone); }
.jauge-curseur {
  position: absolute; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border-radius: 50%; background: var(--encre); border: 4px solid var(--etat-repos);
  box-shadow: 0 2px 6px rgb(0 0 0 / 25%);
  transition: left .6s cubic-bezier(.16, 1, .3, 1), background-color .3s;
}
.champ-etat[data-etat="arme"] .jauge-curseur { border-color: var(--etat-arme); }
.champ-etat[data-etat="intrusion"] .jauge-curseur { border-color: var(--etat-intrusion); }
.jauge[data-hors-zone="oui"] .jauge-curseur { background: #F2B8B5; }
.champ-etat[data-etat="repos"] .jauge[data-hors-zone="oui"] .jauge-curseur { background: var(--danger); }
.jauge-legende { display: flex; justify-content: space-between; font-size: 13px; opacity: .8; }
.jauge-absente { margin-top: auto; padding-top: 28px; font-size: 14px; opacity: .85; display: flex; gap: 8px; align-items: center; }
.jauge-absente svg { width: 20px; height: 20px; }

.action-principale { margin: 20px 0 0; }
.action-principale .bouton { width: 100%; min-height: 58px; font-size: 17px; border-radius: 16px; }
.bouton-desarmer { background: var(--surface); color: var(--texte); border: 1.5px solid var(--texte); }
.bouton-couper { background: var(--etat-intrusion); border-color: var(--etat-intrusion); color: #fff; }
/* Bouton en attente de la réponse du serveur */
.rond-chargement { width: 18px; height: 18px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: tourne .7s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }

.infos { margin: 20px 0 0; padding: 0; list-style: none; background: var(--surface); border-radius: var(--rayon); box-shadow: var(--ombre); }
.infos li { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-top: 1px solid var(--trait); }
.infos li:first-child { border-top: 0; }
.infos svg { color: var(--marque); }
.infos .libelle { color: var(--texte-doux); font-size: 14px; }
.infos .valeur { margin-left: auto; font-weight: 600; text-align: right; }
.pastille { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; }
.pastille-ok { background: var(--vert-fond); color: var(--vert); }
.pastille-ko { background: var(--ambre-fond); color: var(--ambre); }
.pastille-alerte { background: var(--marque-clair); color: var(--danger); }
.pastille-neutre { background: var(--etat-repos); color: var(--etat-repos-texte); }

.vide { padding: 40px 20px; text-align: center; color: var(--texte-doux); }

/* ---------- 6. Listes, réglages ---------- */
.groupe { margin-bottom: 28px; }
.titre-groupe { font-size: 15px; font-weight: 700; color: var(--texte-doux); margin: 0 4px 10px; }
.titre-groupe-ligne { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.titre-groupe-ligne .titre-groupe { margin-bottom: 0; }
.groupe > .ligne, .groupe > .depliant, .groupe > .ligne-bouton { background: var(--surface); border-top: 1px solid var(--trait); }
.groupe > :is(.ligne, .depliant, .ligne-bouton):nth-child(2) { border-top: 0; border-radius: var(--rayon) var(--rayon) 0 0; }
.groupe > :is(.ligne, .depliant, .ligne-bouton):last-child { border-radius: 0 0 var(--rayon) var(--rayon); }
.groupe > :is(.ligne, .depliant, .ligne-bouton):nth-child(2):last-child { border-radius: var(--rayon); }
.groupe { filter: drop-shadow(0 4px 10px rgb(23 35 42 / 5%)); }
.ligne { display: flex; align-items: center; gap: 14px; min-height: 60px; padding: 10px 16px; }
.ligne-icone { color: var(--marque); }
.ligne-decalee { padding-left: 54px; } /* aligne le texte sur les lignes qui ont une icône */
.ligne-texte { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.ligne-texte small { color: var(--texte-doux); font-size: 13px; }
.ligne-bouton { width: 100%; border: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.ligne-bouton:hover, summary.ligne:hover { background: #FBFAF7; }
.depliant summary { list-style: none; cursor: pointer; }
.depliant summary::-webkit-details-marker { display: none; }
.formulaire-encart { padding: 4px 16px 18px; }
.mention { font-size: 13px; color: var(--texte-doux); padding: 0 4px; }

/* Interrupteur (notifications) */
.interrupteur {
  position: relative; width: 52px; height: 32px; flex: none;
  border: 0; border-radius: 99px; background: #CFC9BC; cursor: pointer;
  transition: background .2s;
}
.interrupteur::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 25%);
  transition: transform .25s cubic-bezier(.2, .8, .2, 1);
}
.interrupteur[aria-checked="true"] { background: var(--marque); }
.interrupteur[aria-checked="true"]::after { transform: translateX(20px); }
.interrupteur:disabled { opacity: .5; cursor: default; }

/* Historique */
.jour { margin-bottom: 22px; }
.jour h2 { font-size: 14px; font-weight: 700; color: var(--texte-doux); margin: 0 4px 8px; }
.evenements { margin: 0; padding: 0; list-style: none; background: var(--surface); border-radius: var(--rayon); box-shadow: var(--ombre); }
.evenements li { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-top: 1px solid var(--trait); }
.evenements li:first-child { border-top: 0; }
.evenements svg { width: 20px; height: 20px; color: var(--texte-doux); }
.evenements .ev-alerte { color: var(--danger); font-weight: 600; }
.evenements .ev-alerte svg { color: var(--danger); }
.evenements .ev-activation svg { color: var(--marque); }
.evenements .ev-capteur svg { color: var(--ambre); }
.evenements time { margin-left: auto; color: var(--texte-doux); font-size: 14px; }

/* ---------- 7. Administration ---------- */
.liste { margin: 0; padding: 0; list-style: none; background: var(--surface); border-radius: var(--rayon); box-shadow: var(--ombre); }
.liste > li { padding: 14px 16px; border-top: 1px solid var(--trait); }
.liste > li:first-child { border-top: 0; }
.element { display: flex; align-items: center; gap: 12px; }
.element-texte { flex: 1; min-width: 0; }
.element-texte strong { display: block; }
.element-texte small { color: var(--texte-doux); font-size: 13px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.boutons-ligne { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.liste .boutons-ligne .bouton-petit { padding: 0 11px; font-size: 13px; }
.liste .boutons-ligne .bouton-danger { margin-left: auto; }
.role { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--etat-repos); color: var(--etat-repos-texte); margin-left: 6px; vertical-align: 2px; }
.role-admin { background: var(--marque-clair); color: var(--marque-fonce); }
.formulaire-encart:not(.depliant .formulaire-encart) { background: var(--surface); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 8px 16px 18px; margin-bottom: 12px; }
.encart-jeton { margin-bottom: 12px; padding: 16px; border-radius: var(--rayon); background: var(--ambre-fond); color: #4A3200; }
.encart-jeton code { display: block; margin: 10px 0; padding: 10px 12px; border-radius: 10px; background: #fff; color: var(--texte); word-break: break-all; font-size: 14px; }
.encart-jeton p { margin: 0; font-size: 14px; }
.encart-jeton p code { display: inline; padding: 1px 5px; margin: 0; }

/* ---------- 8. Message en bas d'écran ---------- */
.message {
  position: fixed; left: 50%; z-index: 20;
  bottom: calc(var(--hauteur-onglets) + env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%);
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 18px; border-radius: 12px;
  background: var(--texte); color: #fff; font-size: 15px;
  box-shadow: 0 8px 24px -6px rgb(0 0 0 / 35%);
  animation: apparition .3s cubic-bezier(.16, 1, .3, 1);
}
@keyframes apparition { from { opacity: 0; transform: translate(-50%, 8px); } }

/* Grand écran (démo projetée) : on centre l'application */
@media (min-width: 760px) {
  .application { max-width: 640px; }
  .champ-etat { margin: 0; border-radius: 28px; min-height: 420px; padding: 40px 40px 36px; }
  .etat-icone { width: 56px; height: 56px; }
  .etat-titre { font-size: 52px; }
  .etat-phrase { font-size: 19px; }
  .jauge-distance { font-size: 30px; }
  .onglets { left: 50%; right: auto; transform: translateX(-50%); width: 520px; bottom: 16px; border: 1px solid var(--trait); border-radius: 20px; box-shadow: var(--ombre); }
  .application { padding-bottom: calc(var(--hauteur-onglets) + 48px); }
  .message { bottom: calc(var(--hauteur-onglets) + 32px); }
}

/* Respect du réglage « réduire les animations » */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
