/* ── Ad unit base ──────────────────────────────────────────────────────────── */

.ad-unit {
    position: relative;
    margin: var(--sp-4) auto;
    max-width: 100%;
    text-align: center;
    overflow: hidden;
}

/* Disclosure badge — always visible (legal transparency requirement) */
.ad-label {
    display: inline-block;
    font-size: 10px;
    line-height: 1;
    color: var(--muted, #888);
    background: var(--surface, #f5f5f5);
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 2px;
    padding: 1px 4px;
    margin-bottom: var(--sp-1, 4px);
    letter-spacing: 0.04em;
    user-select: none;
}

.ad-unit-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

/* ── Banner (image) ─────────────────────────────────────────────────────────── */

.ad-unit--banner img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: var(--r-sm, 4px);
    max-height: 250px;
    object-fit: contain;
}

/* ── Text ad ────────────────────────────────────────────────────────────────── */

.ad-text-inner {
    display: block;
    background: var(--surface, #f9f9f9);
    border: 1px solid var(--border, #e0e0e0);
    border-radius: var(--r-md, 8px);
    padding: var(--sp-3, 12px) var(--sp-4, 16px);
    text-align: start;
    transition: background 0.15s;
}

.ad-text-inner:hover {
    background: color-mix(in srgb, var(--accent, #c8102e) 5%, var(--surface, #f9f9f9));
}

.ad-text-headline {
    font-size: var(--text-sm, 14px);
    font-weight: 700;
    color: var(--ink, #111);
    margin-bottom: var(--sp-1, 4px);
}

.ad-text-body {
    font-size: var(--text-xs, 12px);
    color: var(--muted, #666);
    margin-bottom: var(--sp-2, 8px);
    line-height: 1.5;
}

.ad-text-cta {
    font-size: var(--text-xs, 12px);
    color: var(--accent, #c8102e);
    font-weight: 600;
}

/* ── AdSense unit ───────────────────────────────────────────────────────────── */

.ad-unit--adsense .adsbygoogle {
    display: block;
    width: 100%;
}

/* ── CLS: reserve the real slot height before the iframe loads ───────────────
   A single flat min-height cannot serve slots of different sizes. The zones are
   300x250 (sidebar-right, detail-sidebar), 728x90 (below-player, footer-banner,
   video-list-feed) and 468x60 (home-feed). Reserving 90px for a 300x250 slot
   shifts everything below it by 160px the moment the ad fills.

   --ad-h is emitted inline per unit from the zone's HeightPx column, so the
   reservation follows the database rather than a hardcoded list that goes stale
   the first time someone resizes a zone in the admin UI. */
.ad-unit--adsense {
    min-height: var(--ad-h, 90px);
}

/* Below 768px AdSense substitutes mobile creatives (typically 320x100 or 300x250)
   for desktop leaderboards. The previous rule reserved *less* on mobile (60px),
   guaranteeing a shift on exactly the devices where CLS is weighted hardest.
   max() keeps the taller of the zone height and the mobile creative floor. */
@media (max-width: 768px) {
    .ad-unit--adsense {
        min-height: max(var(--ad-h, 90px), 100px);
    }
}

/* ── Video embed ────────────────────────────────────────────────────────────── */

.ad-video-wrap {
    display: block;
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: var(--r-sm, 4px);
    overflow: hidden;
}

.ad-video-wrap iframe {
    width: 100%;
    height: 100%;
    border: 0;
}

/* ── Demo placeholder ───────────────────────────────────────────────────────── */

.ad-unit--demo {
    width: min(100%, var(--ad-hint-w, 728px));
    height: var(--ad-hint-h, 90px);
    min-height: 60px;
    background: repeating-linear-gradient(
        135deg,
        color-mix(in srgb, var(--accent, #c8102e) 4%, transparent) 0px,
        color-mix(in srgb, var(--accent, #c8102e) 4%, transparent) 10px,
        transparent 10px,
        transparent 20px
    );
    border: 2px dashed color-mix(in srgb, var(--accent, #c8102e) 30%, var(--border, #e0e0e0));
    border-radius: var(--r-md, 8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-1, 4px);
}

.ad-demo-inner {
    display: flex;
    align-items: center;
    gap: var(--sp-3, 12px);
    background: color-mix(in srgb, var(--white, #fff) 85%, transparent);
    border-radius: var(--r-sm, 4px);
    padding: var(--sp-2, 8px) var(--sp-3, 12px);
    backdrop-filter: blur(2px);
}

.ad-demo-icon {
    width: 20px;
    height: 20px;
    color: color-mix(in srgb, var(--accent, #c8102e) 60%, var(--muted, #888));
    flex-shrink: 0;
}

.ad-demo-text {
    text-align: start;
    line-height: 1.3;
}

.ad-demo-title {
    font-size: var(--text-xs, 12px);
    font-weight: 700;
    color: var(--ink, #111);
}

.ad-demo-zone {
    font-size: 10px;
    color: var(--accent, #c8102e);
    font-family: monospace;
}

.ad-demo-dims {
    font-size: 10px;
    color: var(--muted, #888);
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .ad-unit--demo {
        width: 100%;
        height: auto;
        min-height: 60px;
        padding: var(--sp-3, 12px);
    }

    /* .ad-unit--adsense mobile height is set with the CLS reservation rules above.
       A flat 60px here previously won on source order and under-reserved every slot. */
}

/* RTL overrides — already correct since site is Arabic/RTL, included for clarity */
[dir="rtl"] .ad-text-cta {
    direction: rtl;
}
