/* Stacking context isolation to prevent map controls, legend, and panels from overlapping the sticky site header */
.section-mapa-entorno {
    position: relative;
    z-index: 10;
}

.map-wrapper {
    position: relative;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(29,37,44,0.12);
}

#entorno-map {
    width: 100%;
    height: 600px;
}

/* Sidebar legend */
.map-legend {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 12px;
    padding: 20px;
    max-width: 300px;
    max-height: calc(100% - 32px);
    overflow-y: auto;
    box-shadow: 0 4px 24px rgba(29,37,44,0.15);
    scrollbar-width: thin;
    scrollbar-color: #009abf transparent;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease;
}

.map-legend.collapsed {
    transform: translateX(-120%);
    opacity: 0;
    pointer-events: none;
}

.map-legend::-webkit-scrollbar {
    width: 4px;
}
.map-legend::-webkit-scrollbar-thumb {
    background: #009abf;
    border-radius: 4px;
}

.map-legend h3 {
    font-size: 15px;
    font-weight: 700;
    color: #1d252c;
    margin-bottom: 14px;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-section {
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(29,37,44,0.08);
}

.legend-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.legend-section-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #6b7280;
    font-weight: 600;
    margin-bottom: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
    font-size: 13px;
    line-height: 1.3;
}

.legend-item:hover {
    background: #f4f5f6;
}

.legend-item.active {
    background: rgba(0,154,191,0.08);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

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

.legend-icon svg {
    width: 14px;
    height: 14px;
    display: block;
}

.legend-item-text {
    display: flex;
    flex-direction: column;
}

.legend-item-name {
    font-weight: 500;
    color: #1d252c;
}

.legend-item-detail {
    font-size: 11px;
    color: #6b7280;
    margin-top: 1px;
}

/* Info panel for selected marker */
.info-panel {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 1000;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 14px;
    padding: 18px 22px;
    max-width: 420px;
    width: calc(100% - 32px);
    box-shadow: 0 8px 32px rgba(29,37,44,0.18);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.info-panel.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

.info-panel-close {
    position: absolute;
    top: 12px;
    right: 14px;
    width: 28px;
    height: 28px;
    border: 1px solid rgba(29,37,44,0.08);
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #6b7280;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.info-panel-close:hover {
    background: #e85d4a;
    color: #ffffff;
    border-color: #e85d4a;
    transform: scale(1.15) rotate(90deg);
    box-shadow: 0 4px 12px rgba(232,93,74,0.25);
}

.info-panel-close:active {
    transform: scale(0.95);
}

.info-panel-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    margin-bottom: 8px;
}

.info-panel h4 {
    font-size: 17px;
    font-weight: 700;
    color: #1d252c;
    margin-bottom: 6px;
    letter-spacing: -0.02em;
    padding-right: 30px;
}

.info-panel p {
    font-size: 13px;
    color: #6b7280;
    line-height: 1.55;
    margin-bottom: 0;
}

.info-panel-stats {
    display: flex;
    gap: 16px;
    margin-top: 10px;
}

.info-panel-stat {
    font-size: 12px;
    color: #1d252c;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.info-panel-stat-icon {
    width: 14px;
    height: 14px;
    color: #6b7280;
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.info-panel-stat span {
    color: #6b7280;
    font-weight: 400;
}

/* Custom Leaflet overrides */
.leaflet-popup-content-wrapper {
    border-radius: 10px !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15) !important;
    padding: 0 !important;
}

.leaflet-popup-content {
    margin: 12px 14px !important;
    font-family: 'Montserrat', sans-serif !important;
    font-size: 13px !important;
    line-height: 1.4 !important;
}

.leaflet-popup-tip {
    box-shadow: 0 4px 16px rgba(0,0,0,0.1) !important;
}

.custom-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 3px solid #ffffff;
    box-shadow: 0 3px 12px rgba(29,37,44,0.3);
    transition: transform 0.2s ease;
}

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

.custom-marker svg {
    width: 55%;
    height: 55%;
    color: #ffffff;
    display: block;
}

.home-marker {
    width: 44px;
    height: 44px;
    background: #f3bd48;
}

.nature-marker {
    width: 36px;
    height: 36px;
    background: #009abf;
}

.culture-marker {
    width: 36px;
    height: 36px;
    background: #1d252c;
}

.route-marker {
    width: 34px;
    height: 34px;
    background: #76bc21;
}

.gastro-marker {
    width: 34px;
    height: 34px;
    background: #e85d4a;
}

.service-marker {
    width: 34px;
    height: 34px;
    background: #7c3aed;
}

/* Toggle for legend */
.legend-toggle {
    display: flex;
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 1001;
    width: 42px;
    height: 42px;
    background: #ffffff;
    border: 1px solid rgba(29,37,44,0.08);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(29,37,44,0.12);
    cursor: pointer;
    font-size: 18px;
    font-weight: 600;
    color: #1d252c;
    align-items: center;
    justify-content: center;
    transition: left 0.4s cubic-bezier(0.16, 1, 0.3, 1), background 0.2s, color 0.2s, transform 0.2s;
}

.legend-toggle:hover {
    background: #1d252c;
    color: #ffffff;
    transform: scale(1.05);
}

.legend-toggle:active {
    transform: scale(0.95);
}

.legend-toggle.open {
    left: 328px; /* 300px max-width + 16px left + 12px gap */
}

@media (max-width: 768px) {
    #entorno-map {
        height: 500px;
    }

    .map-legend {
        max-width: 260px;
        padding: 16px;
        max-height: 60%;
    }

    .legend-toggle.open {
        left: 280px; /* 260px max-width + 16px left + 4px gap */
    }

    .info-panel {
        max-width: calc(100% - 24px);
        padding: 14px 16px;
    }
}
