/* ==========================================
   ************** 1. الخطوط المحلية **************
   ========================================== */
@font-face {
    font-family: 'CairoLocal';
    src: url('Cairo-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'AlMohanadLocal';
    src: url('al-mohanad.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

/* ==========================================
   ************** 2. التنسيقات الأساسية (Base) **************
   ========================================== */
body {
    font-family: 'CairoLocal', sans-serif !important;
    line-height: 1.4;
}

/* منع الخطوط العربية من السيطرة على أيقونات Font Awesome */
i, .fa, .fas, .fab, .far {
    font-family: "Font Awesome 6 Free", "Font Awesome 6 Brands", sans-serif !important;
    font-style: normal !important;
}

[dir="rtl"] { text-align: right; }

/* فئات عامة للاتجاه */
.ltr-text { direction: ltr; text-align: left; }
.rtl-text { direction: rtl; text-align: right; }

/* ==========================================
   ************** 3. بطاقات الأسئلة **************
   ========================================== */
.question-card, .qa-concept-card {
    transition: transform .18s ease, box-shadow .18s ease;
    border-radius: 14px;
}
.question-card { border: 1px solid #d1d5db; }
.qa-concept-card { border: 1px solid #60a5fa; }

.question-card:hover, .qa-concept-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(16,24,40,0.06);
}
.dark .question-card:hover, .dark .qa-concept-card:hover {
    box-shadow: 0 8px 20px rgba(0,0,0,0.5);
}

/* إطارات الحالة */
.frame-neutral { border: 1px solid #d1d5db !important; }
.frame-red    { border: 1px solid #ef4444 !important; }
.frame-green  { border: 1px solid #10b981 !important; }
.frame-yellow { border: 1px solid #f59e0b !important; }
.frame-blue   { border: 1px solid #3b82f6 !important; }
.frame-purple { border: 1px solid #8b5cf6 !important; }

/* ==========================================
   ************** 4. أزرار الخيارات **************
   ========================================== */
.option-btn {
    transition: transform .08s ease, background .18s ease, border-color .18s ease, opacity .2s ease;
    direction: rtl;
    text-align: right;
}
.option-btn:active { transform: scale(.99); }
.option-btn:disabled { cursor: default; }
.option-btn.faded { opacity: .55; }

.option-label {
    min-width: 32px; min-height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 9999px; background: #e0f7fa; color: #059669;
    font-weight: 700; font-size: 0.8rem;
    flex-shrink: 0; margin-left: 0.75rem;
}
.option-btn .flex-1 { direction: rtl; text-align: right; }

/* الحالات: صحيح / خطأ */
.is-correct {
    background: #ecfdf5 !important;
    border-color: #4ade80 !important;
    color: #065f46 !important;
}
.dark .is-correct {
    background: #064e3b !important;
    border-color: #34d399 !important;
    color: #a7f3d0 !important;
}
.is-wrong {
    background: #fff1f2 !important;
    border-color: #f87171 !important;
    color: #7f1d1d !important;
}
.dark .is-wrong {
    background: #7f1d1d !important;
    border-color: #fca5a5 !important;
    color: #fecaca !important;
}
.is-correct .option-label { background: #16a34a !important; color: white !important; }
.is-wrong .option-label   { background: #dc2626 !important; color: white !important; }

/* تحسينات إضافية للخيارات الصحيحة والخاطئة */
.option-btn.is-correct {
    background-color: #ecfdf5 !important;
    border-color: #059669 !important;
    border-width: 1px !important;
    opacity: 1 !important;
    box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2);
}
.option-btn.is-wrong {
    background-color: #fff1f2 !important;
    border-color: #e11d48 !important;
    opacity: 0.9 !important;
}
.dark .option-btn.is-correct {
    background-color: rgba(6, 78, 59, 0.4) !important;
    border-color: #34d399 !important;
    color: #ecfdf5 !important;
}
.dark .option-btn.is-wrong {
    background-color: rgba(159, 18, 57, 0.4) !important;
    border-color: #fb7185 !important;
    color: #fff1f2 !important;
}

/* اختيار متعدد */
.multi-selected {
    background: rgba(59, 130, 246, 0.2) !important;
    border-color: #3b82f6 !important;
}
.dark .multi-selected {
    background: rgba(59, 130, 246, 0.3) !important;
    border-color: #3b82f6 !important;
}

/* أزرار التحقق متعدد */
.check-multi-btn.disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    background-color: #9ca3af !important;
}
.check-multi-btn.enabled {
    opacity: 1 !important;
    cursor: pointer !important;
    background-color: #059669 !important;
}

/* ==========================================
   ************** 5. الشريط العلوي الثابت **************
   ========================================== */
#fixedTopBar {
    position: fixed; width: 100%; top: 0;
    padding: 4px 10px; min-height: 44px;
    background-color: rgba(255, 255, 255, 0.98);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    backdrop-filter: blur(4px);
    border-bottom: 1px solid #e2e8f0;
    z-index: 9999;
}
.dark #fixedTopBar {
    background-color: rgba(17, 24, 39, 0.98);
    border-bottom: 1px solid #374151;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5);
    color: #f3f4f6;
}

#progressFillTop {
    transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.shimmer-effect {
    position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    transform: translateX(-100%); pointer-events: none;
}
.animate-shimmer { animation: progress-shimmer 2s ease-in-out; }
@keyframes progress-shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* ==========================================
   ************** 6. البحث الذكي (Search) **************
   ========================================== */
.search-highlight {
    background-color: #fef08a;
    color: #1e293b;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
.search-highlight-input {
    background-color: rgba(254, 240, 138, 0.2) !important;
    border-color: #eab308 !important;
    box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.1) !important;
}
.search-match-highlight {
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
}
#searchResultsInfo {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border: 1px solid #93c5fd;
    color: #1e40af;
}
.dark .search-highlight {
    background-color: #854d0e;
    color: #fef9c3;
}
.dark .search-highlight-input {
    background-color: rgba(133, 77, 14, 0.2) !important;
    border-color: #a16207 !important;
}
.dark .search-match-highlight {
    border-color: #60a5fa !important;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2) !important;
}
.dark #searchResultsInfo {
    background: linear-gradient(135deg, #1e3a5f, #1e40af);
    border-color: #3b82f6;
    color: #bfdbfe;
}

/* ==========================================
   ************** 7. المفضلة (Favorites) **************
   ========================================== */
.favorite-btn {
    transition: all 0.2s ease;
    color: #d1d5db;
}
.favorite-btn.active { color: #f59e0b; text-shadow: 0 0 8px rgba(245, 158, 11, 0.5); }
.favorite-btn:hover { transform: scale(1.1); }

.favorite-card {
    border-color: #f59e0b !important;
    background: linear-gradient(to left, #fffbeb, #fef3c7) !important;
}
.dark .favorite-card {
    background: linear-gradient(to left, #78350f, #92400e) !important;
    border-color: #f59e0b !important;
}

/* ==========================================
   ************** 8. النوافذ المنبثقة (Modals) **************
   ========================================== */
.modal-overlay {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    z-index: 10000;
    opacity: 0; visibility: hidden;
    transition: 0.25s;
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal-content {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    transform: translateY(25px) scale(0.95);
    opacity: 0;
    transition: 0.3s;
    max-height: 90vh; overflow: auto;
    direction: rtl;
}
.modal-overlay.active .modal-content { transform: none; opacity: 1; }
.dark .modal-content {
    background: rgba(17, 24, 39, 0.9);
    border-color: rgba(75, 85, 99, 0.4);
}

/* ==========================================
   ************** 9. إدارة المستخدمين **************
   ========================================== */
.user-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.3s ease;
}
.user-avatar:hover { transform: scale(1.1); }

.user-dropdown {
    position: absolute; top: 100%; left: 0; margin-top: 10px;
    background: white; border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    min-width: 200px; z-index: 50; display: none;
}
.user-dropdown.show { display: block; }
.dark .user-dropdown { background: #1f2937; border-color: #374151; }

.dropdown-item {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px; color: #374151;
    border-bottom: 1px solid #f3f4f6;
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: #f9fafb; }
.dark .dropdown-item {
    color: #d1d5db; border-bottom: 1px solid #374151;
}
.dark .dropdown-item:hover { background: #374151; }

/* أيقونات المستخدمين */
.user-icon { transition: all 0.3s ease; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.user-icon:hover { transform: scale(1.05); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.icon-super_admin { background: linear-gradient(135deg, #f59e0b, #d97706); }
.icon-admin { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.icon-editor { background: linear-gradient(135deg, #10b981, #059669); }
.icon-student { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }

/* ==========================================
   ************** 10. سجل النشاط (Activity Log) **************
   ========================================== */
.activity-badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; text-transform: uppercase;
}
.activity-badge-add     { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.3); }
.activity-badge-edit    { background: rgba(59, 130, 246, 0.1); color: #3b82f6; border: 1px solid rgba(59, 130, 246, 0.3); }
.activity-badge-delete  { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.3); }
.activity-badge-restore { background: rgba(245, 158, 11, 0.1); color: #f59e0b; border: 1px solid rgba(245, 158, 11, 0.3); }

.activity-action-btn {
    padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 500;
    transition: all 0.2s; display: flex; align-items: center; gap: 5px;
    border: none; cursor: pointer; color: white; width: 100%;
}
.activity-action-btn:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.restore-btn            { background: linear-gradient(135deg, #10b981, #059669); }
.delete-permanent-btn   { background: linear-gradient(135deg, #ef4444, #dc2626); }

/* ==========================================
   ************** 11. القراءة الصوتية (TTS) **************
   ========================================== */
.tts-btn {
    transition: all 0.2s ease;
    cursor: pointer;
}
.tts-btn:hover { transform: scale(1.05); }
.tts-btn:active { transform: scale(0.95); }

.tts-controls {
    position: fixed; bottom: 20px; left: 20px; right: 20px;
    z-index: 1000; display: none;
    animation: slideUp 0.3s ease-out;
}
@media (min-width: 768px) {
    .tts-controls { left: auto; right: 20px; width: 380px; }
}
@keyframes slideUp {
    from { transform: translateY(100px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

.speed-dropdown { position: relative; display: inline-block; }
.speed-btn {
    background: #4f46e5; color: white;
    padding: 8px 12px; border-radius: 12px; font-size: 13px; font-weight: bold;
    display: flex; align-items: center; gap: 6px;
    cursor: pointer;
}
.speed-btn:hover { background: #4338ca; transform: scale(1.02); }
.speed-menu {
    position: absolute; bottom: 100%; left: 0; margin-bottom: 8px;
    background: white; border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.2);
    overflow: hidden; min-width: 120px; display: none; z-index: 100;
}
.speed-menu.show { display: block; animation: slideUp 0.2s ease-out; }
.speed-option {
    padding: 8px 16px; cursor: pointer; text-align: center; color: #1f2937;
}
.speed-option:hover { background: #e0e7ff; }
.speed-option.active { background: #4f46e5; color: white; }

.reading-now {
    transform: scale(1.02) !important;
    box-shadow: 0 20px 25px -12px rgba(0,0,0,0.25) !important;
    border: 2px solid #f59e0b !important;
    transition: all 0.3s cubic-bezier(0.4,0,0.2,1) !important;
    position: relative; z-index: 10;
}
.reading-now::before {
    content: "🔊";
    position: absolute; top: -10px; right: -10px;
    background: #f59e0b; color: white;
    border-radius: 50%; width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    animation: pulse 1s infinite;
}
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* ==========================================
   ************** 12. إدارة المحتوى (Content Management) **************
   ========================================== */
#contentFormContainer input,
#contentFormContainer textarea,
#contentFormContainer select { direction: rtl; text-align: right; }
#optionsContainer textarea { direction: rtl; text-align: right; }
#contentFormContainer .peer:checked~div { transform: scale(1.03); }
#contentFormContainer .w-16.h-16:hover { transform: scale(1.05) rotate(4deg); }

/* أزرار الإدارة */
.admin-btn {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white;
}
.admin-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4); }
.edit-btn { background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); color: white; }
.delete-btn { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); color: white; }

.action-btn {
    padding: 6px 12px; border-radius: 8px; font-size: 12px; font-weight: bold;
    transition: all 0.2s ease;
    display: flex; align-items: center; gap: 5px;
    border: none; cursor: pointer;
}
.action-btn:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.action-btn:active { transform: scale(0.95); }

/* ==========================================
   ************** 13. البطاقات المقالية (QA) والمفاهيم **************
   ========================================== */
.qa-concept-card {
    border-right: 5px solid #1e40af !important;
    background: linear-gradient(to left, #ffffff, #fcfcfc);
}
.dark .qa-concept-card {
    background: linear-gradient(to left, #1f2937, #111827);
    border-right-color: #3b82f6 !important;
}
.qa-concept-card p { text-align: justify; text-justify: inter-word; }
.qa-concept-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.02);
}
.qa-concept-card .favorite-btn {
    border-radius: 50%; width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
}
.qa-concept-card .favorite-btn:hover {
    background-color: rgba(139, 92, 246, 0.1);
    transform: scale(1.05);
}
.qa-header-card, .qa-note-card {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    backdrop-filter: blur(4px);
}
.qa-header-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
}
.qa-note-card {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%) !important;
    color: white !important;
}
.qa-header-card::before, .qa-note-card::before {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255,255,255,0.1) 50%, transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
    pointer-events: none;
}
.qa-header-card:hover::before, .qa-note-card:hover::before {
    transform: translateX(100%);
}
.qa-header-card:hover, .qa-note-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.qa-action-buttons { display: flex; gap: 8px; margin-top: 12px; }
.qa-action-buttons button {
    transition: all 0.2s ease;
    font-weight: 600;
}
.qa-action-buttons button:hover { transform: translateY(-2px); }

/* ==========================================
   ************** 14. النماذج والحقول **************
   ========================================== */
.form-input {
    width: 100%; padding: 10px 15px;
    border: 1px solid #d1d5db; border-radius: 8px;
    background: white; color: #1f2937;
    transition: all 0.2s;
}
.form-input:focus {
    outline: none; border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.dark .form-input {
    background: #374151; border-color: #4b5563; color: white;
}
textarea {
    resize: vertical; min-height: 60px; max-height: 400px;
    overflow-y: auto; transition: height 0.2s ease;
}
.password-strength { height: 4px; border-radius: 4px; margin-top: 6px; }
.strength-weak  { background: linear-gradient(90deg, #ef4444 25%, #e5e7eb 0); }
.strength-medium{ background: linear-gradient(90deg, #f59e0b 50%, #e5e7eb 0); }
.strength-strong{ background: linear-gradient(90deg, #10b981 75%, #e5e7eb 0); }
.strength-very-strong { background: #3b82f6; }

.validation-message { font-size: 12px; margin-top: 4px; display: flex; align-items: center; gap: 5px; }
.validation-success { color: #10b981; }
.validation-error   { color: #ef4444; }

/* ==========================================
   ************** 15. معالجة KaTeX والمعادلات الطويلة **************
   ========================================== */
.katex-display {
    direction: ltr !important;
    text-align: center !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    max-width: 100%;
    padding: 0.5rem 0.25rem;
    margin: 1rem 0;
}
.katex-display::-webkit-scrollbar { height: 5px; }
.katex-display::-webkit-scrollbar-thumb { background-color: #94a3b8; border-radius: 4px; }
.dark .katex-display::-webkit-scrollbar-thumb { background-color: #475569; }

.math-rtl { direction: rtl !important; text-align: right !important; }
.math-ltr { direction: ltr !important; text-align: center !important; }
.math-rtl .vlist-t, .math-rtl .vlist-b, .math-rtl .vlist { direction: ltr !important; }

/* النص العربي داخل المعادلات */
.katex .text {
    direction: rtl !important;
    unicode-bidi: embed;
    white-space: nowrap;
}
/* الجداول والمعادلات في إدارة المحتوى */
#contentManagementView .question-card,
#contentManagementView .explanation-section,
#contentManagementView .explanation-text {
    overflow-x: auto !important;
    max-width: 100%;
}
.overflow-x-auto { overflow-x: auto !important; max-width: 100%; }
table {
    min-width: 400px;
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0;
}
@media (max-width: 640px) {
    .explanation-steps table { font-size: 0.7rem; }
    .explanation-steps th, .explanation-steps td { padding: 4px; }
}

/* ==========================================
   ************** 16. الإشعارات (Toast) **************
   ========================================== */
.toast-container {
    position: fixed; top: 20px; right: 20px;
    z-index: 10001;
    display: flex; flex-direction: column; gap: 10px;
}
.toast {
    padding: 12px 20px; border-radius: 10px;
    color: white; font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideIn 0.3s ease-out;
    display: flex; align-items: center; gap: 10px;
}
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}
.toast-success { background: #10b981; }
.toast-error   { background: #ef4444; }
.toast-warning { background: #f59e0b; }
.toast-info    { background: #3b82f6; }

