:root {
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --primary: #3b82f6;
    --success: #10b981;
    --danger: #ef4444;
    --warn: #f59e0b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Inter', system-ui, sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Navbar */
.navbar {
    height: 60px;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 50;
}

/* Layout */
.layout { display: flex; flex: 1; overflow: hidden; }

/* Sidebar */
.sidebar {
    width: 320px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.device-list { flex: 1; overflow-y: auto; padding: 1rem; }

.device-item {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.device-item:hover { border-color: var(--primary); }
.device-item.active { border-color: var(--primary); background: rgba(59, 130, 246, 0.1); }

/* Main Content */
.main {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    background: var(--bg-dark);
    position: relative;
}

/* Components */
.tab-btn {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.2s;
}
.tab-btn.active { background: var(--primary); color: white; }

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.5rem;
}

.chart-container { height: 250px; width: 100%; position: relative; } /* Ridotto altezza per stack verticale */

#map { height: 600px; width: 100%; border-radius: 0.5rem; z-index: 1; }

.modal {
    display: none;
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.75);
    z-index: 100; align-items: center; justify-content: center;
}
.modal.show { display: flex; }

.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.connected { background: var(--success); box-shadow: 0 0 8px var(--success); }
.dot.disconnected { background: var(--danger); }

.form-input {
    width: 100%;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: white;
    padding: 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
}
.form-input:disabled { opacity: 0.5; cursor: not-allowed; }

.btn {
    font-weight: 700;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    transition: all 0.2s;
    color: white;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(100%); }
.btn-primary { background-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background-color: #2563eb; }
.btn-success { background-color: var(--success); }
.btn-success:hover:not(:disabled) { background-color: #059669; }
.btn-danger { background-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background-color: #dc2626; }
.btn-warn { background-color: var(--warn); }
.btn-warn:hover:not(:disabled) { background-color: #d97706; }
.btn-secondary { background-color: #475569; }
.btn-secondary:hover:not(:disabled) { background-color: #334155; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ========== MOBILE RESPONSIVE ========== */

/* Mobile menu toggle button */
.mobile-menu-btn {
    display: none;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: white;
    padding: 0.5rem;
    border-radius: 0.375rem;
    font-size: 1.25rem;
    cursor: pointer;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
}
.sidebar-overlay.show { display: block; }

/* Mobile breakpoint: < 768px */
@media (max-width: 767px) {
    .navbar {
        padding: 0 1rem;
        height: 56px;
    }

    .navbar .text-xl {
        font-size: 1rem;
    }

    .mobile-menu-btn {
        display: block;
    }

    .layout {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 56px;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        z-index: 45;
        transition: left 0.3s ease;
    }

    .sidebar.open {
        left: 0;
    }

    .main {
        padding: 1rem;
        width: 100%;
    }

    /* Tabs scrollable on mobile */
    #tabs-nav {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding-bottom: 0.5rem;
        margin-bottom: 1rem;
    }

    #tabs-nav::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
        flex-shrink: 0;
    }

    /* Cards full width */
    .card {
        padding: 1rem;
    }

    /* Grid adjustments */
    .grid-cols-2 { grid-template-columns: 1fr !important; }
    .grid-cols-3 { grid-template-columns: 1fr !important; }
    .grid-cols-4 { grid-template-columns: repeat(2, 1fr) !important; }
    .md\:grid-cols-2 { grid-template-columns: 1fr !important; }
    .md\:grid-cols-3 { grid-template-columns: 1fr !important; }
    .md\:grid-cols-4 { grid-template-columns: repeat(2, 1fr) !important; }

    /* Buttons stack vertically */
    .card .grid.grid-cols-2.gap-3 {
        grid-template-columns: 1fr;
    }

    /* File panel heights */
    .card.h-\[380px\] {
        height: auto;
        max-height: none;
    }

    /* Chart containers smaller on mobile */
    .chart-container {
        height: 200px;
    }

    /* Map smaller on mobile */
    #map {
        height: 400px;
    }

    /* Modal full width on mobile */
    .modal > div {
        width: 95% !important;
        max-width: 400px;
        margin: 1rem;
        padding: 1.5rem !important;
    }

    /* Device name smaller */
    #dev-name {
        font-size: 1.25rem;
    }

    /* Analysis toolbar */
    #chart-area .flex.flex-wrap {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    #chart-area .flex.flex-wrap > * {
        width: 100%;
    }

    /* Group buttons */
    .md\:grid-cols-4 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* Small mobile: < 480px */
@media (max-width: 479px) {
    .navbar .text-xl {
        font-size: 0.875rem;
    }

    .grid-cols-4 { grid-template-columns: 1fr !important; }
    .md\:grid-cols-4 { grid-template-columns: 1fr !important; }

    .tab-btn {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
    }

    .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.875rem;
    }

    .chart-container {
        height: 180px;
    }
}

/* Tablet: 768px - 1024px */
@media (min-width: 768px) and (max-width: 1024px) {
    .sidebar {
        width: 260px;
    }

    .main {
        padding: 1rem;
    }

    .chart-container {
        height: 220px;
    }
}

/* OTA Update Section Styles */
.ota-section {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    margin-top: 1rem;
}

.ota-progress {
    height: 1.5rem;
    background: var(--bg-dark);
    border-radius: 0.375rem;
    overflow: hidden;
    border: 1px solid var(--border);
}

.ota-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: bold;
    color: white;
}

.ota-status {
    padding: 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    text-align: center;
}

.ota-status.pending { background: rgba(245, 158, 11, 0.2); color: var(--warn); }
.ota-status.success { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.ota-status.error { background: rgba(239, 68, 68, 0.2); color: var(--danger); }