(function () {
// 1. إنشاء الحاوية الرئيسية مع تعيين ID لسهولة التحكم
const container = document.createElement("div");
container.id = "wa-chat-container";
// استخدام خطوط النظام لضمان وضوحها على الايفون والاندرويد + أعلى z-index ممكن
container.style.cssText = "position: fixed; right: 20px; bottom: 20px; z-index: 2147483647; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; display: flex; flex-direction: column; align-items: flex-end;";
container.dir = "rtl";
// 2. إنشاء نافذة الدردشة (مخفية افتراضياً)
const chatBox = document.createElement("div");
chatBox.id = "wa-chat-box";
// تم تحويل العرض ليكون متجاوباً (يأخذ 300 بكسل، وإذا كانت الشاشة صغيرة يأخذ عرض الشاشة ناقص الحواف)
chatBox.style.cssText = "display: none; width: 320px; max-width: calc(100vw - 40px); box-sizing: border-box; background: #fff; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); margin-bottom: 15px; overflow: hidden; transform: translateY(20px); opacity: 0; transition: all 0.3s ease;";
// تم تكبير مساحة الضغط لزر الإغلاق (padding) ليكون سهل اللمس في الجوال
chatBox.innerHTML = `