/* ================================================================
   Shelly Monitor — stile minimale, responsive
   ================================================================ */

/* ---- Reset & base ---- */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    background: #f0f4f8;
    color: #1e293b;
}

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Navbar ---- */
.navbar {
    background: #1e3a8a;
    color: #fff;
    min-height: 54px;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    box-shadow: 0 2px 6px rgba(0,0,0,.18);
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand {
    font-size: 1.05rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: .45rem;
    color: #fff;
    text-decoration: none;
    padding: .75rem 0;
}
.nav-brand:hover { text-decoration: none; color: #fff; }
.nav-links {
    display: flex;
    align-items: center;
    gap: .2rem;
    flex-wrap: wrap;
}
.nav-link {
    color: rgba(255,255,255,.82);
    padding: .35rem .85rem;
    border-radius: 5px;
    font-size: .9rem;
    transition: background .15s;
}
.nav-link:hover { background: rgba(255,255,255,.15); color: #fff; text-decoration: none; }
.nav-user {
    color: rgba(255,255,255,.6);
    font-size: .85rem;
    padding: .35rem .6rem;
}

/* Hamburger button — nascosto su desktop */
.nav-hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: .5rem;
    border-radius: 6px;
    transition: background .15s;
}
.nav-hamburger:hover { background: rgba(255,255,255,.15); }
.nav-hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: transform .2s, opacity .2s;
}

/* ---- Layout ---- */
.container { max-width: 1160px; margin: 0 auto; padding: 1.5rem 1rem; }

.page-header {
    display: flex;
    align-items: center;
    gap: .85rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.page-header h1 { margin: 0; font-size: 1.45rem; font-weight: 700; }

/* ---- Cards ---- */
.card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    margin-bottom: 1rem;
    overflow: hidden;
}
.card-header {
    padding: .7rem 1.25rem;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    font-weight: 600;
    font-size: .9rem;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.card-body { padding: 1.25rem; }
.card-danger .card-header { background: #fff5f5; border-bottom-color: #fecaca; color: #b91c1c; }

/* Collapsible add-device panel */
details.card > summary {
    padding: .7rem 1.25rem;
    cursor: pointer;
    font-weight: 600;
    font-size: .9rem;
    color: #2563eb;
    background: #f8fafc;
    list-style: none;
    user-select: none;
}
details.card > summary::marker,
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "+ "; }
details[open].card > summary::before { content: "− "; }

/* ---- Status badges ---- */
.badge {
    display: inline-block;
    padding: .2rem .7rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.badge-online     { background: #dcfce7; color: #15803d; }
.badge-silenzioso { background: #fef3c7; color: #b45309; }
.badge-offline    { background: #fee2e2; color: #b91c1c; }
.badge-nuovo      { background: #f1f5f9; color: #64748b; }

/* ---- Table ---- */
.table { width: 100%; border-collapse: collapse; }
.table th {
    padding: .6rem 1rem;
    text-align: left;
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #64748b;
    background: #f8fafc;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
}
.table td {
    padding: .8rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }

/* ---- Metric cards (device detail) ---- */
.metrics-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}
.metric-card {
    background: #fff;
    border-radius: 10px;
    padding: 1.4rem;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.metric-value { font-size: 2.8rem; font-weight: 800; line-height: 1; }
.metric-value.temp { color: #e53935; }
.metric-value.hum  { color: #1976d2; }
.metric-label { font-size: .85rem; color: #64748b; margin-top: .4rem; font-weight: 500; }
.metric-threshold { font-size: .75rem; color: #94a3b8; margin-top: .2rem; }

/* ---- Charts ---- */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}
.chart-wrap { padding: 1rem 1.25rem 1.25rem; }
.chart-container { position: relative; height: 220px; }
.no-data { color: #94a3b8; font-style: italic; text-align: center; padding: 2rem 0; }

/* ---- Forms ---- */
.form-body  { padding: 1.25rem 1.25rem .5rem; }
.form-footer { padding: .75rem 1.25rem 1.25rem; }
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: .75rem;
}
.form-group { display: flex; flex-direction: column; gap: .3rem; }
.form-group label { font-weight: 500; font-size: .9rem; color: #374151; }

input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"] {
    padding: .45rem .75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: .95rem;
    width: 100%;
    transition: border-color .15s, box-shadow .15s;
    background: #fff;
}
input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
input.narrow { max-width: 110px !important; }

.check-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.check-row input[type="checkbox"] { width: auto; }
.check-row label { margin: 0; font-weight: 500; font-size: .9rem; }
.input-unit { display: flex; align-items: center; gap: .4rem; }
.unit { color: #64748b; font-size: .9rem; }
.form-hint { font-size: .78rem; color: #6b7280; margin-top: .2rem; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1.2rem;
    border: none;
    border-radius: 6px;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: filter .15s;
    white-space: nowrap;
}
.btn:hover { filter: brightness(.91); text-decoration: none; }
.btn-primary   { background: #2563eb; color: #fff; }
.btn-secondary { background: #e2e8f0; color: #334155; }
.btn-danger    { background: #dc2626; color: #fff; }
.btn-sm { padding: .3rem .85rem; font-size: .82rem; }
.btn-full { width: 100%; justify-content: center; }

/* ---- Alerts ---- */
.alert { padding: .75rem 1.1rem; border-radius: 7px; margin-bottom: 1rem; font-size: .9rem; }
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.alert-danger  { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }

/* ---- Misc ---- */
.text-muted   { color: #94a3b8; }
.text-center  { text-align: center; }
.small        { font-size: .82rem; }
.mono         { font-family: "Consolas", "Courier New", monospace; font-size: .95em; }
.mt-1         { margin-top: 1rem; }

.device-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1.2rem;
    background: #fff;
    border-radius: 10px;
    padding: .75rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    font-size: .9rem;
}
.device-meta strong { color: #475569; }

/* ---- Login page ---- */
body.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
}
.login-box {
    background: #fff;
    border-radius: 14px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 24px 48px rgba(0,0,0,.22);
}
.login-box h1 { text-align: center; margin: 0 0 1.75rem; font-size: 1.35rem; color: #1e293b; }
.login-box .form-group { margin-bottom: 1rem; }
.login-box label { display: block; margin-bottom: .3rem; font-weight: 500; font-size: .9rem; }
.login-box .btn { margin-top: .5rem; }

/* ---- Nav user label ---- */
.nav-user {
    color: rgba(255,255,255,.6);
    padding: .35rem .6rem;
    font-size: .85rem;
    font-style: italic;
}

/* ---- Tabella dati (admin) ---- */
.data-table {
    border-collapse: collapse;
    font-size: .9rem;
}
.data-table th {
    text-align: left;
    padding: .6rem 1rem;
    background: var(--bg-alt, #f8fafc);
    border-bottom: 2px solid var(--border, #e2e8f0);
    font-weight: 600;
    color: var(--text-muted, #64748b);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.data-table td {
    padding: .65rem 1rem;
    border-bottom: 1px solid var(--border, #e2e8f0);
    vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(37,99,235,.04); }

/* ---- Select stilizzata ---- */
.form-select {
    display: block;
    width: 100%;
    padding: .45rem .75rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    font-size: .92rem;
    color: #1e293b;
    appearance: auto;
}
.form-select:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }

/* ---- Input disabilitato ---- */
.input-disabled {
    display: block;
    width: 100%;
    padding: .45rem .75rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
    color: #94a3b8;
    font-size: .92rem;
}

/* ---- Responsive ---- */
@media (max-width: 720px) {
    .chart-grid   { grid-template-columns: 1fr; }
    .metrics-row  { grid-template-columns: 1fr 1fr; }
    .form-grid    { grid-template-columns: 1fr; }
    .data-table th, .data-table td { padding: .5rem .65rem; }

    /* Card touch-friendly */
    .btn { padding: .55rem 1rem; min-height: 42px; }
    .card { border-radius: 10px; }
}

/* ---- Navbar mobile ---- */
@media (max-width: 640px) {
    .navbar { padding: 0 1rem; position: relative; }

    .nav-hamburger { display: flex; }

    /* Menu chiuso: nascosto */
    .nav-links {
        display: none;
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
        padding: .5rem 0 .75rem;
        gap: .1rem;
        border-top: 1px solid rgba(255,255,255,.15);
    }

    /* Menu aperto */
    .nav-links.nav-open { display: flex; }

    .nav-link {
        width: 100%;
        padding: .65rem .9rem;
        font-size: .95rem;
        border-radius: 6px;
    }
    .nav-user {
        padding: .5rem .9rem;
        font-size: .85rem;
    }
    .nav-link-logout {
        margin-top: .25rem;
        border-top: 1px solid rgba(255,255,255,.12);
        padding-top: .75rem;
    }
}
