/* =============================================
   الاسيوطي للرخام والجرانيت - نظام إدارة
   ============================================= */

:root {
    --primary: #c0392b;
    --primary-dark: #922b21;
    --primary-light: #f5b7b1;
    --sidebar-width: 260px;
    --navbar-height: 58px;
    --sidebar-bg: #1a1f2e;
    --sidebar-text: #a8b0c8;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.05);
    --border-radius: 10px;
    --transition: all 0.22s ease;
    --border-color: #e2e8f0;
    --navbar-glass: rgba(192,57,43,0.97);
}

* { font-family: 'Cairo', sans-serif !important; }
.fw-500 { font-weight: 500 !important; }
.fw-600 { font-weight: 600 !important; }
.fw-700 { font-weight: 700 !important; }

body {
    background: #f3f4f8;
    min-height: 100vh;
    direction: rtl;
    color: #2d3748;
    font-size: 0.93rem;
}

/* =============================================
   شريط تقدم التنقل
   ============================================= */
#pageProgress {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, #fff 0%, rgba(255,255,255,0.7) 100%);
    z-index: 9999;
    width: 0;
    transition: width 0.4s ease, opacity 0.3s ease;
    opacity: 0;
}
#pageProgress.loading { width: 75%; opacity: 1; }
#pageProgress.done { width: 100%; opacity: 0; transition: width 0.2s ease, opacity 0.4s ease 0.1s; }

/* =============================================
   شريط التنقل العلوي
   ============================================= */
.navbar-main {
    background: linear-gradient(to left, var(--primary) 0%, var(--primary-dark) 100%);
    height: var(--navbar-height);
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1030;
    box-shadow: 0 2px 20px rgba(0,0,0,0.3);
}
.navbar-inner {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 14px;
    gap: 6px;
}

/* أزرار الأيقونات */
.nav-icon-btn {
    background: rgba(255,255,255,0.11);
    border: 1px solid rgba(255,255,255,0.18);
    color: #fff;
    border-radius: 8px;
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.18rem;
    cursor: pointer;
    transition: background 0.16s, border-color 0.16s, transform 0.12s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}
.nav-icon-btn:hover  { background: rgba(255,255,255,0.2);  border-color: rgba(255,255,255,0.38); }
.nav-icon-btn:active { background: rgba(255,255,255,0.28); transform: scale(0.93); }

/* منطقة الشعار - تأخذ حجمها الطبيعي فقط */
.nav-brand {
    display: flex; align-items: center; gap: 9px;
    color: #fff !important; text-decoration: none;
    flex: 0 0 auto;
    max-width: 320px;
    min-width: 0;
    padding: 0 2px;
}
.nav-logo {
    height: var(--logo-height, 26px);
    max-width: calc(var(--logo-height, 26px) * 3.5);
    object-fit: contain;
    flex-shrink: 0;
}
.nav-brand-icon { font-size: 1.1rem; flex-shrink: 0; opacity: 0.85; }
.nav-brand-text {
    font-size: 0.93rem; font-weight: 700; letter-spacing: 0.2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 230px;
}
.nav-brand-short { display: none; font-size: 0.9rem; font-weight: 700; white-space: nowrap; }

/* فراغ مرن يملأ المنتصف */
.nav-spacer { flex: 1; min-width: 8px; }

/* فاصل رأسي */
.nav-sep {
    width: 1px; height: 22px;
    background: rgba(255,255,255,0.18);
    flex-shrink: 0;
    margin: 0 2px;
}

/* مجموعة أدوات اليمين */
.nav-actions {
    display: flex; align-items: center; gap: 5px;
    flex-shrink: 0;
    margin-inline-start: auto;
    margin-right: 8px;
}

/* زر المستخدم - pill shape */
.nav-user-btn {
    display: flex; align-items: center; gap: 7px;
    background: rgba(255,255,255,0.13);
    border: 1px solid rgba(255,255,255,0.22);
    color: #fff;
    border-radius: 22px;
    padding: 4px 12px 4px 5px;
    cursor: pointer;
    transition: background 0.16s, border-color 0.16s, transform 0.12s;
    font-family: 'Cairo', sans-serif;
    font-size: 0.84rem; font-weight: 600;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    max-width: 200px;
}
.nav-user-btn:hover  { background: rgba(255,255,255,0.22); border-color: rgba(255,255,255,0.4); }
.nav-user-btn:active { transform: scale(0.97); }

.nav-user-avatar {
    width: 28px; height: 28px;
    background: rgba(255,255,255,0.28);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.82rem; font-weight: 800;
    flex-shrink: 0;
}
.nav-user-name { overflow: hidden; text-overflow: ellipsis; max-width: 100px; }
.nav-chevron { font-size: 0.6rem; opacity: 0.62; }

/* القائمة المنسدلة - مثبتة على اليسار في RTL */
.navbar-main .dropdown-menu {
    border-radius: 12px;
    border: 1px solid rgba(0,0,0,0.07);
    box-shadow: 0 8px 30px rgba(0,0,0,0.16);
    min-width: 215px;
    margin-top: 6px !important;
    left: 0 !important;
    right: auto !important;
}
[data-bs-theme="dark"] .navbar-main .dropdown-menu  { background: #1c2128; border-color: #2d3748; }
[data-bs-theme="dark"] .navbar-main .dropdown-item  { color: #c9d1d9; }
[data-bs-theme="dark"] .navbar-main .dropdown-item:hover { background: #21262d; }

/* =============================================
   القائمة الجانبية
   ============================================= */
.wrapper { padding-top: var(--navbar-height); min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    height: calc(100vh - var(--navbar-height));
    background: var(--sidebar-bg);
    position: fixed;
    top: var(--navbar-height);
    right: 0;
    z-index: 1020;
    overflow-y: scroll;
    overflow-x: hidden;
    transition: var(--transition);
    box-shadow: -3px 0 15px rgba(0,0,0,0.12);
}
.sidebar.collapsed { width: 0; overflow: hidden; }

/* غطاء الخلفية عند فتح الشريط في الموبايل */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1015;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

.sidebar-header {
    padding: 16px 20px 12px;
    color: rgba(255,255,255,0.4);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-nav { padding: 8px 10px 20px; }

.sidebar-nav .nav-link {
    color: var(--sidebar-text);
    padding: 9px 14px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: var(--transition);
    white-space: nowrap;
    text-decoration: none;
    border-radius: 8px;
    margin-bottom: 2px;
}
.sidebar-nav .nav-link i { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; opacity: 0.85; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,0.08); color: white; }
.sidebar-nav .nav-link:hover i { opacity: 1; }
.sidebar-nav .nav-link.active {
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    font-weight: 600;
    box-shadow: 0 3px 12px rgba(192,57,43,0.4);
}
.sidebar-nav .nav-link.active i { opacity: 1; }

.nav-section-title {
    color: rgba(255,255,255,0.28);
    font-size: 0.67rem;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    padding: 16px 14px 5px;
}

/* =============================================
   المحتوى الرئيسي
   ============================================= */
.main-content {
    margin-right: var(--sidebar-width);
    min-height: calc(100vh - var(--navbar-height));
    transition: var(--transition);
}
.main-content.expanded { margin-right: 0; }

/* =============================================
   عنوان الصفحة
   ============================================= */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border-color);
}
.page-title {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.page-subtitle { color: #718096; font-size: 0.83rem; margin: 0; }

/* =============================================
   البطاقات
   ============================================= */
.card {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    transition: var(--transition);
    background: #fff;
}
.card:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.09); }

.card-header {
    background: #fafbfc;
    border-bottom: 1px solid var(--border-color);
    padding: 13px 18px;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: var(--border-radius) var(--border-radius) 0 0 !important;
    color: #374151;
    display: flex;
    align-items: center;
}
.card-footer {
    background: #fafbfc;
    border-top: 1px solid var(--border-color);
    padding: 12px 18px;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
}

/* =============================================
   بطاقات الإحصاء - نمط التدرج
   ============================================= */
.stat-card {
    border-radius: var(--border-radius);
    padding: 20px 22px;
    color: white;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.13);
    transition: var(--transition);
    border: none !important;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(0,0,0,0.18); }
.stat-card .stat-icon {
    font-size: 4rem;
    opacity: 0.15;
    position: absolute;
    left: -5px;
    bottom: -10px;
    line-height: 1;
}
.stat-card .stat-value { font-size: 1.7rem; font-weight: 800; line-height: 1.15; }
.stat-card .stat-label { font-size: 0.82rem; opacity: 0.88; font-weight: 500; margin-bottom: 3px; }
.stat-card .stat-sub { font-size: 0.72rem; opacity: 0.68; }

/* ألوان بطاقات الإحصاء */
.bg-gradient-primary { background: linear-gradient(135deg, #c0392b 0%, #922b21 100%); }
.bg-gradient-success { background: linear-gradient(135deg, #047857 0%, #10b981 100%); }
.bg-gradient-warning { background: linear-gradient(135deg, #b45309 0%, #f59e0b 100%); }
.bg-gradient-info    { background: linear-gradient(135deg, #0369a1 0%, #38bdf8 100%); }
.bg-gradient-danger  { background: linear-gradient(135deg, #b91c1c 0%, #f87171 100%); }
.bg-gradient-purple  { background: linear-gradient(135deg, #6d28d9 0%, #a78bfa 100%); }

/* =============================================
   بطاقات الإحصاء - النمط الأفقي (بدون تدرج)
   ============================================= */
.stat-card-h {
    background: #fff;
    border-radius: var(--border-radius);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color) !important;
    transition: var(--transition);
}
.stat-card-h:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.1); transform: translateY(-2px); }
.stat-card-h .stat-icon-box {
    width: 54px;
    height: 54px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}
.stat-card-h .stat-info { flex: 1; min-width: 0; }
.stat-card-h .stat-value { font-size: 1.45rem; font-weight: 800; line-height: 1.15; }
.stat-card-h .stat-label { font-size: 0.8rem; color: #718096; font-weight: 500; }

/* =============================================
   الجداول
   ============================================= */
.table { margin-bottom: 0; font-size: 0.875rem; }
.table th {
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
    padding: 11px 14px;
}
.table td { vertical-align: middle; padding: 10px 14px; }
.table-dark { --bs-table-bg: #2d3748; }
.table-dark th { letter-spacing: 0.5px; }
.table-hover > tbody > tr:hover > * { background-color: rgba(139,69,19,0.04); }
.table-striped > tbody > tr:nth-of-type(odd) > * { background-color: rgba(0,0,0,0.018); }
.table-responsive { border-radius: 0 0 var(--border-radius) var(--border-radius); }

/* =============================================
   الأزرار
   ============================================= */
.btn { font-weight: 600; border-radius: 7px; transition: var(--transition); font-size: 0.875rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); color: white; }
.btn-sm { font-size: 0.78rem; padding: 4px 10px; border-radius: 6px; }
.btn-lg { font-size: 0.95rem; padding: 10px 24px; }

/* =============================================
   النماذج
   ============================================= */
.form-control, .form-select {
    border-radius: 8px;
    font-size: 0.9rem;
    padding: 8px 12px;
    border: 1px solid #d1d9e0;
    transition: var(--transition);
    background: #fff;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139,69,19,0.12);
    outline: none;
}
.form-label { font-weight: 600; font-size: 0.86rem; margin-bottom: 5px; color: #4a5568; }
.input-group-text { font-size: 0.88rem; background: #f8f9fa; border-color: #d1d9e0; color: #6c757d; }
.form-control-sm, .form-select-sm { font-size: 0.83rem; padding: 5px 10px; }

/* =============================================
   الشارات
   ============================================= */
.badge { font-size: 0.72rem; padding: 4px 9px; border-radius: 20px; font-weight: 600; }

/* =============================================
   ملاحظات
   ============================================= */
.note-item {
    background: #fffbea;
    border-right: 3px solid #f59e0b;
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 8px;
    font-size: 0.87rem;
    line-height: 1.7;
}

/* =============================================
   ملفات المرفقات
   ============================================= */
.file-item {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 9px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.84rem;
    transition: var(--transition);
    background: #fafbfc;
    margin-bottom: 4px;
}
.file-item:hover { background: #f0f4f8; border-color: #b0bec5; }
.file-item .file-icon { font-size: 1.4rem; }
.file-item .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* =============================================
   قوائم منسدلة (list-group)
   ============================================= */
.list-group-item { font-size: 0.88rem; padding: 11px 16px; border-color: var(--border-color); }
.list-group-flush > .list-group-item:last-child { border-bottom: 0; }

/* =============================================
   Modals
   ============================================= */
.modal-content { border-radius: 12px; border: none; box-shadow: 0 20px 60px rgba(0,0,0,0.18); }
.modal-header { border-bottom: 1px solid var(--border-color); padding: 16px 20px; }
.modal-footer { border-top: 1px solid var(--border-color); padding: 14px 20px; }
.modal-body { padding: 20px; }
.modal-title { font-weight: 700; font-size: 1rem; }

/* =============================================
   الوضع الليلي
   ============================================= */
[data-bs-theme="dark"] {
    --border-color: #2d3748;
    --card-shadow: 0 1px 4px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.2);
}
/* الهيدر في الوضع الليلي - نفس الألوان (gradient يطغى) */
[data-bs-theme="dark"] .navbar-main { box-shadow: 0 2px 16px rgba(0,0,0,0.45); }
[data-bs-theme="dark"] body { background: #0f1117; color: #c9d1d9; }
[data-bs-theme="dark"] .sidebar { background: #161b22; box-shadow: -3px 0 15px rgba(0,0,0,0.3); }
[data-bs-theme="dark"] .main-content { background: #0f1117; }
[data-bs-theme="dark"] .card { background: #1c2128; border-color: #2d3748; }
[data-bs-theme="dark"] .card:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.3); }
[data-bs-theme="dark"] .card-header { background: #161b22; border-color: #2d3748; color: #c9d1d9; }
[data-bs-theme="dark"] .card-footer { background: #161b22; border-color: #2d3748; }
[data-bs-theme="dark"] .page-header { border-color: #2d3748; }
[data-bs-theme="dark"] .table { color: #c9d1d9; }
[data-bs-theme="dark"] .table-dark { --bs-table-bg: #21262d; }
[data-bs-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * { background-color: rgba(255,255,255,0.025); }
[data-bs-theme="dark"] .table-hover > tbody > tr:hover > * { background-color: rgba(255,255,255,0.05); }
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select { background: #1c2128; border-color: #2d3748; color: #c9d1d9; }
[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus { border-color: var(--primary); background: #1c2128; }
[data-bs-theme="dark"] .input-group-text { background: #161b22; border-color: #2d3748; color: #8b949e; }
[data-bs-theme="dark"] .form-label { color: #8b949e; }
[data-bs-theme="dark"] .modal-content { background: #1c2128; }
[data-bs-theme="dark"] .modal-header,
[data-bs-theme="dark"] .modal-footer { border-color: #2d3748; }
[data-bs-theme="dark"] .note-item { background: #1a1500; border-color: #f59e0b; color: #e2c97e; }
[data-bs-theme="dark"] .file-item { background: #161b22; border-color: #2d3748; color: #c9d1d9; }
[data-bs-theme="dark"] .file-item:hover { background: #21262d; }
[data-bs-theme="dark"] .stat-card-h { background: #1c2128; border-color: #2d3748 !important; }
[data-bs-theme="dark"] .stat-card-h .stat-label { color: #8b949e; }
[data-bs-theme="dark"] .list-group-item { background: #1c2128; border-color: #2d3748; color: #c9d1d9; }
[data-bs-theme="dark"] .dropdown-menu { background: #1c2128; border-color: #2d3748; }
[data-bs-theme="dark"] .dropdown-item { color: #c9d1d9; }
[data-bs-theme="dark"] .dropdown-item:hover { background: #21262d; color: white; }
[data-bs-theme="dark"] .dropdown-item-text { color: #8b949e; }
[data-bs-theme="dark"] .text-primary { color: #d2691e !important; }
[data-bs-theme="dark"] .bg-light { background: #21262d !important; }
[data-bs-theme="dark"] .table-light { --bs-table-bg: #21262d; color: #c9d1d9; }
[data-bs-theme="dark"] .sidebar-overlay { background: rgba(0,0,0,0.7); }
[data-bs-theme="dark"] .alert { border-color: #2d3748; }
[data-bs-theme="dark"] .border { border-color: #2d3748 !important; }
[data-bs-theme="dark"] .page-title { color: #d2691e; }

/* =============================================
   صفحة تسجيل الدخول
   ============================================= */
.marble-bg-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 18vw;
    font-weight: 900;
    color: rgba(255,255,255,0.03);
    white-space: nowrap;
    pointer-events: none;
    user-select: none;
    letter-spacing: 0.1em;
}

.landing-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #1a0800 0%, #3d1800 50%, #1a0800 100%);
    position: relative;
    overflow: hidden;
}
.landing-page::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.login-card {
    background: rgba(255,255,255,0.06);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 44px 40px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.55);
}
.login-card .form-control {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
    color: white;
    padding: 12px 16px;
}
.login-card .form-control::placeholder { color: rgba(255,255,255,0.4); }
.login-card .form-control:focus {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.5);
    color: white;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.08);
}
.login-card .form-label { color: rgba(255,255,255,0.72); font-size: 0.88rem; }
.login-card .btn-login {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border: none;
    padding: 12px;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 10px;
    transition: all 0.28s;
    color: white;
}
.login-card .btn-login:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(139,69,19,0.45); }

/* =============================================
   هيدر وفوتر الطباعة (مخفي في الشاشة)
   ============================================= */
.print-only { display: none !important; }

/* هيدر الطباعة */
#printCompanyHeader {
    width: 100%;
    margin-bottom: 18px;
}
.print-header-inner {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    padding: 16px 0 12px;
}
.print-header-logo img { max-height: 70px; max-width: 160px; object-fit: contain; }
.print-header-info { flex: 1; }
.print-company-name { font-size: 1.4rem; font-weight: 800; color: #1a1a1a; margin: 0 0 4px; }
.print-company-meta { font-size: 0.8rem; color: #555; margin: 2px 0; }
.print-company-contacts { display: flex; gap: 20px; font-size: 0.8rem; color: #444; margin-top: 4px; }
.print-header-date { text-align: left; font-size: 0.8rem; color: #555; white-space: nowrap; }
.print-date-label { font-size: 0.7rem; color: #888; }
.print-date-value { font-size: 1.1rem; font-weight: 700; color: #222; }
.print-page-title { font-size: 0.78rem; color: #666; margin-top: 4px; }
.print-header-divider { border-bottom: 2.5px solid #333; margin-top: 8px; }

/* فوتر الطباعة */
.print-footer-section { width: 100%; margin-top: 20px; }
.print-footer-divider { border-top: 1px solid #aaa; margin-bottom: 8px; }
.print-footer-inner {
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 0.78rem;
    color: #555;
    flex-wrap: wrap;
}

/* =============================================
   الطباعة - أبيض وأسود وملون
   ============================================= */
@media print {
    /* ====== إخفاء عناصر الشاشة ====== */
    .sidebar, .navbar-main, .no-print, .modal, .modal-backdrop,
    .sidebar-overlay, .btn:not(.btn-print), .alert,
    .page-header .btn, .page-header .d-flex,
    [data-bs-toggle="modal"], [data-confirm],
    .pagination, nav[aria-label],
    form.d-flex, .card.mb-3:has(form) { display: none !important; }

    /* ====== إظهار هيدر وفوتر الطباعة ====== */
    .print-only { display: block !important; }

    /* الهيدر يظهر في كل صفحة */
    #printCompanyHeader {
        display: block !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        background: #fff !important;
        z-index: 999 !important;
    }

    /* المحتوى يعوض مكان الهيدر/الfooter الثابتين */
    .print-section-content {
        padding-top: 110px !important;
        padding-bottom: 55px !important;
    }

    .print-footer-section { display: block !important; }
    .print-header-inner { display: flex !important; }
    .print-footer-inner { display: flex !important; }
    .print-company-contacts { display: flex !important; }

    /* رقم الصفحة تلقائيًا */
    #printCompanyFooter .print-page-num::before {
        content: counter(page);
    }

    /* لوجو أبيض/أسود واضح */
    #printCompanyHeader img {
        filter: grayscale(1) contrast(1.2) brightness(1.1);
    }

    /* ====== إعدادات الصفحة ====== */
    @page {
        margin: 18mm 14mm 20mm;
        size: A4 portrait;
    }
    @page :first { margin-top: 10mm; }

    /* ====== إعادة ضبط الألوان للأبيض والأسود ====== */
    html, body {
        background: #fff !important;
        color: #000 !important;
        font-size: 11pt !important;
        font-family: 'Cairo', Arial, sans-serif !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* ====== المحتوى الرئيسي ====== */
    .main-content { margin: 0 !important; padding: 0 !important; }
    .wrapper { padding-top: 0 !important; display: block !important; }
    .container-fluid { padding: 0 !important; max-width: 100% !important; }

    /* ====== البطاقات ====== */
    .card {
        box-shadow: none !important;
        border: 1.5px solid #000 !important;
        break-inside: avoid;
        margin-bottom: 10pt !important;
        page-break-inside: avoid;
    }
    .card-header {
        background: #000 !important;
        color: #fff !important;
        border-bottom: 1.5px solid #000 !important;
        padding: 7pt 10pt !important;
        font-weight: 700 !important;
        font-size: 10pt !important;
    }
    .card-body { padding: 8pt !important; }
    .card-footer {
        background: #f0f0f0 !important;
        border-top: 1px solid #999 !important;
        padding: 5pt 8pt !important;
    }

    /* ====== الجداول ====== */
    .table { border-collapse: collapse !important; width: 100% !important; }
    .table th, .table td {
        padding: 5pt 7pt !important;
        font-size: 9.5pt !important;
        border: 1px solid #555 !important;
        vertical-align: middle !important;
    }
    .table thead th, .table-dark th {
        background: #222 !important;
        color: #fff !important;
        font-weight: 700 !important;
        font-size: 9pt !important;
        border-color: #000 !important;
    }
    .table-striped > tbody > tr:nth-of-type(odd) > * {
        background: #f5f5f5 !important;
        color: #000 !important;
    }
    .table-hover > tbody > tr:hover > * {
        background: transparent !important;
    }
    .table-responsive { overflow: visible !important; }

    /* ====== الشارات (Badges) - واضحة في الأبيض والأسود ====== */
    .badge {
        border: 1.5px solid #000 !important;
        font-weight: 700 !important;
        padding: 2pt 5pt !important;
        font-size: 8.5pt !important;
        border-radius: 3pt !important;
    }
    /* شارات ملونة تعمل في الأبيض والأسود */
    .badge.bg-success, .badge.bg-success * { background: #fff !important; color: #000 !important; border-color: #000 !important; }
    .badge.bg-success::before { content: '✓ '; }
    .badge.bg-danger, .badge.bg-danger * { background: #f0f0f0 !important; color: #000 !important; border-color: #000 !important; }
    .badge.bg-danger::before { content: '✗ '; }
    .badge.bg-warning, .badge.bg-warning * { background: #e8e8e8 !important; color: #000 !important; border-color: #555 !important; }
    .badge.bg-warning::before { content: '◐ '; }
    .badge.bg-info, .badge.bg-info * { background: #fff !important; color: #000 !important; border-color: #555 !important; }
    .badge.bg-secondary, .badge.bg-secondary * { background: #e0e0e0 !important; color: #000 !important; border-color: #555 !important; }
    .badge.bg-primary, .badge.bg-primary * { background: #fff !important; color: #000 !important; border-color: #000 !important; }

    /* ====== الألوان النصية ====== */
    .text-success { color: #000 !important; font-weight: 700; }
    .text-danger  { color: #000 !important; font-weight: 700; }
    .text-warning { color: #333 !important; }
    .text-primary { color: #000 !important; font-weight: 700; }
    .text-muted   { color: #444 !important; }
    .fw-bold      { font-weight: 900 !important; }

    /* ====== الأرقام والمبالغ - أوضح في الأبيض والأسود ====== */
    .text-success.fw-bold::before { content: '+ '; font-size: 0.85em; }
    .text-danger.fw-bold::before  { content: '- '; font-size: 0.85em; }

    /* ====== stat-card ====== */
    .stat-card-h {
        border: 1.5px solid #000 !important;
        break-inside: avoid;
        background: #fff !important;
        box-shadow: none !important;
    }
    .stat-card-h .stat-value { color: #000 !important; }
    .stat-card-h .stat-label { color: #444 !important; }
    .stat-card-h .stat-icon-box { border: 1px solid #ccc !important; background: #f5f5f5 !important; }
    .stat-card {
        break-inside: avoid;
        background: #fff !important;
        border: 1.5px solid #000 !important;
        box-shadow: none !important;
    }
    .stat-card * { color: #000 !important; }

    /* ====== عنوان الصفحة ====== */
    .page-header {
        border-bottom: 2px solid #000 !important;
        padding-bottom: 8pt !important;
        margin-bottom: 12pt !important;
    }
    .page-title {
        color: #000 !important;
        font-size: 14pt !important;
        font-weight: 900 !important;
    }
    .page-subtitle { color: #444 !important; font-size: 9pt !important; }

    /* ====== القوائم ====== */
    .list-group-item {
        border: 1px solid #aaa !important;
        background: #fff !important;
        color: #000 !important;
        padding: 5pt 8pt !important;
    }

    /* ====== روابط ====== */
    a { color: #000 !important; text-decoration: none !important; }

    /* ====== إخفاء العناصر الزخرفية ====== */
    .stat-icon { display: none !important; }
    .hide-mobile { display: table-cell !important; }
    .d-none-print { display: none !important; }

    /* ====== صفحات جديدة ====== */
    .page-break-before { page-break-before: always; }
    .page-break-after  { page-break-after: always; }
    .no-break { page-break-inside: avoid; break-inside: avoid; }

    /* ====== فوتر الطباعة ====== */
    #printCompanyFooter {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #fff;
        border-top: 1px solid #000;
    }
    .print-footer-inner { font-size: 8pt !important; color: #000 !important; }

    /* ====== شبكة Bootstrap في الطباعة ====== */
    .row { display: flex !important; flex-wrap: wrap !important; }
    [class*="col-"] { box-sizing: border-box !important; padding-left: 6pt !important; padding-right: 6pt !important; }
    .col-3,  .col-md-3,  .col-lg-3  { width: 25% !important;     flex: 0 0 25% !important; }
    .col-4,  .col-md-4,  .col-lg-4  { width: 33.333% !important; flex: 0 0 33.333% !important; }
    .col-6,  .col-md-6,  .col-lg-6  { width: 50% !important;     flex: 0 0 50% !important; }
    .col-8,  .col-md-8,  .col-lg-8  { width: 66.667% !important; flex: 0 0 66.667% !important; }
    .col-9,  .col-md-9,  .col-lg-9  { width: 75% !important;     flex: 0 0 75% !important; }
    .col-12, .col-md-12, .col-lg-12 { width: 100% !important;    flex: 0 0 100% !important; }
    .col-5 { width: 41.667% !important; flex: 0 0 41.667% !important; }
    .col-7 { width: 58.333% !important; flex: 0 0 58.333% !important; }
    .g-3 > *, .g-4 > * { padding: 4pt 6pt !important; }
    .gap-2, .gap-3 { gap: 6pt !important; }
}

/* =============================================
   z-index — ترتيب الطبقات
   ============================================= */
/* الأنيميشن على .main-content يُنشئ stacking context يُخفي البوب أب — محذوف نهائياً */
/* البوب أب تُنقل إلى body عبر app.js للأمان الإضافي */

/* =============================================
   استجابة للموبايل - شاملة
   ============================================= */

/* --- 992px وما دون (Tablet) --- */
@media (max-width: 991px) {

    /* الشريط الجانبي */
    .sidebar {
        transform: translateX(110%);
        height: 100vh;
        top: 0;
        z-index: 1025;
        padding-top: var(--navbar-height);
    }
    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: -6px 0 28px rgba(0,0,0,0.35);
    }
    .main-content { margin-right: 0 !important; }

    /* المحتوى */
    .container-fluid { padding: 12px !important; }
    .page-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
        margin-bottom: 14px;
        padding-bottom: 12px;
    }
    .page-header > div:last-child { width: 100%; }
    .page-header .d-flex { flex-wrap: wrap; width: 100%; }
    .page-title { font-size: 1.1rem; }

    /* البطاقات */
    .card { border-radius: 8px; }
    .card-header { padding: 10px 14px; font-size: 0.85rem; }
    .card-body { padding: 14px; }

    /* الجداول */
    .table-responsive { -webkit-overflow-scrolling: touch; overflow-x: auto; }
    .table th { font-size: 0.73rem; padding: 8px 9px; white-space: nowrap; }
    .table td { font-size: 0.82rem; padding: 7px 9px; }

    /* بطاقات الإحصاء */
    .stat-card { padding: 15px 16px; }
    .stat-card .stat-value { font-size: 1.3rem; }
    .stat-card-h { padding: 12px 14px; gap: 12px; }
    .stat-card-h .stat-icon-box { width: 42px; height: 42px; font-size: 1.15rem; }
    .stat-card-h .stat-value { font-size: 1.15rem; }

    /* الـ Modals */
    .modal-dialog { margin: 6px; max-width: calc(100vw - 12px); }
    .modal-body { padding: 14px; }
    .modal-header, .modal-footer { padding: 11px 14px; }
    .modal-xl { max-width: calc(100vw - 12px); }

    /* الأزرار */
    .btn-sm { padding: 4px 9px; font-size: 0.75rem; }
}

/* --- 767px وما دون (Mobile) --- */
@media (max-width: 767px) {

    /* الهيدر على الموبايل */
    .nav-brand-text { display: none; }
    .nav-brand-short { display: inline; }
    .nav-user-name  { display: none; }
    .nav-chevron    { display: none; }
    .nav-sep        { display: none; }
    .nav-user-btn   { padding: 4px 8px 4px 4px; border-radius: 20px; }
    .nav-user-avatar { width: 26px; height: 26px; }

    /* الـ grid - عمودان */
    .col-md-3, .col-md-4, .col-md-6 { flex: 0 0 50%; max-width: 50%; }
    .row.g-3 .col-md-3 { flex: 0 0 50%; max-width: 50%; }

    /* Container */
    .container-fluid { padding: 10px !important; }

    /* الجداول - إخفاء أعمدة ثانوية */
    .hide-mobile { display: none !important; }
    .table th, .table td { padding: 6px 8px; font-size: 0.8rem; }

    /* أزرار الجداول - أيقونة فقط */
    .table .btn-sm .btn-text { display: none; }
    .table .btn-sm { padding: 4px 7px; }

    /* stat-card-h */
    .stat-card-h { padding: 10px 12px; gap: 10px; }
    .stat-card-h .stat-value { font-size: 1.05rem; }
    .stat-card-h .stat-label { font-size: 0.72rem; }
    .stat-card .stat-value { font-size: 1.15rem; }

    /* page-header أزرار في صف */
    .page-header .btn, .page-header .d-flex .btn {
        font-size: 0.78rem;
        padding: 5px 10px;
    }

    /* النماذج */
    .form-label { font-size: 0.82rem; margin-bottom: 4px; }
    .form-control, .form-select { font-size: 0.88rem; padding: 7px 10px; }
    .input-group-text { font-size: 0.83rem; padding: 6px 10px; }

    /* card-body ضيق */
    .card-body { padding: 10px; }
    .card-header { padding: 9px 12px; }
    .card-footer { padding: 9px 12px; }

    /* pagination */
    .page-link { padding: 5px 10px; font-size: 0.8rem; }

    /* stat-card 2 per row */
    .col-6.col-md-3 { flex: 0 0 50%; max-width: 50%; }
}

/* --- 576px وما دون (Small Mobile) --- */
@media (max-width: 575px) {
    :root { --sidebar-width: 85vw; }

    /* الهيدر - أصغر */
    .nav-icon-btn { width: 34px; height: 34px; font-size: 1.05rem; }
    .nav-logo { height: min(var(--logo-height, 26px), 26px) !important; } /* حد أقصى 26px على الموبايل */
    .nav-user-btn { padding: 4px 7px 4px 4px; }
    .nav-user-avatar { width: 24px; height: 24px; font-size: 0.75rem; }

    /* المحتوى */
    .container-fluid { padding: 8px !important; }

    /* stat-cards - صف واحد */
    .col-6 { flex: 0 0 50% !important; max-width: 50% !important; }

    /* الجداول */
    .table th, .table td { padding: 5px 6px; font-size: 0.75rem; }

    /* أزرار العناوين */
    .page-header .btn { font-size: 0.75rem; padding: 4px 9px; }

    /* modal */
    .modal-dialog { margin: 4px; }
    .modal-body { padding: 10px; }
    .modal-header, .modal-footer { padding: 9px 12px; }

    /* نموذج */
    .form-control, .form-select { font-size: 0.85rem; padding: 6px 9px; }

    /* card */
    .card-body { padding: 8px; }
    .card-header { font-size: 0.82rem; }

    /* stat-card vertical */
    .stat-card-h {
        flex-direction: row;
        align-items: center;
        padding: 9px 10px;
        gap: 9px;
    }
    .stat-card-h .stat-icon-box { width: 36px; height: 36px; font-size: 1rem; }
    .stat-card-h .stat-value { font-size: 1rem; }
    .stat-card-h .stat-label { font-size: 0.68rem; }
    .stat-card .stat-value { font-size: 1.1rem; }
    .stat-card { padding: 12px 14px; }
}

/* --- 400px وما دون (Very Small) --- */
@media (max-width: 400px) {
    .nav-brand-short { font-size: 0.8rem; }
    .nav-user-btn    { padding: 3px 6px 3px 3px; }
    .nav-user-avatar { width: 22px; height: 22px; font-size: 0.7rem; }
    .nav-icon-btn    { width: 32px; height: 32px; }
    .container-fluid { padding: 6px !important; }
    .page-title      { font-size: 0.95rem; }
}

/* =============================================
   التمرير المخصص
   ============================================= */
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.35); border-radius: 4px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.55); }
.sidebar { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.35) transparent; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e0; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a0aec0; }

/* =============================================
   أدوات مساعدة
   ============================================= */
.border-primary { border-color: var(--primary) !important; }
.text-primary    { color: var(--primary) !important; }
.bg-primary      { background-color: var(--primary) !important; }
.cursor-pointer  { cursor: pointer; }
.text-truncate-2 { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* تأثير hover على الصفوف */
tr { transition: background 0.15s ease; }

/* حدود البطاقة الجانبية المميزة */
.card.border-start-primary { border-right: 3px solid var(--primary) !important; }
.card.border-start-success { border-right: 3px solid #10b981 !important; }
.card.border-start-danger  { border-right: 3px solid #ef4444 !important; }
.card.border-start-warning { border-right: 3px solid #f59e0b !important; }

/* =============================================
   الجداول الإلكترونية (Spreadsheet)
   ============================================= */
.sheet-toolbar {
    background: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: 8px 8px 0 0;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
[data-bs-theme="dark"] .sheet-toolbar { background: #1c2128; border-color: #2d3748; }

.sheet-toolbar .toolbar-sep { width: 1px; height: 22px; background: var(--border-color); margin: 0 4px; }
.sheet-toolbar .btn-tool { padding: 4px 8px; font-size: 0.8rem; border-radius: 5px; min-width: 30px; }

.sheet-container {
    overflow: auto;
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: calc(100vh - 280px);
    min-height: 400px;
    position: relative;
}
.sheet-table {
    border-collapse: collapse;
    min-width: 800px;
    font-size: 0.85rem;
    table-layout: fixed;
}
.sheet-table th.row-header {
    background: #f0f2f5;
    border: 1px solid #d0d5dd;
    padding: 4px 8px;
    font-weight: 600;
    text-align: center;
    min-width: 44px;
    width: 44px;
    position: sticky;
    right: 0;
    z-index: 3;
    font-size: 0.75rem;
    color: #555;
}
.sheet-table th.col-header {
    background: #f0f2f5;
    border: 1px solid #d0d5dd;
    padding: 4px 8px;
    font-weight: 600;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 2;
    font-size: 0.75rem;
    color: #555;
    min-width: 100px;
    user-select: none;
    cursor: pointer;
}
.sheet-table th.col-header:hover { background: #e0e4eb; }
.sheet-table th.corner-header {
    background: #e8eaf0;
    border: 1px solid #d0d5dd;
    position: sticky;
    top: 0;
    right: 0;
    z-index: 4;
    min-width: 44px;
    width: 44px;
}
.sheet-table td {
    border: 1px solid #ddd;
    padding: 0;
    position: relative;
    min-width: 100px;
    height: 28px;
}
.sheet-table td.selected { outline: 2px solid #0d6efd; outline-offset: -2px; }
.sheet-table td.formula-result { background: rgba(13,110,253,0.04); }

.cell-input {
    width: 100%;
    height: 100%;
    min-height: 28px;
    border: none;
    outline: none;
    padding: 4px 6px;
    background: transparent;
    font-size: 0.85rem;
    font-family: 'Cairo', sans-serif;
    direction: rtl;
    box-sizing: border-box;
}
.cell-input:focus { background: #fff; }
[data-bs-theme="dark"] .cell-input:focus { background: #0f1117; color: #c9d1d9; }
[data-bs-theme="dark"] .sheet-table th.col-header,
[data-bs-theme="dark"] .sheet-table th.row-header,
[data-bs-theme="dark"] .sheet-table th.corner-header { background: #21262d; border-color: #2d3748; color: #8b949e; }
[data-bs-theme="dark"] .sheet-table td { border-color: #2d3748; }
[data-bs-theme="dark"] .cell-input { color: #c9d1d9; }

.formula-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-top: none;
    border-bottom: none;
    font-size: 0.85rem;
}
[data-bs-theme="dark"] .formula-bar { background: #1c2128; border-color: #2d3748; color: #c9d1d9; }
.formula-bar-cell { font-weight: 700; min-width: 50px; color: var(--primary); }
.formula-bar-input { flex: 1; border: none; outline: none; background: transparent; font-family: monospace; font-size: 0.88rem; }
[data-bs-theme="dark"] .formula-bar-input { color: #c9d1d9; }

/* كرت الجدول في القائمة */
.sheet-card { transition: var(--transition); cursor: pointer; }
.sheet-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.1); }
.sheet-card .sheet-icon { font-size: 2.5rem; color: #198754; opacity: 0.7; }

/* =============================================
   رواتب الموظفين الجماعية
   ============================================= */
.bulk-pay-table .emp-row-selected { background: rgba(25,135,84,0.08) !important; }
.bulk-pay-table .salary-input { max-width: 120px; }
.employee-card-print { max-width: 750px; margin: 0 auto; }

/* =============================================
   تحسينات الموبايل الإضافية
   ============================================= */
@media (max-width: 767px) {
    /* إخفاء نص الاسم في الهيدر لتوفير مساحة */
    .navbar-brand-text { display: none !important; }

    /* الجداول - تمرير أفقي سلس */
    .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 0; }

    /* تكديس row */
    .row-mobile-stack > [class*="col-"] { flex: 0 0 100%; max-width: 100%; }

    /* النماذج في الموبايل */
    .form-row-mobile .col-md-6 { flex: 0 0 100%; max-width: 100%; }

    /* الأزرار في page-header */
    .page-header { flex-wrap: wrap; }
    .page-header .btn { font-size: 0.78rem; padding: 5px 10px; }

    /* modal في الموبايل - استغلال كل العرض */
    .modal-dialog { margin: 4px; max-width: calc(100vw - 8px); }
    .modal-content { border-radius: 10px; }

    /* إخفاء أعمدة إضافية في الجداول */
    th.d-none-mobile, td.d-none-mobile { display: none !important; }
}

@media (max-width: 480px) {
    /* الهيدر */
    .navbar-main .btn-outline-light { padding: 4px 8px; font-size: 0.78rem; }

    /* الكاردات */
    .row.g-3 > [class*="col-"] { padding: 6px; }

    /* stat-card-h رأسي في الشاشات الصغيرة جداً */
    .stat-card-h { flex-direction: column; align-items: flex-start; gap: 8px; }
}
