/* ===========================
   CSS محسّن لموقع إخباري حديث
   تم التنظيم والتحسين للأداء مع الحفاظ على الأبعاد
=========================== */

/* ===== المتغيرات الأساسية ===== */
:root {
  /* الألوان */
  --bg-color: #f5f7fb;
  --text-color: #1f2937;
  --primary-text: #6b7280;
  --secondary-text: #39393a;
  --card-bg: #ffffff;
  --accent-color: #2f71d3;
  --accent-hover: #1d4ed8;
  --btn-bg: var(--accent-color);
  --btn-color: #fff;
  --border-color: #f3f4f6;
  
  /* الظلال */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
  
  /* الأنماط */
  --border-radius: 10px;
  --border-radius-sm: 6px;
  
  /* التحويلات */
  --transition-fast: 0.3s;
  --transition-slow: 0.8s;
}

/* تحسين تحميل الخطوط */
@font-face {
  font-family: 'Cairo';
  font-display: swap;
}

/* الوضع الداكن */
body.dark-mode {
  --bg-color: #111827;
  --text-color: #f9fafb;
  --primary-text: #d1d5db;
  --secondary-text: #9ca3af;
  --card-bg: #1f2937;
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --border-color: #374151;
}

/* تحسينات متقدمة للوضع الداكن */
body.dark-mode img {
  filter: brightness(0.9) contrast(1.1);
}

body.dark-mode .slide-content {
  background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
}

/* تحسين النص في الوضع الداكن */
body.dark-mode {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== الأساسيات ===== */
html, body {
  overflow-x: hidden;
  scroll-behavior: smooth;
  font-family: 'Cairo', Arial, sans-serif;
  margin: 0;
}

body {
  background: var(--bg-color);
  color: var(--text-color);
  transition: background var(--transition-fast), color var(--transition-fast);
}

/* تحسينات للأداء */
img {
  content-visibility: auto;
}

/* تحسينات للرسوم المتحركة */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* تحسينات للوصول */
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/* ===== رسائل التحميل المحسنة ===== */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  text-align: center;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(47, 113, 211, 0.2);
  border-left: 4px solid var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 15px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-state p {
  color: var(--secondary-text);
  font-size: 16px;
  margin: 0;
}

.error-state {
  background: #fff3cd;
  border: 1px solid #ffeaa7;
  border-radius: var(--border-radius);
  padding: 20px;
  text-align: center;
  color: #856404;
}

.retry-btn {
  background: var(--accent-color);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  margin-top: 10px;
  transition: background var(--transition-fast);
}

.retry-btn:hover {
  background: var(--accent-hover);
}

.empty-state {
  text-align: center;
  color: var(--secondary-text);
  padding: 30px 20px;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  border: 1px dashed var(--border-color);
}
.empty-state p {
    margin: 0 0 10px 0;
    font-size: 1.1em;
}

.empty-state small {
    display: block;
    margin-top: 5px;
}

/* ===== السلايدر ===== */
#slider-container {
  position: relative;
  width: 100%;
  max-width: 1000px;
  margin: 70px auto 20px;
  overflow: hidden;
  border-radius: none;
  box-shadow: var(--shadow-lg);
}

#slider-wrapper {
  position: relative;
  width: 100%;
  height: clamp(350px, 50vh, 750px);
  overflow: hidden;
  border-radius: none;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.slide {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s ease-in-out;
}

.slide.active {
  opacity: 1;
  visibility: visible;
  z-index: 2;
}

#slider-container .slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: none;
  border: 2px solid var(--accent-color);
  margin: 0;
  padding: 0;
  background: #a3a0a0;
}

/* تحسين نص السلايدر للتجاوب */
.slide-content {
  position: absolute;
  bottom: 0;
  right: 0;
  left: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
  color: #fff;
  padding: 20px 15px 15px;
  z-index: 3;
}

.slide-title {
  margin: 0;
  font-size: clamp(18px, 4vw, 28px);
  font-weight: bold;
  line-height: 1.3;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.7);
}

.slide-meta {
  font-size: clamp(12px, 3vw, 16px);
  opacity: 0.9;
  margin-top: 5px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
}

/* ===== أزرار السلايدر ===== */
.slider-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.4);
  color: white;
  border: none;
  font-size: 16px;
  padding: 10px 14px;
  cursor: pointer;
  border-radius: 50%;
  z-index: 4;
  transition: background 0.3s;
}

.slider-btn.prev { left: 15px; }
.slider-btn.next { right: 15px; }
.slider-btn:hover { background: rgba(0,0,0,0.7); }

/* ===== مؤشرات السلايدر ===== */
#slider-indicators {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 3;
}

#slider-indicators span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(255,255,255,0.8);
  cursor: pointer;
  border: 1px solid #fff;
  transition: background 0.3s, transform 0.3s;
}

#slider-indicators span:hover {
  transform: scale(1.1);
}

#slider-indicators .active {
  background: var(--accent-color);
  border: 1px solid #fff;
}
/* هذا النمط لإخفاء المحتوى عن البشر فقط - مهم لتحسين تجربة المستخدم */
.visually-hidden-for-humans {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    
    /* التأكد من عدم التسبب في أي مشاكل مرئية */
    visibility: hidden !important;
    opacity: 0 !important;
}
/* ===== توزيع الأقسام ===== */
#news-section {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  max-width: 1200px;
  margin: 30px auto;
  flex-wrap: nowrap;
}

.news-column {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.news-column h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-color);
  border-right: 4px solid var(--accent-color);
  padding-right: 8px;
  margin-bottom: 10px;
  display: inline-block;
  box-sizing: border-box;
}

/* كل قسم يأخذ نسبة معينة */
#latest-news {
  flex: 0 0 54%;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

#most-read {
  flex: 0 0 21%;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

#forYouSection {
  flex: 0 0 21%;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* ===== قسم آخر الأخبار ===== */
#latest-news .section-title,
#most-read .section-title,
#forYouSection .section-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-color);
  border-bottom: 2px solid var(--accent-color);
  padding-bottom: 6px;
  margin-bottom: 0px;
}

#latest-news .related-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 10px;
  margin-bottom: 8px;
  overflow: hidden;
  transition: transform var(--transition-fast) ease, box-shadow var(--transition-fast) ease;
  position: relative;
  min-height: 120px; /* إضافة ارتفاع أدنى */
}

/* بوردر جانبي للبطاقات - مرئي دائمًا */
#latest-news .related-card::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(135deg, var(--accent-color), #8b5cf6);
  border-radius: 0 var(--border-radius) var(--border-radius) 0;
  opacity: 0.7;
  transition: opacity var(--transition-fast) ease, width var(--transition-fast) ease;
}

#latest-news .related-card:hover::before {
  opacity: 1;
  width: 5px;
}

#latest-news .related-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

#latest-news .related-card .text-content {
  display: flex;
  align-items: flex-start; /* تغيير من center إلى flex-start */
  gap: 12px;
}

#latest-news .related-card h4 {
  font-size: 1rem;
  margin: 0;
  color: var(--text-color);
  flex: 1; /* إضافة flex:1 */
}

#latest-news .related-card .bottom-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-end; /* تغيير من center إلى flex-end */
  gap: 10px;
  margin-top: auto; /* إضافة لجعل المحتوى يلتصق بالأسفل */
  padding-top: 8px; /* إضافة مسافة علوية */
}

#latest-news .related-card .snippet-container {
  flex: 1;
  display: flex;
  align-items: center;
  min-height: 40px; /* ارتفاع ثابت للمحتوى المختصر */
}

#latest-news .related-card .bottom-content .snippet {
  font-size: 0.9rem;
  color: var(--secondary-text);
  margin: 0;
  line-height: 1.4;
  flex: 1;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

 .read-more {
  display: inline-block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  padding: 2px 8px;
  background: var(--btn-bg);
  color: var(--btn-color);
  border-radius: var(--border-radius-sm);
  font-size: 0.85rem;
  transition: background var(--transition-fast) ease;
  text-decoration: none;
}

.read-more:hover {
  background: var(--accent-hover);
  transform: translateY(-1px); /* إضافة تأثير عند hover */
}

/* ===== قسم التصنيفات ===== */
#category-section {
  display: flex;
  flex-wrap: wrap;
  gap: 30px;
  max-width: 1200px;
  margin: 30px auto;
}

#category-section .news-column {
  flex: 0 0 23%;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

#category-section .news-column h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-color);
  border-bottom: 2px solid var(--accent-color);
  padding-bottom: 6px;
  margin-bottom: 0;
}

/* ===== الأنماط المشتركة للأقسام ===== */
#most-read .related-card,
#forYouContainer .related-card,
#category-section .related-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 10px;
  margin-bottom: 15px;
  gap: 15px;
  text-align: center;
  overflow: hidden;
  transition: transform var(--transition-fast) ease, box-shadow var(--transition-fast) ease;
  position: relative;
}

/* بوردر جانبي للبطاقات الجانبية - مرئي دائمًا */
#most-read .related-card::before,
#forYouContainer .related-card::before,
#category-section .related-card::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(135deg, var(--accent-color), #8b5cf6);
  border-radius: 0 var(--border-radius) var(--border-radius) 0;
  opacity: 0.7;
  transition: opacity var(--transition-fast) ease, width var(--transition-fast) ease;
}

#most-read .related-card:hover::before,
#forYouContainer .related-card:hover::before,
#category-section .related-card:hover::before {
  opacity: 1;
  width: 5px;
}

#most-read .related-card:hover,
#forYouContainer .related-card:hover,
#category-section .related-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

#most-read .related-card .snippet,
#forYouContainer .related-card .snippet,
#category-section .related-card .snippet {
  font-size: 0.9rem;
  margin: 0;
  color: var(--secondary-text);
  line-height: 1.8;
  display: inline;
}


#most-read .related-card h4,
#forYouContainer .related-card h4,
#category-section .related-card h4 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-color);
  margin: 0;
  padding: 0;
}

/* ===== الصور - الحفاظ على الأبعاد الأصلية ===== */
#latest-news .related-card img,
#most-read .related-card img,
#forYouContainer .related-card img,
#category-section .related-card img {
  width: 215px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--border-radius);
  border: 2px solid var(--accent-color);
  flex-shrink: 0;
  margin: 0;
  padding: 0;
  margin-bottom: 10px;
  background: #a3a0a0;
}

/* ===== تحسينات إضافية للتحميل ===== */
.slider-loading,
.slider-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
}

.slider-loading p,
.slider-error p {
  color: var(--secondary-text);
  font-size: 16px;
  margin: 0;
}

/* تحسينات للوضع الداكن */
body.dark-mode .error-state {
  background: #332701;
  border-color: #665200;
  color: #ffd351;
}

body.dark-mode .empty-state {
  background: var(--card-bg);
  color: var(--secondary-text);
  border-color: var(--border-color);
}

/* بوردر جانبي في الوضع الداكن */
body.dark-mode #latest-news .related-card::before,
body.dark-mode #most-read .related-card::before,
body.dark-mode #forYouContainer .related-card::before,
body.dark-mode #category-section .related-card::before {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
}

/* ===== 🎨 نظام التحميل المتميز في الوضع الداكن ===== */

body.dark-mode .loading-state {
    background: linear-gradient(135deg, #111827 0%, #1a2846 100%) !important;
    color: #f0f0f0 !important;
    border: 1px solid #444 !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
}

body.dark-mode .loading-state::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.1), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

body.dark-mode .loading-state p {
    color: #e0e0e0 !important;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    font-weight: 500;
    position: relative;
    z-index: 1;
}

body.dark-mode .loading-spinner {
    border: 4px solid rgba(59, 130, 246, 0.2) !important;
    border-top: 4px solid #3b82f6 !important;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
    position: relative;
    z-index: 1;
}

/* تحسينات إضافية لللمسة النهائية */
body.dark-mode .error-state {
    background: linear-gradient(135deg, #332701 0%, #443a01 100%) !important;
    border: 1px solid #665200 !important;
    color: #ffd351 !important;
    box-shadow: 0 4px 15px rgba(255, 211, 81, 0.1);
}

body.dark-mode .empty-state {
    background: linear-gradient(135deg, #111827 0%, #1c2d52 100%) !important;
    color: #aaa !important;
    border: 1px dashed #555 !important;
}

/* ===========================
   التجاوب للصفحة الرئيسية محسّن
=========================== */

/* 🔹 الشاشات المتوسطة (1200px) */
@media (max-width: 1200px) {
  #news-section,
  #category-section {
    gap: 10px;
  }

  #latest-news {
    flex: 0 0 50%;
  }

  #most-read,
  #forYouSection {
    flex: 0 0 20%;
  }
  #category-section .news-column {
    flex: 0 0 24%;
    gap: 10px;
  }
  
  /* تحسينات السلايدر للشاشات المتوسطة */
  #slider-wrapper {
    height: clamp(280px, 45vh, 500px);
  }
}
/* 🔹 الشاشات اللوحية (1024px) */
@media (max-width: 1024px) {
  /* تحسينات السلايدر للشاشات اللوحية */
  #slider-wrapper {
    height: clamp(320px, 40vh, 600px);
  }
  #slider-container .slide img {
    width: 100%;
    height: 100%;
  }
  .slide-content {
    padding: 15px 12px 12px;
  }
}
/* 🔹 الشاشات اللوحية (1024px) */
@media (max-width: 991px) {
  #news-section,
  #category-section {
    flex-direction: column;
    align-items: center;
    gap: 1px;
  }
  
  #latest-news,
  #most-read,
  #forYouSection,
  #category-section .news-column {
    flex: 0 0 100%;
    width: 100%;
    max-width: 950px;
  }
  .news-column h2,
  #latest-news .section-title,
  #most-read .section-title,
  #forYouSection .section-title {
    font-size: 24px;
    text-align: center;
  }
  .related-card {
    text-align: center;
    align-items: center;
    gap: 1px;
  }

  #category-section .related-card img,
  #latest-news .related-card img,
  #most-read .related-card img,
  #forYouSection .related-card img {
    width: 100%;
    height: auto;
    object-fit: cover;
  }

  #latest-news .related-card .text-content {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
  }

  #latest-news .related-card .bottom-content {
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
  }

  #latest-news .related-card .snippet-container {
    min-height: auto;
  }

  #latest-news .related-card .bottom-content .snippet {
    text-align: center;
    -webkit-line-clamp: 3;
  }

  .related-card h4 {
    font-size: 1rem;
    text-align: center;
  }

  .related-card .snippet {
    font-size: 0.9rem;
    line-height: 1.7;
  }

}

/* 🔹 الشاشات الصغيرة (768px) */
@media (max-width: 768px) {
  #slider-container {
    margin: 60px auto 15px;
    margin-bottom: 0;
    padding-bottom: 0;
    border-radius: none;
  }
  
  #slider-wrapper {
    height: clamp(200px, 35vh, 350px);
    border-radius: none;
  }

  #slider-container .slide img {
    width: 100%;
    height: 100%;
  }
  .slide-title {
    font-size: 16px;
  }
  .slide-meta {
    font-size: 11px;
  }
  .news-column h2,
  #latest-news .section-title,
  #most-read .section-title,
  #forYouSection .section-title {
    font-size: 24px;
    text-align: center;
    padding: 1px;
  }

  #news-section,
  #category-section {
    flex-direction: column;
    align-items: center;
    gap: 1px;
  }

  .related-card {
    padding: 1px;
    gap: 1px;
    border-radius: var(--border-radius);
  }
  
  #category-section .related-card img,
  #latest-news .related-card img,
  #most-read .related-card img,
  #forYouSection .related-card img {
    width: 98%;
    height: auto;
    object-fit: cover;
  }

  .related-card h4 {
    font-size: 1rem;
    text-align: center;
  }

  .related-card .snippet {
    font-size: 0.9rem;
    line-height: 1.7;
  }
  
  /* تحسينات السلايدر للشاشات الصغيرة */
  .slide-content {
    padding: 12px 10px 10px;
  }
  
  .slider-btn {
    padding: 8px 12px;
    font-size: 14px;
  }
  
  #slider-indicators span {
    width: 12px;
    height: 12px;
  }
}

/* 🔹 الشاشات الصغيرة جداً (480px) */
@media (max-width: 480px) {
  #slider-container {
    margin: 50px auto 10px;
  }
  
  #slider-wrapper {
    height: clamp(180px, 30vh, 280px);
  }

  #slider-container .slide img {
    height: 100%;
  }
  .slide-title {
    font-size: 14px;
  }
  .slide-meta {
    font-size: 10px;
  }
  .news-column h2,
  #latest-news .section-title,
  #most-read .section-title,
  #forYouSection .section-title {
    font-size: 22px;
    text-align: center;
  }

  .related-card img {
    width: 100%;
    height: auto;
    border-radius: 8px;
    object-fit: cover;
  }

  .related-card h4 {
    font-size: 0.95rem;
    text-align: center;
  }

  #latest-news .related-card .bottom-content .snippet {
    -webkit-line-clamp: 4;
  }
  
  /* تحسينات السلايدر للشاشات الصغيرة جداً */
  .slide-content {
    padding: 10px 8px 8px;
  }
  
  .slider-btn {
    padding: 6px 10px;
    font-size: 12px;
  }
  
  #slider-indicators {
    bottom: 12px;
  }
  
  #slider-indicators span {
    width: 10px;
    height: 10px;
  }

}

/* 🔹 الشاشات الصغيرة جداً (360px) */
@media (max-width: 360px) {
  #slider-wrapper {
    height: clamp(150px, 25vh, 220px);
  }
  
  .slide-content {
    padding: 8px 6px 6px;
  }
  
  .slide-title {
    font-size: 12px;
  }
  
  .slide-meta {
    font-size: 9px;
  }
}

/* 🔹 الشاشات الكبيرة جداً (1600px) */
@media (min-width: 1600px) {
  #news-section,
  #category-section {
    max-width: 1400px;
  }
}

/* 🔹 تحسينات للطابعات */
@media print {
  .slider-btn,
  #slider-indicators,
  .read-more {
    display: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
}

/* 🔹 تحسينات للوصول */
@media (prefers-contrast: high) {
  :root {
    --accent-color: #0000ff;
    --text-color: #000000;
  }
}

/* تحسينات للقراءة */
.article-content {
  line-height: 1.7;
  max-width: 65ch;
}