:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fb; --line: #e3e6eb; --line-strong: #cfd4dc;
  --text: #14171c; --muted: #6a7280; --faint: #9aa1ad;
  --accent: #2563eb; --accent-soft: #e6eeff;
  --hot: #ef4444; --hot-soft: #fde8e8; --warm: #f59e0b; --cold: #3b82f6; --cold-soft: #e3eefe;
  --ok: #16a34a; --pipe-idle: #d5d9e0; --unit-body: #ffffff; --unit-shade: #eef0f4;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 8px 24px rgba(16,24,40,.06);
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116; --surface: #171b22; --surface-2: #1d222b; --line: #2a303b; --line-strong: #3a4250;
    --text: #eef1f5; --muted: #9aa3b2; --faint: #6b7483;
    --accent: #6b9bff; --accent-soft: #1c2a4a;
    --hot: #f87171; --hot-soft: #3a1d1f; --warm: #fbbf24; --cold: #60a5fa; --cold-soft: #172a45;
    --ok: #4ade80; --pipe-idle: #343b47; --unit-body: #232933; --unit-shade: #1a1f27;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- barra superiore ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line); }
.brand { font-weight: 650; letter-spacing: -.01em; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.conn { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); transition: background .3s; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.dot.bad { background: var(--hot); }
.power-all.on { color: #fff; background: var(--ok); border-color: var(--ok); }
.power-all.busy { opacity: .55; pointer-events: none; }
.refresh-btn { width: 30px; height: 30px; margin-left: -4px; }
.refresh-btn svg { width: 16px; height: 16px; }
.refresh-btn.busy svg { animation: spin .9s linear infinite; }
.refresh-btn.busy { pointer-events: none; color: var(--accent); }
.spacer { flex: 1; }
.field-label { font-size: 12px; color: var(--muted); margin-right: 8px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font-size: 13px; color: var(--muted);
  transition: background .18s, color .18s, box-shadow .18s; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(16,24,40,.14); }
.seg button:disabled { opacity: .45; cursor: not-allowed; }
.seg.busy { opacity: .6; pointer-events: none; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); transition: color .15s, border-color .15s, transform .1s; }
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }
.icon-btn:active { transform: scale(.96); }
.icon-btn svg { width: 18px; height: 18px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- palco ---------- */
main { padding: 20px; max-width: 1320px; margin: 0 auto; }
.stage { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); overflow-x: auto; }
.stage-inner { min-width: 920px; padding: 8px 12px 12px; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; padding: 4px 20px 16px; color: var(--muted); font-size: 12.5px; }
.legend i { display: inline-block; width: 22px; height: 5px; border-radius: 3px; vertical-align: middle; margin-right: 6px; }
.banner { margin: 0 0 14px; padding: 10px 14px; border-radius: 12px; background: var(--hot-soft); color: var(--hot); font-size: 13.5px; }

/* ---------- schema SVG ---------- */
#cycle-svg { width: 100%; height: auto; display: block; }
#cycle-svg text { font-family: inherit; fill: var(--text); }
.t-muted { fill: var(--muted) !important; }
.t-faint { fill: var(--faint) !important; }
.casing { fill: var(--unit-body); stroke: var(--line-strong); stroke-width: 1.5; }
.casing-shade { fill: var(--unit-shade); }
.detail { stroke: var(--line-strong); fill: none; stroke-width: 1.5; stroke-linecap: round; }
.pipe { fill: none; stroke: var(--pipe-idle); stroke-width: 11; stroke-linecap: square; stroke-linejoin: round; transition: stroke .6s; }
.pipe.hot { stroke: var(--hot); } .pipe.warm { stroke: var(--warm); } .pipe.cold { stroke: var(--cold); }
.pipe-halo { fill: none; stroke: var(--surface); stroke-width: 19; }
.chev { fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; opacity: .92;
  offset-rotate: auto; animation: travel var(--dur, 7s) linear infinite; }
.route.rev .chev { animation-direction: reverse; offset-rotate: auto 180deg; }
.route { transition: opacity .5s; }
.route.off { opacity: 0; }
@keyframes travel { from { offset-distance: 0%; } to { offset-distance: 100%; } }
.spin { transform-box: fill-box; transform-origin: center; animation: spin 1.4s linear infinite; animation-play-state: paused; }
.running .spin { animation-play-state: running; }
@keyframes spin { to { transform: rotate(360deg); } }
.coil { stroke-width: 2; fill: var(--unit-shade); stroke: var(--line-strong); transition: fill .6s, stroke .6s; }
.coil.hot { fill: var(--hot-soft); stroke: var(--hot); } .coil.cold { fill: var(--cold-soft); stroke: var(--cold); }
.callout rect { fill: var(--surface-2); stroke: var(--line); transition: stroke .2s, fill .2s; }
.callout { cursor: pointer; }
.callout:hover rect, .callout:focus-visible rect { stroke: var(--accent); fill: var(--accent-soft); }
.callout .val { font-weight: 650; font-size: 15px; }
.callout .lab { font-size: 11.5px; }
.leader { stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 2 3; fill: none; }
.chip-heat { fill: var(--hot) !important; } .chip-cool { fill: var(--cold) !important; }
.eev-ring-bg { fill: var(--surface); stroke: var(--line); stroke-width: 4; }
.eev-ring { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; transition: stroke-dashoffset .9s ease, stroke .5s; }
.eev-gate { fill: var(--text); transition: transform .9s ease; transform-box: fill-box; }
.eev.off .eev-ring { stroke: var(--pipe-idle); }
.unit { cursor: pointer; transition: opacity .5s, filter .5s; }
.unit .casing { transition: stroke .2s, filter .2s; }
.unit:hover .casing, .unit:focus-visible .casing { stroke: var(--accent); filter: drop-shadow(0 6px 14px rgba(37,99,235,.18)); }
.unit.off { opacity: .62; filter: saturate(.3); }
.unit .big { font-size: 34px; font-weight: 650; letter-spacing: -.02em; }
.unit .name { font-size: 14px; font-weight: 600; }
.badge-on { fill: var(--ok) !important; font-weight: 600; } .badge-off { fill: var(--faint) !important; }
.louver { fill: var(--line-strong); transform-box: fill-box; transform-origin: 50% 0%; transition: transform .8s ease; }
.louver.swing { animation: swing 5s ease-in-out infinite; }
@keyframes swing { 0%,100% { transform: scaleY(1) } 50% { transform: scaleY(4.6) } }
.air { fill: var(--faint); opacity: 0; transition: fill .5s; transform-box: fill-box; transform-origin: center; will-change: transform, opacity; }
.unit.on .air { animation: drift 1.6s linear infinite; }
.cycle-heat .unit.blow .air { fill: var(--hot); } .cycle-cool .unit.blow .air { fill: #38bdf8; }
/* ogni barra finisce esattamente dove (posizione, larghezza, opacità) comincia la successiva: il moto è continuo */
@keyframes drift { from { transform: translateY(0) scaleX(1); opacity: calc(var(--o1) * var(--air, .6)); } to { transform: translateY(12px) scaleX(var(--k)); opacity: calc(var(--o2) * var(--air, .6)); } }
.display-led { fill: var(--faint); transition: fill .4s; } .display-led.lit { fill: var(--ok); }
.snow { color: var(--faint); transition: color .4s; }
.snow.active { color: var(--cold); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.pending-ring { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 6; opacity: 0; animation: spin-dash 1s linear infinite; }
.unit.pending .pending-ring { opacity: .9; }
@keyframes spin-dash { to { stroke-dashoffset: -12; } }

/* ---------- pannello unità ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10,14,20,.38); z-index: 30; opacity: 0; pointer-events: none; transition: opacity .25s; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); z-index: 31; background: var(--surface);
  border-left: 1px solid var(--line); box-shadow: var(--shadow); transform: translateX(104%); transition: transform .32s cubic-bezier(.3,.8,.3,1);
  display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.drawer header { display: flex; align-items: center; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.drawer h2 { margin: 0; font-size: 18px; font-weight: 650; flex: 1; }
.drawer .sub { font-size: 12.5px; color: var(--muted); font-weight: 400; display: block; margin-top: 2px; }
.drawer-body { overflow-y: auto; padding: 6px 20px 28px; flex: 1; }
.group { padding: 16px 0; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group h3 { margin: 0 0 10px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: 6px; }
.group .note { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }
.switch { position: relative; width: 46px; height: 28px; border-radius: 999px; border: 0; background: var(--line-strong); transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .22s cubic-bezier(.3,.8,.3,1); }
.switch[aria-checked="true"] { background: var(--ok); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.switch:disabled { opacity: .45; cursor: not-allowed; }
.setpoint { display: flex; align-items: center; justify-content: center; gap: 18px; }
.setpoint .value { font-size: 52px; font-weight: 650; letter-spacing: -.03em; min-width: 120px; text-align: center; font-variant-numeric: tabular-nums; }
.setpoint .value small { font-size: 22px; color: var(--muted); font-weight: 500; }
.round { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--surface); font-size: 22px; line-height: 1; transition: background .15s, transform .1s; }
.round:hover { background: var(--surface-2); } .round:active { transform: scale(.94); } .round:disabled { opacity: .4; cursor: not-allowed; }
input[type=range] { width: 100%; accent-color: var(--accent); margin-top: 10px; }
.readouts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.readout { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; text-align: left; transition: border-color .15s; }
.readout:hover { border-color: var(--accent); }
.readout b { display: block; font-size: 19px; font-weight: 650; }
.readout span { font-size: 11.5px; color: var(--muted); }
.toggles { display: grid; gap: 4px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.toggle-row .tname { font-size: 14.5px; }
.tag { font-size: 10.5px; color: var(--warm); border: 1px solid color-mix(in srgb, var(--warm) 50%, transparent); border-radius: 6px; padding: 0 5px; margin-left: 6px; vertical-align: 1px; }
.off-note { background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: 12px; padding: 14px; color: var(--muted); font-size: 13.5px; margin-top: 16px; }

/* ---------- grafici ---------- */
.modal { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; opacity: 0; pointer-events: none; transform: translateY(12px); transition: opacity .22s, transform .22s; }
.modal.open { opacity: 1; pointer-events: auto; transform: none; }
.modal header { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.modal h2 { margin: 0; font-size: 17px; font-weight: 650; }
.charts-body { display: grid; grid-template-columns: 260px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); min-height: 0; flex: 1; }
.keylist { overflow-y: auto; border-right: 1px solid var(--line); background: var(--surface); padding: 10px 14px 24px; }
.keylist h4 { margin: 14px 0 6px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.keylist label { display: flex; align-items: center; gap: 8px; padding: 4px 2px; font-size: 13.5px; cursor: pointer; }
.keylist label small { color: var(--faint); margin-left: auto; }
.plot-wrap { padding: 16px 20px; min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
#plot { flex: 1; min-height: 0; overflow: hidden; }
.keylist { min-height: 0; }
.plot-empty { color: var(--muted); padding: 40px 0; text-align: center; }
.range-custom { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.range-custom input { font: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); }
.u-legend { font-size: 12.5px !important; } .u-legend th, .u-legend td { color: var(--text); }
@media (max-width: 760px) { .charts-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: 170px minmax(0, 1fr); } .keylist { border-right: 0; border-bottom: 1px solid var(--line); } main { padding: 12px; } }

/* ---------- tooltip, toast, login ---------- */
#tip { position: fixed; z-index: 60; max-width: 280px; background: #14171c; color: #f2f4f7; font-size: 12.5px; line-height: 1.4; padding: 8px 10px; border-radius: 9px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); pointer-events: none; opacity: 0; transform: translateY(4px); transition: opacity .14s, transform .14s; }
#tip.show { opacity: 1; transform: none; }
#toast { position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px); z-index: 70; background: #14171c; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); } #toast.err { background: #b42318; }
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 32px 30px 28px; }
.login-card h1 { margin: 14px 0 4px; font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
.login-card p { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.login-card input { width: 100%; font: inherit; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); }
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.btn-primary { width: 100%; margin-top: 22px; padding: 12px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; transition: filter .15s, transform .1s; }
.btn-primary:hover { filter: brightness(1.07); } .btn-primary:active { transform: scale(.99); } .btn-primary:disabled { opacity: .6; cursor: wait; }
.form-error { color: var(--hot); font-size: 13.5px; margin-top: 14px; min-height: 20px; }
.hint { font-size: 12.5px; color: var(--faint); margin-top: 16px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- icone alette, (i) e scheda specifiche ---------- */
.seg button.icon-opt { padding: 5px 8px; display: grid; place-items: center; }
.info { cursor: pointer; }
.info circle { fill: var(--surface-2); stroke: var(--line-strong); stroke-width: 1.2; transition: fill .15s, stroke .15s; }
.info path { stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; fill: none; }
.info:hover circle, .info:focus-visible circle { fill: var(--accent-soft); stroke: var(--accent); }
.info:hover path { stroke: var(--accent); }
.sheet { position: fixed; z-index: 45; left: 50%; top: 50%; width: min(560px, calc(100vw - 24px)); max-height: min(86vh, 760px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  transform: translate(-50%, -46%) scale(.98); opacity: 0; pointer-events: none; transition: opacity .2s, transform .22s cubic-bezier(.3,.8,.3,1); }
.sheet.open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%); }
.sheet header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.sheet h2 { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
.sheet .sub { font-size: 13px; color: var(--muted); }
.sheet-body { overflow-y: auto; padding: 4px 20px 20px; }
.sheet h3 { margin: 18px 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.sheet dl { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.sheet dt, .sheet dd { margin: 0; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.sheet dt { color: var(--muted); padding-right: 16px; }
.sheet dd { font-weight: 550; text-align: right; font-variant-numeric: tabular-nums; }
.sheet .note { font-size: 12px; color: var(--faint); margin: 16px 0 0; line-height: 1.5; }

/* ---------- scenari ---------- */
.scenarios { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 0; align-items: center; }
/* maniglia per il trascinamento: il resto del chip resta cliccabile e scorrevole */
.scn .grip { color: var(--faint); cursor: grab; touch-action: none; padding: 0 4px 0 10px; display: grid; place-items: center; }
.scn .grip:hover { color: var(--text); }
.scn .grip svg { width: 14px; height: 14px; }
.scn.dragging { border-color: var(--accent); box-shadow: 0 8px 22px rgba(37,99,235,.22); transform: scale(1.02); z-index: 2; position: relative; }
.scn.dragging .grip { cursor: grabbing; color: var(--accent); }
body.sorting, body.sorting * { cursor: grabbing !important; user-select: none; }
.scn { display: inline-flex; align-items: stretch; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: 0 1px 2px rgba(16,24,40,.04); transition: border-color .15s, transform .1s; }
.scn:hover { border-color: var(--line-strong); }
.scn.busy { opacity: .6; pointer-events: none; }
.scn button { border: 0; background: transparent; padding: 9px 12px; font-size: 14px; }
.scn .run { font-weight: 600; display: flex; align-items: center; gap: 8px; padding-right: 8px; }
.scn .run:hover { background: var(--accent-soft); color: var(--accent); }
.scn .run:active { transform: scale(.98); }
.scn .run svg { width: 14px; height: 14px; color: var(--accent); }
.scn .edit { color: var(--faint); padding: 9px 10px; border-left: 1px solid var(--line); display: grid; place-items: center; }
.scn .edit:hover { color: var(--text); background: var(--surface-2); }
.scn .edit svg { width: 15px; height: 15px; }
.scn-add { border: 1px dashed var(--line-strong); background: transparent; color: var(--muted); border-radius: 12px; padding: 9px 14px; font-size: 14px; transition: color .15s, border-color .15s; }
.scn-add:hover { color: var(--accent); border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 10px; align-items: center; margin: 10px 0; font-size: 14px; }
.form-row > label, .form-row > span:first-child { color: var(--muted); }
.sheet input[type=text], .sheet input[type=number], .sheet select { width: 100%; font: inherit; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); }
.scn-unit { border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px 8px; margin-top: 12px; }
.scn-unit h3 { margin: 12px 0 4px; }
.sheet-actions { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.btn { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 10px; padding: 9px 16px; font-weight: 550; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn.danger { color: var(--hot); border-color: color-mix(in srgb, var(--hot) 45%, transparent); }
.btn:disabled { opacity: .5; cursor: wait; }

/* ---------- telefono ---------- */
@media (max-width: 760px) {
  body { font-size: 15px; }
  .topbar { padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); gap: 8px 10px; }
  .topbar .conn { font-size: 12px; min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .spacer { display: none; }
  .mode-wrap { order: 5; width: 100%; display: flex; align-items: center; min-width: 0; }
  .mode-wrap .field-label { display: none; }
  .mode-wrap .seg { flex: 1; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .mode-wrap .seg::-webkit-scrollbar { display: none; }
  .mode-wrap .seg button { flex: 1 0 auto; padding: 8px 12px; }
  .icon-btn { width: 40px; height: 40px; }
  .brand-name { display: none; }   /* sul telefono basta il logo: lascia spazio ai tasti */
  main { padding: 10px 10px calc(16px + env(safe-area-inset-bottom)); }
  .stage { overflow: hidden; border-radius: 16px; }
  .stage-inner { min-width: 0; padding: 8px 4px 8px; }
  .legend { padding: 4px 14px 14px; gap: 6px 14px; font-size: 12px; }
  /* scenari uno sopra l'altro, a tutta larghezza */
  .scenarios { flex-direction: column; align-items: stretch; margin-top: 10px; }
  .scn .run { flex: 1; }
  .scn button { padding: 13px 12px; }
  .scn .grip { padding: 0 12px; }
  .scn-add { padding: 13px 14px; }
  /* pannello unità come foglio dal basso */
  .drawer { top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-height: 90dvh; height: 90dvh; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 20px 20px 0 0; transform: translateY(104%); }
  .drawer header { padding: 14px 16px 12px; }
  .drawer-body { padding: 4px 16px calc(24px + env(safe-area-inset-bottom)); }
  .seg button.icon-opt { padding: 8px 9px; }
  .seg[data-param] { display: flex; }
  .seg[data-param] button { flex: 1; padding-top: 9px; padding-bottom: 9px; }
  .switch { width: 50px; height: 30px; } .switch::after { width: 24px; height: 24px; } .switch[aria-checked="true"]::after { transform: translateX(20px); }
  .sheet { width: calc(100vw - 16px); max-height: 88dvh; }
  .form-row { grid-template-columns: 1fr; gap: 4px; }
  .sheet dl { grid-template-columns: 1fr; } .sheet dt { border-bottom: 0; padding-bottom: 0; font-size: 12.5px; } .sheet dd { text-align: left; padding-top: 2px; }
  .modal header { padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); gap: 8px; }
  .range-custom { display: none; }
  .charts-body { grid-template-rows: 150px minmax(0, 1fr); }
  .plot-wrap { padding: 8px 6px; }
  #toast { bottom: calc(18px + env(safe-area-inset-bottom)); }
  input, select, button { font-size: 16px; }   /* evita lo zoom automatico di iOS sui campi */
  .seg button { font-size: 14px; }
}

/* ---------- programmazione oraria ---------- */
.sched-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.sched-row .info-col { flex: 1; min-width: 0; }
.sched-row b { font-weight: 600; display: block; }
.sched-row small { color: var(--muted); font-size: 12.5px; display: block; margin-top: 2px; }
.sched-row small.warn { color: var(--hot); }
.sched-row.disabled .info-col { opacity: .5; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days button { width: 40px; height: 36px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted); font-size: 13px; transition: background .15s, color .15s, border-color .15s; }
.days button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.time-pair { display: flex; align-items: center; gap: 8px; }
.sheet input[type=time] { font: inherit; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); }
.empty { color: var(--muted); padding: 22px 0 8px; font-size: 14px; }

/* ---------- circuito dentro l'unità esterna ---------- */
.pipe.thin { stroke-width: 8; }
/* valvola 4 vie in sezione: corpo pieno di gas di mandata, coppa scorrevole */
#valve4 .valve-body { fill: var(--surface); stroke: var(--line-strong); stroke-width: 2; transition: fill .6s, stroke .6s; }
#valve4.heat .valve-body, #valve4.cool .valve-body { fill: var(--hot-soft); stroke: var(--hot); }
.vcup { transform: translateX(182.5px); transition: transform 1s cubic-bezier(.5,0,.2,1); }
#valve4.pos-cool .vcup { transform: translateX(217.5px); }
.vcup-shell { fill: var(--surface-2); stroke: var(--line-strong); stroke-width: 1.5; }
.vcup-ch { fill: none; stroke: var(--pipe-idle); stroke-width: 6; transition: stroke .6s; }
#valve4.heat .vcup-ch, #valve4.cool .vcup-ch { stroke: var(--cold); }
#valve4 { outline: none; }
.pipe-halo.in { stroke: var(--unit-body); stroke-width: 15; }
.comp { fill: var(--unit-shade); stroke: var(--line-strong); stroke-width: 2; transition: stroke .5s; }
.comp-rotor { fill: none; stroke: var(--faint); stroke-width: 2; stroke-dasharray: 5 9; }
.heat-arrows { opacity: 0; transition: opacity .6s; }
.heat-arrows.show { opacity: 1; }
.heat-arrows path { fill: none; stroke: var(--warm); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; animation: heat-in 1.6s ease-in-out infinite; }
.ha-dir { transform-box: fill-box; transform-origin: center; transition: transform .6s; }
.heat-arrows.out .ha-dir { transform: scaleX(-1); }
@keyframes heat-in { 0% { transform: translateX(-5px); opacity: .25; } 60% { opacity: 1; } 100% { transform: translateX(5px); opacity: .25; } }
