/**
 * JAL RealState — Buscador Mapa Estilo Zillow
 * Layout split-screen: mapa izquierda | tarjetas derecha
 */

/* ── Reset & Variables ── */
:root {
    --jal-primary: #1e3a8a;
    --jal-secondary: #dc2626;
    --jal-marker-bg: #1a1a1a;
    --jal-marker-active: #dc2626;
    --jal-card-radius: 12px;
    --jal-shadow: 0 4px 16px rgba(0,0,0,0.10);
    --jal-shadow-hover: 0 8px 32px rgba(0,0,0,0.18);
    --jal-filter-h: 64px;
}

/* ── Wrapper principal ── */
#jal-map-buscador {
    display: flex;
    flex-direction: column;
    /* Altura relativa a la ventana, no al contenedor de Elementor */
    height: calc(100vh - 120px); /* descuenta el header aprox. Ajustar si el header tiene otra altura */
    overflow: hidden;
    font-family: 'Montserrat', sans-serif;
    background: #f7f8fa;

    /* Técnica de escape del contenedor de Elementor/page-builder */
    /* Hace que el buscador ocupe el ancho COMPLETO del viewport */
    width: 100vw;
    position: relative;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
    max-width: 100vw;
}

/* ── Barra de filtros ── */
#jal-filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px;
    height: var(--jal-filter-h);
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    z-index: 100;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    overflow-x: auto;
    scrollbar-width: none;
}
#jal-filter-bar::-webkit-scrollbar { display: none; }

.jal-filter-select {
    appearance: none;
    -webkit-appearance: none;
    padding: 8px 32px 8px 14px;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23374151' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E") no-repeat right 10px center / 14px;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    white-space: nowrap;
    min-width: 130px;
}
.jal-filter-select:hover, .jal-filter-select:focus {
    border-color: var(--jal-primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(30,58,138,0.10);
}

.jal-filter-price {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f3f4f6;
    border-radius: 8px;
    padding: 4px 10px;
    border: 1.5px solid #d1d5db;
}
.jal-filter-price input {
    width: 90px;
    border: none;
    background: transparent;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    outline: none;
}
.jal-filter-price span {
    font-size: 12px;
    color: #9ca3af;
    font-weight: 500;
}

#jal-filter-reset {
    padding: 8px 16px;
    background: #f3f4f6;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
#jal-filter-reset:hover {
    background: #e5e7eb;
    color: #374151;
}

#jal-result-count {
    margin-left: auto;
    font-size: 12px;
    color: #6b7280;
    white-space: nowrap;
    font-weight: 500;
    padding-right: 4px;
}

/* ── Layout split-screen ── */
#jal-map-split {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - var(--jal-filter-h));
    width: 100%;
}

/* ── Mapa (columna izquierda) ── */
#jal-map-container {
    flex: 0 0 60%; /* 60% para el mapa */
    position: relative;
    z-index: 1;
    height: 100%;
}

#jal-leaflet-map {
    width: 100%;
    height: 100%;
}

/* ── Panel de tarjetas (columna derecha) ── */
#jal-cards-panel {
    flex: 0 0 40%; /* 40% del total */
    /* Encadenar altura exacta al contenedor padre (= altura del mapa) */
    height: 100%;
    max-height: 100%;
    overflow-y: auto; /* scroll solo dentro de esta caja */
    overflow-x: hidden;
    padding: 12px;
    background: #f7f8fa;
    scroll-behavior: smooth;
    box-shadow: -4px 0 15px rgba(0,0,0,0.05);
    z-index: 2;
    /* Grid de 2 columnas estilo Zillow */
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    grid-auto-rows: min-content !important; /* Fijar filas al contenido, no estirar */
    gap: 12px !important;
    align-content: start;
}

/* Scrollbar estilizado para el panel derecho */
#jal-cards-panel::-webkit-scrollbar { width: 8px; }
#jal-cards-panel::-webkit-scrollbar-track { background: #f1f1f1; }
#jal-cards-panel::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
#jal-cards-panel::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Estado de carga ── */
#jal-loading-overlay {
    position: absolute; inset: 0; background: rgba(255,255,255,0.75);
    display: flex; align-items: center; justify-content: center;
    z-index: 500; backdrop-filter: blur(4px); opacity: 0; pointer-events: none;
    transition: opacity 0.25s;
}
#jal-loading-overlay.active { opacity: 1; pointer-events: all; }
.jal-spinner {
    width: 40px; height: 40px; border: 3px solid #e5e7eb;
    border-top-color: var(--jal-primary); border-radius: 50%;
    animation: jal-spin 0.7s linear infinite;
}
@keyframes jal-spin { to { transform: rotate(360deg); } }

/* ── Tarjeta de Propiedad (layout VERTICAL para grilla 2 columnas) ── */
div#jal-cards-panel > article.jal-prop-card {
    background: #fff !important;
    border-radius: var(--jal-card-radius) !important;
    box-shadow: var(--jal-shadow) !important;
    overflow: hidden !important;
    cursor: pointer !important;
    transition: box-shadow 0.2s, transform 0.2s, border 0.15s;
    border: 1px solid #e5e7eb !important;
    
    /* Layout VERTICAL: imagen arriba + info abajo */
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 250px !important; /* Altura mínima: 200px imagen + ~50px body */
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
}
@keyframes cardFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
div#jal-cards-panel > article.jal-prop-card:hover {
    box-shadow: var(--jal-shadow-hover) !important;
    transform: translateY(-2px);
    border-color: #d1d5db !important;
}
div#jal-cards-panel > article.jal-prop-card.active {
    border-color: #1a2b49 !important;
    box-shadow: 0 0 0 2px rgba(26,43,73,0.15), var(--jal-shadow-hover) !important;
    transform: translateY(-2px);
}

/* imagen de la tarjeta (layout vertical — imagen arriba) */
.jal-card-img-wrap {
    position: relative;
    /* Ancho completo, altura fija */
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    height: 200px !important;
    min-height: 200px !important;
    max-height: 200px !important;
    overflow: hidden !important;
    flex-shrink: 0 !important;
    background: #f3f4f6 !important;
    margin: 0 !important;
    padding: 0 !important;
}
/* Slides del carrusel: ocultos por defecto, solo active visible */
.jal-card-img-slide {
    display: none !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    position: absolute !important;
    inset: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    transition: transform 0.7s ease;
}
.jal-card-img-slide.active {
    display: block !important;
}
.jal-prop-card:hover .jal-card-img-slide.active,
.jal-prop-card.active .jal-card-img-slide.active {
    transform: scale(1.05);
}

/* Botón de favoritos (corazón, top-right de imagen) */
.jal-fav-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 3;
    background: rgba(0,0,0,0.35);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background 0.2s, transform 0.15s;
}
.jal-fav-btn:hover {
    background: rgba(0,0,0,0.55);
    transform: scale(1.1);
}
.jal-fav-btn.is-fav {
    background: rgba(255,255,255,0.9);
}

/* Flechas del carrusel */
.jal-card-prev,
.jal-card-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 3;
    background: rgba(255,255,255,0.88);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    color: #111827;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.jal-card-prev { left: 8px; }
.jal-card-next { right: 44px; } /* deja espacio al botón favoritos */
.jal-prop-card:hover .jal-card-prev,
.jal-prop-card:hover .jal-card-next { opacity: 1; }
.jal-card-prev:hover,
.jal-card-next:hover { background: rgba(255,255,255,1); }

/* Dots de navegación */
.jal-card-dots {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    z-index: 3;
}
.jal-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255,255,255,0.55);
    transition: background 0.2s, transform 0.2s;
}
.jal-dot.active {
    background: #fff;
    transform: scale(1.2);
}
.jal-card-badge-op {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(255,255,255,0.95);
    color: #111827;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 4px 10px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.jal-card-no-img {
    width: 100%;
    height: 100%;
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #d1d5db;
    font-size: 3rem;
}

/* body de la tarjeta */
.jal-card-body {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

/* Precio hero (primer elemento del body) */
.jal-card-price-new {
    font-size: 17px;
    font-weight: 800;
    color: #111827;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

/* Stats: texto plano con separador · */
.jal-card-stats-new {
    font-size: 12px;
    color: #374151;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Dirección */
.jal-card-address {
    font-size: 11px;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Footer oculto (no se usa en el nuevo diseño) */
.jal-card-footer { display: none !important; }

/* ── Marcadores de precio (rojo Zillow, texto blanco forzado) ── */
.jal-price-marker {
    background: #c0392b !important; /* Rojo tipo Zillow */
    color: #ffffff !important;       /* Texto blanco — forzado contra herencias de Leaflet */
    font-size: 13px !important;
    font-weight: 700 !important;
    padding: 6px 12px;
    border-radius: 9999px; /* Pill shape */
    white-space: nowrap;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), background 0.2s, box-shadow 0.2s;
    line-height: 1;
    letter-spacing: -0.01em;
    border: 2px solid #ffffff; /* Borde blanco para resaltar sobre el mapa */
    text-shadow: none !important;
}
.jal-price-marker:hover,
.jal-price-marker.active {
    background: #1a3c5e !important;
    color: #ffffff !important;
    transform: scale(1.1);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
    z-index: 1000 !important;
}

/* ── Campo de búsqueda por zona en la barra de filtros ── */
.jal-filter-zona-wrap {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1; /* Ocupa el espacio disponible */
    min-width: 200px;
    max-width: 400px;
    background: #f3f4f6;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    padding: 0 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.jal-filter-zona-wrap:focus-within {
    border-color: var(--jal-primary);
    box-shadow: 0 0 0 3px rgba(30,58,138,0.10);
    background: #fff;
}
.jal-zona-icon {
    width: 15px;
    height: 15px;
    color: #9ca3af;
    flex-shrink: 0;
    margin-right: 8px;
}
#jal-filter-zona {
    border: none;
    background: transparent;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    outline: none;
    width: 100%;
    padding: 8px 0;
}
#jal-filter-zona::placeholder {
    color: #9ca3af;
    font-weight: 400;
}

/* ── Empty state ── */
#jal-empty-state {
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    text-align: center;
    padding: 40px 20px;
    color: #9ca3af;
    grid-column: 1 / -1; /* Ocupa ambas columnas del grid */
}
#jal-empty-state.visible {
    display: flex;
}
#jal-empty-state i {
    font-size: 3rem;
    color: #d1d5db;
}
#jal-empty-state p {
    font-size: 14px;
    font-weight: 500;
}

/* ── Responsive ── */
@media (max-width: 900px) {
    #jal-map-split {
        flex-direction: column;
        height: auto;
        overflow: visible;
    }
    #jal-map-buscador {
        height: auto;
        overflow: visible;
    }
    #jal-map-container {
        flex: none;
        height: 45vh; /* 45% del viewport para el mapa en mobile/tablet */
        width: 100%;
        position: relative; /* Asegura que se desplace naturalmente en mobile */
    }
    #jal-cards-panel {
        display: grid !important;
        grid-template-columns: 1fr !important; /* 1 columna en mobile */
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        width: 100% !important;
        padding: 16px;
        gap: 14px !important;
    }
    .jal-prop-card {
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto;
    }
    .jal-card-img-wrap {
        height: 180px !important; /* Ligeramente más baja en mobile para no dominar */
        min-height: 180px !important;
        max-height: 180px !important;
    }
    #jal-filter-bar {
        flex-wrap: nowrap;
        height: auto;
        padding: 10px 16px;
    }
}

/* ── Leaflet overrides ── */
.leaflet-container {
    font-family: 'Montserrat', sans-serif;
}
.leaflet-control-attribution {
    font-size: 9px !important;
    opacity: 0.7;
}
.leaflet-popup-content-wrapper {
    border-radius: 10px;
    box-shadow: var(--jal-shadow-hover);
    padding: 0;
    overflow: hidden;
}
.leaflet-popup-content {
    margin: 0;
    width: 220px !important;
}
.jal-popup-inner {
    padding: 14px;
}
.jal-popup-title {
    font-size: 13px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.jal-popup-price {
    font-size: 16px;
    font-weight: 800;
    color: var(--jal-primary);
    margin-bottom: 8px;
}
.jal-popup-stats {
    display: flex;
    gap: 10px;
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 10px;
}
.jal-popup-btn {
    display: block;
    text-align: center;
    background: var(--jal-primary);
    color: #fff;
    padding: 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    transition: background 0.2s;
}
.jal-popup-btn:hover {
    background: #1e40af;
    color: #fff;
    text-decoration: none;
}

/* ═══════════════════════════════════════════════
   Modal de Detalle de Propiedad (overlay Zillow)
   ═══════════════════════════════════════════════ */

/* Overlay oscuro */
.jal-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.jal-modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* Card del modal */
.jal-modal-card {
    background: #fff;
    border-radius: 16px;
    width: 90vw;
    max-width: 680px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.35);
    transform: translateY(24px) scale(0.97);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    position: relative;
}
.jal-modal-overlay.active .jal-modal-card {
    transform: translateY(0) scale(1);
}

/* Scrollbar del modal */
.jal-modal-card::-webkit-scrollbar { width: 6px; }
.jal-modal-card::-webkit-scrollbar-track { background: transparent; }
.jal-modal-card::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* Botón cerrar */
.jal-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    line-height: 1;
}
.jal-modal-close:hover {
    background: rgba(0, 0, 0, 0.75);
}

/* Imagen principal */
.jal-modal-img-wrap {
    width: 100%;
    height: 360px;
    overflow: hidden;
    background: #f3f4f6;
    border-radius: 16px 16px 0 0;
    position: relative;
}
.jal-modal-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.jal-modal-img-wrap .jal-card-badge-op {
    top: 16px;
    left: 16px;
    font-size: 12px;
    padding: 5px 14px;
    border-radius: 6px;
}

/* Body del modal */
.jal-modal-body {
    padding: 24px 28px 28px;
}

/* Precio modal */
.jal-modal-price {
    font-size: 30px;
    font-weight: 800;
    color: #111827;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}
.jal-modal-price .currency {
    font-size: 16px;
    font-weight: 500;
    color: #374151;
}

/* Stats row */
.jal-modal-stats {
    display: flex;
    gap: 20px;
    font-size: 15px;
    color: #374151;
    margin-bottom: 16px;
    font-weight: 500;
}
.jal-modal-stats span {
    display: flex;
    align-items: center;
    gap: 6px;
}
.jal-modal-stats i,
.jal-modal-stats svg {
    color: #6b7280;
    font-size: 14px;
    width: 16px;
    height: 16px;
}

/* Divider */
.jal-modal-divider {
    border: none;
    border-top: 1px solid #f3f4f6;
    margin: 16px 0;
}

/* Título */
.jal-modal-title {
    font-family: 'Montserrat', sans-serif;
    font-size: 19px;
    font-weight: 700;
    color: #111827;
    line-height: 1.4;
    margin: 0 0 10px 0;
}

/* Dirección */
.jal-modal-address {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 13px;
    color: #6b7280;
    font-weight: 500;
    margin-bottom: 20px;
}
.jal-modal-address svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    margin-top: 1px;
}

/* Tipo de propiedad */
.jal-modal-tipo {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6b7280;
    background: #f3f4f6;
    padding: 4px 10px;
    border-radius: 4px;
    margin-bottom: 16px;
}

/* Botón CTA */
.jal-modal-cta {
    display: block;
    width: 100%;
    text-align: center;
    background: #1d4ed8;
    color: #fff;
    padding: 14px 20px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 700;
    text-decoration: none;
    transition: background 0.2s, transform 0.15s;
    border: none;
    cursor: pointer;
    letter-spacing: 0.01em;
    box-sizing: border-box;
}
.jal-modal-cta:hover {
    background: #1e40af;
    color: #fff;
    text-decoration: none;
    transform: translateY(-1px);
}

/* ── Carrusel interno del modal ── */
.jal-carousel-container {
    display: flex;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}
.jal-carousel-track {
    display: flex;
    width: 100%;
    height: 100%;
    transition: transform 0.35s ease;
}
.jal-carousel-slide {
    min-width: 100%;
    height: 100%;
}
.jal-carousel-slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
/* Flechas */
.jal-carousel-prev,
.jal-carousel-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    background: rgba(255,255,255,0.88);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 22px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #111827;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    transition: background 0.2s;
    padding: 0;
}
.jal-carousel-prev { left: 12px; }
.jal-carousel-next { right: 12px; }
.jal-carousel-prev:hover,
.jal-carousel-next:hover { background: #fff; }

/* Dots del carrusel */
.jal-carousel-indicators {
    position: absolute;
    bottom: 12px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 6px;
    z-index: 10;
}
.jal-carousel-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255,255,255,0.5);
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}
.jal-carousel-dot.active {
    background: #fff;
    transform: scale(1.25);
}

/* Responsive */
@media (max-width: 600px) {
    .jal-modal-card {
        width: 96vw;
        max-height: 94vh;
        border-radius: 12px;
    }
    .jal-modal-img-wrap {
        height: 240px;
        border-radius: 12px 12px 0 0;
    }
    .jal-modal-body {
        padding: 16px 18px 20px;
    }
    .jal-modal-price {
        font-size: 22px;
    }
    .jal-modal-title {
        font-size: 17px;
    }
}
