:root {
  --bg: #0f1216;
  --card: #181d23;
  --card-2: #20262e;
  --line: #2a313a;
  --text: #e8edf2;
  --muted: #8d97a3;
  --accent: #ff9f43;
  --accent-soft: rgba(255, 159, 67, .14);
  --ok: #3ecf8e;
  --danger: #ff6b6b;
  --radius: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  min-height: 100vh;
}
[hidden] { display: none !important; }
.screen { max-width: 760px; margin: 0 auto; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.4em; }

button, .btn, input, select {
  font: inherit; color: inherit; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); padding: .7em 1em;
}
button, .btn { cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4em; }
.primary { background: var(--accent); color: #1a1205; border-color: transparent; font-weight: 600; }
.ghost { background: transparent; }
.danger { color: var(--danger); }
.icon-btn { background: transparent; border: none; font-size: 1.4rem; padding: .3em .5em; line-height: 1; }
.badge { display: inline-block; margin-top: 4px; font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }

/* Login */
.login-box { min-height: 80vh; display: grid; place-content: center; text-align: center; gap: 12px; }
.logo { font-size: 3rem; }
.login-box h1 { margin: 0 0 8px; }
#login-form { display: flex; gap: 8px; }
#pin { width: 10em; text-align: center; letter-spacing: .3em; font-size: 1.2rem; }

/* App */
.top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.warn { margin-bottom: 16px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.warn p { margin: 0; }

.status { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px; margin-bottom: 20px; }
.indoor { font-size: 3.6rem; font-weight: 300; line-height: 1; font-variant-numeric: tabular-nums; }
.indoor small { font-size: 1.2rem; color: var(--muted); margin-left: 2px; }
.status-lines { display: grid; gap: 4px; }
.status-lines strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.flame { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.small-btn { align-self: start; color: var(--muted); }
.spinning { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.preset {
  position: relative; display: grid; gap: 6px; justify-items: start; justify-content: stretch; align-content: start; text-align: left;
  padding: 18px; min-height: 132px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line);
  transition: transform .08s ease, border-color .2s, background .2s;
}
.preset:active { transform: scale(.97); }
.preset .p-ico { font-size: 1.9rem; }
.preset .p-name { font-weight: 600; font-size: 1.05rem; }
.preset .p-val { color: var(--muted); font-size: .9rem; }
.preset.active { border-color: var(--accent); background: linear-gradient(160deg, var(--accent-soft), var(--card) 70%); }
.preset.active::after { content: "●"; position: absolute; top: 14px; right: 16px; color: var(--accent); font-size: .8rem; }
.preset.busy { opacity: .6; pointer-events: none; }
.preset:disabled { opacity: .4; }

#updated { margin-top: 18px; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 140%);
  background: var(--card-2); border: 1px solid var(--line); padding: 12px 18px; border-radius: 14px;
  transition: transform .25s ease; max-width: 90vw; z-index: 10;
}
#toast.show { transform: translate(-50%, 0); }
#toast.err { border-color: var(--danger); color: var(--danger); }
#toast.ok { border-color: var(--ok); }

/* Réglages */
dialog { border: none; padding: 0; background: transparent; color: var(--text); width: min(760px, 100vw); max-width: 100vw; max-height: 100dvh; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.sheet { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; max-height: 92dvh; overflow: auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet h2 { margin: 0; }
.sheet h3 { margin: 10px 0 0; font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.sheet-foot { position: sticky; bottom: -18px; background: var(--card); padding: 12px 0 0; display: flex; justify-content: flex-end; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }

.prow {
  display: grid; gap: 8px; align-items: center; padding: 10px; border-radius: 12px; background: var(--card-2);
  grid-template-columns: 3.2em 1fr auto;
  grid-template-areas: "icon label actions" "hold hold hold" "temp temp until";
  margin-bottom: 8px;
}
.prow .p-icon { grid-area: icon; text-align: center; padding: .5em 0; }
.prow .p-label { grid-area: label; min-width: 0; }
.prow .p-actions { grid-area: actions; display: flex; }
.prow .p-hold { grid-area: hold; }
.prow .p-temp-wrap { grid-area: temp; white-space: nowrap; }
.prow .p-temp { width: 4.8em; }
.prow .p-until { justify-self: start; }
.prow .p-until { grid-area: until; }
@media (min-width: 1000px) {
  .prow { grid-template-columns: 3.2em minmax(8em, 1fr) 13em 7.5em 7em auto; grid-template-areas: "icon label hold temp until actions"; }
}
#device-select { width: 100%; }
