/*
 * Leaflet CSS Overrides for Accessibility
 * This file overrides default Leaflet styles to fix accessibility issues
 * with special focus on mobile device optimizations
 */

/* 1. Fix contrast for all text */
.leaflet-container {
    color: #333 !important;
    background: #f8f9fa !important;
}

/* 2. Fix focus styles */
.leaflet-container:focus,
.leaflet-container:focus-visible,
.leaflet-container:focus-within {
    outline: 3px solid #4d90fe !important;
    outline-offset: 2px;
}

/* 3. Fix zoom controls */
.leaflet-bar {
    box-shadow: 0 1px 5px rgba(0,0,0,0.4) !important;
    border-radius: 4px !important;
}

.leaflet-bar a,
.leaflet-bar a:hover {
    background-color: #fff !important;
    color: #333 !important;
    border-bottom: 1px solid #ccc !important;
    width: 30px !important;
    height: 30px !important;
    line-height: 30px !important;
    font-size: 22px !important;
    font-weight: bold !important;
}

.leaflet-bar a:hover {
    background-color: #f4f4f4 !important;
}

.leaflet-bar a:first-child {
    border-top-left-radius: 4px !important;
    border-top-right-radius: 4px !important;
}

.leaflet-bar a:last-child {
    border-bottom-left-radius: 4px !important;
    border-bottom-right-radius: 4px !important;
    border-bottom: none !important;
}

/* 4. Fix popups */
.leaflet-popup-content-wrapper {
    background: #fff !important;
    color: #333 !important;
    border-radius: 4px !important;
    box-shadow: 0 3px 14px rgba(0,0,0,0.4) !important;
    padding: 1px !important;
}

.leaflet-popup-content {
    margin: 13px 19px !important;
    line-height: 1.4 !important;
}

.leaflet-popup-content p {
    margin: 18px 0 !important;
}

.leaflet-popup-tip-container {
    width: 40px !important;
    height: 20px !important;
    position: absolute !important;
    left: 50% !important;
    margin-left: -20px !important;
    overflow: hidden !important;
    pointer-events: none !important;
}

.leaflet-popup-tip {
    width: 17px !important;
    height: 17px !important;
    padding: 1px !important;
    margin: -10px auto 0 !important;
    -webkit-transform: rotate(45deg) !important;
       -moz-transform: rotate(45deg) !important;
        -ms-transform: rotate(45deg) !important;
         -o-transform: rotate(45deg) !important;
            transform: rotate(45deg) !important;
    background: #fff !important;
    box-shadow: 0 3px 14px rgba(0,0,0,0.4) !important;
}

/* 5. Fix close button */
.leaflet-popup-close-button {
    background: #fff !important;
    color: #333 !important;
    font-size: 22px !important;
    font-weight: bold !important;
    line-height: 20px !important;
    text-align: center !important;
    width: 24px !important;
    height: 24px !important;
    border-radius: 4px !important;
    padding: 0 !important;
    margin: 5px 5px 0 0 !important;
    text-decoration: none !important;
}

.leaflet-popup-close-button:hover {
    background: #f4f4f4 !important;
    color: #000 !important;
}

/* 6. Fix attribution */
.leaflet-container .leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.9) !important;
    color: #333 !important;
    padding: 2px 5px !important;
    font-size: 11px !important;
}

.leaflet-container .leaflet-control-attribution a {
    color: #0078a8 !important;
    text-decoration: none !important;
}

.leaflet-container .leaflet-control-attribution a:hover {
    text-decoration: underline !important;
}

/* 7. Enhanced touch controls for mobile */
.leaflet-touch .leaflet-bar {
    border: 2px solid rgba(0, 0, 0, 0.2) !important;
    background-clip: padding-box !important;
}

.leaflet-touch .leaflet-bar a {
    width: 40px !important;
    height: 40px !important;
    line-height: 40px !important;
    font-size: 24px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    -webkit-tap-highlight-color: transparent !important;
}

.leaflet-touch .leaflet-bar a:active {
    background-color: #f4f4f4 !important;
}

/* Prevent text selection on touch devices */
.leaflet-container {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

/* Improve touch targets */
.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
    min-width: 40px !important;
    min-height: 40px !important;
}

/* 8. Fix for high contrast mode */
@media (forced-colors: active) {
    .leaflet-bar a,
    .leaflet-bar a:hover {
        background-color: white !important;
        color: black !important;
    }
    
    .leaflet-popup-content-wrapper {
        border: 1px solid black !important;
    }
}

/* 9. Ensure proper contrast for all text */
.leaflet-control-scale-line {
    color: #333 !important;
    background: rgba(255, 255, 255, 0.9) !important;
    border: 2px solid #777 !important;
    border-top: none !important;
    line-height: 1.1 !important;
    padding: 2px 5px 1px !important;
    font-size: 11px !important;
    white-space: nowrap !important;
    overflow: hidden;
    -moz-box-sizing: border-box !important;
         box-sizing: border-box !important;
}

.leaflet-control-scale-line:not(:first-child) {
    border-top: 2px solid #777 !important;
    border-bottom: none !important;
    margin-top: -2px !important;
}

.leaflet-control-scale-line:not(:first-child):not(:last-child) {
    border-bottom: none !important;
}

/* 10. Mobile-specific optimizations */
@media (max-width: 768px) {
    /* Make map controls more touch-friendly */
    .leaflet-control-container .leaflet-top.leaflet-right {
        margin-top: 60px; /* Make room for mobile header */
    }
    
    /* Increase hit area for touch devices */
    .leaflet-popup-close-button {
        width: 36px !important;
        height: 36px !important;
        font-size: 28px !important;
        line-height: 36px !important;
    }
    
    /* Make attribution more compact on mobile */
    .leaflet-control-attribution {
        max-width: 200px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 10px !important;
        padding: 2px 5px !important;
    }
    
    /* Ensure map takes full width on mobile */
    .leaflet-container {
        width: 100% !important;
    }
}

/* 11. Fix for print */
@media print {
    .leaflet-control-container .leaflet-control {
        display: none !important;
    }
}

/* Fix for high contrast mode */
@media (forced-colors: active) {
    .leaflet-bar a,
    .leaflet-bar a:hover {
        forced-color-adjust: none;
        background-color: white !important;
        color: black !important;
    }
    
    .leaflet-popup-content {
        color: black !important;
    }
}

/* Ensure map tiles have proper text alternatives */
.leaflet-tile {
    background-color: #f4f4f4;
}

/* Fix for screen readers */
.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
    font-size: 1.5em;
    line-height: 26px;
    font-weight: bold;
}

/* Make sure the map container is focusable */
.leaflet-container[tabindex="0"]:focus {
    outline: 3px solid #4d90fe !important;
    outline-offset: 2px;
}

/* Fix for touch devices */
.leaflet-touch .leaflet-bar a {
    width: 30px;
    height: 30px;
    line-height: 30px;
}

/* Ensure proper contrast for disabled state */
.leaflet-disabled {
    opacity: 0.5;
    cursor: default;
}

/* Fix for print styles */
@media print {
    .leaflet-control-container,
    .leaflet-control-zoom {
        display: none !important;
    }
}
