/*
===========================================
iOS Safari Fixes - إصلاحات خاصة بالآيفون
===========================================
*/

/* إصلاح مشاكل position: fixed على iOS */
@supports (-webkit-touch-callout: none) {
  /* هذا الكود يعمل فقط على Safari/iOS */
  
  /* إصلاح القائمة الجانبية */
  .main-nav {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-perspective: 1000;
    perspective: 1000;
  }
  
  /* إصلاح التمرير السلس */
  .main-nav,
  .cart-sidebar,
  .search-modal-content {
    -webkit-overflow-scrolling: touch;
  }
  
  /* منع التشوه عند فتح القائمة */
  body.menu-open {
    position: fixed;
    width: 100%;
    overflow: hidden;
  }
  
  /* إصلاح شامل لصفحة المنتج */
  .product-page,
  .product-content,
  .product-container {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    will-change: auto;
  }
  
  /* إصلاح الصور في صفحة المنتج */
  .product-images,
  .main-image,
  .thumbnail-images,
  .product-gallery {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    position: relative;
  }
  
  /* إصلاح الصورة الرئيسية */
  .main-image img,
  .product-gallery img {
    max-width: 100%;
    height: auto;
    display: block;
    -webkit-user-select: none;
    user-select: none;
  }
  
  /* إصلاح معلومات المنتج */
  .product-info,
  .product-details {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
  
  /* إصلاح الأزرار في صفحة المنتج */
  .product-actions,
  .add-to-cart-btn,
  .buy-now-btn {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
  
  /* إصلاح الهيدر */
  .header {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
  
  /* منع zoom عند التركيز على input */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  textarea,
  select {
    font-size: 16px !important;
  }
  
  /* إصلاح مشاكل الـ viewport */
  html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
  }
  
  /* إصلاح مشاكل الـ sticky */
  .product-images {
    position: relative !important;
    top: auto !important;
  }
  
  /* إصلاح الأزرار */
  button,
  .btn,
  a {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    -webkit-touch-callout: none;
  }
  
  /* إصلاح overflow على الصفحة بأكملها */
  body {
    -webkit-overflow-scrolling: touch;
  }
  
  /* منع التشوه في الصور */
  img {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    image-rendering: -webkit-optimize-contrast;
  }
  
  /* إصلاح النماذج المخصصة */
  .custom-form-inline,
  .custom-form-modal,
  #custom-form-inline,
  #custom-order-form {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
  
  /* إصلاح خيارات المنتج (الألوان، الأحجام، إلخ) */
  .product-options,
  .option-group,
  .color-options,
  .size-options {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
  
  /* إصلاح الـ modals */
  .modal,
  .modal-content,
  .modal-overlay {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
}

/* إصلاحات إضافية للموبايل */
@media (max-width: 768px) {
  /* منع التشوه عند فتح القائمة */
  body.menu-open {
    position: fixed;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
  }
  
  /* إصلاح القائمة الجانبية */
  .main-nav {
    position: fixed;
    top: 0;
    right: -100%;
    width: 280px;
    max-width: 85vw;
    height: 100dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 99999;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .main-nav.active {
    right: 0;
  }
  
  /* Overlay */
  .nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
  }
  
  .nav-overlay.active {
    opacity: 1;
    visibility: visible;
  }
  
  /* منع التشوه في الـ modals */
  .search-modal,
  .cart-sidebar {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }
}

/* إصلاح مشاكل الـ transform في Safari */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  /* Safari only */
  .main-nav,
  .cart-sidebar,
  .search-modal {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
}


/* إصلاحات محددة لإعدادات صفحة المنتج على iOS */
@supports (-webkit-touch-callout: none) {
  /* إصلاح position: sticky في grid layouts */
  .product-info[style*="position: sticky"] {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }
  
  /* إصلاح الصور ذات position: absolute */
  .product-images .main-image img[style*="position: absolute"],
  .product-images .thumbnail img[style*="position: absolute"] {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
  
  /* إصلاح overflow في حاويات الصور */
  .product-images .main-image[style*="overflow: hidden"],
  .product-images .thumbnail[style*="overflow: hidden"] {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }
}
