:root {
  --bg: #111318; --card: #1c1f26; --card2: #242832; --card3: #2c313c; --line: #2e333e;
  --text: #e8eaed; --muted: #8d95a3; --dim: #5d6573;
  --yellow: #fdd835; --amber: #ffb300; --blue: #2196f3; --cyan: #03a9f4; --green: #43b581;
  --orange: #ff9800; --red: #ef5350; --purple: #9575cd;
  --r: 16px; --gap: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
body { padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 40px max(16px, env(safe-area-inset-left)); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--red); min-height: 1.3em; margin: 8px 0 0; font-size: 14px; }
svg.i { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.sm { width: 18px; height: 18px; }
svg.i.lg { width: 34px; height: 34px; }

/* Login */
.login { min-height: 90vh; display: grid; place-items: center; }
.login-box { width: min(360px, 100%); background: var(--card); border-radius: 22px; padding: 32px 28px; display: grid; gap: 12px; text-align: center; }
.login-box h1 { margin: 4px 0 0; font-size: 24px; font-weight: 600; }
.login-box p { margin: 0 0 6px; }
.login-logo { width: 64px; height: 64px; margin: 0 auto; background: url(icon.svg) center/contain no-repeat; }
input[type=text], input[type=password], input[type=number], input:not([type]), select {
  width: 100%; background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; outline: none;
}
input:focus, select:focus { border-color: var(--cyan); }

/* Buttons */
.btn { border: 0; background: var(--card3); border-radius: 12px; padding: 10px 16px; cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 8px; justify-content: center; transition: background .15s, transform .1s; }
.btn:hover { background: #363c49; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--cyan); color: #04131c; }
.btn.primary:hover { background: #29b6f6; }
.btn.danger { background: rgba(239, 83, 80, .15); color: var(--red); }
.btn.green { background: var(--green); color: #07170f; }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--card3); display: grid; place-items: center; cursor: pointer; transition: background .15s, transform .1s; }
.icon-btn:hover { background: #363c49; }
.icon-btn:active { transform: scale(.93); }
.icon-btn.on { background: var(--cyan); color: #04131c; }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.greet { font-size: 26px; font-weight: 600; letter-spacing: -.01em; }
.tabs { display: flex; gap: 4px; background: var(--card); padding: 4px; border-radius: 14px; overflow-x: auto; max-width: 100%; }
.tabs button { border: 0; background: none; padding: 9px 14px; border-radius: 10px; cursor: pointer; color: var(--muted); display: flex; align-items: center; gap: 7px; white-space: nowrap; font-weight: 500; }
.tabs button.on { background: var(--card3); color: var(--text); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { background: var(--card); border-radius: 999px; padding: 7px 14px 7px 10px; display: inline-flex; align-items: center; gap: 7px; font-size: 14px; }
.chip svg { width: 18px; height: 18px; }
.chip.warn { color: var(--orange); }
.chip.alert { background: rgba(239, 83, 80, .15); color: var(--red); }
.rooms { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 16px; scrollbar-width: none; }
.rooms button { border: 1px solid var(--line); background: none; border-radius: 999px; padding: 6px 14px; cursor: pointer; color: var(--muted); white-space: nowrap; font-size: 14px; }
.rooms button.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* Masonry */
.masonry { column-width: 360px; column-gap: var(--gap); }
.masonry > * { break-inside: avoid; margin-bottom: var(--gap); }
.card { background: var(--card); border-radius: var(--r); padding: 18px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: -2px 0 14px; }
.card-h h2 { font-size: 17px; font-weight: 600; margin: 0; display: flex; align-items: center; gap: 8px; }
.card-h .muted { font-size: 13px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px 4px; font-weight: 600; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }
.empty a, .link { color: var(--cyan); cursor: pointer; text-decoration: none; }

/* Weather */
.wx-top { display: flex; align-items: flex-start; justify-content: space-between; }
.wx-icon svg { width: 76px; height: 76px; stroke-width: 1.4; }
.wx-temp { font-size: 54px; font-weight: 300; line-height: 1; letter-spacing: -.03em; }
.wx-temp small { font-size: 20px; vertical-align: top; margin-left: 2px; color: var(--muted); }
.wx-desc { text-align: right; color: var(--muted); font-size: 14px; margin-top: 6px; }
.wx-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 16px; margin: 16px 0 14px; font-size: 13.5px; color: var(--muted); }
.wx-meta div { display: flex; align-items: center; gap: 7px; }
.wx-meta div:nth-child(even) { justify-content: flex-end; }
.wx-meta svg { width: 17px; height: 17px; color: var(--cyan); }
.wx-days { display: grid; grid-template-columns: repeat(5, 1fr); border-top: 1px solid var(--line); padding-top: 12px; }
.wx-day { text-align: center; font-size: 13px; display: grid; gap: 6px; justify-items: center; border-left: 1px solid var(--line); }
.wx-day:first-child { border: 0; }
.wx-day svg { width: 26px; height: 26px; }
.wx-day b { font-size: 14px; font-weight: 600; }
.wx-day .muted { font-size: 12px; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.tile { position: relative; background: var(--card2); border: 0; border-radius: 14px; min-height: 104px; padding: 14px 10px 12px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; transition: background .2s, transform .1s; user-select: none; -webkit-user-select: none; }
.tile:hover { background: #2a2f3a; }
.tile:active { transform: scale(.96); }
.tile .tn { font-size: 14px; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile .ts { font-size: 12px; color: var(--muted); }
.tile .ti { color: var(--dim); transition: color .2s, filter .2s; }
.tile.on { background: #2d2c26; }
.tile.on .ti { color: var(--yellow); filter: drop-shadow(0 0 10px rgba(253, 216, 53, .45)); }
.tile.on.plug .ti, .tile.on.fan .ti { color: var(--cyan); filter: drop-shadow(0 0 10px rgba(3, 169, 244, .4)); }
.tile.on.plug, .tile.on.fan { background: #1f2a33; }
.tile.on.heater .ti { color: var(--orange); filter: drop-shadow(0 0 10px rgba(255, 152, 0, .4)); }
.tile.off-line { opacity: .45; }
.tile.busy::after { content: ""; position: absolute; top: 9px; right: 9px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--muted); border-top-color: transparent; animation: spin .7s linear infinite; }
.tile .more { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: var(--dim); }
.tile .more:hover { background: var(--card3); color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Covers */
.cover { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.cover:first-of-type { border: 0; padding-top: 2px; }
.cover-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--card2); display: grid; place-items: center; color: var(--dim); position: relative; overflow: hidden; }
.cover-icon.open { color: var(--cyan); }
.cover-icon .fill { position: absolute; left: 0; right: 0; top: 0; background: rgba(3, 169, 244, .14); transition: height .5s; }
.cover-name { font-weight: 500; }
.cover-state { font-size: 13px; color: var(--muted); }
.cover-btns { display: flex; gap: 6px; }
.cover-btns .icon-btn { width: 38px; height: 38px; }
.cover input[type=range] { grid-column: 1 / -1; }
.cover-all { display: flex; gap: 8px; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; background: transparent; cursor: pointer; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--cyan) var(--p, 0%), var(--card3) var(--p, 0%)); }
input[type=range]::-moz-range-track { height: 8px; border-radius: 4px; background: var(--card3); }
input[type=range]::-moz-range-progress { height: 8px; border-radius: 4px; background: var(--cyan); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: #fff; margin-top: -7px; box-shadow: 0 1px 4px rgba(0, 0, 0, .5); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border: 0; border-radius: 50%; background: #fff; }
input[type=range].yellow::-webkit-slider-runnable-track { background: linear-gradient(90deg, var(--yellow) var(--p, 0%), var(--card3) var(--p, 0%)); }
input[type=range].yellow::-moz-range-progress { background: var(--yellow); }

/* Cameras */
.cams { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.cams.big { grid-template-columns: repeat(auto-fill, minmax(min(420px, 100%), 1fr)); gap: var(--gap); }
.cam { position: relative; aspect-ratio: 16 / 9; background: #0b0c10; border-radius: 12px; overflow: hidden; cursor: pointer; }
.cam img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .3s; }
.cam img.ok { opacity: 1; }
.cam .cam-l { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 10px 7px; font-size: 13px; background: linear-gradient(transparent, rgba(0, 0, 0, .75)); display: flex; align-items: center; gap: 6px; }
.cam .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; }
.cam.off .dot { background: var(--red); }
.cam.off::before { content: "Offline"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); font-size: 13px; }
.cam.nosnap::before { content: "Anteprima non disponibile"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); font-size: 13px; }
.cams.big .cam { border-radius: var(--r); }
.cams.big .cam .cam-l { font-size: 15px; padding: 24px 14px 10px; }

/* Intercom */
.ic-view { aspect-ratio: 4 / 3; margin-bottom: 12px; }
.ic-doors { display: grid; gap: 8px; }
.door-btn { width: 100%; padding: 14px; font-size: 16px; border-radius: 14px; }
.door-btn.confirm { background: var(--orange); color: #1d1100; animation: pulse 1s infinite; }
.door-btn.opened { background: var(--green); color: #07170f; }
@keyframes pulse { 50% { opacity: .75; } }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--card3); color: var(--muted); font-weight: 500; }
.badge.ok { background: rgba(67, 181, 129, .15); color: var(--green); }
.badge.bad { background: rgba(239, 83, 80, .15); color: var(--red); }
.badge.warn { background: rgba(255, 152, 0, .15); color: var(--orange); }
.badge.blue { background: rgba(3, 169, 244, .15); color: var(--cyan); }

/* Appliances */
.appl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; align-items: center; }
.appl + .appl { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.appl-ic { width: 52px; height: 52px; border-radius: 14px; background: var(--card2); display: grid; place-items: center; color: var(--muted); grid-row: span 2; }
.appl-ic.run { color: var(--cyan); background: #1f2a33; }
.appl-name { font-weight: 600; }
.appl-sub { font-size: 13px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.appl-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.appl-actions .btn { flex: 1; min-width: 90px; }
.appl-props { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-top: 10px; }
.prop { background: var(--card2); border-radius: 12px; padding: 9px 11px; }
.prop .pl { font-size: 12px; color: var(--muted); }
.prop .pv { font-weight: 600; margin-top: 2px; }
.battery { display: inline-flex; align-items: center; gap: 5px; }
.battery i { display: inline-block; width: 26px; height: 12px; border: 1.6px solid currentColor; border-radius: 3px; position: relative; }
.battery i::after { content: ""; position: absolute; left: 1.5px; top: 1.5px; bottom: 1.5px; width: calc((100% - 3px) * var(--b)); background: currentColor; border-radius: 1px; }

/* Energy */
.big-num { font-size: 44px; font-weight: 300; letter-spacing: -.02em; line-height: 1.05; }
.big-num small { font-size: 18px; color: var(--muted); margin-left: 4px; }
.bars { display: grid; gap: 10px; margin-top: 16px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 14px; }
.bar-row .bar { grid-column: 1 / -1; height: 6px; background: var(--card3); border-radius: 3px; overflow: hidden; }
.bar-row .bar i { display: block; height: 100%; background: var(--amber); border-radius: 3px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--card2); border-radius: 14px; padding: 14px; }
.stat .sl { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.stat .sv { font-size: 26px; font-weight: 400; margin-top: 4px; }
.stat .sv small { font-size: 14px; color: var(--muted); margin-left: 3px; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-child { border: 0; }
.row .grow { flex: 1; min-width: 0; }
.switch { position: relative; width: 46px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--card3); border-radius: 13px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #c8ccd4; transition: .2s; }
.switch input:checked + span { background: var(--cyan); }
.switch input:checked + span::before { transform: translateX(20px); background: #fff; }

/* Animali */
.pet-map { height: 210px; border-radius: 12px; overflow: hidden; background: var(--card2); }
.pet-map-inner { width: 100%; height: 100%; }
.pet-ph { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; }
.pet-marker img { width: 38px; height: 38px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.5); object-fit: cover; }
.pet-marker { font-size: 26px; text-align: center; line-height: 38px; }
.pet-links { display: flex; justify-content: space-between; gap: 10px; margin-top: 10px; font-size: 14px; flex-wrap: wrap; }
.leaflet-container { background: #1f232b; font: inherit; }
.leaflet-control-attribution { font-size: 10px; background: rgba(0,0,0,.5) !important; color: #aaa !important; }
.leaflet-control-attribution a { color: #ccc !important; }

/* Clima */
.clima { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 6px 0 14px; }
.clima-dial { width: 170px; height: 170px; border-radius: 50%; display: grid; place-content: center; text-align: center; border: 4px solid var(--c); box-shadow: 0 0 30px -8px var(--c); transition: border-color .3s, box-shadow .3s; }
.clima-set { font-size: 48px; font-weight: 300; line-height: 1; letter-spacing: -.02em; }
.clima-set small { font-size: 17px; color: var(--muted); margin-left: 2px; vertical-align: top; }
.clima-dial .muted { font-size: 13px; margin-top: 6px; }
.clima-modes { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }

/* TV */
.tv-head { display: flex; align-items: center; gap: 14px; }
.tv-power { width: 56px; height: 56px; }
.tv-power.on { background: var(--green); color: #07170f; }
.remote { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: center; margin-top: 16px; }
.dpad { display: grid; grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px); gap: 4px; }
.dpad .icon-btn { width: 46px; height: 46px; border-radius: 12px; }
.dpad .ok { border-radius: 50%; background: var(--card3); font-weight: 700; font-size: 13px; }
.rocker { display: grid; gap: 4px; justify-items: center; }
.rocker small { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tv-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; justify-content: center; }
.app-btn { border: 0; border-radius: 10px; padding: 8px 12px; font-weight: 700; font-size: 13px; cursor: pointer; }
.app-netflix { background: #e50914; color: #fff; }
.app-youtube { background: #fff; color: #e62117; }
.app-prime { background: #00a8e1; color: #fff; }
.app-disney { background: #113ccf; color: #fff; }
.app-raiplay { background: #0b5fff; color: #fff; }
.app-spotify { background: #1db954; color: #000; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--card); border-radius: 22px; width: min(460px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 22px; }
.modal-card.wide { width: min(1100px, 100%); padding: 14px; }
.modal-card.wide img { width: 100%; border-radius: 14px; display: block; }
.modal-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 10px; }
.modal-h h3 { margin: 0; font-size: 19px; font-weight: 600; }
.big-toggle { width: 110px; height: 190px; margin: 6px auto 18px; border-radius: 28px; background: var(--card3); position: relative; cursor: pointer; border: 0; display: block; overflow: hidden; }
.big-toggle i { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; border-radius: 28px; background: #5b6272; transition: .25s; }
.big-toggle.on i { bottom: 50%; background: var(--yellow); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px; font-size: 14px; margin-top: 14px; }
.kv span:nth-child(odd) { color: var(--muted); }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); }

/* Ring */
.ring { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .8); display: grid; place-items: center; padding: 16px; }
.ring-card { background: var(--card); border-radius: 24px; padding: 20px; width: min(520px, 100%); text-align: center; box-shadow: 0 0 0 3px var(--orange); animation: ringglow 1.2s infinite; }
@keyframes ringglow { 50% { box-shadow: 0 0 0 3px var(--orange), 0 0 40px rgba(255, 152, 0, .35); } }
.ring-card h3 { margin: 4px 0 14px; font-size: 22px; display: flex; gap: 10px; justify-content: center; align-items: center; }
.ring-card .cam { margin-bottom: 14px; cursor: default; }
.ring-actions { display: flex; gap: 10px; }
.ring-actions .btn { flex: 1; padding: 14px; font-size: 16px; }

/* Settings */
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(420px, 100%), 1fr)); gap: var(--gap); align-items: start; }
.help { font-size: 13px; color: var(--muted); background: var(--card2); border-radius: 12px; padding: 12px 14px; margin: 0 0 14px; }
.help ol { margin: 6px 0 0; padding-left: 18px; }
.help li { margin: 3px 0; }
.help code { background: var(--card3); padding: 1px 5px; border-radius: 5px; font-size: 12px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; flex-wrap: wrap; }
.ent-table { display: grid; gap: 8px; }
.ent-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.2fr) minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.ent-row input, .ent-row select { padding: 8px 10px; font-size: 14px; }
.ent-row .src { font-size: 11px; color: var(--dim); grid-column: 1 / -1; margin-top: -4px; }
.ent-row.head { font-size: 12px; color: var(--muted); }
.ent-group { font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 2px; }
.geo-list { display: grid; gap: 4px; margin-top: 6px; }
.geo-list button { text-align: left; background: var(--card2); border: 0; border-radius: 10px; padding: 9px 12px; cursor: pointer; }
.geo-list button:hover { background: var(--card3); }

.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: #3a3f4b; padding: 12px 18px; border-radius: 12px; z-index: 70; box-shadow: 0 6px 24px rgba(0, 0, 0, .4); max-width: calc(100% - 32px); }
.toast.bad { background: #5a2626; }

@media (max-width: 640px) {
  .greet { font-size: 22px; }
  .top { gap: 10px; }
  /* Su telefono la navigazione sta in basso, come in un'app */
  body { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; width: auto; max-width: none; border-radius: 0; gap: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: rgba(24, 27, 33, .94); border-top: 1px solid var(--line);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); overflow: visible; }
  .tabs button { flex: 1; flex-direction: column; gap: 3px; padding: 7px 4px; font-size: 11px; justify-content: center; border-radius: 12px; }
  .tabs button svg { width: 22px; height: 22px; }
  .tabs button.on { background: none; color: var(--cyan); }
  .tabs button.on svg { background: rgba(3, 169, 244, .16); border-radius: 999px; padding: 3px 14px; width: 52px; height: 28px; box-sizing: border-box; }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }
  .tiles { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .tile { min-height: 100px; padding: 12px 6px 10px; }
  .tile .tn { font-size: 13px; -webkit-line-clamp: 3; word-break: break-word; }
  .ent-row { grid-template-columns: 1fr 1fr; }
  .ent-row.head { display: none; }
  .wx-temp { font-size: 46px; }
  .remote { grid-template-columns: 1fr; justify-items: center; }
}

/* Movimento */
.cam.moving::after { content: ""; position: absolute; inset: 0; border: 2px solid var(--orange); border-radius: inherit; pointer-events: none; animation: pulse 1.2s infinite; }
.cam-motion { position: absolute; top: 8px; left: 8px; display: inline-flex; align-items: center; gap: 5px; background: var(--orange); color: #1d1100; font-size: 12px; font-weight: 600; padding: 3px 9px 3px 7px; border-radius: 999px; }
.cam-motion svg { width: 14px; height: 14px; }
.cam-l .cam-n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.cam-ago { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: rgba(255, 255, 255, .7); white-space: nowrap; flex: none; }
.cam-ago svg { width: 13px; height: 13px; }
.chip-btn { border: 0; color: inherit; font: inherit; cursor: pointer; }
.chip-btn:hover { background: var(--card2); }
.chip.armed { background: rgba(255, 152, 0, .15); color: var(--orange); }
.chip.motion { color: var(--orange); cursor: pointer; }
.hist-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.hist-tools select { width: auto; flex: 1; min-width: 0; }
.hist-counts { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.hist-counts .badge { border: 0; cursor: pointer; font: inherit; font-size: 12px; }
.hist-counts .badge:hover { background: #363c49; color: var(--text); }
.ev-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(160px, calc(50% - 4px)), 1fr)); gap: 8px; }
.ev-day { grid-column: 1 / -1; font-size: 13px; font-weight: 600; color: var(--muted); margin: 6px 0 0; text-transform: capitalize; }
.ev { border: 0; padding: 0; background: var(--card2); border-radius: 12px; overflow: hidden; cursor: pointer; text-align: left; display: flex; flex-direction: column; color: inherit; font: inherit; }
.ev:hover { background: var(--card3); }
.ev img, .ev-noimg { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; background: #0b0c10; }
.ev-t { padding: 7px 10px 0; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-s { padding: 1px 10px 8px; font-size: 12px; color: var(--muted); }
.cam-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px 12px; font-size: 14px; }
.cam-checks label { display: flex; align-items: center; gap: 7px; }
input[type=time] { width: 100%; background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; color-scheme: dark; }
.ev img.noimg { visibility: hidden; }
.ev:has(img.noimg) .ev-s::after, .ev:has(.ev-noimg) .ev-s::after { content: " · senza anteprima"; }

/* Regole notifiche */
.rule { background: var(--card2); border-radius: 14px; padding: 12px 14px 14px; margin-bottom: 10px; }
.rule.off { opacity: .55; }
.rule-h { display: flex; align-items: center; gap: 10px; }
.rule-name { flex: 1; min-width: 0; font-weight: 600; background: transparent !important; border-color: transparent !important; padding: 6px 8px !important; }
.rule-name:focus { border-color: var(--cyan) !important; background: var(--card) !important; }
.rule-l { font-size: 12px; color: var(--muted); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.rule-l .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pill { border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; min-width: 34px; }
.pill:hover { border-color: #4a5160; color: var(--text); }
.pill.on { background: var(--cyan); border-color: var(--cyan); color: #04131c; font-weight: 600; }
.pill-sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.rule-time { display: flex; align-items: center; gap: 8px; }
.rule-time input { width: auto; flex: 1; max-width: 140px; }
.rule-time span { font-size: 14px; color: var(--muted); }
.rule-check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; }
.rule-check .muted { font-size: 12px; }
.rule-warn { font-size: 12.5px; color: var(--orange); margin: 8px 0 0; }
.rule-sum { font-size: 13px; color: var(--muted); margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.ev { position: relative; }
.ev-ai { position: absolute; top: 6px; left: 6px; display: flex; gap: 4px; flex-wrap: wrap; z-index: 1; }
.ev-ai i { font-style: normal; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: rgba(3, 169, 244, .9); color: #04131c; }
.ev-ai i.p { background: var(--orange); color: #1d1100; }
.ev-ai i.a { background: var(--green); color: #07170f; }

/* App: niente evidenziazione blu al tocco, niente "rimbalzo" della pagina */
html { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
button, .tile, .cam, .pill, .chip-btn { touch-action: manipulation; }
.push-dev { padding: 4px 0 10px; border-top: 1px solid var(--line); }
.push-dev:first-of-type { border-top: 0; }
@media (display-mode: standalone) { body { padding-top: max(12px, env(safe-area-inset-top)); } }
.btn { text-decoration: none; }

/* Chiamata citofono */
.ring-card.live { box-shadow: 0 0 0 3px var(--green); animation: none; }
.call-video { margin-bottom: 14px; aspect-ratio: 4 / 3; }
.call-video img { opacity: 1; }
.call-timer { font-variant-numeric: tabular-nums; color: var(--green); margin-left: 6px; }
.call-hint { font-size: 13px; margin: -4px 0 12px; }
.call-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.call-btn { flex: 1 1 0; min-width: 90px; flex-direction: column; gap: 6px; padding: 14px 8px; border-radius: 18px; font-size: 14px; }
.call-btn svg { width: 28px; height: 28px; }
.call-btn.answer { background: var(--green); color: #07170f; animation: pulse 1.2s infinite; }
.call-btn.hang { background: var(--red); color: #fff; }
.call-btn.door { background: var(--cyan); color: #04131c; }
.call-btn.on { background: var(--orange); color: #1d1100; }
@media (max-width: 640px) { .ring { padding: 10px; align-items: end; } .ring-card { padding: 16px; } .call-btn { min-width: 0; font-size: 13px; } }
.call-btn.hang svg { transform: rotate(135deg); }
