/* Domotique — mobile d'abord, grandes cibles tactiles, contraste élevé,
   thème clair / sombre automatique. */
:root {
  --fond: #f3efe9;
  --surface: #ffffff;
  --surface-2: #f8f5f0;
  --texte: #1f1b17;
  --texte-2: #5a5249;
  --bord: #d9d1c5;
  --primaire: #2b2622;
  --primaire-texte: #ffffff;
  --focus: #1d4ed8;
  --ok: #14532d;      --ok-fond: #dcfce7;
  --ko: #8f1d1d;      --ko-fond: #fde2e2;
  --att: #713f12;     --att-fond: #fdf0c4;
  --info: #1e3a5f;    --info-fond: #e3edf8;
  --demo: #5b21b6;    --demo-fond: #ede7fb;
  --poele: #c2410c;
  --lumieres: #a16207;
  --portail: #15803d;
  --garage: #1d4ed8;
  --rayon: 18px;
  --ombre: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #151311;
    --surface: #211e1b;
    --surface-2: #2a2622;
    --texte: #f4efe8;
    --texte-2: #bdb4a8;
    --bord: #3d3832;
    --primaire: #f4efe8;
    --primaire-texte: #151311;
    --focus: #93c5fd;
    --ok: #bbf7d0;      --ok-fond: #12301e;
    --ko: #fecaca;      --ko-fond: #3b1414;
    --att: #fde68a;     --att-fond: #352a0c;
    --info: #c7dcf3;    --info-fond: #172636;
    --demo: #ddd0fb;    --demo-fond: #2b1f47;
    --poele: #fb923c;
    --lumieres: #facc15;
    --portail: #4ade80;
    --garage: #93c5fd;
    --ombre: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1 { font-size: 1.75rem; line-height: 1.2; margin: .5rem 0 1rem; }
h2 { font-size: 1.25rem; margin: 1.5rem 0 .75rem; }
.carte h2:first-child, .carte h3:first-child { margin-top: 0; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 6px; }
main:focus { outline: none; }
main { max-width: 960px; margin: 0 auto; padding: 1rem 16px 3rem; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.evitement { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.evitement:focus { left: 8px; top: 8px; }

/* ---------- en-tête et bandeaux ---------- */
.entete {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: calc(.6rem + env(safe-area-inset-top)) 16px .6rem;
  background: var(--surface); border-bottom: 1px solid var(--bord);
  position: sticky; top: 0; z-index: 5;
}
.marque { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.2rem; text-decoration: none; min-height: 44px; }
.marque svg { width: 28px; height: 28px; color: var(--poele); }
.menu { display: flex; gap: .1rem; justify-content: flex-end; min-width: 0; }
.lien-entete { padding: .55rem .6rem; white-space: nowrap; border-radius: 999px; text-decoration: none; color: var(--texte-2); font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; }
.lien-entete:hover { background: var(--surface-2); color: var(--texte); }
.bandeau-demo, .bandeau-reseau { padding: .6rem 16px; text-align: center; font-size: .95rem; }
.bandeau-demo { background: var(--demo-fond); color: var(--demo); }
.bandeau-reseau { background: var(--ko-fond); color: var(--ko); font-weight: 600; }

/* ---------- boutons et formulaires ---------- */
.bouton {
  font: inherit; font-weight: 650; cursor: pointer;
  min-height: 48px; padding: .7rem 1.2rem; border-radius: 14px;
  border: 2px solid var(--primaire); background: var(--surface); color: var(--texte);
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; text-decoration: none;
}
.bouton.primaire { background: var(--primaire); color: var(--primaire-texte); }
.bouton.secondaire { border-color: var(--bord); }
.bouton.danger { background: var(--ko); border-color: var(--ko); color: var(--surface); }
.bouton.grand { min-height: 60px; font-size: 1.15rem; flex: 1 1 0; }
.bouton.petit { min-height: 40px; padding: .35rem .8rem; font-size: .95rem; }
.bouton:disabled { opacity: .55; cursor: not-allowed; }
.boutons { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1rem; }

.formulaire { display: grid; gap: 1rem; }
.champ { display: grid; gap: .35rem; }
.champ label, legend { font-weight: 650; }
input[type=text], input[type=password], input:not([type]), select {
  font: inherit; color: var(--texte); background: var(--surface-2);
  border: 2px solid var(--bord); border-radius: 12px; padding: .7rem .85rem; min-height: 50px; width: 100%;
}
input:focus, select:focus { border-color: var(--focus); }
.aide { color: var(--texte-2); font-size: .92rem; margin: 0; }
.cases { border: 1px solid var(--bord); border-radius: 12px; padding: .5rem .9rem .8rem; margin: 0; }
.case { display: flex; align-items: center; gap: .6rem; min-height: 44px; }
.case input { width: 22px; height: 22px; accent-color: var(--primaire); }

.page-connexion { max-width: 440px; margin: 8vh auto 0; }
.intro { color: var(--texte-2); margin-top: -.5rem; }
.chargement { color: var(--texte-2); }

/* ---------- messages ---------- */
.message { border-radius: 12px; padding: .75rem 1rem; margin: .75rem 0 0; border-left: 5px solid currentColor; }
.message p { margin: .25rem 0; }
.message.ok { background: var(--ok-fond); color: var(--ok); }
.message.ko { background: var(--ko-fond); color: var(--ko); }
.message.attention { background: var(--att-fond); color: var(--att); }
.message.info { background: var(--info-fond); color: var(--info); }
.message.demo { background: var(--demo-fond); color: var(--demo); }
.rouet { display: inline-block; width: 1em; height: 1em; border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; vertical-align: -2px; margin-right: .5rem; animation: tourne .8s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }

/* ---------- cartes ---------- */
.carte { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 1.1rem; box-shadow: var(--ombre); margin-bottom: 1rem; }
.retour { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; text-decoration: none; color: var(--texte-2); }
.retour:hover { color: var(--texte); }

/* ---------- tuiles du tableau de bord ---------- */
.tuiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (min-width: 760px) { .tuiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tuile {
  --c: var(--texte);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: .35rem;
  aspect-ratio: 1 / 1; padding: 1rem .6rem; border-radius: 22px; text-decoration: none;
  background: var(--surface); border: 2px solid var(--bord); box-shadow: var(--ombre);
  transition: transform .12s ease, border-color .12s ease;
}
a.tuile:hover { border-color: var(--c); }
a.tuile:active { transform: scale(.97); }
.tuile-icone { width: 46%; max-width: 110px; color: var(--c); }
.tuile-nom { font-weight: 750; font-size: 1.15rem; line-height: 1.2; }
.tuile-sous { font-size: .9rem; color: var(--texte-2); }
.tuile.inactive { opacity: .6; border-style: dashed; box-shadow: none; }
.tuile.inactive .tuile-icone { color: var(--texte-2); }
.tuile-poele { --c: var(--poele); }
.tuile-lumieres { --c: var(--lumieres); }
.tuile-portail { --c: var(--portail); }
.tuile-garage { --c: var(--garage); }

.icone { display: inline-block; line-height: 0; }
.icone svg { width: 100%; height: auto; }
.icone.petite { width: 34px; }
.titre-rubrique { display: flex; align-items: center; gap: .6rem; }

/* ---------- carte d'équipement ---------- */
.cartes { display: grid; gap: 1rem; }
@media (min-width: 760px) { .cartes { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); } }
.equipement { --c: var(--texte-2); }
.type-poele { --c: var(--poele); }
.type-portail { --c: var(--portail); }
.type-porte-garage { --c: var(--garage); }
.type-lumiere { --c: var(--lumieres); }
.carte-haut { display: flex; gap: 1rem; align-items: center; }
.icone.grande { width: 112px; flex: none; color: var(--c); }
@media (max-width: 360px) { .icone.grande { width: 84px; } }
.carte-infos h2 { margin: 0 0 .25rem; font-size: 1.3rem; }
.ligne-etat { margin: .2rem 0; }
.temperature { font-size: 2.6rem; font-weight: 800; line-height: 1.1; margin: .25rem 0 0; font-variant-numeric: tabular-nums; }
.temperature.absente { color: var(--texte-2); }
.explication { margin: .75rem 0 0; color: var(--texte-2); }
.explication:empty, .detail:empty, .maj:empty, .aide:empty { display: none; }
.detail { margin: .6rem 0 0; font-weight: 600; }
.maj { margin: .5rem 0 0; font-size: .92rem; color: var(--texte-2); }
.maj.ancienne { color: var(--att); font-weight: 600; }
.occupee .boutons .bouton { opacity: .55; }

/* Flamme du poêle : visible seulement allumé ; icône grisée si l'état est incertain. */
.type-poele .flamme { color: transparent; }
.type-poele[data-etat="allume"] .flamme { color: var(--poele); }
.equipement[data-etat="inconnu"] .icone.grande,
.equipement[data-etat="indisponible"] .icone.grande { color: var(--texte-2); opacity: .55; }

.pastille { display: inline-block; padding: .15rem .65rem; border-radius: 999px; font-weight: 700; background: var(--surface-2); border: 1px solid var(--bord); }
.pastille-allume, .pastille-ouvert { background: var(--att-fond); color: var(--att); border-color: transparent; }
.pastille-eteint, .pastille-ferme { background: var(--info-fond); color: var(--info); border-color: transparent; }
.pastille-en-mouvement { background: var(--att-fond); color: var(--att); border-color: transparent; }
.pastille-inconnu, .pastille-indisponible, .pastille-non-remonte { background: var(--ko-fond); color: var(--ko); border-color: transparent; }
.etiquette-demo, .etiquette { display: inline-block; font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: .1rem .5rem; border-radius: 6px; background: var(--demo-fond); color: var(--demo); margin: 0 0 .25rem; }
.etiquette { background: var(--surface-2); color: var(--texte-2); margin-left: .5rem; }

/* ---------- dialogue de confirmation ---------- */
dialog {
  width: min(480px, calc(100vw - 32px)); border: none; border-radius: var(--rayon);
  padding: 1.4rem; background: var(--surface); color: var(--texte); box-shadow: 0 20px 60px rgb(0 0 0 / .35);
}
dialog::backdrop { background: rgb(0 0 0 / .55); }
dialog h2 { margin-top: 0; }
.dialogue-boutons { display: flex; gap: .75rem; margin-top: 1.25rem; flex-wrap: wrap-reverse; }
.dialogue-boutons .bouton { flex: 1 1 140px; min-height: 56px; }

/* ---------- administration ---------- */
.fiche { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; }
.fiche dt { color: var(--texte-2); }
.fiche dd { margin: 0; font-weight: 600; }
.comptes { display: grid; gap: 1rem; }
@media (min-width: 760px) { .comptes { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.compte { display: grid; gap: .75rem; margin: 0; }
.compte h3 { margin: 0; }
.compte small { color: var(--texte-2); font-weight: 500; }
.compte.desactive { opacity: .7; border-style: dashed; }
.liste { list-style: none; padding: 0; margin: 0; }
.liste li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .6rem 0; border-top: 1px solid var(--bord); }
.liste li:first-child { border-top: none; }
.ligne { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.lien-invitation { flex: 1 1 220px; font-size: .9rem; }
.tableau-defilant { overflow-x: auto; border: 1px solid var(--bord); border-radius: 12px; background: var(--surface); }
.journal { border-collapse: collapse; width: 100%; font-size: .9rem; }
.journal th, .journal td { padding: .5rem .7rem; text-align: left; border-bottom: 1px solid var(--bord); white-space: nowrap; }
.journal th { background: var(--surface-2); position: sticky; top: 0; }
.resultat-succes { color: var(--ok); font-weight: 700; }
.resultat-echec, .resultat-refuse { color: var(--ko); font-weight: 700; }
.resultat-non-verifie { color: var(--att); font-weight: 700; }

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