/* ============================================================
   الهيكل — قائمة جانبية كحلية داكنة + شريط علوي فاتح
   ============================================================ */
* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font); background: var(--canvas); color: var(--text);
  font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { line-height: 1.25; font-weight: 700; color: var(--heading); }
h1 { font-size: 26px; letter-spacing: -.015em; }
h2 { font-size: 19px; }
h3 { font-size: 15px; font-weight: 600; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-xs); padding: 1px 6px; }
:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: 2px; border-radius: 3px; }
::selection { background: var(--accent-soft); }
.skip-link { position: absolute; inset-inline-start: -999px; top: 8px; z-index: 300;
  background: var(--surface); padding: 10px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow-md); }
.skip-link:focus { inset-inline-start: 8px; }

/* ============================================================
   القائمة الجانبية الداكنة
   ============================================================ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--sidebar-w); z-index: 95;
  background: var(--nav-bg); color: var(--nav-text);
  display: flex; flex-direction: column;
  transform: translateX(calc(var(--dir,-1) * 100%)); transition: transform var(--t);
}
html[dir="rtl"] .sidebar { --dir: 1; }
.sidebar.open { transform: translateX(0); }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(12,22,32,.5); z-index: 94; }

.sidebar-brand {
  display: flex; align-items: center; gap: 10px; height: var(--topbar-h);
  padding: 0 14px; flex-shrink: 0; border-bottom: 1px solid var(--nav-line);
}
.sidebar-brand .brand-mark {
  width: 32px; height: 32px; border-radius: var(--radius-sm); flex-shrink: 0;
  background: var(--brand-accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 16px;
}
.sidebar-brand .brand-name {
  color: #fff; font-weight: 700; font-size: 16px; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-brand a:hover { text-decoration: none; }
.sidebar-collapse {
  margin-inline-start: auto; width: 26px; height: 26px; flex-shrink: 0;
  display: grid; place-items: center; border: 1px solid var(--nav-line); border-radius: var(--radius-xs);
  background: transparent; color: var(--nav-text); cursor: pointer; font-size: 12px;
}
.sidebar-collapse:hover { background: var(--nav-hover); color: #fff; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 8px 16px; }
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 3px; }

.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px; margin-bottom: 2px;
  border-radius: var(--radius-sm); color: var(--nav-text); font-size: 14px; font-weight: 500;
  text-decoration: none; cursor: pointer; transition: background var(--t-fast), color var(--t-fast);
}
.nav-item:hover { background: var(--nav-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--nav-active-bg); color: var(--brand-accent); font-weight: 600; }
.nav-icon { width: 19px; text-align: center; font-size: 15px; flex-shrink: 0; opacity: .92; }
.nav-item .chev { margin-inline-start: auto; font-size: 10px; opacity: .6; transition: transform var(--t-fast); }
.nav-group.open > .nav-item .chev { transform: rotate(90deg); }
html[dir="rtl"] .nav-group.open > .nav-item .chev { transform: rotate(-90deg); }

.nav-group { margin-bottom: 1px; }
.nav-sub { padding-inline-start: 12px; margin-bottom: 4px; }
.nav-sub .nav-item {
  position: relative; padding: 7px 11px 7px 30px; font-size: 13.5px; font-weight: 400; color: var(--nav-text);
}
html[dir="rtl"] .nav-sub .nav-item { padding: 7px 30px 7px 11px; }
.nav-sub .nav-item::before {
  content: ""; position: absolute; inset-inline-start: 13px; top: 50%; transform: translateY(-50%);
  width: 5px; height: 5px; border-radius: 50%; background: transparent;
}
.nav-sub .nav-item.active { background: transparent; color: var(--brand-accent); font-weight: 600; }
.nav-sub .nav-item.active::before { background: var(--brand-accent); }
.nav-sub .nav-item:hover { background: var(--nav-hover); color: #fff; }

.menu-label { display: block; padding: 14px 12px 6px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase; color: rgba(180,196,212,.55); }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--nav-line);
  font-size: 11.5px; color: rgba(180,196,212,.6); flex-shrink: 0; }

/* --- الوضع المطوي (سطح المكتب) --- */
@media (min-width: 1024px) {
  html.nav-collapsed { --sidebar-w: var(--sidebar-w-min); }
  html.nav-collapsed .sidebar-brand .brand-name,
  html.nav-collapsed .nav-item span:not(.nav-icon):not(.chev),
  html.nav-collapsed .nav-item .chev,
  html.nav-collapsed .menu-label,
  html.nav-collapsed .nav-sub,
  html.nav-collapsed .sidebar-footer { display: none; }
  html.nav-collapsed .nav-item { justify-content: center; padding: 10px 0; }
  html.nav-collapsed .sidebar-brand { justify-content: center; padding: 0 8px; }
  html.nav-collapsed .sidebar-collapse { margin: 0; }
}

/* ============================================================
   الشريط العلوي الفاتح
   ============================================================ */
.content-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 80; height: var(--topbar-h); flex-shrink: 0;
  display: flex; align-items: center; gap: 10px; padding: 0 18px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar-search { position: relative; width: min(380px, 42vw); }
.topbar-search input {
  width: 100%; height: 36px; padding: 0 36px 0 14px;
  background: var(--surface-2); border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--text); font-family: inherit; font-size: 13.5px;
  transition: background var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast);
}
html[dir="rtl"] .topbar-search input { padding: 0 14px 0 36px; }
.topbar-search input::placeholder { color: var(--text-3); }
.topbar-search input:focus { outline: none; background: var(--surface); border-color: var(--brand-accent); box-shadow: var(--ring); }
.topbar-search::before {
  content: "⌕"; position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); font-size: 16px; pointer-events: none;
}
html[dir="rtl"] .topbar-search input { padding-inline-start: 34px; padding-inline-end: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 4px; margin-inline-start: auto; }

.icon-btn {
  position: relative; width: 36px; height: 36px; display: grid; place-items: center;
  background: transparent; border: 0; border-radius: var(--radius-sm);
  color: var(--text-2); font-family: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--surface-2); color: var(--heading); }
.badge-dot {
  position: absolute; top: 3px; inset-inline-end: 3px; min-width: 15px; height: 15px; padding: 0 4px;
  background: var(--brand-accent); color: #fff; border: 2px solid var(--surface);
  border-radius: var(--radius-pill); font-size: 9.5px; font-weight: 700;
  display: grid; place-items: center; line-height: 1;
}
.topbar-sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }

.user-chip {
  display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-pill);
  color: var(--text); font-family: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}
html[dir="rtl"] .user-chip { padding: 4px 4px 4px 10px; }
.user-chip:hover { background: var(--surface-2); border-color: var(--line-strong); }
.user-name { display: none; }
@media (min-width: 900px) { .user-name { display: inline; } }

/* --- الصور الرمزية بالأحرف الأولى --- */
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; color: #fff;
  font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: .02em;
  background: var(--av, #516F90);
}
.avatar-lg { width: 46px; height: 46px; font-size: 17px; }
.avatar-sm { width: 22px; height: 22px; font-size: 10px; }

/* ============================================================
   القوائم المنسدلة
   ============================================================ */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 8px); inset-inline-end: 0; min-width: 214px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 120; animation: menuIn .14s ease;
}
@keyframes menuIn { from { opacity: 0; transform: translateY(-5px); } }
.dropdown-menu a { display: block; padding: 8px 12px; border-radius: var(--radius-xs);
  font-size: 13.5px; color: var(--text); }
.dropdown-menu a:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-menu .menu-label { padding: 6px 12px; color: var(--text-3); }
.link-sm { font-size: 12px; color: var(--link); }

.notif-menu { width: min(350px, calc(100vw - 24px)); padding: 0; }
.notif-head { display: flex; align-items: center; justify-content: space-between;
  padding: 13px 15px; border-bottom: 1px solid var(--line); }
.notif-head strong { font-size: 14px; color: var(--heading); }
.notif-list { max-height: 390px; overflow-y: auto; padding: 6px; }
.notif-list:empty::after { content: attr(data-empty); display: block; padding: 28px 14px;
  text-align: center; color: var(--text-3); font-size: 13px; }
.notif-item { display: block; padding: 10px 12px; border-radius: var(--radius-xs); color: var(--text);
  border-inline-start: 2px solid transparent; }
.notif-item:hover { background: var(--surface-2); text-decoration: none; border-inline-start-color: var(--brand-accent); }
.notif-item strong { display: block; font-size: 13.5px; font-weight: 600; color: var(--heading); }
.notif-item span { display: block; font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* ============================================================
   المحتوى
   ============================================================ */
.main { flex: 1; padding: 22px 20px 60px; max-width: 1560px; width: 100%; margin: 0 auto; }
@media (min-width: 1024px) {
  .sidebar { transform: none; }
  .sidebar-backdrop { display: none; }
  .layout { padding-inline-start: var(--sidebar-w); }
  #sidebarToggle { display: none; }
  .main { padding: 26px 30px 70px; }
}

/* --- رأس الصفحة --- */
.page-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 26px; font-weight: 700; }
.page-head .sub { display: block; font-size: 13px; color: var(--text-2); margin-top: 2px; }
.page-head .spacer { flex: 1; }
.page-head .btn { margin-top: 4px; }

.breadcrumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--text-3); margin-bottom: 12px; }
.breadcrumbs a { color: var(--text-2); }
.crumb-sep { opacity: .5; }

/* --- الشبكات --- */
.grid { display: grid; gap: 16px; margin-bottom: 18px; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 720px) { .grid-2 { grid-template-columns: repeat(2,1fr); } .grid-3 { grid-template-columns: repeat(2,1fr); } }
@media (min-width: 1180px) { .grid-3 { grid-template-columns: repeat(3,1fr); } .grid-4 { grid-template-columns: repeat(4,1fr); } }

/* ============================================================
   الدخول والأخطاء
   ============================================================ */
.login-box, .error-box, .box {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 34px 30px; width: 100%; max-width: 428px; margin: 8vh auto;
}
.login-brand { text-align: center; margin-bottom: 26px; }
.login-brand .brand-mark { width: 52px; height: 52px; margin: 0 auto 14px; border-radius: var(--radius);
  background: var(--brand-accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 22px; }
.login-brand h1 { font-size: 21px; }
.login-brand .sub { color: var(--text-2); font-size: 13.5px; margin-top: 5px; }
.error-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.error-code { font-family: var(--font-num); font-size: 76px; font-weight: 700; color: var(--brand-accent); line-height: 1; }

/* ============================================================
   الطباعة
   ============================================================ */
@media print {
  .topbar, .sidebar, .noprint, .filters, .toolbar, .btn, .sidebar-backdrop, .tabs { display: none !important; }
  body { background: #fff; }
  .layout { padding: 0 !important; }
  .main { padding: 0; }
  .card, .kpi { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
}

/* ============================================================
   بحث القائمة + بطاقة المستخدم في التذييل
   ============================================================ */
.sidebar-search { padding: 12px 12px 6px; flex-shrink: 0; }
.sidebar-search input {
  width: 100%; height: 34px; padding: 0 12px;
  background: rgba(255,255,255,.06); border: 1px solid var(--nav-line);
  border-radius: var(--radius-sm); color: #fff; font-family: inherit; font-size: 13px;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.sidebar-search input::placeholder { color: rgba(180,196,212,.6); }
.sidebar-search input:focus { outline: none; background: rgba(255,255,255,.1); border-color: var(--brand-accent); }
html.nav-collapsed .sidebar-search { display: none; }

.sidebar-user {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-top: 1px solid var(--nav-line); flex-shrink: 0; color: var(--nav-text); text-decoration: none;
}
.sidebar-user:hover { background: var(--nav-hover); text-decoration: none; }
.sidebar-user .su-text { min-width: 0; }
.sidebar-user strong { display: block; font-size: 13px; font-weight: 600; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user span { display: block; font-size: 11.5px; color: rgba(180,196,212,.75); }
html.nav-collapsed .sidebar-user .su-text { display: none; }
html.nav-collapsed .sidebar-user { justify-content: center; }

/* اختصار لوحة المفاتيح في البحث العلوي */
.kbd {
  position: absolute; inset-inline-end: 8px; top: 50%; transform: translateY(-50%);
  padding: 2px 7px; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-xs); font-family: var(--font-num); font-size: 10.5px;
  color: var(--text-3); pointer-events: none; letter-spacing: .04em;
}
