/* Estilos para la página del mapa */
.map-page {
    padding: clamp(1rem, 4vw, 2rem) 0;
    min-height: calc(100vh - 200px);
}

.map-container {
    position: relative;
    width: 100%;
    height: clamp(280px, 50vmin, 600px);
    border-radius: clamp(8px, 2vw, 12px);
    /* IMPORTANTE: NO usar overflow: hidden aquí, puede ocultar los tiles */
    overflow: visible;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    margin-bottom: clamp(1rem, 4vw, 2rem);
    background-color: var(--bg-section);
}

/* Contenedor del mapa de Leaflet - CRÍTICO para que funcione */
#map {
    width: 100% !important;
    height: clamp(280px, 50vmin, 600px) !important;
    min-height: clamp(280px, 50vmin, 600px) !important;
    position: relative !important;
    z-index: 1;
    background-color: var(--bg-muted);
}

/* Estilos adicionales para Leaflet - CRÍTICOS */
.leaflet-container {
    height: 100% !important;
    width: 100% !important;
    z-index: 1;
    position: relative;
}

/* Asegurar que los tiles sean visibles */
.leaflet-tile-container {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 200;
}

.leaflet-tile {
    visibility: visible !important;
    opacity: 1 !important;
}

.map-filters {
    background: var(--bg-section);
    padding: clamp(1rem, 3vw, 1.5rem);
    border-radius: clamp(8px, 2vw, 12px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    margin-bottom: clamp(1rem, 4vw, 2rem);
    border: 1px solid var(--border);
}

.map-filters h3 {
    margin-bottom: 1rem;
    color: var(--primary);
    font-size: clamp(1rem, 2.5vw, 1.25rem);
}

.filters-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    align-items: end;
}

.filter-group-map {
    display: flex;
    flex-direction: column;
}

.filter-group-map label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text);
    font-size: 0.9rem;
}

.filter-group-map select {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--bg-section);
    color: var(--text);
    transition: border-color 0.3s, box-shadow 0.3s;
}

.filter-group-map select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--focus-ring);
}

.filter-group-map select:disabled {
    background: var(--surface-2);
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-filter {
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-filter:hover {
    background: var(--primary-dark);
}

.btn-filter:disabled {
    background: var(--gray-300);
    color: var(--gray-700);
    cursor: not-allowed;
}

.map-info {
    background: var(--surface-2);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    border: 1px solid var(--border);
}

.map-info p {
    margin: 0;
    color: var(--text-muted);
}

.map-info strong {
    color: var(--primary);
}

/* Estilos para los popups del mapa */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.leaflet-popup-content {
    margin: 1rem;
    min-width: 200px;
}

.popup-property {
    font-family: 'Inter', sans-serif;
}

.popup-property h4 {
    margin: 0 0 0.5rem 0;
    color: #1a5f7a;
    font-size: 1.1rem;
    font-weight: 600;
}

.popup-property .popup-location {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.popup-property .popup-price {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1a5f7a;
    margin: 0.5rem 0;
}

.popup-property .popup-details {
    display: flex;
    gap: 1rem;
    margin: 0.5rem 0;
    font-size: 0.85rem;
    color: #666;
}

.popup-property .popup-link {
    display: inline-block;
    margin-top: 0.75rem;
    padding: 0.5rem 1rem;
    background: #1a5f7a;
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: background 0.3s;
}

.popup-property .popup-link:hover {
    background: #144a5e;
}

.popup-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: #ffc107;
    color: #000;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

/* Loading state */
.map-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    background: rgba(255, 255, 255, 0.95);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.map-loading p {
    margin: 0.5rem 0 0 0;
    color: #666;
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #1a5f7a;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive mapa - todos los dispositivos */
@media (max-width: 374px) {
    .map-container,
    #map {
        height: 260px !important;
        min-height: 260px !important;
    }
    .filters-row {
        grid-template-columns: 1fr;
    }
    .map-info {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 768px) {
    .map-container {
        height: clamp(320px, 55vh, 400px);
    }
    #map {
        height: clamp(320px, 55vh, 400px) !important;
        min-height: clamp(320px, 55vh, 400px) !important;
    }
    .filters-row {
        grid-template-columns: 1fr;
    }
    .map-info {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* Fix adicional para asegurar visibilidad de tiles */
.leaflet-pane {
    z-index: 400;
}

.leaflet-map-pane {
    z-index: 400;
}

.leaflet-tile-pane {
    z-index: 200;
}

.leaflet-overlay-pane {
    z-index: 400;
}

.leaflet-shadow-pane {
    z-index: 500;
}

.leaflet-marker-pane {
    z-index: 600;
}

.leaflet-tooltip-pane {
    z-index: 650;
}

.leaflet-popup-pane {
    z-index: 700;
}
