:root {
    --bg: #1a1a20;
    --bg-gradient-start: #23232b;
    --bg-panel: #14141a;
    --bg-card: #262f3d;
    --bg-card-dark: #1a2430;
    --bg-row: #202b38;
    --bg-input: #0d1620;
    --bg-inset: #16202b;
    --border-card: #34495e;
    --border-strong: #4f5d75;
    --text-main: #ffffff;
    --text-input: #dbe4ee;
    --accent: #f39c12;
    --accent-soft: rgba(243, 156, 18, 0.15);
    --blue: #3498db;
    --green: #2ecc71;
    --red: #e74c3c;
    --text-dim: #8aa0b8;
}

/* TEMA CHIARO: stesse variabili, valori chiari. Attivato/disattivato da
   toggleTemaDashboard() in Domotica.js (Impostazioni > Generali), persistito
   in localStorage così resta impostato tra una visita e l'altra. Elementi
   "di chrome" con colori fissi (nav-bar, bottoni scene-btn/btn-toggle,
   badge di stato) restano volutamente scuri/colorati in entrambi i temi:
   funzionano bene su sfondo sia chiaro che scuro, cambiarli non aggiungeva
   nulla e aumentava solo il rischio di un risultato incoerente. */
body.tema-chiaro {
    --bg: #e9edf2;
    --bg-gradient-start: #ffffff;
    --bg-panel: #ffffff;
    --bg-card: #f4f6f9;
    --bg-card-dark: #e9edf2;
    --bg-row: #e9edf2;
    --bg-input: #ffffff;
    --bg-inset: #dee4ea;
    --border-card: #d3dae2;
    --border-strong: #c0c9d3;
    --text-main: #1a2430;
    --text-input: #1a2430;
    --text-dim: #5a6b7d;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: radial-gradient(circle at top, var(--bg-gradient-start) 0%, var(--bg) 55%);
    background-attachment: fixed;
    color: var(--text-main);
    margin: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    -webkit-font-smoothing: antialiased;
    transition: background 0.2s ease, color 0.2s ease;
}

/* Leggera comparsa a fade-in dei contenuti al caricamento */
.zone-container, .header-bar, .nav-bar, .scene-bar {
    animation: fadeInUp 0.35s ease both;
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1100px;
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
}
h1 { 
    color: #f39c12; 
    margin: 0;
    text-shadow: 1px 1px 4px rgba(0,0,0,0.4);
}

.status-indicator {
    background-color: #141419;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border-card);
}
.dot {
    width: 10px;
    height: 10px;
    background-color: #2ecc71;
    border-radius: 50%;
    display: inline-block;
}
.dot.syncing {
    animation: pulse 1.5s infinite;
}
.dot.error {
    background-color: #e74c3c;
    animation: none;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(46, 204, 113, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

.zone-container {
    width: 100%;
    max-width: 1100px;
    margin-bottom: 30px;
    background-color: var(--bg-panel);
    padding: 20px;
    border-radius: 14px;
    border-left: 5px solid var(--accent);
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
    box-sizing: border-box;
}
/* "Consumi" è una pagina a sé (vedi mostraZona/applicaFiltro in Domotica.js):
   deve restare nascosta di default anche al primissimo caricamento, prima
   che qualunque JS/click intervenga, altrimenti compare per un istante (o
   in modo permanente se non si clicca mai altrove) dentro l'Overview. */
#zona-consumi {
    display: none;
}
#zona-report {
    display: none;
}
#zona-notifiche {
    display: none;
}
#zona-impostazioni {
    display: none;
}
.zone-title-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}
.zone-title {
    font-size: 20px;
    font-weight: bold;
    color: #f39c12;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0;
}
.zone-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.house-map {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    width: 100%;
}

.room {
    background-color: var(--bg-card);
    border: 2px solid var(--border-card);
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.room:hover {
    border-color: #e67e22;
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(0,0,0,0.3);
}
.room-title {
    font-size: 16px;
    font-weight: bold;
    border-bottom: 2px solid var(--border-strong);
    padding-bottom: 6px;
    margin-bottom: 12px;
    color: #e67e22;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}
.room-title::after {
    content: '▾';
    font-size: 12px;
    color: var(--text-dim);
    transition: transform 0.2s ease;
    margin-left: 8px;
}
.room.collapsed .room-title::after {
    transform: rotate(-90deg);
}
.room.collapsed .device,
.room.collapsed .power-chart-container {
    display: none !important;
}
/* Eccezione: elementi marcati "stay-visible" restano visibili anche a stanza
   chiusa (es. il consumo totale e il suo grafico nel Quadro Elettrico). */
.room.collapsed .device.stay-visible {
    display: flex !important;
}
.room.collapsed .power-chart-container.stay-visible {
    display: block !important;
}

.device {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card-dark);
    padding: 8px 10px;
    margin: 6px 0;
    border-radius: 6px;
    font-size: 13px;
    transition: background-color 0.15s ease;
}
.device:hover {
    background-color: var(--bg-row);
}

.power-chart-container {
    margin-top: 10px;
    height: 90px;
    width: 100%;
}

/* PAGINA CONSUMI (grafico multi-linea, un colore per magnetotermico) */
.consumi-container {
    width: 100%;
    box-sizing: border-box;
}
.consumi-nota {
    color: var(--text-dim);
    font-size: 13px;
    margin: 0 0 14px 0;
    line-height: 1.5;
}
.consumi-chart-wrapper {
    width: 100%;
    height: 340px;
    background-color: var(--bg-row);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 12px;
    box-sizing: border-box;
}
.consumi-ripartizione {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 18px;
}
.consumi-riga {
    display: grid;
    grid-template-columns: 11px 1fr 120px 60px 48px;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-input);
    background-color: var(--bg-row);
    border: 1px solid var(--border-card);
    border-radius: 6px;
    padding: 8px 12px;
}
.consumi-riga-nome {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.consumi-riga-barra {
    height: 8px;
    background-color: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
}
.consumi-riga-barra-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.4s ease;
}
.consumi-riga-watt {
    text-align: right;
    color: #f1c40f;
    font-weight: bold;
    white-space: nowrap;
}
.consumi-riga-pct {
    text-align: right;
    font-weight: bold;
    color: var(--accent);
}
.consumi-riga-figlia {
    margin-left: 20px;
    background-color: var(--bg-inset);
    font-size: 12px;
    opacity: 0.92;
}
.consumi-riga-figlia .consumi-riga-watt {
    color: #d9a441;
}

.consumi-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 18px;
    margin-top: 14px;
    justify-content: center;
}
.consumi-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-input);
    cursor: pointer;
    user-select: none;
    padding: 3px 8px;
    border-radius: 4px;
    transition: background-color 0.15s ease, opacity 0.15s ease;
}
.consumi-legend-item:hover {
    background-color: rgba(255,255,255,0.06);
}
.consumi-legend-item.nascosto {
    opacity: 0.4;
    text-decoration: line-through;
}
.consumi-legend-item-figlia {
    font-size: 12px;
    opacity: 0.85;
}
.consumi-legend-azioni {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}
.consumi-legend-azioni .scene-btn {
    padding: 6px 14px;
    font-size: 12px;
}
.consumi-legend-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.consumi-range-switch {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-bottom: 12px;
}
.consumi-range-switch .scene-btn {
    padding: 8px 16px;
    font-size: 13px;
}
.consumi-range-switch .scene-btn.active {
    border-color: var(--accent);
    color: var(--accent);
}

@media (max-width: 640px) {
    .consumi-chart-wrapper {
        height: 260px;
    }
    .consumi-range-switch {
        justify-content: center;
        width: 100%;
    }
    .consumi-range-switch .scene-btn {
        padding: 7px 10px;
        font-size: 12px;
    }
    .consumi-riga {
        grid-template-columns: 9px 1fr 55px 42px;
        gap: 6px;
        font-size: 12px;
        padding: 7px 9px;
    }
    .consumi-riga-barra {
        display: none;
    }
    .report-stats {
        grid-template-columns: 1fr 1fr;
    }
    .report-chart-wrapper {
        height: 240px;
    }
    .report-trend-wrapper {
        height: 180px;
    }
}

/* ================= REPORT CONSUMI ================= */
.report-container {
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.report-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}
.report-stat-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background-color: var(--bg-row);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 14px 16px;
}
.report-stat-label {
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.report-stat-valore {
    font-size: 24px;
    font-weight: bold;
    color: #f1c40f;
}
.report-stat-costo {
    font-size: 13px;
    color: var(--text-dim);
}
#report-confronto.report-peggio {
    color: #e74c3c;
}
#report-confronto.report-meglio {
    color: #2ecc71;
}
.report-chart-wrapper {
    width: 100%;
    height: 300px;
    background-color: var(--bg-row);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 12px;
}
.report-trend-wrapper {
    width: 100%;
    height: 220px;
    background-color: var(--bg-row);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 12px;
}
.report-date-label {
    font-size: 13px;
    color: var(--text-dim);
}
.report-date-picker {
    background-color: var(--bg-row);
    color: var(--text-input);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    color-scheme: dark;
}
body.tema-chiaro .report-date-picker {
    color-scheme: light;
}
.report-date-picker:hover {
    border-color: var(--accent);
}
.report-sottotitolo {
    margin: 4px 0 10px 0;
    font-size: 15px;
    color: var(--text-main);
}
.report-dettaglio {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.camera-container {
    margin-top: 6px;
    width: 100%;
}
.camera-snapshot {
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border-card);
    cursor: pointer;
    display: block;
    background: var(--bg-input);
    min-height: 90px;
}
.camera-live {
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border-card);
    background: #000;
}
.camera-controls {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

/* SCENE RAPIDE */
.scene-bar {
    width: 100%;
    max-width: 1100px;
    margin-bottom: 20px;
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}
.scene-btn {
    background: linear-gradient(135deg, #2c3e50, #24303e);
    color: #fff;
    border: 1px solid var(--border-card);
    padding: 10px 18px;
    border-radius: 10px;
    font-weight: bold;
    font-size: 13px;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.scene-btn:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(243, 156, 18, 0.25);
}
.scene-btn:disabled {
    opacity: 0.6;
    cursor: default;
    transform: none;
}
.scene-btn-pericolo {
    background: linear-gradient(135deg, #7a2b2b, #5a1f1f);
}
.scene-btn-pericolo:hover {
    border-color: #e74c3c;
    box-shadow: 0 4px 14px rgba(231, 76, 60, 0.25);
}

.device.inline-zone-device {
    margin: 0;
    background: var(--bg-card-dark);
    border: 1px solid var(--border-card);
    gap: 10px;
}

.dimmer-controls, .clima-controls, .lock-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}
.hdmi-source-group {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
}
.btn-hdmi-source {
    padding: 2px 8px;
    font-size: 10px;
    min-width: 46px;
}
.btn-hdmi-source.on {
    border-color: var(--accent);
    color: var(--accent);
    background-color: rgba(243, 156, 18, 0.12);
}
.telecomando-panel {
    width: 100%;
    margin: 4px 0 10px;
    padding: 12px;
    background-color: var(--bg-inset);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    box-sizing: border-box;
}
.telecomando-dpad {
    display: grid;
    grid-template-columns: repeat(3, 46px);
    grid-template-rows: repeat(3, 38px);
    gap: 4px;
    justify-content: center;
    margin-bottom: 10px;
}
.telecomando-dpad button {
    padding: 0;
    font-size: 14px;
}
.telecomando-dpad button:nth-child(1) { grid-column: 2; grid-row: 1; }
.telecomando-dpad button:nth-child(2) { grid-column: 1; grid-row: 2; }
.telecomando-dpad button:nth-child(3) { grid-column: 2; grid-row: 2; }
.telecomando-dpad button:nth-child(4) { grid-column: 3; grid-row: 2; }
.telecomando-dpad button:nth-child(5) { grid-column: 2; grid-row: 3; }
.telecomando-riga {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 6px;
}
.telecomando-riga:last-child {
    margin-bottom: 0;
}
.dimmer-slider {
    width: 80px;
    cursor: pointer;
}

.btn-toggle {
    background-color: var(--red);
    color: white;
    border: none;
    padding: 5px 12px;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.1s ease;
    min-width: 55px;
}
.btn-toggle:hover {
    filter: brightness(1.08);
}
.btn-toggle:active {
    transform: scale(0.96);
}
.btn-toggle.on {
    background-color: var(--green);
    box-shadow: 0 0 10px rgba(46, 204, 113, 0.35);
}
.btn-toggle.offline {
    background-color: #4a4f57;
    color: #b0b6bf;
    cursor: not-allowed;
}
.btn-toggle.offline:hover {
    filter: none;
}
.btn-toggle.cleaning {
    background-color: #3498db;
    min-width: 110px;
}

.shutter-container {
    display: flex;
    align-items: center;
    gap: 5px;
}
.clima-ctrl {
    width: 38px;
    background: var(--bg-inset);
    color: var(--text-input);
    border: 1px solid var(--border-strong);
    padding: 3px;
    border-radius: 4px;
    text-align: center;
}
.device.inline-zone-device .clima-ctrl {
    background: var(--bg-inset);
}

.shutter-slider {
    width: 80px;
    cursor: pointer;
}
.shutter-btn {
    background-color: var(--bg-inset);
    color: #f39c12;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    width: 22px;
    height: 22px;
    line-height: 1;
    font-size: 10px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.shutter-btn:hover {
    background-color: var(--border-card);
}
.shutter-value {
    background-color: var(--bg-inset);
    color: #3498db;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    min-width: 38px;
    text-align: center;
}
.shutter-value.offline {
    color: #b0b6bf;
}
.shutter-slider:disabled,
.shutter-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.shutter-btn:disabled:hover {
    background-color: var(--bg-inset);
}

.power-badge {
    color: #f1c40f;
    font-size: 11px;
    margin-left: 6px;
    font-weight: bold;
}
.temp-badge {
    color: #3498db;
    font-size: 11px;
    margin-left: 6px;
    font-weight: bold;
}
.hum-badge {
    color: #16a085;
    font-size: 11px;
    margin-left: 6px;
    font-weight: bold;
}
.app-badge {
    color: var(--text-dim);
    font-size: 11px;
    margin-left: 6px;
    font-weight: bold;
}

.pdc-valore {
    color: #3498db;
    font-weight: bold;
    font-size: 13px;
    white-space: nowrap;
}
.pdc-valore.pdc-errore-attivo {
    color: #e74c3c;
}
.pdc-valore.pdc-ok {
    color: #2ecc71;
}

.sensor-badge {
    padding: 4px 10px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 11px;
    text-transform: uppercase;
    min-width: 50px;
    text-align: center;
}
.sensor-badge.closed {
    background-color: #27ae60;
    color: #fff;
}
.sensor-badge.open {
    background-color: #d35400;
    color: #fff;
    animation: blink 1s infinite alternate;
}
.sensor-badge.loading {
    background-color: #7f8c8d;
    color: #fff;
}
.sensor-badge.error {
    background-color: #c0392b;
    color: #fff;
}

.title-temp-value {
    background-color: var(--bg-inset);
    color: #3498db;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: bold;
    border: 1px solid var(--border-card);
}

.title-hum-value {
    background-color: var(--bg-inset);
    color: #16a085;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: bold;
    border: 1px solid var(--border-card);
    margin-left: 4px;
}

/* NAVBAR GENERICA */
.nav-bar {
    width: 100%;
    max-width: 1100px;
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
    justify-content: center;
    position: relative;
    z-index: 20;
}
.nav-link {
    background: #2c3e50; 
    color: #fff; 
    padding: 10px 20px; 
    border-radius: 8px; 
    font-weight: bold; 
    text-decoration: none; 
    border: 1px solid var(--border-strong);
}
.nav-link.active {
    background: #f39c12;
    color: #1e1e24;
    border-color: #f39c12;
}
.nav-badge {
    display: inline-block;
    margin-left: 6px;
    background-color: #e74c3c;
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    padding: 1px 6px;
    border-radius: 10px;
}

/* ================= NOTIFICHE ================= */
.notifiche-lista {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.notifiche-voce {
    background-color: var(--bg-row);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 12px 14px;
    opacity: 0.75;
}
.notifiche-voce.non-letta {
    opacity: 1;
    border-left: 3px solid var(--accent);
}
.notifiche-voce-testata {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 4px;
}
.notifiche-voce-titolo {
    font-weight: bold;
    color: #f1c40f;
    font-size: 14px;
}
.notifiche-voce-orario {
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
}
.notifiche-voce-elimina {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}
.notifiche-voce-elimina:hover {
    color: #e74c3c;
}
.notifiche-voce-messaggio {
    display: block;
    font-size: 13px;
    color: var(--text-input);
    line-height: 1.5;
}

/* ================= IMPOSTAZIONI ================= */
.impostazioni-riga {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    background-color: var(--bg-row);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 10px;
}
.impostazioni-testo {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.impostazioni-titolo {
    font-weight: bold;
    font-size: 14px;
}
.impostazioni-descrizione {
    font-size: 12px;
    color: var(--text-dim);
    max-width: 480px;
}
.interruttore {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
    flex-shrink: 0;
}
.interruttore input {
    opacity: 0;
    width: 0;
    height: 0;
}
.interruttore-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--border-strong);
    border-radius: 26px;
    transition: 0.2s;
}
.interruttore-slider::before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: #fff;
    border-radius: 50%;
    transition: 0.2s;
}
.interruttore input:checked + .interruttore-slider {
    background-color: var(--accent);
}
.interruttore input:checked + .interruttore-slider::before {
    transform: translateX(20px);
}

.notifiche-imp-lista {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.notifiche-imp-riga {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    background-color: var(--bg-row);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 12px 14px;
}
.notifiche-imp-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-basis: 100%;
    min-width: 160px;
}
.notifiche-imp-nome {
    font-weight: bold;
    font-size: 13px;
    white-space: normal;
    overflow-wrap: break-word;
}
.notifiche-imp-hint {
    font-size: 11px;
    color: var(--text-dim);
}
.notifiche-imp-toggle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: none;
}
.notifiche-imp-toggle .notifiche-imp-hint {
    font-size: 10px;
    white-space: nowrap;
}

/* SEZIONE UTENTI (Impostazioni) */
.utenti-lista {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}
.utenti-riga {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    background-color: var(--bg-row);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 12px 14px;
}
.utenti-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-basis: 100%;
    min-width: 160px;
}
.utenti-nome {
    font-weight: bold;
    font-size: 13px;
}
.utenti-hint {
    font-size: 11px;
    color: var(--text-dim);
}
.notifiche-imp-input {
    flex: 1;
    min-width: 200px;
    background-color: var(--bg-input);
    border: 1px solid var(--border-card);
    border-radius: 6px;
    color: var(--text-input);
    padding: 8px 10px;
    font-size: 13px;
}
.notifiche-imp-input-soglia {
    flex: none;
    min-width: 70px;
    max-width: 90px;
}
.notifiche-imp-input-ora {
    flex: none;
    min-width: 90px;
    max-width: 110px;
}
.notifiche-imp-esito {
    font-size: 12px;
    font-weight: bold;
    min-width: 90px;
}
.notifiche-imp-esito-ok {
    color: #2ecc71;
}
.notifiche-imp-esito-errore {
    color: #e74c3c;
}

.impostazioni-sottonav {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.impostazioni-sottonav .scene-btn {
    padding: 8px 16px;
    font-size: 13px;
}
.impostazioni-sottonav .scene-btn.active {
    border-color: var(--accent);
    color: var(--accent);
}

.automazioni-lista {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.automazione-card {
    background-color: var(--bg-row);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 14px 16px;
}
.automazione-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.automazione-nome {
    flex: 1;
    min-width: 160px;
    background-color: var(--bg-input);
    border: 1px solid var(--border-card);
    border-radius: 6px;
    color: var(--text-input);
    padding: 8px 10px;
    font-size: 14px;
    font-weight: bold;
}
.automazione-trigger {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 12px;
}
.automazione-trigger input {
    width: 64px;
    background-color: var(--bg-input);
    border: 1px solid var(--border-card);
    border-radius: 6px;
    color: var(--text-input);
    padding: 6px 8px;
    font-size: 13px;
}
.automazione-passi {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.automazione-passo {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
    background-color: var(--bg-inset);
    border: 1px solid var(--border-card);
    border-radius: 6px;
    padding: 10px 12px;
}
.automazione-passo-minuti {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex: none;
    font-size: 11px;
    color: var(--text-dim);
}
.automazione-passo-minuti input {
    width: 60px;
    background-color: var(--bg-input);
    border: 1px solid var(--border-card);
    border-radius: 6px;
    color: var(--text-input);
    padding: 6px 8px;
    font-size: 13px;
    text-align: center;
}
.automazione-azioni {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 220px;
}
.automazione-azione {
    display: flex;
    align-items: center;
    gap: 6px;
}
.automazione-azione select {
    flex: 1;
    background-color: var(--bg-input);
    border: 1px solid var(--border-card);
    border-radius: 6px;
    color: var(--text-input);
    padding: 6px 8px;
    font-size: 12px;
}
.automazione-azione input {
    width: 55px;
    background-color: var(--bg-input);
    border: 1px solid var(--border-card);
    border-radius: 6px;
    color: var(--text-input);
    padding: 6px 8px;
    font-size: 12px;
    text-align: center;
}
.automazione-mini-btn {
    background: none;
    border: 1px solid var(--border-card);
    color: var(--text-dim);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    flex: none;
}
.automazione-mini-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.automazione-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}
.automazione-esito {
    font-size: 12px;
    font-weight: bold;
    align-self: center;
}

@media (max-width: 640px) {
    .notifiche-imp-riga {
        flex-direction: column;
        align-items: stretch;
    }
    .notifiche-imp-input {
        min-width: 0;
    }
}

@keyframes blink {
    0% { opacity: 0.7; }
    100% { opacity: 1; box-shadow: 0 0 5px rgba(211, 84, 0, 0.6); }
}

/* --- STILI PER IL MENU A TENDINA (DROPDOWN) --- */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: #2c3e50;
    min-width: 180px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.4);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    z-index: 100;
    margin-top: 5px;
    overflow: hidden;
}

/* Opzioni interne alla tendina */
.dropdown-option {
    color: white;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.dropdown-option:hover {
    background-color: var(--border-card);
}

/* Mostra la tendina quando viene aggiunta la classe 'show' via JS */
.dropdown-content.show {
    display: block;
}

/* Forzatura colore arancione per stato attivo dei bottoni navbar */
.nav-bar .nav-link.active {
    background-color: #f39c12 !important;
    color: #1e1e24 !important;
    border-color: #f39c12 !important;
}


/* Allineamento orizzontale dei blocchi nell'header */
.header-widgets {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Struttura del box meteo */
.weather-box {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Badge temperatura esterna dinamica */
#weather-temp {
    margin-left: 8px;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: bold;
    transition: background-color 0.5s ease;
    border: 1px solid var(--border-card);
}

/* Slider (dimmer/tapparelle) più grandi e facili da trascinare col dito */
input[type="range"] {
    -webkit-appearance: none;
    height: 6px;
    background: var(--border-card);
    border-radius: 3px;
    outline: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-inset);
}
input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-inset);
}

/* ================= VISTA MOBILE ================= */
@media (max-width: 640px) {
    body {
        padding: 10px;
    }
    .header-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .header-widgets {
        flex-wrap: wrap;
        width: 100%;
    }
    .nav-bar {
        justify-content: flex-start;
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }
    .nav-link {
        flex: none;
        padding: 10px 14px;
        font-size: 13px;
    }
    .scene-bar {
        flex-direction: column;
    }
    .scene-btn {
        width: 100%;
        padding: 14px;
        font-size: 15px;
    }
    .house-map {
        grid-template-columns: 1fr;
    }
    .btn-toggle {
        padding: 10px 16px;
        min-width: 64px;
        font-size: 14px;
    }
    .device {
        padding: 12px 10px;
        font-size: 14px;
        flex-wrap: wrap;
        gap: 8px;
    }
    .shutter-slider, .dimmer-slider {
        width: 100px;
    }
}