:root {
  --fond: #f1f0fa;
  --carte: #ffffff;
  --trait: #e6e4f0;
  --texte: #1d1b2e;
  --discret: #75728a;
  --accent: #6e4ae8;          /* boutons pleins, texte blanc dessus */
  --accent-trait: #6e4ae8;    /* courbes, jauges */
  --accent-doux: #ece7fd;     /* fonds d'icônes, puces */
  --sur-accent: #ffffff;
  --nav: #1d1b2e;
  --nav-icone: #a9a6bd;
  --vert: #2f8a5b;
  --rouge: #c2473b;
  --grille: #ecebf3;
  --rayon: 22px;
  --ombre: 0 1px 2px #1d1b2e0a, 0 8px 24px #1d1b2e0d;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #121119;
    --carte: #1c1b26;
    --trait: #2b2938;
    --texte: #eeedf5;
    --discret: #9a97ad;
    --accent: #7c5cf0;
    --accent-trait: #9476f8;
    --accent-doux: #2a2540;
    --nav: #2a2838;
    --nav-icone: #8f8ca3;
    --vert: #5cc08a;
    --rouge: #e8786c;
    --grille: #262533;
    --ombre: none;
  }
}

/* Sans cette règle, display: grid/flex l'emporte sur l'attribut hidden. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0 auto;
  max-width: 720px;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           calc(110px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--fond);
  color: var(--texte);
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:focus:not(:focus-visible) { outline: none; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 17px; font-weight: 650; }

svg.trait { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.plein { fill: currentColor; }
.ic { display: inline-flex; width: 22px; height: 22px; flex: none; }
.ic svg { width: 100%; height: 100%; }

.carte {
  background: var(--carte);
  border-radius: var(--rayon);
  padding: 20px;
  box-shadow: var(--ombre);
}
.vue { display: grid; gap: 14px; }
.etat { margin: 4px 0 0; font-size: 14px; color: var(--discret); }
.vide { color: var(--discret); text-align: center; padding: 24px; margin: 0; }
.note { margin: 0; padding: 0 8px; font-size: 13px; color: var(--discret); }

/* --- Boutons -------------------------------------------------------------- */
.principal, .secondaire {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 14px; font-weight: 600;
}
.principal { border: 0; background: var(--accent); color: var(--sur-accent); }
.secondaire { border: 0; background: var(--accent-doux); color: var(--texte); }
.large { width: 100%; min-height: 52px; border-radius: 16px; }
.danger { color: var(--rouge) !important; }
.rangee { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.espace { flex: 1; }

/* --- En-têtes ------------------------------------------------------------- */
.accueil-entete { display: flex; align-items: center; gap: 12px; margin: 4px 0 6px; }
.avatar {
  display: grid; place-items: center; width: 46px; height: 46px; flex: none;
  border-radius: 50%; background: var(--accent); color: var(--sur-accent); font-weight: 700; font-size: 18px;
}
.avatar.petit { width: 36px; height: 36px; font-size: 15px; }
.salut { flex: 1; min-width: 0; }
.salut h1 { font-size: 20px; font-weight: 700; }
.salut p { margin: 2px 0 0; font-size: 14px; color: var(--discret); }
.liaison {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px;
  border-radius: 999px; background: var(--carte); font-size: 13px; color: var(--discret); box-shadow: var(--ombre);
}
.point { width: 8px; height: 8px; border-radius: 50%; background: var(--discret); }
.liaison.online .point { background: var(--vert); }
.liaison.offline .point { background: var(--rouge); }
.page-entete { margin: 4px 0 6px; }
.page-entete h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.page-entete p { margin: 4px 0 0; color: var(--discret); font-size: 14px; }
.titre-section { margin-top: 6px; }

/* --- Carte climat (accueil) ----------------------------------------------- */
.climat {
  display: grid; gap: 14px; width: 100%; text-align: left;
  padding: 20px; border: 0; border-radius: var(--rayon);
  background: linear-gradient(135deg, #7b57f0, #5a36d6); color: #fff;
}
.climat-titre { display: flex; align-items: center; gap: 8px; font-weight: 600; opacity: .92; }
.climat-valeurs { display: flex; align-items: center; gap: 20px; }
.climat-valeurs strong { display: block; font-size: 40px; font-weight: 700; line-height: 1.05; letter-spacing: -0.02em; }
.climat-valeurs span { font-size: 13px; opacity: .8; }
.separateur { width: 1px; align-self: stretch; background: #ffffff40; }
.climat-pied { margin: 0; font-size: 13px; opacity: .75; }

/* --- Puces de pièces et scènes --------------------------------------------- */
.puces { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; }
.puces::-webkit-scrollbar { display: none; }
.puces button {
  flex: none; padding: 9px 16px; border-radius: 999px; border: 1px solid var(--trait);
  background: var(--carte); color: var(--discret); font-size: 14px; white-space: nowrap;
}
.puces button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--sur-accent); font-weight: 600; }
.scenes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.scene {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px;
  border: 0; border-radius: 16px; background: var(--carte); font-weight: 600; box-shadow: var(--ombre);
}
.scene .ic { color: var(--accent-trait); }
.scene.envoye { background: var(--accent); color: var(--sur-accent); }
.scene.envoye .ic { color: inherit; }

/* --- Tuiles d'appareils ------------------------------------------------------ */
.tuiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tuile {
  display: grid; gap: 2px; align-content: start; text-align: left;
  padding: 16px; border: 0; border-radius: var(--rayon); background: var(--carte);
  box-shadow: var(--ombre); cursor: pointer; color: inherit;
}
.tuile-haut { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.tuile-dessin svg, .tuile-icone { width: 52px; height: 52px; }
.tuile-icone { display: grid; place-items: center; border-radius: 16px; background: var(--accent-doux); color: var(--accent-trait); }
.tuile-icone .ic { width: 26px; height: 26px; }
.pastille-etat {
  padding: 4px 10px; border-radius: 999px; background: var(--accent-doux);
  font-size: 12px; font-weight: 600; color: var(--texte); text-transform: capitalize;
}
.tuile h3 { font-size: 16px; font-weight: 650; }
.tuile p { margin: 0; font-size: 13px; color: var(--discret); }
.mini-commandes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
.mini-commandes button {
  display: grid; place-items: center; height: 38px; border: 0; border-radius: 12px; background: var(--accent-doux);
  transition: transform .08s;
}
.mini-commandes button:active { transform: scale(.94); }
.mini-commandes .ic { width: 20px; height: 20px; }
.mini-commandes button.envoye, .grand-bouton.envoye { background: var(--accent); color: var(--sur-accent); }
.tuile-mesures { display: flex; align-items: baseline; gap: 10px; margin-top: 12px; }
.tuile-mesures strong { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.tuile-mesures span { display: inline-flex; align-items: center; gap: 2px; font-size: 14px; color: var(--discret); }
.tuile-mesures .ic { width: 16px; height: 16px; }
.tuile.ajout {
  place-items: center; align-content: center; gap: 10px; min-height: 180px;
  background: transparent; box-shadow: none; border: 2px dashed var(--trait); color: var(--discret); font-weight: 600;
}
.rond { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--accent-doux); color: var(--accent-trait); }

/* Illustration de volet */
.illustration, .illustration-grande { display: block; }
.illustration .encre, .illustration-grande .encre { fill: var(--texte); }
.illustration .cadre, .illustration-grande .cadre { fill: none; stroke: var(--texte); stroke-width: 2; }
.illustration-grande { width: 140px; height: 140px; margin: 0 auto; }

/* --- Détail ------------------------------------------------------------------ */
.detail-entete { display: flex; align-items: center; gap: 14px; margin: 4px 0 4px; }
.detail-entete h1 { font-size: 22px; font-weight: 700; }
.detail-entete p { margin: 2px 0 0; color: var(--discret); font-size: 14px; }
.rond-retour {
  display: grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 50%; background: var(--carte); box-shadow: var(--ombre);
}
.scene-volet { display: grid; gap: 12px; text-align: center; padding: 28px 20px; }
.etat-grand { margin: 0; font-weight: 600; }
.grands-boutons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grand-bouton {
  display: grid; justify-items: center; gap: 6px; padding: 16px 0;
  border: 0; border-radius: 18px; background: var(--carte); box-shadow: var(--ombre); font-weight: 600;
}
.grand-bouton .ic { width: 28px; height: 28px; color: var(--accent-trait); }
.grand-bouton.envoye .ic { color: inherit; }
.liste-simple { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }
.liste-simple li { display: flex; gap: 12px; align-items: baseline; }
.liste-simple li.inactif { opacity: .45; }
.liste-simple strong { font-variant-numeric: tabular-nums; }
.liste-simple span { color: var(--discret); font-size: 14px; }

.carte-jauge { display: grid; justify-items: center; gap: 6px; padding-bottom: 18px; }
.jauge { position: relative; width: min(260px, 100%); }
.jauge svg { display: block; width: 100%; }
.jauge-piste, .jauge-valeur { fill: none; stroke-width: 14; stroke-linecap: round; }
.jauge-piste { stroke: var(--accent-doux); }
.jauge-valeur { stroke: var(--accent-trait); }
.jauge-curseur { fill: var(--carte); stroke: var(--accent-trait); stroke-width: 4; }
.jauge-borne { font-size: 12px; fill: var(--discret); }
.jauge-centre { position: absolute; inset: 34% 0 auto; display: grid; justify-items: center; }
.jauge-centre strong { font-size: 44px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.jauge-centre span { font-size: 13px; color: var(--discret); margin-top: 4px; }
.humidite-ligne { display: flex; align-items: center; gap: 6px; margin-top: -8px; }
.humidite-ligne .ic { color: var(--accent-trait); width: 20px; height: 20px; }
.humidite-ligne strong { font-size: 18px; }
.humidite-ligne span { color: var(--discret); font-size: 14px; }

.segments { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--carte); box-shadow: var(--ombre); }
.segments button, .segments label span {
  display: block; padding: 9px 0; border: 0; border-radius: 10px; background: none; color: var(--discret);
  text-align: center; font-size: 14px; font-weight: 600; cursor: pointer;
}
.segments button[aria-selected="true"], .segments input:checked + span { background: var(--accent); color: var(--sur-accent); }
.segments input { position: absolute; opacity: 0; pointer-events: none; }
dialog .segments { background: var(--fond); box-shadow: none; }

/* --- Graphiques --------------------------------------------------------------- */
.graphique { position: relative; margin-top: 12px; min-height: 168px; touch-action: pan-y; }
.graphique svg { display: block; overflow: visible; }
.graphique .grille { stroke: var(--grille); stroke-width: 1; }
.graphique .axe { font-size: 11px; fill: var(--discret); font-variant-numeric: tabular-nums; }
.graphique .ligne { fill: none; stroke: var(--accent-trait); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.graphique .aire { fill: var(--accent-trait); opacity: .1; }
.graphique .point-fin { fill: var(--accent-trait); stroke: var(--carte); stroke-width: 2; }
.graphique .valeur-fin { font-size: 12px; font-weight: 600; fill: var(--texte); }
.graphique .curseur { stroke: var(--discret); stroke-width: 1; }
.infobulle {
  position: absolute; top: -6px; z-index: 2; display: grid; padding: 6px 10px; border-radius: 10px; pointer-events: none;
  background: var(--texte); color: var(--carte); font-size: 12px; white-space: nowrap; transform: translateY(-100%);
}
.infobulle strong { font-size: 14px; }
.resume { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 0; }
.resume div { padding: 10px; border-radius: 12px; background: var(--fond); text-align: center; }
.resume dt { font-size: 12px; color: var(--discret); }
.resume dd { margin: 2px 0 0; font-weight: 650; font-variant-numeric: tabular-nums; }

/* --- Programmes --------------------------------------------------------------- */
.programme { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; cursor: pointer; padding: 16px; }
.programme-icone { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px; background: var(--accent-doux); color: var(--accent-trait); }
.programme h3 { font-size: 16px; font-weight: 650; }
.programme-droite { display: grid; justify-items: end; gap: 8px; }
.programme .heure { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.programme.inactif .infos, .programme.inactif .heure, .programme.inactif .programme-icone { opacity: .45; }
.suggestions { display: grid; gap: 8px; }
.suggestion {
  display: flex; gap: 10px; text-align: left; padding: 13px 14px; border-radius: 14px;
  border: 1px dashed var(--trait); background: var(--fond);
}

.interrupteur { position: relative; width: 48px; height: 28px; flex: none; display: block; }
.interrupteur input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.interrupteur span { position: absolute; inset: 0; border-radius: 14px; background: var(--trait); transition: background .15s; }
.interrupteur span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px #0003; transition: transform .15s;
}
.interrupteur input:checked + span { background: var(--accent); }
.interrupteur input:checked + span::after { transform: translateX(20px); }

/* --- Formulaires et dialogues ------------------------------------------------- */
dialog {
  width: min(480px, calc(100vw - 24px));
  border: 0; border-radius: var(--rayon); padding: 22px; background: var(--carte); color: var(--texte);
}
dialog::backdrop { background: #0d0b1a80; }
.editeur { display: grid; gap: 14px; }
.editeur label, .connexion label { display: grid; gap: 6px; font-size: 14px; color: var(--discret); }
.deux-champs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input:not([type=checkbox]):not([type=radio]), select {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1px solid transparent; border-radius: 14px; background: var(--fond); color: var(--texte);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-size: 14px; color: var(--discret); margin-bottom: 6px; padding: 0; }
.jours { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.puce { position: relative; }
.puce input { position: absolute; opacity: 0; }
.puce span {
  display: grid; place-items: center; height: 42px; border-radius: 12px;
  background: var(--fond); color: var(--texte); font-weight: 600;
}
.puce input:checked + span { background: var(--accent); color: var(--sur-accent); }
.puce input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.case { display: flex !important; align-items: flex-start; gap: 10px !important; color: var(--texte) !important; font-size: 15px !important; }
.case input, .case-courte input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.case small { display: block; color: var(--discret); font-size: 13px; margin-top: 2px; }
.case-courte { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--discret); }
.erreur { margin: 0; font-size: 14px; color: var(--rouge); }
.erreur:empty { display: none; }

/* --- Réglages ------------------------------------------------------------------ */
.reglage .etat { margin-top: 6px; }
.liste-lignes { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 12px; }
.ligne { display: flex; gap: 8px; align-items: flex-start; }
.ligne.compte { align-items: center; }
.ligne-appareil { display: grid; gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--trait); }
.ligne-appareil:last-child { border-bottom: 0; padding-bottom: 0; }
.ligne-appareil > .ligne select { flex: 1; min-width: 0; }
.ligne-appareil small { margin-left: 4px; font-size: 12px; color: var(--discret); }
.ligne-principale { flex: 1; min-width: 0; display: grid; gap: 4px; }
.ligne-principale small { margin-left: 4px; font-size: 12px; color: var(--discret); }
.boutons-ligne { display: flex; gap: 4px; }
.icone {
  display: grid; place-items: center; width: 40px; height: 48px; flex: none;
  border: 0; border-radius: 12px; background: var(--fond);
}
.icone .ic { width: 20px; height: 20px; }
.ajout-ligne { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 14px; }
.ajout-ligne .erreur { grid-column: 1 / -1; }
.ajout-compte { display: grid; gap: 10px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--trait); }
.champ-avec-bouton { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.mot-de-passe { display: grid; gap: 10px; margin-top: 14px; }

/* --- Connexion ------------------------------------------------------------------ */
.connexion { display: grid; gap: 14px; max-width: 400px; margin: 6vh auto 0; }
.connexion-logo img { display: block; border-radius: 20px; }
.connexion h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.connexion .etat { margin: -4px 0 6px; }

/* --- Navigation flottante --------------------------------------------------------- */
.navigation {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 10;
  transform: translateX(-50%);
  display: flex; gap: 6px; padding: 7px;
  border-radius: 999px; background: var(--nav); box-shadow: 0 10px 30px #1d1b2e40;
}
.navigation button {
  display: grid; place-items: center; width: 52px; height: 52px;
  border: 0; border-radius: 50%; background: none; color: var(--nav-icone);
  transition: background .15s, color .15s;
}
.navigation svg { width: 24px; height: 24px; }
.navigation button[aria-current="page"] { background: var(--accent); color: #fff; }

.bandeau {
  position: fixed; left: 50%; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 80px); z-index: 20;
  transform: translateX(-50%); max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 12px; background: var(--texte); color: var(--carte);
  font-size: 14px; box-shadow: var(--ombre);
}

/* Aide installation iOS */
.aide {
  position: relative; margin-bottom: 16px; padding: 14px 40px 14px 16px;
  border-radius: 16px; background: var(--carte); font-size: 14px; box-shadow: var(--ombre);
}
.aide svg { width: 16px; height: 16px; vertical-align: -3px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.aide .fermer { position: absolute; top: 6px; right: 8px; border: 0; background: none; font-size: 22px; color: var(--discret); }

@media (max-width: 360px) {
  .deux-champs { grid-template-columns: 1fr; }
  .climat-valeurs strong { font-size: 34px; }
}
