/* ==========================================================================
   BiddexHub — Soft 3D Sidebar
   ========================================================================== */

:root {
  /* ألوان مستوحاة من الشعار */
  --sb-bg: #1e293b; /* كحلي داكن */
  --sb-bg-light: #334155; 
  --sb-brand: #f97316; /* برتقالي */
  --sb-brand-dark: #ea580c;
  --sb-text: #94a3b8;
  --sb-text-active: #ffffff;
  
  /* أبعاد السايدبار */
  --sb-width: 90px;
  --sb-width-open: 280px;
  --sb-gap: 20px;
  --sb-radius: 32px;
  --sb-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

body.has-sidebar {
  padding-inline-start: calc(var(--sb-width) + var(--sb-gap) * 2);
  transition: padding-inline-start 0.4s var(--sb-ease);
}

/* ---------------------------------------------------------------- Sidebar Base */
.sidebar {
  position: fixed;
  top: var(--sb-gap);
  bottom: var(--sb-gap);
  inset-inline-start: var(--sb-gap);
  z-index: 1000;
  width: var(--sb-width);
  border-radius: var(--sb-radius);
  background: var(--sb-bg);
  transition: width 0.4s var(--sb-ease), box-shadow 0.4s var(--sb-ease),
              transform 0.35s var(--sb-ease);
  
  /* التأثير ثلاثي الأبعاد (Soft 3D) */
  box-shadow: 
    inset 2px 2px 5px rgba(255, 255, 255, 0.05), /* لمعة علوية */
    inset -2px -2px 5px rgba(0, 0, 0, 0.3),      /* ظل داخلي سفلي */
    10px 10px 30px rgba(0, 0, 0, 0.25),          /* ظل خارجي */
    -5px -5px 15px rgba(255, 255, 255, 0.05);    /* انعكاس خارجي */
    
  overflow: hidden;
}

/* التأثير عند التمرير أو التركيز */
.sidebar:hover,
.sidebar:has(:focus-visible) {
  width: var(--sb-width-open);
  box-shadow: 
    inset 2px 2px 5px rgba(255, 255, 255, 0.05),
    inset -2px -2px 5px rgba(0, 0, 0, 0.3),
    15px 15px 40px rgba(0, 0, 0, 0.35),
    -5px -5px 20px rgba(255, 255, 255, 0.08);
}

/* خلفية داخلية لإعطاء عمق (Gradient) */
.sidebar__bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(145deg, var(--sb-bg-light) 0%, var(--sb-bg) 100%);
  z-index: -1;
  opacity: 0.6;
}

.sidebar__content {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 24px 16px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none; /* Firefox */
}
.sidebar__content::-webkit-scrollbar { display: none; } /* Chrome */

/* ---------------------------------------------------------------- Brand */
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding-inline: 10px;
  margin-bottom: 24px;
  text-decoration: none;
}

.sidebar__logo {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  object-fit: contain;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3));
}

.sidebar__brand-text {
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(-10px);
  transition: opacity 0.3s var(--sb-ease), transform 0.3s var(--sb-ease);
}
.sidebar__brand-text span { color: var(--sb-brand); }

.sidebar:hover .sidebar__brand-text,
.sidebar:has(:focus-visible) .sidebar__brand-text {
  opacity: 1;
  transform: translateX(0);
}

/* ---------------------------------------------------------------- Links */
.sidebar__nav,
.sidebar__foot {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar__foot {
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  width: 100%;
  height: 56px;
  padding: 0 16px;
  border-radius: 20px;
  color: var(--sb-text);
  background: transparent;
  border: none;
  cursor: pointer;
  text-decoration: none;
  text-align: start;
  font: inherit;
  transition: all 0.3s var(--sb-ease);
}

/* عدّاد الإشعارات غير المقروءة */
.sidebar__badge {
  position: absolute;
  top: -8px;
  inset-inline-end: -10px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.9);
  pointer-events: none;
}

.sidebar__badge[hidden] {
  display: none;
}

/* الأيقونات */
.sidebar__icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  font-size: 20px;
  transition: color 0.3s ease, transform 0.3s ease;
}

/* النصوص */
.sidebar__label {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(-10px);
  transition: opacity 0.3s var(--sb-ease), transform 0.3s var(--sb-ease);
}

.sidebar:hover .sidebar__label,
.sidebar:has(:focus-visible) .sidebar__label {
  opacity: 1;
  transform: translateX(0);
}

/* ---------------------------------------------------------------- Hover State */
.sidebar__link:hover,
.sidebar__link:focus-visible {
  color: #fff;
  outline: none;
  /* تأثير النقش البارز (Neumorphic press) */
  box-shadow: 
    inset 2px 2px 5px rgba(0,0,0,0.2),
    inset -2px -2px 5px rgba(255,255,255,0.05);
  background: rgba(255,255,255,0.02);
}

.sidebar__link:hover .sidebar__icon {
  transform: scale(1.1);
}

/* ---------------------------------------------------------------- Active State (البرتقالي) */
.sidebar__link.is-active {
  color: var(--sb-text-active);
  font-weight: 700;
  /* تأثير الزر البارز 3D باللون البرتقالي */
  background: linear-gradient(135deg, var(--sb-brand) 0%, var(--sb-brand-dark) 100%);
  box-shadow: 
    4px 4px 10px rgba(234, 88, 12, 0.4),     /* ظل خارجي برتقالي */
    inset 2px 2px 4px rgba(255, 255, 255, 0.4), /* لمعة داخلية */
    inset -2px -2px 4px rgba(0, 0, 0, 0.2);     /* ظل داخلي */
  transform: translateY(-2px); /* يرتفع قليلاً */
}

.sidebar__link.is-active .sidebar__icon {
  color: #fff;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

/* ---------------------------------------------------------------- Modal */
.sidebar-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}

.sidebar-modal.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease;
}

.sidebar-modal__card {
  width: min(420px, 100%);
  padding: 28px;
  border-radius: 32px;
  background: linear-gradient(145deg, #1e293b, #0f172a);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  transform: scale(0.95);
  transition: transform 0.3s var(--sb-ease);
}

.sidebar-modal.is-open .sidebar-modal__card {
  transform: scale(1);
}

.sidebar-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.sidebar-modal__title {
  color: #ffffff;
  font-size: 1.25rem;
  font-weight: 800;
}

.sidebar-modal__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
  transition: background 0.2s ease;
}

.sidebar-modal__close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ---------------------------------------------------------------- Accessibility (Focus Trap Indicator) */
/* إطار واضح للمستخدمين الذين يستخدمون الكيبورد */
.sidebar__link:focus-visible {
  outline: 2px solid var(--sb-brand);
  outline-offset: 2px;
}

/* ------------------------------------------- header next to the sidebar */
@media (min-width: 768px) and (max-width: 1399.98px) {
  body.has-sidebar .main-nav {
    display: none;
  }

  body.has-sidebar .menu-toggle {
    display: inline-flex;
  }

  body.has-sidebar .mobile-drawer:not([hidden]) {
    display: flex !important;
  }
}

@media (min-width: 768px) and (max-width: 1143.98px) {
  body.has-sidebar .header__login {
    padding: 0.55rem;
  }

  body.has-sidebar .header__login span {
    display: none;
  }
}

/* زر "المزيد": للموبايل فقط */
.sidebar__link--more {
  display: none;
}

/* ---------------------------------------------------------------- Mobile: Bottom Navigation */
@media (max-width: 768px) {
  /* مساحة سفلية تساوي ارتفاع الشريط (70px) + هامشه (15px) + تنفّس */
  body.has-sidebar,
  body.has-bottom-nav {
    padding-inline-start: 0;
    padding-bottom: 105px;
  }

  .sidebar,
  .sidebar:hover,
  .sidebar:has(:focus-visible) {
    top: auto;
    bottom: 15px;
    inset-inline: 15px;
    width: auto;
    height: 70px;
    border-radius: 24px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  }

  /* إخفاء الشريط عند التمرير لأسفل (يُدار عبر JS) */
  .sidebar.is-nav-hidden {
    transform: translateY(calc(100% + 30px));
  }

  .sidebar__content {
    flex-direction: row;
    align-items: center;
    padding: 0 10px;
    gap: 5px;
  }

  .sidebar__brand,
  .sidebar__foot {
    display: none; /* إخفاء العناصر غير الضرورية في الموبايل */
  }

  .sidebar__nav {
    flex-direction: row;
    justify-content: space-around;
    width: 100%;
    gap: 5px;
  }

  .sidebar__link {
    flex: 0 1 50px;
    min-width: 0;
    justify-content: center;
    width: 50px;
    height: 50px;
    padding: 0;
    border-radius: 16px;
    gap: 0;
  }

  .sidebar__label {
    display: none; /* إخفاء النصوص في الموبايل */
  }

  /* صفحات غير جاهزة بعد: تظهر في سايدبار الكمبيوتر فقط */
  .sidebar__link--desktop,
  .sidebar__link--mobile-hidden {
    display: none;
  }
  
  .sidebar__link.is-active {
    transform: translateY(-5px); /* يرتفع أكثر في الموبايل */
  }

  /* زر "المزيد" في شريط التنقل السفلي */
  .sidebar__link.sidebar__link--more {
    display: flex;
    flex: 0 1 50px;
    min-width: 0;
    justify-content: center;
    width: 50px;
    height: 50px;
    padding: 0;
    border-radius: 16px;
    margin: 0;
  }

  .sidebar__link.sidebar__link--more:hover,
  .sidebar__link.sidebar__link--more:focus-visible {
    background: var(--sb-brand);
    color: #fff;
  }
}

/* ---------------------------------------------------------------- More Modal */
.sidebar-modal--more {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}

.sidebar-modal--more.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease;
}

.sidebar-modal--more .sidebar-modal__card {
  width: 90%;
  max-width: 300px;
  padding: 20px;
  border-radius: 24px;
  background: linear-gradient(145deg, #1e293b, #0f172a);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  transform: scale(0.95);
  transition: transform 0.3s var(--sb-ease);
}

.sidebar-modal--more.is-open .sidebar-modal__card {
  transform: scale(1);
}

.sidebar-modal--more .sidebar-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sidebar-modal--more .sidebar-modal__title {
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 800;
}

.sidebar-modal--more .sidebar-modal__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  cursor: pointer;
  transition: background 0.2s ease;
}

.sidebar-modal--more .sidebar-modal__close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.sidebar-modal--more .sidebar-modal__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-modal--more .sidebar-modal__link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 10px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: #cbd5e1;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  text-align: start;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.sidebar-modal--more .sidebar-modal__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  font-size: 17px;
  color: #f97316;
}

.sidebar-modal--more .sidebar-modal__link:hover,
.sidebar-modal--more .sidebar-modal__link:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  outline: none;
}

.sidebar-modal--more .sidebar-modal__link--logout {
  color: #ef4444;
  font-weight: 700;
  margin-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 0 0 12px 12px;
}

.sidebar-modal--more .sidebar-modal__link--logout .sidebar-modal__icon {
  color: #ef4444;
}

.sidebar-modal--more .sidebar-modal__link--logout:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
}

/* منع تمرير الخلفية عند فتح أي مودال */
body.has-open-modal {
  overflow: hidden;
}

/* ---------------------------------------------------------------- More Modal: Bottom Sheet (mobile) */
@media (max-width: 768px) {
  .sidebar-modal--more {
    align-items: flex-end;
    padding: 0;
  }

  .sidebar-modal--more .sidebar-modal__card {
    width: 100%;
    max-width: none;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    border-radius: 26px 26px 0 0;
    transform: translateY(100%);
  }

  .sidebar-modal--more.is-open .sidebar-modal__card {
    transform: translateY(0);
  }

  .sidebar-modal--more .sidebar-modal__link {
    padding: 14px 12px;
  }
}

/* ---------------------------------------------------------------- Very small phones */
@media (max-width: 380px) {
  .sidebar__nav {
    gap: 2px;
  }

  .sidebar__link,
  .sidebar__link.sidebar__link--more {
    flex: 1 1 0;
    width: auto;
    height: 44px;
  }

  .sidebar__icon {
    font-size: 18px;
  }
}

/* ---------------------------------------------------------------- Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .sidebar, .sidebar__link, .sidebar__label, .sidebar__brand-text, .sidebar-modal__card {
    transition-duration: 0.001ms !important;
  }
}
