/* ====================================================================
   Expert Soroban Design System - Main Entry Point
   نقطة الدخول الرئيسية لنظام التصميم مع بنية ITCSS
   
   ITCSS (Inverted Triangle CSS) Import Order:
   1-foundations → 2-utilities → 3-components → 4-layouts → 5-themes
   
   نظام متقدم للتصميم يدعم:
   - الثيمات المتعددة والتبديل التلقائي
   - إمكانية الوصول الكاملة (WCAG 2.1)
   - التصميم المتجاوب
   - أفضل الممارسات في الأداء
   ==================================================================== */

/* ==================== 1. FOUNDATIONS LAYER ==================== */
/* أسس التصميم: متغيرات، إعادة تعيين، قواعد أساسية */

@import './1-foundations/tokens.css';
@import './1-foundations/base.css';

/* ==================== 2. UTILITIES LAYER ==================== */
/* فئات مساعدة سريعة: هامش، محاذاة، ألوان سريعة */

@import './2-utilities/helpers.css';

/* ==================== 3. COMPONENTS LAYER ==================== */
/* مكونات قابلة لإعادة الاستخدام: أزرار، بطاقات، نماذج */

@import './3-components/buttons/buttons.css';
@import './3-components/cards/cards.css';
@import './3-components/cards/enhanced-cards.css';
@import './3-components/forms/forms.css';
@import './3-components/tables/tables.css';
@import './3-components/notifications.css';
@import './3-components/search.css';
@import './3-components/statistics.css';
@import './3-components/user-menu.css';
@import './3-components/mobile-nav.css';
@import './3-components/leaderboard-styles.css';

/* ==================== 4. LAYOUTS LAYER ==================== */
/* تخطيطات الصفحات: شبكة، حاويات، تخطيطات مركبة */

@import './4-layouts/layouts.css';
@import './4-layouts/landing-page.css';

/* ==================== 5. THEMES LAYER ==================== */
/* متغيرات الثيم والتخصيصات النهائية */

@import './5-themes/themes.css';

/* ====================================================================
   طباعة معلومات النظام في Console للتطوير
   ==================================================================== */

/* CSS Debug Info - يظهر في Developer Tools */
body::before {
  content: "Expert Soroban Design System v4.0 - ITCSS Architecture Loaded ✓";
  display: none;
  /* مخفي عن المستخدم، لكن موجود للـ DevTools */
}

/* ====================================================================
   تحسينات الأداء العامة
   ==================================================================== */

/* تحسين الأداء للعناصر المتحركة */
.gpu-accelerated {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
  will-change: transform, opacity;
}

/* إزالة will-change بعد انتهاء الحركة */
.gpu-accelerated.animation-complete {
  will-change: auto;
}

/* ====================================================================
   دعم الـ Critical CSS والتحميل التدريجي
   ==================================================================== */

/* إخفاء المحتوى حتى تحميل CSS كاملاً */
.css-loading {
  visibility: hidden;
}

/* إظهار المحتوى بعد تحميل CSS */
.css-loaded {
  visibility: visible;
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* ====================================================================
   دعم المتصفحات القديمة
   ==================================================================== */

/* Fallback للمتصفحات التي لا تدعم CSS Grid */
@supports not (display: grid) {
  .grid {
    display: flex;
    flex-wrap: wrap;
  }

  .grid>* {
    flex: 1 1 300px;
    margin: var(--space-3);
  }
}

/* Fallback للمتصفحات التي لا تدعم CSS Custom Properties */
@supports not (color: var(--color-primary-600)) {
  :root {
    /* استخدام قيم ثابتة كبديل */
    color: #0f172a;
    background-color: #ffffff;
  }

  .btn-primary {
    background-color: #0ea5e9;
    color: white;
  }

  .card {
    background-color: white;
    border: 1px solid #e2e8f0;
  }
}

/* ====================================================================
   تحسينات خاصة بـ Expert Soroban
   ==================================================================== */

/* تصميم خاص بتطبيق السوروبان */
.soroban-bead {
  display: inline-block;
  width: var(--space-4);
  height: var(--space-4);
  background: linear-gradient(135deg, var(--color-primary-600), var(--color-primary-700));
  border-radius: var(--border-radius-full);
  box-shadow: var(--shadow-sm);
  margin: var(--space-1);
  transition: all var(--transition-fast);
}

.soroban-bead:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow);
}

/* أنماط خاصة بالإدارة الجغرافية */
.geographic-hierarchy {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.geographic-hierarchy .separator {
  color: var(--color-border);
}

.geographic-hierarchy .current {
  color: var(--color-primary-600);
  font-weight: var(--font-medium);
}

/* أنماط خاصة بحالات البيانات */
.data-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}

.data-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--space-6);
  height: var(--space-6);
  margin: calc(-1 * var(--space-3));
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary-600);
  border-radius: var(--border-radius-full);
  animation: spin 1s linear infinite;
}

.data-empty {
  text-align: center;
  padding: var(--space-12);
  color: var(--color-text-muted);
}

.data-error {
  background-color: var(--color-error-50);
  border: var(--border-width) solid var(--color-error-600);
  border-radius: var(--border-radius);
  padding: var(--space-4);
  color: var(--color-error-700);
}

/* ====================================================================
   نمط الطباعة المحسن
   ==================================================================== */

@media print {

  /* إخفاء عناصر التحكم في الطباعة */
  .no-print,
  .btn,
  .form-control,
  .sidebar,
  .nav,
  .pagination {
    display: none !important;
  }

  /* تحسين النصوص للطباعة */
  body {
    font-size: 12pt;
    line-height: 1.4;
    color: black;
    background: white;
  }

  .card {
    border: 1px solid black;
    break-inside: avoid;
    margin-bottom: 12pt;
  }

  .table {
    font-size: 10pt;
  }

  .table th,
  .table td {
    border: 1px solid black;
    padding: 4pt;
  }

  /* عناوين الصفحات */
  h1,
  h2,
  h3 {
    break-after: avoid;
    margin-top: 0;
  }

  /* تحسين الروابط للطباعة */
  a[href^="http"]:after {
    content: " (" attr(href) ")";
    font-size: 8pt;
    color: #666;
  }
}

/* ====================================================================
   تخصيصات النهاية وإعادة التعريف
   ==================================================================== */

/* يمكن إضافة تخصيصات خاصة بالمشروع هنا دون تعديل الملفات الأساسية */

/* مثال: تخصيص ألوان خاصة */
.expert-soroban-brand {
  --color-primary-600: #8b5cf6;
  /* بنفسجي مميز */
  --color-primary-700: #7c3aed;
  --color-primary-50: #f3f4f6;
}

/* مثال: تخصيص للوحة المدير */
.admin-dashboard {
  --sidebar-width: 18rem;
  --header-height: 4.5rem;
}

/* مثال: تخصيص للشاشات الكبيرة */
@media (min-width: 1920px) {
  .container {
    max-width: 1600px;
  }

  .grid-auto-fit {
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  }
}

/* ====================================================================
   نهاية نظام التصميم
   ==================================================================== */

/* ✅✅✅ صنف للصفحات التي تحتاج ملء الشاشة بالكامل ✅✅✅ */
.body-fullscreen {
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

.body-fullscreen .layout-main {
  height: 100vh;
  width: 100vw;
  margin: 0;
  padding: 0;
  overflow: auto;
}

/* معلومات النظام للمطورين */
/*
  Expert Soroban Design System v4.0
  Architecture: ITCSS (Inverted Triangle CSS)
  Layers: 5 (Foundations → Utilities → Components → Layouts → Themes)
  Features: RTL Support, Dark Mode, Accessibility, Responsive Design
  Browser Support: Modern browsers (ES6+)
  Last Updated: January 2025
*/
/* ==================== FORCED THEME OVERRIDES ==================== */

/* 1. إجبار الخلفية الشفافة في الوضع النهاري لإظهار التدرجات الشعاعية */
[data-theme="light"] body,
[data-theme="light"] .layout-main,
[data-theme="light"] .container-fluid {
  background-color: transparent !important;
  color: var(--color-text);
}

/* 2. التأكد من أن البطاقات بيضاء تماماً لتبرز فوق البيج */
[data-theme="light"] .card,
[data-theme="light"] .stat-card,
[data-theme="light"] .welcome-card {
  background-color: var(--color-surface) !important;
}

/* 3. إصلاح لون العناوين */
[data-theme="light"] h1,
[data-theme="light"] h2,
[data-theme="light"] h3,
[data-theme="light"] h4,
[data-theme="light"] h5,
[data-theme="light"] h6 {
  color: var(--color-text-primary);
}

/* ==================== Layout Header & Glass Buttons ==================== */
/* تطبيق الهوية البصرية الجديدة على الهيدر الأساسي للنظام */
.layout-header {
  background: linear-gradient(135deg, var(--sky-primary, #0ea5e9) 0%, var(--sky-light, #38bdf8) 100%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 10px 30px rgba(14, 165, 233, 0.15);
  border-radius: 0 0 24px 24px;
  position: sticky;
  top: 0;
  z-index: 1000;
  transition: all 0.3s ease;
}

[data-theme="dark"] .layout-header {
  background: linear-gradient(135deg, var(--royal-dark, #0c4a6e) 0%, var(--royal-primary, #075985) 100%);
  border-bottom: 1px solid rgba(56, 189, 248, 0.15);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* أزرار الهيدر الزجاجية الجديدة */
.header-glass-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff !important;
  backdrop-filter: blur(8px);
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.header-glass-btn:hover,
.header-glass-btn:focus {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.4);
  color: #ffffff !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .header-glass-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .header-glass-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.2);
}

/* تنسيقات نصوص الهيدر لضمان التباين */
.layout-header .page-header__title,
.layout-header .page-header__subtitle {
  color: #ffffff !important;
}

.layout-header .brand-icon {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}


/* --- تحسينات نافذة إعدادات الأسئلة --- */

/* رأس النافذة */
.modal-header-custom {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-bottom: 1px solid #dee2e6;
  padding: 1.5rem;
}

.modal-title-custom {
  font-weight: 800;
  color: var(--color-primary-700);
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* بطاقة الإعداد في القائمة */
.setting-card {
  background: #fff;
  border: 1px solid #edf2f7;
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.setting-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.05);
  border-color: var(--color-primary-200);
}

.setting-card::before {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: #cbd5e0;
  transition: background 0.2s;
}

.setting-card:hover::before {
  background: var(--color-primary-500);
}

.setting-order-badge {
  background: var(--color-background-alt);
  color: var(--color-text-muted);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: bold;
  font-family: 'Roboto Mono', monospace;
}

/* شريط القوالب السريعة */
.quick-template-btn {
  border: 1px solid #e2e8f0;
  background: #fff;
  padding: 8px 15px;
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #4a5568;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.quick-template-btn:hover {
  background: #ebf8ff;
  border-color: #bee3f8;
  color: #2b6cb0;
  transform: scale(1.05);
}

.quick-template-btn i {
  font-size: 1.1em;
}

/* حقول الصعوبة الملونة */
.difficulty-input-group {
  background: #fff;
  padding: 15px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  text-align: center;
  transition: border-color 0.2s;
}

.difficulty-input-group:focus-within {
  border-color: var(--color-primary-300);
  box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}

.diff-label {
  font-size: 0.8rem;
  font-weight: bold;
  margin-bottom: 5px;
  display: block;
}

.diff-easy {
  color: #10b981;
}

.diff-med {
  color: #f59e0b;
}

.diff-hard {
  color: #ef4444;
}

.diff-input {
  text-align: center;
  font-weight: bold;
  font-size: 1.2rem;
  border: none;
  background: #f7fafc;
  border-radius: 8px;
  padding: 5px;
}

.diff-input:focus {
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--color-primary-200);
}

/* زر فحص الجدوى */
.feasibility-box {
  background: linear-gradient(to right, #f0f9ff, #e6fffa);
  border: 1px dashed #b2f5ea;
  border-radius: 10px;
}

/* =========================================================
   إدارة المشاركين (Activity Participants Manager)
   ========================================================= */

/* منطقة التمرير للقوائم */
.participant-scroll-area {
  height: 450px;
  overflow-y: auto;
  padding: 15px;
  background-color: var(--color-background-alt, #f8fafc);
  border-radius: 8px;
  border: 1px solid var(--color-border);
}

/* بطاقة المشارك */
.participant-card {
  background: var(--color-surface, #ffffff);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 10px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  cursor: pointer;
  position: relative;
  /* ✅ حل مشكلة التداخل: حجز مساحة لمربع الاختيار */
  padding-inline-start: 50px;
}

.participant-card:hover {
  border-color: var(--color-primary-400);
  background-color: var(--color-surface-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* تنسيق مربع الاختيار (Checkbox) */
.participant-checkbox {
  position: absolute;
  /* ✅ التموضع الصحيح في RTL و LTR */
  inset-inline-start: 15px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  cursor: pointer;
  z-index: 2;
  accent-color: var(--color-primary-600);
}

/* حالة التحديد */
.participant-card.selected {
  background-color: var(--color-primary-50);
  border-color: var(--color-primary-600);
  box-shadow: inset 0 0 0 1px var(--color-primary-600);
}

/* صورة المستخدم والمعلومات */
.participant-info-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.user-avatar-sm {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-700));
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

/* شريط الإجراءات العائم (Floating Action Bar) */
.bulk-action-bar {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  /* مخفي في الأسفل */
  background: #1e293b;
  /* لون داكن للتباين */
  color: white;
  padding: 10px 24px;
  border-radius: 50px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 1060;
  /* فوق الـ Modal */
  opacity: 0;
  pointer-events: none;
}

.bulk-action-bar.active {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: all;
}

.bulk-divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.2);
}



/* =========================================================
   إدارة المشاركين (Activity Participants Manager)
   ========================================================= */

.participant-scroll-area {
  height: 450px;
  overflow-y: auto;
  padding: 15px;
  background-color: var(--color-background-alt, #f8fafc);
  border-radius: 8px;
}

[data-theme="dark"] .participant-scroll-area {
  background-color: #0f172a;
}

.participant-card {
  background: var(--color-surface, #ffffff);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 10px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  cursor: pointer;
  position: relative;
}

.participant-card:hover {
  border-color: #3b82f6;
  background-color: var(--color-surface-hover, #f1f5f9);
  transform: translateX(-2px);
}

.participant-card.is-selected {
  border-color: #3b82f6;
  background-color: rgba(59, 130, 246, 0.05);
  box-shadow: 0 0 0 1px #3b82f6;
}

[data-theme="dark"] .participant-card.is-selected {
  background-color: rgba(59, 130, 246, 0.1);
}

.user-avatar {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #6366f1 0%, #3b82f6 100%);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.card-action {
  font-size: 1.2rem;
  color: var(--color-text-muted);
  transition: transform 0.2s ease;
}

.participant-card:hover .card-action {
  transform: scale(1.1);
}

/* Floating Action Bar */
.bulk-action-bar {
  position: absolute;
  bottom: -80px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: white;
  padding: 12px 28px;
  border-radius: 50px;
  display: flex;
  align-items: center;
  gap: 24px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 1080;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
}

.bulk-action-bar.active {
  bottom: 30px;
}

.bulk-action-bar span {
  font-weight: 600;
  font-size: 0.95rem;
}

.custom-checkbox .form-check-input {
  width: 1.3rem;
  height: 1.3rem;
  cursor: pointer;
  border-radius: 6px;
  border: 2px solid var(--color-border);
}

.custom-checkbox .form-check-input:checked {
  background-color: #3b82f6;
  border-color: #3b82f6;
}

/* =========================================================
   إصلاح تداخل النوافذ المنبثقة (Modal Stacking Fix)
   ========================================================= */

/* 
   إصلاح تداخل النوافذ المنبثقة (Nested Modals Fix)
   نافذة الإعدادات تأخذ 1055 افتراضياً
   نحن نعطي نافذة المعالج قيمة أعلى لتظهر فوقها
*/
#generateQuestionsModal {
  z-index: 1070 !important;
  /* قيمة أعلى من 1055 */
}

/* 
   إصلاح الخلفية المعتمة (Backdrop) الخاصة بالمعالج 
   يجب أن تكون أعلى من النافذة الأولى (1055) وأقل من النافذة الثانية (1070)
*/
.modal-backdrop.show:nth-of-type(2) {
  z-index: 1060 !important;
}