/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow: hidden;
}

/* Main app container with responsive height */
.app-container {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
}

/* Detect iframe environment and adjust height */
@media screen and (max-height: 500px) {
    .app-container {
        height: 450px;
    }
}

/* Control panel styling */
.control-panel {
    padding: 8px 12px;
    background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.control-group {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.control-select, .control-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    white-space: nowrap;
}

.control-select:hover, .control-btn:hover {
    background: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.control-select:focus {
    outline: 2px solid #4facfe;
    outline-offset: 2px;
}

/* Pollutant toggles */
.pollutant-toggles {
    display: flex;
    gap: 12px;
    align-items: center;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 4px;
    color: white;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #00f2fe;
}

/* Main content layout */
.main-content {
    flex: 1;
    display: flex;
    gap: 12px;
    padding: 12px;
    overflow: hidden;
}

/* Map section */
.map-section {
    flex: 0 0 300px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.singapore-map {
    flex: 1;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.map-svg {
    width: 100%;
    max-width: 280px;
    height: auto;
}

/* Region styling with color coding based on PSI levels */
.region {
    fill: #4CAF50;
    stroke: #2196F3;
    stroke-width: 2;
    cursor: pointer;
    transition: all 0.3s ease;
}

.region:hover {
    stroke-width: 3;
    filter: brightness(1.1);
    transform: scale(1.02);
    transform-origin: center;
}

.region.selected {
    stroke: #FF5722;
    stroke-width: 4;
    filter: brightness(1.2);
}

/* PSI level color classes */
.region.good { fill: #4CAF50; }
.region.moderate { fill: #FFC107; }
.region.unhealthy { fill: #FF9800; }
.region.very-unhealthy { fill: #F44336; }
.region.hazardous { fill: #9C27B0; }

.region-label {
    fill: white;
    font-size: 14px;
    font-weight: bold;
    text-anchor: middle;
    pointer-events: none;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

/* PSI Legend */
.psi-legend {
    background: white;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.legend-title {
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 8px;
    color: #333;
}

.legend-item {
    padding: 4px 8px;
    margin: 2px 0;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    color: white;
    text-shadow: 1px 1px 1px rgba(0,0,0,0.3);
}

.legend-item.good { background: #4CAF50; }
.legend-item.moderate { background: #FFC107; color: #333; text-shadow: none; }
.legend-item.unhealthy { background: #FF9800; }
.legend-item.hazardous { background: #F44336; }

/* Chart section */
.chart-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chart-container {
    flex: 1;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#psiChart {
    max-width: 100%;
    max-height: 100%;
}

/* Time slider */
.time-slider-container {
    background: white;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.slider-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: #333;
    margin-bottom: 8px;
}

.time-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.time-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #4facfe;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.time-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #4facfe;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 11px;
    color: #666;
}

/* Region info panel */
.region-info {
    position: absolute;
    top: 60px;
    right: 20px;
    width: 300px;
    max-height: 70%;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    overflow: hidden;
    z-index: 1000;
    transform: translateX(320px);
    transition: transform 0.3s ease;
}

.region-info:not(.hidden) {
    transform: translateX(0);
}

.info-header {
    background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.info-header h3 {
    font-size: 16px;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease;
}

.close-btn:hover {
    background: rgba(255,255,255,0.2);
}

.info-content {
    padding: 16px;
    max-height: 300px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.5;
}

/* Event popup */
.event-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    width: 90%;
    max-width: 400px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 12px 36px rgba(0,0,0,0.3);
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s ease;
}

.event-popup:not(.hidden) {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.popup-content {
    padding: 20px;
    position: relative;
}

.popup-content .close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    color: #666;
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: rgba(0,0,0,0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    pointer-events: none;
    z-index: 3000;
    max-width: 200px;
    word-wrap: break-word;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.tooltip:not(.hidden) {
    opacity: 1;
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Mobile responsive design */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
        gap: 8px;
        padding: 8px;
    }
    
    .map-section {
        flex: 0 0 200px;
    }
    
    .control-panel {
        padding: 6px 8px;
    }
    
    .control-select, .control-btn {
        font-size: 11px;
        padding: 4px 8px;
    }
    
    .region-info {
        width: calc(100% - 16px);
        right: 8px;
        left: 8px;
        top: 50px;
    }
    
    .pollutant-toggles {
        gap: 8px;
    }
    
    .toggle-label {
        font-size: 11px;
    }
}

/* Touch-friendly sizing for mobile */
@media (hover: none) and (pointer: coarse) {
    .control-select, .control-btn {
        min-height: 44px;
        padding: 8px 12px;
    }
    
    .region {
        stroke-width: 3;
    }
    
    .toggle-label input[type="checkbox"] {
        width: 20px;
        height: 20px;
    }
}