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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f0f0f;
    color: #fff;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    background: #1a1a1a;
    padding: 20px;
    border-bottom: 2px solid #333;
}

h1 {
    font-size: 24px;
    margin-bottom: 15px;
}

.stats {
    display: flex;
    gap: 20px;
}

.stat {
    background: #252525;
    padding: 10px 20px;
    border-radius: 8px;
    display: flex;
    gap: 10px;
    align-items: center;
}

.stat .label {
    color: #888;
    font-size: 14px;
}

.stat .value {
    color: #fff;
    font-size: 18px;
    font-weight: bold;
}

#map {
    flex: 1;
    background: #000;
    position: relative;
}

.legend {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(26, 26, 26, 0.95);
    border: 2px solid #333;
    border-radius: 8px;
    padding: 12px;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5);
}

.legend-title {
    color: #fff;
    font-size: 13px;
    font-weight: bold;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-marker {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #fff;
}

.legend-marker.new {
    background: #ffaa00;
    border-color: #ffff00;
    box-shadow: 0 0 8px rgba(255, 170, 0, 0.6);
}

.legend-marker.old {
    background: #ff4444;
    border-color: #fff;
}

.legend-text {
    color: #ccc;
    font-size: 12px;
}

.controls {
    background: #1a1a1a;
    padding: 15px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    border-top: 2px solid #333;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.filter-group label {
    font-size: 12px;
    color: #888;
    font-weight: 500;
}

.filter-group input[type="range"] {
    width: 100%;
    height: 4px;
    background: #333;
    border-radius: 2px;
    outline: none;
}

.filter-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: #4a90e2;
    cursor: pointer;
    border-radius: 50%;
}

.filter-group input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #4a90e2;
    cursor: pointer;
    border-radius: 50%;
    border: none;
}

.filter-group span {
    font-size: 14px;
    color: #fff;
    font-weight: bold;
}

.layer-controls {
    background: #1a1a1a;
    padding: 15px;
    display: flex;
    gap: 10px;
    border-top: 1px solid #333;
}

.btn {
    background: #2a2a2a;
    border: 1px solid #444;
    color: #fff;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.btn:hover {
    background: #3a3a3a;
    border-color: #555;
}

.btn.active {
    background: #4a90e2;
    border-color: #4a90e2;
}

.status {
    background: #0a0a0a;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #666;
}

#connection-status.connected {
    color: #4caf50;
}

#connection-status.disconnected {
    color: #f44336;
}

/* Leaflet marker customization */
.leaflet-container {
    background: #0a0a0a;
}

.leaflet-tile {
    filter: grayscale(100%) invert(100%) brightness(0.8);
}

/* Marker Cluster Styling */
.marker-cluster {
    background-clip: padding-box;
}

.marker-cluster div {
    text-align: center;
    font-size: 11px;
    line-height: 1.2;
}

.marker-cluster-fire div,
.marker-cluster-flood div,
.marker-cluster-earthquake div,
.marker-cluster-pollution div {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
}

/* Mobile filter toggle - floating gear button */
.filter-toggle {
    display: none;
}

/* Mobile controls panel */
.mobile-controls-panel {
    display: none;
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    /* Hide header on mobile for more map space */
    header {
        display: none;
    }

    /* Floating gear button */
    .filter-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        bottom: 80px;
        right: 15px;
        width: 56px;
        height: 56px;
        background: #4a90e2;
        border: none;
        color: #fff;
        border-radius: 50%;
        cursor: pointer;
        font-size: 24px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
        z-index: 1001;
        transition: all 0.3s;
    }

    .filter-toggle:active {
        transform: scale(0.95);
        background: #3a7bc8;
    }

    /* Mobile controls panel - slides up from bottom */
    .mobile-controls-panel {
        display: block;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #1a1a1a;
        border-top: 2px solid #333;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease-out;
        z-index: 1002;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.5);
    }

    .mobile-controls-panel.show {
        max-height: 80vh;
        overflow-y: auto;
    }

    /* Panel header */
    .mobile-controls-panel .panel-header {
        position: sticky;
        top: 0;
        background: #1a1a1a;
        padding: 15px;
        border-bottom: 1px solid #333;
        display: flex;
        justify-content: space-between;
        align-items: center;
        z-index: 1;
    }

    .mobile-controls-panel .panel-title {
        font-size: 18px;
        font-weight: bold;
        color: #fff;
    }

    .mobile-controls-panel .close-btn {
        background: #2a2a2a;
        border: 1px solid #444;
        color: #fff;
        padding: 8px 16px;
        border-radius: 6px;
        cursor: pointer;
        font-size: 14px;
    }

    /* Stats in mobile panel */
    .mobile-controls-panel .stats {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 15px;
        border-bottom: 1px solid #333;
    }

    .mobile-controls-panel .stat {
        padding: 12px;
        background: #252525;
        border-radius: 8px;
    }

    .mobile-controls-panel .stat .label {
        font-size: 12px;
        color: #888;
    }

    .mobile-controls-panel .stat .value {
        font-size: 18px;
        font-weight: bold;
        color: #fff;
    }

    /* Hide desktop controls on mobile */
    .controls {
        display: none;
    }

    /* Filters in mobile panel */
    .mobile-controls-panel .controls {
        display: grid;
        grid-template-columns: 1fr;
        gap: 15px;
        padding: 15px;
        border-bottom: 1px solid #333;
    }

    .mobile-controls-panel .layer-controls {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 15px;
    }

    .mobile-controls-panel .btn {
        padding: 12px;
        font-size: 14px;
        width: 100%;
    }

    .layer-controls {
        display: none;
    }

    /* Compact legend for mobile */
    .legend {
        bottom: 150px;
        right: 15px;
        left: auto;
        padding: 10px;
        font-size: 11px;
    }

    .legend-title {
        font-size: 11px;
        margin-bottom: 6px;
    }

    .legend-text {
        font-size: 10px;
    }

    .legend-marker {
        width: 10px;
        height: 10px;
    }

    /* Status bar at bottom */
    .status {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 8px 15px;
        font-size: 11px;
        display: flex;
        justify-content: space-between;
        background: #0a0a0a;
        border-top: 1px solid #333;
        z-index: 1000;
    }

    /* Make map touch-friendly */
    .leaflet-control-zoom {
        transform: scale(1.2);
    }

    .leaflet-popup-content {
        font-size: 12px;
    }

    /* Map should fill entire screen on mobile */
    #map {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: 100vh;
    }
}

/* Tablet landscape and small desktops */
@media (min-width: 769px) and (max-width: 1024px) {
    .controls {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats {
        flex-wrap: wrap;
    }

    .stat {
        flex: 1 1 calc(25% - 15px);
    }
}

/* Very small phones */
@media (max-width: 480px) {
    h1 {
        font-size: 16px;
    }

    .stat {
        flex: 1 1 100%;
    }

    .btn {
        flex: 1 1 100%;
    }

    .filter-group label {
        font-size: 11px;
    }

    .legend {
        bottom: 5px;
        right: 5px;
        left: 5px;
        padding: 6px;
    }

    .legend-items {
        flex-direction: row;
        justify-content: space-around;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        padding: 8px 15px;
    }

    h1 {
        font-size: 14px;
        margin-bottom: 5px;
    }

    .stats {
        gap: 8px;
    }

    .stat {
        padding: 5px 10px;
    }

    .controls {
        display: none; /* Hide filters in landscape */
    }

    .layer-controls {
        padding: 8px;
    }

    .btn {
        padding: 6px 10px;
        font-size: 12px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px;
        touch-action: manipulation;
    }

    input[type="range"] {
        min-height: 44px;
        touch-action: manipulation;
    }

    .leaflet-control-zoom a {
        width: 36px;
        height: 36px;
        line-height: 36px;
    }
}
