/* ==================== المتغيرات الأساسية (لوحة الألوان) ==================== */
:root {
    --primary: #1a252f;          /* لون رئيسي داكن للترويسات */
    --secondary: #2c3e50;        /* لون ثانوي لشرائط التنقل */
    --accent: #e74c3c;           /* لون الخطر والإلغاء (أحمر) */
    --success: #27ae60;          /* لون النجاح والتعزيز (أخضر) */
    --info: #2980b9;             /* لون المعلومات والأزرار الأساسية (أزرق) */
    --warning: #f39c12;          /* لون التنبيهات (برتقالي) */
    --bg-color: #ecf0f1;         /* لون خلفية النظام */
    --official-border: #bdc3c7;  /* لون الحدود الرسمية */
    --whatsapp: #25D366;         /* لون الواتساب الرسمي */
}

/* ==================== التنسيقات العامة ==================== */
* { 
    box-sizing: border-box; 
    font-family: 'Cairo', sans-serif; 
    user-select: none; /* منع تحديد النصوص لمنع التلاعب */
}

body { 
    margin: 0; 
    background-color: var(--bg-color); 
    color: #333; 
    overflow-x: hidden; 
    -webkit-touch-callout: none; 
}

/* استثناء حقول الإدخال لتسمح بالكتابة وتحديد النص */
input, textarea, select { 
    user-select: auto; 
}

/* ==================== فئات المساعدة (Utility Classes) ==================== */
.view-hidden { display: none !important; }
.view-active { display: block !important; }
.hidden-btn { display: none; }
.padding-15 { padding: 15px; }
.margin-0 { margin: 0; }
.margin-5-0 { margin: 5px 0; }
.margin-0-bold { margin: 0; font-weight: bold; }
.mt-5 { margin-top: 5px; }
.mt-10 { margin-top: 10px; }
.mt-20 { margin-top: 20px; }
.mt-30 { margin-top: 30px; }
.mb-0 { margin-bottom: 0; }
.font-14 { font-size: 14px; }
.font-15-bold { font-size: 15px; font-weight: bold; }
.font-16 { font-size: 16px; }
.color-info { color: var(--info); }
.color-accent { color: var(--accent); }
.color-export { color: #16a085; }
.center-text { text-align: center; }
.align-end { align-items: flex-end; }
.full-width { width: 100%; }
.overflow-x-auto { overflow-x: auto; }

/* ==================== تصميم الأزرار ==================== */
.btn { 
    background: var(--success); 
    color: white; 
    border: none; 
    padding: 10px 15px; 
    border-radius: 5px; 
    cursor: pointer; 
    font-weight: bold; 
    transition: 0.3s; 
    font-size: 14px; 
    text-decoration: none; 
    display: inline-flex; 
    align-items: center; 
    justify-content: center; 
    gap: 5px; 
}

.btn:hover { background: #219653; } 
.btn:disabled { background: #95a5a6; cursor: not-allowed; }

.btn-danger { background: var(--accent); } 
.btn-danger:hover { background: #c0392b; } 

.btn-primary { background: var(--info); } 
.btn-primary:hover { background: #2471a3; } 

.btn-warning { background: var(--warning); color: #fff; } 
.btn-warning:hover { background: #d68910; } 

.btn-whatsapp { background: var(--whatsapp); color: white; }
.btn-whatsapp:hover { background: #128C7E; }

.btn-purple { background: #8e44ad; color: white; }
.btn-purple:hover { background: #732d91; }

.btn-tall { height: 42px; margin-bottom: 15px; }
.btn-small { padding: 5px 10px; font-size: 12px; }

/* ==================== النماذج وحقول الإدخال ==================== */
.form-group { 
    margin-bottom: 15px; 
    width: 100%; 
} 

.form-group label { 
    display: block; 
    margin-bottom: 5px; 
    font-weight: bold; 
    font-size: 14px; 
} 

.form-group input, 
.form-group select, 
.form-group textarea { 
    width: 100%; 
    padding: 10px; 
    border: 1px solid #ccc; 
    border-radius: 5px; 
    font-family: 'Cairo', sans-serif; 
    font-size: 14px; 
}

/* ==================== الشبكات (Grids) ==================== */
.responsive-grid { 
    display: grid; 
    gap: 15px; 
    grid-template-columns: 1fr; 
} 

.grid-auto-fit { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-1 { grid-template-columns: 1fr; }
.span-2 { grid-column: span 2; }

@media (min-width: 600px) { 
    .responsive-grid:not(.grid-auto-fit):not(.grid-2):not(.grid-1) { grid-template-columns: repeat(2, 1fr); } 
} 
@media (min-width: 900px) { 
    .responsive-grid:not(.grid-auto-fit):not(.grid-2):not(.grid-1) { grid-template-columns: repeat(4, 1fr); } 
}

/* ==================== الجداول المتجاوبة ==================== */
.table-responsive { 
    width: 100%; 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch; 
    margin-top: 15px; 
    background: white; 
    border-radius: 5px; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.1); 
}

table { 
    width: 100%; 
    border-collapse: collapse; 
    min-width: 600px; 
} 

table, th, td { 
    border: 1px solid #eee; 
} 

th, td { 
    padding: 12px; 
    text-align: center; 
    font-size: 14px; 
} 

th { 
    background-color: var(--primary); 
    color: white; 
    white-space: nowrap; 
}

/* ==================== بوابة الدخول الرئيسية ==================== */
#portalView { 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    min-height: 100vh; 
    background: linear-gradient(135deg, var(--primary), var(--secondary)); 
    color: white; 
    padding: 20px; 
}

.portal-header { text-align: center; margin-bottom: 30px; } 
.portal-header h1 { font-size: clamp(24px, 5vw, 42px); margin: 0; font-weight: 900; } 
.portal-header p { font-size: clamp(14px, 3vw, 18px); color: #bdc3c7; margin-top: 10px; }

.login-cards { 
    display: flex; 
    gap: 20px; 
    flex-wrap: wrap; 
    justify-content: center; 
    width: 100%; 
    max-width: 800px; 
}

.login-card { 
    background: white; 
    color: #333; 
    padding: 35px 25px; 
    border-radius: 15px; 
    width: 100%; 
    max-width: 350px; 
    text-align: center; 
    box-shadow: 0 10px 25px rgba(0,0,0,0.2); 
}

.login-card h2 { margin-top: 0; font-size: 22px; color: #2c3e50; } 
.card-admin { border-top: 6px solid var(--info); } 
.card-parent { border-top: 6px solid var(--success); }

.developer-footer-text { margin-top: 40px; font-size: 14px; color: #bdc3c7; text-align: center; }

/* ==================== النوافذ المنبثقة (Modals) ==================== */
.modal { 
    display: none; 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background: rgba(0,0,0,0.7); 
    justify-content: center; 
    align-items: center; 
    z-index: 1000; 
    padding: 10px; 
} 

.modal-content { 
    background: white; 
    padding: 20px; 
    border-radius: 10px; 
    width: 100%; 
    max-width: 1200px; 
    max-height: 95vh; 
    overflow-y: auto; 
} 

.modal-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    border-bottom: 2px solid #eee; 
    padding-bottom: 10px; 
    margin-bottom: 20px; 
}

/* ==================== التبويبات (Tabs) ==================== */
.tabs { 
    display: flex; 
    border-bottom: 2px solid #eee; 
    margin-bottom: 20px; 
    overflow-x: auto; 
    white-space: nowrap; 
    -webkit-overflow-scrolling: touch; 
} 

.tab { 
    padding: 10px 15px; 
    cursor: pointer; 
    font-weight: bold; 
    border-bottom: 3px solid transparent; 
    font-size: 14px; 
} 

.tab.active { border-bottom-color: var(--success); color: var(--success); } 
.danger-tab { color: var(--accent); }
.danger-tab.active { border-bottom-color: var(--accent); }

.tab-content { display: none; } 
.tab-content.active { display: block; }

/* ==================== أقسام الإدارة (Management Sections) ==================== */
.management-section { 
    background: #f8f9fa; 
    border: 1px solid #e9ecef; 
    border-radius: 8px; 
    padding: 20px; 
    margin-bottom: 20px; 
} 

.management-section h3 { 
    margin-top: 0; 
    color: var(--primary); 
    border-bottom: 2px solid #ddd; 
    padding-bottom: 10px; 
    font-size: 18px; 
}

.header-flex { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.flex-end { display: flex; align-items: flex-end; }
.flex-gap { display: flex; gap: 10px; flex-wrap: wrap; }
.divider { border: 1px solid #eee; margin: 15px 0; }
.bg-export { background: #e8f8f5; border-color: #1abc9c; }

/* ==================== الترويسة وشرائط التنقل (Header & Nav) ==================== */
header { 
    background-color: var(--primary); 
    color: white; 
    padding: 15px 20px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    flex-wrap: wrap; 
    gap: 10px; 
    box-shadow: 0 4px 6px rgba(0,0,0,0.1); 
} 

.header-title-wrapper { display: flex; align-items: center; gap: 15px; flex-wrap: wrap; }
header h1 { margin: 0; font-size: clamp(18px, 4vw, 24px); font-weight: 900; }
.header-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

/* رادار السحابة */
.cloud-radar {
    display: flex; 
    align-items: center; 
    gap: 8px; 
    background: rgba(0, 0, 0, 0.2); 
    padding: 5px 12px; 
    border-radius: 20px;
    font-size: 13px;
}

.radar-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #f1c40f; 
    box-shadow: 0 0 5px rgba(255,255,255,0.5);
}

.top-nav { 
    background: var(--secondary); 
    display: flex; 
    overflow-x: auto; 
    white-space: nowrap; 
} 

.nav-btn { 
    background: transparent; 
    color: white; 
    border: none; 
    padding: 15px 20px; 
    font-size: 14px; 
    cursor: pointer; 
    font-weight: bold; 
    border-bottom: 3px solid transparent; 
} 

.nav-btn.active { border-bottom-color: var(--accent); color: var(--accent); }

/* الفلاتر العلوية */
.filters { 
    padding: 15px; 
    text-align: center; 
    background: white; 
    margin: 15px; 
    border-radius: 10px; 
    box-shadow: 0 2px 10px rgba(0,0,0,0.05); 
    display: flex; 
    flex-wrap: wrap; 
    gap: 10px; 
    justify-content: center; 
} 

.filters select { 
    padding: 8px; 
    border-radius: 5px; 
    border: 1px solid #ccc; 
    font-weight: bold; 
    flex: 1; 
    min-width: 120px; 
}

/* ==================== لوحة النجوم (السلوك) ==================== */
.students-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); 
    gap: 20px; 
    padding: 15px; 
    justify-items: center; 
} 

.student-card { 
    text-align: center; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    width: 100%; 
    max-width: 200px; 
} 

.frame-circle { 
    width: 120px; 
    height: 120px; 
    border-radius: 50%; 
    border: 4px dashed #f39c12; 
    padding: 4px; 
    background: white; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.1); 
    position: relative; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    overflow: hidden; 
} 

.frame-circle img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; } 

.counter-box { 
    display: flex; 
    align-items: center; 
    background: black; 
    color: white; 
    border-radius: 5px; 
    margin-top: 15px; 
    padding: 5px; 
    width: 110px; 
    justify-content: space-between; 
} 

.score-display { font-size: 20px; font-weight: bold; width: 50px; text-align: center; } 

.controls { display: flex; flex-direction: column; gap: 2px; } 
.controls button { 
    background: #e67e22; 
    border: none; 
    color: white; 
    width: 35px; 
    height: 22px; 
    cursor: pointer; 
    font-size: 14px; 
    line-height: 1; 
    border-radius: 3px; 
} 

.controls button:hover { background: #d35400; } 
.controls .btn-down { background: #9b59b6; } 

.student-name { margin-top: 10px; font-weight: bold; font-size: 16px; word-wrap: break-word; color: var(--primary); }

/* ==================== واجهة ولي الأمر ==================== */
.container-main { max-width: 1000px; margin: auto; padding: 20px; }
.welcome-text { margin: 0; color: var(--primary); }
.highlight-name { color: var(--accent); }
.grade-text { margin: 5px 0 0 0; font-weight: bold; }
.total-score-display { font-size: 48px; margin: 10px 0; color: var(--success); }
.score-label { font-weight: bold; }

/* ==================== التقارير الرسمية ==================== */
.report-container { 
    background: #fff; 
    padding: 30px; 
    border: 2px solid var(--official-border); 
    border-radius: 5px; 
    margin-top: 20px; 
} 

.report-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    border-bottom: 2px solid var(--primary); 
    padding-bottom: 15px; 
    margin-bottom: 15px; 
    flex-wrap: wrap; 
    gap: 15px; 
    text-align: center; 
} 

.report-header img { width: 80px; height: 80px; object-fit: contain; } 
.student-report-img { border-radius: 50%; object-fit: cover; display: none; }
.report-header .titles { flex-grow: 1; min-width: 200px; } 
.report-header .titles h2 { margin: 0 0 5px 0; color: var(--primary); font-size: 22px; font-weight: 900;} 

.report-section-title { border-bottom: 2px solid #eee; padding-bottom: 5px; }

.report-footer { 
    display: flex; 
    justify-content: space-between; 
    margin-top: 30px; 
    padding-top: 20px; 
    border-top: 1px solid #eee; 
    text-align: center; 
    font-weight: bold; 
    flex-wrap: wrap; 
    gap: 20px; 
}

.stamp-img { height: 70px; margin-top: 5px; object-fit: contain; display: none; }

/* ==================== خطة الواجبات الأسبوعية المصورة (Infographic) ==================== */
.hidden-export-wrapper { display: none; overflow-x: auto; margin-top: 20px; }

.weekly-plan-export {
    background: #ffffff;
    border: 10px solid #f39c12;
    border-radius: 15px;
    padding: 40px;
    text-align: center;
    min-width: 700px;
}

.export-header-flex {
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    border-bottom: 2px solid #34495e; 
    padding-bottom: 15px; 
    margin-bottom: 20px;
}

.export-logo { width: 80px; height: 80px; object-fit: contain; }

.weekly-plan-export h1 { color: #2c3e50; font-size: 32px; margin-bottom: 5px; }

.export-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.export-th { background: #2c3e50; color: white; padding: 15px; font-size: 18px; border: 1px solid #ddd; }

.value-box {
    background: linear-gradient(135deg, #f1c40f, #f39c12);
    color: white;
    padding: 15px;
    border-radius: 10px;
    margin-top: 30px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.value-title { font-size: 18px; display: block; margin-bottom: 5px; font-weight: bold; }
.value-content { font-size: 24px; font-weight: bold; }

.export-footer-signature { margin-top: 30px; text-align: left; font-weight: bold; font-size: 18px; }

/* ==================== شهادة الطالب المثالي ==================== */
.ideal-cert-area {
    background: #fff; 
    border: 10px double #f39c12; 
    padding: 40px; 
    border-radius: 15px; 
    text-align: center; 
    min-width: 600px;
}

.cert-title { color: #2c3e50; font-size: 38px; margin-bottom: 5px; }
.cert-subtitle { color: #7f8c8d; margin-top: 0; }

.cert-img-wrapper {
    margin: 20px auto; 
    width: 150px; 
    height: 150px; 
    border-radius: 50%; 
    border: 5px solid #e74c3c; 
    overflow: hidden; 
    background: #fff;
}

.cert-img { width: 100%; height: 100%; object-fit: cover; }
.cert-name { color: #c0392b; font-size: 36px; margin: 10px 0; }
.cert-msg { font-size: 20px; line-height: 1.6; }

.cert-footer {
    display: flex; 
    justify-content: space-between; 
    margin-top: 40px; 
    font-weight: bold;
}

/* ==================== رفع الوسائط (Media Uploads) ==================== */
.upload-wrapper { 
    position: relative; 
    overflow: hidden; 
    display: inline-block; 
    cursor: pointer; 
} 

.upload-wrapper input[type=file] { 
    font-size: 100px; 
    position: absolute; 
    left: 0; 
    top: 0; 
    opacity: 0; 
    cursor: pointer; 
    height: 100%; 
}

.media-box {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
}

.preview-area {
    margin-top: 15px;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 1px dashed #ccc;
    padding: 10px;
    border-radius: 5px;
}

.preview-area img {
    max-width: 100%;
    max-height: 100px;
    object-fit: contain;
}

.audio-list {
    list-style: none;
    padding: 0;
    margin-top: 10px;
    text-align: right;
    max-height: 150px;
    overflow-y: auto;
}

.audio-list li {
    background: #f1f2f6;
    padding: 8px;
    margin-bottom: 5px;
    border-radius: 4px;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ==================== بروتوكولات إعادة الضبط ==================== */
.danger-section { border-color: var(--accent); background: #fdf2e9; }
.reset-box { margin-top: 30px; padding: 20px; border: 2px dashed; border-radius: 10px; background: white; }
.soft-reset { border-color: #e67e22; }
.soft-reset-title { margin-top: 0; color: #e67e22; }
.hard-reset { border-color: var(--accent); }
.hard-reset-title { margin-top: 0; color: var(--accent); }

/* ==================== مؤشرات التحميل السحابية ==================== */
#loader { 
    display: none; 
    position: fixed; 
    bottom: 20px; 
    right: 20px; 
    background: var(--primary); 
    color: white; 
    padding: 10px 20px; 
    border-radius: 30px; 
    z-index: 9999; 
    align-items: center; 
    gap: 10px; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.3); 
    font-size: 14px; 
    font-weight: bold; 
} 

.spinner { 
    border: 3px solid rgba(255,255,255,0.3); 
    border-top: 3px solid white; 
    border-radius: 50%; 
    width: 20px; 
    height: 20px; 
    animation: spin 1s linear infinite; 
} 

@keyframes spin { 
    0% { transform: rotate(0deg); } 
    100% { transform: rotate(360deg); } 
}

#fullLoader { 
    display: none; 
    position: fixed; 
    top:0; 
    left:0; 
    width:100%; 
    height:100%; 
    background:rgba(255,255,255,0.9); 
    z-index:10000; 
    justify-content:center; 
    align-items:center; 
    flex-direction:column; 
} 

.full-spinner { 
    border: 5px solid #f3f3f3; 
    border-top: 5px solid var(--info); 
    border-radius: 50%; 
    width: 60px; 
    height: 60px; 
    animation: spin 1s linear infinite; 
}

/* ==================== الهيكلة المدرسية وشجرة العرض (V12 التحديث المرن) ==================== */
.structure-box {
    margin-top: 15px; 
    background: #fff; 
    padding: 15px; 
    border-radius: 5px; 
    border: 1px solid #eee;
}

.tree-list { list-style-type: none; padding-right: 0; } 
.tree-list li { margin-bottom: 10px; background: white; padding: 10px; border-radius: 5px; border: 1px solid #eee; } 
.tree-sublist { padding-right: 20px; list-style-type: none; margin-top: 10px; color: #34495e; }

.structure-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fdfdfd;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #e1e8ed;
    margin-bottom: 8px;
}
.grade-header { background: #f4f6f8; border-color: #d1d8dd; }
.structure-actions { display: flex; gap: 5px; }

.classes-wrapper { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; padding-right: 20px; }
.class-badge {
    background: #e8f4f8;
    color: #2980b9;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    border: 1px solid #bce0f0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.class-actions { display: flex; gap: 4px; }
.class-actions i { cursor: pointer; opacity: 0.7; transition: 0.2s; font-style: normal; }
.class-actions i:hover { opacity: 1; transform: scale(1.1); }

/* ==================== تذييل المطور ==================== */
.developer-footer { 
    text-align: center; 
    padding: 20px; 
    margin-top: 40px; 
    background: #1a252f; 
    color: #bdc3c7; 
    font-size: 14px; 
} 

.developer-footer span { font-weight: bold; color: white; }

/* ==================== تنسيق الطباعة ==================== */
.print-area { padding: 20px; background: #fff; }
.print-header { text-align: center; border-bottom: 2px solid #000; padding-bottom: 10px; }
.print-table { width: 100%; border-collapse: collapse; margin-top: 20px; }

@media print { 
    body * { visibility: hidden; } 
    #printableArea, #printableArea * { visibility: visible; } 
    #printableArea { position: absolute; left: 0; top: 0; width: 100%; margin: 0; padding: 0; } 
    .btn, .tabs, .management-section:not(#printableArea .management-section) { display: none !important; } 
}