.map-container {
    background: var(--card-bg);
    border-radius: 15px;
    box-shadow: 0 10px 30px var(--shadow);
    overflow: hidden;
    height: calc(100vh - 160px);
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

.map-legend {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: var(--card-bg);
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 5px 15px var(--shadow);
    z-index: 1000;
    min-width: 220px;
    max-height: 45vh;
    overflow: auto;
}

.legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.legend-title {
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--accent-color);
}

.legend-header .legend-title {
    margin-bottom: 0;
}

.legend-toggle {
    border: 1px solid var(--border-color);
    background: var(--stat-bg);
    color: var(--text-primary);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.75em;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.map-legend.collapsed .legend-body {
    display: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 5px 0;
    font-size: 0.85em;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid white;
}

.legend-line {
    width: 30px;
    height: 4px;
    border-radius: 2px;
}

.legend-heat {
    width: 36px;
    height: 8px;
    border-radius: 999px;
    background: linear-gradient(90deg, #e5f7ec 0%, #34d399 50%, #15803d 100%);
    border: 1px solid var(--border-color);
}

.stats-overlay {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: var(--card-bg);
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 5px 15px var(--shadow);
    z-index: 1000;
}

.stat-item {
    margin: 5px 0;
    font-size: 0.9em;
}

.stat-value {
    font-weight: bold;
    color: var(--accent-color);
}

.deselect-button {
    margin-top: 10px;
    width: 100%;
    padding: 8px 12px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.2s ease;
}

.deselect-button:hover {
    background: #5a6fd8;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.reset-button {
    margin-top: 8px;
    width: 100%;
    padding: 8px 12px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.2s ease;
}

.reset-button:hover {
    background: #5a6fd8;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.map-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--card-bg);
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 5px 15px var(--shadow);
    z-index: 1000;
}

.control-title {
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--accent-color);
}

.control-item {
    margin: 8px 0;
}

.control-item label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9em;
}

.control-item input[type="checkbox"] {
    cursor: pointer;
}

.control-item select {
    width: 100%;
    padding: 5px;
    border-radius: 5px;
    background: var(--stat-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    font-family: inherit;
}

.control-item select:focus {
    outline: 2px solid var(--accent-color);
}

/* Leaflet popup styling */
.leaflet-popup-content-wrapper {
    background: var(--card-bg);
    color: var(--text-primary);
}

.leaflet-popup-tip {
    background: var(--card-bg);
}

.node-popup {
    min-width: 200px;
}

.node-popup h3 {
    color: var(--accent-color);
    margin-bottom: 10px;
}

.node-popup-item {
    margin: 5px 0;
    font-size: 0.9em;
}

.node-label {
    background: rgba(15, 23, 42, 0.8);
    color: #f8fafc;
    border-radius: 999px;
    padding: 2px 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 0.75em;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.25);
}

body.light-theme .node-label {
    background: rgba(255, 255, 255, 0.9);
    color: #0f172a;
    border: 1px solid rgba(0, 0, 0, 0.12);
}

/* Selected node marker styling */
.custom-node-marker.selected > div {
    transform: scale(1.5);
    z-index: 1000 !important;
    animation: pulse-ring 1.5s ease-in-out infinite;
}

@keyframes pulse-ring {
    0% {
        box-shadow: 0 0 0 0px rgba(99, 102, 241, 0.7),
                    0 0 10px rgba(99, 102, 241, 0.5);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(99, 102, 241, 0),
                    0 0 20px rgba(99, 102, 241, 0.3);
    }
    100% {
        box-shadow: 0 0 0 0px rgba(99, 102, 241, 0),
                    0 0 10px rgba(99, 102, 241, 0.5);
    }
}

/* Selected coverage circle styling */
.coverage-circle.selected {
    fill-opacity: 0.12 !important;
    stroke-opacity: 0.9 !important;
    stroke-width: 3 !important;
}

/* Hover effect voor coverage circles */
.coverage-circle:hover {
    fill-opacity: 0.08 !important;
    stroke-opacity: 0.85 !important;
    stroke-width: 3 !important;
    cursor: pointer;
}

/* Selected circle hover */
.coverage-circle.selected:hover {
    fill-opacity: 0.15 !important;
    stroke-opacity: 1 !important;
    stroke-width: 4 !important;
}

/* Loading indicator */
.map-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--card-bg);
    padding: 20px 30px;
    border-radius: 10px;
    box-shadow: 0 5px 20px var(--shadow);
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 1em;
    color: var(--text-primary);
}

.map-loading.hidden {
    display: none;
}

.loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-weight: 500;
}

/* Refresh indicator (klein icoon in stats overlay) */
.refresh-indicator {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.refresh-indicator.active {
    opacity: 1;
}

/* Mobile-First Responsive Design */

/* Small mobile devices (portrait phones) */
@media (max-width: 480px) {
    .map-container {
        height: calc(100vh - 120px);
        border-radius: 10px;
    }

    /* Map Controls - Compact on mobile */
    .map-controls {
        top: 10px;
        right: 10px;
        padding: 10px;
        max-width: 160px;
        font-size: 0.85em;
    }

    .control-title {
        font-size: 0.9em;
        margin-bottom: 8px;
    }

    .control-item {
        margin: 6px 0;
    }

    .control-item label {
        font-size: 0.85em;
        gap: 6px;
    }

    .control-item select {
        font-size: 0.85em;
        padding: 4px;
    }

    /* Map Legend - Move to bottom center on mobile */
    .map-legend {
        bottom: 10px;
        right: 10px;
        left: 10px;
        padding: 10px;
        max-width: none;
    }

    .legend-title {
        font-size: 0.9em;
        margin-bottom: 8px;
    }

    .legend-item {
        font-size: 0.8em;
        gap: 8px;
        margin: 4px 0;
    }

    .legend-color {
        width: 16px;
        height: 16px;
    }

    .legend-line {
        width: 24px;
        height: 3px;
    }

    /* Stats Overlay - Compact on mobile */
    .stats-overlay {
        bottom: 10px;
        left: 10px;
        padding: 10px;
        max-width: calc(100% - 180px);
    }

    .stat-item {
        font-size: 0.8em;
        margin: 4px 0;
    }

    .deselect-button,
    .reset-button {
        padding: 8px 10px;
        font-size: 0.8em;
        margin-top: 8px;
        min-height: 44px;
    }

    /* Loading indicator */
    .map-loading {
        padding: 15px 20px;
        font-size: 0.9em;
        gap: 10px;
    }

    .loading-spinner {
        width: 24px;
        height: 24px;
        border-width: 2px;
    }

    /* Leaflet popup adjustments */
    .node-popup {
        min-width: 150px;
        font-size: 0.9em;
    }

    .node-popup h3 {
        font-size: 1em;
        margin-bottom: 8px;
    }

    .node-popup-item {
        font-size: 0.85em;
        margin: 4px 0;
    }

    /* Leaflet controls */
    .leaflet-control-zoom {
        margin-top: 10px !important;
        margin-right: 10px !important;
    }

    .leaflet-control-zoom a {
        width: 36px !important;
        height: 36px !important;
        line-height: 36px !important;
        font-size: 18px !important;
    }
}

/* Medium mobile devices (landscape phones, small tablets) */
@media (min-width: 481px) and (max-width: 768px) {
    .map-container {
        height: calc(100vh - 140px);
    }

    .map-controls {
        top: 12px;
        right: 12px;
        padding: 12px;
        max-width: 180px;
        font-size: 0.9em;
    }

    .control-title {
        font-size: 0.95em;
    }

    .control-item label {
        font-size: 0.88em;
    }

    .map-legend {
        bottom: 12px;
        right: 12px;
        padding: 12px;
    }

    .legend-item {
        font-size: 0.82em;
    }

    .legend-color {
        width: 18px;
        height: 18px;
    }

    .legend-line {
        width: 28px;
    }

    .stats-overlay {
        bottom: 12px;
        left: 12px;
        padding: 12px;
    }

    .stat-item {
        font-size: 0.85em;
    }

    .deselect-button {
        padding: 8px 12px;
        font-size: 0.85em;
    }

    .node-popup {
        min-width: 180px;
    }

    .leaflet-control-zoom a {
        width: 38px !important;
        height: 38px !important;
        line-height: 38px !important;
    }
}

/* Tablets */
@media (min-width: 769px) and (max-width: 1024px) {
    .map-container {
        height: calc(100vh - 150px);
    }

    .map-controls {
        top: 15px;
        right: 15px;
        padding: 14px;
    }

    .map-legend {
        bottom: 15px;
        right: 15px;
        padding: 14px;
    }

    .stats-overlay {
        bottom: 15px;
        left: 15px;
        padding: 14px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .deselect-button,
    .control-item input[type="checkbox"],
    .control-item select {
        min-width: 44px;
        min-height: 44px;
    }

    .control-item input[type="checkbox"] {
        width: 20px;
        height: 20px;
    }

    .deselect-button:active,
    .reset-button:active {
        transform: scale(0.95);
    }

    /* Disable hover effects on touch */
    .coverage-circle:hover {
        fill-opacity: 0.05 !important;
        stroke-opacity: 0.7 !important;
        stroke-width: 2 !important;
    }

    .deselect-button:hover,
    .reset-button:hover {
        transform: none;
    }

    /* Better touch targets for Leaflet controls */
    .leaflet-bar a {
        min-width: 44px !important;
        min-height: 44px !important;
    }
}

/* Landscape orientation specific adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .map-container {
        height: calc(100vh - 100px);
    }

    .map-controls {
        top: 8px;
        right: 8px;
        padding: 8px;
        font-size: 0.8em;
    }

    .map-legend {
        bottom: 8px;
        right: 8px;
        padding: 8px;
        font-size: 0.8em;
    }

    .stats-overlay {
        bottom: 8px;
        left: 8px;
        padding: 8px;
        font-size: 0.8em;
    }
}
