/* ============================================================
   نظام تصميم المنصة — إعادة بناء شاملة
   نظام تقارير المفهرسين
   ============================================================ */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff6ff;
    --sidebar-bg: #0f172a;
    --sidebar-border: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-text-dim: #64748b;
    --sidebar-active: #2563eb;
    --bg: #f1f5f9;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-dim: #64748b;
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --info: #0891b2;
    --info-bg: #ecfeff;
    --purple: #7c3aed;
    --purple-bg: #f5f3ff;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 4px 6px -1px rgba(15, 23, 42, .08), 0 2px 4px -2px rgba(15, 23, 42, .05);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, .1), 0 4px 6px -4px rgba(15, 23, 42, .05);
    --sidebar-w: 264px;
    --sidebar-w-collapsed: 0px;
    --topbar-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: 'Tajawal', 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

img { max-width: 100%; }

::selection { background: var(--primary); color: #fff; }

/* ==================== Layout ==================== */

.app { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform .25s ease;
    overflow: hidden;
}

.sidebar-brand {
    display: flex; align-items: center; gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--sidebar-border);
    color: #fff;
    flex-shrink: 0;
}

.sidebar-brand .logo {
    width: 38px; height: 38px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 19px; color: #fff;
    flex-shrink: 0;
}

.sidebar-brand .brand-text { min-width: 0; }
.sidebar-brand .brand-text strong { display: block; font-size: 14.5px; line-height: 1.3; }
.sidebar-brand .brand-text small { font-size: 11px; color: var(--sidebar-text-dim); }

.sidebar-brand .brand-user { display: flex; align-items: center; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--sidebar-border); min-width: 0; }
.sidebar-brand .bu-avatar { width: 22px; height: 22px; border-radius: 50%; background: rgba(255,255,255,.15); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.sidebar-brand .bu-name { font-size: 12px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-brand .bu-role { flex-shrink: 0; font-size: 10px; color: #e0e7ff; background: rgba(255,255,255,.12); padding: 1px 8px; border-radius: 20px; white-space: nowrap; }
.sidebar-brand .collapse-btn { margin-right: auto; background: none; border: 1px solid var(--sidebar-border); color: var(--sidebar-text); border-radius: 8px; width: 26px; height: 26px; font-size: 12px; line-height: 1; cursor: pointer; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.sidebar-brand .collapse-btn:hover { color: #fff; border-color: var(--sidebar-text-dim); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px 24px; }

.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 4px; }

.nav-section-title {
    font-size: 11px; font-weight: 700; color: var(--sidebar-text-dim);
    padding: 14px 12px 6px; letter-spacing: .3px;
}

.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--sidebar-text); font-size: 13.5px; margin-bottom: 2px; transition: background .15s, color .15s; cursor: pointer; border: none; background: none; width: 100%; text-align: right; font-family: inherit; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: var(--shadow-sm); }
.nav-item .icon { width: 20px; text-align: center; font-size: 16px; flex-shrink: 0; }
.nav-item .label { flex: 1; }
.nav-item .badge { background: var(--danger); color: #fff; font-size: 10.5px; padding: 1px 7px; border-radius: 10px; }

.nav-sub { display: none; }
.nav-section.open .nav-sub { display: block; padding-right: 18px; }
.nav-section.open .nav-arrow { transform: rotate(180deg); }
.nav-arrow { font-size: 10px; transition: transform .2s; color: var(--sidebar-text-dim); }
.nav-item.nav-toggle .arrow { margin-right: auto; }

.sidebar-footer { border-top: 1px solid var(--sidebar-border); padding: 14px 16px; display: flex; align-items: center; justify-content: center; gap: 10px; flex-shrink: 0; }

/* Main */
.main { flex: 1; margin-right: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; transition: margin .25s ease; }

.topbar {
    position: sticky; top: 0; z-index: 90;
    height: var(--topbar-h);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 14px;
    padding: 0 20px;
}

.topbar .menu-btn { display: inline-flex; background: none; border: 1px solid var(--border); border-radius: 8px; width: 38px; height: 38px; font-size: 17px; cursor: pointer; color: var(--text); }

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); flex: 1; min-width: 0; }
.breadcrumb a { color: var(--text-dim); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { color: #cbd5e1; }
.breadcrumb strong { color: var(--text); font-weight: 600; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
    position: relative; width: 38px; height: 38px;
    border: 1px solid var(--border); background: var(--card);
    border-radius: 10px; cursor: pointer; font-size: 16px;
    display: flex; align-items: center; justify-content: center; color: var(--text-dim);
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--primary-soft); color: var(--primary); }
.icon-btn .dot { position: absolute; top: -4px; left: -4px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; border-radius: 20px; padding: 1px 6px; border: 2px solid var(--card); }

/* Page content */
.content { flex: 1; padding: 22px; max-width: 1400px; width: 100%; }

.page-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title h1 { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.page-title h1 .ico { font-size: 22px; }
.page-title p { color: var(--text-dim); font-size: 13px; margin-top: 3px; }
.page-title .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ==================== Cards ==================== */

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 18px;
}
.card .card-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card .card-header h3 { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card .card-body { padding: 18px; }
.card .card-body:empty, .card-body.flush { padding: 0; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; box-shadow: var(--shadow-sm); display: flex; align-items: center; gap: 14px;
    transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
a.stat-card { text-decoration: none; color: inherit; cursor: pointer; display: flex; }
.stat-card .sc-icon { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 21px; flex-shrink: 0; }
.stat-card .sc-icon.blue { background: var(--primary-soft); }
.stat-card .sc-icon.green { background: var(--success-bg); }
.stat-card .sc-icon.amber { background: var(--warning-bg); }
.stat-card .sc-icon.red { background: var(--danger-bg); }
.stat-card .sc-icon.purple { background: var(--purple-bg); }
.stat-card .sc-icon.cyan { background: var(--info-bg); }
.stat-card .sc-num { font-size: 22px; font-weight: 800; line-height: 1.2; color: var(--primary) !important; }
.stat-card .sc-label { color: var(--text-dim); font-size: 12px; }

/* Quick links */
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.quick-card {
    display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; box-shadow: var(--shadow-sm); color: var(--text);
    transition: transform .15s, box-shadow .15s, border-color .15s;
    position: relative; overflow: hidden;
}
.quick-card::before { content: ''; position: absolute; top: 0; right: 0; left: 0; height: 3px; background: var(--primary); }
.quick-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--primary); color: var(--text); }
.quick-card .qc-icon { font-size: 24px; }
.quick-card strong { font-size: 14px; }
.quick-card small { color: var(--text-dim); font-size: 12px; line-height: 1.5; }

/* ==================== Tables ==================== */

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.table th {
    background: #f8fafc; color: var(--text-dim); font-weight: 700; font-size: 12px;
    padding: 11px 14px; text-align: right; border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.table th[data-sort] { user-select: none; }
table.table th.sort-asc::after { content: " ↑"; color: var(--primary); }
table.table th.sort-desc::after { content: " ↓"; color: var(--primary); }
table.table td { padding: 10px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
table.table tbody tr:hover { background: #f8fafc; }
table.table tbody tr:last-child td { border-bottom: none; }
table.table .num { text-align: left; font-variant-numeric: tabular-nums; }

.table-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.table-tools .grow { flex: 1; }
.table-tools input[type=search], .table-tools input[type=text] { min-width: 200px; }

/* ==================== Forms ==================== */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #334155; }
.form-group label .req { color: var(--danger); }
.form-group .hint { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; }

input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=time], input[type=search], input[type=file],
select, textarea {
    width: 100%; padding: 9px 12px;
    border: 1px solid #cbd5e1; border-radius: var(--radius-sm);
    font-size: 13.5px; font-family: inherit; background: #fff; color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
input:disabled, select:disabled, textarea:disabled { background: #f1f5f9; color: var(--text-dim); cursor: not-allowed; }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); width: 16px; height: 16px; cursor: pointer; }

.inline-field { display: inline-flex; align-items: center; gap: 8px; }
.inline-field input[type=text], .inline-field select { width: auto; }

/* Switch */
.switch { position: relative; display: inline-block; width: 42px; height: 23px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 20px; transition: .2s; cursor: pointer; }
.switch .slider::before { content: ''; position: absolute; width: 17px; height: 17px; border-radius: 50%; background: #fff; top: 3px; right: 3px; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(-19px); }

/* ==================== Buttons ==================== */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 16px; border-radius: var(--radius-sm);
    font-size: 13.5px; font-weight: 600; font-family: inherit;
    border: 1px solid transparent; cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, transform .1s;
    white-space: nowrap; line-height: 1.4;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: #f1f5f9; color: #334155; border-color: #e2e8f0; }
.btn-secondary:hover { background: #e2e8f0; color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #b45309; color: #fff; }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-soft); }
.btn-outline-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger-bg); }
.btn-outline-secondary { background: transparent; color: var(--text-dim); border-color: #cbd5e1; }
.btn-outline-secondary:hover { background: #f1f5f9; color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-block { width: 100%; }

/* ==================== Badges ==================== */

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; line-height: 1.5; white-space: nowrap; }
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-amber { background: var(--warning-bg); color: var(--warning); }
.badge-red { background: var(--danger-bg); color: var(--danger); }
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-cyan { background: var(--info-bg); color: var(--info); }
.badge-gray { background: #f1f5f9; color: var(--text-dim); }

/* ==================== Alerts & Toasts ==================== */

.alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 16px; border: 1px solid transparent; }
.alert-success { background: var(--success-bg); color: #166534; border-color: #bbf7d0; }
.alert-danger { background: var(--danger-bg); color: #991b1b; border-color: #fecaca; }
.alert-warning { background: var(--warning-bg); color: #92400e; border-color: #fde68a; }
.alert-info { background: var(--info-bg); color: #155e75; border-color: #a5f3fc; }

.toast-container { position: fixed; bottom: 20px; left: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--sidebar-bg); color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13.5px; display: flex; align-items: center; gap: 10px; animation: toastIn .25s ease; min-width: 260px; max-width: 380px; }
.toast-success { border-right: 4px solid var(--success); }
.toast-danger { border-right: 4px solid var(--danger); }
.toast-warning { border-right: 4px solid var(--warning); }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ==================== Tabs ==================== */

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 18px; overflow-x: auto; flex-wrap: wrap; }
.tab { padding: 9px 16px; font-size: 13.5px; font-weight: 600; color: var(--text-dim); border-radius: 8px 8px 0 0; border: none; background: none; cursor: pointer; font-family: inherit; white-space: nowrap; }
.tab:hover { color: var(--primary); background: var(--primary-soft); }
.tab.active { color: var(--primary); border-bottom: 2px solid var(--primary); margin-bottom: -2px; }

/* ==================== Modal ==================== */

.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 200; display: none; align-items: center; justify-content: center; padding: 20px; backdrop-filter: blur(2px); }
.modal-backdrop.show { display: flex; }
.modal { background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; animation: toastIn .2s ease; }
.modal-lg { max-width: 860px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 15.5px; font-weight: 700; }
.modal-header .close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-dim); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-start; gap: 8px; }

/* ==================== Dropdown ==================== */

.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; top: calc(100% + 8px); left: 0; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); min-width: 200px; padding: 6px; z-index: 150; display: none; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button { display: flex; align-items: center; gap: 9px; width: 100%; text-align: right; padding: 9px 12px; border: none; background: none; font-size: 13px; color: var(--text); border-radius: 7px; cursor: pointer; font-family: inherit; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--primary-soft); color: var(--primary); }
.dropdown-menu a.danger, .dropdown-menu button.danger { color: var(--danger); }
.dropdown-menu a.danger:hover, .dropdown-menu button.danger:hover { background: var(--danger-bg); }
.dropdown-divider { height: 1px; background: var(--border); margin: 5px 0; }

/* ==================== Misc ==================== */

.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.gap-1 { gap: 6px; } .gap-2 { gap: 10px; } .gap-3 { gap: 16px; }
.justify-between { justify-content: space-between; }
.grow { flex: 1; }
.text-center { text-align: center; }
.text-dim { color: var(--text-dim); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-sm { font-size: 12.5px; }
.text-xs { font-size: 11.5px; }
.font-bold { font-weight: 700; }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 18px; }
.mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 18px; }
.w-100 { width: 100%; }
.nowrap { white-space: nowrap; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-dim); }
.empty-state .es-icon { font-size: 42px; margin-bottom: 10px; opacity: .5; }
.empty-state strong { display: block; font-size: 15px; color: var(--text); margin-bottom: 4px; }

.progress { background: #e2e8f0; border-radius: 20px; height: 8px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); border-radius: 20px; transition: width .3s; }
.progress.green > div { background: var(--success); }
.progress.amber > div { background: var(--warning); }
.progress.red > div { background: var(--danger); }

.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }

.pagination { display: flex; gap: 6px; align-items: center; justify-content: center; padding: 14px; }
.pagination button, .pagination a { min-width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; font-size: 13px; color: var(--text); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }

code, .mono { font-family: Consolas, 'Courier New', monospace; direction: ltr; }

/* ==================== Print ==================== */

@media print {
    .sidebar, .topbar, .no-print, .toast-container, .modal-backdrop { display: none !important; }
    .main { margin: 0 !important; }
    .content { padding: 0; max-width: none; }
    .card { border: none; box-shadow: none; }
    body { background: #fff; }
}

/* ==================== Responsive ==================== */

@media (max-width: 992px) {
    :root { --sidebar-w: 264px; }
    .sidebar { transform: translateX(100%); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .main { margin-right: 0; }
    .topbar .menu-btn { display: inline-flex; }
    body.sidebar-open { overflow: hidden; }
    .sidebar::after { content: ''; position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: -1; }
}

@media (min-width: 993px) {
    body.sidebar-collapsed .sidebar { transform: translateX(100%); }
    body.sidebar-collapsed .main { margin-right: 0; }
}

@media (max-width: 640px) {
    .content { padding: 14px; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
    .quick-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
    .page-title h1 { font-size: 17px; }
    .topbar { padding: 0 12px; }
    .table-tools { flex-direction: column; align-items: stretch; }
}
