/* ---------- La maison, poste par poste (page La Maison) ---------- */
.demo { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); gap: clamp(1.5rem, 3vw, 2.25rem); }

/* Onglets : deux pavillons, soulignés comme la page courante dans la navigation. */
.demo__tabs { display: flex; flex-wrap: wrap; gap: 0.25rem 2.5rem; border-bottom: 1px solid var(--line); }
.demo__tab {
  appearance: none; background: none; border: 0; padding: 0.9rem 0 1rem; margin-bottom: -1px; cursor: pointer;
  font-family: var(--f-display); font-size: clamp(1.05rem, 1.4vw, 1.25rem); line-height: 1.25; color: var(--ink-3);
  border-bottom: 2px solid transparent; transition: color 0.3s var(--ease-ui), border-color 0.3s var(--ease-ui);
}
.demo__tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--navy); }
@media (hover: hover) and (pointer: fine) { .demo__tab:hover { color: var(--ink); } }

.demo__body { display: grid; grid-template-columns: minmax(0, 1fr); gap: clamp(1.5rem, 3vw, 2.5rem); align-items: start; }
.demo__body > * { min-width: 0; }
@media (min-width: 1100px) {
  .demo__body { grid-template-columns: minmax(0, 1fr) 25.5rem; }
}

/* La scène : la hauteur de la maquette est portée par --scene-h ; la fiche se pose dessus
   quand la scène est assez large, sinon elle passe dessous (requêtes de conteneur, en em). */
.demo__stage {
  --scene-h: clamp(24rem, 72svh, 44rem);
  position: relative; width: 100%; container: scene / inline-size;
  background: radial-gradient(120% 90% at 50% 40%, #FFFFFF 0%, var(--porcelain) 60%, var(--cream) 100%);
}
/* Sur grand écran, la maquette reste visible pendant qu'on parcourt le panneau. */
@media (min-width: 1100px) {
  .demo__stage { position: sticky; top: calc(var(--header-h) + 1rem); }
}
.demo__stage::before { content: ""; position: absolute; left: 0.6rem; right: 0.6rem; top: 0.6rem; height: calc(var(--scene-h) - 1.2rem); border: 1px solid var(--line); pointer-events: none; z-index: 1; }
.demo__canvas { position: relative; width: 100%; height: var(--scene-h); display: block; touch-action: pan-y; cursor: grab; opacity: 0; transition: opacity 1.2s var(--ease-out); }
.demo__canvas:active { cursor: grabbing; }
.demo__canvas.is-ready { opacity: 1; }

/* Outils : rotation, pause, retour à la vue d'ensemble. */
.demo__tools { position: absolute; top: 1.4rem; right: 1.4rem; z-index: 3; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.4rem; align-items: center; max-width: calc(100% - 2.8rem); }
.demo__tool, .demo__home {
  appearance: none; min-width: 2.25rem; height: 2.25rem; padding: 0 0.7rem; border: 1px solid var(--navy); background: var(--porcelain); color: var(--ink);
  font-size: 0.82rem; font-weight: 600; cursor: pointer; display: inline-grid; place-items: center;
  transition: background-color 0.3s var(--ease-ui), color 0.3s var(--ease-ui);
}
.demo__tool svg { width: 1.05rem; height: 1.05rem; }
.demo__tool[aria-pressed="true"] { background: var(--navy); color: var(--cream); }
@media (hover: hover) and (pointer: fine) { .demo__tool:hover, .demo__home:hover { background: var(--navy); color: var(--cream); } }

/* Légende des réseaux, en bas à gauche de la maquette. */
.demo__legend {
  position: absolute; left: 1.4rem; top: calc(var(--scene-h) - 1.2rem); transform: translateY(-100%); z-index: 2;
  list-style: none; margin: 0; padding: 0.4rem 0.7rem; background: rgba(251, 252, 251, 0.9);
  display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; font-size: 0.78rem; color: var(--ink-2); max-width: min(calc(100% - 2.8rem), 34em);
}
.demo__legend li { display: inline-flex; align-items: center; gap: 0.45rem; }
.demo__legend li.is-off { display: none; }
.demo__legend i { width: 1.4rem; height: 0.22rem; border-radius: 1px; background: var(--c); }
.demo__legend [data-net="elec"] { --c: var(--copper); }
.demo__legend [data-net="frigo"] { --c: var(--navy); }
.demo__legend [data-net="chaud"] { --c: var(--terracotta); }
.demo__legend [data-net="froid"] { --c: var(--green); }
.demo__legend [data-net="combustible"] { --c: var(--grey); }

/* La fiche d'un équipement : sous la maquette par défaut… */
.demo__focus {
  position: relative; z-index: 4; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.75rem 1.75rem; align-items: start;
  padding: 1.25rem 1.4rem; background: var(--porcelain); border-top: 1px solid var(--line);
  font-size: 0.84rem; line-height: 1.55; color: var(--ink-2);
}
/* … posée en bandeau sur la maquette dès que la scène est assez large (32em, soit dès 1100 px sur ordinateur) : on lit la fiche en voyant le zoom,
   et la scène collante ne dépasse jamais la hauteur de l'écran. */
@container scene (min-width: 32em) {
  .demo__focus {
    position: absolute; left: 1.4rem; right: 1.4rem; bottom: 1.4rem; max-height: calc(var(--scene-h) * 0.52); overflow: auto; overscroll-behavior: contain;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); background: rgba(251, 252, 251, 0.97); border-top: 0; box-shadow: var(--lift);
  }
  .demo__focus-head { grid-column: 1 / -1; grid-template-columns: 1fr auto; align-items: baseline; column-gap: 1rem; }
  .demo__focus-head .demo__focus-calc, .demo__focus-kicker { grid-column: 1 / -1; }
  .demo__focus-close { grid-row: 2; grid-column: 2; }
  .demo__stage:has(.demo__focus:not([hidden])) .demo__legend { display: none; }
}
@container scene (min-width: 62em) {
  .demo__focus { grid-template-columns: minmax(0, 0.85fr) minmax(0, 1fr) minmax(0, 1fr); }
  .demo__focus-head { grid-column: auto; grid-template-columns: 1fr; }
  .demo__focus-close { grid-row: auto; grid-column: auto; }
}
.demo__focus:focus { outline: none; }
.demo__focus:focus-visible { outline: 2px solid var(--terracotta); outline-offset: -2px; }
.demo__focus.is-in { animation: focus-in 0.6s var(--ease-out) both; }
@keyframes focus-in { from { opacity: 0; transform: translateY(0.75rem); } }
/* Une suite à lire : un fondu en bas de la fiche. */
.demo__focus.has-more::after { content: ""; position: sticky; bottom: -1.25rem; grid-column: 1 / -1; height: 2.2rem; margin: -2.2rem -1.4rem -1.25rem; background: linear-gradient(rgba(251, 252, 251, 0), rgba(251, 252, 251, 0.98)); pointer-events: none; }
.demo__focus-head { display: grid; gap: 0.55rem; align-content: start; }
.demo__focus-kicker { display: flex; align-items: center; gap: 0.6rem; font-family: var(--f-display); font-size: 0.82rem; color: var(--ink-3); }
.demo__focus-kicker::before { content: ""; width: 1.2rem; height: 0.28rem; background: var(--copper); clip-path: polygon(0 0, 100% 0, calc(100% - 0.14rem) 100%, 0 100%); }
.demo__focus h3 { font-size: 1.35rem; line-height: 1.15; letter-spacing: -0.015em; color: var(--ink); }
.demo__focus h4 { font-family: var(--f-body); font-weight: 700; font-size: 0.78rem; color: var(--ink); margin-bottom: 0.35rem; }
.demo__focus ul { margin: 0; padding-left: 1rem; display: grid; gap: 0.3rem; }
.demo__focus li::marker { color: var(--copper); }
.demo__focus-net { font-size: 0.8rem; margin-top: 0.6rem; padding-top: 0.6rem; border-top: 1px solid var(--line); }
.demo__focus-calc { font-size: 0.8rem; color: var(--ink-3); }
.demo__focus-close { justify-self: start; appearance: none; background: none; border: 0; padding: 0 0 0.15em; margin-top: 0.2rem; font-weight: 600; font-size: 0.85rem; color: var(--ink); cursor: pointer; background-image: linear-gradient(currentColor, currentColor); background-size: 100% 1px; background-repeat: no-repeat; background-position: 0 100%; }

/* Sans 3D : un message à la place de la maquette. */
.demo__no3d { position: relative; padding: 1.5rem; font-size: 0.9rem; color: var(--ink-2); }
.no-3d .demo__canvas, .no-3d .demo__tools, .no-3d .demo__legend, .no-3d .demo__stage::before { display: none; }
/* Sans maquette, la fiche suit le message au lieu de se poser sur une scène vide (spécificité 0,2,0 : l'emporte sur les requêtes de conteneur). */
.no-3d .demo__focus { position: relative; left: auto; right: auto; bottom: auto; max-height: none; overflow: visible; box-shadow: none; background: var(--porcelain); border-top: 1px solid var(--line); animation: none; }
.no-3d .demo__focus.has-more::after { display: none; }

/* Le panneau, comme une carte de menu. */
.demo__panel { position: relative; background: var(--cream); padding: clamp(1.5rem, 3vw, 2rem); display: grid; gap: 0; min-width: 0; }
.demo__panel::before { content: ""; position: absolute; inset: 0.6rem; border: 1px solid var(--line); pointer-events: none; }
.demo__group { border: 0; margin: 0; padding: 1.25rem 0; min-width: 0; display: grid; gap: 0.85rem; border-top: 1px solid var(--line); position: relative; }
.demo__group:first-of-type { border-top: 0; padding-top: 0.25rem; }
.demo__group legend, .demo__tarif summary, .demo__result h3 {
  font-family: var(--f-display); font-size: 1.15rem; line-height: 1.3; color: var(--ink); padding: 0; margin-bottom: 0.1rem;
}
.demo__group legend { float: left; width: 100%; }
.demo__group legend + * { clear: both; }
.demo__profile { font-size: 0.9rem; line-height: 1.55; color: var(--ink-2); }
.demo__perso { display: grid; gap: 0.8rem; }
.demo__warn { color: var(--error); }

/* Choix segmentés */
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--navy); width: fit-content; max-width: 100%; }
.seg label { position: relative; cursor: pointer; flex: 1 1 auto; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 0.5rem 0.9rem; font-size: 0.88rem; line-height: 1.3; color: var(--ink); text-align: center; transition: background-color 0.25s var(--ease-ui), color 0.25s var(--ease-ui); }
.seg label + label span { border-left: 1px solid var(--navy); }
.seg input:checked + span { background: var(--navy); color: var(--cream); }
.seg input:focus-visible + span { outline: 2px solid var(--terracotta); outline-offset: 2px; }
.seg--s span { padding: 0.32rem 0.7rem; font-size: 0.82rem; }

/* Champs numériques */
.num { display: grid; gap: 0.35rem; font-size: 0.86rem; color: var(--ink-2); }
.num__field { display: flex; align-items: baseline; gap: 0.5rem; border-bottom: 1px solid var(--field-line); }
.num input { appearance: textfield; -moz-appearance: textfield; border: 0; background: transparent; padding: 0.35rem 0; width: 100%; min-width: 0; font-size: 1.05rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.num input::placeholder { color: var(--ink-3); opacity: 1; }
.num input::-webkit-outer-spin-button, .num input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num input:focus { outline: none; }
.num__field:focus-within { border-bottom-color: var(--navy); box-shadow: 0 1px 0 var(--navy); outline: 2px solid var(--terracotta); outline-offset: 4px; }
.num input[aria-invalid="true"] { color: var(--error); }
.num em { font-style: normal; font-size: 0.82rem; color: var(--ink-3); white-space: nowrap; }

/* Les équipements : interrupteurs */
.equip { list-style: none; margin: 0; padding: 0; display: grid; }
.equip__item { display: grid; gap: 0.55rem; padding: 0.7rem 0; border-top: 1px dashed var(--line); }
.equip__item:first-child { border-top: 0; padding-top: 0.1rem; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 1rem; cursor: pointer; font-size: 0.97rem; color: var(--ink); }
.switch input { appearance: none; margin: 0; flex: none; order: 2; width: 2.6rem; height: 1.45rem; border: 1px solid var(--navy); background: var(--porcelain); position: relative; cursor: pointer; transition: background-color 0.3s var(--ease-ui); }
.switch input::after { content: ""; position: absolute; top: 0.2rem; left: 0.2rem; width: 0.95rem; height: 0.95rem; background: var(--navy); clip-path: polygon(0 0, 100% 0, calc(100% - 0.22rem) 100%, 0 100%); transition: transform 0.35s var(--ease-out), background-color 0.3s var(--ease-ui); }
.switch input:checked { background: var(--navy); }
.switch input:checked::after { transform: translateX(1.15rem); background: var(--copper); }
.switch input:disabled { opacity: 0.4; cursor: not-allowed; }
.switch input:disabled + span { color: var(--ink-3); }
.equip__hint { font-size: 0.8rem; color: var(--ink-3); margin-top: -0.3rem; }
.equip [data-when], .equip__see { display: none; }
.equip .is-on [data-when] { display: inline-flex; }
.equip .is-on .equip__see { display: inline-flex; }
.equip__see { justify-self: start; appearance: none; background: none; border: 0; padding: 0 0 0.12em; font-size: 0.8rem; font-weight: 600; color: var(--ink); cursor: pointer; background-image: linear-gradient(currentColor, currentColor); background-size: 100% 1px; background-repeat: no-repeat; background-position: 0 100%; }

.stepper { align-items: center; gap: 0.75rem; }
.stepper button { appearance: none; width: 2rem; height: 2rem; border: 1px solid var(--navy); background: var(--porcelain); color: var(--ink); font-size: 1.05rem; line-height: 1; cursor: pointer; display: grid; place-items: center; }
.stepper button[aria-disabled="true"] { opacity: 0.35; cursor: not-allowed; }
.stepper output { font-size: 0.88rem; color: var(--ink-2); min-width: 9.5rem; text-align: center; font-variant-numeric: tabular-nums; }

/* Le tarif, replié par défaut */
.demo__tarif summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.demo__tarif summary::-webkit-details-marker { display: none; }
.demo__tarif summary::after { content: "+"; content: "+" / ""; font-family: var(--f-body); font-size: 1.2rem; color: var(--ink-3); }
.demo__tarif[open] summary::after { content: "−"; content: "−" / ""; }
.demo__tarif summary span { font-family: var(--f-body); font-size: 0.8rem; color: var(--ink-3); margin-left: auto; text-align: right; }
.demo__tarif-body { display: grid; gap: 0.85rem; padding-top: 0.9rem; }
.demo__reset { font-size: 0.85rem; background-color: transparent; }

/* Le résultat */
.demo__result { padding-top: 1.25rem; border-top: 1px solid var(--line); display: grid; gap: 1rem; }
.demo__result-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.75rem; }
.bill { margin: 0; display: grid; gap: 0.5rem; }
.bill div { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.bill dt { font-size: 0.9rem; color: var(--ink-2); }
.bill dd { text-align: right; margin: 0; font-family: var(--f-display); font-size: 1.3rem; font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
.bill__gap { padding-top: 0.6rem; border-top: 1px solid var(--line); }
.bill__gap dt { color: var(--ink); font-weight: 600; }
.bill__gap dd { font-weight: 800; font-size: 1.6rem; }
.bill dd small { font-family: var(--f-body); font-weight: 400; font-size: 0.8rem; color: var(--ink-3); margin-left: 0.4rem; }
.bill dd .bill__range { display: block; margin: 0.1rem 0 0; text-align: right; font-size: 0.78rem; }

.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.55rem; font-size: 0.82rem; }
.bars li { display: grid; grid-template-columns: 1fr auto; gap: 0.2rem 0.75rem; }
.bars .bars__label { color: var(--ink-2); }
.bars .bars__val { color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bars .bars__track { grid-column: 1 / -1; position: relative; height: 0.4rem; background: var(--line); }
.bars .bars__before, .bars .bars__after { position: absolute; left: 0; top: 0; height: 100%; transition: width 0.7s var(--ease-out); }
.bars .bars__before { background: var(--field-line); }
.bars .bars__after { background: var(--navy); }
.bars .is-up .bars__after { background: var(--terracotta); }
.demo__extra { font-size: 0.86rem; color: var(--ink-2); }
.demo__disclaimer { padding-top: 0.25rem; }
.demo__renov a { color: var(--ink); }

/* Hypothèses et sources */
.demo__sources { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.demo__sources summary { cursor: pointer; list-style: none; padding: 1.1rem 0; font-family: var(--f-display); font-size: 1.1rem; display: flex; justify-content: space-between; gap: 1rem; }
.demo__sources summary::-webkit-details-marker { display: none; }
.demo__sources summary::after { content: "+"; content: "+" / ""; font-family: var(--f-body); color: var(--ink-3); }
.demo__sources[open] summary::after { content: "−"; content: "−" / ""; }
.demo__sources-body { padding-bottom: 1.5rem; display: grid; gap: 1rem; font-size: 0.86rem; color: var(--ink-2); }
.demo__sources-body table { width: 100%; border-collapse: collapse; }
.demo__sources-body th, .demo__sources-body td { text-align: left; vertical-align: top; padding: 0.55rem 0.75rem 0.55rem 0; border-top: 1px solid var(--line); }
.demo__sources-body th { font-weight: 600; color: var(--ink); width: 34%; }
.demo__sources-body a { color: var(--ink); }
@media (max-width: 560px) {
  .demo__sources-body th, .demo__sources-body td { display: block; width: auto; padding-right: 0; }
  .demo__sources-body td { border-top: 0; padding-top: 0; }
}

/* Petits écrans */
@media (max-width: 760px) {
  .demo__stage { --scene-h: clamp(17rem, 56svh, 28rem); }
  .demo__tools { top: 1rem; right: 1rem; max-width: calc(100% - 2rem); }
  /* La légende passe sous la maquette : elle ne couvre plus le socle ni les compteurs. */
  .demo__legend { position: static; transform: none; margin: 0.5rem 1rem 0; padding: 0; background: none; font-size: 0.72rem; gap: 0.25rem 0.75rem; max-width: none; }
}
/* Téléphone à l'horizontale : la maquette tient dans l'écran, la fiche passe dessous. */
@media (max-height: 500px) and (orientation: landscape) {
  .demo__stage { --scene-h: calc(100svh - 5rem); position: relative; top: auto; }
  .demo__focus { position: relative; left: auto; right: auto; bottom: auto; max-height: none; overflow: visible; box-shadow: none; background: var(--porcelain); border-top: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  .demo__focus.is-in { animation: none; }
  .bars .bars__before, .bars .bars__after { transition: none; }
}
