/* FIXED: Map style controls with consistent z-index */
.map-style-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 500; /* FIXED: Consistent with map control layer */
    backdrop-filter: blur(4px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    pointer-events: auto; /* FIXED: Ensure clickability */
}

.map-style-label {
    font-size: 12px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
    text-align: center;
}

.map-layer-options {
    display: flex;
    gap: 8px;
}

.map-layer-option {
    display: flex;
    align-items: center;
    gap: 4px;
}

.map-layer-option input[type="radio"] {
    width: 14px;
    height: 14px;
    margin: 0;
}

.map-layer-option label {
    font-size: 11px;
    color: #555;
    cursor: pointer;
    white-space: nowrap;
}/* UPDATED: Ensure map container proper height and isolation */
.journey-map-container {
    position: relative;
    height: 600px; /* Reasonable height */
    max-height: 90vh; /* Limit height */
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    background-color: #ffffff;
    transition: all 0.3s ease;
    margin-bottom: 20px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    /* ADDED: Better isolation */
    isolation: isolate;
    z-index: 10;
}

.journey-map {
    width: 100%;
    height: 100%;
    z-index: 1;
    background-color: #f8f8f8;
    /* ADDED: Force minimum height */
    min-height: 500px !important;
    /* ADDED: Hardware acceleration */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Map Container - Wider with better controls */
.map-container {
    position: relative;
    height: 600px; /* Reasonable height */
    border-radius: 0;
    overflow: hidden;
    background-color: #f5f5f5;
}

.interactive-map {
    width: 100%;
    height: 100%;
    z-index: 1;
    background-color: #f8f8f8;
}

/* Map sidebar - improved colors and readability */
.map-sidebar {
    background-color: #35423c;
    padding: 1.5rem;
    color: #ffffff;
    display: flex;
    flex-direction: column;
    height: auto;
    max-height: 600px;
    overflow-y: auto;
    border-bottom: 3px solid #af8a56;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.sidebar-header h3 {
    font-family: var(--font-primary, serif);
    font-size: 1.6rem;
    margin: 0;
    color: #ffffff;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* Improved search bar */
.sidebar-search {
    display: flex;
    align-items: center;
    border-radius: 8px;
    overflow: hidden;
    background-color: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 1.25rem;
}

.sidebar-search input {
    border: none;
    background-color: transparent;
    color: #ffffff;
    padding: 0.8rem 1rem;
    border-radius: 8px 0 0 8px;
    width: 100%;
    font-size: 1rem;
    flex: 1;
}

.sidebar-search input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

.sidebar-search button {
    background-color: rgba(255, 255, 255, 0.1);
    border: none;
    color: #ffffff;
    padding: 0.8rem 1rem;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.sidebar-search button:hover {
    background-color: #af8a56;
}

/* Filter buttons - improved contrast and interaction */
.map-filters {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.filter-button {
    background-color: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ffffff;
    padding: 0.8rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-weight: 500;
}

.filter-button i, 
.filter-button svg {
    font-size: 1rem;
    width: 18px;
    height: 18px;
}

.filter-button:hover {
    background-color: rgba(255, 255, 255, 0.25);
    color: #ffffff;
    transform: translateY(-2px);
}

.filter-button.active {
    background-color: #af8a56;
    color: #ffffff;
    border-color: #af8a56;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.reset-filters {
    background-color: transparent;
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #ffffff;
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    text-align: center;
    grid-column: span 2;
}

.reset-filters:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: #ffffff;
}

/* FIXED: Loading spinner with proper visibility and positioning */
.map-loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none; /* Hidden by default */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 600; /* FIXED: Consistent z-index hierarchy */
    background-color: rgba(255, 255, 255, 0.95);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    pointer-events: none; /* FIXED: Don't block interactions when hidden */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.map-loading-spinner.show {
    display: flex !important; /* SHOW WHEN NEEDED */
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Hide spinner when map is loaded */
.map-loading-spinner.hidden {
    display: none !important;
    opacity: 0;
    visibility: hidden;
}

/* UPDATED: Proper spinner animation and styling */
.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(175, 138, 86, 0.3);
    border-top-color: #af8a56;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

.map-loading-spinner span {
    font-size: 1.1rem;
    color: #35423c;
    margin: 0;
    font-weight: 500;
    text-align: center;
}

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

/* Map legend - improved styling with consistent z-index */
.map-legend {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background-color: rgba(255, 255, 255, 0.98);
    border-radius: 8px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    z-index: 400; /* FIXED: Consistent with control layer hierarchy */
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(0, 0, 0, 0.1);
    isolation: isolate;
    backdrop-filter: blur(4px);
    pointer-events: auto; /* FIXED: Ensure legend is interactive */
}

.legend-title {
    font-weight: 600;
    color: #35423c;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    border-bottom: 2px solid #af8a56;
    padding-bottom: 0.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-size: 0.95rem;
    color: #35423c;
}

.legend-icon {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.legend-icon svg,
.legend-icon i {
    width: 14px;
    height: 14px;
    color: #ffffff;
}

.church-marker {
    background-color: #1E88E5;
}

.shrine-marker {
    background-color: #C9A053;
}

.relic-marker {
    background-color: #895348;
}

.saint-marker {
    background-color: #895348;
}

.route-marker {
    background-color: #5b7f95;
}

/* Improved Leaflet Controls */
.leaflet-control-container .leaflet-control {
    clear: both;
    pointer-events: auto;
}

/* Hide default Leaflet zoom controls since we use custom ones */
.leaflet-control-zoom {
    display: none !important;
}

/* These styles will apply if you need to use Leaflet controls */
.leaflet-control-attribution {
    border: none !important;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1) !important;
}

/* Map controls - our custom controls with consistent z-index */
.map-controls {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 450; /* FIXED: Consistent control layer */
    pointer-events: auto; /* FIXED: Ensure controls are clickable */
}

.journey-map-floating-controls {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 450; /* FIXED: Consistent with other controls */
    pointer-events: auto;
}

.map-floating-btn,
.map-control-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255, 255, 255, 0.95);
    color: #35423c;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    pointer-events: auto; /* FIXED: Ensure buttons are clickable */
}

.map-floating-btn:hover {
    background-color: #ffffff;
    color: #af8a56;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

/* Custom popup styling */
.improved-popup .leaflet-popup-content-wrapper {
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    padding: 0;
    overflow: hidden;
}

.improved-popup .leaflet-popup-content {
    margin: 0;
    padding: 0;
    width: 250px !important;
}

.improved-popup .leaflet-popup-tip {
    background-color: #ffffff;
}

.popup-content {
    padding: 1rem;
}

.popup-content h4 {
    font-family: var(--font-primary, serif);
    font-size: 1.1rem;
    margin: 0 0 0.5rem;
    color: #35423c;
    font-weight: 600;
}

.popup-content p {
    font-size: 0.95rem;
    margin: 0 0 0.75rem;
    color: #5a5a5a;
}

.popup-link {
    display: inline-block;
    background-color: #af8a56;
    color: #ffffff;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.popup-link:hover {
    background-color: #c29c67;
    transform: translateY(-2px);
}

/* Enhanced map marker styles with pilgrimage theme */
.custom-marker {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

.marker-inner {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 24px !important;
    height: 24px !important;
    border-radius: 4px !important;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.marker-inner:hover {
    transform: scale(1.2) translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
}

.marker-inner svg {
    width: 14px !important;
    height: 14px !important;
    color: #ffffff;
}

/* Custom attribution styling */
.leaflet-control-attribution {
    background-color: rgba(255, 255, 255, 0.7) !important;
    padding: 5px 8px !important;
    border-radius: 4px !important;
    margin: 5px !important;
    font-size: 10px !important;
    max-width: 80% !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* UPDATED: Better map error handling and styling */
/* UPDATED: Better map error handling and styling - properly integrated */
.map-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 400px;
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    text-align: center;
    padding: 20px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    color: #6c757d;
}

.map-error .error-icon {
    font-size: 48px;
    margin-bottom: 15px;
    color: #dc3545;
}

.map-error .error-message {
    font-size: 16px;
    color: #666;
    margin-bottom: 20px;
    max-width: 300px;
}

.map-error .error-retry {
    background: #8b0000;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s ease;
}

.map-error .error-retry:hover {
    background: #660000;
}

/* Ensure map container has a minimum height */
.journey-map {
    min-height: 300px;
}

/* Improve marker visibility and z-index */
.journey-marker {
    z-index: 1000 !important;
}

.journey-marker-number {
    z-index: 1001 !important;
}

/* Ensure map controls are properly visible */
.journey-map-floating-controls {
    z-index: 1002;
}

/* Fix popup z-index issues */
.leaflet-popup {
    z-index: 1003 !important;
}

.leaflet-popup-content-wrapper {
    overflow: visible !important;
}

/* Fixed tile loading error display */
.leaflet-tile-pane {
    opacity: 1 !important;
}

/* FIXED: Leaflet container with proper background and positioning */
.leaflet-container {
    background-color: #f8f8f8 !important;
    /* REMOVED: Problematic transforms that can cause grey screen */
    position: relative;
    z-index: 1;
    /* ADDED: Ensure visibility */
    opacity: 1 !important;
    visibility: visible !important;
}

/* Fix for Retina displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .journey-marker-number,
    .journey-marker {
        transform-origin: center center;
        transform: translate(-50%, -50%) scale(1) !important;
    }
}

/* Ensure SVG markers display properly */
.marker-inner svg {
    width: 14px !important;
    height: 14px !important;
    display: block !important;
    pointer-events: none;
}

/* Ensure marker containers are properly positioned */
.leaflet-marker-icon {
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    background: transparent !important;
}

/* Additional fix for marker clustering */
.marker-cluster {
    background-color: rgba(255, 255, 255, 0.8) !important;
    border-radius: 50% !important;
    width: 40px !important;
    height: 40px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-weight: bold !important;
    font-size: 14px !important;
    color: #333 !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3) !important;
    z-index: 999 !important;
}

.marker-cluster div {
    width: 30px !important;
    height: 30px !important;
    border-radius: 50% !important;
    background-color: rgba(175, 138, 86, 0.8) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: white !important;
    font-weight: bold !important;
}

/* Force correct sizing for map container */
.journey-map-container {
    position: relative !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
}

/* Fix for map controls layering */
.leaflet-control-container {
    z-index: 1000 !important;
    position: relative !important;
}

/* Fix map attribution positioning */
.leaflet-control-attribution {
    position: absolute !important;
    bottom: 0 !important;
    right: 0 !important;
    padding: 2px 5px !important;
    background-color: rgba(255, 255, 255, 0.7) !important;
    font-size: 10px !important;
    z-index: 800 !important;
}

/* Fix for tile loading */
.leaflet-tile {
    visibility: visible !important;
}

/* Fix for Safari/iOS specific issues */
.journey-map-container,
.journey-map {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    -moz-transform: translateZ(0);
    -ms-transform: translateZ(0);
    -o-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Force hardware acceleration */
.leaflet-container {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* ENSURE MAP CONTAINER ISOLATION */
.journey-map-container {
    isolation: isolate;
    z-index: 10;
    position: relative;
}

/* HIDE ANY INTERFERING TEXT */
.map-container::before,
.map-container::after {
    display: none !important;
}

/* FORCE MAP TO BE VISIBLE */
.journey-map {
    background-color: #f8f8f8 !important;
    min-height: 500px !important;
}



/* Ensure popups display correctly */
.leaflet-popup {
    margin-bottom: 15px !important;
}

/* Fix animation issues */
.leaflet-fade-anim .leaflet-tile,
.leaflet-fade-anim .leaflet-popup {
    opacity: 1 !important;
    transition: none !important;
}

/* Additional mobile adjustments */
@media (max-width: 768px) {
    .map-sidebar {
        height: 500px;
        border-radius: 16px 16px 0 0;
    }
    
    .map-container {
        height: 400px;
        border-radius: 0 0 16px 16px;
    }
    
    .legend-title {
        font-size: 0.95rem;
    }
    
    .legend-item {
        font-size: 0.8rem;
    }
    
    .legend-icon {
        width: 25px;
        height: 25px;
    }
    
    .map-legend {
        left: 10px;
        bottom: 60px;
        padding: 1rem;
        max-width: 180px;
    }
}

/* Enhanced popup for journey items */
.popup-add-journey {
    display: inline-block;
    background-color: #af8a56;
    color: #ffffff;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
    border: none;
    margin-right: 0.5rem;
}

.popup-add-journey:hover {
    background-color: #c29c67;
    transform: translateY(-2px);
}
