/* Estilos del contenedor del mapa con responsividad completa */
.map-container {
    width: 100%;
    height: 300px; /* Altura base para móviles */
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    margin-bottom: 1rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

@media (min-width: 576px) {
    .map-container {
        height: 350px; /* Altura para tablets */
    }
}

@media (min-width: 992px) {
    .map-container {
        height: 100%; /* Altura dinámica para desktop */
        min-height: 400px;
        margin-bottom: 0;
    }
}

/* Estado de carga del mapa */
.map-container.loading::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 400;
}

.map-container.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 110, 109, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    z-index: 401;
    animation: map-spinner 1s linear infinite;
}

@keyframes map-spinner {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Controles del mapa optimizados para táctil */
.leaflet-control-container .leaflet-control-zoom {
    border: none;
    margin: 1rem;
}

.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
    background: white !important;
    border: none !important;
    width: 36px !important; /* Más grande para mejor toque */
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
    border-radius: 8px !important;
    color: var(--primary-color) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
    transition: all 0.3s ease !important;
    margin-bottom: 8px !important;
}

@media (hover: hover) {
    .leaflet-control-zoom-in:hover,
    .leaflet-control-zoom-out:hover {
        background: var(--primary-color) !important;
        color: white !important;
    }
}

/* Personalización de controles para dispositivos táctiles */
@media (pointer: coarse) {
    .leaflet-control-zoom-in,
    .leaflet-control-zoom-out {
        width: 44px !important; /* Aún más grande para dispositivos táctiles */
        height: 44px !important;
        line-height: 44px !important;
    }
    
    /* Posicionar controles de zoom en la esquina inferior derecha para acceso con pulgar */
    .leaflet-control-container .leaflet-bottom.leaflet-right {
        bottom: 20px;
        right: 20px;
    }
}

/* Marcador personalizado optimizado */
.custom-marker-container {
    background: transparent;
    contain: layout style;
}

.custom-marker {
    width: 40px;
    height: 40px;
    position: relative;
    transform-origin: bottom center;
    transition: transform 0.2s ease;
}

.custom-marker:hover {
    z-index: 1000 !important;
}

.map-marker {
    width: 30px;
    height: 30px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    border: 2px solid white;
    transition: all 0.3s ease;
    position: relative;
}

.map-marker::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px 6px 0 6px;
    border-color: white transparent transparent transparent;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.1));
}

.map-marker i {
    transform: rotate(45deg);
    font-size: 14px;
}

/* Tipos específicos de marcadores */
.marker-house {
    background: var(--primary-color);
}

.marker-apartment {
    background: #9B8B70;
}

.marker-condo {
    background: var(--secondary-color);
}

.marker-land {
    background: #A69F95;
}

.marker-estate {
    background: #8E8279;
}

/* Marcador activo con animación */
.map-marker.active {
    transform: scale(1.2) rotate(-45deg);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    animation: markerPulse 1.5s infinite;
}

@keyframes markerPulse {
    0% { box-shadow: 0 0 0 0 rgba(0, 110, 109, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(0, 110, 109, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 110, 109, 0); }
}

/* Vista previa del marcador con diseño responsivo */
.marker-preview {
    position: absolute;
    bottom: calc(100% + 15px);
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    background: white;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    min-width: 220px;
    max-width: 250px;
    display: none;
    z-index: 1001;
    pointer-events: none;
    transition: all 0.3s ease;
    overflow: hidden;
}

@media (min-width: 576px) {
    .marker-preview {
        min-width: 250px;
        max-width: 280px;
    }
}

/* Solo mostrar previsualización en hover para dispositivos con hover */
@media (hover: hover) {
    .map-marker:hover .marker-preview {
        display: block;
    }
}

/* Para dispositivos táctiles, usamos un enfoque diferente */
@media (pointer: coarse) {
    .map-marker.touched .marker-preview {
        display: block;
    }
    
    /* Para evitar que el toque dispare el click del marcador */
    .map-marker.preview-open {
        pointer-events: none;
    }
    
    /* La previsualización sí debe recibir eventos */
    .map-marker.preview-open .marker-preview {
        pointer-events: auto;
    }
}

.marker-preview::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 8px 8px 0 8px;
    border-color: white transparent transparent transparent;
}

.property-image {
    width: 100%;
    height: 120px;
    background: #f5f5f5;
}

.property-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-info {
    padding: 10px;
}

.property-type {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--primary-color);
    margin-bottom: 5px;
    font-weight: 500;
}

.property-location {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.property-price {
    font-size: 14px;
    font-weight: 600;
    color: var(--secondary-color);
}

/* Popup del mapa mejorado para táctil */
.leaflet-popup {
    margin-bottom: 20px;
}

.leaflet-popup-content-wrapper {
    border-radius: 8px;
    padding: 0;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

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

.map-popup {
    padding: 1rem;
}

.map-popup h4 {
    color: var(--primary-color);
    margin: 0 0 0.5rem;
    font-size: 1rem;
}

.map-popup p {
    color: var(--text-secondary);
    margin: 0;
    font-size: 0.875rem;
}

/* Botón para cerrar el popup */
.leaflet-popup-close-button {
    width: 30px !important;
    height: 30px !important;
    font-size: 18px !important;
    padding: 4px !important;
    color: var(--primary-color) !important;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.leaflet-popup-close-button:hover {
    opacity: 1;
    background: rgba(0, 110, 109, 0.1) !important;
    color: var(--primary-color) !important;
}

/* Botón de vista del mapa responsivo */
.view-map-btn {
    display: inline-block;
    width: 100%;
    padding: 0.75rem 1rem;
    text-align: center;
    color: var(--primary-color);
    text-decoration: none;
    border: 1px solid var(--primary-color);
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.3s ease;
    margin-top: 1rem;
    min-height: 44px; /* Para mejor usabilidad en táctil */
}

@media (hover: hover) {
    .view-map-btn:hover {
        background: var(--primary-color);
        color: white;
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0, 110, 109, 0.2);
    }
}

/* Atribución del mapa mejorada para visibilidad */
.leaflet-container .leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.8);
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: 4px;
    margin: 5px;
}

/* Mejor visibilidad de controles */
.leaflet-bar a {
    text-align: center !important;
}

.leaflet-touch .leaflet-bar a {
    width: 40px !important;
    height: 40px !important;
    line-height: 40px !important;
}

/* Controles adicionales para dispositivos táctiles */
.map-touch-controls {
    position: absolute;
    bottom: 15px;
    left: 15px;
    z-index: 1000;
    display: none; /* Oculto por defecto */
}

@media (pointer: coarse) {
    .map-touch-controls {
        display: flex;
        gap: 10px;
    }
}

.map-touch-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    color: var(--primary-color);
    font-size: 16px;
    transition: all 0.3s ease;
}

.map-touch-btn:active {
    transform: scale(0.95);
    background: rgba(0, 110, 109, 0.1);
}

/* Botón de recentrar mapa */
.recenter-map-btn {
    position: absolute;
    bottom: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    color: var(--primary-color);
    z-index: 999;
    font-size: 16px;
    transition: all 0.3s ease;
    opacity: 0;
    pointer-events: none;
}

.recenter-map-btn.visible {
    opacity: 1;
    pointer-events: auto;
}

@media (hover: hover) {
    .recenter-map-btn:hover {
        background: var(--primary-color);
        color: white;
        transform: rotate(360deg);
    }
}

/* Ajustes para el mapa modal */
.modal-map-container {
    height: 300px;
    border-radius: 8px;
    overflow: hidden;
    margin-top: 1rem;
}

@media (min-width: 768px) {
    .modal-map-container {
        height: 400px;
    }
}

/* Marcador del modal de propiedad */
.modal-map-marker {
    width: 32px;
    height: 32px;
    position: relative;
}

.modal-marker-pin {
    width: 32px;
    height: 32px;
    border-radius: 50% 50% 50% 0;
    background: var(--secondary-color);
    transform: rotate(-45deg);
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -20px 0 0 -16px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    border: 2px solid white;
    animation: bounce 0.5s ease-out;
}

.modal-marker-pin::after {
    content: '';
    position: absolute;
    width: 60%;
    height: 60%;
    border-radius: 50%;
    background: white;
    top: 20%;
    left: 20%;
}

@keyframes bounce {
    0% { transform: translateY(-20px) rotate(-45deg); }
    50% { transform: translateY(-10px) rotate(-45deg); }
    100% { transform: translateY(0) rotate(-45deg); }
}

/* Estilo especial para mapa elegante */
.elegant-map .leaflet-tile-pane {
    filter: grayscale(0.7) contrast(0.9) brightness(1.05);
}

/* Responsive para pantallas muy pequeñas */
@media (max-width: 320px) {
    .map-container {
        height: 250px;
    }
    
    .marker-preview {
        min-width: 180px;
        max-width: 200px;
    }
    
    .property-image {
        height: 100px;
    }
    
    .leaflet-control-zoom-in,
    .leaflet-control-zoom-out {
        width: 32px !important;
        height: 32px !important;
        line-height: 32px !important;
    }
}

/* Responsive para pantallas extra grandes */
@media (min-width: 1400px) {
    .map-container {
        min-height: 500px;
    }
    
    .map-marker {
        width: 36px;
        height: 36px;
    }
    
    .map-marker i {
        font-size: 16px;
    }
    
    .marker-preview {
        min-width: 280px;
        max-width: 320px;
    }
    
    .property-image {
        height: 140px;
    }
}

/* Adaptaciones de accesibilidad */
@media (prefers-reduced-motion: reduce) {
    .map-marker,
    .marker-preview,
    .modal-marker-pin,
    .recenter-map-btn,
    .map-touch-btn,
    .leaflet-control-zoom-in,
    .leaflet-control-zoom-out {
        transition: none !important;
        animation: none !important;
    }
    
    .map-container.loading::after {
        animation: none !important;
    }
    
    .map-marker.active {
        animation: none !important;
        transform: scale(1.2) rotate(-45deg);
    }
}

/* Soporte para modo oscuro */
@media (prefers-color-scheme: dark) {
    .map-container {
        border-color: rgba(255, 255, 255, 0.1);
    }
    
    .map-container.loading::before {
        background: rgba(0, 0, 0, 0.5);
    }
    
    .marker-preview {
        background: #222;
        box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    }
    
    .marker-preview::after {
        border-color: #222 transparent transparent transparent;
    }
    
    .property-type {
        color: var(--secondary-color);
    }
    
    .property-location {
        color: #aaa;
    }
    
    .leaflet-popup-content-wrapper {
        background: #222;
        color: #eee;
    }
    
    .leaflet-container .leaflet-control-attribution {
        background: rgba(0, 0, 0, 0.7);
        color: #bbb;
    }
    
    .map-popup h4 {
        color: var(--secondary-color);
    }
    
    .map-popup p {
        color: #bbb;
    }
    
    .leaflet-control-zoom-in,
    .leaflet-control-zoom-out,
    .map-touch-btn,
    .recenter-map-btn {
        background: #333 !important;
        color: var(--secondary-color) !important;
    }
    
    /* Estilo especial para mapa oscuro */
    .elegant-map .leaflet-tile-pane {
        filter: invert(1) hue-rotate(180deg) grayscale(0.7) contrast(0.9) brightness(0.8);
    }
}

/* Soporte para modo de alto contraste */
@media (forced-colors: active) {
    .map-container {
        border: 2px solid CanvasText;
    }
    
    .map-marker {
        border: 2px solid ButtonText;
        forced-color-adjust: none;
    }
    
    .modal-marker-pin {
        forced-color-adjust: none;
    }
    
    .leaflet-control-zoom-in,
    .leaflet-control-zoom-out,
    .map-touch-btn,
    .recenter-map-btn {
        border: 1px solid ButtonText !important;
    }
}