:root {
  --bg-0: #070b18;
  --bg-1: #0b1020;
  --card: rgba(20, 26, 54, 0.55);
  --card-hi: rgba(35, 45, 90, 0.7);
  --line: rgba(120, 140, 200, 0.15);
  --text: #e9efff;
  --muted: #8694c2;
  --accent: #ffd166;
  --accent-2: #ffaa33;
  --cool: #60a5fa;
  --warm: #ef6a4d;
  --ok: #36e391;
  --bad: #ff5972;
  --shadow: 0 10px 40px -10px rgba(0,0,0,.6);
  --radius: 18px;
  --t: cubic-bezier(.2,.8,.2,1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 800px at 10% -10%, #1a2247 0%, var(--bg-0) 60%) fixed,
              radial-gradient(900px 600px at 110% 10%, #2a1a47 0%, transparent 60%) fixed,
              var(--bg-1);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ---- ORB di sfondo animati ---- */
.bg-orbs { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.orb {
  position: absolute; border-radius: 50%; filter: blur(60px); opacity: .55;
  animation: float 18s ease-in-out infinite;
}
.orb-1 { width: 520px; height: 520px; left: -120px; top: -100px;
  background: radial-gradient(circle at 30% 30%, #6c8cff, transparent 60%); }
.orb-2 { width: 460px; height: 460px; right: -120px; top: 30%;
  background: radial-gradient(circle at 40% 40%, #ff6cb0, transparent 60%);
  animation-delay: -6s; }
.orb-3 { width: 600px; height: 600px; left: 30%; bottom: -200px;
  background: radial-gradient(circle at 50% 50%, #4cd9c1, transparent 60%);
  animation-delay: -12s; }
@keyframes float {
  0%,100% { transform: translate(0,0) scale(1); }
  50%     { transform: translate(40px,-30px) scale(1.08); }
}

/* ---- TOP BAR ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  backdrop-filter: blur(14px);
  background: linear-gradient(180deg, rgba(7,11,24,.85), rgba(7,11,24,.45));
  border-bottom: 1px solid var(--line);
}
.brand { display:flex; align-items:center; gap:12px; }
.logo-mark {
  width: 38px; height: 38px; border-radius: 12px;
  background: conic-gradient(from 180deg, #ffd166, #ff7eb6, #6c8cff, #4cd9c1, #ffd166);
  position: relative; box-shadow: var(--shadow);
  animation: spin 12s linear infinite;
}
.logo-mark span {
  position:absolute; inset:4px; border-radius:9px; background: var(--bg-1);
}
@keyframes spin { to { transform: rotate(360deg); } }
.brand-title { font-weight: 700; letter-spacing: .3px; }
.brand-sub { font-size: 11px; color: var(--muted); }

.status {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: rgba(255,255,255,.03); font-size: 12px; color: var(--muted);
}
.status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); box-shadow: 0 0 0 0 currentColor;
  animation: pulse 2s infinite;
}
.status.ok    .dot { background: var(--ok);   color: var(--ok);   }
.status.err   .dot { background: var(--bad);  color: var(--bad);  }
.status.ok    .label { color: #b9ffe1; }
.status.err   .label { color: #ffd0d6; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0   rgba(54,227,145,.6); }
  70%  { box-shadow: 0 0 0 8px rgba(54,227,145,0);  }
  100% { box-shadow: 0 0 0 0   rgba(54,227,145,0);  }
}

/* ---- TABS (nascoste, restano per logica gotoTab) ---- */
.tabs { display: none; }
.tabs-legacy {
  position: sticky; top: 64px; z-index: 9;
  display: flex; gap: 6px; padding: 10px 12px;
  overflow-x: auto; scrollbar-width: none;
  background: linear-gradient(180deg, rgba(7,11,24,.7), rgba(7,11,24,.0));
}
.tabs::-webkit-scrollbar { display:none; }
.tab {
  flex: 0 0 auto;
  display:flex; align-items:center; gap:8px;
  padding: 10px 14px; border-radius: 12px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  color: var(--muted); font-weight: 600; font-size: 13px;
  cursor: pointer; transition: all .25s var(--t);
}
.tab svg { width: 18px; height: 18px; fill: currentColor; }
.tab:hover { color: var(--text); transform: translateY(-1px); }
.tab.active {
  color: var(--bg-0);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  box-shadow: 0 8px 20px -8px rgba(255,170,51,.7);
}
.tab.disabled { opacity: .35; pointer-events: none; }

/* ---- MAIN ---- */
main {
  position: relative; z-index: 1;
  padding: 14px 14px 80px; max-width: 1600px; margin: 0;
  display: grid; grid-template-columns: 320px 1fr; gap: 20px;
  align-items: start;
}
.sidebar {
  position: sticky; top: 76px;
  display: grid; gap: 10px; align-content: start;
}
.content { min-width: 0; }

@media (max-width: 820px) {
  main { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    grid-template-columns: repeat(2, 1fr);
  }
}
.page { display: none; animation: fadeUp .35s var(--t); }
.page.active { display: block; }
@keyframes fadeUp { from {opacity:0; transform: translateY(10px);} to {opacity:1; transform:none;} }

.page-head {
  display:flex; align-items:center; justify-content: space-between;
  margin: 12px 4px 14px; gap: 10px; flex-wrap: wrap;
}
.page-head h1 {
  margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.2px;
  background: linear-gradient(135deg, #fff, #b6c6ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.counters { display:flex; align-items:center; gap: 8px; flex-wrap: wrap; }
.badge {
  padding: 6px 12px; border-radius: 999px; font-size: 12px;
  color: var(--muted);
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
}
.badge b { color: var(--text); margin-right: 4px; }
.badge.dim { opacity: .8; }
.btn-ghost {
  padding: 8px 14px; border-radius: 12px; cursor:pointer;
  background: rgba(255,255,255,.04);
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 600; font-size: 13px;
  transition: all .2s var(--t);
}
.btn-ghost:hover { background: rgba(255,255,255,.08); transform: translateY(-1px); }

/* ---- FLOOR FILTER ---- */
.floor-filter { display:flex; gap:6px; margin: 6px 4px 16px; flex-wrap: wrap; }
.pill {
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  background: rgba(255,255,255,.04); color: var(--muted);
  border: 1px solid var(--line); font-size: 12px; font-weight: 600;
  letter-spacing: .3px; transition: all .25s var(--t);
}
.pill:hover { color: var(--text); transform: translateY(-1px); }
.pill.active {
  color: #052018;
  background: linear-gradient(135deg, #4cd9c1, #7af0e0);
  border-color: transparent;
  box-shadow: 0 8px 18px -8px rgba(76,217,193,.7);
}

/* ---- SUB HEADER ---- */
.sub-h {
  margin: 26px 4px 12px; font-size: 16px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 2px;
}

/* ---- CLIMA SWITCHES ---- */
.clima-switches {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.card-clima {
  position: relative; padding: 16px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--card), rgba(20,26,54,.25));
  border: 1px solid var(--line); cursor: pointer; overflow: hidden;
  transition: all .25s var(--t);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.card-clima:hover { transform: translateY(-2px); }
.card-clima .name { font-weight: 600; }
.card-clima .toggle {
  width: 46px; height: 26px; border-radius: 999px;
  background: rgba(255,255,255,.08); position: relative;
  transition: background .25s var(--t);
}
.card-clima .toggle::after {
  content:""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3);
  transition: transform .25s var(--t);
}
.card-clima.on  { border-color: rgba(255,209,102,.5);
  box-shadow: 0 10px 30px -10px rgba(255,170,51,.45); }
.card-clima.on .toggle { background: linear-gradient(135deg, #ffd166, #ff9d2a); }
.card-clima.on .toggle::after { transform: translateX(20px); }

/* ---- ZONES ---- */
.zones { display: flex; flex-direction: column; gap: 22px; }
.zone {
  background: linear-gradient(180deg, var(--card), rgba(20,26,54,.3));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.zone-head { display:flex; align-items:center; justify-content: space-between; margin-bottom: 12px; }
.zone-title { font-weight: 700; letter-spacing: .2px; font-size: 15px; }
.zone-count { font-size: 12px; color: var(--muted); }

.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

/* ---- LIGHT CARD ---- */
.card-light {
  position: relative;
  padding: 14px 12px 12px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(20,26,54,.6), rgba(20,26,54,.25));
  border: 1px solid var(--line);
  cursor: pointer; overflow: hidden;
  transition: transform .25s var(--t), border-color .25s var(--t), box-shadow .25s var(--t);
}
.card-light:hover { transform: translateY(-2px); border-color: rgba(255,209,102,.4); }
.card-light .bulb {
  width: 46px; height: 46px; border-radius: 50%; margin: 4px auto 10px;
  background: radial-gradient(circle at 50% 40%, #3a4170, #1a2042 70%);
  position: relative;
  transition: background .4s var(--t), box-shadow .4s var(--t);
}
.card-light .bulb::after {
  content:""; position: absolute; inset:-8px; border-radius:50%;
  background: radial-gradient(circle, rgba(255,209,102,.0), transparent 60%);
  transition: background .4s var(--t);
}
.card-light .name { text-align: center; font-size: 13px; color: var(--muted); }
.card-light .where { text-align: center; font-size: 10px; color: rgba(255,255,255,.25); margin-top: 2px; letter-spacing: .5px;}
.card-light.on {
  border-color: rgba(255,209,102,.6);
  box-shadow: 0 10px 30px -10px rgba(255,170,51,.55), inset 0 1px 0 rgba(255,255,255,.04);
}
.card-light.on .bulb {
  background: radial-gradient(circle at 50% 40%, #fff5c9, #ffd166 70%, #ff9d2a);
  box-shadow: 0 0 28px rgba(255,209,102,.85), 0 0 60px rgba(255,170,51,.35);
}
.card-light.on .bulb::after {
  background: radial-gradient(circle, rgba(255,209,102,.55), transparent 60%);
  animation: glowpulse 3s ease-in-out infinite;
}
.card-light.on .name { color: var(--text); }
@keyframes glowpulse {
  0%,100% { opacity: .8; transform: scale(1); }
  50%     { opacity: 1;  transform: scale(1.06); }
}
.card-light .ripple {
  position: absolute; inset: 0; pointer-events: none; border-radius: 14px;
}
.card-light .ripple::before {
  content:""; position: absolute; top:50%; left:50%; width: 10px; height: 10px;
  border-radius: 50%; background: rgba(255,209,102,.5);
  transform: translate(-50%,-50%) scale(0); opacity: 0;
}
.card-light.flash .ripple::before {
  animation: rip .55s var(--t);
}
@keyframes rip {
  0%   { transform: translate(-50%,-50%) scale(0);   opacity: .9; }
  100% { transform: translate(-50%,-50%) scale(24);  opacity: 0;  }
}

/* ---- SHUTTERS ---- */
.shutters {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.card-shutter {
  background: linear-gradient(180deg, var(--card), rgba(20,26,54,.25));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.card-shutter .label { font-weight: 600; font-size: 14px; display:flex; justify-content: space-between; align-items: center; }
.card-shutter .where { font-size: 10px; color: var(--muted); letter-spacing:.5px; }
.shut-view {
  position: relative; height: 70px; border-radius: 10px;
  background: linear-gradient(180deg, #0c1330, #06091c);
  border: 1px solid var(--line); overflow: hidden;
}
.shut-blind {
  position: absolute; top:0; left:0; right:0;
  background: repeating-linear-gradient(180deg, #243262 0 4px, #1a2554 4px 6px);
  border-bottom: 2px solid #3a4eaa;
  transition: height .4s var(--t);
}
.shut-blind.up   { height: 8%; }
.shut-blind.idle { height: 50%; }
.shut-blind.dn   { height: 100%; }
.shut-blind.moving::after {
  content:""; position:absolute; left:0; right:0; bottom:-2px; height:2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: scan 1.2s linear infinite;
}
@keyframes scan { 0%{transform:translateX(-100%);} 100%{transform:translateX(100%);} }

.shut-actions { display: flex; gap: 8px; justify-content: space-between; }
.shut-btn {
  flex: 1; padding: 10px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: rgba(255,255,255,.04);
  color: var(--text); font-weight: 600; font-size: 14px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: all .2s var(--t);
}
.shut-btn:hover { transform: translateY(-1px); background: rgba(255,255,255,.08); }
.shut-btn.up    { background: linear-gradient(135deg, #4cd9c1, #2dbe8d); color: #052018; border: none; }
.shut-btn.down  { background: linear-gradient(135deg, #6c8cff, #5468d8); color: #fff; border: none; }
.shut-btn.stop  { background: rgba(255,255,255,.06); }
.shut-btn:active { transform: scale(.97); }

/* ---- THERMOS ---- */
.thermos {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.card-thermo {
  position: relative;
  border-radius: var(--radius);
  padding: 18px;
  background: linear-gradient(180deg, var(--card), rgba(20,26,54,.3));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-thermo.heating::before {
  content:""; position: absolute; inset:-1px; border-radius: inherit; pointer-events: none;
  background: linear-gradient(135deg, rgba(239,106,77,.5), transparent 60%);
  animation: heatglow 3s ease-in-out infinite;
}
.card-thermo.cooling::before {
  content:""; position: absolute; inset:-1px; border-radius: inherit; pointer-events: none;
  background: linear-gradient(135deg, rgba(96,165,250,.55), transparent 60%);
  animation: heatglow 3s ease-in-out infinite;
}
@keyframes heatglow { 0%,100%{opacity:.6;} 50%{opacity:1;} }

.thermo-head { display:flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.thermo-label { font-weight: 700; }
.thermo-mode {
  font-size: 11px; padding: 4px 8px; border-radius: 999px;
  background: rgba(255,255,255,.06); color: var(--muted); text-transform: uppercase; letter-spacing: 1px;
}
.thermo-mode.heat { background: rgba(239,106,77,.18); color: #ffb29c; }
.thermo-mode.cool { background: rgba(96,165,250,.18); color: #a8c8ff; }
.thermo-mode.off  { background: rgba(140,150,200,.18); color: var(--muted); }

.thermo-dial {
  position: relative;
  width: 180px; height: 180px; margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
}
.dial-ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from -135deg,
    #60a5fa 0deg, #4cd9c1 90deg, #ffd166 180deg, #ef6a4d 270deg);
  mask: radial-gradient(circle at center, transparent 60%, #000 61%, #000 80%, transparent 81%);
  -webkit-mask: radial-gradient(circle at center, transparent 60%, #000 61%, #000 80%, transparent 81%);
  opacity: .85;
}
.dial-needle {
  position: absolute; top: 50%; left: 50%; height: 70px; width: 3px;
  margin-left: -1.5px; margin-top: -70px; transform-origin: bottom center;
  background: linear-gradient(180deg, #fff, transparent);
  transition: transform .8s var(--t);
  border-radius: 3px;
}
.dial-center {
  position: relative; z-index: 1; text-align: center;
}
.dial-center .temp {
  font-size: 38px; font-weight: 800; letter-spacing: -1px;
  background: linear-gradient(135deg, #fff, #b6c6ff);
  -webkit-background-clip:text; background-clip:text; color: transparent;
}
.dial-center .unit { font-size: 14px; color: var(--muted); margin-left: 2px; }
.dial-center .sp   { font-size: 12px; color: var(--muted); margin-top: 4px; }

.thermo-ctrl { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sp-btn {
  width: 38px; height: 38px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: rgba(255,255,255,.04);
  color: var(--text); font-size: 18px; font-weight: 700;
  transition: all .2s var(--t);
}
.sp-btn:hover { transform: translateY(-1px); background: rgba(255,255,255,.08); }
.sp-btn:active { transform: scale(.92); }
.sp-val { font-weight: 700; font-size: 17px; color: var(--text); min-width: 70px; text-align: center; }

.mode-row { display:flex; gap: 6px; margin-top: 12px; }
.mode-btn {
  flex:1; padding: 8px; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(255,255,255,.03);
  color: var(--muted); font-weight: 600; font-size: 12px; cursor: pointer;
  transition: all .2s var(--t);
}
.mode-btn:hover { color: var(--text); }
.mode-btn.sel.off  { background: rgba(140,150,200,.18); color: var(--text); border-color: transparent; }
.mode-btn.sel.heat { background: linear-gradient(135deg,#ef6a4d,#ffa56b); color:#180806; border-color: transparent; }
.mode-btn.sel.cool { background: linear-gradient(135deg,#60a5fa,#7cd1ff); color:#02112a; border-color: transparent; }
.mode-btn.sel.auto { background: linear-gradient(135deg,#4cd9c1,#7af0e0); color:#062a22; border-color: transparent; }

/* ---- SOLARE ---- */
.solar-grid { display: grid; gap: 16px; }

/* Flow PV → Casa ← Rete */
.flow {
  display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; gap: 10px;
  align-items: center;
  padding: 22px; border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255,209,102,.08), rgba(76,217,193,.06)), var(--card);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.flow-node {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px; border-radius: 14px;
  background: rgba(255,255,255,.03); border: 1px solid var(--line);
  min-width: 0;
}
.flow-node .flow-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 2px; }
.flow-node .flow-val {
  font-size: 24px; font-weight: 800; letter-spacing: -.5px;
  background: linear-gradient(135deg, #fff, #b6c6ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.flow-node .flow-val .unit { font-size: 14px; color: var(--muted); -webkit-text-fill-color: var(--muted); margin-left: 4px; }
.flow-node.sun .hero-sun { width: 64px; height: 64px; }
.flow-node.sun .sun-core { width: 36px; height: 36px; }
.flow-node.sun .flow-val {
  background: linear-gradient(135deg, #fff5c9, #ffd166 60%, #ff9d2a);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.house-svg, .grid-svg { width: 56px; height: 56px; fill: currentColor; opacity: .85; }
.flow-node.house { color: #7af0e0; }
.flow-node.grid  { color: #ff9d6b; }
.flow-node.grid.exporting { color: #4cd9c1; }
.flow-arrow {
  width: 100%; max-width: 120px; height: 40px; color: var(--muted);
  transition: color .3s var(--t);
}
.flow-arrow.active { color: var(--accent); animation: dash 1.2s linear infinite; }
.flow-arrow path { stroke-dasharray: 6 6; }
@keyframes dash { to { stroke-dashoffset: -24; } }
.flow-arrow.reverse { transform: scaleX(-1); }

.solar-hero {
  display: flex; align-items: center; gap: 22px;
  padding: 22px; border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255,209,102,.12), rgba(255,128,40,.08)), var(--card);
  border: 1px solid rgba(255,209,102,.25); box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.solar-hero::after {
  content:""; position:absolute; inset:-50% -50% auto auto; width: 60%; aspect-ratio: 1;
  background: radial-gradient(circle, rgba(255,209,102,.35), transparent 60%);
  filter: blur(40px); animation: float 9s ease-in-out infinite;
}
.hero-sun {
  position: relative; width: 110px; height: 110px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
}
.sun-core {
  width: 60px; height: 60px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff5c9, #ffd166 50%, #ff8a1f);
  box-shadow: 0 0 50px #ffaa33, 0 0 90px #ff7a00;
  animation: pulse-sun 3s ease-in-out infinite;
}
@keyframes pulse-sun {
  0%,100% { transform: scale(1); }
  50%     { transform: scale(1.06); }
}
.sun-rays {
  position: absolute; inset: 0;
  background:
    conic-gradient(from 0deg,
      transparent 0deg, rgba(255,209,102,.55) 6deg, transparent 12deg,
      transparent 30deg, rgba(255,209,102,.55) 36deg, transparent 42deg,
      transparent 60deg, rgba(255,209,102,.55) 66deg, transparent 72deg,
      transparent 90deg, rgba(255,209,102,.55) 96deg, transparent 102deg,
      transparent 120deg, rgba(255,209,102,.55) 126deg, transparent 132deg,
      transparent 150deg, rgba(255,209,102,.55) 156deg, transparent 162deg,
      transparent 180deg, rgba(255,209,102,.55) 186deg, transparent 192deg,
      transparent 210deg, rgba(255,209,102,.55) 216deg, transparent 222deg,
      transparent 240deg, rgba(255,209,102,.55) 246deg, transparent 252deg,
      transparent 270deg, rgba(255,209,102,.55) 276deg, transparent 282deg,
      transparent 300deg, rgba(255,209,102,.55) 306deg, transparent 312deg,
      transparent 330deg, rgba(255,209,102,.55) 336deg, transparent 342deg);
  mask: radial-gradient(circle, transparent 36px, #000 36px);
  -webkit-mask: radial-gradient(circle, transparent 36px, #000 36px);
  animation: spin 30s linear infinite;
  opacity: .9;
}
.hero-meta { flex: 1; min-width: 0; }
.hero-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 2px; }
.hero-power {
  font-weight: 800; letter-spacing: -1px; line-height: 1;
  font-size: 64px; margin: 6px 0 8px;
  background: linear-gradient(135deg, #fff5c9, #ffd166 60%, #ff9d2a);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-power .unit { font-size: 22px; margin-left: 6px; color: var(--accent); -webkit-text-fill-color: var(--accent); }
.hero-sub { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 2px; }
.hero-sub b { color: var(--text); margin: 0 4px; }

.solar-stats {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.stat {
  padding: 14px; border-radius: 14px;
  background: linear-gradient(180deg, var(--card), rgba(20,26,54,.25));
  border: 1px solid var(--line); box-shadow: var(--shadow);
  transition: transform .25s var(--t);
}
.stat:hover { transform: translateY(-2px); }
.stat-icon {
  font-size: 18px; width: 32px; height: 32px; border-radius: 10px;
  background: rgba(255,209,102,.12);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.stat-val { font-size: 22px; font-weight: 700; margin: 8px 0 2px; }
.stat-val .unit { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 4px; }
.stat-lab { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

.solar-info {
  margin-top: 8px; padding: 12px 16px; font-size: 12px; color: var(--muted);
  border-radius: 12px; background: rgba(255,255,255,.02); border: 1px solid var(--line);
}
.solar-info b { color: var(--text); }

@media (max-width: 720px) {
  .gate-hero { grid-template-columns: 1fr; }
  .flow { grid-template-columns: 1fr; }
  .flow-arrow {
    transform: rotate(90deg); height: 36px; width: 80px; justify-self: center;
  }
  .flow-arrow.reverse { transform: rotate(90deg) scaleX(-1); }
}
@media (max-width: 540px) {
  .hero-power { font-size: 44px; }
  .hero-sun { width: 80px; height: 80px; }
  .sun-core { width: 40px; height: 40px; }
}

/* ---- HOME ---- */
.home-grid {
  display: flex; flex-direction: column; gap: 14px;
}
.home-cam {
  display: flex; flex-direction: column; gap: 14px;
  min-width: 0; max-width: 560px;
}
.home-cam .cam-frame {
  aspect-ratio: 16/9; min-height: 180px;
  box-shadow: 0 24px 50px -16px rgba(0,0,0,.6),
              0 0 0 1px rgba(108,140,255,.2);
}
.home-cam .cam-frame::before {
  content:""; position:absolute; inset:-2px; border-radius: calc(var(--radius) + 2px);
  background: conic-gradient(from 0deg, rgba(108,140,255,.0), rgba(108,140,255,.5), rgba(255,209,102,.4), rgba(76,217,193,.4), rgba(108,140,255,.0));
  z-index: -1; filter: blur(8px); opacity: .55;
  animation: spin 12s linear infinite;
}
.home-cam .gate-btn.big {
  display: flex; align-items: center; justify-content: center;
  width: 100%; padding: 22px; font-size: 22px;
  background: linear-gradient(135deg, #4cd9c1, #2dbe8d 60%, #1a9e75);
  color: #02211a; box-shadow: 0 14px 40px -12px rgba(76,217,193,.7);
}
.home-cam .gate-btn.big:hover { box-shadow: 0 18px 50px -10px rgba(76,217,193,.9); }
.home-cam .gate-btn.big::after {
  content:""; position:absolute; inset:0; border-radius:inherit;
  background: radial-gradient(circle at 50% 0%, rgba(255,255,255,.45), transparent 50%);
  pointer-events:none;
}

/* .home-tiles non più usata (rimosse dalla page-home, ora sidebar globale) */
.home-tiles { display: none; }

.tile {
  --tc1: #6c8cff; --tc2: #4a5fcf;
  position: relative; cursor: pointer;
  padding: 18px 18px; border-radius: 16px;
  background:
    radial-gradient(120% 80% at 100% 0%, color-mix(in srgb, var(--tc1) 35%, transparent), transparent 60%),
    radial-gradient(80% 100% at 0% 100%, color-mix(in srgb, var(--tc2) 25%, transparent), transparent 55%),
    linear-gradient(180deg, rgba(20,26,54,.85), rgba(12,16,40,.7));
  border: 1px solid color-mix(in srgb, var(--tc1) 30%, var(--line));
  box-shadow: var(--shadow);
  display: grid; grid-template-columns: 52px 1fr; gap: 4px 14px;
  align-items: center; color: var(--text); text-align: left;
  overflow: hidden; min-height: 84px;
  transition: transform .25s var(--t), box-shadow .3s var(--t), border-color .3s var(--t);
}
.tile svg { grid-row: span 2; }
.tile-name { grid-column: 2; align-self: end; }
.tile-info { grid-column: 2; align-self: start; }
.tile::before {
  content:""; position: absolute; right:-30px; top:-30px;
  width: 110px; height: 110px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--tc1) 45%, transparent), transparent 70%);
  filter: blur(20px); opacity: .85; transition: transform .5s var(--t);
}
.tile:hover {
  transform: translateX(4px);
  border-color: var(--tc1);
  box-shadow: 0 22px 60px -16px color-mix(in srgb, var(--tc1) 70%, transparent);
}
.tile.active {
  border-color: var(--tc1);
  background:
    radial-gradient(120% 80% at 100% 0%, color-mix(in srgb, var(--tc1) 55%, transparent), transparent 60%),
    radial-gradient(80% 100% at 0% 100%, color-mix(in srgb, var(--tc2) 45%, transparent), transparent 55%),
    linear-gradient(180deg, rgba(35,45,90,.9), rgba(20,26,54,.8));
  box-shadow: 0 14px 40px -14px color-mix(in srgb, var(--tc1) 70%, transparent);
}
.tile.active::after {
  content:""; position: absolute; left: 0; top: 12%; bottom: 12%;
  width: 4px; border-radius: 0 4px 4px 0;
  background: var(--tc1);
  box-shadow: 0 0 12px var(--tc1);
}
.tile:hover::before { transform: scale(1.4); }
.tile:active { transform: scale(.96); }
.tile svg {
  width: 32px; height: 32px; fill: var(--tc1);
  filter: drop-shadow(0 2px 8px color-mix(in srgb, var(--tc1) 60%, transparent));
  transition: transform .3s var(--t);
}
.tile:hover svg { transform: scale(1.15) rotate(-4deg); }
.tile-name { font-weight: 800; font-size: 15px; letter-spacing: -.2px; }
.tile-info { color: var(--muted); font-size: 11px; font-weight: 500; }
.tile.dim { opacity: .35; pointer-events: none; filter: grayscale(.5); }

.tile[data-go="home"]        { --tc1: #6c8cff; --tc2: #3a4eaa; }
.tile[data-go="luci"]        { --tc1: #ffd166; --tc2: #ff8a1f; }
.tile[data-go="tapparelle"]  { --tc1: #6c8cff; --tc2: #3a4eaa; }
.tile[data-go="termo"]       { --tc1: #ff7e5f; --tc2: #d63838; }
.tile[data-go="solare"]      { --tc1: #ffe16e; --tc2: #ffa133; }
.tile[data-go="trend"]       { --tc1: #b388ff; --tc2: #7c4dff; }
.tile[data-go="varchi"]      { --tc1: #4cd9c1; --tc2: #00a896; }
.tile[data-go="automazioni"] { --tc1: #ff7bd1; --tc2: #c63bd5; }
.tile[data-go="allarme"]     { --tc1: #ff5972; --tc2: #b80024; }

/* icone animate sottilmente */
@keyframes wob   { 50% { transform: scale(1.06) rotate(2deg); } }
@keyframes drift { 50% { transform: translateY(-2px); } }
.tile:nth-child(odd)  svg { animation: drift 4s ease-in-out infinite; }
.tile:nth-child(even) svg { animation: wob   5s ease-in-out infinite; }

/* Camera placeholder */
.cam-frame { isolation: isolate; }
.cam-frame .cam-loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px; letter-spacing: 1px; text-transform: uppercase;
  background: linear-gradient(135deg, #0a1230 0%, #0e1840 100%);
  z-index: 0;
  background-image:
    linear-gradient(135deg, rgba(255,255,255,.04) 25%, transparent 25%, transparent 50%,
                     rgba(255,255,255,.04) 50%, rgba(255,255,255,.04) 75%,
                     transparent 75%, transparent),
    linear-gradient(135deg, #0a1230 0%, #0e1840 100%);
  background-size: 20px 20px, 100% 100%;
  animation: stripeMove 1.4s linear infinite;
}
.cam-frame img { position: relative; z-index: 1; }
.cam-frame img.err { display: none; }
@keyframes stripeMove { to { background-position: 20px 0, 0 0; } }

@media (max-width: 820px) {
  .home-grid { grid-template-columns: 1fr; }
  .home-tiles { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 380px) {
  .home-tiles { grid-template-columns: 1fr; }
}

/* ---- VARCHI ---- */
.gate-hero {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px;
  margin-bottom: 14px;
}
.cam-frame {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: #000; aspect-ratio: 16/9; min-height: 200px;
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.cam-frame img { width: 100%; height: 100%; object-fit: cover; display: block;
  position: absolute; inset: 0; }
.cam-overlay {
  position: absolute; top: 12px; left: 12px;
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(0,0,0,.6); color: #fff; font-size: 11px;
  text-transform: uppercase; letter-spacing: 2px;
}
.rec-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #ff3b3b;
  box-shadow: 0 0 8px #ff3b3b;
  animation: rec 1.4s ease-in-out infinite;
}
@keyframes rec { 50% { opacity: .3; } }

.gate-action {
  display: flex; flex-direction: column; gap: 10px;
  padding: 22px; border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255,209,102,.10), rgba(76,217,193,.06)), var(--card);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  justify-content: center;
}
.gate-title { font-weight: 700; font-size: 18px; }
.gate-sub   { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; }
.gate-btn {
  margin-top: 6px; padding: 14px 18px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b1020; border: none; cursor: pointer;
  font-weight: 800; letter-spacing: 2px; font-size: 14px;
  transition: transform .15s var(--t), box-shadow .25s var(--t);
}
.gate-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 30px -10px rgba(255,170,51,.7); }
.gate-btn:active { transform: scale(.97); }
.gate-btn.big { padding: 22px; font-size: 22px; }
.gate-btn.fired { animation: gateflash .6s ease; }
@keyframes gateflash {
  0%,100% { box-shadow: 0 0 0 rgba(76,217,193,0); }
  50%     { box-shadow: 0 0 40px rgba(76,217,193,.8); }
}
.gate-response { font-size: 11px; color: var(--muted); min-height: 1em; }

.gates-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.gate-card {
  padding: 18px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--card), rgba(20,26,54,.25));
  border: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}

/* ---- AUTOMAZIONI ---- */
.auto-card {
  padding: 16px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--card), rgba(20,26,54,.25));
  border: 1px solid var(--line); box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.auto-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.auto-row .dim { color: var(--muted); font-size: 12px; }
.toggle-row { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.toggle-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }

.slots { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.slot {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(255,255,255,.03);
}
.slot input[type=time] {
  background: rgba(255,255,255,.04); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
  font-family: inherit; font-size: 14px;
  color-scheme: dark;
}
.slot .dash { color: var(--muted); }
.slot .rm {
  margin-left: auto; padding: 4px 10px; border-radius: 8px;
  background: rgba(255,89,114,.15); color: #ffd0d6;
  border: 1px solid rgba(255,89,114,.3); cursor: pointer; font-size: 12px;
}

.lights-auto {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.light-auto {
  padding: 14px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--card), rgba(20,26,54,.25));
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.light-auto-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.light-auto-title { font-weight: 700; }
.light-auto-where { color: var(--muted); font-size: 11px; }
.mode-pills { display: flex; gap: 6px; margin-bottom: 10px; }
.mode-pills .pill { flex: 1; padding: 6px; text-align: center; font-size: 11px; }
.astro-row { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 8px; }
.astro-row input[type=number] {
  width: 60px; background: rgba(255,255,255,.04); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px;
}

/* ---- TREND CHART ---- */
.chart-wrap {
  position: relative; margin: 12px 4px;
  padding: 18px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--card), rgba(20,26,54,.25));
  border: 1px solid var(--line); box-shadow: var(--shadow);
  height: 60vh; min-height: 320px;
}
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* ---- PLACEHOLDER ---- */
.placeholder {
  margin: 60px auto; max-width: 480px; text-align: center;
  padding: 30px; border: 1px dashed var(--line); border-radius: var(--radius);
  background: rgba(255,255,255,.02); color: var(--muted);
}
.placeholder h1 { color: var(--text); margin-top: 0; }

/* ---- RESPONSIVE ---- */
@media (max-width: 540px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(115px, 1fr)); gap: 10px; }
  .page-head h1 { font-size: 22px; }
  .tab span { display: none; }
  .tab { padding: 10px; }
  .thermo-dial { width: 150px; height: 150px; }
  .dial-needle { height: 58px; margin-top: -58px; }
  .dial-center .temp { font-size: 30px; }
}

/* ============================================================
   LOGIN PAGE — usata via /login.html quando si accede da Internet
   ============================================================ */
body.login-page {
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-wrap {
  position: relative; z-index: 2; width: 100%;
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  width: min(420px, 100%);
  background: linear-gradient(145deg, rgba(35,45,90,.85), rgba(20,26,54,.85));
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 36px 30px 26px;
  box-shadow: var(--shadow), 0 0 80px -20px rgba(120,140,255,.35);
  backdrop-filter: blur(12px);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-logo {
  width: 64px; height: 64px; margin: 0 auto 8px;
  display: grid; place-items: center; font-size: 34px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  border-radius: 50%;
  box-shadow: 0 0 28px rgba(255, 209, 102, .55);
  animation: floaty 4s ease-in-out infinite;
}
@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}
.login-brand h1 { margin: 6px 0 2px; font-weight: 700; letter-spacing: -0.5px; }

.lf-field {
  display: block; margin: 14px 0;
}
.lf-field span {
  display: block; font-size: 12px; text-transform: uppercase;
  letter-spacing: .12em; color: var(--muted); margin-bottom: 6px;
}
.lf-field input {
  width: 100%; padding: 12px 14px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text); font-size: 16px;
  transition: border-color .2s var(--t), background .2s var(--t);
}
.lf-field input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255,255,255,.08);
}
.lf-remember {
  display: flex; align-items: center; gap: 8px;
  margin: 14px 0 18px; color: var(--muted); font-size: 14px; cursor: pointer;
}
.lf-remember input { accent-color: var(--accent); width: 16px; height: 16px; }
.lf-submit {
  display: block; width: 100%;
  padding: 13px; border: 0; border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: #1a1100; font-weight: 700; font-size: 16px; letter-spacing: .03em;
  cursor: pointer; transition: transform .15s var(--t), box-shadow .2s var(--t);
}
.lf-submit:hover { transform: translateY(-1px); box-shadow: 0 8px 24px -8px rgba(255,170,51,.7); }
.lf-submit:active { transform: translateY(0); }
.lf-err {
  margin: 10px 0 0; min-height: 1.2em;
  color: var(--bad); font-size: 14px; text-align: center;
}
.login-foot { text-align: center; margin: 22px 0 0; font-size: 12px; letter-spacing: .08em; }

/* ============================================================
   SIDEBAR — tile Setup e box utente in fondo
   ============================================================ */
.tile-setup { --tc1: #a78bfa; --tc2: #6366f1; }

.sidebar-user {
  margin-top: 16px; padding: 12px 14px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.su-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .14em;
  color: var(--muted);
}
.su-name { font-weight: 700; color: var(--text); font-size: 14px; }
.su-logout {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(255, 89, 114, .12);
  border: 1px solid rgba(255, 89, 114, .3);
  color: var(--bad);
  border-radius: 10px;
  font-size: 13px; cursor: pointer;
  transition: background .15s var(--t);
}
.su-logout:hover { background: rgba(255, 89, 114, .22); }

/* ============================================================
   PAGINA SETUP — tabella utenti + form nuovo utente
   ============================================================ */
.users-table {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
.users-table th, .users-table td {
  padding: 10px 12px; text-align: left;
  border-bottom: 1px solid var(--line);
}
.users-table th {
  color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .1em; font-size: 11px;
}
.users-table td .role-pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .1em; font-weight: 700;
}
.role-pill.admin { background: rgba(167, 139, 250, .15); color: #c4b5fd; border: 1px solid rgba(167,139,250,.4); }
.role-pill.user  { background: rgba(96, 165, 250, .12); color: #93c5fd; border: 1px solid rgba(96,165,250,.4); }
.users-table button {
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
  color: var(--text); padding: 5px 10px; border-radius: 8px;
  font-size: 12px; cursor: pointer; margin-right: 4px;
}
.users-table button.del { color: var(--bad); border-color: rgba(255,89,114,.3); }
.users-table button:hover { background: rgba(255,255,255,.1); }

.users-form {
  display: grid; grid-template-columns: 1fr 1fr 120px auto; gap: 10px; align-items: end;
}
.users-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.users-form input, .users-form select {
  padding: 9px 11px; background: rgba(255,255,255,.05);
  border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-size: 14px;
}
.users-form .btn-prim {
  padding: 10px 16px; border: 0; border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: #1a1100; font-weight: 700; cursor: pointer;
}
.users-form .err { grid-column: 1 / -1; color: var(--bad); margin: 0; min-height: 1.2em; }

@media (max-width: 720px) {
  .users-form { grid-template-columns: 1fr 1fr; }
  .users-form .btn-prim { grid-column: 1 / -1; }
}


/* ============================================================
   ALLARME — Tecnoalarm EV50 (CSS basico, no aspect-ratio)
   ============================================================ */
.tile-alarm { --tc1: #ef4444; --tc2: #b91c1c; }

/* ---- Card home compatta cliccabile ---- */
.home-alarm-card {
  display: flex; align-items: center; gap: 14px;
  margin-top: 14px; padding: 12px 16px;
  background: rgba(35, 45, 90, .55);
  border: 1px solid var(--line);
  border-radius: 14px;
  text-decoration: none; color: var(--text);
  cursor: pointer;
}
.home-alarm-card:hover { border-color: rgba(239, 68, 68, .4); }
.hac-icon {
  width: 44px; height: 44px; min-width: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(145deg, #ef4444, #b91c1c);
}
.hac-icon svg { width: 22px; height: 22px; fill: white; }
.hac-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.hac-label { font-size: 10px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); font-weight: 700; }
.hac-state { font-size: 16px; font-weight: 700; color: var(--text); }
.hac-sub { font-size: 12px; color: var(--muted); }
.hac-arrow { font-size: 24px; color: var(--muted); }
.home-alarm-card.is-armed { border-color: rgba(34, 197, 94, .5); }
.home-alarm-card.is-armed .hac-state { color: #22c55e; }
.home-alarm-card.is-alarm { border-color: #ef4444; }
.home-alarm-card.is-alarm .hac-state { color: #ef4444; }
.home-alarm-card.is-off .hac-state { color: var(--muted); }

/* ---- Banner top pagina ---- */
.al-banner {
  margin-bottom: 22px; padding: 16px 18px;
  background: rgba(35, 45, 90, .5);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.alb-main { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.alb-light { width: 14px; height: 14px; border-radius: 50%; background: var(--muted); display: inline-block; }
.alb-text { display: flex; flex-direction: column; }
.alb-headline { font-size: 18px; font-weight: 700; color: var(--text); }
.alb-sub { font-size: 13px; color: var(--muted); }
.al-banner.is-ok .alb-light    { background: #22c55e; box-shadow: 0 0 12px #22c55e; }
.al-banner.is-armed .alb-light { background: #22c55e; box-shadow: 0 0 14px #22c55e; }
.al-banner.is-warn .alb-light  { background: #f59e0b; box-shadow: 0 0 14px #f59e0b; }
.al-banner.is-alarm { border-color: #ef4444; }
.al-banner.is-alarm .alb-light { background: #ef4444; box-shadow: 0 0 16px #ef4444; }
.alb-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.alb-chip {
  font-size: 11px; padding: 4px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, .05); color: var(--muted);
  border: 1px solid var(--line);
}
.alb-chip.ok { color: #22c55e; border-color: rgba(34, 197, 94, .3); }
.alb-chip.warn { color: #f59e0b; border-color: rgba(245, 158, 11, .35); }
.alb-chip.bad { color: #ef4444; border-color: rgba(239, 68, 68, .35); }

/* ---- Section header ---- */
.al-h {
  font-size: 13px; text-transform: uppercase; letter-spacing: .14em;
  color: var(--muted); font-weight: 700; margin: 20px 0 10px;
}
.al-h .small { font-size: 11px; font-weight: 500; margin-left: 8px; color: var(--muted); }
.al-section { margin-top: 8px; }
.al-section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 12px; }
.al-legend { display: flex; flex-wrap: wrap; gap: 6px; }
.al-legend .lg {
  font-size: 10px; text-transform: uppercase; letter-spacing: .1em; font-weight: 700;
  padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line);
}
.lg-ok    { color: #22c55e; border-color: rgba(34, 197, 94, .35); }
.lg-open  { color: #f59e0b; border-color: rgba(245, 158, 11, .4); }
.lg-alarm { color: #ef4444; border-color: rgba(239, 68, 68, .4); }
.lg-iso   { color: #c4b5fd; border-color: rgba(168, 85, 247, .4); }

/* ---- Programmi: 3 cards ---- */
.al-progs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.al-prog {
  min-height: 160px;
  padding: 16px;
  background: rgba(20, 26, 54, .6);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.alp-head { display: flex; align-items: center; gap: 10px; }
.alp-led { width: 12px; height: 12px; min-width: 12px; border-radius: 50%; background: rgba(255, 255, 255, .2); }
.alp-num { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .15em; text-transform: uppercase; }
.alp-title { font-size: 15px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alp-state { font-size: 13px; color: var(--muted); min-height: 1.3em; }
.alp-btn {
  margin-top: auto;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  font-weight: 700; font-size: 13px; letter-spacing: .04em;
  cursor: pointer;
}
.alp-btn:hover { background: rgba(255, 255, 255, .12); }
.alp-btn.arm { color: #22c55e; border-color: rgba(34, 197, 94, .4); }
.alp-btn.dis { color: #ef4444; border-color: rgba(239, 68, 68, .4); }
.al-prog.armed { border-color: rgba(34, 197, 94, .5); }
.al-prog.armed .alp-led { background: #22c55e; box-shadow: 0 0 10px #22c55e; }
.al-prog.armed .alp-state { color: #22c55e; font-weight: 600; }
.al-prog.exiting { border-color: rgba(245, 158, 11, .5); }
.al-prog.exiting .alp-led { background: #f59e0b; box-shadow: 0 0 10px #f59e0b; }
.al-prog.exiting .alp-state { color: #f59e0b; font-weight: 600; }
.al-prog.alarm { border-color: #ef4444; }
.al-prog.alarm .alp-led { background: #ef4444; box-shadow: 0 0 12px #ef4444; }
.al-prog.alarm .alp-state { color: #ef4444; font-weight: 700; }

@media (max-width: 760px) {
  .al-progs { grid-template-columns: 1fr; }
}

/* ---- Zone: griglia con altezze esplicite (NO aspect-ratio) ---- */
.al-zones {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px; margin-top: 10px;
}
@media (min-width: 480px) { .al-zones { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 900px) { .al-zones { grid-template-columns: repeat(8, minmax(0, 1fr)); } }

.al-zone {
  height: 86px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .04);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  display: flex; flex-direction: column; justify-content: space-between;
  overflow: hidden;
  font: inherit;
}
.al-zone:hover { background: rgba(255, 255, 255, .07); }
.azn-top {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10px; color: var(--muted); font-weight: 700; letter-spacing: .1em;
}
.azn-dot {
  width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 255, 255, .2);
  display: inline-block;
}
.azn-name {
  font-size: 12px; font-weight: 600; color: var(--text);
  line-height: 1.25; overflow: hidden;
}
.azn-flags { display: flex; gap: 3px; flex-wrap: wrap; }
.azn-flag {
  font-size: 8px; padding: 1px 5px; border-radius: 3px;
  background: rgba(255, 89, 114, .15); color: #fda4af;
  text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
}
.al-zone.empty   { opacity: .35; cursor: default; }
.al-zone.empty:hover { background: rgba(255, 255, 255, .04); }
.al-zone.ok      { border-color: rgba(34, 197, 94, .35); background: rgba(34, 197, 94, .08); }
.al-zone.ok .azn-dot { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.al-zone.open    { border-color: rgba(245, 158, 11, .5); background: rgba(245, 158, 11, .1); }
.al-zone.open .azn-dot { background: #f59e0b; box-shadow: 0 0 6px #f59e0b; }
.al-zone.alarm   { border-color: #ef4444; background: rgba(239, 68, 68, .16); }
.al-zone.alarm .azn-dot { background: #ef4444; box-shadow: 0 0 8px #ef4444; }
.al-zone.isolated{ border-color: rgba(168, 85, 247, .45); background: rgba(168, 85, 247, .1); }
.al-zone.isolated .azn-dot { background: #a78bfa; }

/* ---- Tastiera virtuale: tasti 56x56 ESPLICITI ---- */
.al-keypad {
  max-width: 320px;
  padding: 14px;
  background: rgba(20, 26, 54, .6);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.kp-display {
  background: #061206;
  border: 2px solid #1f3a1f;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
  font-family: "Courier New", monospace;
}
.kp-line {
  color: #33ff33;
  font-size: 14px;
  letter-spacing: 2px;
  min-height: 1.4em;
  text-shadow: 0 0 8px rgba(51, 255, 51, .5);
  white-space: pre;
  margin: 0;
}
.kp-leds {
  display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px;
  min-height: 1.4em;
}
.kp-led {
  font-size: 9px; padding: 2px 5px; border-radius: 3px;
  background: rgba(255, 255, 255, .05); color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.kp-led.on { background: rgba(34, 197, 94, .2); color: #22c55e; box-shadow: 0 0 6px rgba(34, 197, 94, .35); }

/* GRID FORZATO + altezze esplicite (no aspect-ratio) */
.kp-keys {
  display: grid !important;
  grid-template-columns: repeat(4, 64px);
  grid-auto-rows: 64px;
  gap: 6px;
  justify-content: center;
}
.kp-key {
  height: 64px; width: 64px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 20px; font-weight: 700;
  cursor: pointer;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 0;
}
.kp-key:hover { background: rgba(255, 255, 255, .14); }
.kp-key.fn { font-size: 14px; }
.kp-key.fn small { display: block; font-size: 8px; font-weight: 600; color: var(--muted); letter-spacing: .06em; margin-top: 1px; }
.kp-key.ok { color: #22c55e; border-color: rgba(34, 197, 94, .35); }
.kp-key.no { color: #f59e0b; border-color: rgba(245, 158, 11, .35); }
.kp-key.esc { color: var(--bad); border-color: rgba(255, 89, 114, .35); }

@media (max-width: 380px) {
  .kp-keys { grid-template-columns: repeat(4, 56px); grid-auto-rows: 56px; }
  .kp-key  { width: 56px; height: 56px; font-size: 18px; }
}

@keyframes al-blink { 0%, 100% { opacity: 1; } 50% { opacity: .65; } }
.al-banner.is-alarm, .home-alarm-card.is-alarm, .al-prog.alarm, .al-zone.alarm {
  animation: al-blink .9s infinite;
}

/* ============================================================
   MITSUBISHI ECODAN (caldaia / pompa di calore)
   ============================================================ */
.tile-mitsu { --tc1: #06b6d4; --tc2: #0e7490; }

.mitsu-ctrl, .mitsu-setpoints {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.mc-card {
  background: rgba(20, 26, 54, .6);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.mc-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .14em;
  color: var(--muted); font-weight: 700;
}
.mc-state { font-size: 13px; color: var(--text); font-weight: 600; }
.mc-row { display: flex; gap: 8px; flex-wrap: wrap; }
.mc-btn {
  flex: 1; min-width: 80px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  font-weight: 700; font-size: 13px;
  cursor: pointer;
}
.mc-btn:hover { background: rgba(255, 255, 255, .12); }
.mc-btn.off { color: var(--bad); border-color: rgba(255, 89, 114, .35); }
.mc-btn.ghost { background: transparent; }

.mc-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.mc-pills button {
  padding: 6px 10px; border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .04);
  color: var(--muted);
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  cursor: pointer;
}
.mc-pills button:hover { background: rgba(255, 255, 255, .1); color: var(--text); }
.mc-pills button.active {
  background: linear-gradient(145deg, #06b6d4, #0e7490);
  color: white; border-color: #06b6d4;
  box-shadow: 0 0 14px -4px rgba(6, 182, 212, .6);
}

.mc-spinner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.mc-bump {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .06);
  color: var(--text); font-size: 22px; font-weight: 700;
  cursor: pointer;
}
.mc-bump:hover { background: rgba(255, 255, 255, .14); }
.mc-temp {
  font-size: 28px; font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.mc-temp.dim { color: var(--muted); }

.mitsu-sensors {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px; margin-bottom: 20px;
}
.ms-sensor {
  padding: 12px 14px;
  background: rgba(20, 26, 54, .55);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.ms-sensor .ms-label { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.ms-sensor .ms-value { font-size: 20px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.ms-sensor .ms-unit  { font-size: 12px; color: var(--muted); margin-left: 2px; }

.mitsu-info {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}
.mi-row {
  padding: 8px 12px;
  background: rgba(20, 26, 54, .45);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.mi-row .mi-k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.mi-row .mi-v { font-size: 13px; font-weight: 700; color: var(--text); }
.mi-row.on  .mi-v { color: #22c55e; }

/* ============================================================
   HOME GATES — bottoni grandi (cancello + 2 sezionali)
   ============================================================ */
.home-gates {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}
.home-gate {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  min-height: 78px;
  padding: 12px 8px;
  background: linear-gradient(145deg, rgba(35,45,90,.7), rgba(20,26,54,.7));
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  cursor: pointer;
  transition: transform .12s var(--t), border-color .15s var(--t), box-shadow .2s var(--t);
}
.home-gate svg { width: 26px; height: 26px; fill: currentColor; }
.home-gate .hg-label { font-size: 13px; font-weight: 700; letter-spacing: .04em; }
.home-gate .hg-sub   { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.home-gate:hover     { transform: translateY(-1px); }
.home-gate:active    { transform: translateY(0); }
.home-gate.gate-cancello { color: #ffd166; border-color: rgba(255,209,102,.35); }
.home-gate.gate-cancello:hover { box-shadow: 0 0 18px -5px rgba(255,209,102,.5); }
.home-gate.gate-sez      { color: #60a5fa; border-color: rgba(96,165,250,.35); }
.home-gate.gate-sez:hover { box-shadow: 0 0 18px -5px rgba(96,165,250,.5); }
.home-gate.pulsing       { animation: gate-flash .8s; }
@keyframes gate-flash {
  0%   { background: rgba(34,197,94,.4); }
  100% { background: linear-gradient(145deg, rgba(35,45,90,.7), rgba(20,26,54,.7)); }
}

/* ============================================================
   KIOSK MODE — Akuvox X933 (1024×600 landscape)
   Tutto molto più grande del default desktop.
   ============================================================ */
body.kiosk {
  overflow: hidden;
  font-size: 18px;
}
body.kiosk .bg-orbs { opacity: .35; }

/* layout: sidebar 280px + content */
body.kiosk main {
  grid-template-columns: 280px 1fr;
  margin: 0;
  height: 100vh;
}
body.kiosk .sidebar {
  padding: 12px;
  gap: 8px;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
}
body.kiosk .tile {
  padding: 12px 14px;
  min-height: 0;
  gap: 4px;
  border-radius: 14px;
}
body.kiosk .tile svg { width: 28px; height: 28px; }
body.kiosk .tile-name { font-size: 16px; font-weight: 700; }
body.kiosk .tile-info { font-size: 12px; }

/* topbar e tab orizzontali nascosti */
body.kiosk .topbar { display: none; }
body.kiosk .tabs   { display: none; }
body.kiosk .content {
  max-height: 100vh;
  overflow-y: auto;
  padding: 32px 22px 22px;     /* + spazio sopra per non incollare al bordo */
}

/* page head più grande */
body.kiosk .page-head h1 { font-size: 28px; }
body.kiosk .page-head .badge { font-size: 14px; padding: 6px 12px; }
body.kiosk .sub-h, body.kiosk .al-h { font-size: 16px; margin: 20px 0 12px; }

/* touch target minimi */
body.kiosk .card-light, body.kiosk .card-shutter,
body.kiosk .alp-btn, body.kiosk .mc-btn,
body.kiosk .ap-btn, body.kiosk .kp-key, body.kiosk .vk-key {
  min-height: 64px;
  font-size: 15px;
}
body.kiosk .card-light .name { font-size: 15px; }
body.kiosk .card-light .bulb { width: 36px; height: 36px; }

/* HOME: layout adattato 1024x600 */
body.kiosk .home-grid { grid-template-columns: 1fr; gap: 14px; }
body.kiosk .home-cam { max-width: 100%; }
/* immagine cam intera, no crop in alto */
body.kiosk .cam-frame      { max-height: 300px; aspect-ratio: auto; height: 300px; }
body.kiosk .cam-frame img  { object-fit: contain; background: #000; }
body.kiosk .cam-loading    { font-size: 13px; }
body.kiosk .home-gate {
  min-height: 96px;
  padding: 14px 10px;
}
body.kiosk .home-gate svg     { width: 34px; height: 34px; }
body.kiosk .home-gate .hg-label { font-size: 17px; }
body.kiosk .home-gate .hg-sub   { font-size: 11px; }

/* home alarm card più grande */
body.kiosk .home-alarm-card {
  padding: 16px 18px; gap: 18px;
  margin-top: 14px;
}
body.kiosk .hac-icon { width: 56px; height: 56px; min-width: 56px; }
body.kiosk .hac-icon svg { width: 28px; height: 28px; }
body.kiosk .hac-state { font-size: 20px; }
body.kiosk .hac-sub   { font-size: 14px; }
body.kiosk .hac-arrow { font-size: 36px; }

/* griglie tile più larghe per touch */
body.kiosk .grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

/* tapparelle */
body.kiosk .card-shutter .name { font-size: 14px; }

/* termo: dial più piccolo per stare nei 600px */
body.kiosk .thermo-dial { width: 180px; height: 180px; }

/* allarme: programmi più grandi */
body.kiosk .al-progs { gap: 14px; }
body.kiosk .al-prog  { min-height: 180px; padding: 18px; }
body.kiosk .alp-title { font-size: 17px; }
body.kiosk .alp-state { font-size: 14px; }
body.kiosk .alp-btn   { padding: 14px; font-size: 14px; }

/* allarme: zone più grandi */
body.kiosk .al-zones { gap: 10px; }
body.kiosk .al-zone  { height: 104px; padding: 12px 14px; }
body.kiosk .azn-name { font-size: 14px; }
body.kiosk .azn-top  { font-size: 12px; }

/* tastiera virtuale: tasti più grandi */
body.kiosk .al-keypad { max-width: 100%; padding: 20px; }
body.kiosk .kp-keys   { grid-template-columns: repeat(8, 72px); grid-auto-rows: 72px; gap: 8px; justify-content: start; }
body.kiosk .kp-key    { width: 72px; height: 72px; font-size: 22px; }
body.kiosk .kp-display .kp-line { font-size: 18px; }

/* caldaia: card controllo */
body.kiosk .mc-card { padding: 18px; }
body.kiosk .mc-label { font-size: 12px; }
body.kiosk .mc-state { font-size: 16px; }
body.kiosk .mc-btn   { padding: 14px 16px; font-size: 14px; }
body.kiosk .mc-pills button { padding: 9px 14px; font-size: 13px; }
body.kiosk .mc-bump  { width: 52px; height: 52px; font-size: 28px; }
body.kiosk .mc-temp  { font-size: 34px; }
body.kiosk .ms-sensor .ms-label { font-size: 11px; }
body.kiosk .ms-sensor .ms-value { font-size: 24px; }
body.kiosk .mi-row .mi-k { font-size: 12px; }
body.kiosk .mi-row .mi-v { font-size: 15px; }

/* badge stato banner allarme/caldaia più visibili */
body.kiosk .al-banner { padding: 16px 20px; margin-bottom: 18px; }
body.kiosk .alb-headline { font-size: 22px; }
body.kiosk .alb-sub { font-size: 14px; }
body.kiosk .alb-chip { font-size: 13px; padding: 5px 12px; }
body.kiosk .alb-light { width: 18px; height: 18px; }

/* setup/utente non rilevanti in kiosk */
body.kiosk .sidebar-user, body.kiosk .tile-setup { display: none !important; }

/* scrollbar interna sottile ma visibile */
body.kiosk .sidebar::-webkit-scrollbar, body.kiosk .content::-webkit-scrollbar { width: 8px; }
body.kiosk .sidebar::-webkit-scrollbar-thumb,
body.kiosk .content::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }
