/**
 * Header Component Styles
 * MyTidyHome
 */

.header {
  background-color: var(--bg-primary);
  border-bottom: var(--border-width) solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  box-shadow: var(--shadow-sm);
  overflow-x: hidden; /* Prevent horizontal scrolling */
  overflow-y: visible; /* Allow dropdowns to overflow vertically */
}

.header__container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--spacing-6);
  min-height: 64px;
  position: relative;
  overflow-x: hidden; /* Prevent horizontal scrolling */
  overflow-y: visible; /* Allow dropdowns to overflow vertically */
  max-width: 100%; /* Ensure container doesn't exceed viewport */
  box-sizing: border-box; /* Include padding in width calculation */
}

.header__brand {
  display: flex;
  align-items: center;
}

.header__logo-link {
  display: flex;
  align-items: center;
  gap: var(--spacing-3);
  text-decoration: none;
  color: var(--text-primary);
  transition: opacity var(--transition-fast);
}

.header__logo-link:hover {
  opacity: 0.8;
}

.header__logo {
  width: 40px;
  height: 40px;
  display: block;
}

.header__brand-name {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
}

/* Mobile: Smaller brand name to save space */
@media (max-width: 767px) {
  .header__brand-name {
    font-size: var(--font-size-base);
  }
}

.header__burger {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  z-index: var(--z-dropdown);
}

/* Mobile profile switcher removed - we use desktop profile switcher for both */

.header__burger-line {
  width: 100%;
  height: 3px;
  background-color: var(--text-primary);
  border-radius: var(--border-radius-full);
  transition: all var(--transition-base);
  transform-origin: center;
}

.header__burger.active .header__burger-line:nth-child(1) {
  transform: rotate(45deg) translate(8px, 8px);
}

.header__burger.active .header__burger-line:nth-child(2) {
  opacity: 0;
}

.header__burger.active .header__burger-line:nth-child(3) {
  transform: rotate(-45deg) translate(8px, -8px);
}

.header__nav {
  display: none;
}

.header__nav.active {
  display: block;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background-color: var(--bg-primary);
  border-top: var(--border-width) solid var(--border-color);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  padding: var(--spacing-4);
  max-width: 100%; /* Prevent nav from exceeding container */
  box-sizing: border-box; /* Include padding in width calculation */
  overflow-x: visible; /* Allow dropdowns to overflow horizontally */
  overflow-y: visible; /* Allow dropdowns to overflow vertically */
  max-height: none; /* No max-height restriction */
}

/* Nav menu is visible on mobile when logged in (contains profile switcher) */
/* No need to hide it - we use the same nav for both logged in and logged out */

.header__nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-2);
}

.header__nav-item {
  margin: 0;
}

.header__nav-link {
  display: block;
  padding: var(--spacing-2) var(--spacing-4);
  color: var(--text-primary);
  text-decoration: none;
  border-radius: var(--border-radius-md);
  transition: background-color var(--transition-fast);
  font-weight: var(--font-weight-medium);
}

.header__nav-link:hover {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

.header__nav-link--primary {
  background-color: var(--color-primary);
  color: var(--text-inverse);
}

.header__nav-link--primary:hover {
  background-color: var(--color-primary-dark);
  color: var(--text-inverse);
}

/* Desktop Styles */
@media (min-width: 768px) {
  .header__burger {
    display: none !important;
  }
  
  /* Ensure burger is hidden on desktop even if JavaScript sets it */
  .header__burger[style*="display: flex"] {
    display: none !important;
  }
  
  /* Mobile profile switcher removed - we use desktop profile switcher for both */
  
  .header__nav {
    display: block !important;
    position: static !important; /* Override mobile fixed positioning on desktop */
    background: transparent;
    border: none;
    box-shadow: none;
    top: auto !important; /* Reset mobile positioning */
    bottom: auto !important; /* Reset mobile positioning */
    left: auto !important; /* Reset mobile positioning */
    right: auto !important; /* Reset mobile positioning */
  }
  
  /* Ensure active state doesn't override desktop positioning */
  .header__nav.active {
    position: static !important; /* Override mobile fixed positioning on desktop */
    top: auto !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
  }
  
  /* Override logged-in hiding on desktop - nav must be visible for desktop profile */
  .header__nav--logged-in {
    display: block !important;
  }
  
  .header__nav-list {
    flex-direction: row;
    align-items: center;
    gap: var(--spacing-2);
  }
  
  .header__nav-link {
    white-space: nowrap;
  }
  
  .header__nav-item--language {
    margin-left: var(--spacing-2);
  }
  
  .header__nav-item--profile {
    margin-left: auto;
  }
}

/* Language Switcher Styles */
.header__language-switcher {
  position: relative;
  display: inline-block;
}

.header__language-btn {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  padding: var(--spacing-2) var(--spacing-4);
  background-color: transparent;
  border: none;
  border-radius: var(--border-radius-md);
  color: var(--text-primary);
  cursor: pointer;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  font-family: var(--font-primary);
  transition: background-color var(--transition-fast);
}

.header__language-btn:hover {
  background-color: var(--bg-secondary);
}

.header__language-btn[aria-expanded="true"] {
  background-color: var(--bg-secondary);
}

.header__language-icon {
  font-size: var(--font-size-lg);
  line-height: 1;
}

.header__language-text {
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-base);
  font-family: var(--font-primary);
  min-width: 32px;
  text-align: center;
}

.header__language-arrow {
  display: none;
}

.header__language-dropdown {
  position: absolute;
  top: calc(100% + var(--spacing-2));
  right: 0;
  min-width: 140px;
  background-color: var(--bg-primary);
  border: none;
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-lg);
  list-style: none;
  margin: 0;
  padding: var(--spacing-2);
  display: none;
  z-index: calc(var(--z-sticky) + 10);
}

.header__language-dropdown.active {
  display: block;
}

.header__language-item {
  margin: 0;
  margin-bottom: var(--spacing-1);
}

.header__language-item:last-child {
  margin-bottom: 0;
}

.header__language-option {
  width: 100%;
  padding: var(--spacing-2) var(--spacing-3);
  background: transparent;
  border: none;
  text-align: left;
  color: var(--text-primary);
  cursor: pointer;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  font-family: var(--font-primary);
  border-radius: var(--border-radius-sm);
  transition: background-color var(--transition-fast);
  display: flex;
  align-items: center;
}

.header__language-option:hover {
  background-color: var(--bg-secondary);
}

.header__language-option.active {
  background-color: var(--color-primary);
  color: var(--text-inverse);
  font-weight: var(--font-weight-medium);
}

/* Mobile adjustments for language switcher */
@media (max-width: 767px) {
  .header__language-dropdown {
    right: auto;
    left: 0;
  }
}

/* Profile Switcher */
.header__profile-switcher {
  position: relative;
  /* Dropdown is positioned fixed, so no overflow issues */
}

.header__profile-btn {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  padding: 0; /* No padding to maintain equal spacing from screen edges */
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: var(--border-radius-md);
  transition: background-color var(--transition-fast);
  color: var(--text-primary);
  font-family: inherit;
  min-width: 0; /* Allow flex-shrink to work properly */
  flex-shrink: 1; /* Allow button to shrink when needed */
}

.header__profile-btn:hover {
  background-color: var(--bg-secondary);
}

.header__profile-btn[aria-expanded="true"] {
  background-color: var(--bg-secondary);
}

.header__profile-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  order: 1;
  min-width: 0; /* Allow flex-shrink to work properly */
  flex-shrink: 1; /* Allow info to shrink when needed */
  max-width: 100%; /* Prevent overflow */
}

.header__profile-greeting {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-normal);
  color: var(--text-secondary);
  line-height: 1.2;
}

.header__profile-name {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  white-space: nowrap;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  min-width: 0; /* Ensure ellipsis works in flex container */
}

.header__profile-picture,
.header__profile-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border-color);
  flex-shrink: 0;
  order: 2;
}

.header__profile-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-secondary);
}

.header__profile-icon {
  font-size: 1.5rem;
  opacity: 0.6;
}

.header__profile-dropdown {
  position: fixed;
  min-width: 180px;
  background-color: var(--bg-primary);
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-lg);
  list-style: none;
  margin: 0;
  padding: var(--spacing-2);
  display: none;
  z-index: calc(var(--z-sticky) + 10);
  /* Position will be calculated by JavaScript */
}

.header__profile-dropdown.active {
  display: block;
}

.header__profile-item {
  margin: 0;
  margin-bottom: var(--spacing-1);
}

.header__profile-item:last-child {
  margin-bottom: 0;
}

.header__profile-option {
  width: 100%;
  padding: var(--spacing-2) var(--spacing-3);
  background: transparent;
  border: none;
  text-align: left;
  color: var(--text-primary);
  cursor: pointer;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  font-family: var(--font-primary);
  border-radius: var(--border-radius-sm);
  transition: background-color var(--transition-fast);
  display: block;
  text-decoration: none;
}

.header__profile-option:hover {
  background-color: var(--bg-secondary);
}

/* Mobile adjustments for profile switcher */
@media (max-width: 767px) {
  /* Profile dropdown adjustments for mobile */
  /* Position is calculated by JavaScript, no CSS changes needed */
  
  /* Profile info (greeting + name) should be visible on mobile */
  /* Keep right alignment on mobile (same as desktop) */
  .header__profile-info {
    align-items: flex-end; /* Right-aligned like desktop */
    gap: 0.125rem; /* Small gap between greeting and name */
    max-width: 100px; /* Match profile name max-width to prevent overflow */
  }
  
  /* Profile button padding is unified - no mobile-specific changes needed */
  
  /* Adjust profile picture size for mobile */
  .header__profile-picture,
  .header__profile-placeholder {
    width: 32px;
    height: 32px;
    border-width: 1px; /* Thinner border on mobile */
  }
  
  /* Adjust profile name max-width for mobile (smaller screens need less space) */
  .header__profile-name {
    max-width: 100px; /* Reduced from 120px to prevent overflow */
  }
  
  /* Ensure profile info doesn't overflow on mobile */
  .header__profile-info {
    max-width: 100px; /* Match profile name max-width */
  }
  
  /* Ensure profile button doesn't overflow container */
  .header__profile-btn {
    max-width: 100%; /* Prevent button from exceeding container */
  }
  
  /* Hide desktop profile button on mobile (we use the same button for both) */
  .header__profile-btn--desktop {
    display: none;
  }
}

/* Desktop: Hide mobile profile switcher and mobile profile menu items */
@media (min-width: 768px) {
  .header__profile-switcher--mobile {
    display: none !important;
  }
  
  .header__nav-item--profile-mobile {
    display: none !important;
  }
  
  /* Show desktop profile button on desktop */
  .header__profile-btn--desktop {
    display: flex;
  }
  
  /* Ensure desktop profile item is visible ONLY when logged in */
  /* JavaScript will set display: '' when logged in, which will make it visible */
  /* When logged out, JavaScript sets display: 'none', which should override this */
  .header__nav-item--profile[style*="display: none"] {
    display: none !important;
  }
}

/* Mobile Styles */
@media (max-width: 767px) {
  /* Show burger menu by default on mobile (when not logged in) */
  /* NO !important here - JavaScript will control it */
  .header__burger {
    display: flex;
  }
  
  /* Hide burger when logged in (JavaScript sets display: none with important) */
  .header__burger[style*="display: none"] {
    display: none !important;
  }
  
  /* Nav menu: Show when burger is active (clicked) OR when logged in */
  /* When logged in, nav should be visible to show profile switcher */
  .header__nav {
    display: none; /* Hidden by default, shown when burger is active */
    max-height: none; /* No height restriction */
    overflow-y: visible; /* Allow dropdowns to overflow */
  }
  
  .header__nav.active {
    display: block; /* Show when burger is clicked (logged out) */
    position: fixed; /* Overlay entire viewport, not just header */
    top: 64px; /* Start below header (min-height: 64px) */
    left: 0;
    right: 0;
    bottom: 0; /* Extend to bottom of viewport */
    max-height: none; /* No height restriction */
    overflow-y: auto; /* Allow scrolling if content is too long */
    overflow-x: visible; /* Allow dropdowns to overflow horizontally */
    z-index: calc(var(--z-sticky) + 5); /* Above header, below modals */
  }
  
  /* When logged in, nav should be visible (contains profile switcher) */
  /* JavaScript sets nav.style.display = '' when logged in */
  .header__nav[style*="display:"]:not([style*="display: none"]) {
    display: block !important;
    max-height: none !important; /* No height restriction */
    overflow-y: visible !important; /* Allow dropdowns to overflow */
  }
  
  /* Hide mobile profile menu items (we use dropdown instead) */
  .header__nav-item--profile-mobile {
    display: none !important;
  }
  
  /* Profile item is visible on mobile when logged in (same as desktop) */
  /* JavaScript sets display: '' when logged in, which makes it visible */
  /* Only hide if JavaScript explicitly sets display: none (when logged out) */
  .header__nav-item--profile[style*="display: none"] {
    display: none !important;
  }
}

