/* The facet rail and result summary.
 *
 * Tokens with fallbacks throughout, exactly as spec-panel.css does, so one
 * component serves both design states. See that file's header for why.
 */

.ww-facets__heading {
  font-family: var(--ww-font-mono, 'Montserrat', sans-serif);
  font-size: var(--ww-text-xs, 0.75rem);
  letter-spacing: var(--ww-tracking-label, 0.12em);
  text-transform: uppercase;
  font-weight: 500;
  color: var(--ww-c-label, #4F4F4F);
  margin: 0 0 12px;
}

.ww-facets__group {
  padding: 14px 0;
  border-top: 1px solid var(--ww-rule, #E6E6E6);
}

.ww-facets__label {
  font-family: var(--ww-font-mono, 'Montserrat', sans-serif);
  font-size: var(--ww-text-xs, 0.75rem);
  letter-spacing: var(--ww-tracking-label, 0.12em);
  text-transform: uppercase;
  font-weight: 500;
  color: var(--ww-c-label, #4F4F4F);
  margin: 0 0 8px;
}

.ww-facets__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ww-facets__opt {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 0;
  font-size: var(--ww-text-sm, 0.875rem);
  color: var(--ww-ink-2, #4F4F4F);
  text-decoration: none;
  line-height: 1.4;
}

.ww-facets__opt:hover .ww-facets__name {
  text-decoration: underline;
}

/* A real 1.4.11 boundary: --ww-rule is a hairline and must never carry
 * meaning, so the control border uses a colour that actually reaches 3:1. */
.ww-facets__box {
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  border: 1px solid var(--ww-rule-firm, #767676);
  background: var(--ww-c-surface, var(--ww-paper, #FFFFFF));
  position: relative;
}

.ww-facets__opt.is-on {
  color: var(--ww-ink, #0C1E13);
  font-weight: 500;
}

.ww-facets__opt.is-on .ww-facets__box {
  background: var(--ww-c-accent-fill, var(--ww-oxide, #0F6037));
  border-color: var(--ww-oxide, #0F6037);
}

.ww-facets__opt.is-on .ww-facets__box::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 3px;
  height: 7px;
  border: solid var(--ww-paper, #FFFFFF);
  border-width: 0 1.6px 1.6px 0;
  transform: rotate(43deg);
}

.ww-facets__count {
  margin-left: auto;
  font-family: var(--ww-font-mono, 'Montserrat', sans-serif);
  font-variant-numeric: tabular-nums;
  font-size: var(--ww-text-xs, 0.75rem);
  color: var(--ww-c-label, #4F4F4F);
}

.ww-facets__opt:focus-visible {
  outline: 2px solid var(--ww-oxide, #0F6037);
  outline-offset: 2px;
}

/* --- result summary --- */

.ww-results {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  padding-bottom: 12px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--ww-rule, #E6E6E6);
}

.ww-results__count {
  margin: 0;
  font-family: var(--ww-font-mono, 'Montserrat', sans-serif);
  font-variant-numeric: tabular-nums;
  font-size: var(--ww-text-sm, 0.875rem);
  color: var(--ww-ink-2, #4F4F4F);
}

.ww-results__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.ww-results__chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--ww-font-mono, 'Montserrat', sans-serif);
  font-size: var(--ww-text-xs, 0.75rem);
  border: 1px solid var(--ww-rule-firm, #767676);
  border-radius: var(--ww-radius-control, 8px);
  padding: 3px 8px;
  color: var(--ww-ink, #0C1E13);
  text-decoration: none;
}

.ww-results__chip:hover {
  border-color: var(--ww-oxide, #0F6037);
  color: var(--ww-oxide, #0F6037);
}

.ww-results__chip:focus-visible {
  outline: 2px solid var(--ww-oxide, #0F6037);
  outline-offset: 2px;
}

/* Mobile: the rail sits above the grid rather than beside it. The template's
 * existing col-md-3 / col-md-9 pair already stacks; this just tightens it. */
@media screen and (max-width: 767px) {
  .ww-facets {
    margin-bottom: 20px;
  }
}

/* Reveal the sidebar column, but only where there is a rail.
 *
 * cust.css carries `.col-md-3 { display: none }` and sizes both columns
 * `flex: 0 0 100%`. The column has been hidden since the theme was written,
 * which is why the `<p>Filter</p>` placeholder inside it was never seen by
 * anyone. Scoped to `.ww-has-facets` so a category with nothing to filter is
 * left exactly as it was rather than growing an empty column.
 */
.ww-has-facets > .col-md-3 {
  display: block;
}

@media screen and (min-width: 992px) {
  .ww-has-facets > .col-md-3 {
    flex: 0 0 232px;
    max-width: 232px;
  }

  .ww-has-facets > .col-md-9 {
    flex: 1 1 0;
    max-width: none;
    min-width: 0; /* or a wide product title stops the column shrinking */
  }
}

/* --- sort control --- */

.ww-sort {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: baseline;
  margin-left: auto;
}

.ww-sort__label {
  font-family: var(--ww-font-mono, 'Montserrat', sans-serif);
  font-size: var(--ww-text-xs, 0.75rem);
  letter-spacing: var(--ww-tracking-label, 0.12em);
  text-transform: uppercase;
  color: var(--ww-c-label, #4F4F4F);
}

.ww-sort__list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.ww-sort__opt {
  font-size: var(--ww-text-sm, 0.875rem);
  color: var(--ww-ink-2, #4F4F4F);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.ww-sort__opt:hover {
  color: var(--ww-oxide, #0F6037);
  border-bottom-color: var(--ww-oxide, #0F6037);
}

.ww-sort__opt.is-on {
  color: var(--ww-ink, #0C1E13);
  font-weight: 500;
  border-bottom-color: var(--ww-oxide, #0F6037);
}

.ww-sort__opt:focus-visible {
  outline: 2px solid var(--ww-oxide, #0F6037);
  outline-offset: 2px;
}

@media screen and (max-width: 640px) {
  .ww-sort {
    margin-left: 0;
    width: 100%;
  }
}

/* --- the mobile filter sheet ---
 *
 * The rail is rendered ONCE and restyled, never duplicated: a second copy for
 * mobile would mean two elements carrying id="ww-facets-heading", and duplicate
 * DOM ids are a defect this theme has already had to fix once.
 *
 * The dialog behaviour is popups.js's — `.popup` + `data-popup-id` gives role,
 * aria-modal, the focus trap, Escape and focus restore. Reusing it is the point:
 * CLAUDE.md is explicit that aria-modal and a trap have to ship together, and a
 * second trap on this site would be a second thing to get wrong.
 */

.ww-facets__open {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  justify-content: center;
  padding: 11px 16px;
  font-family: var(--ww-font-sans, 'Montserrat', sans-serif);
  font-size: var(--ww-text-sm, 0.875rem);
  font-weight: 500;
  color: var(--ww-ink, #0C1E13);
  background: var(--ww-c-surface, var(--ww-paper, #FFFFFF));
  border: 1px solid var(--ww-rule-firm, #767676);
  border-radius: var(--ww-radius-control, 8px);
  cursor: pointer;
}

.ww-facets__badge {
  min-width: 20px;
  padding: 1px 6px;
  font-family: var(--ww-font-mono, 'Montserrat', sans-serif);
  font-size: var(--ww-text-xs, 0.75rem);
  font-variant-numeric: tabular-nums;
  color: var(--ww-paper, #FFFFFF);
  background: var(--ww-c-accent-fill, var(--ww-oxide, #0F6037));
  border-radius: 10px;
}

/* Bottom sheet. Overrides the centred .popup card from popups.css. */
.ww-facet-sheet {
  top: auto;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  max-width: none;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom, 0px));
  border-radius: var(--ww-radius, 16px) var(--ww-radius, 16px) 0 0;
  transform: none;
  /* ONE STEP ABOVE THE OVERLAY (--ww-z-sheet on the ladder in
     general-styles.css). Every other .popup is a child of
     #popup-overlay, so its 1001 ranks it inside the overlay's stacking
     context. This sheet lives in the archive's rail, outside it, so at the
     same 1001 the overlay — later in the DOM — painted over it: the sheet sat
     under the 50% scrim and every tap on an option landed on the overlay,
     whose click handler closes the dialog. Filtering on a phone did nothing
     but close the sheet (measured 2026-09-24, touch emulation at 390px). */
  z-index: var(--ww-z-sheet, 1002);
}

.ww-facet-sheet__close {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 26px;
  line-height: 1;
  background: none;
  border: 0;
  color: var(--ww-ink-2, #4F4F4F);
  cursor: pointer;
}

/* Sticks to the bottom of the sheet so the count is always reachable without
 * scrolling back down past a long species list. */
.ww-facets__apply {
  position: sticky;
  bottom: 0;
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 13px 16px;
  font-family: var(--ww-font-sans, 'Montserrat', sans-serif);
  font-size: var(--ww-text-base, 1rem);
  font-weight: 500;
  color: var(--ww-paper, #FFFFFF);
  background: var(--ww-c-accent-fill, var(--ww-oxide, #0F6037));
  border: 0;
  border-radius: var(--ww-radius-control, 8px);
  cursor: pointer;
}

.ww-facets__open:focus-visible,
.ww-facets__apply:focus-visible,
.ww-facet-sheet__close:focus-visible {
  outline: 2px solid var(--ww-oxide, #0F6037);
  outline-offset: 2px;
}

/* Desktop: no sheet at all. The rail is a static column again.
 *
 * `display: block !important` is deliberate and not laziness. popups.js writes
 * `style.display = 'none'` inline onto EVERY `.popup` whenever any dialog
 * closes — open and dismiss the cart on a desktop category page and the facet
 * rail would vanish with it. An inline style can only be beaten by !important.
 */
@media screen and (min-width: 992px) {
  .ww-facet-sheet {
    display: block !important;
    position: static;
    max-height: none;
    overflow: visible;
    padding: 0;
    background: none;
    box-shadow: none;
    border-radius: 0;
  }

  .ww-facets__open,
  .ww-facet-sheet__close,
  .ww-facets__apply {
    display: none;
  }
}
