/* ===== المتغيرات العامة ===== */
:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --background: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --radius-sm: 8px;
}

/* ===== الأساسيات ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Cairo', sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ===== الهيدر ===== */
header {
    text-align: center;
    padding: 40px 20px;
}

.logo {
    font-size: 4rem;
    margin-bottom: 10px;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.back-link {
    display: inline-block;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    margin-bottom: 20px;
    transition: color 0.3s;
}

.back-link:hover {
    color: var(--primary-dark);
}

/* ===== صندوق البحث ===== */
.search-box {
    display: flex;
    gap: 10px;
    max-width: 700px;
    margin: 0 auto 40px;
    background: var(--card-bg);
    padding: 10px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.search-box input {
    flex: 1;
    padding: 15px 20px;
    font-size: 1.1rem;
    font-family: 'Cairo', sans-serif;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.3s;
}

.search-box input:focus {
    border-color: var(--primary-color);
}

.search-box button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 15px 30px;
    font-size: 1.1rem;
    font-family: 'Cairo', sans-serif;
    font-weight: 600;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.3s, transform 0.2s;
}

.search-box button:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.search-box button:active {
    transform: translateY(0);
}

/* ===== التحميل ===== */
.loading-section {
    text-align: center;
    padding: 60px 20px;
}

.loading-section.hidden {
    display: none;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.loading-subtext {
    color: var(--text-secondary);
}

/* ===== المميزات ===== */
.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.feature {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    transition: transform 0.3s, box-shadow 0.3s;
}

.feature:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.feature-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 15px;
}

.feature h3 {
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.feature p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* ===== دليل التصنيفات ===== */
.classification-guide {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.classification-guide h3 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.classifications {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.classification {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 25px;
    border-radius: var(--radius-sm);
    min-width: 100px;
}

.classification .grade {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
}

.classification .range {
    font-size: 0.9rem;
    color: rgba(255,255,255,0.9);
}

.classification.a-star { background: linear-gradient(135deg, #ffd700, #ffb700); }
.classification.a { background: linear-gradient(135deg, #22c55e, #16a34a); }
.classification.b { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.classification.c { background: linear-gradient(135deg, #f59e0b, #d97706); }
.classification.review { background: linear-gradient(135deg, #64748b, #475569); }

/* ===== صفحة النتائج ===== */
.results-page header {
    padding: 20px;
    text-align: right;
}

.results-page header h1 {
    font-size: 1.8rem;
    text-align: center;
}

.result-section {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 25px;
}

.result-section h2 {
    font-size: 1.3rem;
    color: var(--text-primary);
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

/* ===== البيانات الأساسية ===== */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
}

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

.info-item label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.info-item span,
.info-item a {
    color: var(--text-primary);
    font-size: 1rem;
}

.info-item a {
    color: var(--primary-color);
    text-decoration: none;
}

.info-item a:hover {
    text-decoration: underline;
}

/* ===== كارت المعيار ===== */
.criterion-card {
    background: var(--background);
    border-radius: var(--radius-sm);
    padding: 20px;
    margin-bottom: 15px;
    border-right: 4px solid var(--primary-color);
}

.criterion-card.confirmed {
    border-right-color: var(--success-color);
}

.criterion-card.unconfirmed {
    border-right-color: var(--warning-color);
}

.criterion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.criterion-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.criterion-score {
    display: flex;
    align-items: center;
    gap: 10px;
}

.score-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.status-badge.confirmed {
    background: #dcfce7;
    color: #166534;
}

.status-badge.unconfirmed {
    background: #fef3c7;
    color: #92400e;
}

.criterion-level {
    background: var(--card-bg);
    padding: 10px 15px;
    border-radius: var(--radius-sm);
    margin-bottom: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.criterion-justification h4,
.criterion-sources h4,
.criterion-note h4 {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.criterion-justification ul {
    list-style: none;
    padding: 0;
}

.criterion-justification li {
    padding: 5px 0;
    padding-right: 20px;
    position: relative;
}

.criterion-justification li::before {
    content: '•';
    position: absolute;
    right: 0;
    color: var(--primary-color);
}

.criterion-sources {
    margin-top: 15px;
}

.criterion-sources a {
    display: block;
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 3px 0;
    word-break: break-all;
}

.criterion-sources a:hover {
    text-decoration: underline;
}

.criterion-sources a::before {
    content: '🔗 ';
}

.criterion-note {
    margin-top: 15px;
    background: #fef3c7;
    padding: 15px;
    border-radius: var(--radius-sm);
}

.criterion-note p {
    color: #92400e;
}

/* ===== جدول الملخص ===== */
.summary-table {
    width: 100%;
    border-collapse: collapse;
}

.summary-table th,
.summary-table td {
    padding: 12px 15px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.summary-table th {
    background: var(--background);
    font-weight: 600;
    color: var(--text-secondary);
}

.summary-table tbody tr:hover {
    background: var(--background);
}

.summary-table .total-row {
    background: var(--primary-color);
    color: white;
}

.summary-table .total-row td {
    font-weight: 700;
    font-size: 1.1rem;
    border: none;
}

/* ===== صندوق التصنيف ===== */
.classification-box {
    text-align: center;
    padding: 40px;
}

.classification-box .grade {
    font-size: 4rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.classification-box .score {
    font-size: 1.3rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
}

.classification-box .note {
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

/* تلوين التصنيفات */
.grade-a-star { color: #d97706 !important; }
.grade-a { color: #16a34a !important; }
.grade-b { color: #2563eb !important; }
.grade-c { color: #f59e0b !important; }
.grade-review { color: #64748b !important; }

/* ===== العناصر غير المؤكدة ===== */
.unconfirmed-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.unconfirmed-table th,
.unconfirmed-table td {
    padding: 12px 15px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.unconfirmed-table th {
    background: var(--background);
}

.potential-scores {
    background: var(--background);
    padding: 20px;
    border-radius: var(--radius-sm);
}

.potential-scores p {
    margin: 10px 0;
}

.potential-high {
    color: var(--success-color);
}

.current-score {
    color: var(--text-primary);
}

/* ===== الأزرار ===== */
.actions-section {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
    margin-top: 30px;
}

.btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 15px 25px;
    font-size: 1rem;
    font-family: 'Cairo', sans-serif;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.3s;
}

.btn-confirm {
    background: var(--warning-color);
    color: white;
}

.btn-confirm:hover {
    background: #d97706;
}

.btn-pdf {
    background: #ef4444;
    color: white;
}

.btn-pdf:hover {
    background: #dc2626;
}

.btn-excel {
    background: #22c55e;
    color: white;
}

.btn-excel:hover {
    background: #16a34a;
}

/* ===== النوافذ المنبثقة ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.2rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body {
    padding: 20px;
}

.modal-intro {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.confirm-item {
    background: var(--background);
    padding: 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 15px;
}

.confirm-item label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
}

.confirm-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-top: 3px;
}

.confirm-item .item-text {
    flex: 1;
}

.confirm-item .item-title {
    font-weight: 600;
    display: block;
    margin-bottom: 5px;
}

.confirm-item .item-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.confirm-item .evidence-input {
    margin-top: 15px;
    display: none;
}

.confirm-item input:checked ~ .item-text .evidence-input {
    display: block;
}

.evidence-input input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: 'Cairo', sans-serif;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.btn-cancel {
    background: var(--background);
    color: var(--text-primary);
}

.btn-submit {
    background: var(--primary-color);
    color: white;
}

.btn-submit:hover {
    background: var(--primary-dark);
}

/* نافذة النتيجة */
.modal-success .modal-header {
    background: #dcfce7;
}

.modal-success .modal-header h2 {
    color: #166534;
}

#confirmChanges .change-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

#confirmChanges .change-item:last-child {
    border-bottom: none;
}

#confirmChanges .new-totals {
    background: var(--background);
    padding: 20px;
    border-radius: var(--radius-sm);
    margin-top: 20px;
    text-align: center;
}

#confirmChanges .new-totals .new-score {
    font-size: 2rem;
    font-weight: 700;
    color: var(--success-color);
}

#confirmChanges .new-totals .new-grade {
    font-size: 1.5rem;
    font-weight: 700;
}

/* ===== الفوتر ===== */
footer {
    text-align: center;
    padding: 30px;
    color: var(--text-secondary);
}

/* ===== التجاوب ===== */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }
    
    .search-box {
        flex-direction: column;
    }
    
    .search-box button {
        justify-content: center;
    }
    
    .classifications {
        gap: 10px;
    }
    
    .classification {
        padding: 10px 15px;
        min-width: 80px;
    }
    
    .actions-section {
        flex-direction: column;
    }
    
    .btn {
        justify-content: center;
    }
}

/* ===== الطباعة ===== */
@media print {
    .actions-section,
    .back-link {
        display: none;
    }
    
    .result-section {
        box-shadow: none;
        border: 1px solid var(--border-color);
    }
}

/* ===== الأنيميشن ===== */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== عناصر التعديل الجديدة ===== */

/* اختيار الدرجة */
.score-select {
    padding: 8px 12px;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'Cairo', sans-serif;
    border: 2px solid var(--primary-color);
    border-radius: var(--radius-sm);
    background: white;
    color: var(--primary-color);
    cursor: pointer;
    min-width: 70px;
}

.score-select:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.score-max {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-right: 5px;
}

/* تبديل التأكيد */
.confirm-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    margin-right: 15px;
}

.confirm-toggle input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.toggle-label {
    font-size: 0.9rem;
    font-weight: 600;
}

/* حقل المستوى */
.criterion-level {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 15px 0;
    padding: 10px;
    background: var(--background);
    border-radius: var(--radius-sm);
}

.criterion-level label {
    font-weight: 600;
    white-space: nowrap;
}

.level-input {
    flex: 1;
    padding: 10px 15px;
    font-family: 'Cairo', sans-serif;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: white;
}

.level-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* قائمة التبريرات */
.justification-list {
    list-style: none;
    margin: 10px 0;
}

.editable-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--background);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.editable-item .item-text {
    flex: 1;
}

/* أزرار التعديل والحذف */
.edit-btn, .delete-btn {
    padding: 5px 10px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.edit-btn {
    background: var(--warning-color);
    color: white;
}

.edit-btn:hover {
    background: #d97706;
}

.delete-btn {
    background: var(--danger-color);
    color: white;
}

.delete-btn:hover {
    background: #dc2626;
}

/* زر الإضافة */
.add-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 15px;
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Cairo', sans-serif;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 10px;
}

.add-btn:hover {
    background: #16a34a;
}

/* قائمة المصادر */
.sources-list {
    margin: 10px 0;
}

.source-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--background);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.source-item a {
    flex: 1;
    color: var(--primary-color);
    text-decoration: none;
    word-break: break-all;
}

.source-item a:hover {
    text-decoration: underline;
}

/* ملاحظة عدم التأكد */
.criterion-note {
    margin-top: 15px;
    padding: 15px;
    background: #fef3c7;
    border-radius: var(--radius-sm);
    border-right: 4px solid var(--warning-color);
}

.criterion-note h4 {
    color: #92400e;
    margin-bottom: 10px;
}

.note-input {
    width: 100%;
    padding: 10px 15px;
    font-family: 'Cairo', sans-serif;
    font-size: 1rem;
    border: 2px solid #fcd34d;
    border-radius: var(--radius-sm);
    background: white;
}

.note-input:focus {
    outline: none;
    border-color: var(--warning-color);
}

/* رسالة فارغة */
.empty-message {
    color: var(--text-secondary);
    font-style: italic;
    padding: 10px;
}

/* تحسين بطاقة المعيار */
.criterion-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border-right: 5px solid var(--border-color);
    transition: all 0.3s;
}

.criterion-card.confirmed {
    border-right-color: var(--success-color);
}

.criterion-card.unconfirmed {
    border-right-color: var(--warning-color);
}

.criterion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.criterion-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.criterion-score {
    display: flex;
    align-items: center;
    gap: 10px;
}

.criterion-justification h4,
.criterion-sources h4 {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 10px;
}
