:root {
    --bg-color: #1F2527;
    /* Crema Background Default */
    --card-bg: #2B3137;
    /* Crema Background Paper */
    --text-primary: #ffffff;
    --text-secondary: #e5e7eb;
    --accent: #0A8FDC;
    /* Crema Primary Blue */
    --accent-hover: #0779ba;
    --success: #11C15B;
    /* Crema Success */
    --warning: #FF5252;
    /* Crema Warning (Reddish in config) */
    --danger: #FF5252;
    --border: rgba(255, 255, 255, 0.1);
    --sidebar-bg: #313541;
    /* Crema Dark Sidebar */
    --sidebar-width: 260px;
    --radius: 16px;
    /* Crema Standard Radius */
    --shadow: 0px 10px 10px 4px rgba(0, 0, 0, 0.04);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Be Vietnam Pro', 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

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

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 40px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.menu-item {
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s;
}

.menu-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.menu-item.active {
    background-color: rgba(56, 189, 248, 0.1);
    color: var(--accent);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
    position: relative;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

/* Views (Modules) */
.view-section {
    display: none;
    /* Hidden by default */
    height: 100%;
    animation: fadeIn 0.3s ease;
}

.view-section.active {
    display: block;
    /* Flex or Grid inside specific views */
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Dashboard Grid (Executive) */
.exec-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: auto auto;
    gap: 20px;
    height: 100%;
}

.kpi-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.kpi-title {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 10px 0;
}

.kpi-sub {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.chart-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    grid-column: span 2;
}

.big-chart-card {
    grid-column: span 3;
    min-height: 300px;
}

.rank-card {
    grid-column: span 1;
    background-color: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    overflow: hidden;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    table-layout: fixed;
    /* Force fixed table layout */
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 8px 5px;
    /* Reduce padding */
    border-bottom: 1px solid #1e293b;
    font-size: 0.85rem;
    /* Slightly smaller font */
}

.data-table th {
    color: var(--text-secondary);
    font-weight: 500;
}

/* Rank Column */
.data-table th:nth-child(1),
.data-table td:nth-child(1) {
    width: 20%;
    text-align: left;
    padding-left: 5px;
}

/* Name Column */
.data-table th:nth-child(2),
.data-table td:nth-child(2) {
    width: 50%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Value Column */
.data-table th:nth-child(3),
.data-table td:nth-child(3) {
    width: 30%;
    text-align: right;
}

/* --- Device Table Specifics (5 Columns) --- */
/* 1. Status */
#device-table th:nth-child(1),
#device-table td:nth-child(1) {
    width: 12%;
    text-align: left;
    white-space: nowrap;
}

/* 2. Device Name */
#device-table th:nth-child(2),
#device-table td:nth-child(2) {
    width: 38%;
    text-align: left;
}

/* 3. Device Type */
#device-table th:nth-child(3),
#device-table td:nth-child(3) {
    width: 20%;
    text-align: center;
}

/* 4. Battery */
#device-table th:nth-child(4),
#device-table td:nth-child(4) {
    width: 18%;
    text-align: left;
}

/* 5. Last Active */
#device-table th:nth-child(5),
#device-table td:nth-child(5) {
    width: 12%;
    text-align: right;
    white-space: nowrap;
}

/* Last Active */

.rank-row td:first-child {
    font-weight: bold;
    color: var(--accent);
}

/* Status Dot */
.status-dot {
    height: 8px;
    width: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.dot-green {
    background-color: var(--success);
}

.dot-yellow {
    background-color: var(--warning);
}

.dot-red {
    background-color: var(--danger);
}

/* Full Map */
#map-view {
    height: 100%;
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

/* Utilities */
.text-green {
    color: var(--success);
}

.text-yellow {
    color: var(--warning);
}

.bg-green-500 {
    background-color: #22c55e;
}

.bg-yellow-500 {
    background-color: #eab308;
}

.bg-red-500 {
    background-color: #ef4444;
}

.text-red {
    color: var(--danger);
}

/* --- Mobile Responsive (Max Width 768px) --- */
@media (max-width: 768px) {
    body {
        flex-direction: column-reverse;
        /* Nav at bottom */
    }

    /* 1. Sidebar becomes Bottom Nav */
    .sidebar {
        width: 100%;
        height: 70px;
        /* Fixed height for bottom nav */
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border);
        padding: 0 10px;
        justify-content: space-between;
        align-items: center;
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 999;
    }

    .logo {
        display: none;
        /* Hide Logo in bottom nav to save space */
    }

    .nav-menu {
        flex-direction: row;
        width: 100%;
        justify-content: space-around;
        gap: 0;
    }

    .menu-item {
        flex-direction: column;
        gap: 4px;
        font-size: 0.7rem;
        padding: 8px;
        text-align: center;
        border-radius: 8px;
    }

    .menu-item span {
        font-size: 1.2rem;
        /* Make icons bigger */
    }

    /* 2. Main Content Adjustments */
    .main-content {
        padding: 15px;
        padding-bottom: 80px;
        /* Space for bottom nav */
        width: 100%;
    }

    .header {
        flex-direction: row;
        /* Keep row but maybe smaller */
        justify-content: space-between;
    }

    #page-title {
        font-size: 1.2rem;
    }

    /* 3. Grid to Single Column */
    .exec-grid {
        display: flex;
        /* Flex is easier for vertical stacking */
        flex-direction: column;
        gap: 15px;
    }

    .kpi-card,
    .chart-card,
    .big-chart-card,
    .rank-card {
        width: 100%;
    }

    /* Make charts fit screen width */
    .big-chart-card canvas,
    #historyChart {
        max-width: 100%;
    }

    /* 4. Table Adjustments */
    .data-table {
        font-size: 0.75rem;
    }

    .data-table th,
    .data-table td {
        padding: 6px 4px;
    }

    /* Device Table Scroll */
    .chart-card {
        overflow-x: auto;
        /* Allow horizontal scroll for wide tables */
    }

    #device-table {
        min-width: 500px;
        /* Ensure table doesn't squish too much */
    }

    /* 5. Map View */
    #map-full {
        height: calc(100vh - 140px) !important;
        /* Full height minus nav/header */
        min-height: unset;
    }
}