/*
 * Header category bar (template-parts/header-category-menu.php): second row of the sticky header with a
 * "☰ Product categories" button. The list opens on hover (mouse), keyboard focus, or click (.is-open, JS).
 * Phones (under 900px): the button is replaced by a sideways-scrolling row of chips (.category-chips).
 */

.category-bar {
  border-top: 1px solid var(--color-border);
  /* Very light taupe: half primary-soft, half the header white, so the row reads as part of the header. */
  background: color-mix(in srgb, var(--color-primary-soft) 50%, var(--color-surface));
}

/* The sticky header is one bar taller: sticky sidebars and anchors offset by the whole header. */
:root {
  --header-offset: calc(var(--header-height) + 2.75rem);
}

.category-bar__inner {
  display: flex;
  align-items: center;
  min-height: 2.75rem;
}

.category-menu {
  position: relative;
}

.category-menu__toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-text);
  font: inherit;
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
}

.category-menu__toggle:hover,
.category-menu.is-open .category-menu__toggle {
  color: var(--color-primary);
}

.category-menu__toggle .icon {
  width: 1.25rem;
  height: 1.25rem;
}

.category-menu__list {
  position: absolute;
  top: 100%;
  left: 0;
  display: none;
  min-width: 16rem;
  max-width: calc(100vw - 2 * var(--container-gutter));
  margin: 0;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
  list-style: none;
}

/* Open: click (JS), keyboard focus inside, or mouse hover on devices that have one. */
.category-menu.is-open .category-menu__list,
.category-menu:has(:focus-visible) .category-menu__list {
  display: grid;
}

@media (hover: hover) {
  .category-menu:hover .category-menu__list {
    display: grid;
  }
}

.category-menu__list a {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  text-decoration: none;
}

.category-menu__list a:hover,
.category-menu__list a:focus-visible {
  background: var(--color-primary-soft);
  color: var(--color-primary-hover);
}

/* "All products" first, set apart from the categories by a line. */
.category-menu__all {
  margin-bottom: var(--space-1);
  padding-bottom: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  font-weight: var(--font-weight-semibold);
}

.category-menu__count {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.category-menu__list a[aria-current='page'] {
  background: var(--color-primary-soft);
  color: var(--color-primary-hover);
}

/* Phones: one row of pill chips, swipe sideways; the current one is filled. */
.category-chips {
  position: relative; /* offsetLeft of chips is measured from the row (JS) */
  display: none;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-2) 0;
  overflow-x: auto;
  list-style: none;
  scrollbar-width: none;
}

.category-chips::-webkit-scrollbar {
  display: none;
}

.category-chips__chip {
  display: block;
  padding: var(--space-1) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  white-space: nowrap;
  text-decoration: none;
}

.category-chips__chip:hover {
  border-color: var(--color-primary);
  color: var(--color-primary-hover);
}

.category-chips__chip[aria-current='page'],
.category-chips__chip[aria-current='page']:hover {
  border-color: var(--button-bg);
  background: var(--button-bg);
  color: var(--button-text);
}

@media (max-width: 899px) {
  .category-menu {
    display: none;
  }

  .category-chips {
    display: flex;
  }
}
