:root {
    color-scheme:dark;
    --bg:#0b1220;
    --panel:#111c2e;
    --panel2:#142238;
    --line:#24334a;
    --muted:#8d9bb0;
    --text:#edf3fb;
    --blue:#4e8cff;
    --green:#27c995;
    --orange:#f1ad52;
    --red:#f16b70;
}
* {
    box-sizing:border-box;
}
html {
    scroll-behavior:smooth;
}
body {
    margin:0;
    background:var(--bg);
    color:var(--text);
    font:14px/1.5 Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,sans-serif;
}
.sidebar {
    position:fixed;
    inset:0 auto 0 0;
    width:242px;
    background:#0e192a;
    border-right:1px solid #1e2b40;
    padding:25px 18px;
    display:flex;
    flex-direction:column;
    z-index:5;
}
.brand {
    display:flex;
    align-items:center;
    gap:11px;
    color:#f3f7fc;
    text-decoration:none;
    font-size:17px;
    font-weight:800;
    letter-spacing:-.5px;
}
.brand-light {
    font-weight:500;
    color:#a9b7ca;
}
.brand small {
    display:block;
    font-size:9px;
    letter-spacing:1.5px;
    color:#71829b;
    font-weight:700;
    margin-top:2px;
}
.brand-icon {
    width:39px;
    height:39px;
    border-radius:11px;
    background:linear-gradient(145deg,#4d91ff,#2860c6);
    display:grid;
    place-items:center;
    color:white;
    font-size:13px;
    font-weight:900;
    box-shadow:0 5px 18px #2860c644;
}
.nav-label {
    font-size:10px;
    letter-spacing:1.5px;
    color:#64758e;
    font-weight:800;
    margin:43px 10px 12px;
}
.nav-link {
    display:flex;
    align-items:center;
    gap:12px;
    text-decoration:none;
    color:#9aa9be;
    padding:12px 13px;
    border-radius:9px;
    margin:3px 0;
    font-weight:600;
}
.nav-link span {
    font-size:18px;
    width:20px;
    text-align:center;
}
.nav-link.active,.nav-link:hover {
    background:#1b2c45;
    color:#fff;
}
.nav-link.active {
    box-shadow:inset 3px 0 #5592ff;
}
.sidebar-bottom {
    margin-top:auto;
}
.side-status {
    display:flex;
    align-items:center;
    gap:11px;
    padding:14px 10px;
    border-bottom:1px solid #24334a;
}
.side-status b,.side-status small {
    display:block;
}
.side-status b {
    font-size:12px;
}
.side-status small {
    font-size:10px;
    color:var(--muted);
}
.status-dot {
    width:8px;
    height:8px;
    border-radius:50%;
    background:#e3a94e;
    display:inline-block;
    flex:none;
    box-shadow:0 0 0 4px #e3a94e1c;
}
.status-dot.online {
    background:var(--green);
    box-shadow:0 0 0 4px #27c99520;
}
.side-user {
    display:flex;
    align-items:center;
    gap:9px;
    padding:15px 5px 0;
    color:#c4cfdd;
    font-size:12px;
}
.avatar {
    width:27px;
    height:27px;
    border-radius:50%;
    display:grid;
    place-items:center;
    background:#2c4261;
    color:#dceaff;
    font-weight:800;
}
.side-user form {
    margin-left:auto;
}
.logout {
    border:0;
    background:transparent;
    color:#9aabc2;
    cursor:pointer;
    font:inherit;
}
.main {
    max-width:1600px;
    margin-left:242px;
    padding:34px 38px 22px;
}
.mobile-header {
    display:none;
}
.page-top {
    display:flex;
    justify-content:space-between;
    align-items:flex-end;
    gap:20px;
    margin-bottom:23px;
}
.eyebrow {
    font-size:10px;
    letter-spacing:1.8px;
    color:#6f86a5;
    font-weight:800;
}
.page-top h1 {
    font-size:27px;
    letter-spacing:-.8px;
    margin:5px 0 1px;
}
.subline,.panel-heading p {
    margin:0;
    color:var(--muted);
    font-size:12px;
}
.top-meta {
    text-align:right;
}
.online-pill {
    display:inline-flex;
    align-items:center;
    gap:9px;
    background:#14243a;
    border:1px solid #293d59;
    border-radius:30px;
    padding:8px 13px;
    font-size:11px;
    color:#c8d5e6;
}
.updated {
    font-size:10px;
    color:#74859e;
    margin-top:8px;
}
.updated b {
    color:#b7c5d8;
    font-weight:600;
    margin-left:4px;
}
.dev-notice,.toast {
    border-radius:9px;
    padding:11px 14px;
    margin:0 0 18px;
    font-size:11px;
}
.dev-notice {
    background:#342a1b;
    border:1px solid #624a2a;
    color:#e5c58e;
    display:flex;
    gap:9px;
    flex-wrap:wrap;
}
.dev-notice span {
    color:#c9b58e;
}
.toast {
    background:#12372f;
    border:1px solid #23634e;
    color:#8de0bf;
}
.metrics {
    display:grid;
    grid-template-columns:repeat(4,minmax(0,1fr));
    gap:14px;
    margin-bottom:16px;
}
.metric-card,.panel {
    background:var(--panel);
    border:1px solid var(--line);
    border-radius:12px;
    box-shadow:0 8px 26px #00000012;
}
.metric-card {
    padding:17px 18px 15px;
    min-width:0;
}
.metric-top {
    display:flex;
    align-items:center;
    justify-content:space-between;
    color:#9babc0;
    font-size:11px;
}
.metric-icon {
    width:29px;
    height:29px;
    border-radius:8px;
    background:#1b304c;
    color:#73a6ff;
    display:grid;
    place-items:center;
    font-size:17px;
}
.metric-value {
    display:flex;
    align-items:baseline;
    gap:7px;
    margin-top:12px;
}
.metric-value strong {
    font-size:29px;
    line-height:1.1;
    letter-spacing:-1px;
    font-weight:750;
    font-variant-numeric:tabular-nums;
}
.metric-value small {
    font-size:12px;
    color:#8495ad;
}
.metric-foot {
    font-size:10px;
    color:#6f819b;
    margin-top:9px;
}
.content-grid {
    display:grid;
    grid-template-columns:minmax(0,1.7fr) minmax(290px,1fr);
    gap:15px;
}
.panel {
    padding:19px;
    margin-bottom:15px;
    min-width:0;
}
.panel-heading {
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:12px;
    margin-bottom:17px;
}
.panel-heading h2 {
    font-size:14px;
    margin:0 0 3px;
    letter-spacing:-.2px;
}
.period-tag,.live-tag {
    font-size:9px;
    letter-spacing:1px;
    font-weight:800;
    color:#8fa4c2;
    background:#1b2a40;
    border:1px solid #2a3b54;
    padding:6px 9px;
    border-radius:5px;
    white-space:nowrap;
}
.live-tag {
    color:#7eb4ff;
}
.chart-legend {
    display:flex;
    gap:17px;
    color:#9aabc1;
    font-size:10px;
    margin:1px 0 8px;
}
.chart-legend span {
    display:flex;
    align-items:center;
    gap:6px;
}
.chart-legend i {
    width:7px;
    height:7px;
    border-radius:50%;
    display:inline-block;
}
.legend-grid {
    background:#5594ff;
}
.legend-solar {
    background:#27c995;
}
.legend-house {
    background:#e8aa55;
}
.chart-area {
    height:190px;
    width:100%;
    overflow:hidden;
}
.chart-area svg {
    width:100%;
    height:100%;
    overflow:visible;
}
.chart-empty {
    fill:#72849e;
    font-size:12px;
}
.chart-gridline {
    stroke:#25354c;
    stroke-width:1;
    stroke-dasharray:3 5;
}
.line-grid,.line-solar,.line-house {
    fill:none;
    stroke-width:2.6;
    stroke-linecap:round;
    stroke-linejoin:round;
}
.line-grid {
    stroke:#5594ff;
}
.line-solar {
    stroke:#27c995;
}
.line-house {
    stroke:#e8aa55;
}
.chart-axis {
    display:flex;
    justify-content:space-between;
    color:#71829a;
    font-size:9px;
    padding:3px 2px 0;
}
.source-current {
    display:flex;
    align-items:center;
    gap:12px;
    padding:15px;
    background:#172840;
    border:1px solid #2b405d;
    border-radius:9px;
    margin-bottom:17px;
}
.source-symbol {
    width:37px;
    height:37px;
    border-radius:9px;
    background:#203c60;
    color:#75aaff;
    display:grid;
    place-items:center;
    font-size:22px;
}
.source-current small,.source-current strong {
    display:block;
}
.source-current small {
    font-size:9px;
    letter-spacing:1px;
    color:#8195b1;
}
.source-current strong {
    font-size:20px;
    margin-top:1px;
}
.control-label {
    font-size:9px;
    letter-spacing:1px;
    color:#7e91ac;
    font-weight:800;
    margin-bottom:8px;
}
.source-buttons,.mode-buttons {
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:8px;
}
.source-buttons form,.mode-buttons form {
    margin:0;
}
.source-btn,.mode-btn {
    width:100%;
    border:1px solid #344a68;
    border-radius:7px;
    padding:10px 8px;
    background:#1a2b43;
    color:#cbd8e9;
    font:600 11px inherit;
    cursor:pointer;
}
.source-btn:hover,.mode-btn:hover {
    border-color:#609aff;
    background:#203957;
}
.mode-row {
    display:flex;
    justify-content:space-between;
    align-items:center;
    margin:17px 0 8px;
    color:#9aabc0;
    font-size:10px;
}
.mode-row b {
    color:#dce7f5;
}
.mode-btn {
    background:transparent;
    padding:8px;
}
.safety-note {
    font-size:9px;
    line-height:1.5;
    color:#788ba5;
    margin:13px 0 0;
}
.lower-grid {
    display:grid;
    grid-template-columns:1.35fr 1fr;
    gap:15px;
}
.relay-grid {
    display:grid;
    grid-template-columns:repeat(4,1fr);
    gap:9px;
}
.relay-item {
    display:flex;
    align-items:center;
    gap:8px;
    padding:10px 8px;
    background:#15243a;
    border:1px solid #263951;
    border-radius:8px;
    min-width:0;
}
.relay-led {
    width:7px;
    height:7px;
    border-radius:50%;
    background:#64748b;
    flex:none;
}
.relay-led.on {
    background:var(--green);
    box-shadow:0 0 8px #27c99580;
}
.relay-item b,.relay-item small {
    display:block;
    white-space:nowrap;
}
.relay-item b {
    font-size:10px;
}
.relay-item small {
    font-size:9px;
    color:#7f91aa;
}
.alarm-count {
    background:#25354a;
    color:#aebdd0;
    border-radius:20px;
    min-width:23px;
    text-align:center;
    padding:3px 7px;
    font-size:10px;
}
.alarm-content {
    padding:13px;
    background:#15253a;
    border:1px solid #293d57;
    border-radius:8px;
    color:#8fa1b9;
    font-size:11px;
}
.alarm-content.has-alarm {
    background:#382226;
    border-color:#704047;
    color:#ffb3b7;
}
.queue-info {
    display:flex;
    justify-content:space-between;
    margin-top:15px;
    padding-top:12px;
    border-top:1px solid #26364d;
    color:#91a2b8;
    font-size:10px;
}
.queue-info b {
    color:#e4edf8;
}
.history-panel {
    margin-top:0;
}
.table-scroll {
    overflow:auto;
}
table {
    width:100%;
    border-collapse:collapse;
    white-space:nowrap;
    font-size:10px;
}
th,td {
    text-align:left;
    padding:10px 11px;
    border-bottom:1px solid #223149;
}
th {
    color:#7f91aa;
    font-size:9px;
    letter-spacing:.7px;
    text-transform:uppercase;
    font-weight:700;
}
td {
    color:#c0ccdc;
}
tbody tr:last-child td {
    border-bottom:0;
}
.empty {
    text-align:center;
    color:#7588a2;
    padding:22px!important;
}
.commands-panel {
    padding-bottom:8px;
}
.command-list {
    display:grid;
    gap:0;
}
.command-row {
    display:grid;
    grid-template-columns:75px minmax(80px,1fr) 65px 130px;
    gap:10px;
    align-items:center;
    padding:9px 2px;
    border-top:1px solid #24334a;
    font-size:10px;
}
.command-row:first-child {
    border-top:0;
}
.command-row span {
    color:#91a5c0;
    font-weight:700;
}
.command-row b {
    color:#c8d5e5;
    font-weight:500;
    overflow:hidden;
    text-overflow:ellipsis;
}
.command-row em {
    font-style:normal;
    color:#d8b779;
}
.command-row small {
    color:#71839c;
    text-align:right;
}
.state-done {
    color:#53d4a6!important;
}
.state-error {
    color:#ff858b!important;
}
footer {
    text-align:center;
    color:#61738d;
    font-size:10px;
    padding:8px 0 15px;
}
footer span {
    padding:0 5px;
    color:#344761;
}

/* ---------------------------------------------------------
   Layout responsive: notebook, tablet, iPad e smartphone
   --------------------------------------------------------- */

html,
body {
    width: 100%;
    min-width: 320px;
    overflow-x: hidden;
}

.main,
.panel,
.metric-card,
.content-grid > *,
.lower-grid > * {
    min-width: 0;
}

.main {
    width: auto;
}

.table-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-scroll table {
    min-width: 760px;
}

button,
input,
select,
textarea {
    max-width: 100%;
}

/* Notebook e tablet in orizzontale */
@media (max-width: 1200px) {
    .main {
        padding: 28px 26px;
    }

    .metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .content-grid {
        grid-template-columns: minmax(0, 1.4fr) minmax(270px, 1fr);
    }

    .lower-grid {
        grid-template-columns: minmax(0, 1.2fr) minmax(260px, 1fr);
    }
}

/* Tablet e iPad in verticale */
@media (max-width: 900px) {
    .sidebar {
        display: none;
    }

    .main {
        margin-left: 0;
        max-width: none;
        padding: 24px;
    }

    .mobile-header {
        display: flex;
        align-items: center;
        gap: 11px;
        margin: 0 0 25px;
        padding: 10px 0 15px;
        border-bottom: 1px solid var(--line);
    }

    .mobile-header b {
        font-size: 15px;
    }

    .mobile-header form {
        margin-left: auto;
    }

    .content-grid,
    .lower-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .source-panel {
        display: block;
    }

    .relay-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* Smartphone */
@media (max-width: 600px) {
    .main {
        padding: 15px 12px 20px;
    }

    .mobile-header {
        margin-bottom: 20px;
        padding: 7px 0 12px;
    }

    .brand-icon {
        width: 36px;
        height: 36px;
        flex: 0 0 36px;
    }

    .page-top {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
        margin-bottom: 17px;
    }

    .page-top h1 {
        font-size: clamp(21px, 6vw, 25px);
        line-height: 1.2;
    }

    .subline {
        font-size: 11px;
    }

    .top-meta {
        width: 100%;
        text-align: left;
    }

    .online-pill {
        padding: 7px 10px;
    }

    .updated {
        margin-top: 6px;
    }

    .metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 9px;
        margin-bottom: 12px;
    }

    .metric-card {
        padding: 12px 11px;
        border-radius: 10px;
    }

    .metric-top {
        align-items: flex-start;
        gap: 6px;
        font-size: 10px;
    }

    .metric-icon {
        width: 25px;
        height: 25px;
        flex: 0 0 25px;
    }

    .metric-value {
        gap: 4px;
        margin-top: 10px;
    }

    .metric-value strong {
        font-size: clamp(19px, 6vw, 24px);
        overflow-wrap: anywhere;
    }

    .metric-value small {
        font-size: 10px;
    }

    .metric-foot {
        font-size: 9px;
        line-height: 1.35;
    }

    .panel {
        padding: 13px;
        margin-bottom: 12px;
        border-radius: 10px;
    }

    .panel-heading {
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 13px;
    }

    .panel-heading h2 {
        font-size: 13px;
    }

    .panel-heading p {
        font-size: 10px;
    }

    .period-tag,
    .live-tag {
        padding: 5px 6px;
        font-size: 8px;
    }

    .chart-legend {
        flex-wrap: wrap;
        gap: 8px 13px;
        font-size: 9px;
    }

    .chart-area {
        height: 155px;
    }

    .source-current {
        padding: 12px;
        margin-bottom: 14px;
    }

    .source-btn,
    .mode-btn {
        min-height: 42px;
        padding: 10px 7px;
        font-size: 11px;
    }

    .mode-row {
        gap: 8px;
        font-size: 10px;
    }

    .relay-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 7px;
    }

    .relay-item {
        padding: 9px 7px;
    }

    .relay-item b {
        font-size: 10px;
    }

    .relay-item small {
        font-size: 9px;
    }

    .command-row {
        grid-template-columns: 58px minmax(0, 1fr) 55px;
        gap: 7px;
        font-size: 9px;
    }

    .command-row small {
        display: none;
    }

    .dev-notice {
        display: block;
        line-height: 1.45;
    }

    .dev-notice span {
        display: block;
        margin-top: 4px;
    }

    .table-scroll table {
        min-width: 700px;
    }

    footer {
        padding-bottom: 10px;
    }
}

/* Smartphone stretto */
@media (max-width: 380px) {
    .main {
        padding-right: 9px;
        padding-left: 9px;
    }

    .metrics {
        gap: 7px;
    }

    .metric-card {
        padding: 10px 9px;
    }

    .metric-value strong {
        font-size: 19px;
    }

    .panel {
        padding: 11px;
    }

    .chart-legend {
        gap: 7px;
    }

    .relay-item {
        gap: 6px;
        padding: 8px 6px;
    }
}

/* Rispetta la preferenza di sistema per le animazioni ridotte */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}


/* ---------------------------------------------------------
   Pagina di accesso: desktop, tablet e smartphone
   --------------------------------------------------------- */

body.auth {
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    margin: 0;
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
}

.auth-card {
    width: 100%;
    max-width: 440px;
    margin: auto;
    padding: 34px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 18px 55px #00000035;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 30px;
}

.auth-brand .brand-mark {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(145deg, #4d91ff, #2860c6);
    color: #ffffff;
    font-size: 14px;
    font-weight: 900;
    box-shadow: 0 5px 18px #2860c644;
}

.auth-brand-name {
    color: var(--text);
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.6px;
}

.auth-heading {
    margin-bottom: 25px;
}

.auth-heading h1 {
    margin: 0 0 6px;
    color: var(--text);
    font-size: 25px;
    line-height: 1.2;
    letter-spacing: -0.6px;
}

.auth-heading p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 17px;
    width: 100%;
    margin: 0;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    width: 100%;
    min-width: 0;
}

.auth-field label {
    display: block;
    color: #cbd7e7;
    font-size: 12px;
    font-weight: 650;
}

.auth-field input {
    display: block;
    width: 100%;
    min-width: 0;
    min-height: 46px;
    padding: 11px 13px;
    border: 1px solid #34445d;
    border-radius: 8px;
    outline: none;
    background: #080f1c;
    color: var(--text);
    font: inherit;
    font-size: 16px;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.auth-field input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px #4e8cff25;
}

.auth-submit {
    display: block;
    width: 100%;
    min-height: 46px;
    margin-top: 5px;
    border: 1px solid #5b9aff;
    border-radius: 8px;
    background: var(--blue);
    color: #ffffff;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.auth-submit:hover {
    background: #397bea;
}

.auth-card .success,
.auth-card .alert {
    margin: 0 0 17px;
    padding: 11px 13px;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.45;
}

.auth-card .success {
    border: 1px solid #23634e;
    background: #12372f;
    color: #8de0bf;
}

.auth-card .alert {
    border: 1px solid #704047;
    background: #382226;
    color: #ffb3b7;
}

/* Tablet */
@media (max-width: 900px) {
    body.auth {
        padding: 22px;
    }

    .auth-card {
        max-width: 420px;
    }
}

/* Smartphone */
@media (max-width: 600px) {
    body.auth {
        align-items: center;
        padding: 18px 14px;
    }

    .auth-card {
        max-width: 100%;
        padding: 25px 21px;
        border-radius: 13px;
    }

    .auth-brand {
        gap: 10px;
        margin-bottom: 25px;
    }

    .auth-brand .brand-mark {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
    }

    .auth-brand-name {
        font-size: 19px;
    }

    .auth-heading {
        margin-bottom: 22px;
    }

    .auth-heading h1 {
        font-size: 23px;
    }

    .auth-form {
        gap: 16px;
    }

    .auth-field input {
        min-height: 48px;
        font-size: 16px;
    }

    .auth-submit {
        min-height: 48px;
        margin-top: 3px;
    }
}

/* Smartphone stretto */
@media (max-width: 360px) {
    body.auth {
        padding: 12px;
    }

    .auth-card {
        padding: 22px 17px;
    }
}
