@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css');
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800&display=swap');

:root {
    --primary: #4361ee;
    --dark: #1e293b;
    --bg: #f8fafc;
    --text: #334155;
    --sidebar-w: 260px;
    --header-h: 65px;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body { font-family: 'Cairo', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; overflow-x: hidden; }
a { text-decoration: none; color: inherit; transition: 0.3s; }
ul { list-style: none; }

/* === Layout === */
.wrapper { display: flex; width: 100%; min-height: 100vh; position: relative; }

/* Sidebar (Desktop) */
.sidebar {
    width: var(--sidebar-w);
    background: var(--dark);
    height: 100vh;
    position: fixed;
    top: 0; left: 0;
    z-index: 1050;
    overflow-y: auto;
    transition: transform 0.3s ease;
}
body[dir="rtl"] .sidebar { left: auto; right: 0; }

/* Main Content (Desktop) */
.main-content {
    flex: 1;
    width: 100%;
    padding: 95px 30px 30px;
    margin-left: var(--sidebar-w);
    transition: margin 0.3s ease;
}
body[dir="rtl"] .main-content { margin-left: 0; margin-right: var(--sidebar-w); }

/* Headers */
.desktop-header {
    position: fixed; top: 0; left: var(--sidebar-w); right: 0;
    height: var(--header-h); background: white;
    border-bottom: 1px solid #e2e8f0; z-index: 1000;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 30px; transition: left 0.3s ease, right 0.3s ease;
}
body[dir="rtl"] .desktop-header { left: 0; right: var(--sidebar-w); }

.mobile-top-bar {
    display: none; position: fixed; top: 0; left: 0; right: 0;
    height: var(--header-h); background: white; z-index: 1001;
    padding: 0 15px; align-items: center; justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

/* === Mobile Fixes === */
@media (max-width: 992px) {
    .desktop-header { display: none !important; }
    .mobile-top-bar { display: flex; }

    .sidebar { transform: translateX(-100%); }
    body[dir="rtl"] .sidebar { transform: translateX(100%); }
    .sidebar.active { transform: translateX(0); box-shadow: 0 0 20px rgba(0,0,0,0.5); }

    .main-content {
        margin-left: 0 !important; margin-right: 0 !important;
        width: 100% !important; padding: 85px 15px 30px;
    }

    .dashboard-grid, .grid-2, .ops-grid, .charts-row { grid-template-columns: 1fr !important; }
    .card { overflow-x: auto; }
    table { min-width: 600px; }
}

/* Sidebar Overlay */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1040; backdrop-filter: blur(2px); }
.sidebar-overlay.active { display: block; }

/* === 🔥 MODAL FIX (إصلاح المودال) 🔥 === */
.modal {
    display: none; /* مخفي افتراضياً */
    position: fixed; /* ثابت فوق كل شيء */
    z-index: 9999; /* طبقة عالية جداً */
    left: 0; top: 0;
    width: 100%; height: 100%;
    overflow: auto; /* السماح بالتمرير إذا كان المودال طويلاً */
    background-color: rgba(0,0,0,0.6); /* خلفية معتمة */
    backdrop-filter: blur(4px);
    align-items: center; justify-content: center;
}

/* لإظهار المودال */
.modal[style*="display: block"] {
    display: flex !important; /* استخدام فليكس لسنترة المحتوى */
}

.modal-content {
    background-color: #fff;
    margin: auto;
    padding: 30px;
    border-radius: 16px;
    width: 90%; max-width: 400px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    text-align: center;
    position: relative;
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.close {
    position: absolute; top: 15px; right: 20px;
    color: #aaa; font-size: 28px; font-weight: bold; cursor: pointer;
    line-height: 1;
}
.close:hover { color: #000; }

.modal-btn-group, .modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 25px; }

/* === Header Styles === */
.header-actions { display: flex; align-items: center; gap: 12px; }
.header-lang { display: flex; gap: 5px; background: #f1f5f9; padding: 3px; border-radius: 6px; }
.header-lang a { font-size: 0.7rem; font-weight: 800; padding: 4px 8px; border-radius: 4px; color: #64748b; }
.header-lang a.active { background: white; color: var(--primary); box-shadow: 0 2px 4px rgba(0,0,0,0.05); }

.btn-icon-header { background: white; border: 1px solid #e2e8f0; width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: #64748b; position: relative; }
.notif-badge { position: absolute; top: -5px; right: -5px; background: #ef4444; color: white; border-radius: 50%; width: 18px; height: 18px; font-size: 10px; display: flex; align-items: center; justify-content: center; }
.notif-dropdown { display: none; position: absolute; top: 50px; right: 0; width: 300px; background: white; border: 1px solid #eee; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.15); z-index: 2000; overflow: hidden; }
.notif-dropdown.show { display: block; }

/* === Components === */
.nav-link { display: flex; align-items: center; padding: 12px 15px; margin: 5px 10px; border-radius: 8px; color: #cbd5e1; font-weight: 600; }
.nav-link:hover, .nav-link.active { background: var(--primary); color: white; }
.nav-link i { width: 25px; text-align: center; font-size: 1.1rem; }
.nav-header { padding: 15px 20px 5px; font-size: 0.7rem; text-transform: uppercase; font-weight: 800; color: #64748b; }
.sidebar .logo { padding: 20px; color: white; font-weight: 800; border-bottom: 1px solid rgba(255,255,255,0.1); display: flex; gap:10px; align-items: center; }

.card, .stat-card { background: white; border-radius: 12px; padding: 20px; box-shadow: 0 2px 6px rgba(0,0,0,0.02); border: 1px solid #e2e8f0; margin-bottom: 20px; }
.dashboard-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 30px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.stat-card h3 { margin: 0; font-size: 1.8rem; color: var(--dark); }
.stat-card p { margin: 5px 0 0; color: #64748b; font-weight: bold; }
.stat-icon { position: absolute; top: 20px; right: 20px; font-size: 2.5rem; opacity: 0.1; }
.card-income { border-bottom: 4px solid #10b981; } .card-expense { border-bottom: 4px solid #ef4444; } .card-profit { border-bottom: 4px solid #3b82f6; }

table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 12px 15px; border-bottom: 1px solid #eee; text-align: left; }
body[dir="rtl"] th, body[dir="rtl"] td { text-align: right; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 8px; outline: none; background: #fff; }
input:focus, select:focus { border-color: var(--primary); }
.btn { padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; color: white; display: inline-block; font-weight: bold; }
.btn-primary { background: var(--primary); } .btn-dark { background: var(--dark); } .btn-danger { background: #ef4444; } .btn-success { background: #10b981; }
