﻿/* ===== Ad Styles ===== */

/* حاوية الإعلان - منع CLS + منع تجاوز العرض */
.ad-container {
    contain: layout style;
    overflow: hidden;
    max-width: 100%;
    width: 100%;
}

/* إخفاء وحدات الإعلان الفارغة */
.ad-adsense:empty,
.ad-html:empty,
.ad-script:empty {
    display: none;
}

/* وحدة الإعلان */
.ad-unit {
    background: transparent;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

/* رابط الإعلان */
.ad-link {
    display: block;
    transition: opacity 0.2s;
}

.ad-link:hover {
    opacity: 0.95;
}

/* صورة الإعلان */
.ad-image {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

/* ===== مواقع الإعلانات ===== */

/* قبل المحتوى */
.ad-chapter_before_content,
.ad-chapter_after_content {
    margin: 1.5rem auto;
    text-align: center;
}

/* وسط المحتوى */
.ad-chapter_middle_content {
    margin: 2rem auto;
    text-align: center;
    padding: 1rem 0;
    border-top: 1px solid rgba(0,0,0,0.05);
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.dark .ad-chapter_middle_content {
    border-color: rgba(255,255,255,0.05);
}

/* صفحة الرواية */
.ad-novel_below_description {
    margin: 1.5rem 0;
}

.ad-novel_sidebar {
    position: sticky;
    top: 100px;
}

/* الهيدر */
.ad-header_banner {
    margin: 0.5rem auto;
}

/* الفوتر */
.ad-footer_banner {
    margin: 1rem auto;
    padding: 1rem 0;
}

/* ===== إعلان الموبايل الثابت ===== */
/*
 * الحاوية شفافة بالكامل: المحتوى الداخلي (مثل .arba7 / .arba7k) هو من
 * يتحكم في موضعه وحجمه وظهوره. هذا يسمح للمشرف بلصق كود إعلان
 * كامل (HTML + CSS + JS) في لوحة الإعلانات بدون أن يتعارض مع
 * تنسيقات الحاوية.
 */
.ad-mobile_anchor {
    background: transparent;
    padding: 0;
    margin: 0;
    overflow: visible;
    contain: none;
    min-height: 0 !important;
    /* إخفاؤها على الشاشات الكبيرة - الإعلان للموبايل فقط */
    display: none;
}

@media (max-width: 768px) {
    .ad-mobile_anchor {
        display: block;
    }

    /* رفع الأزرار العائمة فوق شريط التنقل والإعلان عند ظهوره */
    .arba7k.activ ~ * #app-floating-wrapper,
    .arba7k.activ ~ * #telegram-floating-wrapper {
        bottom: 360px !important;
    }
    body:has(.arba7k.activ) #app-floating-wrapper,
    body:has(.arba7k.activ) #telegram-floating-wrapper {
        bottom: 360px !important;
    }
}

/* ===== arba7k floating anchor (auto-wrap لمكان mobile_anchor) ===== */
.arba7 {
    position: relative;
    overflow: visible;
}
.arba7k {
    transition: transform .35s cubic-bezier(.25,.8,.25,1), opacity .25s ease;
    position: fixed;
    bottom: 110px; /* الموضع النهائي ثابت؛ نتحكم بالظهور عبر transform */
    right: 0;
    left: 0;
    z-index: 50; /* أقل من شريط التنقل (z-40 sticky) لتفادي حجبه */
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    opacity: 0;
    transform: translateY(140%);
    visibility: hidden; /* لا يُحسب للشاشة قبل الظهور */
}
.arba7k.activ {
    pointer-events: auto;
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
}
.arba7k > .arba7k-inner {
    position: relative;
    pointer-events: auto;
    /* حاوية ضيقة مناسبة لـ mobile anchor 320x100 */
    display: inline-block;
    width: auto;
    max-width: calc(100vw - 24px);
    /* الخلفية شفافة جداً قبل ما الإعلان يتحمّل (مفيش صندوق غامق يحجب الرؤية) */
    background: transparent;
    border: 1px solid transparent;
    border-radius: 14px;
    box-shadow: none;
    padding: 6px 6px 4px;
    transition: background-color .25s ease, border-color .25s ease, box-shadow .25s ease;
    /* ارتفاع أدنى لتفادي layout shift أثناء انتظار الإعلان */
    min-height: 60px;
}
/* لما الإعلان فعلاً يتحمّل (في iframe من AdSense/GAM) → نظهر الخلفية والظل */
.arba7k > .arba7k-inner:has(iframe) {
    background: rgba(255,255,255,0.98);
    border-color: rgba(0,0,0,0.08);
    box-shadow: 0 -8px 28px rgba(0,0,0,0.18), 0 2px 6px rgba(0,0,0,0.06);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
/* الـ ins بأبعاد ثابتة 300x250 (مفروضة من ad-slot.blade.php) */
.arba7k-inner ins.adsbygoogle {
    display: inline-block !important;
    width: 300px !important;
    height: 250px !important;
    max-width: 100%;
}
/* الـ GPT div (GAM ad units) بأبعاد ثابتة 300x250 */
.arba7k-inner [id^="div-gpt-ad-"] {
    display: inline-block !important;
    width: 300px !important;
    height: 250px !important;
    max-width: 100%;
    vertical-align: top;
}
.arba7k-inner [id^="div-gpt-ad-"] iframe {
    width: 100% !important;
    height: 100% !important;
    border: 0;
}
.dark .arba7k > .arba7k-inner:has(iframe) {
    background: rgba(30,41,59,0.98);
    border-color: rgba(255,255,255,0.08);
    box-shadow: 0 -8px 28px rgba(0,0,0,0.55), 0 2px 6px rgba(0,0,0,0.3);
}
/* شارة "إعلان" — التزام بسياسة AdSense ومنع الالتباس بمحتوى الموقع */
.arba7k-label {
    position: absolute;
    top: -22px;
    right: 12px;
    font-size: 10px;
    font-weight: 700;
    color: #6b7280;
    background: rgba(255,255,255,0.95);
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    line-height: 1.4;
    user-select: none;
    pointer-events: none;
}
.dark .arba7k-label {
    background: rgba(30,41,59,0.95);
    color: #cbd5e1;
    border-color: rgba(255,255,255,0.08);
}
/* اخفاء الـ label والـ close button طول ما الإعلان لسه مفيش iframe (مفيش محتوى يحجب الرؤية) */
.arba7k > .arba7k-inner:not(:has(iframe)) .arba7k-label,
.arba7k > .arba7k-inner:not(:has(iframe)) #closeingg {
    opacity: 0;
    visibility: hidden;
}
/* زر الإغلاق — صغير ومُزاح حتى لا يُضغط بالخطأ */
.arba7k #closeingg {
    cursor: pointer;
    display: flex;
    width: 26px;
    height: 26px;
    align-items: center;
    justify-content: center;
    background: rgba(17,24,39,0.85);
    color: #fff;
    position: absolute;
    top: -10px;
    left: -10px; /* بعيد عن مساحة الإعلان لتفادي الضغط بالخطأ */
    right: auto;
    border-radius: 50%;
    margin: 0;
    font-size: 16px;
    line-height: 1;
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    user-select: none;
    transition: background .2s, transform .2s;
    border: 2px solid #fff;
}
.dark .arba7k #closeingg {
    border-color: #1e293b;
}
.arba7k #closeingg:hover,
.arba7k #closeingg:focus-visible {
    background: #ef4444;
    transform: scale(1.08);
    outline: none;
}
/* إخفاء كامل للحاوية الفارغة (لو AdSense لم يملأ) */
.ad-mobile_anchor.ad-unfilled,
.arba7k.ad-empty { display: none !important; }

/* إخفاء حاوية الإعلان الثابت على الشاشات الكبيرة */
@media (min-width: 769px) {
    .ad-mobile_anchor .arba7,
    .ad-mobile_anchor .arba7k { display: none !important; }
}

/* ===== النافذة المنبثقة ===== */
.ad-popup_interstitial {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10001;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 50px rgba(0,0,0,0.3);
    padding: 1rem;
}

.dark .ad-popup_interstitial {
    background: #1e293b;
}

.ad-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 10000;
}

.ad-popup-close {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #ef4444;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: transform 0.2s;
}

.ad-popup-close:hover {
    transform: scale(1.1);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .ad-container {
        margin: 1rem auto;
    }
    
    .ad-chapter_before_content,
    .ad-chapter_after_content {
        margin: 1rem auto;
    }
    
    /* إخفاء الإعلانات الكبيرة على الموبايل */
    .ad-header_banner .ad-image,
    .ad-footer_banner .ad-image {
        max-width: 320px;
    }
}

/* ===== AdSense Specific ===== */
.ad-adsense {
    overflow: hidden;
    max-width: 100%;
    width: 100%;
    text-align: center;
}

.ad-adsense ins {
    display: block !important;
    max-width: 100% !important;
    width: 100% !important;
}

/* إخفاء الإعلانات التي لم يتم ملؤها */
.ad-adsense ins.adsbygoogle[data-ad-status="unfilled"] {
    display: none !important;
    min-height: 0 !important;
}
.ad-container.ad-unfilled {
    display: none !important;
}

/* ===== منع تجاوز الإعلانات للعرض ===== */
.ad-html,
.ad-script {
    overflow: hidden;
    max-width: 100%;
}

.ad-html iframe,
.ad-script iframe,
.ad-adsense iframe {
    max-width: 100% !important;
}

/* ===== منع إعلانات AdSense التلقائية من تجاوز العرض + منع sticky ===== */
ins.adsbygoogle[data-ad-status],
.adsbygoogle,
[id^="google_ads"],
[id^="aswift"],
iframe[id^="aswift"],
.google-auto-placed {
    max-width: 100% !important;
    overflow: hidden !important;
}

/* منع الإعلانات التلقائية من أن تكون sticky أو fixed */
.google-auto-placed,
.google-auto-placed ins,
div[data-google-query-id] {
    position: static !important;
    max-width: 100% !important;
}

.google-auto-placed > ins {
    max-width: 100% !important;
}
