/**
 * AddiListo — archive List | Map view.
 * Mobile-first. Leaflet + marker clustering are lazy-loaded by map-view.js
 * only when the visitor first opens the map, so the list view pays nothing.
 */

/* Toolbar holds the sort control and the view toggle on opposite ends. */
.apl-archive__toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

/* Segmented List | Map control. */
.apl-viewtoggle {
    display: inline-flex;
    background: var(--apl-bg-2, #f1f5f9);
    border: 1px solid var(--apl-line, #e2e8f0);
    border-radius: 999px;
    padding: 3px;
    gap: 2px;
}
.apl-viewtoggle__btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 0;
    background: transparent;
    color: var(--apl-ink, #0f172a);
    font: inherit;
    font-weight: 600;
    font-size: 13px;
    line-height: 1;
    padding: 8px 14px;
    border-radius: 999px;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.apl-viewtoggle__btn svg { width: 16px; height: 16px; }
.apl-viewtoggle__btn:hover { color: var(--apl-primary-aa, #4338ca); }
.apl-viewtoggle__btn.is-active {
    background: var(--apl-primary, #4f46e5);
    color: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .12);
}
.apl-viewtoggle__btn:focus-visible {
    outline: 2px solid var(--apl-primary, #4f46e5);
    outline-offset: 2px;
}

/* View switching: when the results are in map mode, hide the list bits. */
.apl-archive__results[data-view="map"] .apl-grid,
.apl-archive__results[data-view="map"] .apl-skel-grid,
.apl-archive__results[data-view="map"] .apl-pagination,
.apl-archive__results[data-view="map"] .apl-sort { display: none; }

/* Map container. */
.apl-mapview {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}
.apl-mapview[hidden] { display: none; }
.apl-mapview__canvas {
    width: 100%;
    height: 68vh;
    min-height: 460px;
    max-height: 820px;
    border-radius: var(--apl-radius, 14px);
    overflow: hidden;
    border: 1px solid var(--apl-line, #e2e8f0);
    background: var(--apl-bg-2, #f1f5f9);
    z-index: 0;
}
.apl-mapview__canvas.is-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--apl-muted, #64748b);
    font-weight: 600;
}
.apl-mapview__hint {
    margin: 0;
    font-size: 13px;
    color: var(--apl-muted, #64748b);
    text-align: center;
}

/* Price-pill markers (a DivIcon) — nicer than a bare pin. */
.apl-pin {
    background: none;
    border: 0;
}
.apl-pin__label {
    display: inline-block;
    transform: translate(-50%, -100%);
    white-space: nowrap;
    background: var(--apl-primary-aa, #4338ca);
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    line-height: 1;
    padding: 7px 10px;
    border-radius: 999px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, .28);
    position: relative;
    transition: transform .1s ease, background .1s ease;
}
.apl-pin__label::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--apl-primary-aa, #4338ca);
}
.leaflet-marker-icon.apl-pin:hover .apl-pin__label,
.leaflet-marker-icon.apl-pin:focus .apl-pin__label {
    background: var(--apl-primary, #4f46e5);
}

/* Popup card. */
.apl-mappop { display: grid; gap: 4px; min-width: 172px; }
.apl-mappop__img { width: 100%; height: 96px; object-fit: cover; border-radius: 8px; background: var(--apl-bg-2, #f1f5f9); }
.apl-mappop__price { font-size: 15px; font-weight: 800; color: var(--apl-ink, #0f172a); }
.apl-mappop__title { font-size: 13px; color: var(--apl-ink, #0f172a); font-weight: 600; }
.apl-mappop__loc { font-size: 12px; color: var(--apl-muted, #64748b); }
.apl-mappop__link { font-weight: 700; color: var(--apl-primary-aa, #4338ca); text-decoration: none; margin-top: 2px; }
.apl-mappop__link:hover { text-decoration: underline; }
.leaflet-popup-content { margin: 10px 12px; }
.leaflet-popup-content-wrapper { border-radius: 12px; }

/* Cluster bubble tinting to the brand. !important + the .leaflet-container
   scope beat MarkerCluster.Default.css, which is lazy-loaded AFTER this file
   and would otherwise win on equal specificity with its default green. */
.leaflet-container .marker-cluster-small,
.leaflet-container .marker-cluster-medium,
.leaflet-container .marker-cluster-large {
    background: color-mix(in srgb, var(--apl-primary, #4f46e5) 25%, transparent) !important;
}
.leaflet-container .marker-cluster-small div,
.leaflet-container .marker-cluster-medium div,
.leaflet-container .marker-cluster-large div {
    background: var(--apl-primary, #4f46e5) !important;
    color: #fff !important;
    font-weight: 800;
}

/* Phones: taller, edge-to-edge feel, clear of the bottom tab bar. */
@media (max-width: 782px) {
    .apl-viewtoggle__btn { padding: 9px 16px; font-size: 14px; }
    .apl-mapview__canvas {
        height: calc(100dvh - 230px);
        min-height: 380px;
        border-radius: var(--apl-radius, 14px);
    }
    /* Keep the toggle reachable while panning the map. */
    .apl-archive__results[data-view="map"] .apl-archive__toolbar {
        position: sticky;
        top: 0;
        z-index: 6;
        background: var(--apl-bg, #fff);
        padding: 8px 0;
    }
}
