/* Dashboard Casa — tema scuro, pensato per il telefono e scalabile su tablet e PC. */
:root {
  --bg: #0f1115; --card: #1a1d24; --card2: #232731; --card3: #2c313c; --line: #2f3440;
  --text: #e9ebef; --muted: #939aa8; --dim: #5f6675;
  --accent: #4f8cff; --accent2: #2f6fe8; --yellow: #ffcc33; --amber: #ffb020; --green: #3fb67d;
  --red: #ef5350; --orange: #ff9a3c; --purple: #9b7ef0; --cyan: #29b6f6;
  --r: 16px; --gap: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
body { padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) calc(90px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 16px; } h3 { font-size: 17px; }
.muted { color: var(--muted); } .dim { color: var(--dim); } .small { font-size: 13px; }
.err { color: var(--red); min-height: 1.2em; margin: 0; font-size: 14px; }
.ok { color: var(--green); }
.pre { white-space: pre-line; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.sm { width: 17px; height: 17px; } svg.i.lg { width: 32px; height: 32px; } svg.i.xl { width: 44px; height: 44px; }

/* Layout */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; } .row.between { justify-content: space-between; } .row.nowrap { flex-wrap: nowrap; }
.stack { display: grid; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); align-items: start; }
.grid.tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.section { margin: 22px 0 10px; display: flex; align-items: center; gap: 8px; }
.section h2 { font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* Barra superiore */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.greet { font-size: 22px; font-weight: 600; }
.top .weather { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.top .weather b { color: var(--text); font-size: 20px; font-weight: 600; }

/* Navigazione: in basso sul telefono, in alto sugli schermi grandi */
.tabs { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; background: rgba(20, 22, 28, .96);
  backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tabs button { background: none; border: 0; display: grid; justify-items: center; gap: 2px; font-size: 11.5px; color: var(--muted); padding: 4px 10px; border-radius: 12px; cursor: pointer; }
.tabs button.on { color: var(--text); }
.tabs button.on svg { color: var(--accent); }
@media (min-width: 900px) {
  body { padding-bottom: 40px; max-width: 1500px; margin: 0 auto; }
  .tabs { position: static; background: none; border: 0; backdrop-filter: none; justify-content: flex-start; gap: 4px; padding: 0; margin-bottom: 16px; }
  .tabs button { grid-auto-flow: column; gap: 8px; font-size: 14px; padding: 9px 14px; }
  .tabs button.on { background: var(--card); }
}

/* Chip (stanze, filtri, riepilogo) */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; margin-bottom: 10px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; background: var(--card); border: 1px solid transparent; border-radius: 999px; padding: 7px 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--accent2); }
.chip.warn { border-color: var(--amber); color: var(--amber); }
.chip.alert { background: rgba(239, 83, 80, .15); color: #ff8a80; }

/* Card */
.card { background: var(--card); border-radius: var(--r); padding: 14px; min-width: 0; }
.card-h { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-h h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.card.off { opacity: .55; }

/* Tessere dei dispositivi */
.tile { background: var(--card); border-radius: var(--r); padding: 12px; display: grid; gap: 8px; align-content: space-between; min-height: 108px; cursor: pointer; border: 0; text-align: left; position: relative; user-select: none; -webkit-tap-highlight-color: transparent; }
.tile .t-name { font-weight: 600; font-size: 14.5px; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile .t-sub { font-size: 13px; color: var(--muted); }
.tile .t-ic { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--card2); color: var(--muted); }
.tile.on .t-ic { background: rgba(255, 204, 51, .18); color: var(--yellow); }
.tile.on.kind-switch .t-ic { background: rgba(79, 140, 255, .2); color: var(--accent); }
.tile.on.kind-breaker .t-ic { background: rgba(63, 182, 125, .2); color: var(--green); }
.tile.offline { opacity: .5; }
.tile.ro { cursor: default; }
.tile .t-more { position: absolute; top: 8px; right: 8px; background: none; border: 0; color: var(--dim); padding: 4px; cursor: pointer; }
.tile.busy::after { content: ''; position: absolute; inset: 0; border-radius: var(--r); background: rgba(255, 255, 255, .04); }

/* Pulsanti */
.btn { background: var(--card2); border: 0; border-radius: 12px; padding: 10px 15px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 500; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--card3); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent2); color: #fff; } .btn.primary:hover { background: var(--accent); }
.btn.danger { background: rgba(239, 83, 80, .18); color: #ff8a80; }
.btn.green { background: rgba(63, 182, 125, .2); color: #7be0ad; }
.btn.small { padding: 6px 11px; font-size: 13.5px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.big { padding: 15px 18px; font-size: 16px; border-radius: 14px; }
.icon-btn { background: var(--card2); border: 0; border-radius: 50%; width: 40px; height: 40px; display: inline-grid; place-items: center; cursor: pointer; color: var(--text); flex: none; }
.icon-btn:hover { background: var(--card3); }
.icon-btn.flat { background: none; }
.icon-btn.on { background: var(--accent2); }
.seg { display: inline-flex; background: var(--card2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { background: none; border: 0; border-radius: 9px; padding: 7px 12px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--card3); color: var(--text); }

/* Moduli */
input[type=text], input[type=password], input[type=number], input[type=email], input[type=date], input[type=time], input[type=datetime-local], input:not([type]), select, textarea {
  width: 100%; background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; outline: none; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
label.field > span:first-child { color: var(--text); font-weight: 500; }
.help { font-size: 13px; color: var(--muted); }
label.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
label.check input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--card3); border-radius: 999px; transition: background .15s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--accent2); }
.switch input:checked + span::after { transform: translateX(18px); }

/* Badge */
.badge { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--card2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: rgba(63, 182, 125, .16); color: #7be0ad; }
.badge.bad { background: rgba(239, 83, 80, .16); color: #ff8a80; }
.badge.warn { background: rgba(255, 176, 32, .16); color: var(--amber); }
.badge.blue { background: rgba(79, 140, 255, .18); color: #8db4ff; }

/* Elenchi */
.list { display: grid; }
.list > .li { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--line); min-width: 0; }
.list > .li:last-child { border-bottom: 0; }
.li .li-main { flex: 1; min-width: 0; }
.li .li-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .li-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); flex: none; }
.dot.ok { background: var(--green); } .dot.bad { background: var(--red); } .dot.warn { background: var(--amber); }

/* Telecamere */
.cams { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); }
.cam { position: relative; background: #000; border-radius: 14px; overflow: hidden; aspect-ratio: 16 / 9; cursor: pointer; }
.cam img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam .cam-l { position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 12px 9px; background: linear-gradient(transparent, rgba(0, 0, 0, .7)); display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
.cam .cam-l .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cam .live { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.cam.off { display: grid; place-items: center; color: var(--muted); }
.viewer { background: #000; border-radius: 14px; overflow: hidden; position: relative; }
.viewer img { width: 100%; display: block; max-height: 75vh; object-fit: contain; }
.events { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.ev { background: var(--card2); border-radius: 12px; overflow: hidden; cursor: pointer; border: 0; padding: 0; text-align: left; }
.ev img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; background: #000; }
.ev .ev-t { padding: 7px 9px; font-size: 13px; display: grid; gap: 1px; }
.ev .ev-t b { font-weight: 600; }
.ev.noimg .ev-ph { aspect-ratio: 16 / 9; display: grid; place-items: center; color: var(--dim); background: #000; }

/* Media */
.media-art { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--card2); flex: none; display: grid; place-items: center; color: var(--dim); }
.media-ctrl { display: flex; justify-content: center; gap: 14px; margin: 10px 0 4px; }
.remote { display: grid; grid-template-columns: repeat(3, 56px); gap: 8px; justify-content: center; margin: 8px 0; }
.remote .icon-btn { width: 56px; height: 56px; border-radius: 16px; }

/* Citofono e chiamata */
.ring { position: fixed; inset: 0; z-index: 60; background: rgba(5, 6, 9, .96); display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
.ring-card { width: min(560px, 100%); display: grid; gap: 14px; }
.ring-card h3 { text-align: center; font-size: 20px; display: flex; justify-content: center; gap: 10px; align-items: center; }
.ring-card .viewer { aspect-ratio: 4 / 3; }
.call-btns { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; }
.call-btn { display: grid; justify-items: center; gap: 6px; padding: 14px 6px; border-radius: 18px; background: var(--card2); border: 0; cursor: pointer; font-size: 14px; }
.call-btn.answer { background: var(--green); color: #fff; }
.call-btn.hang { background: var(--red); color: #fff; }
.call-btn.door { background: rgba(79, 140, 255, .22); color: #a9c6ff; }
.call-btn.on { background: var(--accent2); color: #fff; }
.pulse { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.door-btn.confirm { background: var(--amber); color: #000; }
.door-btn.opened { background: var(--green); color: #fff; }

/* Finestre */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .6); display: grid; place-items: end center; padding: 0; }
.modal-card { background: var(--card); width: min(560px, 100%); max-height: 92vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 12px; }
.modal-card.wide { width: min(980px, 100%); }
.modal-h { display: flex; align-items: center; gap: 10px; }
.modal-h h3 { flex: 1; min-width: 0; }
@media (min-width: 700px) { .modal { place-items: center; padding: 20px; } .modal-card { border-radius: 20px; } }

.toast { position: fixed; z-index: 70; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); background: var(--card3); padding: 11px 16px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0, 0, 0, .4); max-width: min(92vw, 520px); }
.toast.bad { background: #5a2323; }

/* Accesso */
.login { min-height: 85vh; display: grid; place-items: center; }
.login-box { width: min(380px, 100%); background: var(--card); border-radius: 22px; padding: 30px 24px; display: grid; gap: 12px; }
.login-box h1 { text-align: center; font-size: 24px; }
.login-box .logo { width: 64px; height: 64px; margin: 0 auto; }
.login-box .center { text-align: center; }
.qr { background: #fff; border-radius: 12px; padding: 10px; width: min(240px, 100%); margin: 0 auto; }
.qr svg { width: 100%; height: auto; display: block; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--card2); border-radius: 12px; padding: 12px; }

/* Impostazioni */
.set-nav { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { color: var(--muted); font-weight: 500; }
.scroll-x { overflow-x: auto; }
.perm-grid { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* Grafici consumi */
.chart { width: 100%; height: 180px; display: block; }
.chart .ax { stroke: var(--line); stroke-width: 1; }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .ar { fill: rgba(79, 140, 255, .14); stroke: none; }
.chart text { fill: var(--muted); font-size: 11px; }
.big-num { font-size: 30px; font-weight: 600; }

.empty { color: var(--muted); text-align: center; padding: 24px 10px; }
.banner { background: rgba(79, 140, 255, .12); border: 1px solid rgba(79, 140, 255, .35); border-radius: 14px; padding: 12px 14px; display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.banner.warn { background: rgba(255, 176, 32, .1); border-color: rgba(255, 176, 32, .35); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--card3); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Impostazioni: dettagli delle sezioni */
.set-loading { justify-content: center; padding: 24px; }
.set-click { cursor: pointer; }
.set-click:hover { background: rgba(255, 255, 255, .02); }
.set-badges { gap: 6px; margin-top: 4px; }
.set-tight { gap: 6px; }
.set-checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.set-actions { gap: 8px; }
.set-actions .btn { justify-content: flex-start; }
.set-fs { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 0; display: grid; gap: 10px; }
.set-fs legend, .set-fs summary { color: var(--text); font-weight: 500; cursor: pointer; padding: 0 4px; }
.set-perm { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.set-perm .seg button { padding: 5px 9px; font-size: 13px; }
.set-perm.changed > span:first-child { color: var(--accent); }
.set-int-form { margin-top: 10px; }
.day-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.day-chips .chip { padding: 6px 10px; }
.audit-row.fail .li-title { color: #ff8a80; }
.set-perm select { width: auto; max-width: 48%; padding: 6px 8px; }
