/**
 * Dar Al-Khair Results Portal - Custom CSS Stylesheet
 * المسار: portal/assets/css/style.css
 * الهوية اللونية: الأزرق (#1b75bc) والبرتقالي الذهبي (#f58220) المستوحاة من شعار المجمع
 */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700;800;900&family=Tajawal:wght@400;500;700;800;900&display=swap');

:root {
    --primary: #1b75bc;
    --primary-rgb: 27, 117, 188;
    --secondary: #f58220;
    --secondary-rgb: 245, 130, 32;
    --dark-slate: #0f172a;
    --slate-800: #1e293b;
    --slate-700: #334155;
    --light-bg: #f8fafc;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --font-cairo: 'Cairo', sans-serif;
    --font-tajawal: 'Tajawal', sans-serif;
    --radius-lg: 20px;
    --radius-md: 12px;
}

/* التنسيق العام */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--light-bg);
    color: var(--dark-slate);
    font-family: var(--font-cairo);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    position: relative;
}

/* الخلفيات الفنية المتدرجة الدائرية لتوفير مظهر فخم للموقع */
body::before {
    content: '';
    position: absolute;
    top: -20%;
    right: -10%;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(27,117,188,0.15) 0%, rgba(255,255,255,0) 70%);
    z-index: -1;
}

body::after {
    content: '';
    position: absolute;
    bottom: -10%;
    left: -10%;
    width: 500px;
    height: 500px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(245,130,32,0.12) 0%, rgba(255,255,255,0) 70%);
    z-index: -1;
}

/* الحاوية الرئيسية */
.portal-container {
    width: 100%;
    max-width: 900px;
    margin: auto;
    padding: 30px 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.portal-wide-container {
    max-width: 1200px !important;
}

/* تصميم الزجاج البلوري Glassmorphism */
.glass-card {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: var(--radius-lg);
    box-shadow: 0 15px 35px -5px rgba(15, 23, 42, 0.06), 
                0 10px 15px -8px rgba(15, 23, 42, 0.04);
    padding: 40px;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

/* الشعار الرئيسي للمجمع */
.logo-container {
    text-align: center;
    margin-bottom: 25px;
}

.logo-container img {
    height: 120px;
    width: auto;
    object-fit: contain;
    transition: transform 0.5s ease;
}

.logo-container img:hover {
    transform: rotate(5deg) scale(1.05);
}

.portal-title {
    font-family: var(--font-tajawal);
    font-size: 24px;
    font-weight: 900;
    color: var(--primary);
    text-align: center;
    margin-bottom: 5px;
}

.portal-subtitle {
    font-size: 14px;
    color: var(--gray);
    text-align: center;
    margin-bottom: 35px;
    font-weight: 600;
}

/* فورم البحث التفاعلي */
.search-box {
    max-width: 480px;
    margin: 0 auto;
}

.form-group {
    position: relative;
    margin-bottom: 20px;
}

.input-icon {
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary);
    font-size: 18px;
    transition: all 0.3s ease;
}

.form-input {
    width: 100%;
    padding: 16px 50px 16px 20px;
    font-size: 15px;
    font-weight: 600;
    border: 2px solid #e2e8f0;
    border-radius: var(--radius-md);
    outline: none;
    background-color: #ffffff;
    transition: all 0.3s ease;
    text-align: right;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
}

.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(27, 117, 188, 0.15);
}

.form-input:focus + .input-icon {
    transform: translateY(-50%) scale(1.1);
    color: var(--secondary);
}

/* الأزرار الاحترافية والتفاعلية */
.btn-submit {
    width: 100%;
    padding: 15px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary) 0%, #125488 100%);
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 20px -10px rgba(27, 117, 188, 0.5);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-submit:hover {
    background: linear-gradient(135deg, #1d7bbf 0%, var(--primary) 100%);
    transform: translateY(-2px);
    box-shadow: 0 12px 24px -10px rgba(27, 117, 188, 0.6);
}

.btn-submit:active {
    transform: translateY(0);
}

/* بطاقة الشهادة التقديرية التفاعلية للنتيجة (The Certificate Card) */
.certificate-card {
    border: 3px double var(--border);
    border-radius: var(--radius-lg);
    background: #ffffff;
    padding: 40px;
    margin-top: 30px;
    position: relative;
    box-shadow: 0 20px 40px -15px rgba(15, 23, 42, 0.1);
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* تحديد البرواز الملون بحسب التقدير والمعدل */
.cert-rating-excellent { border-color: #ffd700; box-shadow: 0 0 25px rgba(255, 215, 0, 0.15); }
.cert-rating-verygood { border-color: #c0c0c0; box-shadow: 0 0 20px rgba(192, 192, 192, 0.15); }
.cert-rating-good { border-color: #cd7f32; box-shadow: 0 0 15px rgba(205, 127, 50, 0.15); }
.cert-rating-pass { border-color: var(--primary); }
.cert-rating-fail { border-color: var(--error); }

/* تهنئة النجاح المضيئة (Success Header) */
.success-banner {
    text-align: center;
    margin-bottom: 30px;
    animation: pulseGlow 2s infinite ease-in-out;
}

.success-title {
    font-family: var(--font-tajawal);
    font-size: 26px;
    font-weight: 900;
    color: var(--secondary);
    margin-bottom: 5px;
}

.success-subtitle {
    font-size: 14px;
    color: var(--success);
    font-weight: 700;
}

/* بيانات الطالب الأساسية */
.student-info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px 30px;
    background-color: var(--light-bg);
    padding: 20px 25px;
    border-radius: var(--radius-md);
    margin-bottom: 30px;
    border: 1px solid rgba(226, 232, 240, 0.8);
}

.info-item {
    display: flex;
    flex-direction: column;
}

.info-label {
    font-size: 12px;
    color: var(--gray);
    font-weight: 700;
    margin-bottom: 3px;
}

.info-value {
    font-size: 15px;
    font-weight: 700;
    color: var(--dark-slate);
}

/* دائرة النسبة المئوية الدائرية الفخمة */
.percentage-badge-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 30px;
}

.percentage-circle {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: radial-gradient(circle, #ffffff 60%, var(--light-bg) 100%);
    border: 8px solid var(--secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(245, 130, 32, 0.15);
    position: relative;
    animation: scaleIn 0.5s ease-out;
}

.percentage-val {
    font-size: 32px;
    font-weight: 900;
    color: var(--secondary);
    line-height: 1;
}

.percentage-label {
    font-size: 12px;
    font-weight: 800;
    color: var(--primary);
    margin-top: 5px;
}

/* جدول المواد والتفاصيل */
.results-table-container {
    width: 100%;
    margin-bottom: 30px;
    overflow-x: auto;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
    min-width: 500px;
}

.results-table th {
    background-color: var(--primary);
    color: #ffffff;
    font-weight: 700;
    font-size: 13px;
    padding: 12px 15px;
}

.results-table th:first-child { border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.results-table th:last-child { border-radius: var(--radius-md) 0 0 var(--radius-md); }

.results-table td {
    padding: 14px 15px;
    font-size: 14px;
    font-weight: 700;
    border-bottom: 1px solid #edf2f7;
    color: var(--slate-700);
}

.results-table tr:last-child td {
    border-bottom: none;
}

/* درجات وتنبيهات المواد */
.badge-status {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    display: inline-block;
}

.badge-passed { background-color: #dcfce7; color: var(--success); }
.badge-failed { background-color: #fef2f2; color: var(--error); }
.badge-absent { background-color: #fef3c7; color: var(--warning); }
.badge-optional { background-color: #f1f5f9; color: var(--gray); }

/* شريط تقدم تفصيلي للمادة */
.sub-progress-bar {
    height: 6px;
    background-color: #e2e8f0;
    border-radius: 3px;
    margin-top: 5px;
    width: 100px;
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
}

.sub-progress-fill {
    height: 100%;
    border-radius: 3px;
}

.fill-passed { background-color: var(--success); }
.fill-failed { background-color: var(--error); }

/* لوحة الأرقام والمجاميع الإجمالية */
.total-summary-card {
    background-color: var(--primary-light);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    border: 1px solid rgba(27, 117, 188, 0.15);
}

.summary-block {
    text-align: center;
}

.summary-block-val {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
}

.summary-block-lbl {
    font-size: 11px;
    color: var(--slate-700);
    font-weight: 700;
    margin-top: 3px;
}

/* طبقة الـ Confetti */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

/* تذييل الصفحة */
.portal-footer {
    text-align: center;
    padding: 20px;
    font-size: 11px;
    color: var(--gray);
    font-weight: 700;
    margin-top: 30px;
    border-top: 1px solid rgba(226, 232, 240, 0.5);
}

/* صفحة إغلاق الصيانة */
.maintenance-box {
    text-align: center;
    padding: 40px 20px;
}

.maintenance-icon {
    font-size: 50px;
    color: var(--secondary);
    margin-bottom: 20px;
    animation: rotateWrench 2.5s infinite ease-in-out;
}

/* أنيميشن */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.cert-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 350px;
    height: 350px;
    opacity: 0.02;
    pointer-events: none;
    z-index: 0;
}

/* الترويسة الاحترافية المنسقة للشهادة */
.cert-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--secondary);
    padding-bottom: 12px;
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
}

.header-logo {
    width: 100px;
    height: 75px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-logo img {
    max-height: 100%;
    max-width: 100%;
    object-fit: contain;
}

.header-center {
    text-align: center;
    flex-grow: 1;
}

.basmala {
    font-size: 11px;
    color: var(--slate-700);
    font-weight: 700;
    display: block;
    margin-bottom: 4px;
}

.institution-name {
    font-size: 20px;
    font-weight: 900;
    color: var(--primary);
    font-family: var(--font-tajawal);
}

.header-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 5px;
}

.header-divider::before, .header-divider::after {
    content: '';
    height: 1.5px;
    width: 80px;
    background: linear-gradient(90deg, transparent, var(--secondary), transparent);
}

.diamond {
    width: 8px;
    height: 8px;
    background-color: var(--secondary);
    transform: rotate(45deg);
    margin: 0 10px;
}

/* وشاح عنوان الامتحان المنتصف */
.exam-ribbon-wrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
    z-index: 1;
    position: relative;
}

.exam-ribbon {
    background-color: var(--primary);
    color: #ffffff;
    padding: 8px 45px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 15px;
    position: relative;
    border: 2px solid var(--secondary);
    box-shadow: 0 4px 6px rgba(27,117,188,0.15);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* صندوق بيانات الطالب المطور */
.student-info-box {
    border: 1.5px solid var(--secondary);
    border-radius: 12px;
    padding: 18px 25px;
    margin-bottom: 25px;
    background: #fffcf9;
    z-index: 1;
    position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.01);
}

.info-row-full {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 12px;
    border-bottom: 1px dashed rgba(245,130,32,0.3);
    margin-bottom: 12px;
    font-size: 15px;
}

.info-row-full i {
    color: var(--secondary);
    font-size: 18px;
}

.info-row-full .label {
    font-weight: 700;
    color: var(--slate-700);
}

.info-row-full .value-name {
    font-weight: 900;
    color: var(--primary);
    font-size: 17px;
}

.info-grid-three {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 15px;
}

.info-column {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.info-column i {
    color: var(--secondary);
    font-size: 16px;
}

.info-column .label {
    font-weight: 700;
    color: var(--slate-700);
}

.info-column .value {
    font-weight: 800;
    color: var(--primary);
}

/* جدول الدرجات الأفقي التفاعلي */
.horizontal-table-wrapper {
    margin-bottom: 25px;
    z-index: 1;
    position: relative;
    width: 100%;
    overflow-x: auto; /* السماح بالتمرير اللطيف على مقاسات الجوال لحماية سلامة النصوص */
}

.horizontal-table {
    width: 100%;
    table-layout: auto; /* ضبط العرض ديناميكياً حسب طول النص لمنع أي تداخل */
    border-collapse: collapse;
    border: 1.5px solid var(--secondary);
    border-radius: 10px;
    overflow: hidden;
}

.table-header-row th {
    background-color: var(--primary);
    color: #ffffff;
    padding: 12px 10px;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    border: 1px solid var(--secondary);
    white-space: nowrap; /* إجبار اسم المادة على البقاء في سطر واحد لمنع التداخل */
}

.table-header-row th .subject-title {
    display: block;
    margin-bottom: 3px;
    line-height: 1.2;
}

.table-header-row th .max-grade-label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    opacity: 0.9;
}

.table-grade-row td {
    padding: 14px 10px;
    font-size: 14px;
    font-weight: 800;
    text-align: center;
    border: 1px solid var(--secondary);
    background-color: #ffffff;
    white-space: nowrap; /* منع تداخل الأرقام والدرجات */
}

.header-label-cell, .grade-label-cell {
    background-color: #fcf6f0 !important;
    color: var(--primary) !important;
    font-weight: 800 !important;
    text-align: right !important;
    padding-right: 15px !important;
    font-size: 14px !important;
    white-space: nowrap;
}

.total-header-cell, .total-grade-cell {
    /* تترك العروض حرة ليتحكم بها المتصفح تلقائياً حسب النص */
}

.passed-grade {
    color: var(--success);
    font-weight: 900;
}

.failed-grade {
    color: var(--error);
    font-weight: 900;
}

.absent-badge {
    color: var(--error);
    font-size: 12px;
    font-weight: 800;
}

.optional-badge {
    color: var(--slate-700);
    font-size: 12px;
    font-weight: 500;
}

.total-header-cell {
    background-color: var(--secondary) !important;
    border-color: var(--secondary) !important;
}

.total-grade-cell {
    background-color: #fef6f0 !important;
    border-color: var(--secondary) !important;
}

/* صندوق تعليق رائد الصف المطور */
.teacher-comment-box {
    border: 1.5px solid var(--secondary);
    border-radius: 12px;
    padding: 12px 18px;
    margin-bottom: 25px;
    background: #ffffff;
    z-index: 1;
    position: relative;
}

.comment-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 5px;
}

.comment-body {
    font-size: 12px;
    color: var(--slate-700);
    line-height: 1.6;
    font-weight: 600;
}

/* التواقيع السفلية والختم المدمج */
.signatures-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 30px;
    padding: 0 10px;
    margin-bottom: 25px;
    z-index: 1;
    position: relative;
}

.signature-line {
    font-size: 12px;
    font-weight: 800;
    color: var(--slate-700);
    display: flex;
    align-items: center;
    gap: 8px;
    width: 260px;
}

.signature-line i {
    color: var(--primary);
}

.school-seal {
    width: 75px;
    height: 75px;
    border: 2px dashed var(--secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(-8deg);
    background-color: #fffcf9;
}

.seal-inner {
    font-size: 9px;
    font-weight: 900;
    color: var(--slate-400);
    text-align: center;
    line-height: 1.3;
}

/* الزخرفة والتمويج السفلي */
.bottom-decorative-wave {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 25px;
    background: linear-gradient(135deg, var(--primary) 0%, #125488 100%);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    border-top: 3px solid var(--secondary);
    z-index: 0;
}

.bottom-medal-seal {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 32px;
    background-color: var(--secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    z-index: 1;
}

.bottom-medal-seal i {
    color: #ffffff;
    font-size: 12px;
}

/* تحسينات الطباعة للـ A4 */
@media print {
    body {
        background-color: #ffffff !important;
        background-image: none !important;
        color: #000000 !important;
        font-size: 11px;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    body::before, body::after {
        display: none !important;
    }
    .portal-container {
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }
    .certificate-card {
        border: 6px double var(--primary) !important;
        box-shadow: none !important;
        background: #ffffff !important;
        padding: 20px 25px 35px 25px !important;
        margin-top: 0 !important;
        border-radius: 12px !important;
        width: 100% !important;
        position: relative !important;
        page-break-inside: avoid !important;
    }
    .btn-submit, .search-box, .portal-subtitle, .logo-container img:not(.print-logo), #print-btn-group, .portal-footer, #balloons-container {
        display: none !important;
    }
    
    /* تقليل المسافات العمودية في الطباعة لضمان ملاءمتها لصفحة A4 واحدة */
    .cert-header {
        margin-bottom: 12px !important;
        padding-bottom: 8px !important;
    }
    .exam-ribbon-wrapper {
        margin-bottom: 12px !important;
    }
    .exam-ribbon {
        padding: 6px 30px !important;
        font-size: 13px !important;
    }
    .student-info-box {
        margin-bottom: 15px !important;
        padding: 12px 20px !important;
    }
    .info-row-full {
        padding-bottom: 8px !important;
        margin-bottom: 8px !important;
        font-size: 13px !important;
    }
    .info-row-full .value-name {
        font-size: 15px !important;
    }
    .horizontal-table-wrapper {
        margin-bottom: 15px !important;
    }
    .table-grade-row td {
        padding: 8px !important;
        font-size: 12px !important;
    }
    .teacher-comment-box {
        margin-bottom: 15px !important;
        padding: 8px 15px !important;
    }
    
    .table-header-row th {
        background-color: var(--primary) !important;
        color: #ffffff !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .total-header-cell {
        background-color: var(--secondary) !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .header-label-cell, .grade-label-cell {
        background-color: #fcf6f0 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .total-grade-cell {
        background-color: #fef6f0 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .student-info-box {
        background-color: #fffcf9 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .bottom-decorative-wave {
        background: var(--primary) !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .bottom-medal-seal {
        background-color: var(--secondary) !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* بالونات احتفالية عائمة */
.balloon {
    position: fixed;
    bottom: -100px;
    width: 42px;
    height: 54px;
    border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
    z-index: 999;
    opacity: 0.8;
    animation: floatUp 7s linear infinite;
    pointer-events: none;
}

.balloon::after {
    content: "";
    position: absolute;
    bottom: -8px;
    left: 20px;
    width: 2px;
    height: 12px;
    background-color: #94a3b8;
}

@keyframes floatUp {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 0.8;
    }
    90% {
        opacity: 0.8;
    }
    100% {
        transform: translateY(-115vh) rotate(20deg);
        opacity: 0;
    }
}
