/* Frontend Map Styles */
.im-map-wrapper {
    font-family: Mulish, Arial, sans-serif;
    width: 100%;
}

.im-map-container {
    display: flex;
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    width: 100%;
    min-height: 500px;
    height: 600px;
}

/* Sidebar */
.im-sidebar {
    width: 400px;
    min-width: 400px;
    background: white;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    z-index: 1;
    flex-shrink: 0;
}

/* Default View - List */
.im-default-view {
    padding: 25px;
}

.im-title {
    font-size: 28px;
    margin-bottom: 10px;
    color: #1a1a1a;
    font-weight: 700;
}

.im-description {
    color: #666;
    font-size: 14px;
    margin-bottom: 25px;
}

.im-section-title {
    font-size: 12px;
    color: #999;
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.im-spot-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.im-spot-card {
    background: white;
    padding: 4px 16px 4px 4px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 15px;
    border: 2px solid transparent;
}

.im-spot-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.im-spot-card.active {
    border: 2px solid #1559aa;
    background: #f0f7ff;
}

.im-spot-icon {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.im-spot-info {
    flex: 1;
}

.im-spot-name {
    font-weight: 600;
    font-size: 16px;
    color: #1a1a1a;
    margin-bottom: 4px;
}

.im-spot-category {
    font-size: 13px;
    color: #666;
}

/* Detail View */
.im-detail-view {
    display: none;
    flex-direction: column;
    height: 100%;
}

.im-detail-view.active {
    display: flex;
}

.im-detail-header {
    position: relative;
    width: 100%;
    height: 250px;
    background: #f0f0f0;
    overflow: hidden;
}

.im-detail-header img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.im-no-image {
    width: 100%;
    height: 100%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 64px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.im-back-button {
    position: absolute;
    top: 15px;
    left: 15px;
    background: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: all 0.3s;
    font-size: 20px;
    z-index: 10;
}

.im-back-button:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.im-detail-content {
    padding: 25px;
    flex: 1;
    overflow-y: auto;
}

.im-detail-title {
    font-size: 26px;
    font-weight: 700;
    color: #1a1a1a;
    margin-bottom: 8px;
}

.im-detail-category {
    font-size: 14px;
    color: #666;
    margin-bottom: 20px;
}

.im-detail-address {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 14px;
    color: #495057;
}

.im-detail-address-icon {
    font-size: 18px;
    margin-top: 2px;
}

.im-detail-info {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 15px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 14px;
    color: #495057;
}

.im-info-icon {
    font-size: 18px;
    margin-top: 2px;
}

.im-detail-info a {
    color: #1559aa;
    text-decoration: none;
}

.im-detail-info a:hover {
    text-decoration: underline;
}

.im-maps-button {
    width: 100%;
    padding: 14px;
    background-image: linear-gradient(30deg, #00234e, #1559aa);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
}

.im-maps-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(21, 89, 170, 0.4);
}

.im-detail-description {
    font-size: 15px;
    line-height: 1.6;
    color: #495057;
    margin-bottom: 25px;
    white-space: pre-wrap;
}

.im-detail-gallery {
    margin-bottom: 25px;
}

.im-gallery-title {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 15px;
}

.im-gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.im-gallery-item {
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s;
}

.im-gallery-item:hover {
    transform: scale(1.05);
}

.im-gallery-item img,
.im-gallery-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Map */
.im-frontend-map {
    flex: 1;
    min-width: 0;
    height: 100%;
    min-height: 500px;
    position: relative;
    z-index: 1;
}

/* Lightbox */
.im-lightbox {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.9);
    align-items: center;
    justify-content: center;
}

.im-lightbox.active {
    display: flex;
}

.im-lightbox-content {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
}

.im-lightbox-close {
    position: absolute;
    top: 20px;
    right: 40px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10001;
}

.im-lightbox-close:hover {
    color: #ccc;
}

/* Loading State */
.im-loading {
    padding: 40px 20px;
    text-align: center;
    color: #666;
}

/* Responsive */
@media (max-width: 768px) {
    /*
      Mobile layout (<=768px):
      - Map full screen
      - Bottom horizontal carousel for spots (like Framer example)
    */

    .im-map-container {
        position: relative;
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }

    /* Hide title + description on mobile (keep elements in DOM for JS) */
    .im-map-title,
    .im-map-description {
        display: none !important;
    }

    /* Layering: keep everything at z-index 0/1 (requested) */
    .im-map-wrapper,
    .im-frontend-map {
        z-index: 0;
    }

    .im-sidebar,
    .im-detail-view {
        z-index: 1;
    }

    /* Map takes the full viewport */
    .im-map-wrapper,
    .im-frontend-map {
        height: 100% !important;
        min-height: 100% !important;
    }

    /* Ensure UI sits above the map but keep z-index low as requested */
    .im-frontend-map { z-index: 0; }

    /* Sidebar becomes an overlay “bottom bar” */
    .im-sidebar {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        min-width: 100%;
        height: auto;
        max-height: 36vh;
        background: transparent;
        border-right: none;
        border-top: none;
        padding: 0;
        overflow: visible;
        z-index: 1;
        pointer-events: none; /* let the map receive gestures */
    }

    .im-default-view {
        pointer-events: auto; /* re-enable interactions inside */
        padding: 14px 0px 14px 0px;
        background: #13192780;
    }

    /* Hide map title + description on mobile (requested)
       NOTE: keep elements in DOM (JS may reference them). */
    .im-map-title,
    .im-map-description,
    .im-title,
    .im-description {
        display: none !important;
    }

    .im-section-title {
        display: none;
    }

    /* Filters row becomes horizontal and scrollable */
    .im-filter-tags {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        gap: 8px;
        padding-bottom: 8px;
    }

    .im-filter-tag {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    /* Spots list becomes a horizontal carousel */
    .im-spot-list {
        display: flex;
        flex-direction: row;
        gap: 10px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 0px 16px 0px 16px;
        scroll-snap-type: x mandatory;
    }

    .im-spot-item {
        flex: 0 0 auto;
        min-width: 220px;
        max-width: 260px;
        border: 1px solid #eee;
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.96);
        box-shadow: 0 10px 30px rgba(0,0,0,0.10);
        scroll-snap-align: start;
    }

    .im-spot-item:hover {
        background: rgba(255, 255, 255, 0.98);
    }

    /* Quando apro un luogo: nascondo SOLO la lista/carousel, non la sidebar intera */
    .im-map-wrapper.im-detail-open .im-default-view {
        display: none;
    }
    
    /* La detail view deve restare visibile e cliccabile */
    .im-map-wrapper.im-detail-open .im-detail-view {
        display: flex;        /* sicurezza */
        pointer-events: auto; /* sicurezza */
    }
    
    /* Sidebar overlay: ok pointer-events none, ma la detail view deve ricevere tap */
    .im-detail-view {
      pointer-events: auto;
    }


    .im-spot-icon {
        width: 42px;
        height: 42px;
        border-radius: 12px;
        font-size: 18px;
    }

    /* Detail view: bottom sheet over the full-screen map (Framer-like) */
    .im-detail-view {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        height: 70vh;
        z-index: 1; /* requested */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        box-shadow: 0 -20px 50px rgba(0,0,0,0.18);
        transform: translateY(105%);
        transition: transform 0.25s ease;
        background-color: #ffffff;
    }

    .im-detail-view.active {
        transform: translateY(0);
    }

    .im-detail-header {
        height: 220px;
    }

    .im-gallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .im-back-button {
        position: absolute;
        top: 15px;
        left: 15px;
        width: 40px;
        height: 40px;
        z-index: 2;
    }
}

/* Custom Leaflet Marker */
.custom-marker {
    background: none;
    border: none;
}

/* Leaflet Popup Customization */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: 0 3px 14px rgba(0,0,0,0.3);
}

.leaflet-popup-content {
    margin: 15px;
    font-family: inherit;
}
