/**
 * Dropdown Menu Styles with Bug Fixes
 * Enhanced styles for the user dropdown menu in the navigation bar
 * with fixes for edge cases and mobile responsiveness
 */

/* User Dropdown Menu */
.nav-user-menu {
  position: relative;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-greeting {
  color: var(--white, #ffffff);
  font-size: 0.9rem;
  display: block;
  margin-right: 0.5rem;
}

.user-dropdown {
  position: relative;
}

.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 50px;
  padding: 0.4rem;
  color: var(--white, #ffffff);
  cursor: pointer;
  transition: background-color 0.2s;
}

.user-menu-btn:hover, 
.user-menu-btn:focus {
  background: rgba(255, 255, 255, 0.2);
  outline: none;
}

/* High contrast focus styles for accessibility */
.user-menu-btn:focus-visible {
  outline: 2px solid var(--white, #ffffff);
  outline-offset: 2px;
}

.user-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  background: var(--royal-blue, #1e56a0);
  color: var(--white, #ffffff);
  border-radius: 50%;
  font-weight: bold;
  font-size: 0.9rem;
}

.dropdown-content {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  min-width: 200px;
  background: var(--white, #ffffff);
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  transform-origin: top right;
  max-height: calc(100vh - 100px);
  overflow-y: auto; /* Allow scrolling for many items */
}

.dropdown-content.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  animation-name: dropdownFadeIn;
  animation-duration: 0.2s;
  animation-fill-mode: both;
}

.dropdown-content a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--text-dark, #2d3748);
  text-decoration: none;
  transition: background-color 0.2s;
}

.dropdown-content a:hover,
.dropdown-content a:focus {
  background-color: var(--light-blue, #e6f2ff);
  outline: none;
}

/* High contrast focus styles for accessibility */
.dropdown-content a:focus-visible {
  outline: 2px solid var(--royal-blue, #1e56a0);
  outline-offset: -2px;
}

.dropdown-content a i {
  width: 1.25rem;
  text-align: center;
  color: var(--royal-blue, #1e56a0);
}

.dropdown-divider {
  height: 1px;
  background-color: var(--medium-gray, #e2e8f0);
  margin: 0.5rem 0;
}

/* Animation keyframes */
@keyframes dropdownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Role-based visibility */
.hidden {
  display: none !important;
}

/* Use data attributes for role-based display */
.admin-only {
  display: none;
}

body[data-role="admin"] .admin-only {
  display: flex;
}

/* Screen reader only class */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Overlay for mobile dropdown */
.dropdown-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 999;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Dark theme adjustments */
.dark-theme .dropdown-content {
  background: var(--navy-blue, #0a2463);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.dark-theme .dropdown-content a {
  color: var(--text-light, #e2e8f0);
}

.dark-theme .dropdown-content a:hover,
.dark-theme .dropdown-content a:focus {
  background-color: rgba(255, 255, 255, 0.1);
}

/* High contrast focus styles for dark theme */
.dark-theme .dropdown-content a:focus-visible {
  outline: 2px solid var(--accent-orange, #ff6b35);
  outline-offset: -2px;
}

.dark-theme .dropdown-content a i {
  color: var(--accent-orange, #ff6b35);
}

.dark-theme .dropdown-divider {
  background-color: rgba(255, 255, 255, 0.1);
}

.dark-theme .user-initials {
  background: var(--accent-orange, #ff6b35);
}

.dark-theme .user-menu-btn:focus-visible {
  outline: 2px solid var(--accent-orange, #ff6b35);
  outline-offset: 2px;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .user-greeting {
    display: none;
  }
  
  .dropdown-content.mobile {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    border-radius: 12px 12px 0 0;
    transform: translateY(100%);
    max-height: 80vh; /* Limit height on mobile */
  }
  
  .dropdown-content.mobile.show {
    transform: translateY(0);
    animation-name: dropdownSlideUp;
  }
  
  .dropdown-content.mobile a {
    padding: 1rem;
    /* Larger touch targets for mobile */
    min-height: 3rem;
  }
  
  @keyframes dropdownSlideUp {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }
}

/* Fix for iOS Safari issues */
@supports (-webkit-touch-callout: none) {
  .dropdown-content {
    /* Fix for iOS Safari scrolling issues */
    -webkit-overflow-scrolling: touch;
  }
  
  /* Fix for iOS Safari focus issues */
  .user-menu-btn:focus,
  .dropdown-content a:focus {
    outline: none;
  }
}

/* Fix for Firefox focus ring */
@-moz-document url-prefix() {
  .user-menu-btn:focus-visible,
  .dropdown-content a:focus-visible {
    outline-style: dotted;
    outline-width: 2px;
  }
}

/* Fix for Edge browser */
@supports (-ms-ime-align: auto) {
  .dropdown-content {
    /* Edge doesn't support overflow-y with visibility: hidden */
    display: none;
  }
  
  .dropdown-content.show {
    display: block;
  }
}

/* Fix for older browsers that don't support CSS variables */
@supports not (--custom: property) {
  .user-greeting {
    color: #ffffff;
  }
  
  .user-menu-btn {
    color: #ffffff;
  }
  
  .user-initials {
    background: #1e56a0;
    color: #ffffff;
  }
  
  .dropdown-content {
    background: #ffffff;
  }
  
  .dropdown-content a {
    color: #2d3748;
  }
  
  .dropdown-content a:hover,
  .dropdown-content a:focus {
    background-color: #e6f2ff;
  }
  
  .dropdown-content a i {
    color: #1e56a0;
  }
  
  .dropdown-divider {
    background-color: #e2e8f0;
  }
  
  .dark-theme .dropdown-content {
    background: #0a2463;
  }
  
  .dark-theme .dropdown-content a {
    color: #e2e8f0;
  }
  
  .dark-theme .dropdown-content a i {
    color: #ff6b35;
  }
  
  .dark-theme .user-initials {
    background: #ff6b35;
  }
}

/* Print styles - hide dropdown when printing */
@media print {
  .nav-user-menu {
    display: none !important;
  }
}
