/* storefront/app/static/css/header.css */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--primary-color);
  border-bottom: 1px solid var(--border-color);
  z-index: 1000;
  height: 80px;
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
  height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  height: 50px;
}

.logo img {
  height: 100%;
  width: auto;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-lg);
}

/* Improved User Menu */
.user-menu {
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
  font-weight: 500;
  transition: color 0.2s ease;
}

.user-greeting {
  display: inline-block;
  white-space: nowrap;
}

.user-dropdown-toggle {
  background: transparent;
  border: none;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem;
  cursor: pointer;
  font-size: 1rem;
}

.dropdown-arrow {
  font-size: 0.75rem;
  transition: transform 0.2s ease;
}

.user-menu.active .dropdown-arrow {
  transform: rotate(180deg);
}

.user-menu:hover,
.user-menu.active {
  color: var(--icy-blue);
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--primary-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--glass-shadow);
  min-width: 200px;
  z-index: 1001;
  overflow: hidden;

  /* Change these properties to make transitions work better */
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}


/* Show dropdown on hover (desktop) or when active (mobile) */
.user-menu.active .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(5px);
  /* Add display property explicitly to ensure it shows */
  display: block;
}

.dropdown-menu a {
  display: block;
  padding: var(--spacing-sm) var(--spacing-md);
  color: var(--text-primary);
  transition: all 0.2s ease;
  border-bottom: 1px solid var(--border-color);
  font-weight: normal;
  text-decoration: none;
}

.dropdown-menu a:last-child {
  border-bottom: none;
}

.dropdown-menu a:hover {
  background: var(--hover-color);
  color: var(--icy-blue);
}

.auth-links {
  display: flex;
  gap: var(--spacing-md);
}

.btn-glass {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-glass-primary {
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
}

.btn-glass:hover {
  background: var(--glass-hover-bg);
  border-color: var(--icy-blue);
  color: var(--icy-blue);
}

.btn-icon {
  display: none;
  font-size: 1.1rem;
}

/* Improved Cart Widget */
.cart-widget {
  position: relative;
}

.cart-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  transition: all 0.2s ease;
  position: relative;
}

.cart-icon::before {
  content: '\f07a'; /* Font Awesome shopping cart icon */
  font-family: 'Font Awesome 5 Free';
  font-weight: 900;
  font-size: 1.25rem;
}

.cart-icon:hover {
  background: var(--glass-hover-bg);
  border-color: var(--icy-blue);
  transform: translateY(-2px);
  color: var(--icy-blue);
}

.cart-count {
  position: absolute;
  top: -8px;
  right: -8px;
  color: var(--text-primary);
  font-size: 0.75rem;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Cart Dropdown */
.cart-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  background: var(--primary-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--glass-shadow);
  width: 300px;
  z-index: 1001;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.2s ease;
}

.cart-widget:hover .cart-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.cart-dropdown h3 {
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.cart-dropdown-items {
  max-height: 300px;
  overflow-y: auto;
}

.cart-dropdown-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-color);
}

.cart-dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item-image {
  width: 50px;
  height: 50px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--secondary-color);
}

.dropdown-item-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dropdown-item-details {
  flex: 1;
  min-width: 0;
}

.dropdown-item-title {
  font-size: 0.875rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.25rem;
}

.dropdown-item-price {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.cart-dropdown-total {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border-color);
  font-weight: 600;
  margin-top: 0.5rem;
}

.cart-dropdown-total .label {
  color: var(--text-secondary);
}

.cart-dropdown-total .value {
  color: var(--text-primary);
}

.cart-dropdown-actions {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.btn-cart,
.btn-checkout {
  padding: 0.75rem 1rem;
  text-align: center;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: all 0.2s ease;
  cursor: pointer;
  text-decoration: none;
}

.btn-cart {
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
}

.btn-cart:hover {
  background: var(--glass-hover-bg);
  border-color: var(--icy-blue);
}

.btn-checkout {
  background: rgba(129, 204, 219, 0.15);
  border: 1px solid rgba(129, 204, 219, 0.3);
  color: var(--text-primary);
}

.btn-checkout:hover {
  background: rgba(129, 204, 219, 0.25);
}

.empty-cart-message {
  text-align: center;
  padding: 1rem 0;
  color: var(--text-secondary);
}

/* Responsive adjustments */
@media (max-width: 991px) {
  .header-actions {
    gap: var(--spacing-md);
  }

  .user-greeting {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 768px) {
  .site-header {
    height: 70px; /* Slightly smaller header on mobile */
  }

  .header-container {
    padding: 0 var(--spacing-sm);
  }

  .logo {
    height: 40px; /* Smaller logo on mobile */
  }

  .header-actions {
    gap: var(--spacing-sm);
  }

  .user-greeting {
    display: none;
  }

  .user-dropdown-toggle {
    padding: 0.5rem;
    font-size: 1.1rem;
  }

  .dropdown-menu {
    position: absolute;
    top: calc(100% + 5px);
    right: auto; /* Remove the fixed right positioning */
    left: 10%;   /* Center it based on the user-menu */
    transform: translateX(-50%) translateY(10px) !important; /* Center horizontally */
    min-width: 180px;
    max-width: 80vw; /* Limit width to 80% of viewport */
  }

  /* When active or hovered */
  .user-menu:hover .dropdown-menu,
  .user-menu.active .dropdown-menu {
    transform: translateX(-50%) translateY(5px) !important; /* Keep horizontal centering when showing */
  }

  /* Ensure the dropdown doesn't overflow the screen */
  .dropdown-menu {
    max-height: 80vh;
    overflow-y: auto;
    /* Add padding on smaller screens to ensure content doesn't touch edges */
    padding: 8px;
  }


  /* Special mobile positioning for larger screens */
  @media (min-width: 400px) {
    .dropdown-menu {
      right: 0; /* Align with edge of button */
    }
  }

  /* Show icons instead of text for auth buttons */
  .auth-links .btn-text {
    display: none;
  }

  .auth-links .btn-icon {
    display: block;
  }

  .auth-links a {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
  }

  /* Cart dropdown positioning fix */
  .cart-dropdown {
    width: auto;
    min-width: 280px;
    right: 0;
    max-width: 90vw;
  }

  /* Force dropdown to remain in viewport */
  .dropdown-menu {
    max-height: calc(100vh - 80px);
    overflow-y: auto;
  }
}

/* Fix for very small screens */
@media (max-width: 350px) {
  .header-actions {
    gap: 8px;
  }

  .logo {
    height: 36px;
  }

  .auth-links a,
  .cart-icon,
  .user-dropdown-toggle {
    width: 36px;
    height: 36px;
  }

  .dropdown-menu {
    left: 0;
    right: 0;
    transform: translateY(10px) !important; /* Remove X transform */
    width: 100%; /* Full width */
    max-width: 100%;
  }

  .user-menu:hover .dropdown-menu,
  .user-menu.active .dropdown-menu {
    transform: translateY(5px) !important;
  }

}
