/* ═══════════════════════════════════════════════════════════════════════
   ALMIGHWARI ENTERPRISE — نظام التخطيط (App Shell)
   يملك بالكامل: الهيدر + السايدبار + منطقة المحتوى + طبقة التعتيم
   كحلي + ذهبي | RTL | متجاوب | يُحمَّل بعد almighwari-brand.css
   ─────────────────────────────────────────────────────────────────────
   ملاحظة معمارية: هذا الملف هو المصدر الوحيد لتصميم هيكل التطبيق.
   لا تضع تنسيقات الهيدر/السايدبار داخل القوالب (header/sidebar/base).
═══════════════════════════════════════════════════════════════════════ */

:root {
  /* أبعاد الهيكل */
  --app-header-h: 70px;
  --app-sidebar-w: 300px;

  /* مقياس الطبقات (z-index) — مصدر واحد لمنع التضارب */
  --z-overlay:  1040;
  --z-sidebar:  1045;
  --z-header:   1050;
  --z-dropdown: 1060;

  /* أسماء متوارثة تعتمد عليها بعض الشاشات — لا تحذفها */
  --header-height: var(--app-header-h);
  --sidebar-width: var(--app-sidebar-w);
  --primary-color: var(--am-gold, #C8860A);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ══════════════════════ الهيدر ══════════════════════ */
.header {
  position: fixed;
  top: 0; right: 0; left: 0;
  height: var(--app-header-h);
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  direction: rtl;
  padding: 0 20px;
  background: linear-gradient(135deg, var(--am-navy-deep, #0F1B2F) 0%, var(--am-navy, #1A2B4A) 55%, var(--am-navy-light, #243660) 100%);
  border-bottom: 3px solid var(--am-gold, #C8860A);
  box-shadow: 0 4px 22px rgba(0, 0, 0, 0.28);
  transition: padding-right 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.logo { display: flex; align-items: center; text-decoration: none; transition: transform 0.2s ease; }
.logo:hover { transform: scale(1.02); }
.logo img {
  max-height: 48px; width: auto; object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(200, 134, 10, 0.40));
}

/* زر فتح/إغلاق السايدبار */
.toggle-sidebar-btn {
  display: flex; align-items: center;
  font-size: 26px; margin-right: 15px;
  color: rgba(255, 255, 255, 0.82);
  cursor: pointer; user-select: none;
  transition: color 0.2s ease, transform 0.3s ease;
}
.toggle-sidebar-btn:hover { color: var(--am-gold-light, #E8A020); transform: rotate(90deg); }

/* اسم الفرع — حبّة في منتصف الهيدر */
.branch-name {
  position: absolute; left: 50%; transform: translateX(-50%); z-index: 1;
  font-size: 15px; font-weight: 700; white-space: nowrap;
  color: var(--am-gold-light, #E8A020);
  padding: 7px 20px; border-radius: 30px;
  background: rgba(200, 134, 10, 0.12);
  border: 1px solid rgba(200, 134, 10, 0.40);
}

/* حاوية التنقل */
.header-nav-container { display: flex; align-items: center; }
.header-nav ul {
  display: flex; align-items: center; gap: 10px;
  list-style: none; margin: 0; padding: 0;
}
.header-nav .nav-item { position: relative; }

/* أزرار الهيدر الدائرية (مميّزة عن روابط السايدبار) */
.header-nav .nav-link {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none; cursor: pointer; position: relative;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.header-nav .nav-link:hover {
  background: rgba(200, 134, 10, 0.20);
  color: var(--am-gold-light, #E8A020);
  transform: translateY(-2px);
}
.header-nav .nav-link i { font-size: 21px; }

/* شارة العدد */
.badge-number {
  position: absolute; top: 2px; right: 2px;
  display: flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  font-size: 10px; font-weight: 700; color: #fff;
  background: var(--am-danger, #C0392B);
  border: 2px solid var(--am-navy, #1A2B4A); border-radius: 50%;
}

/* حبّة الملف الشخصي */
.nav-profile {
  width: auto !important; height: auto !important;
  border-radius: 30px !important;
  gap: 8px; padding: 5px 14px !important;
}
.nav-profile img {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.18);
}
.nav-profile span { font-weight: 600; font-size: 14px; color: rgba(255, 255, 255, 0.92); }
.dropdown-toggle::after {
  margin-right: 5px; vertical-align: middle; content: "";
  border-top: 0.3em solid; border-right: 0.3em solid transparent; border-left: 0.3em solid transparent;
}

/* ══════════ القوائم المنسدلة في الهيدر ══════════ */
.dropdown-menu {
  position: absolute; top: 100%; right: 0; left: auto; z-index: var(--z-dropdown);
  display: none; min-width: 260px; margin-top: 0.5rem; padding: 0.5rem 0;
  text-align: right; list-style: none; background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.10); border-radius: 0.6rem;
  box-shadow: 0 0.6rem 1.4rem rgba(15, 27, 47, 0.18);
  opacity: 0; visibility: hidden; transform: translateY(-10px);
  transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease;
}
.dropdown-menu.show { display: block; opacity: 1; visibility: visible; transform: translateY(0); }
.messages-dropdown-menu { right: auto; left: 0; }
.dropdown-header { padding: 0.75rem 1rem; font-size: 0.85rem; color: var(--am-steel, #4A5568); border-bottom: 1px solid #eef0f4; }
.dropdown-item {
  display: block; width: 100%; padding: 0.55rem 1rem; clear: both;
  color: #212529; text-align: inherit; text-decoration: none; white-space: nowrap;
  background: transparent; border: 0; cursor: pointer; transition: background 0.15s, color 0.15s;
}
.dropdown-item:hover { background: rgba(200, 134, 10, 0.07); color: var(--am-gold, #C8860A); }
.dropdown-item i { margin-left: 10px; font-size: 18px; }
.dropdown-divider { height: 0; margin: 0.4rem 0; border-top: 1px solid #eef0f4; }
.message-item { padding: 0.7rem 1rem; border-bottom: 1px solid #f3f4f7; transition: background 0.15s; }
.message-item:hover { background: rgba(200, 134, 10, 0.04); }
.message-item h4 { margin: 0 0 4px; font-size: 14px; font-weight: 600; color: #333; }
.message-item p { margin: 0; font-size: 12px; color: #777; line-height: 1.5; }

/* ══════════════════════ السايدبار ══════════════════════ */
.sidebar {
  position: fixed; top: var(--app-header-h); right: 0;
  width: var(--app-sidebar-w); height: calc(100% - var(--app-header-h));
  z-index: var(--z-sidebar);
  overflow-y: auto; overflow-x: hidden;
  background: linear-gradient(180deg, var(--am-navy-deep, #0F1B2F) 0%, var(--am-navy, #1A2B4A) 100%);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.22);
  transition: right 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(200, 134, 10, 0.55); border-radius: 10px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--am-gold, #C8860A); }

.sidebar-header { padding: 18px 16px; text-align: center; border-bottom: 1px solid rgba(255, 255, 255, 0.07); }
.sidebar-header h4 { margin: 0; font-weight: 800; color: var(--am-gold-light, #E8A020); letter-spacing: 0.5px; }

.sidebar-nav { padding: 8px 0; margin: 0; list-style: none; }
.sidebar-nav .nav-item { position: relative; margin-bottom: 2px; }

/* روابط السايدبار الرئيسية */
.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 18px; margin: 2px 8px; border-radius: var(--am-r-sm, 6px);
  color: rgba(255, 255, 255, 0.72); font-size: 14px; font-weight: 600;
  text-decoration: none; cursor: pointer;
  border-right: 3px solid transparent;
  transition: background 0.2s, color 0.2s, transform 0.2s, border-color 0.2s;
}
.sidebar-nav .nav-link:hover {
  background: rgba(200, 134, 10, 0.14); color: var(--am-gold-light, #E8A020);
  border-right-color: var(--am-gold, #C8860A); transform: translateX(-3px);
}
.sidebar-nav .nav-link.active {
  background: linear-gradient(135deg, var(--am-gold, #C8860A), var(--am-gold-light, #E8A020));
  color: var(--am-navy-deep, #0F1B2F); font-weight: 800;
  box-shadow: 0 4px 14px rgba(200, 134, 10, 0.38);
}
.sidebar-nav .nav-link i { font-size: 18px; min-width: 24px; text-align: center; color: inherit; }
.sidebar-nav .nav-link span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-nav .nav-link .bi-chevron-down { font-size: 12px; transition: transform 0.25s ease; color: rgba(255, 255, 255, 0.45); }
.sidebar-nav .nav-link.collapsed .bi-chevron-down { transform: rotate(-90deg); }

/* قوائم فرعية */
.nav-content { display: none; padding: 4px 0; margin: 0; list-style: none; background: rgba(255, 255, 255, 0.04); }
.nav-content.show { display: block; }
.nav-content li { border: 0; }
.nav-content a {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 44px 10px 18px; font-size: 13px;
  color: rgba(255, 255, 255, 0.60); text-decoration: none; position: relative;
  transition: background 0.15s, color 0.15s, padding 0.15s;
}
.nav-content a:hover { background: rgba(200, 134, 10, 0.10); color: var(--am-gold-light, #E8A020); padding-right: 50px; }
.nav-content a.active { background: rgba(200, 134, 10, 0.16); color: var(--am-gold-light, #E8A020); font-weight: 700; }
.nav-content a.active::before { content: ''; position: absolute; right: 0; top: 0; bottom: 0; width: 3px; background: var(--am-gold, #C8860A); }
.nav-content i { font-size: 12px; color: var(--am-gold, #C8860A); }
.sidebar .dropdown-divider { margin: 4px 16px; border-top: 1px solid rgba(255, 255, 255, 0.07); }

/* ══════════════════════ منطقة المحتوى ══════════════════════ */
#main {
  margin-top: var(--app-header-h);
  padding: 24px;
  background: var(--am-light, #F4F6FA);
  transition: margin-right 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ══════════════════════ طبقة التعتيم (الجوال) ══════════════════════ */
.sidebar-overlay {
  position: fixed; inset: 0; z-index: var(--z-overlay);
  display: none; opacity: 0;
  background: rgba(15, 27, 47, 0.55);
  transition: opacity 0.28s ease;
}
body.sidebar-open .sidebar-overlay { display: block; opacity: 1; }

/* ══════════════════════ سطح المكتب (≥ 992px) ══════════════════════ */
@media (min-width: 992px) {
  /* السايدبار مخفي افتراضياً خارج الشاشة، يظهر عند الفتح */
  body:not(.sidebar-open) .sidebar { right: calc(-1 * var(--app-sidebar-w)); }
  body.sidebar-open #main { margin-right: var(--app-sidebar-w); }
  body.sidebar-open .header { padding-right: var(--app-sidebar-w); }
  /* لا حاجة لطبقة التعتيم على سطح المكتب */
  .sidebar-overlay { display: none !important; }
}

/* ══════════════════════ الأجهزة اللوحية والجوال (≤ 991px) ══════════════════════ */
@media (max-width: 991px) {
  .sidebar {
    width: 86%; max-width: 340px; right: -100%;
    box-shadow: 2px 0 26px rgba(0, 0, 0, 0.30);
  }
  body.sidebar-open .sidebar { right: 0; }
  body.sidebar-open #main { margin-right: 0; }   /* المحتوى لا يتزحزح، السايدبار يطفو فوقه */
  body.sidebar-open .header { padding-right: 0; }
  body.sidebar-open { overflow: hidden; }         /* منع تمرير الخلفية */
  #main { padding: 16px 12px; }
}

@media (max-width: 768px) {
  .header { padding: 0 12px; }
  .logo img { max-height: 38px; }
  .toggle-sidebar-btn { font-size: 23px; margin-right: 10px; }
  .branch-name { display: none; }
  .nav-profile span { display: none; }
  .header-nav .nav-link { width: 38px; height: 38px; }
  .header-nav .nav-link i { font-size: 18px; }
  .header-nav ul { gap: 6px; }
  #main { padding: 12px 8px; }
  /* القوائم المنسدلة تملأ العرض على الجوال */
  .dropdown-menu, .messages-dropdown-menu, .profile-dropdown-menu {
    position: fixed; top: var(--app-header-h); right: 8px; left: 8px;
    min-width: 0; max-height: 78vh; overflow-y: auto;
  }
}

/* ══════════════════════ الطباعة ══════════════════════ */
@media print {
  .header, .sidebar, .sidebar-overlay, .toggle-sidebar-btn { display: none !important; }
  #main { margin: 0 !important; padding: 0 !important; }
}
