/* =====================================================================
   StatLogic - التنسيق الموحد لكل الصفحات
   ===================================================================== */
:root {
    --brand-900: #0f172a;
    --brand-800: #1e293b;
    --brand-700: #1e3a8a;
    --brand-600: #1d4ed8;
    --brand-500: #2563eb;
    --surface: #ffffff;
    --surface-muted: #f1f5f9;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --topbar-h: 64px;
    --sidebar-w: 250px;
    --radius: 14px;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow: 0 6px 24px rgba(15, 23, 42, .06);
}

html, body { min-height: 100%; }
body.app {
    background: var(--surface-muted);
    color: var(--text);
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    font-size: .95rem;
}
a { text-decoration: none; }
.text-danger-soft { color: #fca5a5 !important; }

/* ---------- الشريط العلوي ---------- */
.topbar {
    position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 1040;
    display: flex; align-items: center; gap: .75rem; padding: 0 1.25rem;
    background: linear-gradient(90deg, var(--brand-900) 0%, var(--brand-700) 60%, var(--brand-600) 100%);
    color: #fff; box-shadow: 0 4px 18px rgba(15, 23, 42, .25);
}
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; min-width: 0; }
.brand:hover { color: #fff; }
.brand-logo {
    width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #fff;
    border: 2px solid rgba(255, 255, 255, .35); flex-shrink: 0;
}
.brand-logo-fallback { display: inline-flex; align-items: center; justify-content: center; color: var(--brand-700); }
.brand-name { font-weight: 700; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: .5rem; }
.topbar-chip {
    align-items: center; gap: .4rem; padding: .3rem .8rem; border-radius: 999px;
    background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .18); font-size: .85rem;
}
.btn-icon {
    width: 40px; height: 40px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center;
    color: #fff; background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .15);
}
.btn-icon:hover, .btn-icon:focus { color: #fff; background: rgba(255, 255, 255, .2); }
.user-chip {
    display: inline-flex; align-items: center; gap: .5rem; color: #fff; border-radius: 999px;
    background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .15); padding: .25rem .75rem .25rem .5rem;
}
.user-chip:hover, .user-chip:focus, .user-chip.show { color: #fff; background: rgba(255, 255, 255, .2); }
.avatar {
    width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .2); font-weight: 700; flex-shrink: 0;
}
.avatar-lg { width: 44px; height: 44px; font-size: 1.1rem; background: rgba(255, 255, 255, .12); }

/* ---------- الإشعارات ---------- */
.notif-badge {
    position: absolute; top: -4px; left: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
    background: #ef4444; color: #fff; font-size: .72rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
    border: 2px solid var(--brand-700);
}
.notif-menu { width: 360px; max-width: calc(100vw - 24px); padding: 0; border-radius: var(--radius); overflow: hidden; }
.notif-menu-head { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; border-bottom: 1px solid var(--border); background: #f8fafc; }
.notif-list { max-height: 380px; overflow-y: auto; }
.notif-item { display: block; padding: .7rem 1rem; border-bottom: 1px solid #f1f5f9; color: var(--text); white-space: normal; }
.notif-item:hover { background: #f8fafc; color: var(--text); }
.notif-item.unread { background: #eff6ff; }
.notif-item .notif-title { font-weight: 700; font-size: .9rem; }
.notif-item .notif-body { font-size: .82rem; color: var(--text-muted); white-space: pre-line; }
.notif-item .notif-time { font-size: .75rem; color: #94a3b8; }
.toast-container { z-index: 1090; margin-top: var(--topbar-h); }
.toast .toast-body { white-space: pre-line; }

/* ---------- القائمة الجانبية ---------- */
.sidebar {
    position: fixed; top: var(--topbar-h); right: 0; bottom: 0; width: var(--sidebar-w); z-index: 1030;
    background: linear-gradient(180deg, var(--brand-800) 0%, #334155 100%); color: #fff;
    padding: 1rem .85rem; overflow-y: auto; transition: transform .25s ease;
}
.sidebar-user { display: flex; align-items: center; gap: .75rem; padding: .5rem .5rem 1rem; border-bottom: 1px solid rgba(255, 255, 255, .1); margin-bottom: .75rem; }
.sidebar .nav-link {
    display: flex; align-items: center; gap: .7rem; color: rgba(255, 255, 255, .78);
    border-radius: 10px; padding: .6rem .8rem; margin: 2px 0; font-weight: 500;
}
.sidebar .nav-link i { width: 20px; text-align: center; }
.sidebar .nav-link:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.sidebar .nav-link.active { color: #fff; background: linear-gradient(90deg, var(--brand-500), var(--brand-600)); box-shadow: 0 4px 14px rgba(37, 99, 235, .35); }
.sidebar hr { border-color: rgba(255, 255, 255, .15); opacity: 1; margin: .75rem 0; }
.sidebar-backdrop { display: none; }

.main { margin-top: var(--topbar-h); margin-right: var(--sidebar-w); padding: 1.5rem 1.75rem 2.5rem; min-height: calc(100vh - var(--topbar-h)); }
.main-guest { margin: 0; padding: 0; }

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(100%); box-shadow: -6px 0 24px rgba(0, 0, 0, .3); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 1025; background: rgba(15, 23, 42, .55); }
    .main { margin-right: 0; padding: 1rem; }
    .topbar { padding: 0 .75rem; }
}

/* ---------- العناوين والبطاقات ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.page-title { font-size: 1.45rem; font-weight: 700; margin: 0; }
.page-title i { color: var(--brand-500); margin-left: .5rem; }
.page-subtitle { color: var(--text-muted); margin: .2rem 0 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.card { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-header { background: #fff; border-bottom: 1px solid #f1f5f9; padding: .9rem 1.1rem; font-weight: 600; border-radius: var(--radius) var(--radius) 0 0 !important; }
.card-header h5, .card-header .card-title { font-size: 1rem; margin: 0; font-weight: 700; }
.card-header i { color: var(--brand-500); margin-left: .4rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card { display: flex; align-items: center; gap: 1rem; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow-sm); }
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.25rem; flex-shrink: 0; }
.stat-value { font-size: 1.35rem; font-weight: 700; line-height: 1.2; direction: ltr; text-align: right; unicode-bidi: plaintext; }
.stat-label { color: var(--text-muted); font-size: .85rem; }
.stat-hint { color: #94a3b8; font-size: .75rem; }
.tone-blue { background: rgba(37, 99, 235, .1); color: #2563eb; }
.tone-green { background: rgba(16, 185, 129, .12); color: #059669; }
.tone-purple { background: rgba(139, 92, 246, .12); color: #7c3aed; }
.tone-amber { background: rgba(245, 158, 11, .14); color: #d97706; }
.tone-red { background: rgba(239, 68, 68, .1); color: #dc2626; }
.tone-cyan { background: rgba(6, 182, 212, .12); color: #0891b2; }

/* ---------- الجداول والنماذج ---------- */
.table { margin-bottom: 0; }
.table > thead th { background: #f8fafc; color: #475569; font-weight: 600; font-size: .85rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { vertical-align: middle; }
.table tfoot td, .table tfoot th { background: #f8fafc; font-weight: 700; }
.num { direction: ltr; unicode-bidi: plaintext; text-align: right; white-space: nowrap; }
.filter-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.25rem; }
.filter-card .form-label { font-size: .8rem; color: var(--text-muted); margin-bottom: .25rem; }
.form-control, .form-select { border-radius: 10px; border-color: #dbe2ea; }
.form-control:focus, .form-select:focus { border-color: var(--brand-500); box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .15); }
.btn { border-radius: 10px; font-weight: 500; }
.btn-primary { background: linear-gradient(135deg, var(--brand-700), var(--brand-500)); border: none; }
.btn-primary:hover, .btn-primary:focus { background: linear-gradient(135deg, #172554, var(--brand-600)); }
.badge-cat { background: #eef2ff; color: #3730a3; font-weight: 600; }
.badge-official { background: #f5f3ff; color: #6d28d9; font-weight: 600; }
.empty-state { text-align: center; color: #94a3b8; padding: 2.5rem 1rem; }
.empty-state i { font-size: 2.4rem; margin-bottom: .75rem; display: block; }
.empty-state p { margin: 0; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .6rem 0; border-bottom: 1px dashed #e5e7eb; }
.list-row:last-child { border-bottom: 0; }
.chart-box { position: relative; height: 280px; }

/* ---------- صفحة الدخول ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: linear-gradient(135deg, var(--brand-900) 0%, var(--brand-700) 55%, var(--brand-600) 100%); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 22px; box-shadow: 0 24px 48px rgba(15, 23, 42, .3); padding: 2.25rem 2rem; }
.auth-logo { width: 76px; height: 76px; border-radius: 50%; object-fit: cover; border: 3px solid #e2e8f0; }

/* ---------- الطباعة ---------- */
.print-only { display: none !important; }
@media print {
    @page { size: A4; margin: 12mm; }
    body.app { background: #fff; font-size: 12px; }
    .no-print, .topbar, .sidebar, .sidebar-backdrop, .btn, .alert, form.filter-card, .toast-container { display: none !important; }
    .print-only { display: flex !important; }
    .print-header { align-items: center; gap: 12px; border-bottom: 2px solid #1e3a8a; padding-bottom: 8px; margin-bottom: 16px; }
    .print-header img { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; }
    .main { margin: 0 !important; padding: 0 !important; }
    .card, .stat-card { box-shadow: none !important; break-inside: avoid; }
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
    .chart-box { height: 220px; }
    a { color: inherit; }
}
