/* ===========================
   CSS محسّن لصفحة المعرفة
   تم التوحيد مع الصفحة الرئيسية مع الحفاظ على الهيكل
=========================== */

/* ===== المتغيرات الأساسية ===== */
:root {
  /* الألوان */
  --bg-color: #f5f7fb;
  --text-color: #1f2937;
  --primary-text: #1f2937;
  --secondary-text: #6b7280;
  --card-bg: #ffffff;
  --accent-color: #2f71d3;
  --accent-hover: #1d4ed8;
  --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);
  --shadow-hover: 0 20px 25px rgba(0,0,0,0.15);
  
  /* الأنماط */
  --border-radius: 12px;
  --border-radius-sm: 8px;
  
  /* التحويلات */
  --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: #f9fafb;
  --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 {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== الأساسيات المحسنة ===== */
* {
  box-sizing: border-box;
}

html, body {
  overflow-x: hidden;
  scroll-behavior: smooth;
  font-family: 'Cairo', system-ui, sans-serif;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  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;
}

/* ===========================
   بطاقة الإشعار
=========================== */
.notice-card {
  max-width: min(1000px, 95vw);
  margin: 90px auto 2rem;
  padding: 1.5rem 2rem;
  background: var(--card-bg);
  border-right: 4px solid var(--accent-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  text-align: center;
  transition: all var(--transition-fast) ease;
  position: relative;
}

/* بوردر جانبي للإشعار */
.notice-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;
}

.notice-card h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  color: var(--primary-text);
  margin-bottom: 0.75rem;
  position: relative;
  z-index: 1;
}

.notice-card p {
  font-size: 1.125rem;
  color: var(--secondary-text);
  margin: 0;
  position: relative;
  z-index: 1;
}

.notice-card a {
  color: var(--accent-color);
  font-weight: 600;
  text-decoration: none;
  transition: color var(--transition-fast) ease;
}

.notice-card a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ===========================
   الحاوية الرئيسية
=========================== */
#knowledge-container {
  max-width: min(1000px, 95vw);
  margin: 0 auto 3rem;
  padding: 0 1rem;
}

/* ===========================
   شبكة البطاقات
=========================== */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
  align-items: start;
}

/* ===========================
   بطاقات المعرفة
=========================== */
.knowledge-card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: all var(--transition-fast) ease;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 400px;
  position: relative;
}

/* بوردر جانبي للبطاقات */
.knowledge-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;
  z-index: 1;
}

.knowledge-card:hover::before {
  opacity: 1;
  width: 5px;
}

.knowledge-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent-color);
}

.knowledge-card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  background: var(--border-color);
  transition: transform var(--transition-fast) ease;
}

.knowledge-card:hover img {
  transform: scale(1.05);
}

.knowledge-card h3 {
  margin: 1rem 1rem 0.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--primary-text);
  text-align: center;
  line-height: 1.4;
  position: relative;
  z-index: 1;
}

.knowledge-card .card-content {
  padding: 0 1rem 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

.knowledge-card .card-content p {
  margin: 0 0 1rem 0;
  color: var(--secondary-text);
  line-height: 1.6;
  text-align: justify;
  flex: 1;  
}

.knowledge-card .read-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  background: var(--accent-color);
  color: white;
  border-radius: var(--border-radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--transition-fast) ease;
  border: none;
  cursor: pointer;
  align-self: flex-start;
  margin-top: auto;
}

.knowledge-card .read-more:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.card-content a {
  color: var(--accent-color);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition-fast) ease;
}

.card-content a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ===========================
   زر تحميل المزيد
=========================== */
#loadMoreWrapper {
  text-align: center;
  margin-top: 3rem;
}

.load-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.875rem 2rem;
  background: var(--accent-color);
  color: white;
  border-radius: 50px;
  font-weight: 700;
  font-size: 1rem;
  transition: all var(--transition-fast) ease;
  border: none;
  cursor: pointer;
  font-family: 'Cairo', sans-serif;
  position: relative;
  overflow: hidden;
}

.load-more::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left var(--transition-slow) ease;
}

.load-more:hover::before {
  left: 100%;
}

.load-more:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* ===========================
   رسالة نهاية المحتوى
=========================== */
.no-more-content {
  text-align: center;
  padding: 2rem;
  color: #666;
  background: #f8f9fa;
  border-radius: 10px;
  margin: 1rem 0;
  grid-column: 1 / -1;
}

.no-more-content p {
  margin: 0 0 0.5rem 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.no-more-content small {
  color: #888;
  font-size: 0.9rem;
}

/* ===========================
   حالات التحميل والأخطاء المحسنة
=========================== */
.loading-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--secondary-text);
  grid-column: 1 / -1;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  margin: 20px 0;
  transition: all var(--transition-fast) ease;
  position: relative;
  overflow: hidden;
}

.loading-state::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(47, 113, 211, 0.1), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(47, 113, 211, 0.2);
  border-top: 4px solid var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
  position: relative;
  z-index: 1;
}

.loading-spinner-small {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 8px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-state p {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 500;
  position: relative;
  z-index: 1;
}

.error-state {
  text-align: center;
  padding: 40px 20px;
  background: #fff3cd;
  border: 1px solid #ffeaa7;
  border-radius: var(--border-radius);
  color: #856404;
  grid-column: 1 / -1;
  margin: 20px 0;
}

.retry-btn {
  padding: 10px 20px;
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  margin-top: 15px;
  font-family: 'Cairo', sans-serif;
  transition: background var(--transition-fast) ease;
}

.retry-btn:hover {
  background: var(--accent-hover);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--secondary-text);
  background: var(--card-bg);
  border: 1px dashed var(--border-color);
  border-radius: var(--border-radius);
  grid-column: 1 / -1;
  margin: 20px 0;
  transition: all var(--transition-fast) ease;
  position: relative;
}

.empty-state p {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 500;
}

/* ===========================
   🎨 تحسينات الوضع الداكن للرسائل
=========================== */

body.dark-mode .loading-state {
  background: linear-gradient(135deg, #111827 0%, #1a2846 100%);
  color: #f0f0f0;
  border: 1px solid #444;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

body.dark-mode .loading-state p {
  color: #e0e0e0;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

body.dark-mode .loading-spinner {
  border: 4px solid rgba(59, 130, 246, 0.2);
  border-top: 4px solid #3b82f6;
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

body.dark-mode .error-state {
  background: #332701;
  border: 1px solid #665200;
  color: #ffd351;
}

body.dark-mode .empty-state {
  background: linear-gradient(135deg, #111827 0%, #1c2d52 100%);
  color: #aaa;
  border: 1px dashed #555;
}

body.dark-mode .no-more-content {
  background: #1f2937;
  color: #d1d5db;
  border: 1px solid #374151;
}

body.dark-mode .no-more-content small {
  color: #9ca3af;
}

/* بوردر جانبي في الوضع الداكن */
body.dark-mode .knowledge-card::before,
body.dark-mode .notice-card::before {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
}

/* ===========================
   التجاوب الكامل مع تحسينات الرسائل
=========================== */

/* 🔹 الشاشات المتوسطة (768px) */
@media (max-width: 768px) {
  .notice-card {
    margin: 80px auto 1.5rem;
    padding: 1.25rem 1.5rem;
  }
  
  .notice-card h1 {
    font-size: clamp(1rem, 5vw, 1.5rem);
  }
  
  #knowledge-container {
    padding: 0 0.5rem;
  }
  
  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
  }
  
  .knowledge-card h3 {
    font-size: 1rem;
  }
  
  .loading-state,
  .error-state,
  .empty-state,
  .no-more-content {
    padding: 30px 15px;
  }
  
  .loading-state p,
  .empty-state p {
    font-size: 1rem;
  }
  
  .loading-spinner {
    width: 40px;
    height: 40px;
  }
}

/* 🔹 الشاشات الصغيرة (480px) */
@media (max-width: 480px) {
  .notice-card {
    margin: 70px 0.5rem 1rem;
    padding: 1rem 1.25rem;
  }
  
  .cards-grid {
    grid-template-columns: 1fr;
  }
  
  .knowledge-card img {
    height: 160px;
  }
  
  .load-more {
    padding: 0.75rem 1.5rem;
    font-size: 0.875rem;
  }
  
  .knowledge-card .card-content p {
    text-align: right;
  }
  
  .loading-state,
  .error-state,
  .empty-state,
  .no-more-content {
    padding: 25px 12px;
    margin: 10px 0;
  }
  
  .loading-state p,
  .empty-state p {
    font-size: 0.95rem;
  }
  
  .loading-spinner {
    width: 35px;
    height: 35px;
    margin-bottom: 15px;
  }
  
  .retry-btn {
    padding: 8px 16px;
    font-size: 0.875rem;
  }
}

/* 🔹 الشاشات الصغيرة جداً (360px) */
@media (max-width: 360px) {
  .loading-state p,
  .empty-state p {
    font-size: 0.9rem;
    padding: 0 5px;
  }
  
  .loading-state,
  .empty-state {
    padding: 20px 10px;
  }
  
  .loading-spinner {
    width: 30px;
    height: 30px;
    margin-bottom: 12px;
  }
}

/* 🔹 الشاشات الكبيرة جداً (1600px) */
@media (min-width: 1600px) {
  #knowledge-container,
  .notice-card {
    max-width: 1200px;
  }
}

/* 🔹 تحسينات للطابعات */
@media print {
  .load-more,
  .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;
}

/* 🔹 تحسينات للأجهزة ذات اللمس */
@media (hover: none) and (pointer: coarse) {
  .loading-state,
  .error-state,
  .empty-state {
    min-height: 160px;
  }
  
  .retry-btn {
    padding: 12px 24px;
    font-size: 16px;
  }
}

/* 🔹 تحسينات للشاشات عالية الدقة */
@media (min-resolution: 192dpi) {
  .loading-spinner {
    border-width: 3px;
  }
}