/* =========================================================
   1. BASE & VARIABLES
========================================================= */
:root {
  --bg: #f3f4f6ef;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;

  --accent: #6d28d9;
  --accent-soft: rgba(109,40,217,.12);

  --header-h: 60px;   /* ✅ ارتفاع الهيدر ثابت */
  --sb-collapsed: 72px; /* ✅ عرض السايدبار المغلق */
  --sb-open: 260px;     /* ✅ عرض السايدبار المفتوح */
  
  --sb-bg: #ffffff;
  --sb-border: #e5e7eb;
  --sb-radius: 22px;

  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; background: var(--bg); }

/* =========================================================
   2. BODY SPACE RESERVATION (ZERO SHAKE)
========================================================= */
body {
  margin: 0;
  font-family: "Cairo", "Tajawal", system-ui, sans-serif;
  color: var(--text);
  direction: rtl; /* ✅ العربية */
  
  /* 🔥 حجز المساحة مسبقاً لمنع الرعشة */
  padding-top: var(--header-h);
  padding-left: var(--sb-collapsed); /* السايدبار على اليسار */
  transition: padding-left .18s ease;
}

body.sidebar-open {
  padding-left: var(--sb-open);
}

/* 🛡️ شوبيفاي: إزالة المساحات تلقائياً */
html.is-shopify body {
  padding-top: 0 !important;
  padding-left: 0 !important;
  background: transparent;
}

/* =========================================================
   3. MAIN CONTENT
========================================================= */
main, .app-main {
  padding: 24px;
  margin: 0 !important;
  min-height: calc(100vh - var(--header-h));
}

html.is-shopify main, 
html.is-shopify .app-main {
  padding: 16px;
  min-height: 100vh;
}

/* =========================================================
   4. FIXED HEADER
========================================================= */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  z-index: 3000;
  background: #272727;
  color: #fff;
  border-bottom: 1px solid #7c7c7c;
}

html.is-shopify .app-header {
  display: none !important;
}

.header-inner {
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* =========================================================
   FIXED HEADER TITLE (ANTI-SHAKE)
========================================================= */
.header-title {
  min-width: 150px;
  height: 24px;         
  display: flex;
  align-items: center;  
}

.header-title h1 {
  margin: 0 !important;
  font-size: 1.15rem !important; 
  font-weight: 800 !important;
  line-height: 1 !important;
  white-space: nowrap !important; 
  letter-spacing: 0 !important;
  visibility: visible !important;
}

/* =========================================================
   5. SIDEBAR (LEFT POSITIONED - RTL ADAPTED)
========================================================= */
:root {
  --sb-collapsed: 68px; /* تصغير قليلاً ليصبح أنيقاً */
  --sb-open: 240px;      /* عرض مثالي للـ Desktop */
  --sb-bg: #ffffff;
}
.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  height: calc(100vh - var(--header-h));
  width: var(--sb-open);
  transform: translateX(calc(-100% + var(--sb-collapsed))); 
  background: var(--sb-bg);
  color: var(--text);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sb-border);
  border-top-right-radius: var(--sb-radius);
  border-bottom-right-radius: var(--sb-radius);
  box-shadow: 5px 0px 30px rgba(0,0,0,.05);
  transition: transform .18s ease;
  will-change: transform;
}
/* 🔥 القاعدة المفقودة التي تجعل السايدبار يفتح فعلياً */
body.sidebar-open .sidebar {
  transform: translateX(0) !important;
}

.sidebar-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 20px 10px;
}

.menu-top, .menu-middle {
  list-style: none; padding: 0; margin: 0;
}
.menu-middle {
  margin-top: auto; /* يدفع الجزء المتوسط للأسفل قليلاً */
  margin-bottom: auto;
}

.menu-bottom {
  list-style: none; padding: 0; margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 15px;
}
.sidebar-menu li a, .logout-btn {
  display: flex;
  align-items: center;
  flex-direction: row-reverse; /* أيقونة يمين، نص يسار */
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--muted);
  transition: all 0.2s;
}

/* 🛡️ إخفاء السايدبار في شوبيفاي */
html.is-shopify .sidebar,
html.is-shopify #sidebar-container {
  display: none !important;
}

/* ---------------- Sidebar Handle (Arrow) ---------------- */
.sidebar-handle {
  position: absolute;
  top: 18px;
  right: 12px; /* الزر على الحافة اليمنى ليبقى مرئياً */
  width: 44px; height: 44px;
  border: 0; border-radius: 14px;
  background: rgba(109,40,217,0.08);
  cursor: pointer; display: grid; place-items: center;
  transition: background .15s ease;
}
.sidebar-handle:hover { background: #ddd6fe; }

.sidebar-handle .chev {
  width: 10px; height: 10px;
  border-right: 3px solid var(--accent);
  border-bottom: 3px solid var(--accent);
  transform: rotate(-45deg); /* يشير لليمين لطلب الفتح */
  transition: transform .18s ease;
}
body.sidebar-open .sidebar-handle .chev {
  transform: rotate(135deg); /* يشير لليسار للطي */
}

/* ---------------- Sidebar Content ---------------- */
.sidebar-brand {
  padding: 12px 12px 10px 12px;
  display: flex; align-items: center; gap: 12px;
}

.sidebar-menu {
  list-style: none; padding: 68px 12px 12px 12px; margin: 0;
  display: flex; flex-direction: column; gap: 4px; height: 100%;
}

.sidebar-menu li > a, .logout-btn {
  width: 100%; 
  display: flex; 
  align-items: center; 
  justify-content: flex-end; /* دفع العناصر لليمين حتى لا تختفي */
  gap: 12px;
  padding: 10px 18px; /* توازن الهوامش */
  border-radius: 14px;
  color: var(--text); 
  text-decoration: none; border: none;
  background: transparent; cursor: pointer; text-align: right;
  transition: background .15s, transform .15s;
}

.sidebar-menu li > a:hover, .logout-btn:hover {
  background: var(--hover-bg); 
  transform: translateX(2px); /* حركة لليمين */
}

/* SVG Icons Style (✅ إصلاح الأيقونات) */
.sidebar-menu svg {
width: 20px !important;
  height: 20px !important;
  stroke: currentColor; /* ليتغير اللون مع الـ Hover */
  stroke-width: 2;
  fill: none; /* أغلب أيقونات اللوجستيك تعمل بالـ Stroke */
  flex-shrink: 0;
}
body:not(.sidebar-open) .label {
  display: none;
}

.sidebar-menu li.active > a {
  background: var(--accent-soft); 
  color: var(--accent);
}
.sidebar-menu li.active svg { 
  color: var(--accent); 
}

/* ✅ إصلاح اختفاء النصوص (Labels) */
.label { 
  white-space: nowrap; 
  flex-grow: 1; /* دفع النص لأخذ المساحة المتاحة */
  text-align: right; /* محاذاة النص لليمين */
}

.sidebar:not(.open) .label { 
  display: none; 
}
body.sidebar-open .label { 
  display: block; 
}

/* ---------------- Tooltips (Left Sidebar) ---------------- */
.sidebar-menu li { position: relative; }
.sidebar-menu li::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px); /* تظهر على اليمين */
  top: 50%; transform: translateY(-50%);
  background: linear-gradient(135deg, #6d28d9, #8b5cf6);
  color: #fff; font-size: 13px; padding: 6px 10px;
  border-radius: 8px; white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity .15s ease; z-index: 3000;
}
body:not(.sidebar-open) .sidebar-menu li:hover::after { opacity: 1; }



.nav-bottom-group {
  margin-top: auto; /* هذا هو "السر" لدفع الإعدادات والخروج للأسفل */
  padding-top: 15px;
  border-top: 1px solid var(--sb-border);
}
/* =========================================================
   6. RESPONSIVE (MOBILE)
========================================================= */
@media (max-width: 768px) {
  .sidebar {
    top: 0; /* يبدأ من الأعلى تماماً في الهاتف */
    height: 100vh;
    width: 280px;
  }
  
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  /* زر القائمة في الهيدر */
  .header-mobile-menu {
    display: block !important;
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
  }
}

.chev-icon {
  width: 16px;
  height: 16px;
}