/* Map-Specific Styles */

.map-container {
    width: 100%;
    height: calc(100vh - var(--header-height) - var(--bottom-nav-height) - 60px);
    min-height: 400px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    position: relative;
    z-index: 1;
}

.map-controls {
    display: flex;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    align-items: center;
    flex-wrap: wrap;
}

/* Leaflet map overrides */
.leaflet-container {
    background: var(--bg-tertiary);
    font-family: inherit;
}

.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow-md) !important;
}

.leaflet-control-zoom a {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 1.25rem !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-secondary) !important;
}

/* Cluster styling based on risk level */
.marker-cluster {
    background-clip: padding-box;
    border-radius: 50%;
}

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
    background: rgba(99, 102, 241, 0.2);
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
    background: var(--primary);
    color: white;
    font-weight: 700;
    border-radius: 50%;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Risk-based cluster colors */
.marker-cluster.cluster-low {
    background: rgba(16, 185, 129, 0.2);
}

.marker-cluster.cluster-low div {
    background: var(--success);
}

.marker-cluster.cluster-medium {
    background: rgba(245, 158, 11, 0.2);
}

.marker-cluster.cluster-medium div {
    background: var(--warning);
}

.marker-cluster.cluster-high {
    background: rgba(239, 68, 68, 0.2);
}

.marker-cluster.cluster-high div {
    background: var(--danger);
}

/* Custom marker icons */
.vehicle-marker {
    background: var(--success);
    border: 3px solid white;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 16px;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: all var(--transition-speed);
}

.vehicle-marker:hover {
    transform: scale(1.15);
}

.vehicle-marker.risk-low {
    background: var(--success);
}

.vehicle-marker.risk-medium {
    background: var(--warning);
}

.vehicle-marker.risk-high,
.vehicle-marker.risk-critical {
    background: var(--danger);
}

.vehicle-marker.offline {
    background: var(--text-tertiary);
    opacity: 0.6;
}

/* Custom popup styling */
.leaflet-popup-content-wrapper {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 0;
}

.leaflet-popup-content {
    margin: 0;
    min-width: 200px;
}

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

/* Map overlay for bottom sheet */
.map-container::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100px;
    background: linear-gradient(to top, var(--bg-secondary), transparent);
    pointer-events: none;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.3s;
}

.map-container.sheet-open::after {
    opacity: 1;
}

/* Map loading state */
.map-container.loading {
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.map-container.loading::before {
    content: '';
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Map attribution styling */
.leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.8) !important;
    color: var(--text-primary) !important;
    font-size: 0.625rem !important;
    padding: 2px 6px !important;
    backdrop-filter: blur(4px);
}

@media (prefers-color-scheme: dark) {
    .leaflet-control-attribution {
        background: rgba(26, 26, 46, 0.8) !important;
    }
}

/* Map layer control */
.leaflet-control-layers {
    background: var(--bg-primary) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-md) !important;
}

.leaflet-control-layers-toggle {
    background-image: none !important;
    width: 36px !important;
    height: 36px !important;
}

/* Mobile optimizations for map */
@media (max-width: 640px) {
    .map-container {
        height: calc(100vh - var(--header-height) - var(--bottom-nav-height) - 50px);
        min-height: 300px;
        border-radius: var(--radius-md);
    }
    
    .vehicle-marker {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    
    .leaflet-control-zoom a {
        width: 32px !important;
        height: 32px !important;
        line-height: 32px !important;
    }
    
    .marker-cluster-small,
    .marker-cluster-medium {
        width: 36px !important;
        height: 36px !important;
    }
    
    .marker-cluster-large {
        width: 44px !important;
        height: 44px !important;
    }
    
    .leaflet-popup-content-wrapper {
        max-width: calc(100vw - 40px);
    }
}

/* Tablet optimizations */
@media (min-width: 768px) {
    .map-container {
        height: calc(100vh - var(--header-height) - var(--bottom-nav-height) - 80px);
    }
    
    .map-controls {
        gap: var(--spacing-md);
    }
}

/* Full screen map on landscape mobile */
@media (orientation: landscape) and (max-height: 500px) {
    .map-container {
        height: calc(100vh - var(--header-height) - var(--bottom-nav-height) - 30px);
        min-height: 250px;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .vehicle-marker {
        border-width: 4px;
    }
    
    .leaflet-control-zoom a {
        border-width: 2px !important;
    }
}

/* Map touch enhancements */
.leaflet-container {
    -webkit-tap-highlight-color: transparent;
}

.leaflet-interactive {
    cursor: pointer;
    touch-action: manipulation;
}

/* Disable leaflet drag on certain elements */
.leaflet-control-container {
    pointer-events: none;
}

.leaflet-control {
    pointer-events: auto;
}

/* Vehicle marker animation */
.vehicle-marker.moving {
    animation: markerPulse 2s ease-in-out infinite;
}

@keyframes markerPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(99, 102, 241, 0);
    }
}

/* Dark mode map adjustments */
@media (prefers-color-scheme: dark) {
    .leaflet-container {
        background: #0f3460;
    }
    
    .vehicle-marker {
        border-color: #1a1a2e;
    }
    
    .leaflet-control-zoom a {
        background: #16213e !important;
        color: #f9fafb !important;
        border-color: #374151 !important;
    }
}

/* Realtime control button positioning */
.map-controls .btn {
    z-index: 10;
}

/* Layer selector in controls */
#map-layer {
    min-width: 120px;
}

/* Bottom sheet overlays map when open */
#map-view .bottom-sheet {
    z-index: 1000;
}

/* Ensure map controls are touch-friendly */
.map-controls button,
.map-controls select {
    min-height: 44px;
}

/* Optimize map rendering */
.leaflet-pane {
    will-change: transform;
}

.leaflet-tile-container {
    will-change: transform;
}
