/* =========================================
   1. المتغيرات ونظام الألوان (Strategic Palette)
   ========================================= */
:root {
    /* Base Colors - تركيز على الألوان الرسمية */
    --primary-color: #0c4a6e;       /* أزرق داكن (للسلطة والجدية) */
    --primary-hover: #083344;
    --accent-color: #fbbf24;        /* ذهبي/أصفر (للتركيز والأهمية) */
    
    /* Action Colors */
    --secondary-btn: #3b82f6;       /* أزرق ثانوي للأزرار الإدارية */
    --secondary-btn-hover: #2563eb;
    --data-btn: #475569;            /* سُكني للبيانات الخام */
    --pdf-btn: #be123c;             /* أحمر (Rose) خاص للملفات والتقارير */
    
    /* Utility Colors */
    --bg-color: #f7f7f9;            /* خلفية ناعمة للصفحة */
    --card-bg: #ffffff;             /* خلفية البطاقات */
    --text-primary: #1e293b;        /* نص أساسي غامق */
    --text-secondary: #64748b;      /* نص ثانوي للشروحات */
    --border-color: #e2e8f0;        /* حدود خفيفة */
    --input-bg: #ffffff;            
    
    /* Semantic Colors */
    --danger-color: #dc2626;        /* أحمر فاقع للخطر والحذف فقط */
    --success-color: #16a34a;       /* أخضر للنجاح والتحميل */
    --warning-color: #f59e0b;       /* برتقالي للتحذير */
    
    /* Spacing & Typography */
    --radius: 12px;
    --spacing-unit: 25px; 
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); 
    --font-family: 'Almarai', sans-serif;
    --base-line-height: 1.7;
    --nav-height: 70px;             /* ارتفاع الناف بار الجديد */
}

/* =========================================
   2. التأسيس والخطوط (Base & Typography)
   ========================================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    direction: rtl;
    line-height: var(--base-line-height);
    /* تم تعديل الحشو لأن الناف بار سيأخذ مساحة من الأعلى */
    padding: 0 0 60px 0; 
    min-height: 100vh;
}

/* الحاوية الرئيسية للمحتوى */
.container { 
    max-width: 1000px; 
    margin: 30px auto; /* مسافة من الناف بار */
    padding: 0 15px; 
}

/* تنسيق الهيدر القديم (تم تخفيفه قليلاً) */
header { text-align: center; margin-bottom: 40px; }

.badge { 
    background-color: var(--accent-color); color: var(--text-primary); 
    padding: 4px 12px; border-radius: 20px; 
    font-size: 0.85rem; font-weight: 800; 
    display: inline-block;
}

header h1 { color: var(--primary-color); font-size: 2.5rem; margin: 10px 0; font-weight: 800; }
header p { color: var(--text-secondary); font-size: 1.1rem; }

/* =========================================
   3. شريط التنقل الجديد (Navbar Styling)
   ========================================= */
.navbar {
    background-color: var(--card-bg);
    height: var(--nav-height);
    width: 100%;
    position: sticky; /* التثبيت الذكي */
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    border-bottom: 1px solid var(--border-color);
}

/* العلامة التجارية (يمين) */
.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    color: var(--primary-color);
    font-size: 1.2rem;
    transition: opacity 0.2s;
}
.nav-brand:hover { opacity: 0.8; }
.nav-icon { font-size: 1.5rem; }

/* الروابط (وسط) */
.nav-links {
    display: flex;
    gap: 25px;
}
.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 700;
    font-size: 0.95rem;
    padding: 8px 12px;
    border-radius: 8px;
    transition: all 0.3s ease;
    position: relative;
}
.nav-link:hover {
    color: var(--primary-color);
    background-color: #f1f5f9;
}
/* الحالة النشطة (أنا هنا) */
.nav-link.active {
    color: var(--primary-color);
    background-color: #e0f2fe; /* لون خلفية خفيف للأزرق */
}
.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -22px; /* لتلامس حافة الناف بار السفلية */
    left: 0;
    right: 0;
    height: 3px;
    background-color: var(--primary-color);
    border-radius: 3px 3px 0 0;
}

/* منطقة المستخدم (يسار) */
.nav-user {
    display: flex;
    align-items: center;
}
.client-badge {
    background-color: #f1f5f9;
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    font-weight: 700;
    padding: 6px 15px;
    border-radius: 20px;
    font-size: 0.9rem;
}
.warning-badge {
    background-color: #fff7ed;
    color: var(--warning-color);
    border-color: #ffedd5;
}

/* استجابة للجوال (Mobile Responsive) */
@media (max-width: 768px) {
    .navbar { padding: 0 15px; overflow-x: auto; justify-content: start; gap: 20px; }
    .nav-links { gap: 10px; }
    .nav-link { font-size: 0.85rem; padding: 6px 10px; white-space: nowrap; }
    .nav-brand span.nav-title { display: none; } /* إخفاء النص والاكتفاء بالأيقونة */
}

/* =========================================
   4. البطاقات والنماذج (Forms & Sections)
   ========================================= */
.form-section, .management-area {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 35px;
    margin-bottom: var(--spacing-unit);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    position: relative;
}

.form-section h3, .management-area h3 {
    font-size: 1.35rem; 
    color: var(--primary-color);
    margin-bottom: 25px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
    font-weight: 800;
}

.form-group { margin-bottom: 25px; }

label { display: block; font-weight: 700; margin-bottom: 8px; color: var(--text-primary); font-size: 1rem; }
.sub-label { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 8px; margin-top: -4px; }

input, textarea, select {
    width: 100%; padding: 14px 18px; background-color: var(--input-bg);
    border: 2px solid var(--border-color); border-radius: var(--radius);
    font-family: var(--font-family); font-size: 1rem; color: var(--text-primary);
    transition: all 0.3s ease;
    -webkit-appearance: none; appearance: none;
}
textarea { min-height: 120px; }
input:focus, textarea:focus, select:focus {
    outline: none; border-color: var(--accent-color);
    box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.35); 
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; gap: 20px; } }

/* =========================================
   5. الأزرار (Buttons)
   ========================================= */
.btn {
    font-family: var(--font-family); font-weight: 700; padding: 12px 20px;
    border: none; border-radius: var(--radius); cursor: pointer;
    transition: all 0.3s; text-decoration: none; display: inline-block; text-align: center;
}
.btn-primary {
    background-color: var(--primary-color); color: white;
    font-weight: 800; font-size: 1.15rem; padding: 18px 50px;
    box-shadow: 0 4px 8px rgba(12, 74, 110, 0.4);
    width: 100%; max-width: 500px;
}
.btn-primary:hover:not(:disabled) { 
    background-color: var(--primary-hover); transform: translateY(-2px); 
    box-shadow: 0 10px 15px rgba(12, 74, 110, 0.5); 
}
.btn-secondary { background-color: var(--secondary-btn); color: white; width: 100%; }
.btn-secondary:hover { background-color: var(--secondary-btn-hover); }

.btn-small { font-size: 0.9rem; padding: 10px 18px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); white-space: nowrap; }

.btn-pdf { background: var(--pdf-btn); color: white; }
.btn-pdf:hover { background: #9f1239; }
.btn-csv { background: var(--data-btn); color: white; }

.btn-outline {
    background: transparent; border: 2px solid var(--border-color); 
    color: var(--text-secondary); margin-top: 10px;
}
.btn-outline:hover:not(:disabled) { border-color: var(--primary-color); color: var(--primary-color); }
.btn:disabled, .btn[disabled] { opacity: 0.6; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

/* =========================================
   6. مكونات (Components)
   ========================================= */
/* Loading */
.loading-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.9); z-index: 2000; /* أعلى من الناف بار */
    display: flex; justify-content: center; align-items: center; flex-direction: column;
}
.spinner {
    width: 50px; height: 50px; border: 5px solid #e2e8f0; border-top: 5px solid var(--primary-color); 
    border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Messages */
.message-box { padding: 15px; border-radius: var(--radius); margin-bottom: 20px; font-weight: 700; border: 1px solid transparent; }
.error-box { background: #fee2e2; color: var(--danger-color); border-color: #fca5a5; }
.success-box { background: #dcfce7; color: var(--success-color); border-color: #86efac; }
.info-box { background: #eff6ff; color: var(--secondary-btn); border-color: #93c5fd; }
.warning-box { background: #fffde1; color: var(--warning-color); border-color: #fcd34d; }

/* Markdown Report */
.markdown-body { padding: 20px 0; line-height: var(--base-line-height); }
.markdown-body h2 { 
    color: var(--primary-color); font-size: 1.8rem; margin-top: 35px; margin-bottom: 15px; 
    border-bottom: 2px solid var(--accent-color); padding-bottom: 10px; font-weight: 800;
}
.markdown-body h3 { 
    color: #4b5563; font-size: 1.4rem; margin-top: 25px; margin-bottom: 15px; 
    border-right: 4px solid var(--accent-color); padding-right: 10px; font-weight: 700;
    background: linear-gradient(90deg, #f8fafc 0%, transparent 100%);
}
.markdown-body table { width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 0.95rem; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border-color); padding: 12px; text-align: right; }
.markdown-body th { background-color: #f1f5f9; color: var(--text-primary); font-weight: 800; }

/* Records Grid */
.record-list-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; margin-top: 20px; }
.record-card {
    background: var(--card-bg); padding: 20px; border-radius: var(--radius);
    border: 1px solid var(--border-color); box-shadow: var(--shadow-sm); transition: transform 0.2s;
}
.record-card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); }
.record-actions { margin-top: 15px; display: flex; gap: 10px; border-top: 1px solid var(--border-color); padding-top: 15px; }

/* Dashboard Actions */
.dashboard-actions { display: flex; flex-wrap: wrap; gap: 15px; margin-bottom: 40px; justify-content: center; }
.dashboard-actions .btn { flex-grow: 1; min-width: 200px; }

.hidden { display: none !important; }