:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #f8f6f2;
  --line: #e7e2da;
  --text: #1d1b19;
  --muted: #77716a;
  --faint: #a9a39b;
  --accent: #e8641b;          /* chauffe */
  --accent-soft: #fdeadf;
  --confort: #f08a24;
  --confort-soft: #fdebd6;
  --eco: #4f6bd8;
  --eco-soft: #e3e8fb;
  --horsgel: #2aa3c4;
  --horsgel-soft: #dcf2f7;
  --off: #8b8680;
  --off-soft: #ecebe8;
  --manual: #8b5cf6;
  --manual-soft: #ede6fe;
  --ok: #22a06b;
  --danger: #d43c3c;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 4px 16px rgba(40, 30, 20, .06);
  --radius: 20px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #222227;
    --surface-2: #1c1c21;
    --line: #34343b;
    --text: #f3f1ee;
    --muted: #a7a29b;
    --faint: #6f6b66;
    --accent: #ff7a33;
    --accent-soft: #3d2619;
    --confort: #ff9a3d;
    --confort-soft: #3b2a18;
    --eco: #7d93f0;
    --eco-soft: #232b48;
    --horsgel: #4cc3e2;
    --horsgel-soft: #173840;
    --off: #8d8984;
    --off-soft: #2c2c31;
    --manual: #a78bfa;
    --manual-soft: #2f2747;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body { overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Boot / login ---------- */
.boot { display: grid; place-items: center; min-height: 100dvh; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: 100%; max-width: 360px; display: grid; gap: 14px; text-align: center; }
.login .logo { font-size: 56px; line-height: 1; }
.login h1 { margin: 4px 0 0; font-size: 26px; letter-spacing: -.02em; }
.login p { margin: 0 0 8px; color: var(--muted); }
.field { width: 100%; padding: 16px 18px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--surface); font-size: 17px; }
.field:focus { border-color: var(--accent); outline: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 22px; border-radius: 16px; font-weight: 650; font-size: 17px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { filter: brightness(.92); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 40px; padding: 0 14px; border-radius: 12px; font-size: 15px; }
.error { color: var(--danger); min-height: 1.4em; font-size: 15px; }

/* ---------- Structure ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0 14px; }
.topbar h1 { margin: 0; font-size: 30px; letter-spacing: -.03em; line-height: 1.1; }
.topbar .sub { color: var(--muted); font-size: 14px; margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.dot.bad { background: var(--danger); }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); font-size: 20px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 2px 10px; }
.section-title h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.section-title button { color: var(--accent); font-weight: 600; font-size: 15px; }

.banner { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; background: var(--off-soft); margin-bottom: 10px; font-size: 15px; }
.banner.warn { background: #fff1e6; color: #8a3b0a; }
@media (prefers-color-scheme: dark) { .banner.warn { background: #3b2416; color: #ffc59d; } }
.banner b { font-weight: 650; }
.banner .grow { flex: 1; }

/* ---------- Modes ---------- */
.modes { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x proximity; margin: 0 -16px; padding: 2px 16px 8px; scrollbar-width: none; }
.modes::-webkit-scrollbar { display: none; }
.mode {
  flex: 0 0 auto; scroll-snap-align: start; min-width: 118px; max-width: 168px; min-height: 104px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 8px;
  padding: 14px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); text-align: left;
  border: 2px solid transparent; transition: transform .12s ease;
}
.mode:active { transform: scale(.97); }
.mode .m-icon { font-size: 26px; line-height: 1; }
.mode .m-name { font-weight: 650; font-size: 15px; line-height: 1.2; }
.mode .m-sub { font-size: 12.5px; color: var(--muted); }
.mode.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.mode.on .m-sub { color: rgba(255, 255, 255, .88); }
.mode.add { background: transparent; box-shadow: none; border: 2px dashed var(--line); color: var(--muted); justify-content: center; align-items: center; min-width: 96px; }

/* ---------- Pièces ---------- */
.rooms { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
@media (min-width: 680px) { .rooms { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .rooms { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.room { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 16px 14px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; position: relative; overflow: hidden; }
.room::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--tone, var(--off)); }
.room.is-off { --tone: var(--off); }
.room-head { display: flex; align-items: center; gap: 12px; }
.room-head .r-icon { width: 44px; height: 44px; border-radius: 14px; background: var(--tone-soft, var(--off-soft)); display: grid; place-items: center; font-size: 22px; flex: none; }
.room-head .r-title { flex: 1 1 0; min-width: 0; text-align: left; }
.room-head .r-name { font-weight: 700; font-size: 18px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-head .r-amb { color: var(--muted); font-size: 14px; }
.power { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--off-soft); color: var(--off); flex: none; }
.power svg { width: 22px; height: 22px; }
.power.on { background: var(--accent); color: #fff; box-shadow: 0 4px 14px rgba(232, 100, 27, .35); }

.room-body { display: flex; align-items: center; gap: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 999px; font-size: 13.5px; font-weight: 600; background: var(--tone-soft, var(--off-soft)); color: var(--text); max-width: 100%; text-align: left; }
.chip .x { margin-left: 2px; width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center; background: rgba(0, 0, 0, .08); font-size: 12px; }
.chip span.t { overflow-wrap: anywhere; line-height: 1.25; }
.room-body .grow { flex: 1; min-width: 0; }
.stepper { display: flex; align-items: center; gap: 4px; flex: none; }
.stepper button { width: 46px; height: 46px; border-radius: 14px; background: var(--surface-2); font-size: 24px; font-weight: 500; display: grid; place-items: center; }
.stepper button:active { background: var(--line); }
.stepper button:disabled { opacity: .35; }
.stepper .target { min-width: 78px; text-align: center; font-size: 30px; font-weight: 750; letter-spacing: -.03em; color: var(--tone, var(--text)); }
.stepper .target small { font-size: 16px; font-weight: 600; }
.stepper .target.off { font-size: 18px; color: var(--muted); font-weight: 650; }
.pending { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.t-confort { --tone: var(--confort); --tone-soft: var(--confort-soft); }
.t-eco { --tone: var(--eco); --tone-soft: var(--eco-soft); }
.t-horsgel { --tone: var(--horsgel); --tone-soft: var(--horsgel-soft); }
.t-off { --tone: var(--off); --tone-soft: var(--off-soft); }
.t-manual { --tone: var(--manual); --tone-soft: var(--manual-soft); }
.t-temp { --tone: var(--accent); --tone-soft: var(--accent-soft); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar button { display: grid; justify-items: center; gap: 2px; padding: 6px 0; font-size: 11.5px; font-weight: 600; color: var(--faint); border-radius: 12px; }
.tabbar button .ti { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabbar button.on { color: var(--accent); }
.tabbar button.on .ti { filter: none; opacity: 1; }

/* ---------- Planning ---------- */
.pills { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 10px; scrollbar-width: none; }
.pills::-webkit-scrollbar { display: none; }
.pill { flex: none; padding: 10px 16px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow); font-weight: 600; font-size: 15px; white-space: nowrap; }
.pill.on { background: var(--text); color: var(--bg); }
.card { min-width: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.row .grow { flex: 1; min-width: 0; }
.row + .row { border-top: 1px solid var(--line); }
.row .label { font-weight: 600; }
.row .hint { font-size: 13.5px; color: var(--muted); }

.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }

.presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.preset-box { border-radius: 16px; padding: 10px 6px; text-align: center; background: var(--tone-soft); }
.preset-box .pl { font-size: 13px; font-weight: 650; color: var(--tone); }
.preset-box .pv { display: grid; grid-template-columns: 1fr 1fr; justify-items: center; gap: 6px; margin-top: 4px; }
.preset-box .pv b { grid-column: 1 / -1; grid-row: 1; }
.preset-box .pv button { width: 100%; max-width: 52px; height: 38px; border-radius: 10px; font-size: 20px; background: rgba(255, 255, 255, .55); }
@media (prefers-color-scheme: dark) { .preset-box .pv button { background: rgba(255, 255, 255, .08); } }
.preset-box .pv b { font-size: 24px; letter-spacing: -.02em; }

.week { display: grid; gap: 6px; }
.day { display: grid; grid-template-columns: 38px 1fr; align-items: center; gap: 10px; padding: 4px 0; text-align: left; width: 100%; }
.day .dn { font-weight: 700; font-size: 14px; color: var(--muted); }
.day.today .dn { color: var(--accent); }
.bar { position: relative; height: 34px; border-radius: 10px; overflow: hidden; display: flex; background: var(--off-soft); }
.bar .seg { height: 100%; background: var(--tone-soft); border-right: 1px solid var(--surface); display: flex; align-items: center; padding-left: 6px; font-size: 11px; font-weight: 700; color: var(--tone); overflow: hidden; white-space: nowrap; }
.bar .now { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); border-radius: 2px; }
.hours { display: grid; grid-template-columns: 38px 1fr; gap: 10px; font-size: 11px; color: var(--faint); }
.hours div:last-child { display: flex; justify-content: space-between; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; background: var(--tone-soft); border: 2px solid var(--tone); vertical-align: -1px; margin-right: 4px; }

/* ---------- Bottom sheet ---------- */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(15, 12, 10, .38); }
.scrim.enter { animation: fade .18s ease; }
.sheet {
  overflow-x: hidden;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 26px 26px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
}
.sheet.enter { animation: up .24s cubic-bezier(.2, .9, .3, 1); }
@media (min-width: 700px) { .sheet { bottom: 50%; transform: translateY(50%); border-radius: 26px; } .sheet.enter { animation: fade .18s ease; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; }
.sheet .lead { color: var(--muted); margin: 0 0 14px; font-size: 15px; }
.sheet .actions { display: grid; gap: 8px; margin-top: 16px; }
.sheet .actions.two { grid-template-columns: 1fr 1fr; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.choice { min-height: 48px; padding: 8px 10px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); font-weight: 600; font-size: 15px; border: 2px solid transparent; }
.choice.on { border-color: var(--accent); background: var(--accent-soft); }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick button { display: grid; justify-items: center; gap: 4px; padding: 12px 4px; border-radius: 16px; background: var(--tone-soft); font-weight: 650; font-size: 13.5px; border: 2px solid transparent; }
.quick button .qi { font-size: 22px; }
.quick button .qv { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.quick button.on { border-color: var(--tone); }

.seg-ctl { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg-ctl button { flex: 1; min-height: 36px; padding: 0 8px; border-radius: 9px; font-size: 13.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg-ctl button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg-ctl button.on.t-confort, .seg-ctl button.on.t-eco, .seg-ctl button.on.t-horsgel, .seg-ctl button.on.t-off, .seg-ctl button.on.t-temp { background: var(--tone-soft); color: var(--tone); }

.slot { display: grid; grid-template-columns: 132px 1fr 40px; grid-template-areas: "time . del" "seg seg seg"; gap: 8px; align-items: center; padding: 10px 0; }
.slot input[type=time] { grid-area: time; }
.slot .seg-ctl { grid-area: seg; }
.slot .del { grid-area: del; }
.slot + .slot { border-top: 1px solid var(--line); }
.slot input[type=time] { min-height: 44px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); padding: 0 8px; font-size: 17px; width: 100%; }
.slot .del { width: 40px; height: 40px; border-radius: 12px; color: var(--danger); font-size: 20px; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days button { width: 42px; height: 42px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow); font-weight: 700; font-size: 14px; }
.days button.on { background: var(--accent); color: #fff; }
.days button:disabled { opacity: 1; background: var(--text); color: var(--bg); }

.mode-room { display: grid; gap: 8px; padding: 12px 0; }
.mode-room + .mode-room { border-top: 1px solid var(--line); }
.mode-room .mr-name { font-weight: 650; display: flex; gap: 8px; align-items: center; }
.emoji-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-grid button { width: 44px; height: 44px; border-radius: 12px; background: var(--surface); font-size: 22px; border: 2px solid transparent; }
.emoji-grid button.on { border-color: var(--accent); background: var(--accent-soft); }
.form-label { display: block; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 2px 8px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline input[type=time], .inline select, .inline input[type=number] { min-height: 44px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); padding: 0 10px; font-size: 16px; }

.journal { font-size: 14px; }
.journal li { padding: 8px 0; border-top: 1px solid var(--line); list-style: none; display: flex; gap: 10px; }
.journal li:first-child { border-top: 0; }
.journal time { color: var(--faint); flex: none; font-variant-numeric: tabular-nums; }
.journal .warn { color: var(--danger); }
.journal ul { margin: 0; padding: 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: all .2s ease;
  background: var(--text); color: var(--bg); border-radius: 16px; padding: 12px 8px 12px 16px;
  display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 15px; max-width: calc(100% - 32px); box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
}
#toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
#toast button { color: var(--accent); font-weight: 700; padding: 6px 10px; border-radius: 10px; }
#toast .msg { padding-right: 6px; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .big { font-size: 44px; }

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