/**
 * Universal Sidebar Styles
 * Consistent sidebar styling across all pages
 */

.main-sidebar {
  position: fixed;
  top: 0;
  left: -100%;
  width: 280px;
  height: 100vh;
  z-index: 1006; /* Higher z-index to ensure visibility above overlay */
  background: #f8fafc;
  border-right: 1px solid #e5e7eb;
  overflow-y: auto;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding-top: 20px; /* Reduced padding for better visibility */
  display: block; /* Ensure it's always block when needed */
  visibility: visible; /* Force visibility */
}

.main-sidebar.active {
  left: 0 !important; /* Force left position when active */
  transform: translateX(0) !important;
  box-shadow: 2px 0 20px rgba(0, 0, 0, 0.15);
  visibility: visible !important;
  display: block !important;
}

.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 1005; /* Below sidebar but above other content */
  pointer-events: none; /* Prevent interaction when not active */
  display: block; /* Always present in DOM */
}

.sidebar-overlay.active {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important; /* Allow interaction when active */
  display: block !important;
}

.sidebar-header {
  display: flex;
  justify-content: flex-end;
  padding: 1rem;
  border-bottom: 1px solid #e5e7eb;
  background: #ffffff;
  position: sticky;
  top: 0;
  z-index: 1004; /* Above sidebar content */
}

.sidebar-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px; /* Larger tap target */
  height: 48px;
  background-color: #ffffff;
  border: 2px solid #3b82f6;
  color: #3b82f6;
  font-weight: bold;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sidebar-close:hover,
.sidebar-close:active {
  background-color: #3b82f6;
  color: #ffffff;
  transform: scale(0.95);
}

.sidebar-nav {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-nav li {
  border-bottom: 1px solid #f3f4f6;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  color: #374151;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s ease;
  border-left: 4px solid transparent;
  min-height: 48px; /* Larger tap target */
}

.sidebar-nav a:hover,
.sidebar-nav a:active {
  background-color: #f8fafc;
  padding-left: 2rem;
  color: #3b82f6;
}

.sidebar-nav a[aria-current="page"] {
  background-color: #eff6ff;
  color: #3b82f6;
  border-left-color: #3b82f6;
}

.sidebar-nav a i {
  font-size: 1.125rem;
  width: 24px;
  text-align: center;
}

body.sidebar-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

@media (min-width: 769px) and (max-width: 1024px) {
  .main-sidebar {
    width: 320px; /* Wider for tablets */
  }
}

@media (min-width: 769px) {
  .mobile-menu-toggle,
  button.mobile-menu-toggle,
  .mobile-menu-toggle[data-sidebar-setup],
  button[aria-label="Toggle mobile menu"],
  nav .mobile-menu-toggle,
  header .mobile-menu-toggle,
  .site-header .mobile-menu-toggle {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
  }
  .main-sidebar {
    display: none !important;
  }
  .sidebar-overlay {
    display: none !important;
  }
}

@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex !important;
    position: relative;
    z-index: 1007 !important;
  }
  .main-sidebar {
    display: block !important;
  }
  .sidebar-overlay {
    display: block !important;
  }
  .sidebar-nav a {
    font-size: 1rem;
    padding: 1.25rem 1.5rem;
  }
  .sidebar-nav a i {
    font-size: 1.25rem;
    width: 24px;
  }
  
  /* Ensure sidebar is always above other content on mobile */
  .main-sidebar.active {
    display: block !important;
    left: 0 !important;
  }
}

@media (hover: none) and (pointer: coarse) {
  .sidebar-close {
    min-height: 48px;
    min-width: 48px;
    touch-action: manipulation;
  }
  .sidebar-nav a {
    min-height: 48px;
    padding: 1.25rem 1.5rem;
    touch-action: manipulation;
  }
}

.sidebar-close:focus,
.sidebar-nav a:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 1003 !important;
}

.main-nav {
  position: relative;
  z-index: 1004 !important;
}

.mobile-menu-toggle {
  display: none;
  flex-direction: column;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s ease;
  z-index: 1004 !important;
  width: 48px; /* Larger tap target */
  height: 48px;
}

.mobile-menu-toggle:hover {
  background-color: #f3f4f6;
}

.mobile-menu-toggle span {
  width: 30px; /* Slightly larger for visibility */
  height: 4px;
  background-color: #374151;
  margin: 3px 0;
  transition: 0.3s;
  border-radius: 2px;
}

.hero {
  z-index: 1 !important;
  position: relative;
}

.mobile-menu-toggle:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.welcome-popup {
  z-index: 10002;
}

/* Hide any conflicting mobile menu overlays to prevent interference */
.mobile-menu-overlay {
  display: none !important;
}