/* ========== SIDEBAR NAVIGATION STYLES ========== */

/* Main content adjustment for always-visible sidebar */
body {
  transition: margin-left 0.3s ease;
}

@media (min-width: 1024px) {
  body {
    margin-left: 280px;
  }

  body.sidebar-hidden {
    margin-left: 0;
  }
}

/* Menu Toggle Buttons */
.menu-toggle {
  width: 45px;
  height: 45px;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* Floating toggle button (appears when sidebar is hidden) */
.floating-toggle {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 1002;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.8);
  transition: all 0.3s ease;
}

/* Show floating toggle when sidebar is hidden on desktop */
body.sidebar-hidden .floating-toggle {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
}

/* Sidebar toggle button (inside the sidebar header) */
.sidebar-toggle {
  width: 35px;
  height: 35px;
  background: transparent;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  opacity: 1;
  visibility: visible;
  transition: all 0.3s ease;
}

/* Hide sidebar toggle when sidebar is hidden on desktop */
body.sidebar-hidden .sidebar-toggle {
  opacity: 0;
  visibility: hidden;
}

.menu-toggle:hover {
  background: #e9ecef;
  transform: scale(1.05);
}

.sidebar-toggle:hover {
  background: rgba(0,0,0,0.05);
}

.hamburger-line {
  width: 20px;
  height: 2px;
  background: #495057;
  transition: all 0.3s ease;
  border-radius: 1px;
}

.sidebar-toggle .hamburger-line {
  width: 16px;
}

.menu-toggle.active .hamburger-line:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active .hamburger-line:nth-child(2) {
  opacity: 0;
}

.menu-toggle.active .hamburger-line:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -6px);
}

/* Sidebar Navigation - Always visible by default */
.sidebar-nav {
  position: fixed;
  top: 0;
  left: 0; /* Always visible */
  width: 280px;
  height: 100vh;
  background: #ffffff;
  border-right: 1px solid #dee2e6;
  z-index: 1000;
  transition: left 0.3s ease;
  overflow-y: auto;
  box-shadow: 2px 0 15px rgba(0,0,0,0.05);
}

/* Hidden state when user clicks to hide */
.sidebar-nav.hidden {
  left: -280px;
}

/* Logo area above the menu */
.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid #dee2e6;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8f9fa;
}

.sidebar-logo {
  display: flex;
  align-items: center;
}

.sidebar-logo .logo-link {
  display: inline-block;
  text-decoration: none;
  transition: opacity 0.3s ease;
}

.sidebar-logo .logo-link:hover {
  opacity: 0.8;
}

.sidebar-logo img {
  display: block;
  max-width: 120px;
  height: auto;
  transition: transform 0.3s ease;
}

.sidebar-logo .logo-link:hover img {
  transform: scale(1.02);
}

.close-btn {
  background: none;
  border: none;
  color: #495057;
  font-size: 24px;
  cursor: pointer;
  padding: 5px;
  border-radius: 4px;
  transition: background 0.3s ease;
}

.close-btn:hover {
  background: rgba(0,0,0,0.1);
}

/* Sidebar Content */
.sidebar-content {
  padding: 0;
}

.nav-section {
  /* padding: 10px 0; */
}

/* Navigation Items */
.nav-item {
  /* margin: 2px 0; */
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 7px 20px;
  color: #495057;
  text-decoration: none;
  transition: all 0.3s ease;
  cursor: pointer;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  background: #f8f9fa;
  border-left-color: #007bff;
  color: #212529;
}

.active-single-link {
  background: #f8f9fa;
  border-left-color: #007bff;
  color: #212529;
}

.nav-link.active {
  background: #e3f2fd;
  border-left-color: #007bff;
  color: #0056b3;
}

/* Navigation Text */
.nav-text {
  flex: 1;
  font-weight: 300;
}

.nav-arrow {
  width: 16px;
  height: 16px;
  font-size: 12px;
  color: #6c757d;
  transition: transform 0.3s ease;
  margin-right: 12px; /* Increased spacing from text */
  order: -1; /* Move arrow to the beginning */
}

.nav-arrow.rotated {
  transform: rotate(180deg);
}

/* Submenu arrow styling */
.submenu-arrow {
  width: 14px;
  height: 14px;
  font-size: 10px;
  color: #6c757d;
  transition: transform 0.3s ease;
  margin-right: 10px; /* Good spacing from text */
  order: -1; /* Move arrow to the beginning */
}

.submenu-arrow.rotated {
  transform: rotate(180deg);
}

/* Submenu Styles - FORCE INITIAL COLLAPSED STATE */
.submenu {
  max-height: 0 !important;
  overflow: hidden !important;
  background: #f8f9fa;
  transition: max-height 0.3s ease;
  border-left: 3px solid #dee2e6;
  visibility: hidden;
  opacity: 0;
}

.submenu.active {
  max-height: 2000px !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.submenu-link {
  display: block;
  padding: 7px 20px 7px 45px; /* Reduced left padding since no icons */
  color: #6c757d;
  text-decoration: none;
  transition: all 0.3s ease;
  border-left: 2px solid transparent;
}

.submenu-link:hover {
  background: #ffffff;
  color: #495057;
  border-left-color: #007bff;
}

.submenu-link.active {
  background: #ffffff;
  color: #0056b3;
  border-left-color: #007bff;
  font-weight: 500;
}

/* Ensure all submenus are collapsed by default */
.submenu:not(.active) {
  max-height: 0 !important;
  opacity: 0;
  pointer-events: none;
}

.submenu.active {
  opacity: 1;
  pointer-events: auto;
}

/* Also ensure arrows are in default state */
.nav-arrow:not(.rotated),
.submenu-arrow:not(.rotated) {
  transform: rotate(0deg);
}

/* Level-specific styles for nested submenus */
.nav-item.level-1 {
  padding-left: 20px;
}

/* Nested submenu styling */
.submenu .submenu {
  background: #f1f3f4;
  border-left: 2px solid #dee2e6;
  margin-left: 10px;
}

.submenu .submenu .submenu {
  background: #e9ecef;
  border-left: 2px solid #ced4da;
}

/* Ensure nav-link in nested submenus has proper display */
.submenu .nav-link {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  color: #6c757d;
  text-decoration: none;
  transition: all 0.3s ease;
}

.submenu .nav-link:hover {
  background: #ffffff;
  color: #495057;
}

/* Overlay */
.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.3);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* ========== RESPONSIVE DESIGN ========== */

/* Desktop */
@media (min-width: 1024px) {
  .sidebar-nav {
    width: 280px;
    left: 0; /* Always visible on desktop */
  }

  /* Hide floating toggle on desktop when sidebar is visible */
  .floating-toggle {
    display: none;
  }

  /* Show floating toggle on desktop only when sidebar is hidden */
  body.sidebar-hidden .floating-toggle {
    display: flex;
    opacity: 1;
    visibility: visible;
    transform: scale(1);
  }

  /* Hide sidebar toggle when sidebar is hidden on desktop */
  body.sidebar-hidden .sidebar-toggle {
    display: none;
  }

  /* Remove the body margin-left here as it's handled globally above */
}

/* Tablet */
@media (max-width: 1023px) and (min-width: 768px) {
  body {
    margin-left: 0 !important; /* Override global margin */
  }

  .sidebar-nav {
    width: 280px;
    left: -280px; /* Hidden by default on tablet */
  }

  .sidebar-nav.active {
    left: 0;
  }

  /* Show floating toggle when sidebar is not active */
  .floating-toggle {
    display: flex;
    opacity: 1;
    visibility: visible;
    transform: scale(1);
  }

  /* Hide floating toggle when sidebar is active */
  .sidebar-nav.active ~ .floating-toggle {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.8);
  }

  /* Sidebar toggle is always visible in the sidebar header */
  .sidebar-toggle {
    display: flex;
    opacity: 1;
    visibility: visible;
  }

  .sidebar-logo img {
    max-width: 100px;
  }
}

/* Mobile */
@media (max-width: 767px) {
  body {
    margin-left: 0 !important; /* Override global margin */
  }

  .sidebar-nav {
    width: 100%;
    left: -100%; /* Hidden by default on mobile */
  }

  .sidebar-nav.active {
    left: 0;
  }

  .menu-toggle {
    top: 15px;
    left: 15px;
    width: 40px;
    height: 40px;
  }

  .hamburger-line {
    width: 18px;
  }

  /* Show floating toggle when sidebar is not active */
  .floating-toggle {
    display: flex;
    opacity: 1;
    visibility: visible;
    transform: scale(1);
  }

  /* Hide floating toggle when sidebar is active */
  .sidebar-nav.active ~ .floating-toggle {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.8);
  }

  /* Sidebar toggle is always visible in the sidebar header */
  .sidebar-toggle {
    display: flex;
    opacity: 1;
    visibility: visible;
  }

  .sidebar-header {
    padding: 15px;
  }

  .sidebar-logo img {
    max-width: 80px;
  }

  .nav-link {
    padding: 15px 20px;
  }

  .nav-text {
    font-size: 16px;
  }
}

/* Small Mobile */
@media (max-width: 480px) {
  .sidebar-nav {
    width: 100%;
  }

  .nav-link {
    padding: 18px 20px;
  }

  .sidebar-logo img {
    max-width: 70px;
  }
}

/* ========== NEW MENU DESIGN WITH SEPARATE LINKS AND TOGGLES ========== */

/* Container for nav items with both links and toggle buttons */
.nav-link-container {
  display: flex;
  align-items: center;
  width: 100%;
  background: transparent;
  border-radius: 8px;
  transition: background-color 0.2s ease;
}

.nav-link-container:hover {
  background: rgba(0,0,0,0.03);
}

/* Main link text (clickable for navigation) */
.nav-link-text {
  flex: 1;
  text-decoration: none;
  color: #495057;
  padding: 7px 15px;
  transition: color 0.2s ease;
  border-radius: 6px 0 0 6px;
}

.nav-link-text:hover {
  color: #007bff;
  text-decoration: none;
}

.nav-link-text:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

.nav-link.active-text {
  color: #007bff;
  border-left: 3px solid #007bff;

  flex: 1;
  text-decoration: none;
  padding: 12px 15px;
  transition: color 0.2s ease;
}

/* Toggle button for expanding/collapsing submenus */
.nav-toggle-btn {
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0 6px 6px 0;
  transition: all 0.2s ease;
}


/* Arrow icons in toggle buttons */
.nav-toggle-btn .nav-arrow,
.nav-toggle-btn .submenu-arrow {
  font-size: 12px;
  transition: transform 0.3s ease;
}

/* Rotate arrow when submenu is expanded */
.nav-item.expanded > .nav-link-container .nav-toggle-btn .nav-arrow,
.nav-item.expanded > .nav-link-container .nav-toggle-btn .submenu-arrow {
  transform: rotate(180deg);
}

/* Active state for nav items with expanded submenus */
.nav-item.expanded > .nav-link-container {
  background: rgba(0, 123, 255, 0.05);
  border-radius: 8px;
}

.nav-item.expanded > .nav-link-container .nav-link-text {
  color: #007bff;
  font-weight: 500;
}

.nav-item.expanded > .nav-link-container .nav-toggle-btn {
  color: #007bff;
}

/* Smooth transition for all nav elements */
.nav-link-text,
.nav-toggle-btn {
  transition: all 0.2s ease;
}

/* Better focus states for accessibility */
.nav-link-text:focus,
.nav-toggle-btn:focus {
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* Ensure proper spacing and alignment */
.nav-link-container {
  min-height: 44px; /* Minimum touch target size */
}

.nav-link-text .nav-text {
  display: block;
  line-height: 1.4;
}

/* ========== ANIMATIONS ========== */
@keyframes slideInLeft {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}

.sidebar-nav.active {
  animation: slideInLeft 0.3s ease;
}

/* ========== ACCESSIBILITY ========== */
.menu-toggle:focus,
.nav-link:focus,
.submenu-link:focus,
.close-btn:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .sidebar-nav,
  .menu-toggle,
  .nav-link,
  .submenu,
  .sidebar-overlay,
  .nav-arrow {
    transition: none;
  }
}
