/* Maison: the home-control standard at Apple Maison's finish. An off tile is a recessed slab, an on tile is the
   brightest, lifted surface with the device colour on its icon; the state of the house reads in one glance.
   Light by default; dark grey on demand (header button), set on <html> by js/theme.js before the first paint. */
:root {
  --fond: #f2f2f7;
  --fond-haut: #f7f7fa;
  --dalle: rgba(0, 0, 0, 0.05);
  --dalle-appui: rgba(0, 0, 0, 0.09);
  --clair: #ffffff;
  --texte: #1c1c1e;
  --doux: #636366;
  --encre: #1c1c1e;
  --encre-douce: #5b5b63;
  --ligne: rgba(0, 0, 0, 0.08);
  --puce: rgba(0, 0, 0, 0.06);
  --creux: rgba(0, 0, 0, 0.03);
  --bascule-off: rgba(120, 120, 128, 0.22);
  --poignee: rgba(0, 0, 0, 0.18);
  --voile: rgba(0, 0, 0, 0.32);
  /* The one strong action and the toast take the inverse of the ground: ink on light, near-white on dark grey. */
  --inverse-fond: #1c1c1e;
  --inverse-texte: #ffffff;
  /* A chosen chip must not rely on white-on-near-white: on light it takes the ink, on dark grey the near-white. */
  --choisi-fond: #1c1c1e;
  --choisi-texte: #ffffff;
  --choisi-doux: rgba(255, 255, 255, 0.72);
  /* Brightness track dark enough that the white level keeps 3:1 against it. */
  --piste: rgba(0, 0, 0, 0.42);
  --lumiere: #f7a928;
  --chaud: #ff7a2f;
  --froid: #2f9bff;
  --prise: #2fbf5b;
  --bouton: #a35bf0;
  /* New-device mark: darker green wherever it sits on a near-white surface, so it keeps 3:1 there. */
  --nouveau: #188a3c;
  --nouveau-sur-clair: #188a3c;
  --danger: #c4000f;
  --focus: #0a64d6;
  --rayon: 18px;
  --ombre: 0 6px 18px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.1);
  --ombre-choix: 0 1px 3px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
  --ombre-feuille: 0 -8px 30px rgba(0, 0, 0, 0.12);
  color-scheme: light;
}
:root[data-theme="sombre"] {
  --fond: #212124;
  --fond-haut: #2a2a2e;
  --dalle: rgba(255, 255, 255, 0.08);
  --dalle-appui: rgba(255, 255, 255, 0.13);
  --clair: #f2f2f5;
  --texte: #f5f5f7;
  --doux: #b4b4bb;
  --encre: #121214;
  --encre-douce: #5b5b63;
  --ligne: rgba(255, 255, 255, 0.09);
  --puce: rgba(255, 255, 255, 0.08);
  --creux: rgba(255, 255, 255, 0.04);
  --bascule-off: rgba(255, 255, 255, 0.16);
  --poignee: rgba(255, 255, 255, 0.2);
  --voile: rgba(0, 0, 0, 0.55);
  --inverse-fond: #f2f2f5;
  --inverse-texte: #121214;
  --choisi-fond: #f2f2f5;
  --choisi-texte: #121214;
  --choisi-doux: #5b5b63;
  --piste: rgba(255, 255, 255, 0.13);
  --nouveau: #30d158;
  --danger: #ff9d97;
  --focus: #5aa9ff;
  --ombre: 0 8px 24px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.25);
  --ombre-choix: none;
  --ombre-feuille: 0 -12px 40px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--fond); color: var(--texte); caret-color: var(--focus);
  font: 400 16px/1.35 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(92px + env(safe-area-inset-bottom));
}
::selection { background: rgba(90, 169, 255, 0.35); }
button, input, select { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; padding: 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 12px; }
.ico { width: 22px; height: 22px; flex: none; }
[hidden] { display: none !important; }

/* Title and status */
.tete { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0 14px; }
.outils { display: flex; gap: 8px; }
.tete h1 { margin: 0; font-size: 34px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.rond { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: var(--dalle); }
.rond:active { background: var(--dalle-appui); }
.rond.tourne .ico { animation: tourne 0.9s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }

.etats { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; margin: 0 0 14px; }
@media (min-width: 700px) { .etats { grid-template-columns: repeat(auto-fill, minmax(150px, 220px)); } }
main { max-width: 960px; margin-inline: auto; }
.demo { margin: -6px 0 12px; color: var(--doux); font-size: 14px; }
.pieces::-webkit-scrollbar { display: none; }
.etat-maison { display: grid; gap: 4px; min-width: 0; padding: 11px 12px; border-radius: 16px; background: var(--dalle); text-align: left; }
.etat-maison b, .etat-maison span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.etat-maison .ico { width: 24px; height: 24px; margin-bottom: 2px; color: var(--c, var(--doux)); }
.etat-maison b { font-size: 13px; font-weight: 600; color: var(--doux); }
.etat-maison span { font-size: 15px; font-weight: 650; }
.etat-maison[aria-pressed="true"] { background: var(--choisi-fond); color: var(--choisi-texte); }
.etat-maison[aria-pressed="true"] b { color: var(--choisi-doux); }

.pieces { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 6px; padding: 0 16px 4px; scrollbar-width: none; }
.onglet-piece { flex: none; height: 36px; padding: 0 14px; border-radius: 99px; font-size: 15px; font-weight: 600; color: var(--doux); white-space: nowrap; }
.onglet-piece[aria-selected="true"] { background: var(--dalle-appui); color: var(--texte); }
.onglet-piece.ajout { display: inline-flex; align-items: center; gap: 4px; }
.onglet-piece.ajout .ico { width: 18px; height: 18px; }

/* Device tiles */
.groupe { margin: 18px 0 8px; display: flex; align-items: baseline; justify-content: space-between; }
.groupe h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.groupe span { color: var(--doux); font-size: 14px; }
.grille { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 700px) { .grille { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); } }

.tuile {
  --c: var(--doux);
  position: relative; display: grid; grid-template-columns: 38px minmax(0, 1fr); align-items: center; column-gap: 10px;
  min-height: 74px; padding: 10px 12px 10px 10px; border-radius: var(--rayon); background: var(--dalle); text-align: left;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: background-color 180ms cubic-bezier(0.2, 0.8, 0.2, 1), transform 120ms ease;
}
.tuile:active { transform: scale(0.97); }
.tuile .puce { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--puce); color: var(--doux); transition: background-color 180ms, color 180ms; }
.tuile .puce .ico { width: 22px; height: 22px; }
.tuile strong { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; font-size: 15px; font-weight: 600; line-height: 1.2; overflow: hidden; overflow-wrap: anywhere; hyphens: auto; }
.tuile small { display: block; margin-top: 1px; font-size: 13px; color: var(--doux); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tuile.allume { background: var(--clair); color: var(--encre); box-shadow: var(--ombre); }
.tuile.allume small { color: var(--encre-douce); }
.tuile.allume .puce { background: color-mix(in srgb, var(--c) 16%, #fff); color: var(--c); }
.tuile.hors-ligne { opacity: 0.45; }
.tuile .nouveau { position: absolute; top: 8px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--nouveau); }
.tuile.allume .nouveau { background: var(--nouveau-sur-clair); }
.c-lumiere { --c: var(--lumiere); }
.c-chaud { --c: var(--chaud); }
.c-froid { --c: var(--froid); }
.c-prise { --c: var(--prise); }
.c-bouton { --c: var(--bouton); }
.squelette { min-height: 74px; border-radius: var(--rayon); background: var(--dalle); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }
.vide { margin: 34px 12px; color: var(--doux); text-align: center; line-height: 1.5; }
.vide strong { display: block; color: var(--texte); font-size: 17px; margin-bottom: 4px; }
.vide .pied { justify-items: center; }

/* Automations */
.tete-autos { display: flex; align-items: center; justify-content: space-between; margin: 10px 0 16px; }
.tete-autos h1 { margin: 0; font-size: 34px; font-weight: 800; letter-spacing: -0.02em; }
.regle { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px; margin-bottom: 8px; border-radius: var(--rayon); background: var(--dalle); text-align: left; }
.regle .texte { flex: 1; min-width: 0; text-align: left; }
.regle strong { display: block; font-size: 16px; font-weight: 650; margin-bottom: 3px; }
.regle p { margin: 0; color: var(--doux); font-size: 14px; line-height: 1.4; }
/* Paused: muted colour, never opacity, so the rule stays readable; the switch carries the state. */
.regle.coupee strong { color: var(--doux); }
.bascule { flex: none; position: relative; width: 52px; height: 32px; border-radius: 99px; background: var(--bascule-off); transition: background-color 160ms; }
.bascule::after { content: ''; position: absolute; top: 2px; left: 2px; width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); transition: transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1); }
.bascule[aria-checked="true"] { background: var(--prise); }
.bascule[aria-checked="true"]::after { transform: translateX(20px); }

/* Buttons */
.bouton { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: 14px; font-weight: 650; background: var(--dalle-appui); }
.bouton .ico { width: 20px; height: 20px; }
.bouton.principal { background: var(--inverse-fond); color: var(--inverse-texte); }
.bouton.danger { color: var(--danger); }
.bouton:active { opacity: 0.8; }

/* Bottom bar: solid, so a bright tile passing beneath never shows through as a blot. */
.barre {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: 1fr 1fr;
  padding: 6px max(24px, calc((100vw - 960px) / 2)) calc(8px + env(safe-area-inset-bottom)); background: var(--fond); border-top: 1px solid var(--ligne);
}
.barre button { display: grid; justify-items: center; gap: 2px; padding: 6px 0; font-size: 12px; font-weight: 600; color: var(--doux); }
.barre button .ico { width: 26px; height: 26px; }
.barre button[aria-current="page"] { color: var(--texte); }

/* Sheet */
.voile { position: fixed; inset: 0; z-index: 8; background: var(--voile); animation: fondu 200ms ease-out; }
@keyframes fondu { from { opacity: 0; } }
.feuille {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom)); border-radius: 28px 28px 0 0; background: var(--fond-haut);
  box-shadow: var(--ombre-feuille); animation: monte 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes monte { from { transform: translateY(48px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .feuille, .voile, .squelette, .rond.tourne .ico { animation: none; } .tuile, .bascule::after { transition: none; } }
.poignee { width: 38px; height: 5px; border-radius: 99px; background: var(--poignee); margin: 0 auto 14px; }
.feuille .entete { display: grid; grid-template-columns: 48px minmax(0, 1fr) 40px; align-items: center; gap: 12px; margin-bottom: 18px; }
.feuille .entete .puce { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--c); }
.feuille h2 { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.2; }
.feuille .sous { margin: 2px 0 0; color: var(--doux); font-size: 14px; }
.fermer { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--dalle); }
.fermer .ico { width: 20px; height: 20px; }
.champ { margin: 18px 0; }
.champ > label, .champ > .titre { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 600; color: var(--doux); }

/* Brightness: the tall pill slider of the standard, filled to the real level. */
.reglette {
  position: relative; width: 120px; height: 300px; margin: 6px auto 14px; border-radius: 30px; overflow: hidden;
  background: var(--piste); touch-action: none; cursor: ns-resize;
}
.reglette .niveau { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--n, 0) * 1%); background: var(--clair); transition: height 120ms ease-out; }
.reglette .ico { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); width: 30px; height: 30px; color: var(--c); z-index: 1; }
.valeur-grande { text-align: center; font-size: 15px; color: var(--doux); }
.valeur-grande b { display: block; font-size: 40px; font-weight: 750; color: var(--texte); letter-spacing: -0.02em; }
.marche { width: 96px; height: 96px; margin: 8px auto 16px; display: grid; place-items: center; border-radius: 50%; background: var(--dalle-appui); color: var(--doux); }
.marche .ico { width: 40px; height: 40px; }
.marche[aria-pressed="true"] { background: var(--clair); color: var(--c); box-shadow: var(--ombre); }

.consigne { display: grid; grid-template-columns: 64px 1fr 64px; align-items: center; gap: 8px; padding: 10px; border-radius: 22px; background: var(--dalle); }
.consigne .valeur { text-align: center; }
.consigne .valeur b { display: block; font-size: 44px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.05; }
.consigne .valeur span { font-size: 14px; color: var(--doux); }
.pas { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; background: var(--dalle-appui); }
.pas .ico { width: 26px; height: 26px; }
.mesure { display: flex; justify-content: space-between; margin: 12px 4px 0; color: var(--doux); font-size: 14px; }
.mesure b { color: var(--texte); font-weight: 650; }

.segments { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: var(--dalle); }
.segments button { display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 42px; padding: 0 8px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--doux); }
.segments button .ico { width: 17px; height: 17px; }
.segments button[aria-pressed="true"] { background: var(--clair); color: var(--encre); box-shadow: var(--ombre-choix); }
.choix { display: flex; flex-wrap: wrap; gap: 8px; }
.choix button { min-height: 40px; padding: 0 14px; border-radius: 99px; background: var(--dalle); font-size: 15px; font-weight: 600; }
.choix button[aria-pressed="true"] { background: var(--choisi-fond); color: var(--choisi-texte); }

input[type="text"], input[type="password"], input[type="time"], input[type="number"], select {
  width: 100%; min-height: 48px; padding: 0 14px; border-radius: 14px; border: 1px solid var(--ligne); background: var(--dalle);
  color: var(--texte); font-size: 16px;
}
select option { background: var(--fond-haut); color: var(--texte); }
input::placeholder { color: var(--doux); }
.rangee { display: flex; gap: 8px; align-items: center; }
.espace-haut { margin-top: 8px; }
.quand { margin-top: 10px; }
.bouton.large { width: 100%; }

/* Password: a closed house asks once per phone, then remembers it for a year. */
.v-code { max-width: 420px; }
.v-code h1 { margin: 10px 0 4px; font-size: 34px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.v-code .sous { margin: 0 0 26px; color: var(--doux); font-size: 16px; }
.form-code { display: grid; gap: 8px; }
.form-code label { font-size: 14px; font-weight: 600; color: var(--doux); }
.erreur-code { margin: 2px 0 0; color: var(--danger); font-size: 15px; font-weight: 600; }
.form-code .bouton { margin-top: 12px; }
.form-code .bouton:disabled { opacity: 0.6; }
.rangee > * { flex: 1; min-width: 0; }
.action { display: grid; gap: 8px; padding: 12px; margin-bottom: 8px; border-radius: 16px; background: var(--creux); }
.action .rangee > .retirer { flex: none; width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--dalle); }
.pied { display: grid; gap: 8px; margin-top: 22px; }
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 10; transform: translateX(-50%);
  margin: 0; padding: 12px 18px; border-radius: 16px; background: var(--inverse-fond); color: var(--inverse-texte); font-weight: 600; font-size: 15px;
  box-shadow: var(--ombre); max-width: calc(100% - 32px); animation: monte 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
