:root {
  --fond: #11161c;
  --carte: #1a2129;
  --carte-2: #222b35;
  --bord: #2d3743;
  --texte: #e8edf2;
  --doux: #93a1b0;
  --accent: #f0a24a;
  --froid: #5fb3e6;
  --ok: #5cc38a;
  --danger: #e5675c;
  --rayon: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
[hidden] { display: none !important; }

/* ---- connexion ---- */
.connexion { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.connexion form { width: min(360px, 100%); display: grid; gap: 12px; }
.connexion h1 { margin-bottom: 12px; }

/* ---- structure ---- */
#app { max-width: 560px; margin: 0 auto; padding: env(safe-area-inset-top) 16px calc(88px + env(safe-area-inset-bottom)); }
.entete { display: flex; align-items: center; justify-content: space-between; padding: 18px 0 14px; }
.rafraichir { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--carte); }
.rafraichir svg { width: 20px; height: 20px; fill: none; stroke: var(--doux); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rafraichir.tourne svg { animation: tourne 0.8s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }
.vue { display: grid; gap: 14px; }
.vue > h2 { padding: 4px 0; }

.carte { background: var(--carte); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 16px; }
.carte-tete { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.vue > .carte-tete { margin-bottom: 0; }
.sous { color: var(--doux); font-size: 0.875rem; margin: 2px 0 0; }
.etiquette { color: var(--doux); font-size: 0.8rem; display: block; }
.vide { color: var(--doux); text-align: center; padding: 32px 0; }

/* ---- boutons ---- */
.principal, .secondaire, .danger {
  min-height: 44px; padding: 0 16px; border-radius: 12px; font-weight: 600;
}
.principal { background: var(--carte-2); border: 1px solid var(--bord); }
.principal:active { background: var(--bord); }
form .principal[type=submit], .connexion .principal { background: var(--accent); color: #1b1208; border: 0; }
.secondaire { background: transparent; border: 1px solid var(--bord); color: var(--doux); }
.danger { background: transparent; color: var(--danger); padding: 0 4px; }
.petit { min-height: 36px; padding: 0 14px; }
.large { width: 100%; }

/* ---- clim ---- */
.clim-tete { display: flex; justify-content: space-between; align-items: flex-start; }
.clim.allumee { border-color: color-mix(in srgb, var(--accent) 45%, var(--bord)); }
.clim.allumee.froid { border-color: color-mix(in srgb, var(--froid) 45%, var(--bord)); }
.interrupteur { width: 56px; height: 32px; border-radius: 16px; background: var(--bord); position: relative; transition: background .2s; flex: none; }
.interrupteur span { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .2s; }
.interrupteur[aria-checked=true] { background: var(--accent); }
.clim.froid .interrupteur[aria-checked=true] { background: var(--froid); }
.interrupteur[aria-checked=true] span { transform: translateX(24px); }

.clim-temps { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0 16px; }
.clim-temps .valeur { font-size: 2.1rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.reglage { display: flex; align-items: center; gap: 8px; }
.reglage button { width: 40px; height: 40px; border-radius: 50%; background: var(--carte-2); border: 1px solid var(--bord); font-size: 1.3rem; line-height: 1; }
.reglage button:active { background: var(--bord); }
.reglage .valeur { min-width: 3.2ch; text-align: center; }

.segments { display: flex; background: var(--fond); border-radius: 12px; padding: 3px; gap: 2px; }
.segments button { flex: 1; min-height: 38px; border-radius: 9px; color: var(--doux); font-size: 0.9rem; font-weight: 550; }
.segments button.actif { background: var(--carte-2); color: var(--texte); box-shadow: 0 1px 2px #0006; }
.ligne-select { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; color: var(--doux); }
select, input:not([type=checkbox]) {
  background: var(--fond); border: 1px solid var(--bord); border-radius: 10px; min-height: 44px; padding: 0 12px; width: 100%;
}
.ligne-select select { width: auto; min-width: 140px; color: var(--texte); }
.desactive { opacity: 0.45; pointer-events: none; }

/* ---- volets ---- */
.tous { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.volets { list-style: none; margin: 0; padding: 0; }
.volets li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--bord); }
.volets li:first-child { border-top: 0; }
.volets .nom { flex: 1; min-width: 0; }
.volets .nom span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.volets .hors-ligne .nom span:first-child { color: var(--doux); }
.volets .etat { font-size: 0.78rem; color: var(--doux); }
.volets .hors-ligne .etat { color: var(--danger); }
.commandes { display: flex; gap: 6px; }
.commandes button { width: 44px; height: 44px; border-radius: 12px; background: var(--carte-2); border: 1px solid var(--bord); display: grid; place-items: center; }
.commandes button:active { background: var(--bord); }
.commandes svg { width: 18px; height: 18px; fill: var(--texte); }
.hors-ligne .commandes { opacity: 0.35; }

/* ---- programmes ---- */
.programmes, .journal { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.programmes li { background: var(--carte); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 14px 16px; display: flex; gap: 12px; align-items: center; }
.programmes .corps { flex: 1; min-width: 0; text-align: left; }
.programmes .titre { font-weight: 600; }
.programmes .inactif { opacity: 0.5; }
.journal li { padding: 10px 2px; border-bottom: 1px solid var(--bord); }
.journal time { color: var(--doux); font-size: 0.8rem; display: block; }
.journal .origine { color: var(--doux); font-size: 0.8rem; }

/* ---- formulaires ---- */
.formulaire { display: grid; gap: 12px; }
label { display: grid; gap: 6px; color: var(--doux); font-size: 0.9rem; }
.deux { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.erreur { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 0.9rem; }

dialog {
  width: min(520px, 100%); max-height: 92dvh; margin: auto auto 0; padding: 0; border: 1px solid var(--bord);
  border-radius: 20px 20px 0 0; background: var(--carte); color: var(--texte);
}
@media (min-width: 600px) { dialog { margin: auto; border-radius: 20px; } }
dialog::backdrop { background: #000a; }
dialog form { display: grid; gap: 14px; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 8px; }
legend { color: var(--doux); font-size: 0.9rem; margin-bottom: 6px; }
.jours { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.jours label, .cases label { display: block; }
.jours input, .cases input { position: absolute; opacity: 0; pointer-events: none; }
.jours span { display: grid; place-items: center; height: 42px; border-radius: 10px; background: var(--fond); border: 1px solid var(--bord); color: var(--doux); font-weight: 600; }
.jours input:checked + span { background: var(--accent); border-color: var(--accent); color: #1b1208; }
.cases { display: flex; flex-wrap: wrap; gap: 6px; }
.cases span { display: inline-block; padding: 8px 12px; border-radius: 999px; background: var(--fond); border: 1px solid var(--bord); color: var(--doux); font-size: 0.85rem; }
.cases input:checked + span { border-color: var(--accent); color: var(--texte); }
.actions { display: flex; gap: 8px; align-items: center; }
.actions > span { flex: 1; }

/* ---- navigation ---- */
.onglets {
  position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--fond) 92%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--bord); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
}
@media (min-width: 600px) { .onglets { border: 1px solid var(--bord); border-bottom: 0; border-radius: 16px 16px 0 0; } }
.onglets button { display: grid; justify-items: center; gap: 2px; padding: 6px 0; color: var(--doux); font-size: 0.72rem; }
.onglets svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.onglets .actif { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--carte-2); border: 1px solid var(--bord); padding: 10px 16px; border-radius: 12px;
  opacity: 0; transition: .2s; pointer-events: none; max-width: calc(100% - 32px); font-size: 0.9rem;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.erreur-toast { border-color: var(--danger); }
