/* Modern Professional Sidebar Styles */
.modern-sidebar {
  position: fixed;
  top: 0;
  right: 0; /* Positioned on the right for RTL support */
  width: 280px;
  height: 100vh;
  background: #1a2335;
  background: linear-gradient(180deg, #111827 0%, #1f2937 100%);
  box-shadow: -5px 0 25px rgba(0, 0, 0, 0.2);
  z-index: 1030;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(255, 255, 255, 0.05);
  overflow: hidden;
  will-change: transform;
}

/* RTL Support - Left-to-Right positioning for LTR languages */
[dir="ltr"] .modern-sidebar {
  right: auto;
  left: 0;
  box-shadow: 5px 0 25px rgba(0, 0, 0, 0.2);
  border-left: none;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

/* Sidebar Header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  position: relative;
  z-index: 2;
  background: rgba(17, 24, 39, 0.5); /* Semi-transparent */
  backdrop-filter: blur(10px);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.25rem;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.brand-text {
  color: #f3f4f6;
  font-weight: 700;
  font-size: 1.2rem;
  margin: 0;
  letter-spacing: 0.5px;
}

.sidebar-collapse-btn {
  background: rgba(255, 255, 255, 0.05);
  border: none;
  color: #9ca3af;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  cursor: pointer;
}

.sidebar-collapse-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #f3f4f6;
}

/* Navigation */
.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Custom Scrollbar */
.sidebar-nav::-webkit-scrollbar {
  width: 5px;
}
.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-item {
  margin-bottom: 0.25rem;
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  color: #9ca3af; /* Muted text color */
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  font-weight: 500;
  font-size: 0.95rem;
  gap: 0.75rem;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #f3f4f6;
  padding-right: 1.25rem; /* Slight shift on hover (RTL) */
}

[dir="ltr"] .nav-link:hover {
  padding-right: 1rem;
  padding-left: 1.25rem; /* Slight shift on hover (LTR) */
}

.nav-link.active {
  background: rgba(37, 99, 235, 0.15);
  color: #60a5fa; /* Light blue text */
}

/* Side border indicator for active state */
.nav-link.active::before {
  content: "";
  position: absolute;
  right: 0; /* RTL default */
  top: 4px;
  bottom: 4px;
  width: 4px;
  background: #3b82f6;
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.5); /* Glow effect */
}

[dir="ltr"] .nav-link.active::before {
  right: auto;
  left: 0;
}

.nav-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  background: rgba(255, 255, 255, 0.03);
}

.nav-link:hover .nav-icon {
  background: rgba(255, 255, 255, 0.08);
}

.nav-link.active .nav-icon {
  background: #3b82f6;
  color: white;
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
}

.nav-icon i {
  font-size: 1rem;
}

.nav-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 0.2s ease;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(17, 24, 39, 0.5);
  backdrop-filter: blur(5px);
}

.logout-link {
  color: #ef4444 !important; /* Red text */
}

.logout-link:hover {
  background: rgba(239, 68, 68, 0.1) !important;
  color: #fca5a5 !important;
}

.logout-link .nav-icon {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.logout-link:hover .nav-icon {
  background: #ef4444;
  color: white;
}

/* Collapsed State */
.modern-sidebar.collapsed {
  width: 80px;
}

.modern-sidebar.collapsed .brand-text,
.modern-sidebar.collapsed .nav-text {
  opacity: 0;
  visibility: hidden;
  position: absolute;
  left: -9999px;
}

.modern-sidebar.collapsed .nav-link {
  justify-content: center;
  padding: 0.75rem;
}

.modern-sidebar.collapsed .nav-icon {
  width: 42px;
  height: 42px;
  font-size: 1.2rem;
}

/* Tooltip on collapsed hover (handled by JS via title attribute, but we can animate) */

.modern-sidebar.collapsed .sidebar-collapse-btn i {
  transform: rotate(180deg);
}
[dir="rtl"] .modern-sidebar.collapsed .sidebar-collapse-btn i {
  transform: rotate(0deg); /* Adjust for RTL */
}

/* Hover to expand logic (optional, user might prefer click only) 
   We keep it simple: click to toggle, hover doesn't expand entire sidebar 
   to avoid jarring layout shifts. */

/* Mobile Responsiveness */
@media (max-width: 991.98px) {
  .modern-sidebar {
    transform: translateX(100%); /* Hidden (RTL) */
    width: 280px; /* Always full width on mobile when shown */
    right: 0;
    left: auto;
  }

  [dir="ltr"] .modern-sidebar {
    transform: translateX(-100%); /* Hidden (LTR) */
    left: 0;
    right: auto;
  }

  .modern-sidebar.show {
    transform: translateX(0) !important;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5); /* Stronger shadow on mobile */
  }

  /* Sidebar Overlay */
  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1025; /* Just below sidebar */
    display: none;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease;
  }

  .sidebar-overlay.show {
    display: block;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Content Wrapper Adjustments */
.main-wrapper {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 100vh;
  background: #f3f4f6; /* Light gray background for content */
}

@media (min-width: 992px) {
  .logged-in .main-wrapper {
    margin-right: 280px; /* RTL default */
  }

  [dir="ltr"] .logged-in .main-wrapper {
    margin-right: 0;
    margin-left: 280px;
  }

  .logged-in .main-wrapper.sidebar-collapsed {
    margin-right: 80px; /* RTL default */
  }

  [dir="ltr"] .logged-in .main-wrapper.sidebar-collapsed {
    margin-right: 0;
    margin-left: 80px;
  }
}
