/* ==========================================================================
   PUD App Shell — هيكل التطبيق المشترك
   الترويسة، التنقل المجمّع، درج الموبايل، الشريط السفلي، مسار التنقّل،
   ترويسة الصفحة، وحالات الفراغ والتحميل.
   كل القيم من css/tokens.css — لا أرقام سحرية هنا.
   ========================================================================== */

/* ==========================================================================
   1) الشريط المؤسسي العلوي
   ========================================================================== */
.gov-branding-bar {
  background: var(--bg-header-bar);
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.gov-branding-inner {
  max-width: var(--max-width);
  margin-inline: auto;
  padding: var(--space-1) var(--pad-page-x);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
  min-height: var(--topbar-height);
}

.gov-brand-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.gov-brand-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--text-muted);
}

.gov-brand-item strong { color: var(--text-secondary); font-weight: var(--weight-semibold); }
.gov-brand-item :is(i, svg) { width: 14px; height: 14px; }

.gov-brand-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* شريحة حالة الخادم والاتصال البرمجي */
.server-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: var(--weight-medium);
  border: 1px solid var(--border-subtle);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--trans-fast);
  font-family: inherit;
}
.server-status-chip:hover {
  border-color: var(--brand-blue);
  background: var(--surface-2);
  color: var(--text-primary);
}
.server-status-chip .status-indicator-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #eab308;
  flex-shrink: 0;
  transition: background 0.3s ease, box-shadow 0.3s ease;
}
.server-status-chip.online .status-indicator-dot {
  background: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.7);
}
.server-status-chip.offline .status-indicator-dot {
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
}

.status-indicator-dot.large {
  width: 14px;
  height: 14px;
}

/* على الموبايل نُخفي السطر الوزاري ونُبقي الجامعة فقط */
@media (max-width: 768px) {
  .gov-brand-item--ministry { display: none; }
}

/* ==========================================================================
   2) الترويسة الرئيسية
   ========================================================================== */
.main-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: var(--bg-header-blur);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
}

.main-header-inner {
  /* أوسع من عمود المحتوى: الترويسة تحمل هوية + تنقل + أدوات،
     وحصرها في 1360 بكسل كان يجبر القائمة على الطي مبكرًا. */
  max-width: min(1600px, 100%);
  margin-inline: auto;
  padding: var(--space-2) var(--pad-page-x);
  display: flex;
  align-items: center;
  gap: var(--space-5);
  min-height: var(--header-height);
}

/* --- الهوية والشعارات --- */
.department-brand-anchor {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: inherit;
  /* يتقلّص قبل أن يدفع أدوات الترويسة خارج الشاشة (كان flex-shrink: 0) */
  flex: 0 1 auto;
  min-width: 0;
  border-radius: var(--radius-md);
  padding: var(--space-1);
}

.logos-cluster {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.brand-logo-img {
  height: 38px;
  width: auto;
  object-fit: contain;
}

.brand-logo-img.pud-logo { height: 42px; }

.brand-text-block {
  display: flex;
  flex-direction: column;
  line-height: var(--leading-tight);
}

.department-title-ar {
  font-size: var(--text-base);
  font-weight: var(--weight-black);
  color: var(--text-primary);
  line-height: 1.45;
  margin: 0;
}

.department-title-en {
  font-family: var(--font-latin);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  color: var(--on-surface-primary);
  letter-spacing: 0.02em;
}

.department-inst {
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

/* على الشاشات الضيقة نُبقي شعار القسم والاسم المختصر فقط */
@media (max-width: 1200px) {
  .brand-logo-img:not(.pud-logo) { display: none; }
  .department-title-en, .department-inst { display: none; }
}

/* ==========================================================================
   3) التنقل الأساسي المجمّع (Desktop)
   ========================================================================== */
.primary-nav {
  /* لا يتقلّص تحت محتواه: التقلّص مع overflow:visible كان يجعل الروابط
     تُرسم فوق أدوات الترويسة بدل أن تُطوى. */
  flex: 0 0 auto;
  overflow: visible;   /* القوائم المنسدلة تخرج خارج الحدود */
}

.navbar-nav {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-1);
  list-style: none;
  margin: 0;
  padding: 0;
  min-width: 0;
}

/* بين 1281 و 1440 بكسل: نصغّر حشو الروابط بدل أن يتراكب التنقل مع الأدوات */
@media (max-width: 1440px) {
  .main-header-inner { gap: var(--space-3); }
  .nav-link { padding: var(--space-2); font-size: var(--text-sm); gap: var(--space-1); }
  .nav-link :is(i, svg) { width: 16px; height: 16px; }
}

.nav-item { position: relative; }

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-h-sm);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-arabic);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-decoration: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  white-space: nowrap;
  transition: var(--t-colors);
}

.nav-link :is(i, svg) { width: 17px; height: 17px; flex-shrink: 0; }

.nav-link:hover {
  color: var(--on-surface-primary);
  background: var(--bg-hover);
}

/* الحالة النشطة: لون + خلفية + خط سفلي (ليست اللون وحده) */
.nav-link[aria-current="page"],
.nav-link.active {
  color: var(--on-surface-primary);
  background: var(--color-primary-glow);
  border-color: var(--border-accent);
}

.nav-link[aria-current="page"]::after {
  content: "";
  position: absolute;
  inset-inline: var(--space-3);
  bottom: -1px;
  height: 2px;
  border-radius: var(--radius-full);
  background: var(--on-surface-primary);
}

.nav-caret {
  width: 14px;
  height: 14px;
  opacity: 0.7;
  transition: transform var(--dur-fast) var(--ease-out);
}

.nav-item[data-open="true"] .nav-caret { transform: rotate(180deg); }

/* --- قائمة منسدلة للمجموعة --- */
.nav-submenu {
  position: absolute;
  inset-inline-start: 0;
  top: calc(100% + var(--space-2));
  min-width: 268px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-4);
  padding: var(--space-2);
  list-style: none;
  margin: 0;
  display: none;
  z-index: var(--z-header);
}

/* جسر الفجوة (hover bridge)
   القائمة بتبعد 8px عن الزرّ، والفجوة دي منطقة ميتة: أول ما الماوس
   ينزل ناحية القائمة بيخرج من الـ <li> فيتنفّذ mouseleave وتقفل قبل
   ما توصلها. العنصر الشفاف ده بيغطّي الفجوة فيفضل المؤشّر "جوّه"
   القائمة طول الطريق. */
.nav-submenu::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: 100%;
  height: calc(var(--space-2) + 2px);
}

.nav-item[data-open="true"] > .nav-submenu {
  display: block;
  animation: navMenuIn var(--dur-base) var(--ease-out);
}

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

.nav-submenu-link {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-height: var(--tap-min);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-secondary);
  transition: var(--t-colors);
}

.nav-submenu-link:hover { background: var(--bg-hover); color: var(--text-primary); }

.nav-submenu-link[aria-current="page"] {
  background: var(--color-primary-glow);
  color: var(--on-surface-primary);
}

.nav-submenu-link :is(i, svg) {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  color: var(--on-surface-primary);
  flex-shrink: 0;
}

.nav-submenu-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.nav-submenu-text strong { font-size: var(--text-base); font-weight: var(--weight-bold); }
.nav-submenu-text small { font-size: var(--text-xs); color: var(--text-muted); line-height: var(--leading-snug); }

/* وسم صغير بجانب رابط التنقل */
.nav-tag {
  font-family: var(--font-latin);
  font-size: var(--text-2xs);
  font-weight: var(--weight-black);
  letter-spacing: 0.04em;
  padding: 1px var(--space-1);
  border-radius: var(--radius-xs);
  background: var(--color-accent);
  color: var(--text-inverse);
  flex-shrink: 0;
}

/* ==========================================================================
   4) أدوات الترويسة
   ========================================================================== */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-inline-start: auto;
  flex: 0 0 auto;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--icon-btn);
  height: var(--icon-btn);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  transition: var(--t-interactive);
}

.icon-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-accent);
  color: var(--on-surface-primary);
}

.icon-btn:active { transform: scale(0.94); }
.icon-btn :is(i, svg) { width: 19px; height: 19px; }

.theme-toggle-btn { composes: icon-btn; }
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--icon-btn);
  height: var(--icon-btn);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--on-surface-accent);
  transition: var(--t-interactive);
}

.theme-toggle-btn:hover { background: var(--bg-hover); border-color: var(--border-accent); }
.theme-toggle-btn:active { transform: scale(0.94); }
.theme-icon-light { display: none; }
.theme-icon-dark { display: inline-flex; }
[data-theme="light"] .theme-icon-light { display: inline-flex; color: var(--on-surface-primary); }
[data-theme="light"] .theme-icon-dark { display: none; }

.search-trigger-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-h);
  padding: 0 var(--space-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-family: var(--font-arabic);
  font-size: var(--text-sm);
  transition: var(--t-colors);
}

.search-trigger-btn:hover { border-color: var(--border-accent); color: var(--text-secondary); }
.search-trigger-btn :is(i, svg) { width: 17px; height: 17px; }

.search-kbd {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  padding: 1px var(--space-1);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
}

@media (max-width: 1560px) {
  .search-trigger-btn .search-kbd { display: none; }
}

@media (max-width: 1560px) {
  .search-trigger-btn .search-trigger-label { display: none; }
  .search-trigger-btn { width: var(--icon-btn); justify-content: center; padding: 0; }
}

/* نص زر الدخول يختصر على الشاشات الضيقة */
@media (max-width: 1440px) {
  .auth-btn-label { display: none; }
  #openAuthModalBtn { width: var(--icon-btn); padding: 0; }
}

/* شريحة تبديل الصلاحية */
.role-switcher-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 2px var(--space-3);
  min-height: 28px;
}

.role-switcher-chip > .role-switcher-label { font-size: var(--text-2xs); color: var(--text-muted); }
.role-switcher-chip :is(i, svg) { width: 13px; height: 13px; color: var(--text-muted); }

.role-select-native {
  background: transparent;
  border: none;
  color: var(--on-surface-primary);
  font-family: var(--font-arabic);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  padding: var(--space-1) 0;
  cursor: pointer;
}

.role-select-native option { background: var(--bg-surface); color: var(--text-primary); }

.user-role-badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  white-space: nowrap;
}

@media (max-width: 1500px) { .user-role-badge { display: none; } }

/* زر قائمة الموبايل */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--icon-btn);
  height: var(--icon-btn);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  transition: var(--t-colors);
}

/* الطي يقرره القياس الفعلي في js/layout.js (السمة data-nav-collapsed)،
   مع نقطة انكسار احتياطية لو تعطّل الجافاسكربت. */
.main-header-inner[data-nav-collapsed="true"] .primary-nav { display: none; }
.main-header-inner[data-nav-collapsed="true"] .mobile-menu-btn { display: inline-flex; }

@media (max-width: 1024px) {
  .primary-nav { display: none; }
  .mobile-menu-btn { display: inline-flex; }
}

/* ==========================================================================
   5) درج التنقل على الموبايل (Navigation drawer)
   ========================================================================== */
.nav-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  background: rgba(4, 7, 16, 0.6);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-base) var(--ease-out), visibility var(--dur-base);
}

.nav-drawer-backdrop[data-open="true"] { opacity: 1; visibility: visible; }

.nav-drawer {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  z-index: calc(var(--z-drawer) + 1);
  width: min(92vw, 360px);
  background: var(--bg-surface);
  border-inline-start: 1px solid var(--border-strong);
  box-shadow: var(--elev-5);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease-out);
  overscroll-behavior: contain;
}

[dir="rtl"] .nav-drawer { transform: translateX(-100%); }
.nav-drawer[data-open="true"] { transform: translateX(0); }

.nav-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.nav-drawer-title { font-size: var(--text-lg); font-weight: var(--weight-black); color: var(--text-primary); }

.nav-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-4) var(--space-9);
}

.nav-drawer-group + .nav-drawer-group { margin-top: var(--space-6); }

.nav-drawer-group-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-black);
  color: var(--text-muted);
  letter-spacing: 0.06em;
  padding: 0 var(--space-3) var(--space-2);
  text-transform: none;
}

.nav-drawer-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap-min);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  transition: var(--t-colors);
}

.nav-drawer-link + .nav-drawer-link { margin-top: var(--space-1); }
.nav-drawer-link:hover { background: var(--bg-hover); color: var(--text-primary); }

.nav-drawer-link[aria-current="page"] {
  background: var(--color-primary-glow);
  color: var(--on-surface-primary);
  box-shadow: inset 3px 0 0 var(--on-surface-primary);
}

[dir="rtl"] .nav-drawer-link[aria-current="page"] { box-shadow: inset -3px 0 0 var(--on-surface-primary); }
.nav-drawer-link :is(i, svg) { width: 20px; height: 20px; flex-shrink: 0; }
.nav-drawer-link small { display: block; font-size: var(--text-xs); font-weight: var(--weight-regular); color: var(--text-muted); }

.nav-drawer-foot {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* ==========================================================================
   6) الشريط السفلي للموبايل (Bottom navigation) — 5 عناصر كحد أقصى
   ========================================================================== */
.bottom-nav {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: var(--z-bottom-nav);
  display: none;
  background: var(--bg-header-blur);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-inner {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: stretch;
}

.bottom-nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: var(--bottom-nav-height);
  padding: var(--space-2) var(--space-1);
  text-decoration: none;
  color: var(--text-muted);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  transition: var(--t-colors);
  position: relative;
}

.bottom-nav-link :is(i, svg) { width: 21px; height: 21px; }
.bottom-nav-link:active { background: var(--bg-hover); }

.bottom-nav-link[aria-current="page"] { color: var(--on-surface-primary); }

.bottom-nav-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 0;
  inset-inline: 26%;
  height: 3px;
  border-radius: var(--radius-full);
  background: var(--on-surface-primary);
}

@media (max-width: 768px) {
  .bottom-nav { display: block; }
  body { padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px)); }
}

/* ==========================================================================
   7) هيكل الصفحة: مسار التنقّل + ترويسة الصفحة
   ========================================================================== */
.main-wrapper {
  max-width: var(--max-width);
  margin-inline: auto;
  padding: var(--space-5) var(--pad-page-x) var(--space-11);
}

.breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
  list-style: none;
  padding: 0;
}

.breadcrumbs li { display: inline-flex; align-items: center; gap: var(--space-2); }
/* رابط مسار التنقّل كان ارتفاعه 21px — أقل من الحد الأدنى 24×24
   في WCAG 2.2 AA. الحشوة العمودية بترفعه من غير ما تغيّر شكله. */
.breadcrumbs a {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding-block: var(--space-1);
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-xs);
}

.breadcrumbs a:hover { color: var(--on-surface-primary); text-decoration: underline; }
.breadcrumbs [aria-current="page"] { color: var(--text-secondary); font-weight: var(--weight-semibold); }
.breadcrumbs .crumb-sep { color: var(--border-strong); }
.breadcrumbs .crumb-sep :is(i, svg) { width: 14px; height: 14px; }

/* ترويسة الصفحة الموحّدة */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-5);
  padding-bottom: var(--space-5);
  margin-bottom: var(--space-7);
  border-bottom: 1px solid var(--border-subtle);
}

.page-head-text { min-width: 0; max-width: var(--measure); }

.page-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--on-surface-primary);
  background: var(--color-primary-glow);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-3);
  margin-bottom: var(--space-3);
}

.page-eyebrow :is(i, svg) { width: 14px; height: 14px; }

.page-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-black);
  color: var(--text-primary);
  line-height: var(--leading-tight);
  margin: 0 0 var(--space-2);
  text-wrap: balance;
}

.page-lede {
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  color: var(--text-secondary);
  margin: 0;
}

.page-head-actions { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }

/* عنوان قسم داخل الصفحة */
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-7);
  padding-bottom: var(--space-4);
  /* خط شعري تحت عنوان القسم: يفصل العنوان عن محتواه ويدّي الصفحة
     إحساس "صفحة مطبوعة" بدل كتل عايمة */
  border-bottom: 1px solid var(--border-subtle);
}

.section-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-display);
  line-height: var(--leading-display);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0;
}

.section-title :is(i, svg) { width: 22px; height: 22px; color: var(--on-surface-primary); }
.section-sub { font-size: var(--text-base); color: var(--text-muted); margin: var(--space-2) 0 0; max-width: 62ch; }
.page-block + .page-block { margin-top: var(--gap-section); }

/* ==========================================================================
   8) بطاقات الانتقال في الصفحة الرئيسية (Hub cards)
   ========================================================================== */
/* شبكة بينتو غير متماثلة.
   الشبكة القديمة (auto-fill minmax 300px) كانت بتطلع صفًّا من كروت
   متطابقة الحجم — وده أشهر تخطيط في الصفحات المولّدة آليًا، وبيخلّي
   كل قسم يبان بنفس الأهمية فالعين ما تعرفش تبدأ منين.
   هنا خريطة المناهج والدليل بياخدوا عمودين، والباقي عمود — فالتسلسل
   بيتقري من الحجم قبل ما تقرا كلمة. */
.hub-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap-card);
}

.hub-card--wide { grid-column: span 2; }

/* لوحة التحكم (لما تظهر لصاحب الصلاحية) تاخد الصف كامل بدل ما تسيب
   فراغ محرج في آخر الشبكة */
#hubAdminCard:not([hidden]) { grid-column: 1 / -1; }

@media (max-width: 1000px) and (min-width: 769px) {
  .hub-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .hub-grid {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    gap: var(--space-4);
    padding-bottom: var(--space-3);
    padding-top: var(--space-1);
    margin-inline: -16px;
    padding-inline: 16px;
    scrollbar-width: thin;
  }
  .hub-grid::-webkit-scrollbar {
    height: 4px;
  }
  .hub-grid::-webkit-scrollbar-track {
    background: transparent;
  }
  .hub-grid::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: var(--radius-full);
  }
  .hub-grid > .hub-card {
    flex: 0 0 84%;
    min-width: 270px;
    max-width: 320px;
    scroll-snap-align: start;
    scroll-snap-stop: normal;
  }
  .hub-card--wide {
    grid-column: auto;
  }
  #hubAdminCard:not([hidden]) {
    grid-column: auto;
    flex: 0 0 84%;
    min-width: 270px;
    max-width: 320px;
    scroll-snap-align: start;
  }
}

/* أزرار التوجيه الجانبية للسلايدر على الموبايل في كل المنصة */
.carousel-mobile-controls {
  display: none;
}

@media (max-width: 768px) {
  .carousel-mobile-controls {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  .carousel-nav-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--t-interactive);
    padding: 0;
  }

  .carousel-nav-btn:hover,
  .carousel-nav-btn:active {
    background: var(--color-primary);
    color: #ffffff;
    border-color: var(--color-primary);
  }

  .carousel-nav-btn i,
  .carousel-nav-btn svg {
    width: 16px;
    height: 16px;
  }
}

.hub-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: clamp(var(--space-5), 2.2vw, var(--space-7));
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--elev-1), var(--edge-light);
  text-decoration: none;
  color: inherit;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  transition: var(--t-interactive);
}

/* ضوء كاشف خفيف من ناحية الأيقونة — بيدّي الكارت اتجاه إضاءة واحد
   بدل ما يبقى مستطيل مسطّح */
.hub-card::before {
  content: "";
  position: absolute;
  inset-block-start: -40%;
  inset-inline-start: -20%;
  width: 70%;
  aspect-ratio: 1;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle, var(--color-primary-glow) 0%, transparent 70%);
  transition: opacity var(--dur-base) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .hub-card:hover {
    border-color: var(--border-accent);
    box-shadow: var(--elev-3), var(--edge-light);
    transform: translateY(var(--lift));
  }
  .hub-card:hover::before { opacity: 1; }
}

/* الضغط لازم يبان فورًا وباللمس كمان — 0.995 القديمة كانت غير محسوسة */
.hub-card:active { transform: scale(0.985); transition-duration: var(--dur-instant); }

.hub-card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius-md);
  background: var(--color-primary-glow);
  color: var(--on-surface-primary);
  border: 1px solid var(--border-accent);
}

.hub-card-icon :is(i, svg) { width: 23px; height: 23px; }
.hub-card h3 { font-size: var(--text-lg); font-weight: var(--weight-black); color: var(--text-primary); margin: 0; }
.hub-card p { font-size: var(--text-sm); line-height: var(--leading-normal); color: var(--text-secondary); margin: 0; max-width: 54ch; }

/* الكارت العريض بيستاهل تايبوغرافي أكبر — وإلا العرض الزيادة بيبان
   مساحة فاضية مش أهمية أعلى */
@media (min-width: 681px) {
  .hub-card--wide { gap: var(--space-4); }
  .hub-card--wide .hub-card-icon { width: 56px; height: 56px; border-radius: var(--radius-lg); }
  .hub-card--wide .hub-card-icon :is(i, svg) { width: 28px; height: 28px; }
  .hub-card--wide h3 { font-size: var(--text-xl); font-weight: var(--weight-display); }
  .hub-card--wide p { font-size: var(--text-base); }
}

.hub-card-meta {
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px dashed var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* الزرّ داخل الزرّ: السهم بيقعد في دايرته الخاصة ملزوق بحافة الحشوة،
   مش عريان جنب النص — تفصيلة صغيرة بس هي اللي بتفرّق */
.hub-card-go {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--on-surface-primary);
  font-weight: var(--weight-bold);
}

.hub-card-go :is(i, svg) {
  width: 15px;
  height: 15px;
  box-sizing: content-box;
  padding: 6px;
  border-radius: var(--radius-full);
  background: var(--overlay-2);
  transition: transform var(--dur-base) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .hub-card:hover .hub-card-go :is(i, svg) {
    transform: translateX(4px);
    background: var(--color-primary-glow);
  }
  [dir="rtl"] .hub-card:hover .hub-card-go :is(i, svg) { transform: translateX(-4px); }
}

/* تنويعات لونية حسب المجال (اللون ليس الدلالة الوحيدة — الأيقونة والنص يحملانها) */
.hub-card--study .hub-card-icon { background: var(--color-primary-glow); color: var(--on-surface-primary); }
.hub-card--create .hub-card-icon { background: rgba(245, 158, 11, 0.14); color: var(--on-surface-accent); border-color: rgba(245, 158, 11, 0.32); }
.hub-card--place .hub-card-icon { background: var(--color-emerald-glow); color: var(--on-surface-success); border-color: rgba(16, 185, 129, 0.32); }
.hub-card--people .hub-card-icon { background: rgba(139, 92, 246, 0.14); color: var(--on-surface-info); border-color: rgba(139, 92, 246, 0.32); }

/* ==========================================================================
   9) حالات الفراغ والتحميل والخطأ (Empty / Loading / Error states)
   ========================================================================== */
.state-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-5);
  background: var(--bg-card);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-secondary);
}

.state-block :is(i, svg) { width: 34px; height: 34px; color: var(--text-muted); }
.state-block h3 { font-size: var(--text-lg); font-weight: var(--weight-bold); color: var(--text-primary); margin: 0; }
.state-block p { font-size: var(--text-sm); color: var(--text-muted); margin: 0; max-width: var(--measure-narrow); }

/* هيكل عظمي (Skeleton) — يحجز المساحة فيمنع قفز التخطيط */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: skeletonSweep 1.4s linear infinite;
  border-radius: var(--radius-md);
}

.skeleton-card { height: 168px; }
.skeleton-line { height: 12px; margin-bottom: var(--space-2); }
.skeleton-line.w-60 { width: 60%; }
.skeleton-line.w-40 { width: 40%; }

@keyframes skeletonSweep {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; background: var(--bg-card); }
}

/* ==========================================================================
   10) التذييل
   ========================================================================== */
.main-footer {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  padding: var(--space-9) var(--pad-page-x) var(--space-6);
  margin-top: var(--space-10);
}

.footer-inner {
  max-width: var(--max-width);
  margin-inline: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: var(--space-8);
  margin-bottom: var(--space-8);
}

.footer-col h4 {
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  margin: 0 0 var(--space-4);
  padding-bottom: var(--space-2);
  position: relative;
}

.footer-col h4::after {
  content: "";
  position: absolute;
  bottom: 0;
  inset-inline-start: 0;
  width: 32px;
  height: 2px;
  background: var(--on-surface-primary);
  border-radius: var(--radius-full);
}

.footer-col p { color: var(--text-secondary); font-size: var(--text-sm); line-height: var(--leading-relaxed); margin: 0; }

.footer-links { list-style: none; display: flex; flex-direction: column; gap: var(--space-1); margin: 0; padding: 0; }

.footer-links a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 34px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--text-sm);
  border-radius: var(--radius-xs);
  transition: var(--t-colors);
}

.footer-links a:hover { color: var(--on-surface-primary); text-decoration: underline; }
.footer-links a :is(i, svg) { width: 14px; height: 14px; opacity: 0.7; }

.footer-bottom {
  max-width: var(--max-width);
  margin-inline: auto;
  padding-top: var(--space-5);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ==========================================================================
   11) تصحيحات النمط النهاري لهيكل التطبيق
   ========================================================================== */
[data-theme="light"] .nav-drawer-backdrop { background: rgba(38, 27, 20, 0.5); }
[data-theme="light"] .icon-btn,
[data-theme="light"] .theme-toggle-btn,
[data-theme="light"] .search-trigger-btn,
[data-theme="light"] .role-switcher-chip,
[data-theme="light"] .mobile-menu-btn {
  background: #FFFFFF;
  border-color: rgba(92, 58, 33, 0.18);
}
[data-theme="light"] .search-kbd { background: rgba(92, 58, 33, 0.07); border-color: rgba(92, 58, 33, 0.14); }
[data-theme="light"] .main-footer { background: #EAE1D3; border-top-color: rgba(92, 58, 33, 0.15); }
[data-theme="light"] .nav-tag { color: #FFFFFF; }
[data-theme="light"] .skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
}

/* ==========================================================================
   12) إصلاحات التمرير الأفقي على الموبايل
   لا يجوز أن تُمرَّر الصفحة أفقيًا أبدًا؛ الأشرطة الطويلة تُمرَّر داخل حاويتها.
   ========================================================================== */

/* الدرج المغلق كان لا يزال يشغل عرضًا خارج الشاشة فيمدّ scrollWidth */
.nav-drawer[hidden],
.nav-drawer-backdrop[hidden] { display: none !important; }

/* الهوية تتقلّص قبل أن تدفع أدوات الترويسة خارج الشاشة */
.brand-text-block { min-width: 168px; }
.logos-cluster { flex-shrink: 0; }
.department-title-ar {
  /* يلتفّ سطرين عند الضيق بدل اقتطاعه بثلاث نقاط.
     بلا overflow:hidden: الحروف العربية النازلة (ج، ع، ي) تتجاوز صندوق
     السطر، وقصّها كان يقطع أطرافها. */
  white-space: normal;
  text-wrap: balance;
  overflow: visible;
}

@media (max-width: 680px) {
  .main-header-inner { gap: var(--space-2); padding-inline: var(--space-4); }
  /* على الهاتف: الشعار وحده يكفي للهوية — الاسم الكامل كان يلتفّ أربعة
     أسطر فيبتلع نصف الشاشة، ومسار التنقّل أسفله يقول أين أنت أصلًا. */
  .brand-text-block { display: none; }
  .brand-logo-img.pud-logo { height: 38px; }
}

/* أشرطة الأزرار الطويلة: تمرير داخلي بدل كسر الصفحة */
.level-tabs-scroll,
.gta-quick-switcher,
.dash-subtabs,
.explorer-toolbar-actions,
.explorer-drive-switcher {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  max-width: 100%;
  padding-bottom: var(--space-1);
}

.level-tabs-scroll > *,
.gta-quick-switcher > *,
.dash-subtabs > *,
.explorer-toolbar-actions > *,
.explorer-drive-switcher > * { flex: 0 0 auto; }

/* الجداول العريضة تُمرَّر داخل إطارها */
.dash-panel table { min-width: 720px; }
.dash-panel .dash-table-wrap,
.dash-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* شبكات البطاقات على أجهزة الكمبيوتر: شبكة أوتوماتيكية متعددة الأعمدة */
@media (min-width: 769px) {
  .projects-grid-container,
  .benchmarks-grid,
  .books-grid,
  .software-grid,
  .analysis-tools-grid,
  .print-shops-grid,
  .drive-folders-grid,
  .inspiration-cards-grid,
  .inspiration-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr));
  }
}

/* تحويل كافة شبكات البطاقات في الصفحات الفرعية إلى سلايدر أفقي على الموبايل لمنع التراكم الرأسي */
@media (max-width: 768px) {
  .projects-grid-container,
  .benchmarks-grid,
  .books-grid,
  .software-grid,
  .analysis-tools-grid,
  .print-shops-grid,
  .drive-folders-grid,
  .inspiration-cards-grid,
  .inspiration-grid,
  .courses-card-grid {
    display: flex !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scroll-snap-type: x mandatory !important;
    -webkit-overflow-scrolling: touch !important;
    scroll-behavior: smooth;
    gap: var(--space-4) !important;
    padding: var(--space-2) 16px var(--space-4) 16px !important;
    margin-inline: -16px !important;
    scrollbar-width: thin;
  }

  .projects-grid-container::-webkit-scrollbar,
  .benchmarks-grid::-webkit-scrollbar,
  .books-grid::-webkit-scrollbar,
  .software-grid::-webkit-scrollbar,
  .analysis-tools-grid::-webkit-scrollbar,
  .print-shops-grid::-webkit-scrollbar,
  .drive-folders-grid::-webkit-scrollbar,
  .inspiration-cards-grid::-webkit-scrollbar,
  .inspiration-grid::-webkit-scrollbar,
  .courses-card-grid::-webkit-scrollbar {
    height: 4px;
  }

  .projects-grid-container::-webkit-scrollbar-thumb,
  .benchmarks-grid::-webkit-scrollbar-thumb,
  .books-grid::-webkit-scrollbar-thumb,
  .software-grid::-webkit-scrollbar-thumb,
  .analysis-tools-grid::-webkit-scrollbar-thumb,
  .print-shops-grid::-webkit-scrollbar-thumb,
  .drive-folders-grid::-webkit-scrollbar-thumb,
  .inspiration-cards-grid::-webkit-scrollbar-thumb,
  .inspiration-grid::-webkit-scrollbar-thumb,
  .courses-card-grid::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: var(--radius-full);
  }

  .projects-grid-container > *,
  .benchmarks-grid > *,
  .books-grid > *,
  .software-grid > *,
  .analysis-tools-grid > *,
  .print-shops-grid > *,
  .drive-folders-grid > *,
  .inspiration-cards-grid > *,
  .inspiration-grid > *,
  .courses-card-grid > * {
    flex: 0 0 84% !important;
    min-width: 270px !important;
    max-width: 330px !important;
    scroll-snap-align: start !important;
    scroll-snap-stop: normal !important;
  }

  .courses-card-grid > .empty-course-card,
  .projects-grid-container > .empty-feed-card,
  .courses-card-grid > .empty-state,
  .projects-grid-container > .empty-state {
    flex: 0 0 100% !important;
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* أي زر داخل صفّ إجراءات يسمح بالالتفاف بدل التمدد */
.shop-links,
.tool-card-actions,
.book-footer,
.software-actions,
.project-footer { flex-wrap: wrap; }
