/* Map Container Styles */
.map-container {
    position: relative;
    width: 100%;
    height: calc(100vh - 100px);
    background: #f5f5f5;
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Control Panel */
.map-controls {
    position: absolute;
    top: 20px;
    left: 20px;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    max-width: 350px;
}

.map-controls h3 {
    margin: 0 0 15px 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.control-group {
    margin-bottom: 15px;
}

.control-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 14px;
    font-weight: 500;
    color: #555;
}

.control-group select,
.control-group input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.control-group button {
    width: 100%;
    padding: 10px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.3s;
}

.control-group button:hover {
    background: #0056b3;
}

/* Side Panel */
.side-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 320px;
    max-height: calc(100vh - 140px);
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.side-panel-header {
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.side-panel-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.side-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px 20px;
}

/* Top Emitters List */
.emitter-list,
.formation-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.emitter-item,
.formation-item {
    padding: 12px;
    margin-bottom: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid #007bff;
    cursor: pointer;
    transition: all 0.3s;
}

.emitter-item:hover,
.formation-item:hover {
    background: #e9ecef;
    transform: translateX(5px);
}

.emitter-item.high {
    border-left-color: #dc3545;
}

.emitter-item.medium {
    border-left-color: #ffc107;
}

.emitter-item.low {
    border-left-color: #28a745;
}

.emitter-name,
.formation-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
}

.emitter-value,
.formation-details {
    font-size: 14px;
    color: #666;
}

/* Search Box */
.search-container {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

.search-box {
    position: relative;
    width: 400px;
}

.search-box input {
    width: 100%;
    padding: 12px 40px 12px 15px;
    border: 1px solid #ddd;
    border-radius: 25px;
    font-size: 14px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    background: white;
}

.search-box button {
    position: absolute;
    right: 5px;
    top: 5px;
    padding: 7px 15px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 5px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    max-height: 300px;
    overflow-y: auto;
    display: none;
}

.search-results.show {
    display: block;
}

.search-result-item {
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}

.search-result-item:hover {
    background: #f8f9fa;
}

.search-result-item:last-child {
    border-bottom: none;
}

/* Popup Styles */
.leaflet-popup-content {
    margin: 0;
    min-width: 200px;
}

.popup-header {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 10px;
    color: #333;
}

.popup-details {
    font-size: 14px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid #f0f0f0;
}

.popup-row:last-child {
    border-bottom: none;
}

.popup-label {
    color: #666;
    font-weight: 500;
}

.popup-value {
    color: #333;
    font-weight: 600;
}

/* Legend */
.map-legend {
    position: absolute;
    bottom: 30px;
    right: 30px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
}

.map-legend h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: 600;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-size: 13px;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    margin-right: 8px;
}

/* Statistics Panel */
.stats-panel {
    position: absolute;
    bottom: 30px;
    left: 30px;
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    min-width: 250px;
}

.stat-item {
    margin-bottom: 10px;
}

.stat-item:last-child {
    margin-bottom: 0;
}

.stat-label {
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: #333;
}

/* Loading Spinner */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Heat Map Colors */
.heat-low { background: #ffffcc; }
.heat-medium { background: #ffeda0; }
.heat-high { background: #feb24c; }
.heat-very-high { background: #f03b20; }
.heat-extreme { background: #bd0026; }

/* Responsive Design */
@media (max-width: 768px) {
    .map-controls,
    .side-panel {
        width: calc(100% - 40px);
        max-width: 100%;
    }
    
    .search-box {
        width: calc(100% - 40px);
    }
    
    .map-legend,
    .stats-panel {
        font-size: 12px;
    }
}

/* Toggle Button */
.toggle-panel-btn {
    position: absolute;
    top: 50%;
    right: -30px;
    transform: translateY(-50%);
    background: white;
    border: none;
    padding: 10px;
    border-radius: 0 4px 4px 0;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    cursor: pointer;
}

.side-panel.collapsed {
    right: -340px;
}

/* Chart Container */
.chart-container {
    margin-top: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
}

.chart-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: #333;
}

/* Enhanced Air Quality Legend */
.air-quality-legend {
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

.air-quality-legend h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: 600;
}

.air-quality-legend .legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    font-size: 12px;
}

.air-quality-legend .legend-color {
    width: 25px;
    height: 15px;
    margin-right: 8px;
    border-radius: 3px;
}

/* Pulsating marker animation */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(255, 0, 0, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 0, 0, 0);
    }
}

.pulsating-marker {
    animation: pulse 2s infinite;
}