/**
 * TLLC /products/ catalog filter + sort.
 * Matches linux theme tokens. Does not restyle ul.products grid.
 * JS breakpoint is 899px (see tll-catalog-filter.js isMobile).
 */

#tll-catalog-filter,
#tll-catalog-filter * {
  box-sizing: border-box;
}

#tll-catalog-filter button {
  appearance: none;
  font: inherit;
}

#tll-catalog-filter {
  --tll-cf-ink: var(--tll-ink, #101418);
  --tll-cf-ink-2: var(--tll-ink-2, #1a2129);
  --tll-cf-paper: var(--tll-paper, #f3f0e8);
  --tll-cf-white: var(--tll-white, #fffcf6);
  --tll-cf-line: var(--tll-line, #d8d1c3);
  --tll-cf-muted: var(--tll-muted, #5c6570);
  --tll-cf-text: var(--tll-text, #1b2128);
  --tll-cf-accent: var(--tll-accent, #c8ef4a);
  --tll-cf-accent-ink: var(--tll-accent-ink, #14180a);
  --tll-cf-shadow: var(--tll-shadow, 0 18px 50px rgba(16, 20, 24, 0.12));
  --tll-cf-sans: var(--tll-sans, "IBM Plex Sans", "Helvetica Neue", Helvetica, Arial, sans-serif);
  --tll-cf-mono: var(--tll-mono, "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace);
  --tll-cf-header: 4.4rem;
  --tll-cf-radius: 1.15rem;
  --tll-cf-pill: 999px;
  color: var(--tll-cf-text);
  font-family: var(--tll-cf-sans);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  html:not(.colors-light) #tll-catalog-filter {
    --tll-cf-ink: #f3f0e8;
    --tll-cf-ink-2: #e8e4dc;
    --tll-cf-paper: #12171c;
    --tll-cf-white: #1a2129;
    --tll-cf-line: #2c3640;
    --tll-cf-muted: #9aa3ad;
    --tll-cf-text: #e8e4dc;
    --tll-cf-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  }
}

body.tll-catalog-lock {
  overflow: hidden;
}

/* Hidden cards leave the CSS grid; do not change ul.products display/columns. */
ul.products > li.product.tll-catalog-out,
ul.products > li.product[hidden],
.woocommerce ul.products > li.product.tll-catalog-out,
.woocommerce ul.products > li.product[hidden] {
  display: none !important;
}

html.tll-catalog-js .woocommerce-result-count,
html.tll-catalog-js form.woocommerce-ordering {
  display: none !important;
}

.tll-catalog-inner {
  width: min(var(--tll-max, 1180px), calc(100% - 2rem));
  margin: 0 auto;
}

.tll-catalog-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 0.85rem;
}

#tll-catalog-filter .tll-catalog-sort-wrap {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
}

#tll-catalog-filter .tll-catalog-sort-wrap label {
  font-family: var(--tll-cf-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--tll-cf-muted);
}

#tll-catalog-sort {
  appearance: none;
  border: 1px solid var(--tll-cf-line);
  border-radius: var(--tll-cf-pill);
  padding: 0.55rem 2.1rem 0.55rem 0.95rem;
  background: var(--tll-cf-white) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%23101418' d='M1 1l5 5 5-5'/></svg>") no-repeat right 0.85rem center;
  color: var(--tll-cf-ink);
  font-family: var(--tll-cf-sans);
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.2;
  min-height: 2.6rem;
  cursor: pointer;
}

#tll-catalog-sort:focus-visible {
  outline: 2px solid var(--tll-cf-ink);
  outline-offset: 2px;
}

#tll-catalog-count {
  margin: 0;
  color: var(--tll-cf-muted);
  font-size: 0.88rem;
}

#tll-catalog-open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.6rem;
  padding: 0.45rem 1.05rem;
  border: 1px solid var(--tll-cf-ink);
  border-radius: var(--tll-cf-pill);
  background: var(--tll-cf-ink);
  color: #fff;
  font-family: var(--tll-cf-sans);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}

#tll-catalog-open[aria-expanded="true"] {
  background: var(--tll-cf-accent);
  border-color: var(--tll-cf-accent);
  color: var(--tll-cf-accent-ink);
}

.tll-catalog-facet {
  border: 0;
  margin: 0 0 0.85rem;
  padding: 0;
  min-width: 0;
}

.tll-catalog-facet legend {
  font-family: var(--tll-cf-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--tll-cf-muted);
  margin: 0 0 0.4rem;
  padding: 0;
}

.tll-catalog-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tll-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid #2a323a;
  background: #fffcf6;
  border-radius: var(--tll-cf-pill);
  padding: 0.32rem 0.78rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #101418 !important;
  cursor: pointer;
  user-select: none;
  line-height: 1.25;
}

.tll-chip input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.tll-chip:hover {
  border-color: #101418;
  background: #f3f0e8;
  color: #101418 !important;
}

/* Selected: accent fill + dark ink text (never light-green-on-white) */
.tll-chip.is-on,
.tll-chip[data-checked="true"] {
  background: var(--tll-cf-accent, #c8ef4a);
  border-color: #101418;
  color: var(--tll-cf-accent-ink, #14180a) !important;
}

.tll-chip:focus-within {
  outline: 2px solid #101418;
  outline-offset: 2px;
}

.tll-chip.is-on:focus-within,
.tll-chip[data-checked="true"]:focus-within {
  outline-color: #101418;
}

[data-tll-catalog-clear] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.4rem;
  padding: 0.4rem 0.95rem;
  border: 1px solid var(--tll-cf-line);
  border-radius: var(--tll-cf-pill);
  background: transparent;
  color: var(--tll-cf-ink);
  font-family: var(--tll-cf-sans);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

[data-tll-catalog-clear]:hover {
  border-color: var(--tll-cf-ink);
}

[data-tll-catalog-clear]:disabled {
  opacity: 0.4;
  cursor: default;
}

#tll-catalog-empty {
  width: min(var(--tll-max, 1180px), calc(100% - 2rem));
  margin: 0 auto 1.2rem;
  padding: 1rem 1.15rem;
  background: var(--tll-white, #fffcf6);
  border: 1px solid var(--tll-line, #d8d1c3);
  border-radius: 1.15rem;
  color: var(--tll-text, #1b2128);
}

#tll-catalog-empty[hidden] {
  display: none !important;
}

#tll-catalog-empty p {
  margin: 0 0 0.65rem;
}

#tll-catalog-close,
#tll-catalog-apply {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.6rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--tll-cf-pill);
  font-family: var(--tll-cf-sans);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}

#tll-catalog-close {
  border: 1px solid var(--tll-cf-line);
  background: transparent;
  color: var(--tll-cf-ink);
}

#tll-catalog-apply {
  border: 1px solid var(--tll-cf-ink);
  background: var(--tll-cf-ink);
  color: var(--tll-cf-accent);
  flex: 1 1 auto;
}

.tll-catalog-backdrop {
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  background: rgba(16, 20, 24, 0.46);
}

.tll-catalog-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 1rem;
}

#tll-catalog-sheet-title {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
  color: var(--tll-cf-ink);
}

.tll-catalog-panel-foot {
  display: flex;
  gap: 0.55rem;
  padding-top: 0.75rem;
  margin-top: 0.4rem;
  border-top: 1px solid var(--tll-cf-line);
}

/* —— Desktop: sticky filter bar, sheet in flow —— */
@media (min-width: 900px) {
  #tll-catalog-filter {
    position: sticky;
    top: var(--tll-cf-header);
    z-index: 40;
    background: var(--tll-cf-paper);
    border-bottom: 1px solid var(--tll-cf-line);
    padding: 0.7rem 0 0.85rem;
    margin: 0 0 1.1rem;
  }

  #tll-catalog-open,
  #tll-catalog-close,
  #tll-catalog-apply,
  .tll-catalog-backdrop,
  .tll-catalog-panel-head,
  .tll-catalog-panel-foot {
    display: none !important;
  }

  #tll-catalog-sheet,
  #tll-catalog-panel {
    display: block;
    position: static;
    inset: auto;
    background: transparent;
    box-shadow: none;
    max-height: none;
    overflow: visible;
    padding: 0;
    transform: none;
  }

  #tll-catalog-sheet[hidden] {
    display: block !important;
  }

  .tll-catalog-toolbar {
    margin-bottom: 0.55rem;
  }

  .tll-catalog-facets {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.35rem 1rem;
  }
}

/* —— Mobile: Filter button + bottom sheet —— */
@media (max-width: 899px) {
  #tll-catalog-filter {
    position: sticky;
    top: var(--tll-cf-header);
    z-index: 40;
    background: var(--tll-cf-paper);
    border-bottom: 1px solid var(--tll-cf-line);
    padding: 0.65rem 0 0.75rem;
    margin: 0 0 1rem;
  }

  .tll-catalog-toolbar {
    margin-bottom: 0;
  }

  #tll-catalog-filter .tll-catalog-sort-wrap {
    margin-left: 0;
    flex: 1 1 auto;
  }

  #tll-catalog-sort {
    width: 100%;
  }

  #tll-catalog-count {
    flex: 1 0 100%;
  }

  #tll-catalog-sheet {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: block;
  }

  #tll-catalog-sheet[hidden] {
    display: none !important;
  }

  .tll-catalog-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
  }

  #tll-catalog-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: min(88vh, 40rem);
    overflow: auto;
    background: var(--tll-cf-paper);
    border-radius: 1.2rem 1.2rem 0 0;
    box-shadow: var(--tll-cf-shadow);
    padding: 1.1rem 1.15rem calc(1.15rem + env(safe-area-inset-bottom, 0px));
    transform: translateY(110%);
    transition: transform 0.22s ease;
  }

  #tll-catalog-sheet.is-open #tll-catalog-panel {
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  #tll-catalog-open,
  #tll-catalog-panel,
  .tll-chip {
    transition: none;
  }
}


/* === OPTION A: compact shop chrome (2026-09-17) === */
/* Collapse shop hero; slim sticky filter flush under .tll-header */

.tll-shop-hero.tll-shop-hero--compact {
  padding: 0.75rem 0 0.7rem;
  margin-bottom: 0 !important;
}

.tll-shop-hero.tll-shop-hero--compact .tll-wrap {
  display: flex;
  align-items: center;
  min-height: 0;
}

.tll-shop-hero.tll-shop-hero--compact h1 {
  margin: 0;
  font-size: clamp(1.15rem, 2.2vw, 1.55rem);
  line-height: 1.25;
  max-width: none;
}

.tll-shop-hero.tll-shop-hero--compact .tll-kicker,
.tll-shop-hero.tll-shop-hero--compact .lede,
.tll-shop-hero.tll-shop-hero--compact .tll-brands,
.tll-shop-hero.tll-shop-hero--compact .tll-shop-filters,
.tll-shop-hero.tll-shop-hero--compact .tll-shop-sale {
  display: none !important;
}

/* Duplicate Woo title under hero — hide on shop when compact chrome is live */
body.post-type-archive-product .woocommerce-products-header {
  display: none !important;
}

/* Slimmer sticky filter toolbar (desktop) */
@media (min-width: 900px) {
  #tll-catalog-filter.tll-catalog-sticky,
  #tll-catalog-filter .tll-catalog-toolbar-stick,
  #tll-catalog-filter {
    --tll-cf-header: 4.4rem;
  }

  #tll-catalog-filter .tll-catalog-toolbar {
    padding: 0.45rem 0;
    gap: 0.45rem 0.65rem;
  }

  #tll-catalog-filter .tll-catalog-panel,
  #tll-catalog-filter .tll-catalog-desktop-facets {
    padding-top: 0.35rem;
    padding-bottom: 0.55rem;
  }

  #tll-catalog-sort {
    min-height: 2.2rem;
    padding: 0.35rem 2rem 0.35rem 0.85rem;
    font-size: 0.88rem;
  }

  #tll-catalog-open {
    min-height: 2.2rem;
    padding: 0.35rem 0.9rem;
    font-size: 0.88rem;
  }

  .tll-chip {
    padding: 0.26rem 0.7rem;
    font-size: 0.82rem;
  }
}

/* Mobile: keep Filter button row tight under hero */
@media (max-width: 899px) {
  #tll-catalog-filter .tll-catalog-toolbar {
    padding: 0.4rem 0 0.55rem;
  }
}

/* === CHIP CONTRAST FIX (2026-09-17) === */
@media (prefers-color-scheme: dark) {
  html:not(.colors-light) .tll-chip {
    background: #1a2129;
    border-color: #9aa3ad;
    color: #f3f0e8 !important;
  }
  html:not(.colors-light) .tll-chip:hover {
    background: #242c35;
    color: #f3f0e8 !important;
  }
  html:not(.colors-light) .tll-chip.is-on,
  html:not(.colors-light) .tll-chip[data-checked="true"] {
    background: var(--tll-cf-accent, #c8ef4a);
    border-color: #c8ef4a;
    color: #14180a !important;
  }
}

/* === HERO–FILTER GAP FIX (2026-09-17) === */
/* No space between compact shop hero and catalog filter */

body.post-type-archive-product .tll-shop-hero.tll-shop-hero--compact {
  margin-bottom: 0 !important;
  padding-bottom: 0.7rem;
}

body.post-type-archive-product #tll-catalog-filter {
  margin-top: 0 !important;
}

/* Kill leftover theme / Woo spacing between hero and filter */
body.post-type-archive-product .tll-shop-hero.tll-shop-hero--compact + *,
body.post-type-archive-product .woocommerce-products-header {
  margin-top: 0 !important;
  padding-top: 0 !important;
}

/* If filter sits after main content open wrappers, still pull flush */
body.post-type-archive-product .site-main > .tll-shop-hero--compact,
body.post-type-archive-product .tll-shop-hero--compact {
  margin-bottom: 0 !important;
}

@media (min-width: 900px) {
  body.post-type-archive-product #tll-catalog-filter {
    padding-top: 0.45rem;
  }
}

@media (max-width: 899px) {
  body.post-type-archive-product #tll-catalog-filter {
    padding-top: 0.4rem;
  }
}
