/* ===============================================
   Mobile Responsive CSS - تصميم متجاوب للهاتف
   =============================================== */

/* ===== 1. إعدادات عامة أساسية ===== */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* إصلاح اللمس بإصبع واحد */
  touch-action: manipulation !important;
  -ms-touch-action: manipulation !important;
}

html {
  overflow-x: hidden !important;
  width: 100% !important;
  max-width: 100vw !important;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* تفعيل التمرير السلس باللمس */
  -webkit-overflow-scrolling: touch !important;
  touch-action: manipulation !important;
}

body {
  overflow-x: hidden !important;
  width: 100% !important;
  max-width: 100vw !important;
  margin: 0 !important;
  padding: 0 !important;
  position: relative;
  min-height: 100vh;
  /* السماح بالتمرير العمودي فقط */
  overscroll-behavior: contain;
  overscroll-behavior-y: auto;
  overscroll-behavior-x: none;
  /* تفعيل التمرير السلس */
  -webkit-overflow-scrolling: touch !important;
  touch-action: manipulation !important;
}

/* ===== 2. منع التمرير الأفقي ===== */
.site,
.site-header,
.site-content,
.site-footer,
.modern-health-footer,
.container,
.medical-tips-hero,
section,
article,
div[class*="wrap"],
div[class*="container"] {
  max-width: 100% !important;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
}

/* ===== 3. الصور والوسائط ===== */
img,
video,
iframe,
embed,
object {
  max-width: 100% !important;
  height: auto !important;
  display: block;
}

img {
  border-radius: 8px;
  image-rendering: -webkit-optimize-contrast;
}

/* ===== 4. الحاويات Containers ===== */
.container {
  width: 100% !important;
  max-width: 100% !important;
  padding-left: 16px !important;
  padding-right: 16px !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

/* ===== 5. تصميم متجاوب للشاشات ===== */

/* شاشات صغيرة جداً: 0 - 374px */
@media screen and (max-width: 374px) {
  html { font-size: 14px; }
  
  body {
    font-size: 14px;
    line-height: 1.5;
  }
  
  .container {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }
  
  h1 { font-size: 24px !important; }
  h2 { font-size: 20px !important; }
  h3 { font-size: 18px !important; }
  h4 { font-size: 16px !important; }
  h5, h6 { font-size: 14px !important; }
  
  /* أزرار أصغر */
  button,
  .btn,
  a.button,
  input[type="submit"],
  input[type="button"] {
    padding: 10px 14px !important;
    font-size: 13px !important;
    min-height: 40px !important;
    border-radius: 8px !important;
  }
}

/* شاشات صغيرة: 375px - 479px */
@media screen and (min-width: 375px) and (max-width: 479px) {
  html { font-size: 15px; }
  
  body {
    font-size: 15px;
    line-height: 1.6;
  }
  
  .container {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }
  
  h1 { font-size: 26px !important; }
  h2 { font-size: 22px !important; }
  h3 { font-size: 19px !important; }
  h4 { font-size: 17px !important; }
  h5, h6 { font-size: 15px !important; }
  
  button,
  .btn,
  a.button,
  input[type="submit"],
  input[type="button"] {
    padding: 11px 16px !important;
    font-size: 14px !important;
    min-height: 42px !important;
    border-radius: 10px !important;
  }
}

/* شاشات متوسطة: 480px - 767px */
@media screen and (min-width: 480px) and (max-width: 767px) {
  html { font-size: 16px; }
  
  body {
    font-size: 16px;
    line-height: 1.65;
  }
  
  .container {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
  
  h1 { font-size: 30px !important; }
  h2 { font-size: 25px !important; }
  h3 { font-size: 21px !important; }
  h4 { font-size: 18px !important; }
  h5, h6 { font-size: 16px !important; }
  
  button,
  .btn,
  a.button,
  input[type="submit"],
  input[type="button"] {
    padding: 12px 18px !important;
    font-size: 15px !important;
    min-height: 44px !important;
    border-radius: 12px !important;
  }
}

/* تابلت عمودي: 768px - 991px */
@media screen and (min-width: 768px) and (max-width: 991px) {
  .container {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }
  
  h1 { font-size: 34px !important; }
  h2 { font-size: 28px !important; }
  h3 { font-size: 23px !important; }
}

/* ===== 6. تصميم الـ Grid للهاتف ===== */
@media screen and (max-width: 767px) {
  /* إجبار Grid على عمود واحد */
  [style*="display: grid"],
  [style*="display:grid"],
  .grid,
  .wp-block-columns {
    display: block !important;
    grid-template-columns: 1fr !important;
  }
  
  /* إصلاح Flexbox */
  [style*="display: flex"],
  [style*="display:flex"],
  .flex {
    flex-direction: column !important;
    flex-wrap: wrap !important;
  }
  
  /* تباعد مناسب للعناصر */
  [style*="display: grid"] > *,
  [style*="display: flex"] > * {
    width: 100% !important;
    margin-bottom: 16px !important;
  }
}

/* ===== 7. الجداول Responsive Tables ===== */
@media screen and (max-width: 767px) {
  table {
    width: 100% !important;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
  }
  
  table thead {
    display: none;
  }
  
  table tr {
    display: block;
    margin-bottom: 16px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px;
  }
  
  table td {
    display: block;
    text-align: right;
    padding: 8px !important;
    border: none !important;
  }
  
  table td:before {
    content: attr(data-label);
    font-weight: bold;
    display: block;
    margin-bottom: 4px;
    color: #64748b;
  }
}

/* ===== 8. النماذج Forms ===== */
@media screen and (max-width: 767px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="url"],
  input[type="search"],
  input[type="number"],
  textarea,
  select {
    width: 100% !important;
    padding: 12px 14px !important;
    font-size: 16px !important; /* منع تكبير الصفحة في iOS */
    border-radius: 10px !important;
    border: 1px solid #d1d5db !important;
    margin-bottom: 12px !important;
    min-height: 44px !important;
  }
  
  textarea {
    min-height: 120px !important;
    resize: vertical;
  }
  
  /* Form في صف واحد يصبح عمود */
  form[style*="display: flex"],
  form[style*="display:flex"] {
    flex-direction: column !important;
  }
  
  form input,
  form button,
  form select {
    width: 100% !important;
    margin-bottom: 12px !important;
  }
}

/* ===== 9. الأزرار Touch-Friendly ===== */
button,
.btn,
a.button,
input[type="submit"],
input[type="button"],
.wp-block-button__link,
a[role="button"] {
  min-height: 44px !important;
  min-width: 44px !important;
  padding: 12px 20px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  border-radius: 12px !important;
  font-size: 15px !important;
  font-weight: 600 !important;
  text-align: center !important;
  cursor: pointer;
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* زر في عرض كامل للهاتف */
@media screen and (max-width: 479px) {
  .btn-block,
  .button-full-width {
    width: 100% !important;
    display: block !important;
  }
}

/* ===== 10. Navigation / القوائم ===== */
@media screen and (max-width: 991px) {
  /* إخفاء القائمة الرئيسية وعرض زر Hamburger */
  .main-navigation ul {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    height: 100vh;
    background: white;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    padding: 60px 20px 20px;
    overflow-y: auto;
  }
  
  .main-navigation ul.mobile-menu-active {
    display: block;
  }
  
  .main-navigation ul li {
    display: block;
    width: 100%;
    margin: 0 0 8px 0 !important;
  }
  
  .main-navigation ul li a {
    display: block;
    padding: 12px 16px;
    border-radius: 8px;
    transition: all 0.3s ease;
  }
  
  .main-navigation ul li a:hover {
    background: #f1f5f9;
  }
  

  

}

/* ===== 11. Cards / البطاقات ===== */
@media screen and (max-width: 767px) {
  .card,
  .tip-card,
  .post-card,
  .article-card,
  [class*="card"] {
    margin-bottom: 16px !important;
    padding: 16px !important;
    border-radius: 12px !important;
  }
  
  /* تأكد من أن البطاقات لا تكبر */
  .card img,
  .tip-card img {
    width: 100%;
    max-width: 100%;
    height: auto;
    object-fit: cover;
    border-radius: 8px;
  }
}

/* ===== 12. Medical Tips Hero Section ===== */
@media screen and (max-width: 767px) {
  .medical-tips-hero {
    padding: 40px 0 32px !important;
    min-height: auto !important;
  }
  
  .medical-tips-hero h1 {
    font-size: 28px !important;
    line-height: 1.3 !important;
    margin-bottom: 12px !important;
  }
  
  .medical-tips-hero p {
    font-size: 15px !important;
    line-height: 1.6 !important;
    margin-bottom: 16px !important;
  }
  
  /* اللوقو في الهيرو */
  .medical-tips-hero [style*="display: inline-flex"] {
    font-size: 32px !important;
    width: 48px !important;
    height: 48px !important;
    margin-bottom: 16px !important;
  }
}

/* ===== 13. Tips Categories Filter ===== */
@media screen and (max-width: 767px) {
  .tips-categories {
    margin: 0 0 24px 0 !important;
    padding: 0 !important;
  }
  
  .tips-categories > div {
    padding: 12px !important;
    border-radius: 12px !important;
  }
  
  .tips-categories [style*="display: flex"] {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    justify-content: center !important;
  }
  
  .tip-category-btn {
    font-size: 13px !important;
    padding: 8px 12px !important;
    margin: 0 !important;
    border-radius: 8px !important;
    white-space: nowrap;
    min-height: 36px !important;
  }
}

/* ===== 14. Tips Grid Container ===== */
@media screen and (max-width: 767px) {
  #tips-container {
    display: block !important;
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    padding: 0 !important;
  }
  
  #tips-container .tip-card {
    width: 100% !important;
    margin-bottom: 16px !important;
  }
}

@media screen and (min-width: 480px) and (max-width: 767px) {
  #tips-container {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
}

/* ===== 15. Daily Tip Widget ===== */
@media screen and (max-width: 767px) {
  .daily-tip-widget {
    margin: 0 0 32px 0 !important;
    padding: 0 16px !important;
  }
  
  .daily-tip-widget > div {
    padding: 24px 20px !important;
    border-radius: 16px !important;
  }
  
  .daily-tip-widget h3 {
    font-size: 20px !important;
    margin-bottom: 12px !important;
  }
  
  .daily-tip-widget p {
    font-size: 15px !important;
    margin-bottom: 16px !important;
  }
  
  .daily-tip-widget button {
    padding: 10px 20px !important;
    font-size: 14px !important;
  }
}

/* ===== 16. Newsletter Section ===== */
@media screen and (max-width: 767px) {
  .newsletter-section {
    margin: 0 0 32px 0 !important;
    padding: 0 16px !important;
  }
  
  .newsletter-section > div {
    padding: 28px 20px !important;
    border-radius: 16px !important;
  }
  
  .newsletter-section h3 {
    font-size: 19px !important;
    margin-bottom: 10px !important;
  }
  
  .newsletter-section p {
    font-size: 14px !important;
    margin-bottom: 20px !important;
  }
  
  .newsletter-section form {
    flex-direction: column !important;
    gap: 12px !important;
    max-width: 100% !important;
  }
  
  .newsletter-section input[type="email"] {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
  }
  
  .newsletter-section button {
    width: 100% !important;
  }
}

/* ===== 17. Footer ===== */
@media screen and (max-width: 767px) {
  .site-footer,
  .modern-health-footer {
    padding: 32px 16px !important;
  }
  
  .footer-widgets {
    display: block !important;
    grid-template-columns: 1fr !important;
  }
  
  .footer-widget {
    margin-bottom: 24px !important;
  }
  
  .footer-widget h3 {
    font-size: 18px !important;
    margin-bottom: 12px !important;
  }
  
  .footer-bottom {
    flex-direction: column !important;
    text-align: center !important;
    gap: 12px !important;
  }
}

/* ===== 18. Header / الهيدر ===== */
@media screen and (max-width: 767px) {
  .site-header {
    padding: 12px 16px !important;
  }
  
  .site-header .logo {
    max-width: 150px !important;
  }
  
  .site-header .logo img {
    max-height: 40px !important;
    width: auto !important;
  }
}

/* ===== 19. إصلاح العناصر الطويلة والنصوص ===== */
@media screen and (max-width: 767px) {
  /* منع النصوص الطويلة من الخروج */
  p, li, span, div {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
  }
  
  /* الروابط الطويلة */
  a {
    word-break: break-word;
  }
  
  /* الكود */
  pre, code {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
  }
}

/* ===== 20. تحسينات الأداء ===== */
@media screen and (max-width: 767px) {
  /* تقليل الظلال لتحسين الأداء */
  *[style*="box-shadow"] {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
  }
  
  /* تبسيط التدرجات */
  *[style*="linear-gradient"] {
    background-attachment: scroll !important;
  }
  
  /* إيقاف الأنيميشن المعقدة */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
}

/* ===== 21. تحسينات iOS Safari ===== */
@supports (-webkit-touch-callout: none) {
  /* إصلاح مشاكل الارتفاع في iOS */
  body {
    min-height: -webkit-fill-available;
  }
  
  /* إصلاح position fixed في iOS */
  .site-header {
    position: -webkit-sticky;
    position: sticky;
  }
  
  /* تحسين التمرير */
  * {
    -webkit-overflow-scrolling: touch;
  }
}

/* ===== 22. Landscape Mode / الوضع الأفقي ===== */
@media screen and (max-width: 767px) and (orientation: landscape) {
  .medical-tips-hero {
    padding: 24px 0 !important;
    min-height: auto !important;
  }
  
  .medical-tips-hero h1 {
    font-size: 24px !important;
    margin-bottom: 8px !important;
  }
  
  /* تقليل المسافات في الوضع الأفقي */
  section {
    margin-bottom: 24px !important;
    padding-top: 16px !important;
    padding-bottom: 16px !important;
  }
}

/* ===== 23. Dark Mode Support ===== */
@media (prefers-color-scheme: dark) {
  /* سيتم إضافة الدعم لاحقاً إذا لزم الأمر */
}

/* ===== 24. إخفاء Scroll Bar في Mobile ===== */
@media screen and (max-width: 767px) {
  /* إخفاء scrollbar مع الحفاظ على وظيفة التمرير */
  ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }
  
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  
  ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
  }
}

/* ===== 25. Loading States / حالات التحميل ===== */
@media screen and (max-width: 767px) {
  .loading,
  .skeleton {
    animation: pulse 1.5s ease-in-out infinite;
  }
  
  @keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
  }
}

/* ===== 26. إصلاحات نهائية ===== */
@media screen and (max-width: 767px) {
  /* منع تكبير النص عند التدوير في iOS */
  html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
  }
  
  /* منع bounce effect في iOS */
  body {
    overscroll-behavior-y: contain;
  }
  
  /* تحسين اللمس */
  a, button, input, textarea, select {
    touch-action: manipulation;
  }
  
  /* إزالة outline للمستخدمين الذين يستخدمون اللمس */
  *:focus:not(:focus-visible) {
    outline: none;
  }
}

/* ===== 27. Print Styles ===== */
@media print {
  .site-header,
  .site-footer,
  button,
  .btn {
    display: none !important;
  }
  
  body {
    font-size: 12pt;
    line-height: 1.5;
  }
  
  .tip-card {
    page-break-inside: avoid;
  }
}

/* ===== 28. إصلاح التمرير باللمس (إصبع واحد) ===== */
/* هذا القسم مهم جداً لحل مشكلة التمرير بإصبعين */

/* تفعيل التمرير بإصبع واحد لجميع العناصر */
html, body {
  touch-action: manipulation !important;
  -webkit-overflow-scrolling: touch !important;
  -ms-touch-action: manipulation !important;
}

/* السماح بالتمرير والتكبير العادي */
* {
  touch-action: manipulation !important;
  -ms-touch-action: manipulation !important;
}

/* تحسين التمرير في المحتوى */
.site-content,
main,
article,
section,
div {
  -webkit-overflow-scrolling: touch !important;
  touch-action: manipulation !important;
}

/* إزالة أي قيود على اللمس */
a, button, input, select, textarea, [role="button"], [onclick], label {
  touch-action: manipulation !important;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* السماح بتحديد النص في الحقول */
input, textarea {
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
}

/* إزالة delay 300ms في اللمس */
a, button, input, select, textarea {
  -ms-touch-action: manipulation;
  touch-action: manipulation;
}

/* تحسين overscroll behavior */
body {
  overscroll-behavior: contain;
  overscroll-behavior-y: auto;
  overscroll-behavior-x: none;
}

/* للمتصفحات القديمة */
html {
  -ms-overflow-style: -ms-autohiding-scrollbar;
  -webkit-overflow-scrolling: touch;
}

/* إصلاح خاص لـ iOS Safari */
@supports (-webkit-touch-callout: none) {
  html, body {
    -webkit-overflow-scrolling: touch !important;
    touch-action: manipulation !important;
  }
  
  * {
    -webkit-overflow-scrolling: touch;
    touch-action: manipulation !important;
  }
}

/* إصلاح خاص لـ Android */
@media screen and (max-width: 767px) {
  html, body {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: manipulation !important;
    position: relative;
  }
  
  body {
    min-height: 100vh;
    min-height: -webkit-fill-available;
  }
  
  html {
    height: -webkit-fill-available;
  }
}
