/* House Finder — Map View Styles */

/* Override container max-width for map page */
body:has(.map-layout) main.container {
    max-width: 100%;
    padding: 0;
}

body:has(.map-layout) .footer {
    display: none;
}

/* Filter bar */
.map-filters-bar {
    background: var(--card-bg);
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.map-filters-bar .filters-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: end;
}

/* Split layout */
.map-layout {
    display: flex;
    height: calc(100vh - 110px);
    overflow: hidden;
    padding: 0.75rem 1rem 1rem;
    gap: 1rem;
}

.map-sidebar {
    width: 375px;
    min-width: 375px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
}

.map-sidebar-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--card-bg);
    font-size: 0.85rem;
}

.map-listing-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.map-container {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

/* Listing cards in sidebar */
.map-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-bottom: 0.5rem;
    transition: box-shadow 0.2s, border-color 0.2s;
    border: 2px solid transparent;
    cursor: pointer;
}

.map-card:hover {
    box-shadow: var(--shadow-md);
}

.map-card-active {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary), var(--shadow-md);
}

.map-card-nocoords {
    opacity: 0.6;
}

.map-card-link {
    display: flex;
    text-decoration: none;
    color: inherit;
}

.map-card-image {
    width: 120px;
    min-height: 100px;
    flex-shrink: 0;
    position: relative;
    background: var(--border);
}

.map-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.map-card-image .no-image {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: 2rem;
    color: var(--text-muted);
}

.map-card-info {
    padding: 0.5rem 0.75rem;
    flex: 1;
    min-width: 0;
}

.map-card-title {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 0.25rem;
}

.map-card-price {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

.map-card-details {
    display: flex;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

.map-card-address {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Price markers on map */
.price-marker {
    background: none;
    border: none;
}

.price-marker-label {
    background: var(--card-bg);
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    border: 1.5px solid var(--text);
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    transition: background 0.15s, color 0.15s, transform 0.15s;
    transform-origin: center;
}

.price-marker-group .price-marker-label {
    padding-right: 0.3rem;
}

.price-marker-expanded .price-marker-label {
    border-color: var(--primary);
    box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}

.price-marker-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.3rem;
    height: 1.3rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: var(--text);
    color: #fff;
    font-size: 0.7rem;
    line-height: 1;
}

.marker-highlight .price-marker-label {
    background: var(--text);
    color: white;
    transform: scale(1.15);
}

.marker-highlight .price-marker-count {
    background: white;
    color: var(--text);
}

/* Map popups */
.map-popup {
    font-size: 0.85rem;
    line-height: 1.4;
}

.map-popup-img {
    width: 100%;
    max-height: 140px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.map-popup-price {
    font-weight: 700;
    color: var(--primary);
}

.map-popup a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.map-popup a:hover {
    text-decoration: underline;
}

/* === Desktop-only elements hidden on mobile === */
.mobile-filter-btn,
.mobile-filter-header,
.mobile-sheet-handle,
.mobile-preview {
    display: none;
}

.desktop-only {
    display: inline-flex;
}

/* Responsive — Airbnb-style mobile map */
@media (max-width: 768px) {

    .desktop-only { display: none !important; }

    /* ── Navbar compact ── */
    body:has(.map-layout) .navbar {
        padding: 0.5rem 0;
    }

    /* ── Filter bar → fullscreen overlay ── */
    .map-filters-bar {
        position: fixed;
        inset: 0;
        z-index: 2000;
        background: var(--bg);
        padding: 0;
        border: none;
        box-shadow: none;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        pointer-events: none;
    }
    .map-filters-bar.mobile-active {
        transform: translateY(0);
        pointer-events: auto;
    }

    .mobile-filter-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--border);
        background: var(--card-bg);
        flex-shrink: 0;
    }
    .mobile-filter-title {
        font-weight: 700;
        font-size: 1.1rem;
    }
    .mobile-filter-close {
        background: none;
        border: none;
        font-size: 1.6rem;
        cursor: pointer;
        padding: 0.25rem 0.5rem;
        color: var(--text);
        line-height: 1;
    }
    .mobile-filter-apply {
        font-size: 0.85rem;
        padding: 0.4rem 1rem;
    }

    .map-filters-bar .filters-form {
        flex-direction: column;
        padding: 1rem;
        gap: 1rem;
    }
    .map-filters-bar .filter-group {
        width: 100%;
    }
    .map-filters-bar .filter-group label {
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
        display: block;
    }
    .map-filters-bar .filter-group input[type="number"] {
        width: 100%;
        padding: 0.6rem 0.75rem;
        font-size: 1rem;
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }

    /* ── Floating filter button ── */
    .mobile-filter-btn {
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        position: fixed;
        top: 52px;
        right: 0.75rem;
        z-index: 900;
        background: var(--card-bg);
        border: 1px solid var(--border);
        border-radius: 999px;
        padding: 0.4rem 0.85rem;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15);
        font-size: 0.8rem;
        font-weight: 600;
        cursor: pointer;
        color: var(--text);
    }
    .mobile-filter-btn:active {
        background: var(--border);
    }
    .mobile-filter-btn svg {
        flex-shrink: 0;
    }

    /* ── Fullscreen map ── */
    .map-layout {
        position: fixed;
        inset: 0;
        top: 44px;
        height: auto;
        padding: 0;
        gap: 0;
        display: block;
    }

    .map-container {
        width: 100%;
        height: 100%;
        border: none;
        border-radius: 0;
    }

    /* ── Sidebar → Bottom sheet ── */
    .map-sidebar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        min-width: 0;
        max-height: none;
        height: 52px;
        z-index: 1000;
        border: none;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -2px 12px rgba(0,0,0,0.12);
        background: var(--card-bg);
        transition: height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
    }
    .map-sidebar.mobile-expanded {
        height: 85vh;
    }

    .map-sidebar-header {
        padding: 0;
        cursor: pointer;
        -webkit-user-select: none;
        user-select: none;
        display: flex;
        flex-direction: column;
        align-items: center;
        border-bottom: none;
    }
    .map-sidebar.mobile-expanded .map-sidebar-header {
        border-bottom: 1px solid var(--border);
    }

    .mobile-sheet-handle {
        display: flex;
        justify-content: center;
        padding: 8px 0 4px;
        width: 100%;
    }
    .handle-pill {
        width: 36px;
        height: 4px;
        border-radius: 2px;
        background: #ccc;
    }

    .map-sidebar-header .badge {
        font-size: 0.8rem;
        padding-bottom: 6px;
    }

    .map-listing-list {
        padding: 0.5rem;
        -webkit-overflow-scrolling: touch;
    }

    /* ── Mobile preview card (on marker tap) ── */
    .mobile-preview {
        display: none;
        position: fixed;
        bottom: 60px;
        left: 0.5rem;
        right: 0.5rem;
        z-index: 999;
        background: var(--card-bg);
        border-radius: var(--radius);
        box-shadow: 0 4px 16px rgba(0,0,0,0.18);
        overflow: hidden;
        animation: slideUpPreview 0.25s ease;
    }
    .mobile-preview.visible {
        display: block;
    }

    @keyframes slideUpPreview {
        from { transform: translateY(20px); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }

    .mobile-preview-link {
        display: flex;
        text-decoration: none;
        color: inherit;
        gap: 0;
    }
    .mobile-preview-img {
        width: 90px;
        height: 80px;
        flex-shrink: 0;
        background: var(--border);
        overflow: hidden;
    }
    .mobile-preview-img img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
    .mobile-preview-img .no-image {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100%;
        font-size: 1.5rem;
    }
    .mobile-preview-info {
        padding: 0.5rem 0.75rem;
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    .mobile-preview-price {
        font-weight: 700;
        font-size: 0.95rem;
        color: var(--primary);
    }
    .mobile-preview-title {
        font-size: 0.8rem;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .mobile-preview-details {
        font-size: 0.75rem;
        color: var(--text-muted);
    }
    .mobile-preview-close {
        position: absolute;
        top: 4px;
        right: 6px;
        background: rgba(0,0,0,0.5);
        color: #fff;
        border: none;
        border-radius: 50%;
        width: 22px;
        height: 22px;
        font-size: 14px;
        line-height: 1;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* ── Leaflet tweaks for mobile ── */
    .leaflet-control-zoom {
        margin-right: 10px !important;
        margin-top: 50px !important;
    }

    /* Hide popups on mobile (we use preview card instead) */
    .leaflet-popup {
        display: none !important;
    }
}
