@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700;900&display=swap');

:root {
    --primary: #1a3a5c;
    --primary-light: #2d5a8e;
    --primary-dark: #0f2340;
    --accent: #f0a500;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #17a2b8;
    --white: #ffffff;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #adb5bd;
    --gray-600: #6c757d;
    --gray-700: #495057;
    --gray-800: #343a40;
    --sidebar-width: 250px;
    --topbar-height: 56px;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.15);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Cairo', sans-serif; background: #f0f4f8; direction: rtl; color: var(--gray-800); }
::-webkit-scrollbar { width: 5px; } ::-webkit-scrollbar-thumb { background: var(--gray-400); border-radius: 3px; }

/* TOPBAR */
.topbar { position: fixed; top: 0; right: 0; left: 0; height: var(--topbar-height); background: var(--primary); display: flex; align-items: center; justify-content: space-between; padding: 0 12px; z-index: 1000; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.topbar-brand { display: flex; align-items: center; gap: 10px; color: white; font-size: 15px; font-weight: 700; }
.topbar-logo { width: 34px; height: 34px; background: var(--accent); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-user { display: flex; align-items: center; gap: 8px; color: white; font-size: 13px; cursor: pointer; padding: 4px 8px; border-radius: 6px; transition: background 0.2s; }
.topbar-user:hover { background: rgba(255,255,255,0.1); }
.topbar-avatar { width: 32px; height: 32px; background: var(--accent); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.menu-toggle { background: none; border: none; color: white; font-size: 22px; cursor: pointer; padding: 4px 8px; line-height: 1; }

/* SIDEBAR */
.sidebar { position: fixed; top: var(--topbar-height); right: 0; width: var(--sidebar-width); height: calc(100vh - var(--topbar-height)); background: var(--primary-dark); overflow-y: auto; overflow-x: hidden; z-index: 900; transition: transform 0.3s ease; }
.sidebar-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 800; }

.nav-section-title { padding: 12px 16px 4px; font-size: 10px; font-weight: 700; color: rgba(255,255,255,0.35); letter-spacing: 1px; text-transform: uppercase; }
.nav-item { position: relative; }
.nav-link { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; color: rgba(255,255,255,0.72); text-decoration: none; font-size: 13px; cursor: pointer; border: none; background: none; width: 100%; text-align: right; font-family: 'Cairo', sans-serif; transition: all 0.2s; }
.nav-link:hover { background: rgba(255,255,255,0.08); color: white; }
.nav-link.active { background: var(--primary-light); color: white; border-right: 3px solid var(--accent); }
.nav-link-inner { display: flex; align-items: center; gap: 10px; }
.nav-icon { font-size: 15px; width: 20px; text-align: center; }
.nav-arrow { font-size: 11px; transition: transform 0.3s; }
.nav-link.open .nav-arrow { transform: rotate(90deg); }

.nav-submenu { display: none; background: rgba(0,0,0,0.25); }
.nav-submenu.open { display: block; }
.nav-sublink { display: block; padding: 8px 16px 8px 36px; color: rgba(255,255,255,0.58); text-decoration: none; font-size: 12px; transition: all 0.2s; font-family: 'Cairo', sans-serif; }
.nav-sublink:hover { color: white; background: rgba(255,255,255,0.06); padding-right: 20px; }
.nav-sublink.active { color: var(--accent); }
.nav-logout { color: #ff8a80 !important; }

/* MAIN */
.main { margin-right: var(--sidebar-width); margin-top: var(--topbar-height); min-height: calc(100vh - var(--topbar-height)); padding: 20px; transition: margin 0.3s; }

/* CARDS */
.card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.card-title { font-size: 14px; font-weight: 700; color: var(--primary); display: flex; align-items: center; gap: 6px; }
.card-body { padding: 18px; }
.card-footer { padding: 12px 18px; border-top: 1px solid var(--gray-200); background: var(--gray-100); }

/* PAGE HEADER */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.page-title { font-size: 18px; font-weight: 700; color: var(--primary); display: flex; align-items: center; gap: 8px; }
.breadcrumb { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.breadcrumb span { color: var(--gray-400); margin: 0 4px; }

/* STATS */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: white; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px; border-right: 4px solid; transition: transform 0.2s; }
.stat-card:hover { transform: translateY(-2px); }
.stat-card.c1 { border-color: #3b82f6; } .stat-card.c2 { border-color: #10b981; } .stat-card.c3 { border-color: #f59e0b; }
.stat-card.c4 { border-color: #ef4444; } .stat-card.c5 { border-color: #8b5cf6; } .stat-card.c6 { border-color: #14b8a6; }
.stat-icon { width: 46px; height: 46px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; background: var(--gray-100); }
.stat-val { font-size: 22px; font-weight: 900; color: var(--gray-800); line-height: 1; }
.stat-lbl { font-size: 11px; color: var(--gray-500); margin-top: 3px; }

/* BUTTONS */
.btn { display: inline-flex; align-items: center; gap: 5px; padding: 7px 14px; border-radius: var(--radius); border: none; font-size: 13px; font-family: 'Cairo', sans-serif; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; transition: all 0.2s; }
.btn:hover { opacity: 0.88; transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: #333; }
.btn-info { background: var(--info); color: white; }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-outline { background: transparent; border: 1.5px solid var(--primary); color: var(--primary); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 14px; }
.btn-block { width: 100%; justify-content: center; }

/* FORMS */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--gray-600); margin-bottom: 5px; }
.form-label.req::after { content: ' *'; color: var(--danger); }
.form-control { width: 100%; padding: 8px 11px; border: 1.5px solid var(--gray-300); border-radius: var(--radius); font-size: 13px; font-family: 'Cairo', sans-serif; color: var(--gray-800); background: white; transition: border-color 0.2s; direction: rtl; }
.form-control:focus { outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(45,90,142,0.1); }
.form-control:disabled { background: var(--gray-100); }
textarea.form-control { resize: vertical; }
.form-row { display: grid; gap: 14px; }
.col-2 { grid-template-columns: 1fr 1fr; }
.col-3 { grid-template-columns: 1fr 1fr 1fr; }
.col-4 { grid-template-columns: repeat(4, 1fr); }
.form-section { border: 1.5px solid var(--gray-200); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.form-section-title { font-size: 12px; font-weight: 700; color: var(--primary); margin-bottom: 12px; padding-bottom: 6px; border-bottom: 1px solid var(--gray-200); }

/* TABLE */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { background: var(--primary); }
th { padding: 11px 13px; text-align: right; color: white; font-weight: 600; white-space: nowrap; font-size: 12px; }
td { padding: 10px 13px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tbody tr:hover { background: #f0f4ff; }
tbody tr:last-child td { border-bottom: none; }

/* BADGES */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 700; }
.bg-success { background: #dcfce7; color: #166534; } .bg-danger { background: #fee2e2; color: #991b1b; }
.bg-warning { background: #fef3c7; color: #92400e; } .bg-info { background: #cffafe; color: #155e75; }
.bg-primary { background: #e0e7ff; color: #3730a3; } .bg-secondary { background: var(--gray-200); color: var(--gray-700); }

/* MODAL */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 2000; align-items: center; justify-content: center; padding: 12px; }
.modal-overlay.open { display: flex; }
.modal { background: white; border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-height: 92vh; overflow-y: auto; animation: mIn 0.2s ease; }
.modal-sm { max-width: 380px; } .modal-md { max-width: 580px; } .modal-lg { max-width: 780px; } .modal-xl { max-width: 1050px; }
@keyframes mIn { from { opacity:0; transform:scale(0.94); } to { opacity:1; transform:scale(1); } }
.modal-header { padding: 14px 18px; background: var(--primary); color: white; display: flex; align-items: center; justify-content: space-between; border-radius: 12px 12px 0 0; }
.modal-title { font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.modal-close { background: rgba(255,255,255,0.18); border: none; color: white; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; font-size: 15px; display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: rgba(255,255,255,0.3); }
.modal-body { padding: 18px; }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--gray-200); display: flex; gap: 8px; }

/* TOOLBAR */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.search-box { display: flex; align-items: center; gap: 8px; background: white; border: 1.5px solid var(--gray-300); border-radius: var(--radius); padding: 0 11px; flex: 1; min-width: 180px; }
.search-box:focus-within { border-color: var(--primary-light); }
.search-box input { border: none; outline: none; font-family: 'Cairo', sans-serif; font-size: 13px; padding: 8px 0; width: 100%; direction: rtl; }

/* PAGINATION */
.pagination { display: flex; align-items: center; gap: 4px; justify-content: center; padding: 14px; flex-wrap: wrap; }
.pg-btn { min-width: 32px; height: 32px; border: 1.5px solid var(--gray-300); border-radius: 6px; background: white; cursor: pointer; font-family: 'Cairo', sans-serif; font-size: 12px; display: flex; align-items: center; justify-content: center; text-decoration: none; color: var(--gray-700); transition: all 0.2s; }
.pg-btn:hover { border-color: var(--primary); color: var(--primary); }
.pg-btn.active { background: var(--primary); border-color: var(--primary); color: white; }

/* ALERTS */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.alert-success { background: #dcfce7; color: #166534; } .alert-danger { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; } .alert-info { background: #cffafe; color: #155e75; }

/* TABS */
.tabs { display: flex; border-bottom: 2px solid var(--gray-200); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab-btn { padding: 9px 16px; border: none; background: none; font-family: 'Cairo', sans-serif; font-size: 12px; font-weight: 600; color: var(--gray-500); cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.2s; }
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane { display: none; } .tab-pane.active { display: block; }

/* EMPTY */
.empty { text-align: center; padding: 40px 20px; color: var(--gray-400); }
.empty-icon { font-size: 40px; margin-bottom: 10px; }

/* RESPONSIVE */
@media (max-width: 768px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .main { margin-right: 0; padding: 12px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .col-2, .col-3, .col-4 { grid-template-columns: 1fr; }
    .modal-xl, .modal-lg { max-width: 100%; }
    .topbar-brand span { display: none; }
    .hide-mobile { display: none !important; }
}
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}
@media print {
    .topbar, .sidebar, .sidebar-overlay, .no-print { display: none !important; }
    .main { margin: 0 !important; padding: 0 !important; }
}

/* === FIXES === */

/* nav-section wrapper */
.nav-section { padding: 4px 0; }

/* Fix sidebar on mobile - swipe overlay covers everything */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(110%);
        box-shadow: -4px 0 20px rgba(0,0,0,0.3);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 850;
    }
    .sidebar-overlay.open {
        display: block;
    }
    /* topbar menu button visible on mobile */
    .menu-toggle {
        display: flex !important;
    }
}

/* Hide menu toggle on desktop */
@media (min-width: 769px) {
    .menu-toggle { display: flex; }
}
