.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  font-family: var(--font-sans);
}

.site-header.is-sticky {
  background: var(--color-bg-white);
  box-shadow: var(--shadow-md);
}

/* Sticky: collapse to a single compact row — promo bar, logo and the
   secondary utility links disappear, the category button jumps next to the
   search bar. */
.site-header.is-sticky .site-header__top,
.site-header.is-sticky .site-header__logo,
.site-header.is-sticky .site-header__utility {
  display: none;
}

.site-header.is-sticky .site-header__main {
  padding: var(--space-2) 0;
}

.site-header.is-sticky .site-header__category {
  order: -1;
}

.site-header.is-sticky .site-header__search {
  order: 0;
}

.site-header.is-sticky .site-header__right {
  order: 1;
}

/* Sticky: the homepage's permanently-open decorative sidebar only makes
   sense over the hero banner, so fall back to normal hover behavior. */
.site-header.is-sticky .site-header__category .category-menu {
  display: none;
}

.site-header.is-sticky .site-header__category:hover .category-menu,
.site-header.is-sticky .site-header__category.is-open .category-menu {
  display: block;
}

/* ---------- Top bar ---------- */

.site-header__top {
  background: var(--color-brand-blue);
  color: var(--color-text-light);
  font-size: var(--text-sm);
  min-height: 32px;
  padding: var(--space-2) 0;
}

.site-header__top-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.site-header__hotlines {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.site-header__pill {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  color: var(--color-text-light);
  font-weight: 700;
  white-space: nowrap;
  background: repeating-linear-gradient(90deg, #c924aa 0, #6a7ed1 98.41%);
  background-size: 200% auto;
  animation: header-pill-shift 2s linear infinite forwards;
}

.site-header__pill-icon {
  flex-shrink: 0;
}

.site-header__top-links {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.site-header__top-link {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--color-text-light);
  white-space: nowrap;
}

.site-header__top-link:hover {
  text-decoration: underline;
}

@keyframes header-pill-shift {
  0% { background-position: 0 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Main header ---------- */

.site-header__main {
  background: var(--color-bg-white);
  padding: var(--space-4) 0;
}

/* Two explicit rows: row1 (logo/search/right) and row2 (category/utility)
   stack vertically by default; each row is its own flex-wrap group. */
.site-header__main-inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.site-header__row1,
.site-header__row2 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
}

/* Sticky: collapse row1/row2 back into a single flex context (same as the
   pre-grouping markup) so the existing order:-1/0/1 jump below still works. */
.site-header.is-sticky .site-header__main-inner {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
}

.site-header.is-sticky .site-header__row1,
.site-header.is-sticky .site-header__row2 {
  display: contents;
}

.site-header__logo {
  display: block;
  flex-shrink: 0;
}

.site-header__logo img {
  display: block;
  height: 70px;
  width: auto;
  width: 200px;
}

.site-header__search {
  flex: 1 1 420px;
  max-width: 480px;
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-1) var(--space-1) var(--space-4);
  background: var(--color-bg-white);
}

.site-header__search-input {
  flex: 1;
  border: 0;
  height: 36px;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--color-text-primary);
  background: transparent;
}

.site-header__search-input::placeholder {
  color: var(--color-text-muted);
}

.site-header__search-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: linear-gradient(180deg, var(--color-brand-blue) 0%, #1da7b0 100%);
  transition: filter var(--transition-fast);
}

.site-header__search-btn:hover {
  filter: brightness(1.05);
}

.site-header__right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.site-header__right-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 44px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  background: #ecf2f9;
  color: var(--color-text-body);
  position: relative;
  transition: background var(--transition-fast);
}

.site-header__right-item:hover {
  background: #e2ecf7;
}

.site-header__right-icon {
  flex-shrink: 0;
  color: var(--color-brand-blue);
}

.site-header__right-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-body);
}

.site-header__hotline-numbers {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  font-size: 15;
  font-weight: 400;
  color: var(--color-text-primary);
}

.site-header__account {
  cursor: pointer;
}

.site-header__cart-icon-wrap {
  position: relative;
  display: inline-flex;
}

.site-header__cart-count {
  position: absolute;
  top: -4px;
  right: -6px;
  min-width: 14px;
  height: 14px;
  line-height: 14px;
  padding: 0 2px;
  border-radius: var(--radius-full);
  background: #ffa41c;
  color: var(--color-text-primary);
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}

/* ---------- Row 2: category button + utility links ---------- */

.site-header__category {
  position: relative;
  flex: 0 0 230px;
}

/* Invisible bridge so the cursor stays "inside" .site-header__category while
   crossing the gap between the button and the dropdown below it — without
   it, the dropdown loses :hover and closes before the pointer ever reaches it. */
.site-header__category::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 0;
  width: 250px;
  height: 30px;
  z-index: 59;
}

.site-header__category-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--color-brand-blue);
  color: var(--color-text-light);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.site-header__category-btn:hover {
  background: var(--color-brand-blue-dark);
}

.site-header__category-btn:active {
  transform: scale(0.98);
}

.site-header__utility {
  flex: 1 1 auto;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.site-header__utility-item {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-body);
  font-size: var(--text-sm);
  font-weight: 700;
  white-space: nowrap;
  text-transform: uppercase;
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.site-header__utility-item svg {
  flex-shrink: 0;
  color: var(--color-brand-blue);
}

.site-header__utility-item:hover {
  background: #f0f7ff;
  border-color: var(--color-brand-blue);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* ---------- Category mega menu ---------- */

.category-menu {
  display: none;
  position: absolute;
  top: calc(100% + 30px);
  left: 0;
  z-index: 60;
}

.site-header__category.is-open .category-menu,
.site-header__category:hover .category-menu {
  display: block;
}

/* Homepage only: live site keeps this panel permanently open as a decorative
   sidebar over the hero banner, instead of requiring hover. */
body.is-homepage .site-header__category .category-menu {
  display: block;
}

@media (max-width: 1024px) {
  body.is-homepage .site-header__category .category-menu {
    display: none;
  }
  body.is-homepage .site-header__category:hover .category-menu,
  body.is-homepage .site-header__category.is-open .category-menu {
    display: block;
  }
}

/* The list is a self-contained box; the panel is positioned beside it
   independently so resizing one never affects the other's layout. */
.category-menu__list {
  position: relative;
  width: 250px;
  list-style: none;
  background: #ffffff;
  border: 1px solid #eaeaea;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  z-index: 99;
}

.category-menu__item:first-child {
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
}

.category-menu__item:last-child {
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
}

.category-menu__list:has(.category-menu__item:first-child:hover),
.category-menu__list:has(.category-menu__item:first-child.is-active) {
  border-top-right-radius: 0 !important;
}

.category-menu__list:has(.category-menu__item:last-child:hover),
.category-menu__list:has(.category-menu__item:last-child.is-active) {
  border-bottom-right-radius: 0 !important;
}

/* Homepage: let the hero banner show faintly through the sidebar. */
body.is-homepage .category-menu__list {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-color: transparent;
  box-shadow: none;
}

/* Sticky: the hero banner is scrolled out of view, so the sidebar goes back
   to a normal solid card instead of showing whatever is now behind it. */
body.is-homepage .site-header.is-sticky .category-menu__list {
  background: #ffffff;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-color: #eaeaea;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.category-menu__item {
  position: relative;
  height: 44px;
  cursor: pointer;
  color: #2d3748;
  font-size: 14px;
  font-weight: 500;
}

.category-menu__item-link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 100%;
  padding: 8px 16px;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.category-menu__icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4a5568;
  transition: color var(--transition-fast);
}

.category-menu__label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-menu__item:hover,
.category-menu__item.is-active {
  background: var(--color-brand-blue);
  color: #ffffff;
  font-weight: 700;

}

.category-menu__item:hover,
.category-menu__item:first-child.is-active {
  border-top-right-radius: 0 !important;
}

.category-menu__item:hover,
.category-menu__item:last-child.is-active {
  border-bottom-right-radius: 0 !important;
}

.category-menu__item:hover .category-menu__icon,
.category-menu__item.is-active .category-menu__icon {
  color: #ffffff;
}

.category-menu__item:not(.category-menu__item--no-sub):hover::after,
.category-menu__item.is-active:not(.category-menu__item--no-sub)::after {
  content: "";
  position: absolute;
  left: 100%;
  top: 0;
  z-index: 2;
  border-top: 22px solid transparent;
  border-bottom: 22px solid transparent;
  border-left: 12px solid var(--color-brand-blue);
}

.category-menu__panel {
  display: none;
  position: absolute;
  z-index: 1;
  top: 0;
  left: calc(250px);
  width: max-content;
  min-width: 180px;
  max-width: 900px;
  /* The panel is absolutely positioned, so it doesn't affect the wrapper's
     height — min-height:100% matches the sibling list's height when the
     category has few subcategories, but lets the panel grow taller than
     the list when it has more (instead of clipping/scrolling content). */
  min-height: 100%;
  padding: 24px 32px;
  background: var(--color-bg-white);
  border: 1px solid #eaeaea;
  border-radius: 16px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
}

.category-menu__list:hover + .category-menu__panel.has-content,
.category-menu__panel.has-content:hover {
  display: block;
}

.category-menu__group-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, max-content));
  grid-auto-rows: 44px;
  column-gap: 26px;
}

.category-menu__group-list li {
  height: 44px;
  display: flex;
  align-items: center;
}

.category-menu__group-link {
  display: inline-block;
  color: #1f2937;
  font-size: 13px;
  font-weight: 400;
  line-height: normal;
  transition: color var(--transition-fast), transform var(--transition-fast);
}

.category-menu__group-link:hover {
  color: var(--color-brand-blue);
  transform: translateX(3px);
}

/* Mobile accordion: toggle + sublist are hidden on desktop/tablet, where
   hovering the shared panel is used instead (see the mobile media query below). */
.category-menu__item-toggle {
  display: none;
}

.category-menu__mobile-sublist {
  display: none;
  list-style: none;
}

.site-header__mobile-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--color-text-primary);
  cursor: pointer;
}

/* ---------- Responsive ---------- */

@media (max-width: 1024px) {
  .site-header__main-inner {
    position: relative;
  }

  .site-header__search {
    order: 3;
    flex: 1 1 100%;
    max-width: none;
  }

  .site-header__category {
    flex: 1 1 auto;
  }

  .site-header__utility {
    flex: 1 1 100%;
    order: 4;
  }

  .category-menu__panel {
    max-width: calc(100vw - 280px);
  }
}

@media (max-width: 600px) {
  /* Mobile: top bar giữ cả hotline (có số) + "Tin tức nổi bật" trên 1 dòng. */
  .site-header__top {
    font-size: 13px;
    padding: 6px 0;
  }

  .site-header__top-inner {
    flex-wrap: nowrap;
  }

  .site-header__top-links {
    gap: var(--space-3);
  }

  .site-header__hotlines {
    gap: var(--space-1);
  }

  .site-header__pill {
    padding: 4px 10px;
  }

  .site-header__main-inner {
    gap: var(--space-2);
  }

  @keyframes mobile-menu-reveal {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* Logo drops out on mobile — the header is a single compact row instead. */
  .site-header__logo {
    display: none;
  }

  /* Row: hamburger, shrunk search icon, cart pinned to the right. Tapping
     the search icon reveals a fixed popup bar instead of an inline input. */
  .site-header__mobile-toggle {
    display: flex;
    order: 1;
    width: 40px;
    height: 40px;
  }

  .site-header__search {
    order: 2;
    flex: 0 0 auto;
    max-width: none;
    width: 40px;
    margin-left: 0;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .site-header__search-input {
    display: none;
  }

  .site-header__hotline-block,
  .site-header__account {
    display: none;
  }

  .site-header__right {
    order: 3;
    margin-left: auto;
    gap: var(--space-2);
  }

  /* ----- Mobile search popup ----- */
  .site-header.is-mobile-search-open .site-header__search {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 80;
    width: auto;
    height: 60px;
    padding: 0 var(--container-pad);
    background: var(--color-bg-white);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
    animation: mobile-menu-reveal 0.2s ease both;
  }

  .site-header.is-mobile-search-open .site-header__search-input {
    display: block;
    flex: 1;
    width: auto;
    margin-right: var(--space-2);
  }

  @keyframes mobile-drawer-fade {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  /* Dark backdrop behind the drawer, painted as part of the header's own
     stacking context so it never needs extra markup. */
  .site-header.is-mobile-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 85;
    background: rgba(15, 23, 42, 0.5);
    animation: mobile-drawer-fade 0.2s ease both;
  }

  .site-header__category-btn {
    display: none;
  }

  /* ----- Drawer: one unified panel, slides in from the left. The utility
     links are moved inside here (as the last child) by header.js on mobile,
     so the whole menu — category nav + utility links — reads as one piece
     instead of two separate floating elements. ----- */
  .site-header__category {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 90;
    width: min(85vw, 320px);
    background: #ffffff;
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.18);
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    pointer-events: none;
  }

  .site-header.is-mobile-open .site-header__category {
    transform: translateX(0);
    pointer-events: auto;
  }

  .site-header__category::before {
    content: "Danh mục sản phẩm";
    flex: 0 0 auto;
    padding: 18px 20px;
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
    background: var(--color-brand-blue);
  }

  .category-menu {
    display: flex;
    flex-direction: column;
    position: static;
    width: 100%;
    flex: 0 0 auto;
  }

  .category-menu__list {
    width: 100%;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  /* The desktop hover flyout doesn't apply on touch; each item gets its own
     plain, single-column dropdown list instead (see category-menu.js). */
  .category-menu__panel {
    display: none;
  }

  /* Touch devices have no real hover: a tap can leave CSS :hover "stuck" on
     an element, and some mobile browsers fire a synthetic mouseenter on tap
     too. These overrides reuse the exact desktop selectors (same or higher
     specificity) so nothing can open/highlight from a tap here — only the
     explicit click handling in category-menu.js controls the dropdown. */
  .site-header__category:hover .category-menu {
    display: flex;
  }

  .category-menu__list:hover + .category-menu__panel.has-content,
  .category-menu__panel.has-content:hover {
    display: none;
  }

  .category-menu__item:hover {
    background: transparent;
    color: inherit;
    font-weight: 500;
  }

  .category-menu__item:hover .category-menu__icon {
    color: #4a5568;
  }

  .category-menu__item:not(.category-menu__item--no-sub):hover::after {
    content: none;
  }

  .category-menu__mobile-sublist {
    display: block;
    width: 100%;
    flex: 1 1 100%;
    max-height: 0;
    overflow: hidden;
    background: #f8fafc;
    transition: max-height 0.25s ease;
  }

  .category-menu__item.is-expanded .category-menu__mobile-sublist {
    max-height: 1200px;
  }

  .category-menu__mobile-sublist li {
    border-top: 1px solid #eef1f5;
  }

  .category-menu__mobile-sublist a {
    display: block;
    padding: 11px 16px 11px 52px;
    font-size: 13px;
    color: #475569;
    transition: background var(--transition-fast), color var(--transition-fast);
  }

  .category-menu__mobile-sublist a:hover,
  .category-menu__mobile-sublist a:active {
    background: #eef4ff;
    color: var(--color-brand-blue);
  }

  .category-menu__item {
    height: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    transition: background var(--transition-fast);
  }

  .category-menu__item-link {
    width: auto;
    height: 48px;
    flex: 1 1 auto;
    gap: var(--space-3);
  }

  /* The flyout arrow points at the desktop hover panel, which doesn't exist here. */
  .category-menu__item::after {
    display: none;
  }

  .category-menu__item-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    background: transparent;
    border: 0;
    border-left: 1px solid #f1f5f9;
    color: #94a3b8;
    cursor: pointer;
  }

  .category-menu__item-toggle svg {
    transition: transform var(--transition-fast);
  }

  .category-menu__item.is-expanded {
    background: #f8fafc;
  }

  .category-menu__item.is-expanded .category-menu__item-toggle {
    color: var(--color-brand-blue);
  }

  .category-menu__item.is-expanded .category-menu__item-toggle svg {
    transform: rotate(180deg);
  }

  /* Safe default before header.js reparents it; the scoped rule below
     takes over once it's actually inside the drawer. */
  .site-header__utility {
    display: none;
  }

  /* ----- Drawer: utility links, laid out as the last section inside the
     same panel (header.js moves this element inside .site-header__category
     on mobile — see syncMobileDrawerLayout). ----- */
  .site-header__category .site-header__utility {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex: 0 0 auto;
    width: 100%;
    background: #ffffff;
    border-top: 1px solid #eef1f5;
    overflow: hidden;
  }

  .site-header__utility-item {
    flex: 1 1 auto;
    width: 100%;
    height: auto;
    padding: 13px 16px;
    border: 0;
    border-radius: 0;
    text-transform: none;
    font-weight: 500;
    font-size: 14px;
  }

  .site-header__utility-item:not(:last-child) {
    border-bottom: 1px solid #f1f5f9;
  }

  .site-header__utility-item:hover,
  .site-header__utility-item:active {
    background: #f8fafc;
    box-shadow: none;
  }
}
