/* Variables */
:root {
    --primary-color: #3a86ff;
    --secondary-color: #8338ec;
    --success-color: #06d6a0;
    --warning-color: #ffbe0b;
    --danger-color: #ef476f;
    --light-bg: #f8f9fa;
    --dark-bg: #212529;
    --card-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    --border-radius: 8px;
    --metrics-width: 280px;
    --main-chart-height: 300px; /* Reduced from 360px */
    --secondary-chart-height: 180px; /* Increased from 120px */
}

/* Base styles */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--light-bg);
}

.dashboard-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

/* Navbar */
.navbar {
    padding: 0.5rem 1rem;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
    flex-shrink: 0; /* Prevent navbar from shrinking */
}

.sensor-select-container {
    width: 180px;
}

/* Dashboard content */
.dashboard-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 10px;
    gap: 10px;
    min-height: 0; /* Important for flex children */
}

/* Metrics panel */
.metrics-panel {
    width: var(--metrics-width);
    background-color: white;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    overflow-y: auto;
    flex-shrink: 0; /* Prevent shrinking */
}

.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 15px;
}

.metric-box {
    background-color: var(--light-bg);
    border-radius: var(--border-radius);
    padding: 12px;
    position: relative;
    text-align: center;
}

/* Metric box variations */
.metric-box.temp-indoor {
    background-color: rgba(54, 162, 235, 0.1);
    border-left: 3px solid rgba(54, 162, 235, 0.7);
}

.metric-box.temp-outdoor {
    background-color: rgba(255, 159, 64, 0.1);
    border-left: 3px solid rgba(255, 159, 64, 0.7);
}

.metric-box.humidity {
    background-color: rgba(75, 192, 192, 0.1);
    border-left: 3px solid rgba(75, 192, 192, 0.7);
}

.metric-box.signal {
    background-color: rgba(153, 102, 255, 0.1);
    border-left: 3px solid rgba(153, 102, 255, 0.7);
}

.metric-box.battery {
    background-color: rgba(255, 99, 132, 0.1);
    border-left: 3px solid rgba(255, 99, 132, 0.7);
}

.metric-box.conductivity {
    background-color: rgba(54, 162, 235, 0.1);
    border-left: 3px solid rgba(54, 162, 235, 0.7);
}

.metric-box.packet-loss {
    background-color: rgba(255, 159, 64, 0.1);
    border-left: 3px solid rgba(255, 159, 64, 0.7);
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0;
}

.metric-label {
    font-size: 0.75rem;
    color: #6c757d;
    margin-bottom: 0;
}

.metric-icon {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 0.8rem;
    color: rgba(0, 0, 0, 0.3);
}

/* Status indicators */
.status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 5px;
}

.status-good { background-color: var(--success-color); }
.status-warning { background-color: var(--warning-color); }
.status-alert { background-color: var(--danger-color); }
.status-unknown { background-color: #9e9e9e; }

/* Sensor info styling */
.sensor-info {
    padding: 10px 15px;
    border-bottom: 1px solid #e9ecef;
}

.sensor-model {
    font-weight: 600;
    font-size: 0.9rem;
    color: #495057;
    margin-bottom: 5px;
}

.last-updated {
    font-size: 0.8rem;
    color: #6c757d;
}

/* Charts panel */
.charts-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    min-height: 0; /* Important for proper flex behavior */
}

.charts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: white;
    padding: 10px 15px;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    flex-shrink: 0; /* Prevent header from shrinking */
}

.main-chart {
    background-color: white;
    padding: 15px;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    height: var(--main-chart-height);
    flex: 2;  /* Reduced from 3 */
    min-height: 250px; /* Ensure minimum height */
}

.secondary-charts {
    display: flex;
    gap: 10px;
    flex: 2;  /* Increased from 1 */
    min-height: var(--secondary-chart-height);
}

.chart-container {
    background-color: white;
    padding: 10px 15px;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    flex: 1 1 0; /* Force equal width distribution */
    min-width: 0; /* Allow shrinking */
    width: 0; /* Reset width to let flex handle it */
    min-height: 150px; /* Ensure minimum height */
}

.chart-title {
    margin-bottom: 5px;
    font-size: 0.9rem;
    color: #495057;
    font-weight: 600;
}

/* Ensure charts resize properly within containers */
.chart-container canvas {
    max-width: 100% !important;
    height: auto !important;
}

/* Hide data points (dots) on secondary charts */
.chart-container canvas {
    --chart-point-radius: 0;
}

/* Custom chart styling - hide points on line charts */
.secondary-charts .chart-container {
    --point-radius: 0;
}

/* Time range buttons */
.btn-group.time-range {
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    overflow: hidden;
}

.time-range-btn {
    border-radius: 0 !important;
    border: none !important;
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    color: #6c757d;
}

.time-range-btn.active {
    background-color: var(--primary-color) !important;
    color: white !important;
}

/* Animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spin {
    animation: spin 1s linear;
}

/* FIXED Media Queries */
@media (max-width: 992px) {
    .dashboard-content {
        flex-direction: column;
        overflow-y: auto; /* Allow vertical scrolling */
        height: auto; /* Remove fixed height constraint */
    }
    
    .metrics-panel {
        width: 100%;
        max-height: none; /* Remove height restriction */
        min-height: auto;
        order: 1; /* Show metrics first */
        flex-shrink: 0;
    }
    
    .charts-panel {
        width: 100%;
        order: 2; /* Show charts second */
        flex: none; /* Remove flex grow */
        min-height: 600px; /* Ensure enough space for charts */
    }
    
    .metrics-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .metric-box.battery {
        grid-column: auto;
    }
    
    .main-chart {
        height: 260px;
        min-height: 260px;
    }
    
    .secondary-charts {
        flex-direction: row; /* Keep horizontal on tablets */
        min-height: 200px;
    }
    
    .chart-container {
        min-height: 180px;
    }
}

@media (max-width: 768px) {
    .dashboard-content {
        padding: 8px;
        gap: 8px;
    }
    
    .metrics-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 12px;
    }
    
    .main-chart {
        height: 240px;
        min-height: 240px;
        padding: 10px;
    }
    
    .secondary-charts {
        flex-direction: column; /* Stack vertically on mobile */
        gap: 8px;
    }
    
    .chart-container {
        flex: none; /* Remove flex for mobile */
        width: 100%; /* Full width for mobile */
        min-height: 160px;
        padding: 8px 12px;
    }
    
    .charts-header {
        padding: 8px 12px;
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .charts-header h5 {
        text-align: center;
        margin-bottom: 0;
    }
    
    .btn-group.time-range {
        align-self: center;
    }
}

@media (max-width: 576px) {
    .dashboard-content {
        padding: 5px;
        gap: 5px;
    }
    
    .metrics-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        padding: 10px;
    }
    
    .metric-box.battery {
        grid-column: span 2;
    }
    
    .metric-value {
        font-size: 1.3rem;
    }
    
    .metric-label {
        font-size: 0.7rem;
    }
    
    .main-chart {
        height: 220px;
        min-height: 220px;
        padding: 8px;
    }
    
    .chart-container {
        min-height: 140px;
        padding: 6px 10px;
    }
    
    .chart-title {
        font-size: 0.8rem;
    }
    
    .sensor-select-container {
        width: 120px;
    }
    
    .navbar {
        padding: 0.4rem 0.8rem;
    }
    
    .time-range-btn {
        padding: 0.2rem 0.6rem;
        font-size: 0.75rem;
    }
}
