.sub-header {
  background-color: #1a252f; /* Match Qili's secondary blue */
  color: white;
  padding: 0;
  position: fixed;
  top: 60px; /* Position below main header */
  left: 0;
  right: 0;
  height: 44px; /* Reduced height with no padding */
  z-index: 9000; /* High enough to be visible but below main header */
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  display: flex !important;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  visibility: visible !important;
}

.sub-header-content {
  display: flex !important;
  align-items: center;
  width: 100%;
  max-width: 100%; /* Full width */
  padding: 0;
  overflow-x: auto;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
  visibility: visible !important;
}

.sub-header-content::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.sub-header-nav {
  display: flex !important;
  align-items: center;
  white-space: normal; /* Allow text wrapping */
  gap: 0;
  width: 100%;
  justify-content: flex-start;
  padding: 0; /* Remove all padding */
  flex-wrap: nowrap; /* Keep items in a row but allow text to wrap within each item */
  visibility: visible !important;
}

.sub-header-link {
  color: white;
  text-decoration: none;
  padding: 6px 8px; /* Reduced horizontal padding for thinner items */
  font-size: 14px; /* Match sidebar font size */
  font-weight: 400; /* Match sidebar font weight (normal) */
  transition: background-color 0.15s ease;
  white-space: pre-line; /* Preserve line breaks and allow wrapping */
  cursor: pointer;
  height: 32px; /* Fixed height for consistency */
  line-height: 1.1; /* Tighter line spacing for two lines */
  display: inline-flex; /* Use inline-flex for better control */
  align-items: center; /* Center content vertically */
  justify-content: center; /* Center content horizontally */
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
  max-width: 130px; /* Further increased width to prevent three lines */
  min-width: 100px; /* Increased minimum width */
  word-wrap: break-word;
  vertical-align: top; /* Align items to top for consistent positioning */
  hyphens: auto; /* Enable automatic hyphenation */
  word-break: break-word; /* Break long words if needed */
  box-sizing: border-box; /* Include padding and border in height calculation */
}

.sub-header-link:first-child {
  border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.sub-header-link:hover {
  background-color: rgba(0, 0, 0, 0.1);
  text-decoration: none;
}

.sub-header-link.active {
  background-color: #2c3a49; /* Darker blue when active */
  font-weight: bold;
  border-bottom: 3px solid #ffa724; /* Qili orange border */
  box-sizing: border-box;
}

/* Make the active state more visible on hover */
.sub-header-link.active:hover {
  background-color: #2c3a49; /* Keep the darker blue on hover */
}

/* Special styling for "All Products" */
.sub-header-link:first-child {
  font-weight: 600;
  background-color: rgba(0, 0, 0, 0.05);
  vertical-align: top; /* Ensure consistent alignment */
  line-height: 1.1; /* Match other links */
}

.sub-header-link:first-child.active {
  background-color: rgba(0, 0, 0, 0.2);
}

/* Shared All Products link styling */
.all-products-link {
  position: relative;
  z-index: 2;
}

/* Sidebar placeholder for All Products link */
.all-products-sidebar-placeholder {
  height: 44px; /* Same as new sub-header height */
  position: relative;
}

/* Clone the sub-header All Products link visually into the sidebar */
@media (min-width: 700px) {
  .all-products-link {
    position: fixed;
    top: 104px; /* 60px header + 44px sub-header */
    left: 0;
    width: 180px;
    height: 32px;
    background: #1a252f;
    color: #ff9900 !important;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-left: 25px;
    border-radius: 0;
    border: none;
    box-shadow: none;
    text-align: left;
    font-size: 15px;
    transition: none;
    pointer-events: auto;
  }
  .sub-header .all-products-link {
    width: auto;
    height: 32px; /* Match the fixed height of other links */
    background: none;
    color: white !important;
    font-weight: 600; /* Keep slightly heavier for "See All Departments" */
    padding: 6px 8px;
    justify-content: center;
    position: static;
    display: inline-flex; /* Match other links */
    align-items: center; /* Center content vertically */
    text-align: center;
    font-size: 14px; /* Match sidebar font size */
    max-width: 130px; /* Increased to match main links */
    min-width: 100px;
    vertical-align: top; /* Ensure consistent alignment with other links */
    line-height: 1.1; /* Match other links */
    box-sizing: border-box; /* Include padding and border in height calculation */
  }
}

@media (max-width: 700px) {
  .all-products-link {
    position: static !important;
    width: auto !important;
    height: 32px !important; /* Match the fixed height */
    background: none !important;
    color: white !important;
    font-weight: 600; /* Keep slightly heavier for "See All Departments" */
    padding: 6px 8px;
    justify-content: center;
    display: inline-flex !important; /* Match other links */
    align-items: center !important; /* Center content vertically */
    text-align: center;
    font-size: 14px; /* Match sidebar font size */
    max-width: 130px; /* Increased to match main links */
    min-width: 100px;
    vertical-align: top; /* Ensure consistent alignment */
    line-height: 1.1; /* Match other links */
    box-sizing: border-box !important; /* Include padding and border in height calculation */
  }
  .all-products-sidebar-placeholder {
    display: none;
  }
}

/* Responsive design */
@media (max-width: 1200px) {
  .sub-header-link {
    font-size: 13px; /* Slightly smaller than 14px */
    padding: 6px 7px;
    max-width: 120px; /* Further increased for better two-line display */
    min-width: 90px;
  }
}

@media (max-width: 900px) {
  .sub-header-link {
    font-size: 12px; /* Proportional reduction */
    padding: 6px 6px;
    max-width: 110px; /* Further increased for better fit */
    min-width: 85px;
  }
}

@media (max-width: 600px) {
  .sub-header-link {
    font-size: 11px; /* Increased from 10px for better readability */
    padding: 6px 5px;
    max-width: 100px; /* Further increased width */
    min-width: 80px;
  }

  .sub-header {
    height: 44px; /* Keep consistent with desktop - no extra padding */
  }

  .main {
    margin-top: 104px !important; /* 60px header + 44px sub-header */
  }

  .checkout-header ~ .main {
    margin-top: 104px !important;
  }

  .sub-header-submenu {
    top: 104px; /* Adjust submenu position */
  }
}

/* Additional breakpoint for very thin screens */
@media (max-width: 480px) {
  .sub-header-link {
    font-size: 10px; /* Reduced font size */
    padding: 5px 4px;
    max-width: 95px; /* Increased width */
    min-width: 75px;
  }

  .sub-header {
    height: 44px; /* Keep consistent with desktop - no extra padding */
  }

  .main {
    margin-top: 104px !important; /* 60px header + 44px sub-header */
  }

  .checkout-header ~ .main {
    margin-top: 104px !important;
  }

  .sub-header-submenu {
    top: 104px;
  }
}

/* Adjust main content to account for sub-header */
.main {
  margin-top: 104px !important; /* 60px (main header) + 44px (sub-header) */
}

/* Special handling for checkout page */
.checkout-header ~ .main {
  margin-top: 104px !important;
}

/* Loading animation for products */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 50px 0;
  width: 100%;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(35, 47, 62, 0.2);
  border-radius: 50%;
  border-top-color: #232f3e;
  animation: spin 1s ease-in-out infinite;
  margin-bottom: 15px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-container p {
  color: #555;
  font-size: 16px;
}

/* Sub-header dropdown submenu styles */
.sub-header-submenu {
  position: fixed;
  top: 104px; /* Below sub-header (60px header + 44px sub-header) */
  left: 0;
  width: 100%;
  background-color: #232f3e;
  color: white;
  z-index: 1001; /* Higher z-index to appear above all content */
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sub-header-submenu.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.sub-header-submenu-content {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 20px;
  max-height: 400px;
  overflow-y: auto;
  justify-content: flex-start;
}

.sub-header-submenu-row {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  gap: 0;
}

.sub-header-submenu-column {
  flex: 1;
  min-width: 200px;
  padding: 0 15px;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  max-height: 300px;
}

.sub-header-submenu-title {
  font-size: 14px;
  font-weight: 600;
  color: #ff9900;
  margin-bottom: 10px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sub-header-submenu-item {
  display: block;
  color: white;
  text-decoration: none;
  padding: 8px 12px;
  margin: 2px 0;
  font-size: 13px;
  transition: all 0.2s ease;
  cursor: pointer;
  border-radius: 4px;
  white-space: nowrap;
  border: 1px solid transparent;
}

.sub-header-submenu-item:hover {
  color: #ff9900;
  background-color: rgba(255, 153, 0, 0.1);
  border-color: rgba(255, 153, 0, 0.2);
}

/* Responsive design for submenus */
@media (max-width: 1200px) {
  .sub-header-submenu-column {
    min-width: 180px;
    padding: 0 12px;
  }

  .sub-header-submenu-content {
    padding: 15px;
  }
}

@media (max-width: 900px) {
  .sub-header-submenu-column {
    min-width: 160px;
    padding: 0 10px;
    max-height: 250px;
  }

  .sub-header-submenu-content {
    padding: 12px;
  }

  .sub-header-submenu-item {
    font-size: 12px;
    padding: 6px 10px;
  }
}

@media (max-width: 600px) {
  .sub-header-submenu-content {
    flex-direction: column;
    padding: 10px;
  }

  .sub-header-submenu-column {
    min-width: auto;
    max-height: none;
    padding: 0 5px;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sub-header-submenu-item {
    display: inline-block;
    margin: 3px;
    font-size: 11px;
    padding: 5px 8px;
  }
}

/* Mobile sub-header positioning adjustments */
@media (max-width: 320px) {
  .sub-header {
    top: 55px !important; /* Position below reduced-height main header */
    height: 44px !important; /* Keep consistent with desktop - no extra padding */
  }

  .sub-header-link {
    font-size: 9px; /* Smaller font to prevent three lines */
    padding: 5px 3px;
    max-width: 90px; /* Further increased width */
    min-width: 70px;
  }

  .main {
    margin-top: 99px !important; /* 55px header + 44px sub-header */
  }

  .checkout-header ~ .main {
    margin-top: 99px !important;
  }

  .sub-header-submenu {
    top: 99px !important;
  }

  .all-products-link {
    top: 99px !important;
  }
}
