:root {
    /* الألوان الرئيسية - تحديث الألوان لتبدو أكثر احترافية وأناقة */
    --primary-color: #2c3e50; /* لون أساسي غامق (أزرق غامق) */
    --primary-light: #3498db; /* لون أساسي فاتح (أزرق سماوي) */
    --primary-dark: #1a252f; /* لون أساسي أغمق */
    --secondary-color: #95a5a6; /* لون ثانوي محايد */
    --success-color: #27ae60; /* نجاح */
    --danger-color: #e74c3c; /* خطر */
    --warning-color: #f39c12; /* تحذير */
    --info-color: #3498db; /* لون معلومات */
    --light-bg: #f5f7fa; /* خلفية الصفحة */
    --card-bg: white; /* خلفية البطاقات */
    --border-color: #e6e9ee; /* حدود خفيفة */
    --input-focus: #b3d4f1; /* تركيز الإدخال */
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08); /* ظل متوسط */
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.1); /* ظل كبير */
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); /* انتقال سلس */
    --radius-sm: 8px; /* نصف قطر صغير */
    --radius-md: 12px; /* نصف قطر متوسط */
    --gradient-primary: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%); 
}

/* 1. الإعدادات الأساسية والتنفيذ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 💡 يجب تثبيت الخط إذا كان مستخدماً في النظام */
@font-face {
    font-family: 'Cairo';
    src: url('assets/fonts/Cairo-Regular.ttf') format('truetype'); /* مثال للمسار */
    font-weight: 400;
}
@font-face {
    font-family: 'Cairo';
    src: url('assets/fonts/Cairo-Bold.ttf') format('truetype');
    font-weight: 700;
}

body {
    font-family: 'Cairo', 'Tajawal', sans-serif;
    background: var(--light-bg);
    color: var(--primary-color);
    direction: rtl;
    min-height: 100vh;
    line-height: 1.6;
    font-size: 16px;
    padding-bottom: 50px;
}

/* 2. الحاوية والرأس - تصميم البطاقة الأساسية */
.container {
    max-width: 1400px;
    margin: 30px auto;
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    transition: var(--transition);
}

header {
    text-align: center;
    margin-bottom: 40px;
    padding-bottom: 25px;
    border-bottom: 2px solid var(--border-color);
}

#mainHeader {
    color: var(--primary-dark);
    font-size: 2.8rem;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 15px;
}

#mainHeader i {
    color: var(--primary-light);
}

.context-badge {
    background: var(--gradient-primary);
    color: white;
    padding: 6px 15px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: var(--shadow-md);
}

/* 3. أقسام النموذج الرئيسية - بطاقات مريحة */
.form-section {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 30px;
    margin-bottom: 30px;
    border: 1px solid var(--border-color);
    box-shadow: 0 0 0 0 var(--input-focus);
    transition: var(--transition);
}

.form-section:hover {
    box-shadow: 0 0 0 3px var(--input-focus); /* تأثير جذاب عند المرور */
}

.form-section h2 {
    color: var(--primary-color);
    font-size: 1.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 25px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

.form-section h2 i {
    color: var(--primary-light);
}

/* 4. الأقسام الفرعية - للتنظيم الداخلي */
.form-subsection {
    margin-top: 30px;
    padding: 20px 0;
    border-top: 1px dashed var(--border-color);
}

.form-subsection:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.form-subsection h3 {
    color: var(--primary-light);
    font-size: 1.4rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

/* 5. تخطيط الحقول - نظام شبكي مُحسَّن */
.form-row {
    display: grid;
    /* 4 أعمدة في الأجهزة الكبيرة */
    grid-template-columns: repeat(4, 1fr); 
    gap: 25px;
    margin-bottom: 20px;
}

@media (max-width: 1200px) {
    .form-row {
        grid-template-columns: repeat(3, 1fr); /* 3 أعمدة في الأجهزة المتوسطة */
    }
    .full-width { grid-column: span 3; }
    .half-width { grid-column: span 2; }
    .third-width { grid-column: span 1; }
    .quarter-width { grid-column: span 1; }
}

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr; /* عمود واحد في الأجهزة الصغيرة */
        gap: 15px;
    }
    .full-width, .half-width, .third-width, .quarter-width { 
        grid-column: span 1; 
    }
    .container {
        padding: 20px;
        margin: 15px;
    }
}


.form-group {
    display: flex;
    flex-direction: column;
}

/* 6. عناصر الإدخال - تركيز على سهولة الإدخال */
label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
    color: var(--primary-color);
}

.required {
    color: var(--danger-color);
    font-size: 1.1rem;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="tel"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    color: var(--primary-dark);
    transition: var(--transition);
    background: #fcfdfe;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px var(--input-focus);
}

select {
    appearance: none;
    background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%233498db" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>');
    background-repeat: no-repeat;
    background-position: left 15px center;
    padding-left: 40px;
}

/* حقل القراءة فقط */
input[readonly] {
    background-color: #f1f3f5;
    cursor: default;
    border-style: dashed;
}

.field-hint {
    font-size: 0.85rem;
    color: var(--secondary-color);
    margin-top: 5px;
}

/* 7. الأزرار وإجراءات النموذج */
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    padding-top: 30px;
    border-top: 1px solid var(--border-color);
    margin-top: 40px;
}

.btn {
    padding: 12px 25px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-md);
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.15);
}

.btn-primary {
    background: var(--primary-light); /* تغيير بسيط للتباين */
    color: white;
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-warning {
    background: var(--warning-color);
    color: white;
}

.btn-info {
    background: var(--info-color);
    color: white;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 8. تحميل الملفات والمرفقات */
input[type="file"] {
    border: 2px dashed var(--border-color);
    background: var(--light-bg);
    cursor: pointer;
    padding: 15px;
}

input[type="file"]:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px var(--input-focus);
}

.file-preview-container {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.file-progress {
    height: 6px;
    background: #e6e9ee;
    margin-top: 5px;
    border-radius: 3px;
    overflow: hidden;
}

/* 9. قسم سياق العمل الإداري */
.admin-context-section {
    background: #f0f7ff;
    border-color: #bbdefb;
    margin-bottom: 40px;
}

.admin-context-section:hover {
    box-shadow: 0 0 0 3px #bbdefb;
}

.context-hint {
    background: #e3f2fd;
    color: #1565c0;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
}

.select-loading {
    font-size: 0.85rem;
    color: var(--secondary-color);
    margin-top: 5px;
    display: none;
}

/* 10. قائمة الطلاب والجداول (تنسيقات بسيطة للوضوح) */
.students-list-section {
    padding: 20px;
    background: #fcfdfe;
}

.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1300px;
}

.data-table th,
.data-table td {
    padding: 12px 15px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background: var(--primary-color);
    color: white;
    font-weight: 700;
}

.data-table tr:hover td {
    background: #f4f6f9;
}

/* 11. النوافذ المنبثقة (Modals) */
.modal {
    /* 💡 هذا التنسيق يحل مشكلة ظهور المودال في أسفل الشاشة */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(44, 62, 80, 0.85); /* خلفية شبه شفافة */
    display: none; /* يتم التحكم في ظهوره عبر JS */
    justify-content: center; /* توسيط أفقي */
    align-items: center; /* توسيط عمودي */
    z-index: 1000;
    overflow-y: auto; 
    padding: 20px;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 30px;
    max-width: 600px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    z-index: 1001; 
    animation: modalSlide 0.3s ease-out;
}

.modal-content.modal-lg {
    max-width: 800px;
}

/* 💡 إزالة التنسيق الإضافي لـ .modal-overlay (غير ضروري إذا كان .modal يغطي الشاشة) */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--secondary-color);
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--danger-color);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 20px;
}

.warning-text {
    color: var(--danger-color);
    font-weight: 600;
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

@keyframes modalSlide {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* 12. تنبيهات وإشعارات */
.notification-container {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1002;
    direction: rtl;
}

.notification {
    padding: 12px 20px;
    margin-bottom: 10px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    color: white;
    font-weight: 500;
    transition: opacity 0.5s ease-out;
}

.notification.success { background-color: var(--success-color); }
.notification.error { background-color: var(--danger-color); }
.notification.warning { background-color: var(--warning-color); }
.notification.info { background-color: var(--info-color); }


/* 13. المحمّل العام (Loader) */
.global-loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(var(--primary-dark-rgb), 0.9); /* استخدام لون أغمق مع شفافية */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    color: white;
}

.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    padding: 30px;
    background: var(--primary-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.loader-icon {
    font-size: 3rem;
}

.loader-text {
    font-size: 1.2rem;
    font-weight: 700;
}
/* 14. إخفاء سياق السنة الدراسية افتراضياً للتحكم به عبر JS */
#academicYearContext {
    display: none;
}
/* تحديث تنسيق معاينة الملفات - أيقونات صغيرة */
.file-preview-container {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 40px;
    padding: 5px;
    border: 1px solid #e0e0e0;
    border-radius: var(--radius-sm);
    background: #fafafa;
}

/* أيقونة صغيرة للملفات */
.file-preview-item {
    position: relative;
    width: 40px; /* تصغير الحجم */
    height: 40px; /* تصغير الحجم */
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    background: white;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.file-preview-item:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* للصور: تقليل حجم المعاينة */
.file-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.8;
}

/* أيقونة الصورة */
.file-preview-item.image-preview::before {
    content: "\f03e"; /* أيقونة الصورة */
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    font-size: 1.2rem;
    color: var(--primary-light);
}

/* أيقونة ملف PDF */
.file-preview-item.pdf-icon::before {
    content: "\f1c1"; /* أيقونة ملف PDF */
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    font-size: 1.2rem;
    color: var(--danger-color);
}

/* أيقونة الملفات العامة */
.file-preview-item.generic-file::before {
    content: "\f15b"; /* أيقونة ملف عام */
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    font-size: 1.2rem;
    color: var(--secondary-color);
}

/* إضافة تلميح يظهر اسم الملف عند المرور */
.file-preview-item::after {
    content: attr(title);
    position: absolute;
    bottom: -25px;
    right: 50%;
    transform: translateX(50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    z-index: 10;
}

.file-preview-item:hover::after {
    opacity: 1;
}

/* حاوية نصية للملفات المتعددة */
.file-count-badge {
    position: absolute;
    top: -5px;
    left: -5px;
    background: var(--danger-color);
    color: white;
    font-size: 0.6rem;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
}
/* رسالة الملفات الإضافية */
.more-files-notice {
    align-self: center;
    font-size: 0.8rem;
    color: var(--secondary-color);
    padding: 3px 8px;
    background: #f0f0f0;
    border-radius: 4px;
}
/* تنسيق لحقول ID المرئية */
.id-field {
    font-weight: bold;
    color: var(--primary-color);
    background-color: #f8f9fa;
    border: 2px solid var(--primary-light);
}

.id-field:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(44, 62, 80, 0.2);
}

/* تنسيق للعناوين في الجدول */
.table-id-cell {
    font-weight: 700;
    color: var(--primary-dark);
    background-color: #f0f7ff;
}

/* تنسيق للعناوين الرئيسية */
.id-label {
    position: relative;
    padding-right: 25px;
}

.id-label::before {
    content: "🔢";
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1rem;
}
/* ==========================================================
   تنسيق الجدول (data-table)
   ========================================================== */

.table-wrapper {
    overflow-x: auto; /* مهم للتوافق مع الشاشات الصغيرة */
    margin-top: 20px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
}

.data-table {
    width: 100%;
    border-collapse: separate; /* مهم لـ border-radius على الخلايا */
    border-spacing: 0;
    font-size: 14px;
    color: #333;
    background-color: #fff;
}

/* الرؤوس (Header) */
.data-table thead th {
    background-color: #002b5c; /* لون أزرق داكن (ثانوي) */
    color: #ffffff;
    padding: 12px 15px;
    text-align: right;
    font-weight: 600;
    position: sticky; /* لجعل الرؤوس ثابتة عند التمرير */
    top: 0;
    z-index: 10;
}

/* الزاوية اليمنى العلوية */
.data-table thead tr:first-child th:first-child {
    border-top-right-radius: 8px; 
}
/* الزاوية اليسرى العلوية */
.data-table thead tr:first-child th:last-child {
    border-top-left-radius: 8px; 
}

/* الصفوف والبيانات */
.data-table tbody td {
    padding: 10px 15px;
    border-bottom: 1px solid #f0f0f0; /* خط فاصل خفيف */
    transition: background-color 0.3s ease;
    vertical-align: middle;
}

/* تأثير التظليل عند المرور على الصف (Hover Effect) */
.data-table tbody tr:hover {
    background-color: #f7f7f7;
}

/* تصميم الصفوف المتناوبة (Zebra Stripes) */
.data-table tbody tr:nth-child(even) {
    background-color: #fafafa;
}

/* الصف الأخير (لإزالة الخط الفاصل السفلي) */
.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* تنسيق الأعمدة الخاصة (مثل الإجراءات) */
.data-table td:last-child {
    text-align: left;
    white-space: nowrap; /* منع تقسيم الأزرار */
}

/* تنسيق أزرار الإجراءات داخل الجدول */
.data-table td .btn-sm {
    padding: 5px 8px;
    margin-left: 4px;
    font-size: 12px;
    border-radius: 4px;
    min-width: 30px;
}
/* في ملف styles.css (أو إضافة في <style> في HTML) */
body, .data-table {
    font-family: 'Cairo', 'Tajawal', 'Arial', sans-serif; /* استخدم خط عربي مريح للقراءة */
}
/* تنسيق حقول الفلترة */
.table-filter-input {
    width: 90%;
    padding: 3px;
    margin: 2px 0;
    border: 1px solid #ccc;
    border-radius: 3px;
    box-sizing: border-box;
    font-size: 10px; /* تصغير الخط داخل حقل البحث */
}