:root {
  --bg: #0a1322; --bg2: #0e1a2e; --panel: #111e35; --panel2: #172744; --line: #22365c; --line2: #2d4573;
  --text: #e8eef9; --muted: #8ea0c2; --dim: #5d6f92;
  --accent: #22d3ee; --accent2: #0ea5c6; --amber: #fbbf24; --amber-soft: rgba(251, 191, 36, .16);
  --green: #34d399; --red: #f87171; --violet: #a78bfa; --blue: #60a5fa; --orange: #fb923c;
  --radius: 16px; --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif; --title: 'Sora', var(--font);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: radial-gradient(1200px 700px at 70% -10%, #13284a 0%, var(--bg) 55%) fixed; color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--title); margin: 0; letter-spacing: -.01em; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }

/* ---------- pages simples (connexion, compte…) ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card { width: 100%; max-width: 400px; background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid var(--line); border-radius: 22px; padding: 26px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.card.wide { max-width: 560px; }
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 6px; }
.brand h1 { font-size: 20px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.logo { width: 44px; height: 44px; flex: 0 0 44px; border-radius: 13px; background: url('favicon.svg') center/26px no-repeat, linear-gradient(135deg, #0e7490, #1e3a8a); box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset, 0 6px 20px rgba(34, 211, 238, .25); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
input, select { background: var(--bg2); border: 1px solid var(--line2); border-radius: 12px; padding: 12px 14px; font-size: 15px; outline: none; min-height: 48px; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 211, 238, .18); }
fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px 14px; margin: 0; }
legend { padding: 0 6px; font-weight: 700; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tag { font-size: 11px; font-weight: 600; color: var(--accent); background: rgba(34,211,238,.1); border-radius: 99px; padding: 2px 8px; margin-left: 6px; }
.err { color: var(--red); margin: 0; font-weight: 600; }
.ok { color: var(--green); margin: 0; font-weight: 600; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.status { border-radius: 12px; padding: 12px 14px; font-size: 13.5px; }
.ok-box { background: rgba(52, 211, 153, .1); border: 1px solid rgba(52, 211, 153, .35); }
.warn-box { background: rgba(251, 191, 36, .1); border: 1px solid rgba(251, 191, 36, .35); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line2); background: var(--panel2); cursor: pointer; font-weight: 700; text-decoration: none; color: var(--text); transition: transform .08s, background .15s, border-color .15s; user-select: none; }
.btn:hover { border-color: var(--accent2); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: linear-gradient(135deg, #22d3ee, #0ea5e9); color: #04202b; border: 0; }
.btn.danger { background: rgba(248, 113, 113, .12); border-color: rgba(248, 113, 113, .45); color: #fecaca; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 36px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
@media (max-width: 520px) { .row2 { grid-template-columns: 1fr; } .card { padding: 20px; } }

/* ---------- page plan ---------- */
body.planpage { overflow: hidden; }
.app { height: 100dvh; display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr); }
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: rgba(10, 19, 34, .85); backdrop-filter: blur(10px); position: relative; z-index: 5; }
.top .logo { width: 38px; height: 38px; flex-basis: 38px; border-radius: 11px; background-size: 22px; }
.top h1 { font-size: 16.5px; white-space: nowrap; }
.top .sub { color: var(--muted); font-size: 12.5px; }
.top .grow { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 99px; font-size: 12.5px; font-weight: 700; background: var(--panel2); border: 1px solid var(--line2); white-space: nowrap; }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.pill.on i { background: var(--green); box-shadow: 0 0 10px var(--green); }
.pill.wait i { background: var(--amber); animation: blink 1s infinite; }
.pill.off i { background: var(--red); }
.pill.demo { color: #fde68a; border-color: rgba(251, 191, 36, .45); }
.pill.demo i { background: var(--amber); }
@keyframes blink { 50% { opacity: .3; } }
.menu { position: relative; }
.menu > button { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line2); background: var(--panel2); cursor: pointer; display: grid; place-items: center; }
.menu .dd { position: absolute; right: 0; top: 48px; min-width: 220px; background: var(--panel2); border: 1px solid var(--line2); border-radius: 14px; padding: 6px; box-shadow: var(--shadow); display: none; }
.menu.open .dd { display: block; }
.dd a, .dd button { display: block; width: 100%; text-align: left; padding: 11px 12px; border-radius: 10px; color: var(--text); text-decoration: none; background: none; border: 0; cursor: pointer; font-weight: 600; }
.dd a:hover, .dd button:hover { background: rgba(255,255,255,.06); }
.dd .who { padding: 8px 12px 10px; color: var(--muted); font-size: 12.5px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

.main { display: grid; grid-template-columns: minmax(0, 1fr) 340px; min-height: 0; }
.zoom { position: absolute; right: 22px; bottom: 22px; display: flex; flex-direction: column; gap: 6px; z-index: 3; }
.zoom button { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line2); background: rgba(23, 39, 68, .92); cursor: pointer; font-size: 18px; font-weight: 700; }
.zoom button:hover { border-color: var(--accent); }
.stage { position: relative; min-height: 0; display: flex; flex-direction: column; }
.planbox { flex: 1; min-height: 0; padding: 14px; display: grid; place-items: center; }
#plan { width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.side { border-left: 1px solid var(--line); background: rgba(14, 26, 46, .7); overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.sc { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; }
.sc h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sc h3 .ic { width: 18px; height: 18px; }
.big { font-family: var(--title); font-size: 26px; font-weight: 700; }
.big small { font-size: 14px; color: var(--muted); font-weight: 600; }
.lst { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.lst li { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; padding: 6px 8px; border-radius: 9px; cursor: pointer; }
.lst li:hover { background: rgba(255,255,255,.05); }
.lst li span:last-child { color: var(--muted); font-weight: 600; white-space: nowrap; }
.empty { color: var(--dim); font-size: 13px; }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 10px; font-size: 12.5px; color: var(--muted); }
.legend div { display: flex; align-items: center; gap: 8px; }
.legend svg { width: 22px; height: 22px; flex: 0 0 22px; }
.sc .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* plan SVG */
.room rect.z { fill: rgba(30, 50, 86, .55); stroke: #34507f; stroke-width: 2; rx: 10; transition: fill .3s, stroke .3s; }
.room.lit rect.z { fill: rgba(251, 191, 36, .13); stroke: rgba(251, 191, 36, .55); }
.room.pres rect.z { stroke: var(--accent); stroke-width: 2.5; }
.withimg .room rect.z { fill: rgba(34, 211, 238, .04); stroke-dasharray: 6 6; stroke: rgba(34, 211, 238, .45); }
.withimg .room.lit rect.z { fill: rgba(251, 191, 36, .14); }
.withimg.hidezones .room rect.z { opacity: 0; }
.room text { fill: #c7d4ee; font: 700 15px var(--title); pointer-events: none; }
.room text.meta { fill: var(--muted); font: 600 12px var(--font); }
.room .pres-dot { fill: var(--accent); }
.dev { cursor: pointer; }
.dev .halo { fill: transparent; transition: fill .3s; }
.dev circle.b { fill: #13233f; stroke: #3b5684; stroke-width: 2; transition: fill .2s, stroke .2s; }
.dev:hover circle.b { stroke: var(--accent); }
.dev .ico { color: #9fb2d6; }
.dev.on circle.b { fill: #3a2c07; stroke: var(--amber); }
.dev.on .ico { color: var(--amber); }
.dev.on .halo { fill: url(#glow); }
.dev.act circle.b { stroke: var(--accent); fill: #0b2b38; }
.dev.act .ico { color: var(--accent); }
.dev.alert circle.b { stroke: var(--red); fill: #3b1010; }
.dev.alert .ico { color: var(--red); }
.dev .val { fill: #dbe5f7; font: 700 11.5px var(--font); paint-order: stroke; stroke: #0a1322; stroke-width: 3px; }
.dev.sel circle.b { stroke: #fff; stroke-width: 3; }
.editing .dev, .editing .room { cursor: grab; }
.editing .dev circle.b { stroke-dasharray: 4 3; }
.handle { fill: var(--accent); cursor: nwse-resize; }
.dev .x { display: none; }
.editing .dev .x { display: block; }
.dev .x circle { fill: var(--red); }
.dev .x path { stroke: #fff; stroke-width: 2; }
@keyframes pulse { 0% { r: 20; opacity: .7; } 100% { r: 34; opacity: 0; } }
.dev.act .ping { fill: none; stroke: var(--accent); stroke-width: 2; animation: pulse 1.8s infinite; }

/* barre d'édition */
.editbar { display: none; margin: 10px 14px 0; z-index: 4; background: rgba(23, 39, 68, .95); border: 1px solid var(--accent2); border-radius: 14px; padding: 8px; gap: 8px; flex-wrap: wrap; align-items: center; box-shadow: var(--shadow); }
.editing .editbar { display: flex; }
.editbar .t { font-weight: 700; font-size: 13px; color: var(--accent); padding: 0 8px; margin-right: auto; }

/* panneau de commande (popup) */
.pop { position: fixed; right: 356px; top: 76px; width: 380px; max-height: calc(100dvh - 96px); overflow-y: auto; background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid var(--line2); border-radius: 20px; box-shadow: var(--shadow); z-index: 20; padding: 16px; display: none; flex-direction: column; gap: 14px; }
.pop.open { display: flex; animation: popin .16s ease-out; }
@keyframes popin { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.pop .hd { display: flex; align-items: center; gap: 12px; }
.pop .hd .ib { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; background: var(--bg2); border: 1px solid var(--line2); }
.pop .hd .ib svg { width: 24px; height: 24px; }
.pop .hd h2 { font-size: 17px; }
.pop .hd p { margin: 1px 0 0; color: var(--muted); font-size: 12.5px; }
.pop .hd .x { margin-left: auto; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line2); background: transparent; cursor: pointer; font-size: 20px; }
.sec { display: flex; flex-direction: column; gap: 9px; }
.sec > .lab { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; display: flex; justify-content: space-between; }
.power { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.power .btn { min-height: 52px; font-size: 15px; }
.power .btn.sel.on { background: rgba(251, 191, 36, .18); border-color: var(--amber); color: #fde68a; }
.power .btn.sel.off { background: rgba(148, 163, 184, .12); border-color: #64748b; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line2); background: var(--bg2); cursor: pointer; font-weight: 700; font-size: 13.5px; display: inline-flex; align-items: center; gap: 6px; }
.chip.sel { background: rgba(34, 211, 238, .16); border-color: var(--accent); color: #a5f3fc; }
.chip .star { color: var(--amber); }
.circ { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
.circ .l1 { display: flex; align-items: center; gap: 10px; }
.circ .l1 b { flex: 1; font-size: 14px; }
.sw { width: 56px; height: 32px; border-radius: 99px; background: #26365a; border: 0; position: relative; cursor: pointer; flex: 0 0 56px; transition: background .2s; }
.sw::after { content: ''; position: absolute; left: 4px; top: 4px; width: 24px; height: 24px; border-radius: 50%; background: #cbd5e1; transition: left .2s, background .2s; }
.sw.on { background: rgba(251, 191, 36, .55); }
.sw.on::after { left: 28px; background: #fff7d6; }
.swatch { width: 34px; height: 34px; border-radius: 10px; border: 2px solid rgba(255,255,255,.25); cursor: pointer; flex: 0 0 34px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 34px; background: transparent; padding: 0; border: 0; min-height: 0; box-shadow: none; }
input[type=range]::-webkit-slider-runnable-track { height: 10px; border-radius: 99px; background: var(--trk, linear-gradient(90deg, #1e293b, #fbbf24)); }
input[type=range]::-moz-range-track { height: 10px; border-radius: 99px; background: var(--trk, linear-gradient(90deg, #1e293b, #fbbf24)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: #fff; margin-top: -8px; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
input[type=range]::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 0; }
.rng { display: flex; align-items: center; gap: 10px; }
.rng output { min-width: 52px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.wheel { display: grid; place-items: center; position: relative; }
.wheel canvas { width: 220px; height: 220px; border-radius: 50%; touch-action: none; cursor: crosshair; }
.wheel .dot { position: absolute; width: 22px; height: 22px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 2px 8px rgba(0,0,0,.5); pointer-events: none; transform: translate(-50%, -50%); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg2); border-radius: 12px; padding: 4px; border: 1px solid var(--line); }
.tabs button { min-height: 38px; border: 0; border-radius: 9px; background: none; cursor: pointer; font-weight: 700; color: var(--muted); }
.tabs button.sel { background: var(--panel2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.05) inset; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 14px; }
.kv span:nth-child(odd) { color: var(--muted); }
.kv span:nth-child(even) { font-weight: 700; text-align: right; }
.bigtemp { display: flex; align-items: baseline; justify-content: space-between; }
.bigtemp .v { font-family: var(--title); font-size: 40px; font-weight: 700; }
.bigtemp .t { color: var(--muted); font-weight: 600; }
.stepper { display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px; align-items: center; }
.stepper .btn { min-height: 52px; font-size: 22px; padding: 0; }
.stepper .c { text-align: center; font-family: var(--title); font-size: 22px; font-weight: 700; }
.note { font-size: 12.5px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: #0f1d33; border: 1px solid var(--line2); padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; z-index: 50; display: none; max-width: calc(100vw - 32px); }
.toast.show { display: block; animation: popin .2s; }
.toast.bad { border-color: rgba(248,113,113,.6); color: #fecaca; }
.scrim { position: fixed; inset: 0; background: rgba(2, 6, 14, .55); z-index: 15; display: none; }
.scrim.open { display: block; }
.hiddenlist { display: flex; flex-wrap: wrap; gap: 6px; }

@media (max-width: 1100px) {
  .main { grid-template-columns: minmax(0, 1fr) 300px; }
  .pop { right: 316px; }
}
@media (max-width: 860px) {
  body.planpage { overflow: auto; }
  .app { height: auto; min-height: 100dvh; }
  .main { grid-template-columns: minmax(0, 1fr); }
  .planbox { padding: 6px; height: auto; display: block; }
  #plan { height: auto; aspect-ratio: var(--ar, 1.58); max-height: 70dvh; display: block; }
  .zoom { right: 12px; bottom: 12px; }
  .top .btxt { display: none; }
  .toast { top: 70px; bottom: auto; }
  .side { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .top .sub { display: none; }
  .pop { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 86dvh; border-radius: 22px 22px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .editbar { position: sticky; top: 0; margin: 0; border-radius: 0; }
}
@media (max-width: 480px) {
  .top { padding: 8px 12px; gap: 8px; }
  .top h1 { font-size: 15px; }
  .pill { padding: 5px 9px; font-size: 11.5px; }
}
@media (min-width: 861px) { .scrim.open { background: transparent; } }
