/**
 * Sokna Ads - Responsive Ad Display
 *
 * CSS media queries for desktop/mobile image switching.
 * Grid alignment so in-grid ads match property card dimensions.
 * image-rendering for crisp display.
 *
 * @package Sokna
 * @since 1.0.0
 */

.sokna-ad-section,
.sokna-ad-slot {
    margin: 0;
    padding: 0;
}

.sokna-ad-section--home {
    padding: 24px 0;
    background: var(--color-gray-100, #F5F5F5);
}

/* Slim desktop banner container: 1200x120 or 1200x150 - minimal vertical space */
.sokna-ad-slot--home-after-hero,
.sokna-ad-section--home .sokna-ad-slot:not(.sokna-ad-slot--300x250) {
    max-width: 1200px;
    margin-inline: auto;
}

.sokna-ad-slot--home-after-hero .sokna-ad-inner,
.sokna-ad-section--home .sokna-ad-slot:not(.sokna-ad-slot--300x250) .sokna-ad-inner {
    max-height: 150px;
}

@media (min-width: 768px) {
    .sokna-ad-slot--home-after-hero .sokna-ad-img--desktop,
    .sokna-ad-section--home .sokna-ad-slot .sokna-ad-img--desktop {
        max-height: 150px;
        min-height: 120px;
        object-fit: cover;
    }
}

.sokna-ad-wrapper,
.sokna-ad-slot .sokna-ad-inner {
    display: block;
    max-width: 100%;
}

/* Wrapper for device-separate links: one <a> for desktop, one for mobile */
.sokna-ad-wrapper {
    display: block;
}
.sokna-ad-wrapper .sokna-ad-cta {
    display: block;
    text-decoration: none;
}

.sokna-ad-cta {
    display: block;
    text-decoration: none;
    border-radius: 4px;
    overflow: hidden;
    transition: opacity 0.2s;
}

.sokna-ad-cta:hover {
    opacity: 0.92;
}

.sokna-ad-inner {
    display: block;
    position: relative;
}

/* Crisp image rendering - fixes blurriness; strict dimensions without stretch */
.sokna-ad-img,
.sokna-ad-container img,
.sokna-ad-cta img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    object-fit: cover !important;
}

/* Desktop image: desktop-only (d-none d-md-block), object-fit cover */
.sokna-ad-img--desktop {
    display: none;
    width: 100%;
    height: auto;
    object-fit: cover;
}

@media (min-width: 768px) {
    .sokna-ad-img--desktop {
        display: block;
    }
}

/* Mobile image: mobile-only (d-block d-md-none), object-fit cover */
.sokna-ad-img--mobile {
    display: block;
    width: 100%;
    height: auto;
    object-fit: cover;
}

@media (min-width: 768px) {
    .sokna-ad-img--mobile {
        display: none;
    }
}

/* When only one image: show everywhere */
.sokna-ad-img--all {
    display: block !important;
}

/* Ad slot in listing grid: legacy full-width (non grid-item) */
.sokna-archive__grid .sokna-ad-slot:not(.sokna-ad-slot--grid-item) {
    grid-column: 1 / -1;
}

/* ============================================
   300x250 AD UNIT - Unified banner (mobile used on desktop)
   Home bottom grid & Search in-grid zones
   ============================================ */
.sokna-ad-300x250 {
    width: 300px;
    height: 250px;
    margin: 0 auto;
    display: block;
    overflow: hidden;
    border-radius: 8px;
}

.sokna-ad-300x250 .sokna-ad-cta,
.sokna-ad-300x250 .sokna-ad-cta--300x250 {
    display: block;
    width: 100%;
    height: 100%;
}

.sokna-ad-300x250 img,
.sokna-ad-img--300x250,
.sokna-ad-slot--300x250 .sokna-ad-cta img,
.sokna-ad-slot--300x250 .sokna-ad-inner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* ============================================
   IN-GRID AD SLOT - 367×250 native (matches property card height)
   ============================================ */
.sokna-ad-slot--grid-item.sokna-ad-slot--300x250 {
    grid-column: auto;
    min-height: 250px;
    width: 100%;
    max-width: 367px;
    margin: 0 auto;
    border-radius: 10px;
    overflow: hidden;
    background: #f1f5f9;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
}

.sokna-ad-slot--grid-item.sokna-ad-slot--300x250 .sokna-ad-300x250 {
    width: 100%;
    max-width: 367px;
    height: 250px;
}

.sokna-ad-slot--grid-item.sokna-ad-slot--300x250 .sokna-ad-cta,
.sokna-ad-slot--grid-item.sokna-ad-slot--300x250 .sokna-ad-placeholder {
    min-height: 250px;
    border-radius: 10px;
}

/* Search: top ad - full-width desktop, 300x250 mobile */
.sokna-archive__top-ad {
    margin-bottom: 32px;
    width: 100%;
}

.sokna-archive__top-ad .sokna-ad-slot {
    max-width: 100%;
}

.sokna-archive__top-ad--responsive {
    width: 100%;
    max-width: 100%;
}

@media (max-width: 767px) {
    .sokna-archive__top-ad--responsive {
        width: 300px;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
        overflow: hidden;
        border-radius: 8px;
    }

    .sokna-archive__top-ad--responsive .sokna-ad-slot {
        width: 300px;
        height: 250px;
        margin: 0 auto;
        overflow: hidden;
    }

    .sokna-archive__top-ad--responsive .sokna-ad-slot .sokna-ad-cta,
    .sokna-archive__top-ad--responsive .sokna-ad-slot .sokna-ad-inner {
        display: block;
        width: 100%;
        height: 250px;
    }

    .sokna-archive__top-ad--responsive .sokna-ad-slot img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        image-rendering: -webkit-optimize-contrast;
    }

    .sokna-archive__top-ad--responsive .sokna-ad-placeholder {
        min-height: 250px;
        width: 300px;
        height: 250px;
    }

    .sokna-archive__top-ad--responsive .sokna-ad-placeholder__link {
        min-height: 250px;
    }
}

/* ============================================
   HOME 3-SLOT GRID - Below properties
   Sync with Premium property cards: same width/height per slot, same row alignment
   ============================================ */
.sokna-ad-grid-3 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 28px;
    width: 100%;
}

@media (min-width: 768px) {
    .sokna-ad-grid-3 {
        grid-template-columns: repeat(2, 1fr);
        gap: 32px;
    }
}

@media (min-width: 1024px) {
    .sokna-ad-grid-3 {
        grid-template-columns: repeat(3, 1fr);
        gap: 36px;
    }
}

.sokna-ad-grid-3__slot {
    display: flex;
    align-items: stretch;
    justify-content: center;
    min-height: 250px;
}

.sokna-ad-grid-3__slot .sokna-ad-300x250,
.sokna-ad-grid-3__slot .sokna-ad-placeholder--300x250 {
    width: 100%;
    max-width: 100%;
    height: 250px;
    min-height: 250px;
    border-radius: 10px;
    overflow: hidden;
}

.sokna-ad-grid-3__slot .sokna-ad-300x250 img,
.sokna-ad-grid-3__slot .sokna-ad-300x250 .sokna-ad-cta img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

.sokna-ad-grid-3__slot .sokna-ad-placeholder--300x250 .sokna-ad-placeholder__link {
    min-height: 250px;
    height: 250px;
}

/* Mobile (max-width: 767px): full width, 250px height to match native format */
@media (max-width: 767px) {
    .sokna-ad-grid-3 {
        display: block !important;
        width: 100%;
    }

    .sokna-ad-grid-3__slot,
    .sokna-ad-grid-3 .ad-slot {
        width: 100% !important;
        max-width: none !important;
        margin-bottom: 20px;
        min-height: 250px;
    }

    .sokna-ad-grid-3__slot:last-child,
    .sokna-ad-grid-3 .ad-slot:last-child {
        margin-bottom: 0;
    }

    .sokna-ad-grid-3__slot .sokna-ad-300x250,
    .sokna-ad-grid-3__slot .sokna-ad-placeholder--300x250,
    .sokna-ad-grid-3 .ad-slot .sokna-ad-300x250,
    .sokna-ad-grid-3 .ad-slot .sokna-ad-placeholder--300x250 {
        width: 100% !important;
        max-width: none !important;
        height: 250px !important;
        min-height: 250px !important;
        margin: 0 !important;
        border-radius: 8px;
        overflow: hidden;
    }

    .sokna-ad-grid-3__slot .sokna-ad-300x250 img,
    .sokna-ad-grid-3__slot .sokna-ad-300x250 .sokna-ad-cta img,
    .sokna-ad-grid-3 .ad-slot img {
        width: 100% !important;
        height: 250px !important;
        object-fit: cover !important;
        object-position: center;
        border-radius: 8px;
    }

    .sokna-ad-grid-3__slot .sokna-ad-placeholder--300x250 .sokna-ad-placeholder__link,
    .sokna-ad-grid-3 .ad-slot .sokna-ad-placeholder__link {
        min-height: 250px;
        height: 250px;
        border-radius: 8px;
    }
}

/* ============================================
   AD TYPES - Agreed dimensions (strict, no stretch)
   large_banner, grid, skyscraper, small_promo
   ============================================ */
.sokna-ad--large_banner .sokna-ad-inner,
.sokna-ad--large_banner .sokna-ad-cta img {
    max-height: 150px;
    object-fit: cover !important;
}
@media (min-width: 768px) {
    .sokna-ad--large_banner .sokna-ad-inner,
    .sokna-ad--large_banner .sokna-ad-cta img {
        max-height: 160px;
        object-fit: cover !important;
    }
}

.sokna-ad--small_promo .sokna-ad-inner,
.sokna-ad--small_promo .sokna-ad-cta img {
    max-height: 50px;
    object-fit: cover !important;
}
@media (min-width: 768px) {
    .sokna-ad--small_promo .sokna-ad-inner,
    .sokna-ad--small_promo .sokna-ad-cta img {
        max-height: 90px;
        object-fit: cover !important;
    }
}

/* Grid Ad: 367×250 — native format, matches .property-card-img height */
.sokna-ad--aspect-4-5,
.sokna-ad--grid .sokna-ad-inner {
    overflow: hidden;
}
.sokna-ad--grid .sokna-ad-inner {
    width: 100%;
    height: 250px;
}
.sokna-ad--aspect-4-5 img,
.sokna-ad--grid .sokna-ad-cta img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

/* Native grid banner: isolate from property cards; fixed 250px to match property-card-img */
.sokna-ad-banner--native-grid {
    display: block;
    width: 100%;
    height: 250px !important;
    min-height: 250px !important;
    max-height: 250px !important;
    overflow: hidden;
    border-radius: 4px;
}
.sokna-ad-banner--native-grid .sokna-ad-inner,
.sokna-ad-banner--native-grid .sokna-ad-cta {
    display: block;
    width: 100%;
    height: 250px !important;
    min-height: 250px !important;
}
.sokna-ad-banner--native-grid img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center;
}

/* Skyscraper: 300×600 desktop only; mobile hidden via rule below */
.sokna-ad--skyscraper .sokna-ad-inner,
.sokna-ad--skyscraper .sokna-ad-cta img {
    max-height: 600px;
    object-fit: cover !important;
}

/* Skyscraper: desktop sidebar only — hide entire slot on mobile */
@media (max-width: 767px) {
    .sokna-ad--skyscraper,
    .sokna-ad-slot--skyscraper,
    .sokna-ad-slot .sokna-ad-wrapper.sokna-ad--skyscraper {
        display: none !important;
    }
}

/* ============================================
   DESKTOP-ONLY / MOBILE-ONLY - Avoid loading wrong size on wrong device
   .d-none .d-md-block = hidden on mobile, visible from 768px up
   .d-block .d-md-none = visible on mobile, hidden from 768px up
   ============================================ */
.d-none { display: none !important; }
.d-block { display: block !important; }

.d-md-block { display: none !important; }
.d-md-none { display: block !important; }

@media (min-width: 768px) {
    .d-md-block { display: block !important; }
    .d-md-none { display: none !important; }
}

/* Mobile: type-specific heights applied above; generic slot centering */
@media (max-width: 767px) {
    .sokna-ad-slot .sokna-ad-img--mobile,
    .sokna-ad-slot .sokna-ad-img--all {
        width: 100%;
        object-fit: cover !important;
        margin-inline: auto;
    }

    .sokna-ad-slot:not(.sokna-ad-slot--300x250) .sokna-ad-inner {
        max-width: 100%;
        margin-inline: auto;
    }

    .sokna-ad-section--home {
        padding: 16px 0;
    }
}

/* Hide empty/broken ad images */
.sokna-ad-img[src=""],
.sokna-ad-img:not([src]) {
    display: none !important;
}

/* Prevent blur-up effect on ad images */
.sokna-ad-img,
.sokna-ad-container img,
.sokna-ad-cta img {
    filter: none !important;
}

@media (max-width: 767px) {
    .sokna-ad-container {
        padding: 0 10px;
    }
}

.sokna-ad-container--300x250 {
    width: 300px;
    height: 250px;
    margin: 0 auto;
    display: block;
    overflow: hidden;
    border-radius: 8px;
}

.sokna-ad-container--300x250 .sokna-ad-cta {
    display: block;
    width: 100%;
    height: 100%;
}

.sokna-ad-container--300x250 .sokna-ad-img--300x250,
.sokna-ad-container--300x250 img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    image-rendering: -webkit-optimize-contrast;
}

/* ============================================
   PLACEHOLDER BANNER - "Place Your Ad Here"
   Shown when no active ad available (slot enabled)
   ============================================ */
.sokna-ad-placeholder {
    display: block;
    min-height: 120px;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border: 2px dashed #cbd5e1;
    border-radius: 10px;
    overflow: hidden;
    transition: border-color 0.3s ease, box-shadow 0.3s ease, transform 0.2s ease;
}

.sokna-ad-placeholder:hover {
    border-color: var(--color-accent, #0061DF);
    box-shadow: 0 4px 20px rgba(0, 97, 223, 0.12);
    transform: translateY(-1px);
}

.sokna-ad-placeholder__link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    padding: 24px 20px;
    text-decoration: none;
    color: #64748b;
    transition: color 0.2s ease;
}

.sokna-ad-placeholder__link:hover {
    color: var(--color-accent, #0061DF);
}

.sokna-ad-placeholder__text {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.sokna-ad-placeholder__text--en {
    margin-bottom: 4px;
}

.sokna-ad-placeholder__text--ar {
    font-family: var(--font-arabic, 'Cairo', 'IBM Plex Sans Arabic', sans-serif);
    font-size: 0.95rem;
    direction: rtl;
}

/* Responsive: taller on desktop for banner feel */
@media (min-width: 768px) {
    .sokna-ad-placeholder {
        min-height: 160px;
    }

    .sokna-ad-placeholder__link {
        min-height: 160px;
        padding: 32px 24px;
    }

    .sokna-ad-placeholder__text {
        font-size: 1.125rem;
    }

    .sokna-ad-placeholder__text--ar {
        font-size: 1.05rem;
    }
}

/* Placeholder 300x250 variant - exactly matches active ad dimensions */
.sokna-ad-placeholder--300x250 {
    width: 300px;
    height: 250px;
    min-width: 300px;
    min-height: 250px;
    border-radius: 8px;
    flex-shrink: 0;
}

.sokna-ad-placeholder--300x250 .sokna-ad-placeholder__link {
    width: 100%;
    height: 100%;
    min-height: 250px;
    padding: 16px;
}
