/* === 1. إعدادات عامة (الوضع الداكن) === */
body {
    font-family: Arial, sans-serif;
    direction: rtl; 
    background-color: #222831; /* لون الخلفية الرئيسي (داكن) */
    color: #eeeeee; /* لون الخط الأساسي (فاتح) */
    margin: 0;
    padding: 0;
}

/* === 2. القائمة الجانبية (Sidebar) === */
.sidebar {
    width: 240px;
    background-color: #393e46; /* لون القائمة */
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    box-shadow: -2px 0 5px rgba(0,0,0,0.3);
    z-index: 100;
}
.sidebar-header {
    padding: 20px;
    text-align: center;
    background-color: #1a1e24; /* لون أغمق للهيدر */
    color: #eeeeee;
    border-bottom: 1px solid #444;
}
.sidebar-header h3 {
    margin: 0;
    color: #00bfff; /* لون سماوي */
}
.sidebar-nav a {
    display: block;
    padding: 15px 20px;
    color: #eeeeee;
    text-decoration: none;
    border-bottom: 1px solid #444;
    transition: background-color 0.2s;
}
.sidebar-nav a:hover {
    background-color: #4a515c;
}
.sidebar-nav a.active {
    background-color: #007bff; /* لون الرابط النشط */
    font-weight: bold;
}

/* === 3. حاوية الصفحة (Page Container) === */
.page-container {
    margin-right: 240px; /* إزاحة المحتوى بمقدار عرض القائمة */
    transition: margin-right 0.3s;
}

/* الشريط العلوي */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #393e46; /* لون الشريط العلوي */
    padding: 15px 30px;
    color: white;
    border-bottom: 1px solid #444;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.top-bar .welcome-message { font-size: 18px; }
.top-bar .logout-link a {
    color: #ffffff;
    text-decoration: none;
    background-color: #dc3545;
    padding: 8px 12px;
    border-radius: 4px;
    transition: background-color 0.2s;
}
.top-bar .logout-link a:hover { background-color: #c82333; }

/* المحتوى الرئيسي (داخل حاوية الصفحة) */
.main-content {
    padding: 25px;
    max-width: 1400px;
    margin: 0 auto;
}
.main-content h1 {
    border-bottom: 2px solid #444; /* خط فاصل (فاتح) */
    padding-bottom: 10px;
    color: #eeeeee; /* لون العنوان (فاتح) */
}


/* === 4. تنسيقات صفحة الدخول (login.php) === */
body.login-body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}
/* إرجاع حاوية الصفحة لوضعها الطبيعي في صفحة الدخول */
body.login-body .page-container {
    margin-right: 0;
}
.login-container {
    background-color: #393e46; /* لون كونتينر الدخول (داكن) */
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    width: 350px;
}
.login-container h2 {
    text-align: center;
    color: #eeeeee; /* لون العنوان (فاتح) */
    margin-top: 0;
}
.login-container .input-group { margin-bottom: 20px; }
.login-container .input-group label {
    display: block;
    margin-bottom: 8px;
    color: #dddddd; /* لون الليبل (فاتح) */
}
.login-container .input-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #555;
    background-color: #222831; /* لون حقل الإدخال (داكن) */
    color: #eeeeee; /* لون الخط (فاتح) */
    border-radius: 4px;
    box-sizing: border-box; 
}
.login-container .btn {
    width: 100%;
    padding: 12px;
    background-color: #007bff; /* إعادة اللون الأزرق */
    border: none;
    border-radius: 4px;
    color: white; /* إعادة لون الخط الأبيض */
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.login-container .btn:hover {
    background-color: #0056b3; /* إضافة تأثير الـ Hover */
}
.login-container .error-message { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; padding: 10px; border-radius: 4px; margin-bottom: 15px; text-align: center; }

/* === 5. تنسيقات كروت الإحصائيات (KPI) === */
.kpi-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 0; 
}
.kpi-box {
    background-color: #393e46; /* لون الخلفية (داكن) */
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    border-left: 5px solid #555;
}
.kpi-title {
    font-size: 16px;
    color: #dddddd;
    margin-bottom: 10px;
}
.kpi-value {
    font-size: 28px;
    font-weight: bold;
    color: #eeeeee;
}
.kpi-box.kpi-overdue { border-left-color: #dc3545; }
.kpi-box.kpi-overdue .kpi-value { color: #dc3545; }
.kpi-box.kpi-expected { border-left-color: #28a745; }
.kpi-box.kpi-expected .kpi-value { color: #28a745; }
.kpi-box.kpi-customers { border-left-color: #ffc107; }
.kpi-box.kpi-customers .kpi-value { color: #ffc107; }
.kpi-box.kpi-active { border-left-color: #17a2b8; }
.kpi-box.kpi-active .kpi-value { color: #17a2b8; }

/* === 6. تنسيقات الأقسام والفورم === */
.section-container {
    background-color: #393e46; /* لون خلفية الأقسام (داكن) */
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    padding: 25px;
    margin-bottom: 30px;
}
.content-area { margin-top: 20px; overflow-x: auto; }
hr.separator { border: 0; height: 1px; background-color: #444; margin: 30px 0; }

.form-container {
    background-color: #2d3239; /* خلفية الفورم (أغمق) */
    padding: 25px;
    border: 1px solid #444;
    border-radius: 8px;
    margin-top: 20px;
}
.input-group { margin-bottom: 15px; }
.input-group label {
    display: block;
    margin-bottom: 5px;
    color: #dddddd; /* لون الليبل (فاتح) */
    font-weight: bold;
}
.input-group input[type="text"],
.input-group input[type="file"],
.input-group input[type="date"],
.input-group input[type="search"], /* <-- هذا هو السطر الجديد */
.input-group textarea,
.input-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #555;
    background-color: #222831; /* لون حقل الإدخال (داكن) */
    color: #eeeeee; /* لون الخط (فاتح) */
    border-radius: 4px;
    box-sizing: border-box; 
}
.input-group textarea { resize: vertical; }
.form-actions { margin-top: 20px; display: flex; gap: 10px; }

/* === 7. تنسيقات الأزرار (عامة) === */
.btn { padding: 10px 20px; border: none; border-radius: 4px; color: white; font-size: 16px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn-primary { background-color: #007bff; }
.btn-primary:hover { background-color: #0056b3; }
.btn-success { background-color: #28a745; }
.btn-success:hover { background-color: #218838; }
.btn-secondary { background-color: #6c757d; }
.btn-secondary:hover { background-color: #5a6268; }
.btn-danger { background-color: #dc3545; }
.btn-danger:hover { background-color: #c82333; }
.btn-warning { background-color: #ffc107; color: #212529; }
.btn-warning:hover { background-color: #e0a800; color: #212529; }
.btn-info { background-color: #17a2b8; }
.btn-info:hover { background-color: #138496; }
.btn-small { padding: 5px 10px; font-size: 14px; margin-left: 5px; }

/* === 8. تنسيقات رسائل التنبيه === */
.message { padding: 15px; margin-bottom: 20px; border-radius: 4px; text-align: center; }
.message.success { color: #d4edda; background-color: #218838; border: 1px solid #28a745; }
.message.error { color: #f8d7da; background-color: #c82333; border: 1px solid #dc3545; }

/* === 9. تنسيقات جدول البيانات === */
.data-table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.data-table th, .data-table td {
    border: 1px solid #444; /* لون حدود الجدول */
    padding: 12px;
    text-align: right;
}
.data-table th {
    background-color: #2d3239; /* لون الهيدر (داكن) */
    color: #eeeeee; /* لون خط الهيدر (فاتح) */
    font-weight: bold;
}
.data-table tbody tr:nth-child(even) {
    background-color: #2d3239; /* لون الصف الفردي */
}
.data-table tbody tr:hover {
    background-color: #4a515c; /* لون الهوفر */
}

/* === 10. تنسيقات حالة الأقساط === */
.data-table tr.status-overdue-heavy { background-color: #5a1e24 !important; border-left: 5px solid #dc3545; }
.data-table tr.status-overdue-light { background-color: #59481e !important; border-left: 5px solid #ffc107; }
.data-table tr.status-due { background-color: #1e4b2a !important; border-left: 5px solid #28a745; }
.data-table tr.status-finished { background-color: #4a515c !important; color: #aaa; }
.data-table tr.status-finished a.btn { opacity: 0.7; }
.data-table td.status-cell { font-weight: bold; font-size: 0.95em; }

/* === 11. تنسيقات صفحة التفاصيل === */
.details-table { width: 100%; border-collapse: collapse; }
.details-table th, .details-table td {
    padding: 12px;
    border-bottom: 1px solid #444;
    text-align: right;
}
.details-table th { width: 25%; font-weight: bold; background-color: #2d3239; }
.documents-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 15px; margin-top: 20px; }
.document-item { border: 1px solid #555; border-radius: 5px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.document-item a { text-decoration: none; color: #eeeeee; display: block; }
.document-item img { display: block; background-color: #555; }
.document-item .doc-title { display: block; padding: 10px; text-align: center; background-color: #2d3239; }
.document-item:hover { box-shadow: 0 2px 5px rgba(0,0,0,0.3); }

.details-table tr.highlighted-row { background-color: #2d3239; }
.details-table tr.bold-row th,
.details-table tr.bold-row td { font-weight: bold; font-size: 1.1em; color: #00bfff; }
.details-table tr.bold-row[style*="#59481e"] { background-color: #59481e !important; color: #ffc107; }

.note { font-size: 14px; color: #dddddd; background-color: #2d3239; border: 1px solid #444; padding: 10px; border-radius: 4px; }

/* === 12. تنسيق قسم الدفعات === */
.payment-section { display: grid; grid-template-columns: 1fr 2fr; gap: 25px; align-items: flex-start; }
.payment-history .data-table { margin-top: 0; }
.payment-history .data-table td,
.payment-history .data-table th { padding: 8px; }
@media (max-width: 768px) {
    /* (تنسيقات الموبايل) */
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        box-shadow: none;
    }
    .page-container {
        margin-right: 0;
    }
    .kpi-container {
        grid-template-columns: 1fr;
    }
    .payment-section {
        grid-template-columns: 1fr; 
    }
}


/* === 14. تنسيق زر حذف المستند (جديد) === */
.document-item {
    position: relative; /* ضروري لتثبيت الزر */
}

.doc-view-link {
    text-decoration: none;
    color: #eeeeee;
    display: block;
}

.doc-delete-btn {
    position: absolute;
    top: 5px;
    left: 5px; /* سيظهر يسار الصورة من الأعلى */
    width: 30px;
    height: 30px;
    background-color: rgba(220, 53, 69, 0.9); /* أحمر */
    color: white;
    text-decoration: none;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    font-weight: bold;
    border-radius: 50%; /* دائري */
    border: 2px solid white;
    opacity: 0; /* إخفاء الزر افتراضياً */
    transition: opacity 0.2s;
}

.document-item:hover .doc-delete-btn {
    opacity: 1; /* إظهار الزر عند الهوفر على الصورة */
}

.doc-delete-btn:hover {
    background-color: rgba(192, 35, 51, 1); /* لون أغمق عند الهوفر */
}



/* === 15. تنسيقات فورم البحث والفلترة (جديد) === */
.search-container {
    background-color: #2d3239; /* نفس لون خلفية الفورم */
    padding: 20px;
    border: 1px solid #444;
    border-radius: 8px;
    margin-bottom: 20px;
}
.search-container .input-group {
    margin-bottom: 0; /* إزالة الهامش السفلي لترتيب أفضل */
}
.search-container form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end; /* لمحاذاة الأزرار مع الحقول */
    gap: 15px;
}
.search-container form .btn {
    align-self: flex-end; /* التأكد من محاذاة الأزرار */
}
/* تنسيق خاص بفلترة الأقساط */
.filter-grid {
    display: grid;
    grid-template-columns: 2fr 1fr; /* جعل حقل البحث أعرض من الفلتر */
    gap: 15px;
    flex-grow: 1; /* لجعل هذا الجزء يملأ المساحة المتاحة */
}
/* للشاشات الصغيرة (الموبايل) */
@media (max-width: 992px) {
    .filter-grid {
        grid-template-columns: 1fr; /* جعلهم تحت بعض */
    }
}


/* === 16. تنسيقات رابط الملف الشخصي (جديد) === */
.top-bar-link {
    color: #00bfff; /* لون سماوي */
    text-decoration: none;
    font-size: 16px;
    font-weight: normal;
    margin-right: 10px;
    transition: color 0.2s;
}
.top-bar-link:hover,
.top-bar-link.active {
    color: #ffffff; /* أبيض */
    text-decoration: underline;
}


/* === 17. تنسيق عدد الأقساط النشطة (جديد) === */
.status-active-count {
    background-color: #17a2b8; /* أزرق (نفس لون كارت الإحصائيات) */
    color: #ffffff;
    padding: 3px 8px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.9em;
}

