/* AcademicSchedules.css - الإصدار الكامل والشامل */
:root {
    --irtiqaa-purple: #6f42c1;
    --irtiqaa-purple-light: #8e67d5;
    --irtiqaa-gold: #d4a017;
    --irtiqaa-gold-dark: #b88a12;
    --sidebar-bg: #2c3e50;
    --content-bg: #f0f2f5;
    --sidebar-width: 250px;
    --white: #ffffff;
    --shadow: 0 4px 15px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; }

body { 
    margin: 0; 
    font-family: 'Segoe UI', Tahoma, sans-serif; 
    background: var(--content-bg); 
    direction: rtl; 
}

.app-layout { display: flex; width: 100%; min-height: 100vh; }

/* القائمة الجانبية - Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--white);
    position: fixed;
    height: 100vh;
    right: 0;
    z-index: 100;
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
}

.sidebar-logo { width: 70%; padding: 25px; display: block; margin: 0 auto; }

.sidebar-nav ul { list-style: none; padding: 0; margin-top: 20px; }

.sidebar-nav a {
    display: flex; 
    align-items: center; 
    padding: 15px 20px;
    color: #ecf0f1; 
    text-decoration: none; 
    border-right: 4px solid transparent;
    transition: 0.3s;
}

.sidebar-nav a.active, .sidebar-nav a:hover {
    background: rgba(255,255,255,0.1);
    border-right-color: var(--irtiqaa-gold);
    color: var(--irtiqaa-gold);
}

.sidebar-nav i { margin-left: 12px; width: 20px; text-align: center; }

/* المحتوى الرئيسي */
.main-content { 
    margin-right: var(--sidebar-width); 
    flex: 1; 
    padding: 25px; 
}

.top-bar {
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    background: var(--white);
    padding: 15px 25px; 
    border-radius: 12px; 
    box-shadow: var(--shadow);
    margin-bottom: 25px;
}

.card { 
    background: var(--white); 
    border-radius: 12px; 
    box-shadow: var(--shadow); 
    padding: 20px; 
    margin-bottom: 25px; 
}

/* التبويبات - Tabs */
.tabs-navigation { 
    margin-bottom: 20px; 
    border-bottom: 2px solid #ddd; 
    display: flex; 
    gap: 10px; 
}

.tab-btn { 
    padding: 12px 25px; 
    border: none; 
    background: none; 
    cursor: pointer; 
    font-weight: bold; 
    color: #7f8c8d;
    transition: 0.3s;
}

.tab-btn.active { 
    color: var(--irtiqaa-purple); 
    border-bottom: 3px solid var(--irtiqaa-purple); 
}

/* جداول النصاب - Matrix Tables */
.irtiqaa-table { width: 100%; border-collapse: separate; border-spacing: 0; }

.irtiqaa-table th { 
    background: var(--irtiqaa-purple); 
    color: var(--white); 
    padding: 12px; 
    text-align: center;
}

.sticky-col { 
    position: sticky; 
    right: 0; 
    background-color: #f8f9fa !important; 
    font-weight: bold; 
    border-left: 2px solid var(--irtiqaa-purple) !important;
    z-index: 5;
}

.quota-input-cell input { 
    width: 60px; 
    padding: 8px; 
    text-align: center; 
    border: 1px solid #ddd; 
    border-radius: 4px; 
    font-weight: bold; 
}

.first-cycle { 
    background: var(--irtiqaa-purple); 
    color: var(--white); 
    padding: 15px 20px; 
    border-radius: 12px 12px 0 0; 
    margin: -20px -20px 20px -20px; 
}

.second-cycle { 
    background: var(--sidebar-bg); 
    color: var(--white); 
    padding: 15px 20px; 
    border-radius: 12px 12px 0 0; 
    margin: -20px -20px 20px -20px; 
}

/* الأزرار */
.btn-save-gold {
    background: var(--irtiqaa-gold); 
    color: var(--white); 
    border: none;
    padding: 15px 45px; 
    border-radius: 30px; 
    cursor: pointer; 
    font-size: 1.1rem;
    display: block; 
    margin: 20px auto; 
    font-weight: bold;
    transition: 0.3s;
}

.btn-save-gold:hover { background: var(--irtiqaa-gold-dark); transform: translateY(-2px); }

.btn-reset-table {
    background: rgba(255, 255, 255, 0.2);
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 6px 15px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: 0.3s;
}

.btn-reset-table:hover { background: #dc3545; border-color: #dc3545; }

/* الفلاتر الديناميكية - Dynamic Filters */
.filter-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.input-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 15px; }

.styled-select {
    appearance: none; /* إزالة شكل السهم الافتراضي للمتصفح */
    -webkit-appearance: none;
    -moz-appearance: none;
    
    width: 100%;
    padding: 12px 40px 12px 15px; /* مساحة إضافية لليمين للأيقونة */
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--sidebar-bg);
    background-color: var(--white);
    
    /* أيقونة سهم مخصصة باستخدام SVG */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%236f42c1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px;
    
    border: 2px solid #e0e4e8;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}
/* تأثير عند تمرير الماوس */
.styled-select:hover {
    border-color: var(--irtiqaa-purple-light);
    box-shadow: 0 4px 8px rgba(111, 66, 193, 0.1);
}
/* تأثير عند النقر أو التركيز */
.styled-select:focus {
    outline: none;
    border-color: var(--irtiqaa-purple);
    box-shadow: 0 0 0 4px rgba(111, 66, 193, 0.15);
    background-color: #fff;
}

/* تنسيق الخيارات داخل القائمة */
.styled-select option {
    padding: 10px;
    background-color: var(--white);
    color: var(--sidebar-bg);
}

/* حالة القائمة عندما تكون غير مفعلة */
.styled-select:disabled {
    background-color: #f1f3f5;
    cursor: not-allowed;
    border-color: #d1d5db;
    color: #adb5bd;
}

/* تنسيق خاص للقوائم داخل الـ Modal لزيادة البروز */
.modal-body .styled-select {
    border-color: #dee2e6;
    background-color: #f8f9fa;
}

/* تحسين شكل الـ Label المرتبط بالقائمة */
.input-group label {
    font-weight: 600;
    color: var(--irtiqaa-purple);
    margin-bottom: 8px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
}

.input-group label i {
    margin-left: 8px;
    font-size: 1rem;
}
/* إعدادات أيام الدوام */
.days-config {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 8px;
}

.day-item { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* شبكة البرنامج الأسبوعي - Timetable Grid */
.timetable-grid td {
    height: 100px;
    vertical-align: top;
    padding: 5px !important;
    cursor: pointer;
    transition: 0.2s;
    border: 1px solid #eee;
    background: #fff;
}

.timetable-grid td:hover { background-color: #fff9e6; }

.slot-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    border-radius: 6px;
    border: 1px dashed #ccc;
    text-align: center;
}

.slot-filled {
    background: linear-gradient(135deg, var(--irtiqaa-purple), #8e67d5) !important;
    color: var(--white);
    border: none !important;
    box-shadow: 0 3px 6px rgba(0,0,0,0.1);
}

.subject-name { font-weight: bold; font-size: 0.9rem; margin-bottom: 4px; }
.teacher-name { font-size: 0.75rem; opacity: 0.9; border-top: 1px solid rgba(255,255,255,0.3); padding-top: 4px; }

/* النافذة المنبثقة - Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(3px);
}

.modal-content {
    background: var(--white);
    margin: 10% auto;
    padding: 30px;
    width: 450px;
    border-radius: 15px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.2);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 25px;
}

.btn-outline {
    background: none;
    border: 1px solid #ddd;
    padding: 10px 25px;
    border-radius: 20px;
    cursor: pointer;
}

/* الطباعة */
@media print {
    .sidebar, .tabs-navigation, .filter-card, .settings-card, .btn-save-gold { display: none !important; }
    .main-content { margin-right: 0; padding: 0; }
    .card { box-shadow: none; border: 1px solid #eee; }
}
.tab-pane {
    padding-top: 20px; /* لضمان وجود مسافة عند الانتقال المباشر */
}
@media print {
    /* إخفاء القائمة الجانبية، أشرطة الأدوات، الأزرار، والتبويبات */
    .sidebar, .top-bar, .tabs-navigation, .filter-card, .settings-card, 
    .action-footer, .btn-print, .btn-save-gold, .sidebar-header {
        display: none !important;
    }

    /* توسيع المحتوى الرئيسي ليشمل كامل الصفحة */
    .main-content {
        margin-right: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    /* إخفاء نصوص "إسناد" الفارغة */
    .empty-hint, .slot-content span:contains('+') {
        visibility: hidden !important;
    }

    /* تنسيق الجدول للطباعة */
    .matrix-card {
        box-shadow: none !important;
        border: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .irtiqaa-table {
        border: 1px solid #000 !important;
        width: 100% !important;
        table-layout: fixed; /* لضمان ثبات عرض الأعمدة */
    }

    .irtiqaa-table th, .irtiqaa-table td {
        border: 1px solid #000 !important;
        color: #000 !important;
        font-size: 10pt !important;
        padding: 8px !important;
    }

    .sticky-col {
        position: static !important; /* إلغاء التثبيت عند الطباعة */
        background-color: #f0f0f0 !important;
        border-left: 1px solid #000 !important;
    }

    /* إظهار خلفيات الألوان (للحصص المملوءة) */
    body {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ==========================================================
   تنسيقات الطباعة الاحترافية - مبادرة ارتقاء
   ========================================================== */

/* 1. إخفاء عناصر الطباعة (الرأس والتذييل) أثناء العرض العادي في المتصفح */
.print-header, 
.print-footer { 
    display: none; 
}

@media print {
    /* 2. إعدادات الصفحة العامة لمنع التقطيع */
    @page {
        margin: 0.5cm;
        size: auto; 
    }

    html, body {
        height: 100%;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* 3. تنسيق رأس الصفحة (Header) */
    .print-header { 
        display: block !important; 
        text-align: center; 
        margin-bottom: 20px;
        direction: rtl;
        page-break-inside: avoid;
        break-inside: avoid;
    }
    
    .header-top { 
        display: flex; 
        align-items: center; 
        justify-content: center; 
        gap: 20px; 
        margin-bottom: 15px; 
    }
    
    .print-logo { 
        width: 80px; 
        height: auto; 
    }
    
    .header-info-grid { 
        display: grid; 
        grid-template-columns: repeat(3, 1fr); 
        gap: 10px; 
        text-align: right; 
        font-size: 11pt;
        border: 1px solid #eee;
        padding: 10px;
        border-radius: 8px;
    }

    /* 4. تنسيق الجدول والبرنامج الدراسي */
    .matrix-card {
        page-break-inside: avoid;
        break-inside: avoid;
        border: none !important;
        box-shadow: none !important;
    }

    .irtiqaa-table {
        font-size: 9pt !important;
        width: 100% !important;
        border-collapse: collapse !important;
        table-layout: fixed; /* لضمان احتواء الأعمدة في صفحة واحدة */
    }

    .irtiqaa-table th, 
    .irtiqaa-table td {
        border: 1px solid #000 !important; /* حدود واضحة للطباعة */
        padding: 4px !important;
    }

    /* 5. تنسيق تذييل الصفحة (Footer) والتواقيع */
    .print-footer { 
        display: block !important; 
        margin-top: 30px; 
        width: 100%;
        direction: rtl;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .footer-signature-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        text-align: center;
        gap: 20px;
    }

    .sig-line { 
        margin-top: 35px; 
        font-weight: normal; 
        color: #000; 
    }

    .stamp-box { 
        border: 1px dashed #ccc; 
        width: 90px; 
        height: 90px; 
        margin: 5px auto; 
        border-radius: 50%; 
    }

    .print-timestamp {
        margin-top: 20px;
        font-size: 8pt;
        color: #555;
        text-align: left;
        border-top: 1px solid #eee;
        padding-top: 5px;
    }

    /* 6. إخفاء كافة العناصر غير الضرورية للطباعة */
    .sidebar, 
    .top-bar, 
    .tabs-navigation, 
    .filter-card, 
    .settings-card, 
    .action-footer, 
    .btn-print, 
    .btn-save-gold,
    .modal,
    .empty-hint {
        display: none !important;
    }

    /* إزالة الهوامش الجانبية للمحتوى الرئيسي */
    .main-content { 
        margin: 0 !important; 
        padding: 0 !important; 
        width: 100% !important;
    }
}
@media print {
    /* تعديل توزيع الأعمدة ليتناسب مع العدد الجديد */
    .irtiqaa-table {
        table-layout: auto !important; /* السماح للمتصفح بتوزيع العرض بناءً على المحتوى */
        word-break: break-word;
    }
    
    .irtiqaa-table th, .irtiqaa-table td {
        min-width: 60px; /* ضمان حد أدنى لعرض الحصة */
        font-size: 8.5pt !important; /* تصغير الخط قليلاً إذا زاد عدد الحصص */
    }
}

/* تنسيق خاص لمادة اللغة الإنجليزية لتمييزها بصرياً */
.slot-filled[data-subject*="انجليزي"] , 
.slot-filled[data-subject*="English"],
.slot-filled[data-subject*="E"] {
    background: linear-gradient(135deg, #28a745, #5cd87d) !important; /* لون أخضر مميز */
    border: 1px solid #1e7e34 !important;
}

.text-success { color: #28a745; font-weight: bold; }
.text-danger { color: #dc3545; font-weight: bold; }
.text-warning { color: #ffc107; font-weight: bold; }

.btn-validate-timetable:hover {
    background: #138496 !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transition: 0.3s;
}
@media print {
    #stats-report-content {
        padding: 20px;
        background: white !important;
    }
    
    .card {
        border: 1px solid #eee !important;
        box-shadow: none !important;
        page-break-inside: avoid; /* منع قطع الرسم البياني بين صفحتين */
    }

    /* ضمان ظهور ألوان Chart.js */
    canvas {
        max-width: 100% !important;
        height: auto !important;
    }
}