/* ===== إصلاح تداخل العناصر والـ Z-index والموبايل ===== */

/* ===== إصلاح الهيدر والتداخل ===== */
.m-header {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    z-index: 998 !important; /* أقل من المودالات ولكن أعلى من المحتوى */
    height: 75px !important;
}

/* ===== إصلاح الصفحة الرئيسية والمحتوى ===== */
.main-content,
.hero-section,
#main {
    position: relative !important;
    z-index: 1 !important;
    margin-top: 85px !important; /* زيادة المسافة من الهيدر لمنع التداخل */
}

/* منع تداخل العناصر في الصفحة الرئيسية */
.index-page .main-content {
    padding-top: 20px !important;
}

/* ضمان عدم تداخل المودال مع أي شيء في الخلفية */
#profileEditor.active {
    background: rgba(0, 0, 0, 0.9) !important; /* خلفية أغمق لعزل المحتوى */
    backdrop-filter: blur(30px) !important;
    -webkit-backdrop-filter: blur(30px) !important;
    z-index: 2147483647 !important; /* أعلى قيمة ممكنة لضمان الظهور فوق كل شيء */
}

/* عزل محتوى الصفحة الرئيسية عند فتح المودال */
body.prevent-scroll .index-page .main-content,
body.prevent-scroll .index-page .m-header {
    filter: blur(5px);
    pointer-events: none;
}

body {
    margin: 0 !important;
    padding: 0 !important;
    overflow-x: hidden !important;
}

/* ===== إصلاح المودالات والويدجتات ===== */
#profileEditor,
#adminProfileEditorModal,
.admin-profile-editor-modal,
#visitorModal,
.absolute-popup-container {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 10000 !important;
    display: none !important; /* إخفاء افتراضي */
    align-items: center !important;
    justify-content: center !important;
    background: rgba(0, 0, 0, 0.7) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
}

/* إظهار المودال عند وجود كلاس active أو عند تغييره بواسطة JS */
#profileEditor.active,
#adminProfileEditorModal.active,
.admin-profile-editor-modal.active,
#visitorModal.active,
.absolute-popup-container.active {
    display: flex !important;
}

/* ===== إصلاح البوت والويدجت ===== */
#floatingToggle,
#floatingToggle.bot-character-img,
.enhanced-widget,
#welcomeBackWidget {
    position: fixed !important;
    z-index: 2147483647 !important; /* أعلى من كل شيء ما عدا المودالات */
}

#floatingToggle {
    bottom: 25px !important;
    right: 25px !important;
    width: 75px !important;
    height: 75px !important;
}

.enhanced-widget,
#welcomeBackWidget {
    bottom: 110px !important;
    right: 25px !important;
    width: 320px !important;
    max-width: 90vw !important;
}

/* ===== إصلاح زر إخفاء التنبيهات ===== */
.hide-all-popups-btn,
#hideAllPopupsBtn {
    position: fixed !important;
    bottom: 20px !important;
    left: 50% !important;
    transform: translateX(-50%) translateY(150px) !important;
    z-index: 2147483646 !important; /* أقل من البوت قليلاً */
    width: auto !important;
    max-width: 90vw !important;
}

.hide-all-popups-btn.show,
#hideAllPopupsBtn.show {
    transform: translateX(-50%) translateY(0) !important;
}

/* ===== إصلاح الإشعارات والـ Popups ===== */
.notif-popup {
    position: fixed !important;
    z-index: 2147483645 !important;
}

/* ===== إصلاح الموبايل والتجاوب ===== */
@media (max-width: 1199px) {
    .m-header {
        padding: 0 15px !important;
    }
    
    .main-content,
    .hero-section,
    #main {
        margin-top: 75px !important;
    }
}

@media (max-width: 768px) {
    /* ===== إصلاح الهيدر للموبايل ===== */
    .m-header {
        height: 70px !important;
        padding: 0 12px !important;
    }
    
    .main-content,
    .hero-section,
    #main {
        margin-top: 70px !important;
        padding: 0 !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* ===== إصلاح المودالات للموبايل ===== */
    #profileEditor,
    #adminProfileEditorModal,
    .admin-profile-editor-modal,
    #visitorModal,
    .absolute-popup-container {
        padding: 15px !important;
    }
    
    #profileEditor > div,
    #adminProfileEditorModal > div,
    .admin-profile-editor-content,
    #visitorModal .popup-box-wrapper,
    .popup-card-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: auto !important;
        border-radius: 20px !important;
    }
    
    /* ===== إصلاح البوت والويدجت للموبايل ===== */
    #floatingToggle {
        width: 65px !important;
        height: 65px !important;
        bottom: 20px !important;
        right: 20px !important;
    }
    
    .enhanced-widget,
    #welcomeBackWidget {
        width: calc(100% - 40px) !important;
        right: 20px !important;
        bottom: 90px !important;
        max-width: calc(100vw - 40px) !important;
    }
    
    /* ===== إصلاح زر إخفاء التنبيهات للموبايل ===== */
    .hide-all-popups-btn,
    #hideAllPopupsBtn {
        bottom: 15px !important;
        padding: 10px 20px !important;
        font-size: 13px !important;
        width: auto !important;
        max-width: 90vw !important;
    }
    
    /* ===== إصلاح الفقاعات والإشعارات ===== */
    .bot-auto-bubble {
        width: 260px !important;
        max-width: calc(100vw - 40px) !important;
        right: -10px !important;
    }
    
    .notif-popup {
        width: calc(100% - 30px) !important;
        max-width: 350px !important;
        right: 15px !important;
    }
    
    /* ===== إصلاح الـ Scrolling والـ Overflow ===== */
    body.prevent-scroll {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
    }
    
    /* ===== إصلاح الـ Inputs والـ Selects ===== */
    input,
    select,
    textarea {
        font-size: 16px !important; /* منع الزووم على iOS */
        -webkit-appearance: none !important;
        appearance: none !important;
    }
    
    /* ===== إصلاح الـ Viewport ===== */
    html {
        height: 100vh !important;
        height: 100dvh !important; /* Dynamic Viewport Height */
    }
}

@media (max-width: 480px) {
    /* ===== إصلاح الهيدر للهاتف الصغير ===== */
    .m-header {
        height: 65px !important;
        padding: 0 10px !important;
    }
    
    .main-content,
    .hero-section,
    #main {
        margin-top: 65px !important;
    }
    
    /* ===== إصلاح المودالات للهاتف الصغير ===== */
    #profileEditor,
    #adminProfileEditorModal,
    .admin-profile-editor-modal,
    #visitorModal,
    .absolute-popup-container {
        padding: 10px !important;
    }
    
    #profileEditor > div,
    #adminProfileEditorModal > div,
    .admin-profile-editor-content,
    #visitorModal .popup-box-wrapper,
    .popup-card-content {
        padding: 15px !important;
        border-radius: 18px !important;
    }
    
    /* ===== إصلاح البوت والويدجت للهاتف الصغير ===== */
    #floatingToggle {
        width: 60px !important;
        height: 60px !important;
        bottom: 15px !important;
        right: 15px !important;
    }
    
    .bot-character-img {
        width: 40px !important;
        height: 40px !important;
    }
    
    .bot-moon-icon {
        font-size: 20px !important;
    }
    
    .enhanced-widget,
    #welcomeBackWidget {
        width: calc(100% - 30px) !important;
        right: 15px !important;
        bottom: 80px !important;
        padding: 15px !important;
    }
    
    /* ===== إصلاح زر إخفاء التنبيهات للهاتف الصغير ===== */
    .hide-all-popups-btn,
    #hideAllPopupsBtn {
        bottom: 12px !important;
        padding: 8px 15px !important;
        font-size: 12px !important;
    }
    
    .hide-all-popups-btn i,
    #hideAllPopupsBtn i {
        font-size: 14px !important;
    }
    
    /* ===== إصلاح الفقاعات والإشعارات ===== */
    .bot-auto-bubble {
        width: calc(100vw - 50px) !important;
        right: -15px !important;
        padding: 12px !important;
        font-size: 11px !important;
    }
    
    .notif-popup {
        width: calc(100% - 20px) !important;
        max-width: 300px !important;
        right: 10px !important;
        left: auto !important;
    }
}

/* ===== إصلاح التداخل على جميع الأجهزة ===== */
.netflix-row {
    position: relative !important;
    z-index: 2 !important;
}

.netflix-card:hover {
    z-index: 5 !important;
}

.scroll-container-wrapper {
    position: relative !important;
    z-index: 2 !important;
}

/* ===== منع التداخل مع الـ Navbar ===== */
.m-header-content {
    position: relative !important;
    z-index: 999 !important;
}

.search-results-dropdown {
    position: absolute !important;
    z-index: 1000 !important;
    top: 100% !important;
}

/* ===== إصلاح الـ Scrollbar والـ Overflow ===== */
html {
    scrollbar-width: thin !important;
    scrollbar-color: rgba(139, 0, 0, 0.5) rgba(0, 0, 0, 0.1) !important;
}

html::-webkit-scrollbar {
    width: 8px !important;
}

html::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1) !important;
}

html::-webkit-scrollbar-thumb {
    background: rgba(139, 0, 0, 0.5) !important;
    border-radius: 4px !important;
}

html::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 0, 0, 0.7) !important;
}

/* ===== منع الـ Zoom على iOS ===== */
input,
select,
textarea,
button {
    font-size: 16px !important;
}

/* ===== إصلاح الـ Touch Events ===== */
* {
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
}

input,
textarea,
select,
a,
button {
    -webkit-user-select: text !important;
    user-select: text !important;
}

/* ===== إصلاح الـ Safe Area ===== */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left)) !important;
        padding-right: max(0px, env(safe-area-inset-right)) !important;
        padding-top: max(0px, env(safe-area-inset-top)) !important;
        padding-bottom: max(0px, env(safe-area-inset-bottom)) !important;
    }
    
    .m-header {
        padding-left: max(15px, env(safe-area-inset-left)) !important;
        padding-right: max(15px, env(safe-area-inset-right)) !important;
    }
}

/* ===== Loading Optimization & Button Fixes ===== */

/* منع ظهور الأزرار بشكل مربع أثناء التحميل عبر فرض border-radius فوري */
.btn, button, .btn-primary, .btn-secondary, .view-all-btn, .nav-link, .m-logo, .m-menu-trigger, .profile-icon-btn, .gender-option, .popup-card-content, .history-card {
    border-radius: 10px !important;
    -webkit-border-radius: 10px !important;
}

/* الأزرار الدائرية والمستديرة بالكامل */
.view-all-btn, .btn-primary, .btn-secondary, .hero-actions button, .global-btt {
    border-radius: 50px !important;
    -webkit-border-radius: 50px !important;
}

.profile-icon-container, .profile-avatar-img, .profile-icon-btn {
    border-radius: 50% !important;
    -webkit-border-radius: 50% !important;
}

/* تحسين تحميل الخطوط ومنع القفز البصري */
body {
    font-family: 'Cairo', sans-serif;
    display: block !important;
    -webkit-font-smoothing: antialiased;
}

/* إصلاح تباعد العناصر على الشاشات الصغيرة جداً */
@media (max-width: 480px) {
    .m-header {
        height: 60px !important;
    }
    .m-logo {
        font-size: 13px !important;
    }
    .profile-icon-btn {
        width: 32px !important;
        height: 32px !important;
    }
}
