/* ==========================================================
   HC Inmobiliaria - MAPAS (Leaflet)
   Estilos compartidos por todos los mapas del sitio: controles,
   pines, clusters y popups. Las alturas de cada contenedor de
   mapa se definen en el CSS de su página (home/listing/detail/contact).
   Acá se usa !important solo para pisar estilos de Leaflet.
   ========================================================== */

/* Evitar que la regla global "img { max-width:100%; }" rompa los tiles de Leaflet */
.leaflet-container img {
    max-width: none !important;
}
.leaflet-container {
    width: 100% !important;
    font-family: var(--font-sans);
    background: #eef1f0;
}
.leaflet-container a:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ===================== CONTROLES ===================== */
/* Zoom (+ / −) */
.leaflet-bar,
.leaflet-touch .leaflet-bar {
    border: 1px solid var(--color-line) !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow) !important;
    background: var(--color-surface);
    overflow: hidden;
}
.leaflet-bottom.leaflet-right .leaflet-control-zoom { margin: 0 14px 14px 0 !important; }
.leaflet-top.leaflet-left .leaflet-control-zoom { margin: 14px 0 0 14px !important; }
.leaflet-bar a,
.leaflet-touch .leaflet-bar a {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 40px !important;
    height: 40px !important;
    line-height: 1 !important;
    background: var(--color-surface) !important;
    color: var(--color-ink) !important;
    border-bottom: 1px solid var(--color-line) !important;
    font-family: var(--font-sans) !important;
    font-size: 20px !important;
    font-weight: 500 !important;
    transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.leaflet-bar a:last-child { border-bottom: none !important; }
.leaflet-bar a:hover {
    background: var(--color-primary-light) !important;
    color: var(--color-primary-dark) !important;
}
.leaflet-bar a:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 3px rgba(var(--color-primary-rgb), 0.45);
}
.leaflet-bar a.leaflet-disabled {
    background: var(--color-surface-alt) !important;
    color: var(--color-line-strong) !important;
    cursor: default;
}

/* Créditos del mapa */
.leaflet-control-attribution {
    padding: 2px 8px;
    border-radius: var(--radius-sm) 0 0 0;
    background: rgba(255, 255, 255, 0.85);
    color: var(--color-text-light);
    font-size: 0.68rem;
}
.leaflet-control-attribution a { color: var(--color-text); }

/* ===================== PINES ===================== */
/* Gota con la punta exactamente en el punto de anclaje del ícono
   (iconSize 34x34, iconAnchor [17, 34]): el cuadrado gira sobre su
   esquina inferior izquierda, que queda en (17px, 34px). */
.map-pin {
    background: transparent;
    border: none;
}
.map-pin::before {                      /* sombra en el piso */
    content: '';
    position: absolute;
    left: 50%;
    bottom: -3px;
    width: 14px;
    height: 5px;
    margin-left: -7px;
    border-radius: 50%;
    background: rgba(20, 18, 16, 0.28);
    filter: blur(1.5px);
}
.map-pin__inner {
    position: absolute;
    left: 17px;
    top: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50% 50% 50% 0;
    border: 2px solid var(--color-white);
    background: var(--color-primary);
    box-shadow: 0 4px 10px rgba(var(--color-primary-rgb), 0.4);
    transform-origin: 0 100%;
    transform: rotate(-45deg);
    transition: transform var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.map-pin__inner i {
    transform: rotate(45deg);
    color: var(--color-white);
    font-size: 0.7rem;
}
.map-pin:hover .map-pin__inner {
    transform: rotate(-45deg) scale(1.12);
    background: var(--color-primary-dark);
}
.map-pin:focus-visible { outline: none; }
.map-pin:focus-visible .map-pin__inner {
    box-shadow: 0 0 0 3px var(--color-white), 0 0 0 6px rgba(var(--color-primary-rgb), 0.55);
}

/* ===================== CLUSTERS ===================== */
/* Halo suave de marca + círculo rojo con borde blanco */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
    background-color: rgba(var(--color-primary-rgb), 0.18);
    border-radius: 50%;
}
.marker-cluster-medium { background-color: rgba(var(--color-primary-rgb), 0.24); }
.marker-cluster-large { background-color: rgba(var(--color-primary-rgb), 0.3); }
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--color-primary-600);
    border: 2px solid var(--color-white);
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(var(--color-primary-rgb), 0.35);
    color: var(--color-white);
    font: 700 13px/1 var(--font-sans);
    transition: transform var(--dur-fast) var(--ease-out);
}
.marker-cluster span {
    line-height: 1;
    color: var(--color-white);
}
.marker-cluster:hover div { transform: scale(1.08); }

/* ===================== POPUPS ===================== */
.leaflet-popup-content-wrapper {
    padding: 0;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.leaflet-popup-content {
    font-family: var(--font-sans);
    font-size: var(--fs-sm);
    color: var(--color-ink);
}
.leaflet-popup-tip { box-shadow: 0 3px 8px rgba(20, 18, 16, 0.08); }

/* Popup de propiedad (index.php y propiedades.php, mismo markup):
   div.map-popup > img + h4 + div(ubicación) + div.price + a.btn */
.leaflet-popup-content:has(> .map-popup) { margin: 0; }
.map-popup {
    width: 240px;
    padding-bottom: 14px;
    font-family: var(--font-sans);
    color: var(--color-text);
}
.map-popup img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    margin: 0 0 12px;
    background: var(--color-surface-alt);
}
.map-popup h4 {
    margin: 0 14px 4px;
    font-size: 15px;
    font-weight: 600;
    line-height: var(--lh-snug);
    letter-spacing: -0.01em;
    color: var(--color-ink);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
}
/* Ubicación (tamaño y color vienen del style inline del template) */
.map-popup h4 + div {
    margin-left: 14px;
    margin-right: 14px;
    line-height: var(--lh-snug);
}
.map-popup h4 + div::before {
    content: "\f3c5";                   /* fa-location-dot */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    margin-right: 6px;
    font-size: 0.75rem;
    color: var(--color-primary);
}
.map-popup .price {
    margin: 6px 14px 12px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: var(--tracking-tight);
    color: var(--color-primary-600);
}
/* Botón "Ver detalle": siempre con texto blanco */
.leaflet-popup-content a.btn,
.map-popup a.btn {
    color: var(--color-white) !important;
    text-decoration: none;
}
.map-popup a.btn {
    display: flex;
    width: calc(100% - 28px);
    height: 40px;
    min-height: 40px;
    margin: 0 14px;
    padding: 0 16px;
    background: var(--color-primary-600);
    border-color: transparent;
    font-size: var(--fs-sm);
    font-weight: 600;
}
.map-popup a.btn:hover {
    background: var(--color-primary-dark);
    color: var(--color-white) !important;
    transform: none;
}

/* Botón de cerrar: círculo blanco sobre la foto */
.leaflet-popup:has(.map-popup) a.leaflet-popup-close-button {
    top: 8px;
    right: 8px;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow-sm);
    color: var(--color-ink);
    font: 400 20px/1 var(--font-sans);
}
.leaflet-popup:has(.map-popup) a.leaflet-popup-close-button:hover {
    background: var(--color-white);
    color: var(--color-primary-dark);
}

/* ===================== MOVIMIENTO REDUCIDO ===================== */
@media (prefers-reduced-motion: reduce) {
    .map-pin__inner,
    .marker-cluster-small div,
    .marker-cluster-medium div,
    .marker-cluster-large div,
    .leaflet-bar a { transition: none !important; }
    .map-pin:hover .map-pin__inner { transform: rotate(-45deg); }
    .marker-cluster:hover div { transform: none; }
}
