/* === HOME ADS GRID & MAP === */
/* Map View Container */
.map-view-container {
    width: 100%;
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    height: calc(100vh - 140px);
    /* Tall as the banner */
}


/* Ads Grid Default */
.ads-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}

.ad-card {
    background-color: var(--bg-card);
    /* Now strictly dark again */
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.05);
    /* Adjusted for dark background */
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    /* Subtle shadow */
    position: relative;
    display: flex;
    flex-direction: column;
}

.ad-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4), var(--shadow-glow);
    border-color: rgba(236, 72, 153, 0.4);
}

.ad-image {
    position: relative;
    width: 100%;
    aspect-ratio: 3/4;
    overflow: hidden;
}

.ad-image::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40%;
    background: linear-gradient(to top, rgba(24, 34, 53, 1) 0%, rgba(24, 34, 53, 0) 100%);
    pointer-events: none;
}

.ad-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s ease;
}

.ad-card:hover .ad-image img {
    transform: scale(1.08);
}

/* Ads List View Modifiers */
.ads-grid.list-view {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ads-grid.list-view .ad-card {
    flex-direction: row;
    height: auto;
    min-height: 320px;
    /* Flexible height for horizontal cards to prevent content squashing */
}

.ads-grid.list-view .ad-card:hover {
    transform: translateX(4px) translateY(-4px);
    /* Slightly different hover for list */
}

.ads-grid.list-view .ad-image {
    width: 400px;
    flex: 0 0 400px;
    /* Doubled from before */
    margin-bottom: 0;
    aspect-ratio: auto;
    flex-shrink: 0;
}

.ads-grid.list-view .ad-image::after {
    /* Gradient from right to left instead of bottom to top to fade image into card details */
    height: 100%;
    width: 100%;
    background: linear-gradient(to left, rgba(24, 34, 53, 1) 0%, rgba(24, 34, 53, 0) 100%);
    display: none;
    /* No gradient over image in list view requested */
}

/* Hide Grid elements in List View */
.ads-grid.list-view .fav-btn,
.ads-grid.list-view .grid-view-only {
    display: none !important;
}

/* Hide List elements in Grid View */
.list-view-extra {
    display: none;
}

/* Show and style List elements in List View */
.ads-grid.list-view .list-view-extra {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    width: 100%;
    margin-top: 32px;
    /* Increased from 8px to push content down */
}

/* Detailed styling for List View Extra */
.list-source-info,
.list-date-info {
    font-size: 0.95rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
}

.list-source-info {
    margin-top: 16px;
    margin-bottom: 8px;
}

.list-source-info span,
.list-date-info span {
    font-weight: 500;
}

.list-date-info strong {
    color: var(--text-main);
    font-weight: 600;
}

.list-source-logo {
    height: 36px;   /* Come sopra, previene il collasso a 0x0 degli SVG */
    max-width: 200px;
    object-fit: contain;
}

.list-categories {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
}

.cat-tag {
    padding: 6px 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.05);
    /* very subtle grey */
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
}

.cat-tag:hover {
    background: rgba(236, 72, 153, 0.1);
    border-color: var(--accent-pink);
    color: var(--accent-pink);
}

.long-fav-btn {
    margin-top: auto;
    /* Pushes to bottom of the card */
    background: rgba(236, 72, 153, 0.1);
    /* Pinkish tint */
    border: 1px solid var(--accent-pink);
    color: var(--text-main);
    padding: 12px 24px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
}

.long-fav-btn img {
    width: 20px;
    height: 20px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.long-fav-btn:hover {
    background: var(--accent-pink-hover);
    box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
    transform: translateY(-2px);
}

.ads-grid.list-view .ad-details {
    padding: 24px 32px;
    margin-top: 0;
    position: static;
    /* Overrides the grid absolute positioning */
    height: 100%;
    flex: 1;
    /* Stretch to fill available row width */
    justify-content: flex-start;
    align-items: stretch;
    /* Allow children to take full width */
}

.ads-grid.list-view .ad-meta {
    margin-top: auto;
    padding-top: 16px;
    width: 100%;
}

.ads-grid.list-view .ad-title {
    display: block;
    /* Overrides clamp */
    font-size: 1.25rem;
    margin-bottom: 12px;
    flex-shrink: 0;
    /* Prevents flexbox from squishing the title height */
    overflow: visible;
    text-align: center;
    /* Centers the title as requested */
}

.ads-grid.list-view .ad-meta {
    width: 100%;
}

@media (max-width: 1530px) and (min-width: 1388px),
(max-width: 1200px) {
    .ads-grid.list-view .ad-image {
        width: auto;
        flex: 1 1 120px;
        /* Allow shrinking */
    }

    .ads-grid.list-view .ad-details {
        width: 400px;
        flex: 0 0 400px;
        /* Lock text column so it doesn't squeeze */
    }
}

/* Floating Actions in Card */
.fav-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(11, 15, 25, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 2;
}

.fav-btn img {
    width: 22px;
    height: 22px;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
    transition: transform 0.3s;
}

.fav-btn:hover {
    background: rgba(236, 72, 153, 0.15);
    border-color: var(--accent-pink);
    transform: scale(1.15);
}

.fav-btn:active {
    transform: scale(0.95);
}

.fav-btn.active {
    background: var(--accent-pink);
    border-color: var(--accent-pink);
}

.fav-btn.active img {
    filter: brightness(0) invert(1);
    transform: scale(1.1);
}

.long-fav-btn.active {
    background: var(--accent-pink);
    color: white;
}

.long-fav-btn.active img {
    filter: brightness(0) invert(1);
}

.source-badge {
    /* Now positioned inside ad-meta flex container */
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    padding: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    /* Align right within its space */
    height: auto;
}

.source-badge img {
    height: 24px;   /* Forza l'altezza vitale per SVG privi di dimensioni intrinseche */
    max-width: 90px;
    object-fit: contain;
}

.ad-details {
    padding: 0 20px 20px;
    position: absolute;
    bottom: 0;
    width: 100%;
    z-index: 3;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.ad-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 12px;
    line-height: 1.4;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
    display: -webkit-box;
    line-clamp: 2;
    /* standard property */
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ad-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
}

.ad-meta .date i {
    color: var(--accent-pink);
    margin-right: 6px;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
    padding: 20px 0 40px;
}

.page-btn {
    background: #182235;
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.05);
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    font-size: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.page-btn.active {
    background: linear-gradient(135deg, var(--accent-pink), var(--accent-pink-hover));
    border-color: transparent;
    color: white;
    box-shadow: 0 4px 12px rgba(236, 72, 153, 0.3);
}

.page-btn:hover:not(.disabled):not(.active) {
    background: var(--hover-card);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.page-btn.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: rgba(24, 34, 53, 0.4);
}

.page-dots {
    display: flex;
    align-items: flex-end;
    padding-bottom: 10px;
    color: var(--text-main);
    font-weight: bold;
    letter-spacing: 2px;
}


@media (max-width: 850px) {
    /* Mosaico (Mobile replacement for Grid) */
    .ads-grid {
        gap: 1px !important;
        background-color: rgba(255, 255, 255, 0.15) !important;
        border: 1px solid rgba(255, 255, 255, 0.15) !important;
        border-left: none !important;
        border-right: none !important;
        border-top: none !important;
        border-bottom: none !important;
    }

    .ad-card {
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
    }

    .ad-card:hover {
        transform: none !important;
        background-color: #1e293b !important;
    }

    .pagination {
        padding-top: 8px !important;
        margin-top: 0 !important;
        padding-bottom: 32px !important;
    }

    /* Tinder (Decoupled Mobile view) */
    .ads-grid.tinder-view {
        display: flex;
        /* REMOVED !important to let JS hide operation work! */
        flex-direction: column !important;
        align-items: center !important;
        gap: 24px !important;
        background: transparent !important;
        border: none !important;
        padding: 16px !important;
        /* Full padding around Tinder */
    }

    .ads-grid.tinder-view .ad-card {
        width: 100% !important;
        max-width: 480px !important;
        border-radius: 20px !important;
        border: 1px solid rgba(255, 255, 255, 0.05) !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
        position: relative;
    }

    /* Stretch details to full height to overlay the title at the top */
    .ads-grid.tinder-view .ad-details {
        height: 100% !important;
        top: 0 !important;
        bottom: 0 !important;
        justify-content: flex-end !important;
        background: linear-gradient(to top, rgba(24, 34, 53, 1) 0%, rgba(24, 34, 53, 0.95) 80px, rgba(24, 34, 53, 0) 220px) !important;
    }

    /* Pin the title to the upper border with its own background shadow */
    .ads-grid.tinder-view .ad-title {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        padding: 24px 20px !important;
        text-align: center !important;
        margin: 0 !important;
        background: linear-gradient(to bottom, rgba(11, 15, 25, 0.95) 0%, rgba(11, 15, 25, 0) 100%) !important;
        font-size: 1.35rem !important;
        z-index: 10 !important;
    }

    /* Move and enlarge the Favorites button even more */
    .ads-grid.tinder-view .fav-btn {
        top: auto !important;
        right: auto !important;
        bottom: 72px !important;
        /* Slightly lower as requested */
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 65px !important;
        /* Considerably bigger primary action */
        height: 65px !important;
        z-index: 15 !important;
    }

    .ads-grid.tinder-view .fav-btn img {
        width: 32px !important;
        /* Scaled icon inside */
        height: 32px !important;
    }

    .ads-grid.tinder-view .fav-btn:hover {
        transform: translateX(-50%) scale(1.15) !important;
    }

    .ads-grid.tinder-view .fav-btn:active {
        transform: translateX(-50%) scale(0.95) !important;
    }

    /* Map Edge-To-Edge and Borderless Mobile */
    .map-view-container iframe,
    #mapViewContainer iframe {
        border-radius: 0 !important;
        border: none !important;
        display: block !important;
    }

    .map-view-container,
    #mapViewContainer {
        border-radius: 0 !important;
        border: none !important;
        height: 100vh !important;
        /* Ensure it strictly fills available space */
        min-height: calc(100vh - 116px) !important;
        /* Force to cover header drop */
    }
}

@media (max-width: 600px) {
    .ads-grid.tinder-view .ad-card {
        border-radius: 16px !important;
    }
}

/* Mosaico Column Control (Strictly 2 to 4) */
@media (max-width: 850px) {
    .ads-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

@media (max-width: 700px) {
    .ads-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

@media (max-width: 500px) {
    .ads-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 450px) {
    .filter-select {
        width: 44px;
        min-width: 44px;
        padding: 10px;
        color: transparent;
        /* hides text securely while keeping functionality */
        background-image: none;
        /* removes the dropdown arrow */
    }

    .filter-select option {
        color: var(--text-main);
        /* Ensures options menu string is visible natively when opened */
    }

    .filter-group {
        flex: 0 0 44px;
        /* lock size */
    }

    .filter-icon {
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
    }
}

/* ========================================================================== */
/* LEAFLET MAP CUSTOM PIN & TOOLTIP STYLES */
/* (Styles moved to common.css for shared usage with single ad map) */
/* ========================================================================== */

#leafletMap {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    z-index: 1;
    background-color: #1e293b;
}
.leaflet-tooltip.mami-tooltip-rich {
    padding: 6px;
    /* Added breathing room globally */
    overflow: hidden;
    width: 250px;
    /* Slightly wider to accommodate gaps */
    white-space: normal;
    /* Allow title to wrap */
}

.map-preview-card {
    display: flex;
    flex-direction: row;
    /* Thumbnail layout */
    align-items: center;
    gap: 12px;
    /* Margin between the thumbnail and text block */
    margin: 0;
}

.map-preview-img {
    width: 76px;
    /* Resized gently for spacing */
    height: 76px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    /* Subtle framing */
    display: block;
    flex-shrink: 0;
}

.map-preview-info {
    padding: 4px 6px 4px 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 0;
    /* allows text truncation */
}

.map-preview-title {
    font-size: 0.90rem;
    /* Slightly smaller for the compact row layout */
    font-weight: 600;
    line-height: 1.3;
    color: white;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    /* Standard property for lint completeness */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-align: left;
}

.map-preview-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.map-preview-date {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ========================================================================== */
