@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap');

/* --- General Styles --- */
body { 
    font-family: 'Cairo', sans-serif;
    background-color: #f0f2f5; 
    color: #333; 
    margin: 0;
    line-height: 1.6;
    direction: rtl; /* لضمان الاتجاه من اليمين لليسار */
    text-align: right; /* لضمان محاذاة النص لليمين */
}

.container { 
    max-width: 1200px; 
    margin: 20px auto; 
    padding: 20px; 
}

h1, h2 { 
    color: #0d2c4f;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 10px;
    margin-top: 0;
}

h1 {
    text-align: center;
    border-bottom: none;
    margin-bottom: 20px;
}

/* --- Statistics Section --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}
.stat-card-link {
    text-decoration: none;
    color: inherit;
}
.stat-card {
    background-color: #ffffff;
    padding: 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transition: transform 0.3s ease;
}
.stat-card:hover {
    transform: translateY(-5px);
}
.stat-icon {
    font-size: 2.5em;
    padding: 15px;
    border-radius: 50%;
    color: #fff;
}
.stat-icon.outgoing { background-color: #c82333; }
.stat-icon.incoming { background-color: #218838; }
.stat-icon.today    { background-color: #ffc107; }
.stat-icon.total    { background-color: #007bff; }

.stat-info {
    display: flex;
    flex-direction: column;
}
.stat-number {
    font-size: 2em;
    font-weight: 700;
    color: #0d2c4f;
}
.stat-label {
    font-size: 1em;
    color: #6c757d;
}

/* --- Menu Styles --- */
.menu { 
    margin-bottom: 40px; 
    text-align: center; 
    background-color: #ffffff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}
.menu a {            
    display: inline-flex; /* استخدام flex لمحاذاة الأيقونة والنص */
    align-items: center;  /* محاذاة عمودية */
    gap: 8px;             /* مسافة بين الأيقونة والنص */
    padding: 10px 20px;
    margin: 5px;
    background-color: #007bff;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.3s ease;            
}
.menu a:hover { 
    background-color: #0056b3; 
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.2);
}

/* --- Main Grid Layout for sections (index.php) --- */
.grid { 
    display: grid; 
    grid-template-columns: 1fr; /* افتراضي لعمود واحد على الشاشات الصغيرة */
    gap: 40px; 
}

/* --- Card Grid Layout for correspondence items (index.php) --- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}
.card {
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
.card-header {
    padding: 15px;
    font-weight: 700;
    font-size: 1.1em;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-body {
    padding: 15px;
    flex-grow: 1;
}
.card-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: #4a5568;
}
.card-status {
    padding: 0 15px 15px;
}
.status-badge {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 0.9em;
    font-weight: 600;
    color: #fff;
}
/* Status Badge Colors */
.status-new { background-color: #007bff; } /* أزرق */
.status-progress { background-color: #ffc107; color: #212529; } /* أصفر */
.status-done { background-color: #6c757d; } /* رمادي */

.card-footer {
    padding: 15px;
    background-color: #f8f9fa;
    border-top: 1px solid #e2e8f0;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    display: flex;
    justify-content: space-between;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 600;
    color: #fff;
}
.badge-outgoing { background-color: #c82333; } /* أحمر داكن */
.badge-incoming { background-color: #218838; } /* أخضر داكن */

.no-items {
    background-color: #fff3cd;
    color: #856404;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

/* --- Table Styles (for view_all.php) --- */
table { 
    width: 100%; 
    border-collapse: collapse; 
    margin-top: 20px; 
    background-color: #ffffff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    border-radius: 8px;
    overflow: hidden; /* لضمان أن الحدود المستديرة تطبق على الجدول بالكامل */
}
th, td { 
    padding: 12px; 
    border: 1px solid #ddd; 
    text-align: right; 
}
th { 
    background-color: #f2f2f2; 
    font-weight: 600;
    color: #0d2c4f;
}

/* --- Filter Form Styles (for view_all.php) --- */
.filter-form { 
    background-color: #ffffff; /* تغيير الخلفية لتتناسب مع التصميم الجديد */
    padding: 20px; 
    border-radius: 8px; 
    margin-bottom: 20px; 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); 
    gap: 15px; 
    align-items: end; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.filter-form div { display: flex; flex-direction: column; }
.filter-form label { margin-bottom: 5px; font-weight: bold; color: #0d2c4f; }
.filter-form input, .filter-form select { padding: 8px; border: 1px solid #ccc; border-radius: 4px; }
.filter-form button { 
    background-color: #007bff; 
    color: white; 
    border: none; 
    padding: 10px; 
    border-radius: 4px; 
    cursor: pointer; 
    font-size: 16px; 
    font-weight: 600;
    transition: background-color 0.3s ease;
}
.filter-form button:hover { background-color: #0056b3; }
.export-button { background-color: #28a745 !important; } /* لون خاص لزر التصدير */
.export-button:hover { background-color: #218838 !important; }

/* --- Pagination Styles (for view_all.php) --- */
.pagination { text-align: center; margin-top: 20px; }
.pagination a { 
    color: #007bff; 
    padding: 8px 16px; 
    text-decoration: none; 
    border: 1px solid #ddd; 
    margin: 0 2px; 
    border-radius: 4px; 
    transition: background-color 0.3s ease, color 0.3s ease;
}
.pagination a.active { background-color: #007bff; color: white; border-color: #007bff; }
.pagination a:hover:not(.active) { background-color: #e2e8f0; }

/* --- No Results Message --- */
.no-results { 
    text-align: center; 
    padding: 20px; 
    background-color: #fff3cd; 
    color: #856404; 
    border-radius: 5px; 
    margin-top: 20px;
}

/* --- Responsive Styles --- */
@media (min-width: 992px) {
    .grid { grid-template-columns: 1fr 1fr; }            
}
@media (max-width: 768px) {
    .menu a { display: flex; justify-content: center; width: auto; } /* الأزرار تملأ العرض وتتوسط */
    .stats-grid { grid-template-columns: 1fr; } /* عمود واحد للإحصائيات */
    .card-grid { grid-template-columns: 1fr; } /* عمود واحد للبطاقات */
    .filter-form { grid-template-columns: 1fr; } /* عمود واحد للفلترة */
    table, .table-container { overflow-x: auto; display: block; width: 100%; } /* لجعل الجداول قابلة للتمرير أفقياً */
    table thead, table tbody, table th, table td, table tr { display: block; }
    table tr { margin-bottom: 15px; border: 1px solid #ddd; border-radius: 8px; }
    table td { text-align: right; border: none; position: relative; padding-right: 50%; }
    table td:before {
        position: absolute;
        right: 6px;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        content: attr(data-label); /* استخدام خاصية data-label لعرض عنوان العمود */
        font-weight: bold;
        color: #0d2c4f;
    }
}

/* --- Login Page Styles --- */
.login-body {
    background-color: #fff;
    margin: 0;
    height: 100vh;
    overflow: hidden;
}

.login-wrapper {
    display: flex;
    height: 100vh;
    width: 100%;
}

.branding-panel {
    flex: 1;
    background-image: linear-gradient(rgba(0, 50, 120, 0.7), rgba(0, 20, 80, 0.9)), url('https://images.pexels.com/photos/325185/pexels-photo-325185.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2');
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    text-align: center;
    padding: 40px;
}
.branding-panel h1 {
    font-size: 2.8em;
    font-weight: 700;
    margin-bottom: 10px;
    border: none;
    color: #fff;
}
.branding-panel p {
    font-size: 1.2em;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.8);
}

.login-form-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
}
.login-form {
    width: 100%;
    max-width: 400px;
}
.login-form h2 {
    border: none;
    text-align: center;
    font-size: 2em;
}
.login-subtitle {
    text-align: center;
    color: #6c757d;
    margin-bottom: 30px;
}
.input-group {
    position: relative;
    margin-bottom: 20px;
}
.input-group i {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #adb5bd;
}
.login-form input {
    width: 100%;
    padding: 12px 40px 12px 12px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    box-sizing: border-box;
    transition: border-color 0.3s ease;
}
.login-form input:focus {
    border-color: #007bff;
    outline: none;
}
.login-form button {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background-color: #007bff;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s ease;
}
.login-form button:hover {
    background-color: #0056b3;
}
.message.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 20px;
    text-align: center;
}

@media (max-width: 992px) {
    .branding-panel {
        display: none; /* إخفاء قسم الصورة على الشاشات الصغيرة للتركيز على النموذج */
    }
    .login-form-container {
        flex: 2; /* جعل النموذج يأخذ مساحة أكبر */
    }
}

/* --- Form Styles (for add/edit pages) --- */
.form-container {
    background-color: #ffffff;
    padding: 30px 40px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    max-width: 750px;
    margin: 40px auto;
}

.form-container h1 {
    text-align: center;
    margin-bottom: 30px;
    border-bottom: none;
    font-size: 1.8em;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #34495e;
}

.form-group input[type="text"],
.form-group input[type="date"],
.form-group input[type="file"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ced4da;
    border-radius: 5px;
    box-sizing: border-box;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: #007bff;
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}

.form-actions {
    display: flex;
    justify-content: flex-start; /* محاذاة العناصر للبداية */
    gap: 15px; /* مسافة بين الأزرار */
    align-items: center;
    margin-top: 30px;
    border-top: 1px solid #e9ecef;
    padding-top: 20px;
}

/* --- Footer Styles --- */
.site-footer {
    background-color: #0d2c4f; /* لون أزرق داكن ليتناسب مع المظهر العام */
    color: #ffffff;
    padding: 20px 0;
    text-align: center;
    margin-top: 40px; /* مسافة علوية لفصل التذييل عن المحتوى */
    border-top: 3px solid #007bff;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logout-link {
    color: #ffc107; /* لون أصفر للتباين */
    text-decoration: none;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: color 0.3s ease;
}

.logout-link:hover {
    color: #dc3545; /* لون أحمر عند التمرير للإشارة إلى إجراء الحذف/الخروج */
}