/* =========================================
   1. إعدادات عامة ومتغيرات
   ========================================= */
:root {
    --primary: #1a7f7e;    /* الأخضر البترولي (لون المجمع) */
    --secondary: #d97706;  /* الذهبي الغامق */
    --bg-color: #f1f5f9;   /* لون خلفية التطبيق */
    --text-dark: #1e293b;
    --text-light: #64748b;
    --border-color: #cbd5e1;
}

* {
    box-sizing: border-box;
    font-family: 'Tajawal', 'Cairo', sans-serif;
}

body {
    background-color: var(--bg-color);
    margin: 0;
    display: flex;
    justify-content: center;
    padding: 20px;
    min-height: 100vh;
    direction: rtl;
}

.app-container {
    display: flex;
    gap: 25px;
    width: 100%;
    max-width: 1350px;
    align-items: flex-start;
}

/* =========================================
   2. لوحة التحكم (اليمين)
   ========================================= */
.editor-panel {
    flex: 0 0 380px; /* عرض ثابت للوحة */
    background: #ffffff;
    padding: 25px;
    border-radius: 16px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05);
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto; /* سكرول إذا كانت الشاشة صغيرة */
}

/* رأس اللوحة */
.panel-header {
    display: flex;
    gap: 15px;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f1f5f9;
}

.header-icon {
    width: 48px;
    height: 48px;
    background: var(--primary);
    color: white;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    box-shadow: 0 4px 10px rgba(26, 127, 126, 0.2);
}

.panel-header h2 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--text-dark);
}

.panel-header p {
    margin: 4px 0 0;
    font-size: 0.85rem;
    color: var(--text-light);
}

/* النماذج والحقول */
.form-group {
    margin-bottom: 16px;
}

.highlight-group {
    background: #f8fafc;
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-dark);
    margin-bottom: 8px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

label i {
    color: var(--primary);
}

input[type="text"],
input[type="date"],
select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    background: #fff;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 127, 126, 0.1);
}

/* منطقة رفع الصور */
.upload-area {
    border: 2px dashed var(--border-color);
    padding: 20px;
    text-align: center;
    border-radius: 10px;
    cursor: pointer;
    transition: 0.2s;
    background: #f8fafc;
}

.upload-area:hover {
    background: #f0fdfa;
    border-color: var(--primary);
}

.upload-icon {
    font-size: 2.5rem;
    color: #94a3b8;
    margin-bottom: 10px;
    display: block;
}

.upload-hint {
    display: block;
    font-size: 0.75rem;
    color: #94a3b8;
    margin-top: 5px;
}

/* مصغرات الصور */
.upload-thumbnails {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 12px;
}

.thumb-item {
    position: relative;
    aspect-ratio: 1;
}

.thumb-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}

.thumb-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.counter-badge {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 8px;
}
.counter-badge.valid { color: var(--primary); font-weight: bold; }

/* الأزرار */
.actions-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid #f1f5f9;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    transition: transform 0.1s ease;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-danger { background: #fee2e2; color: #ef4444; }
.btn-danger:hover { background: #fecaca; }

.main-actions { display: flex; gap: 10px; }

.btn-secondary { background: #f1f5f9; color: var(--text-dark); border: 1px solid #cbd5e1; }
.btn-secondary:hover { background: #e2e8f0; }

.btn-primary { background: var(--primary); color: white; box-shadow: 0 4px 10px rgba(26, 127, 126, 0.3); }
.btn-primary:hover { background: #136362; }

/* =========================================
   3. منطقة المعاينة (A4)
   ========================================= */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.preview-toolbar {
    width: 100%;
    max-width: 210mm;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    color: var(--text-light);
}

.template-wrapper {
    width: 210mm; /* عرض A4 ثابت */
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.08);
}

.report-paper {
    width: 210mm;
    min-height: 297mm; /* ارتفاع A4 */
    background: #ffffff;
    padding: 15mm; /* هوامش الورقة */
    position: relative;
    display: flex;
    flex-direction: column;
    /* خلفية ناعمة جداً */
    background-image: radial-gradient(#f8fafc 1px, transparent 1px);
    background-size: 20px 20px;
}

/* --- الهيدر (الرأس) --- */
.report-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 120px;
    margin-bottom: 15px;
}

.header-right {
    width: 130px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.school-logo {
    max-width: 100%;
    max-height: 110px;
    object-fit: contain;
}

.header-center {
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.school-name {
    margin: 0;
    color: var(--primary);
    font-size: 1.6rem;
    font-weight: 800;
    font-family: 'Cairo', sans-serif;
    line-height: 1.2;
}

.section-name {
    margin: 5px 0;
    color: var(--text-dark);
    font-size: 1.1rem;
    font-weight: 600;
}

/* --- إصلاح الشريط الذهبي (Badge) --- */
.report-type-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--secondary); /* الذهبي */
    color: #ffffff !important;    /* نص أبيض إجباري */
    padding: 6px 25px;
    border-radius: 50px;
    margin-top: 8px;
    font-size: 1rem;
    font-weight: bold;
    box-shadow: 0 3px 6px rgba(217, 119, 6, 0.25);
    z-index: 10;
    min-width: 160px;
}

.report-type-badge i {
    font-size: 1rem;
}

.header-left {
    width: 140px;
    font-size: 0.85rem;
    border-right: 2px solid #e2e8f0;
    padding-right: 15px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.date-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.d-label { color: var(--text-light); font-weight: 700; }
.d-value { font-family: 'Courier New', monospace; font-weight: 700; color: var(--text-dark); }
.hijri .d-value { color: var(--primary); }

/* فاصل زخرفي */
.divider-ornament {
    height: 4px;
    background: linear-gradient(90deg, transparent, var(--primary), var(--secondary), transparent);
    margin: 5px 0 25px;
    border-radius: 2px;
    opacity: 0.8;
}

/* --- جسم التقرير --- */
.report-body {
    flex: 1;
}

.topic-container {
    text-align: center;
    margin-bottom: 25px;
}

.topic-label {
    display: inline-block;
    background: #f1f5f9;
    padding: 4px 15px;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 8px;
}

.topic-text {
    margin: 0;
    font-family: 'Cairo', sans-serif;
    color: var(--text-dark);
    font-size: 1.4rem;
    border-bottom: 2px dashed #cbd5e1;
    padding-bottom: 10px;
    display: inline-block;
    min-width: 70%;
    line-height: 1.4;
}

/* --- نظام الكولاج الذكي (Smart Collage) --- */
.images-grid {
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    border: 4px solid #fff;
    box-shadow: 0 0 0 1px #e2e8f0;
    margin-bottom: 20px;
}

.images-grid.empty-grid {
    height: 300px;
    border: 2px dashed #cbd5e1;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #94a3b8;
    box-shadow: none;
}
.placeholder-content i { font-size: 3rem; margin-bottom: 10px; display: block; }

.collage-item {
    position: relative;
    overflow: hidden;
    border: 2px solid #fff; /* فواصل بيضاء بين الصور */
    background: #eee;
}
.collage-item img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* تنسيقات الشبكات المختلفة (ارتفاعات مضبوطة لـ A4) */

/* صورة واحدة */
.grid-1 { height: 350px; display: flex; }
.item-100 { width: 100%; }

/* صورتان */
.grid-2 { height: 320px; display: flex; }
.grid-2 .item-50 { flex: 1; }

/* 3 صور */
.grid-3-asymmetric { height: 360px; display: flex; }
.item-large-left { flex: 1.5; }
.collage-column { flex: 1; display: flex; flex-direction: column; }
.collage-column .item-50 { flex: 1; }

/* 4 صور (2x2) */
.grid-4 { height: 380px; display: grid; grid-template-columns: 1fr 1fr; }

/* 5 صور */
.grid-5 { height: 450px; display: flex; flex-direction: column; }
.collage-row { display: flex; flex: 1; }
.collage-row .item-50 { flex: 1; }
.collage-row .item-33 { flex: 1; }

/* 6 صور (3x2) */
.grid-6 { 
    height: 400px; /* ارتفاع مناسب لعدم تجاوز الصفحة */
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    grid-template-rows: repeat(2, 1fr); 
}

/* --- التذييل (الفوتر) --- */
.report-footer {
    margin-top: auto;
    padding-top: 20px;
    position: relative;
}

.sign-area {
    position: absolute;
    bottom: 50px; /* رفع التوقيعات قليلاً */
    width: 220px;
    text-align: center;
}

.sign-area.right { right: 20px; }
.sign-area.left { left: 20px; }

.sign-role {
    display: block;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 45px; /* مسافة للتوقيع */
    font-size: 1rem;
}

.sign-name {
    display: block;
    color: var(--text-light);
    font-family: 'Cairo';
    font-weight: 600;
}

.footer-bar {
    text-align: center;
    border-top: 1px solid #e2e8f0;
    padding-top: 12px;
    margin-top: 70px;
    font-size: 0.8rem;
    color: var(--text-light);
}

/* زخارف الزوايا */
.corner-deco {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 3px solid var(--primary);
    opacity: 0.3;
}

.top-left { top: 15mm; left: 15mm; border-right: none; border-bottom: none; }
.bottom-right { bottom: 15mm; right: 15mm; border-left: none; border-top: none; }
