/* Interactive Map Plugin - Enhanced v3.1.0 (MOBILE OPTIMIZED) */
/* 
 * ALL STYLES SCOPED TO .imp-map-container TO PREVENT CSS CONFLICTS
 * Version: 1.9.5 - Natural Image Aspect Ratio
 * 
 * UPDATES IN v1.9.5:
 * - Images display in their natural aspect ratio (no cropping)
 * - Changed from fixed 200px height to flexible height
 * - Images use object-fit: contain instead of cover
 * - Container hidden when no image present
 * - Max height of 400px to prevent extremely tall images
 * 
 * UPDATES IN v1.9.4:
 * - Loading placeholder for lazy-loaded maps
 * - Visual feedback while map resources are loading
 * 
 * UPDATES IN v1.9.3:
 * - Reduced popup backdrop opacity to 0.3
 * 
 * UPDATES IN v1.9.2:
 * - Popup positioned on left side at middle height
 * - Submenu items (point-item) appear on new line below main paths
 * 
 * Previous features maintained:
 * - Mobile-specific touch interactions
 * - iOS scroll behavior fixes
 * - Landscape phone optimization
 * - Small phone support (iPhone SE)
 * - Menu scroll indicators
 * - Better touch feedback
 * - Improved performance on mobile
 * - Enhanced transition support for smooth crossfades
 * - Label fade-in/fade-out with smooth transitions
 * - Marker opacity transitions for smooth path changes
 * - Path line opacity transitions handled by Mapbox
 * - Polished point submenu animations
 */

/* CSS Variables scoped to map container only */
.imp-map-container {
    --imp-primary-color: #007CBF;
    --imp-primary-hover: #0056b3;
    --imp-primary-active: #004085;
    --imp-text-light: #fff;
    --imp-text-dark: #333;
    --imp-border-radius: 4px;
    --imp-shadow: 0 2px 10px rgba(0,0,0,0.1);
    --imp-shadow-large: 0 4px 20px rgba(0,0,0,0.2);
    --imp-transition: all 0.2s ease;
    
    /* Fade transition duration - adjusted based on device */
    --imp-fade-duration: 500ms;
}

/* Mobile: Faster transitions */
@media (max-width: 768px) {
    .imp-map-container {
        --imp-fade-duration: 300ms;
    }
}

/* Container Styles */
.imp-map-container {
    position: relative;
    height: 90vh;
    width: 100%;
    
    /* Mobile: Prevent iOS scroll conflicts */
    overscroll-behavior-y: contain;
    touch-action: pan-x pan-y pinch-zoom;
    -webkit-overflow-scrolling: touch;
    
    /* Lazy loading placeholder */
    background: #f5f5f5;
}

/* Lazy loading placeholder - shows before map initializes */
.imp-map-container::before {
    content: 'Loading map...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #666;
    font-size: 16px;
    font-weight: 500;
    z-index: 1;
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* Hide placeholder once map is initialized */
.imp-map-container.map-initialized::before {
    opacity: 0;
    pointer-events: none;
}

@media (max-width: 768px) {
    .imp-map-container {
        height: 80vh !important;
    }
}

/* Landscape phones: maximize map space */
@media (max-height: 480px) and (orientation: landscape) {
    .imp-map-container {
        height: 95vh !important;
    }
}

.imp-map-container #map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
}

/* Loading Message */
.imp-map-container #loading-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 30px 40px;
    border-radius: 12px;
    box-shadow: var(--imp-shadow-large);
    z-index: 1000;
    text-align: center;
    font-size: 18px;
    font-weight: 500;
    color: var(--imp-text-dark);
    animation: imp-fadeIn 0.3s ease-in;
}

@keyframes imp-fadeIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.imp-map-container #loading-message::after {
    content: '';
    display: block;
    margin: 15px auto 0;
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--imp-primary-color);
    border-radius: 50%;
    animation: imp-spin 1s linear infinite;
}

@keyframes imp-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Fly-Through Label */
.imp-map-container #fly-label {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 18px 35px;
    border-radius: 30px;
    font-size: 26px;
    font-weight: bold;
    z-index: 1000;
    opacity: 0;
    transition: opacity var(--imp-fade-duration) ease;
    pointer-events: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.imp-map-container #fly-label.show {
    opacity: 1;
}

@media (max-width: 768px) {
    .imp-map-container #fly-label {
        top: 30px;
        font-size: 20px;
        padding: 12px 24px;
        border-radius: 20px;
        /* Faster transitions on mobile */
        transition: opacity 400ms ease;
    }
}

/* Point Labels with Smooth Fade Transitions */
.imp-map-container .point-label {
    order: -1;
    margin-bottom: 5px;
    padding: 0;
    
    color: var(--imp-text-dark);
    font-size: 13px;
    font-weight: 700;
    
    background: none;
    border: none;
    
    text-shadow: 
        -1px -1px 0 #fff,
        1px -1px 0 #fff,
        -1px 1px 0 #fff,
        1px 1px 0 #fff,
        -2px -2px 0 #fff,
        2px -2px 0 #fff,
        -2px 2px 0 #fff,
        2px 2px 0 #fff,
        0 0 3px rgba(255, 255, 255, 0.9);
    
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
    max-width: 150px;
    
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    letter-spacing: 0.3px;
    
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    
    transition: opacity var(--imp-fade-duration) ease, 
                visibility var(--imp-fade-duration) ease,
                transform var(--imp-fade-duration) ease;
    
    z-index: 100;
    
    /* Start slightly below for smooth fade-up effect */
    transform: translateY(5px);
}

/* Mobile: Faster, smoother transitions */
@media (max-width: 768px) {
    .imp-map-container .point-label {
        transition: opacity 300ms ease, 
                    visibility 300ms ease,
                    transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* Visible state with smooth fade-in */
.imp-map-container .point-label.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Hover effect on marker shows label momentarily */
.imp-map-container .mapboxgl-marker:hover .point-label {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

@media (max-width: 768px) {
    .imp-map-container .point-label {
        font-size: 12px;
        max-width: 130px;
        margin-bottom: 4px;
    }
}

/* Small phones (iPhone SE) */
@media (max-width: 375px) {
    .imp-map-container .point-label {
        font-size: 11px;
        max-width: 110px;
    }
}

/* Marker Container with Smooth Opacity Transitions */
.imp-map-container .mapboxgl-marker {
    transition: opacity var(--imp-fade-duration) ease !important;
}

/* Bottom Menu with Gradient Background */
.imp-map-container #bottom-menu,
.imp-map-container #menu {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: transparent !important;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    max-height: min(120px, 20vh);
    overflow-y: auto;
    z-index: 10;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
}

/* Hide menu header and close button for bottom menu design */
.imp-map-container #menu .menu-header,
.imp-map-container #menu-toggle {
    display: none !important;
}

/* Landscape phones: reduce menu height */
@media (max-height: 480px) and (orientation: landscape) {
    .imp-map-container #bottom-menu,
    .imp-map-container #menu {
        max-height: 60px !important;
        padding: 5px 0 !important;
    }
}

.imp-map-container #bottom-menu::before,
.imp-map-container #menu::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 150px;
    background: linear-gradient(to bottom, 
        rgba(0, 0, 0, 0) 5%, 
        rgba(0, 0, 0, 0.3) 30%, 
        rgba(0, 0, 0, 0.6) 70%, 
        rgba(0, 0, 0, 0.9) 100%);
    pointer-events: none;
    z-index: -1;
}

.imp-map-container #menu-items {
    display: flex;
    flex-wrap: wrap;
    padding: 10px;
    gap: 10px;
    align-items: flex-start;
    justify-content: center;
    position: relative;
    z-index: 1;
    
    /* Mobile: Enable horizontal scroll with snap */
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

/* Menu scroll indicators (mobile) - using data attributes */
.imp-map-container #menu-items[data-has-scroll]::before,
.imp-map-container #menu-items[data-has-scroll]::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.3s ease;
}

@media (max-width: 768px) {
    .imp-map-container #menu-items[data-has-scroll]::before,
    .imp-map-container #menu-items[data-has-scroll]::after {
        opacity: 1;
    }
    
    .imp-map-container #menu-items[data-has-scroll]::before {
        left: 0;
        background: linear-gradient(to right, rgba(0,0,0,0.6), transparent);
    }
    
    .imp-map-container #menu-items[data-has-scroll]::after {
        right: 0;
        background: linear-gradient(to left, rgba(0,0,0,0.6), transparent);
    }
}

.imp-map-container .menu-item {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    cursor: pointer;
    font-size: 15px;
    white-space: nowrap;
    color: var(--imp-text-light) !important;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: var(--imp-border-radius);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    transition: var(--imp-transition);
    
    /* Mobile: Snap scrolling and touch feedback */
    scroll-snap-align: center;
    -webkit-tap-highlight-color: rgba(0, 123, 191, 0.3);
}

/* Better touch feedback on mobile */
@media (max-width: 768px) {
    .imp-map-container .menu-item:active,
    .imp-map-container .view-all-button:active {
        transform: scale(0.95);
        transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

.imp-map-container .menu-item:hover,
.imp-map-container .menu-item:focus {
    background: var(--imp-primary-color);
    color: white;
    border-color: var(--imp-primary-color);
    transform: translateY(-2px);
    box-shadow: var(--imp-shadow);
}

.imp-map-container .menu-item.active {
    background: var(--imp-primary-color);
    color: white;
    border-color: var(--imp-primary-color);
    box-shadow: var(--imp-shadow);
}

/* Path items */
.imp-map-container .menu-item.path-item {
    font-weight: 600;
    order: 1;
}

/* POI items under paths - UPDATED: All point items start on new line */
.imp-map-container .menu-item.point-item {
    font-size: 13px;
    padding: 5px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.3);
    order: 2;
    
    /* Force ALL point items to start on a new line below main paths */
    flex: 0 1 auto;
    min-width: fit-content;
    
    /* Start each point-item on a new line */
    flex-basis: 100%;
    max-width: fit-content;
    
    /* Visible when displayed, controlled by display property */
    opacity: 1;
    transform: translateY(0);
}

/* Hidden state when display: none */
.imp-map-container .menu-item.point-item[style*="display: none"] {
    opacity: 0;
}

.imp-map-container .menu-item.point-item:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Entering animation for point items */
.imp-map-container .menu-item.point-item-entering {
    animation: imp-slideIn 0.3s ease forwards;
}

@keyframes imp-slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* View All Button */
.imp-map-container .view-all-button {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    color: var(--imp-text-light) !important;
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-radius: var(--imp-border-radius);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    transition: var(--imp-transition);
    order: 0;
}

.imp-map-container .view-all-button:hover,
.imp-map-container .view-all-button:focus {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.8);
    transform: translateY(-2px);
    box-shadow: var(--imp-shadow);
}

.imp-map-container .view-all-button.active {
    background: rgba(255, 255, 255, 0.9);
    color: #333 !important;
    border-color: white;
    box-shadow: var(--imp-shadow-large);
}

/* Custom Popup Styles - UPDATED: Left side positioning at middle height */
.imp-map-container .custom-popup {
    position: absolute;
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
    background: white;
    border-radius: 8px;
    box-shadow: var(--imp-shadow-large);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

.imp-map-container .custom-popup.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%);
}

.imp-map-container .custom-popup .popup-title {
    padding: 20px;
    padding-right: 50px;
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    border-bottom: 1px solid #eee;
    color: #000;
    background: #f8f8f8;
    opacity: 1;
}

.imp-map-container .custom-popup .popup-title:empty {
    padding: 0;
    border: none;
    background: #f0f0f0;
    color: #333;
}

.imp-map-container .custom-popup .popup-description {
    padding: 15px 20px;
    font-size: 14px;
    line-height: 1.6;
    color: #666;
}

.imp-map-container .custom-popup .popup-button {
    display: inline-block;
    padding: 10px 20px;
    background: var(--imp-primary-color);
    color: white;
    border-radius: 4px;
    text-decoration: none;
    margin: 10px;
    transition: background 0.2s ease;
}

.imp-map-container .custom-popup .popup-button:hover,
.imp-map-container .custom-popup .popup-button:focus {
    background: var(--imp-primary-hover);
    outline: 2px solid var(--imp-primary-color);
    outline-offset: 2px;
}

.imp-map-container .custom-popup .popup-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    font-size: 32px;
    line-height: 1;
    padding: 0;
    transition: var(--imp-transition);
    font-weight: 300;
}

.imp-map-container .custom-popup .popup-close:hover,
.imp-map-container .custom-popup .popup-close:focus {
    color: #d63638;
    transform: scale(1.2);
    outline: none;
}

.imp-map-container .custom-popup .popup-image {
    width: 100%;
    max-height: 400px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Hide container when empty */
.imp-map-container .custom-popup .popup-image:empty {
    display: none;
}

.imp-map-container .custom-popup .popup-image img {
    width: 100%;
    height: auto;
    max-height: 400px;
    object-fit: contain;
}

/* Mobile Styles */
@media (max-width: 768px) {
    .imp-map-container .custom-popup {
        left: 0;
        right: 0;
        top: auto;
        bottom: 0;
        transform: translateY(100%);
        width: 100%;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 65vh;
        padding-top: 30px;
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        margin-bottom: 50px;
    }
    
    /* Drag handle for bottom sheet */
    .imp-map-container .custom-popup::before {
        content: '';
        position: absolute;
        top: 12px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: #ccc;
        border-radius: 2px;
    }
    
    .imp-map-container .custom-popup.active {
        transform: translateY(0);
    }
    
    .imp-map-container .popup-close {
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 36px;
    }
    
    .imp-map-container .popup-title {
        font-size: 18px;
    }
    
    .imp-map-container .popup-description {
        font-size: 14px;
        padding: 12px 20px;
    }
    
    .imp-map-container .popup-button {
        padding: 10px 20px;
        font-size: 14px;
        font-weight: 600;
    }
}

@media (max-width: 480px) {
    .imp-map-container #bottom-menu,
    .imp-map-container #menu {
        padding: 10px 0;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0));
        gap: 6px;
        min-height: 45px;
    }
    
    .imp-map-container .menu-item {
        font-size: 13px;
        padding: 6px 12px;
    }
    
    .imp-map-container .menu-item.point-item {
        font-size: 12px;
        padding: 3px 8px;
    }
    
    .imp-map-container .view-all-button {
        padding: 8px 16px;
        font-size: 14px;
    }
    
    .imp-map-container .popup-close {
        width: 42px;
        height: 42px;
        font-size: 34px;
    }
    
    .imp-map-container .custom-popup {
        max-height: 65vh;
        margin-bottom: 45px;
    }
    
    .imp-map-container .popup-title {
        font-size: 17px;
        padding-right: 50px;
    }
    
    .imp-map-container .popup-description {
        font-size: 13px;
        padding: 10px 15px;
    }
}

/* Small phones (iPhone SE) */
@media (max-width: 375px) {
    .imp-map-container .menu-item {
        font-size: 12px;
        padding: 6px 10px;
    }
    
    .imp-map-container .custom-popup {
        max-height: 70vh;
    }
    
    .imp-map-container .popup-title {
        font-size: 16px;
    }
}

/* Landscape phones */
@media (max-height: 480px) and (orientation: landscape) {
    .imp-map-container .menu-item {
        font-size: 12px;
        padding: 5px 10px;
    }
    
    .imp-map-container .view-all-button {
        padding: 6px 14px;
        font-size: 13px;
    }
    
    .imp-map-container .custom-popup {
        max-height: 80vh;
    }
}

/* Popup Backdrop - REMOVED: No dark overlay */
.imp-map-container .popup-backdrop {
    display: none !important;
}

.imp-map-container .popup-backdrop.active {
    display: none !important;
}

@media (max-width: 768px) {
    .imp-map-container .popup-backdrop {
        display: none !important;
    }
}

/* Custom Zoom Controls */
.imp-map-container #custom-zoom-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.imp-map-container .zoom-button {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    color: #333;
    transition: background 0.2s ease, color 0.2s ease;
    user-select: none;
    -webkit-tap-highlight-color: rgba(0, 123, 191, 0.3);
}

.imp-map-container .zoom-button:hover {
    background: var(--imp-primary-color);
    color: white;
}

.imp-map-container .zoom-button:active {
    background: var(--imp-primary-hover);
    transform: scale(0.95);
}

.imp-map-container .zoom-button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.imp-map-container .zoom-button:disabled:hover {
    background: rgba(255, 255, 255, 0.95);
    color: #333;
}

.imp-map-container .zoom-button + .zoom-button {
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {
    .imp-map-container #custom-zoom-controls {
        top: 15px;
        right: 15px;
    }
    
    .imp-map-container .zoom-button {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
}

/* Accessibility improvements */
.imp-map-container .menu-item:focus-visible,
.imp-map-container .view-all-button:focus-visible,
.imp-map-container .popup-button:focus-visible,
.imp-map-container .popup-close:focus-visible {
    outline: 2px solid var(--imp-primary-color);
    outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .imp-map-container *,
    .imp-map-container *::before,
    .imp-map-container *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .imp-map-container #fly-label,
    .imp-map-container .point-label,
    .imp-map-container .point-item-entering,
    .imp-map-container .mapboxgl-marker {
        transition: none !important;
        animation: none !important;
    }
}

/* Print Styles */
@media print {
    .imp-map-container #bottom-menu,
    .imp-map-container #menu,
    .imp-map-container .custom-popup,
    .imp-map-container .mapboxgl-ctrl-group,
    .imp-map-container #fly-label,
    .imp-map-container #loading-message,
    .imp-map-container .point-label,
    .imp-map-container #custom-zoom-controls {
        display: none !important;
    }
    
    .imp-map-container {
        height: 100vh !important;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .imp-map-container .menu-item,
    .imp-map-container .view-all-button {
        border-width: 2px;
    }
    
    .imp-map-container .custom-popup {
        border: 2px solid #000;
    }
    
    .imp-map-container #fly-label {
        border: 2px solid white;
    }
    
    .imp-map-container .point-label {
        border-width: 3px;
    }
}