/* ==================== MASTER FIX - إصلاح شامل لجميع المشاكل ==================== */

/* ==================== 1. إصلاح المحافظات في الصفحة الرئيسية ==================== */
/* توسيط قسم المحافظات */
.bg-white.rounded-2xl.shadow-lg {
  margin-left: auto !important;
  margin-right: auto !important;
  max-width: 1200px !important;
}

/* توسيط شبكة المحافظات */
.grid.grid-cols-2.sm\:grid-cols-3.md\:grid-cols-4.lg\:grid-cols-6 {
  display: grid !important;
  justify-content: center !important;
}

/* ==================== 2. إصلاح القائمة في الديسكتوب ==================== */
@media (min-width: 768px) {
  /* إظهار القائمة الرئيسية */
  nav .hidden.md\:flex {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  /* إظهار روابط القائمة */
  nav .hidden.md\:flex a {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  /* إصلاح شريط البحث */
  nav .hidden.lg\:flex {
    display: flex !important;
  }
}

/* ==================== 3. إصلاح الفئات في تصفح الهاتف ==================== */
@media (max-width: 768px) {
  /* إظهار حاوية الفئات */
  .categories-container-mobile,
  .bg-white.rounded-lg.shadow-sm,
  .bg-white.rounded-lg.border {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    z-index: 10 !important;
    width: 100% !important;
  }
  
  /* إظهار أزرار الفئات */
  .categories-container-mobile button,
  .bg-white.rounded-lg button,
  .overflow-x-auto button {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    min-width: fit-content !important;
  }
  
  /* إصلاح التمرير الأفقي */
  .overflow-x-auto {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    width: 100% !important;
    display: flex !important;
  }
  
  /* إخفاء شريط التمرير */
  .overflow-x-auto::-webkit-scrollbar {
    display: none !important;
  }
  
  .overflow-x-auto {
    -ms-overflow-style: none !important;
    scrollbar-width: none !important;
  }
}

/* ==================== 4. إصلاح زر إضافة عقار ==================== */
.add-property-btn,
button[title="إضافة عقار"],
.bg-blue-500.hover\:bg-blue-600 {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  background-color: #3b82f6 !important;
  color: white !important;
  align-items: center !important;
  justify-content: center !important;
}

/* ==================== 5. إصلاح قائمة المدن على الخريطة ==================== */
@media (max-width: 768px) {
  /* موضع قائمة المدن */
  .city-navigation-container,
  .absolute.bottom-4.left-1\/2 {
    position: fixed !important;
    bottom: 80px !important; /* فوق شريط التنقل السفلي */
    left: 50% !important;
    transform: translateX(-50%) !important;
    z-index: 1000 !important;
    width: calc(100% - 20px) !important;
    max-width: 100% !important;
  }
  
  /* منع ظهورها في منتصف الخريطة */
  .leaflet-container .city-navigation-container {
    top: auto !important;
    bottom: 10px !important;
  }
  
  /* إصلاح ارتفاع الخريطة */
  .leaflet-container {
    height: calc(100vh - 250px) !important;
    position: relative !important;
  }
}

@media (min-width: 769px) {
  /* موضع قائمة المدن على الديسكتوب */
  .city-navigation-container {
    position: absolute !important;
    bottom: 20px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
  }
}

/* ==================== 6. إصلاحات عامة للهاتف ==================== */
@media (max-width: 768px) {
  /* منع القص الأفقي */
  body, html, #root {
    width: 100% !important;
    overflow-x: hidden !important;
  }
  
  /* إصلاح الهيدر */
  .sticky.top-0 {
    position: sticky !important;
    position: -webkit-sticky !important;
    top: 0 !important;
    width: 100% !important;
    z-index: 50 !important;
    left: 0 !important;
    right: 0 !important;
  }
  
  /* إصلاح الحاويات */
  .container {
    max-width: 100% !important;
    padding: 0 !important;
  }
  
  /* حجم أزرار اللمس */
  button {
    min-height: 36px !important;
    min-width: 36px !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent !important;
  }
  
  /* منع التكبير عند النقر على الحقول */
  input[type="text"],
  input[type="search"],
  input[type="number"],
  textarea,
  select {
    font-size: 16px !important;
  }
}

/* ==================== 7. توافق المتصفحات ==================== */
/* Samsung Internet */
@supports (-webkit-appearance: none) {
  * {
    -webkit-appearance: none !important;
  }
  
  .flex {
    display: -webkit-box !important;
    display: -webkit-flex !important;
    display: -ms-flexbox !important;
    display: flex !important;
  }
  
  .inline-flex {
    display: -webkit-inline-box !important;
    display: -webkit-inline-flex !important;
    display: -ms-inline-flexbox !important;
    display: inline-flex !important;
  }
  
  .grid {
    display: grid !important;
  }
}

/* iOS Safari */
@supports (-webkit-touch-callout: none) {
  .sticky {
    position: -webkit-sticky !important;
    position: sticky !important;
  }
  
  .overflow-x-auto,
  .overflow-y-auto {
    -webkit-overflow-scrolling: touch !important;
  }
  
  .fixed {
    padding-bottom: env(safe-area-inset-bottom) !important;
  }
}

/* ==================== 8. إصلاح الرؤية العامة ==================== */
/* التأكد من ظهور جميع العناصر المهمة */
nav *:not(.hidden),
.categories-container-mobile *,
.city-navigation-container *,
.add-property-btn,
button[title="إضافة عقار"] {
  visibility: visible !important;
  opacity: 1 !important;
}

/* إخفاء العناصر التي يجب إخفاؤها فقط */
.hidden:not(.md\:flex):not(.lg\:flex):not(.sm\:block):not(.sm\:inline) {
  display: none !important;
}

/* ==================== 9. تحسينات الأداء ==================== */
.overflow-x-auto,
.overflow-y-auto {
  -webkit-transform: translateZ(0) !important;
  transform: translateZ(0) !important;
  will-change: transform !important;
}

/* ==================== 10. إصلاحات z-index ==================== */
.sticky.top-0 {
  z-index: 9999 !important;
}

.city-navigation-container {
  z-index: 1000 !important;
}

.fixed.inset-0 {
  z-index: 10000 !important;
}

/* ==================== 11. إصلاح ألوان أزرار المدن ==================== */
.bg-red-500,
.hover\:bg-red-500:hover {
  background-color: #ef4444 !important;
  color: white !important;
}

/* ==================== 12. إصلاحات خاصة بصفحة العقارات ==================== */
/* الهيدر */
.bg-white.shadow-sm.border-b {
  width: 100% !important;
}

.bg-white.shadow-sm.border-b .flex {
  display: flex !important;
}

/* شريط البحث */
.bg-white.border-b {
  width: 100% !important;
}

/* الفئات */
.mt-3 > div {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Enhanced Category Filter */
.enhanced-category-filter {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.enhanced-category-filter button {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Hide scrollbars but keep functionality */
.hide-scrollbar::-webkit-scrollbar {
  display: none !important;
}

.hide-scrollbar {
  -ms-overflow-style: none !important;
  scrollbar-width: none !important;
}

/* ==================== 13. إصلاحات النوافذ المنبثقة (Modals) ==================== */
/* Notification and Alert Modals */
.fixed.inset-0.bg-black {
  z-index: 9999 !important;
}

.fixed.inset-0.bg-black > div {
  z-index: 10000 !important;
}

@media (max-width: 768px) {
  /* Full screen modals on mobile */
  .fixed.inset-0 .max-w-2xl {
    max-width: 100% !important;
    width: calc(100% - 32px) !important;
    margin: 16px !important;
  }
}

/* ==================== DEBUG MODE - إزالة في الإنتاج ==================== */
/*
@media (max-width: 768px) {
  .categories-container-mobile {
    border: 2px solid green !important;
  }
  
  .city-navigation-container {
    border: 2px solid blue !important;
  }
  
  button[title="إضافة عقار"] {
    border: 2px solid red !important;
  }
}
*/