/*
 * Full catalogue (archive-ss_product.php), ported from the approved sample prototypes/css/catalogue.css.
 * Header with search, filter rail (desktop), sticky "Filter · Sort" bar + bottom sheet (phones/tablets),
 * results grid with density toggle, quick view.
 */

html.no-scroll { overflow: hidden; }

/* ---------- Header ---------- */
.cathead { padding-block: clamp(24px, 3vw, 40px) clamp(32px, 4vw, 56px); border-bottom: 1px solid var(--line); }
.cathead__inner { display: grid; gap: var(--space-5); }
.cathead__row { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: var(--space-5) var(--space-8); margin-top: var(--space-5); }
.cathead__title { font-size: clamp(3.2rem, 8vw, 7.5rem); font-weight: 300; line-height: 0.9; letter-spacing: -0.045em; }
.cathead__title em { font-style: italic; color: var(--indigo-600); }
.cathead__search { position: relative; flex: 1 1 360px; max-width: 560px; }
.cathead__search svg { position: absolute; left: 22px; top: 50%; translate: 0 -50%; width: 20px; height: 20px; color: var(--ink-3); pointer-events: none; }
.cathead__search input {
  width: 100%; height: 64px; padding: 0 56px 0 56px; border-radius: var(--r-pill); border: 1px solid var(--line-strong);
  background: var(--white); font-size: var(--step-0); box-shadow: var(--shadow-1);
  transition: border-color var(--dur-2), box-shadow var(--dur-2);
}
.cathead__search input:focus { outline: none; border-color: var(--indigo-600); box-shadow: 0 0 0 4px var(--indigo-100); }
.cathead__search kbd {
  position: absolute; right: 20px; top: 50%; translate: 0 -50%; min-width: 24px; height: 24px; display: grid; place-items: center;
  border: 1px solid var(--line-strong); border-radius: 6px; font: 600 12px/1 var(--font-mono); color: var(--ink-3);
}
.cathead__search input:focus + kbd, .cathead__search input:not(:placeholder-shown) + kbd { opacity: 0; }
.cathead__lead { margin: 0; color: var(--text-muted); max-width: 64ch; }
.cathead__divisions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-2); }
.divlink {
  display: flex; align-items: center; gap: var(--space-3); padding: 6px var(--space-5) 6px 6px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--white); text-decoration: none; font-size: var(--step--1);
  transition: border-color var(--dur-2), transform var(--dur-2) var(--ease-out), box-shadow var(--dur-2);
}
.divlink:hover { border-color: transparent; box-shadow: var(--shadow-2); transform: translateY(-2px); }
.divlink__img { width: 48px; height: 48px; border-radius: 50%; overflow: hidden; background: var(--tile-accent); flex: none; }
.divlink__img img { width: 100%; height: 100%; object-fit: cover; scale: var(--crop, 1); }
.divlink__img.is-specimen { background: #000; }
.divlink strong { display: block; font-weight: 700; }
.divlink small { color: var(--text-subtle); font-size: var(--step--2); }

/* ---------- Layout ---------- */
.catlayout { display: grid; grid-template-columns: 272px minmax(0, 1fr); gap: clamp(32px, 4vw, 64px); padding-block: var(--space-6) var(--section); align-items: start; }

/* ---------- Filter rail ---------- */
.rail { position: sticky; top: calc(var(--header-h) + var(--space-5)); }
.rail__scrim, .rail__close, .rail__foot { display: none; }
.rail__panel { display: grid; gap: var(--space-4); max-height: calc(100vh - var(--header-h) - var(--space-7)); overflow: auto; padding-right: var(--space-3); scrollbar-width: thin; }
.rail__head { display: flex; align-items: center; gap: var(--space-3); padding-bottom: var(--space-3); border-bottom: 1px solid var(--line); }
.rail__title { font: 700 var(--step--1)/1 var(--font-body); letter-spacing: 0.12em; text-transform: uppercase; margin-right: auto; }
.rail__clear { border: 0; background: none; padding: 0; font-weight: 700; font-size: var(--step--1); color: var(--indigo-600); text-decoration: underline; text-underline-offset: 3px; }
.rail__body { display: grid; gap: var(--space-5); }
.rail__group { margin: 0; padding: 0 0 var(--space-5); border: 0; border-bottom: 1px solid var(--line); min-width: 0; }
.rail__group legend, .rail__legend { margin: 0 0 var(--space-3); padding: 0; font: 700 var(--step--2)/1 var(--font-body); letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-subtle); }
.rail__group .check { padding-inline: var(--space-2); }
.rail__group .check:hover { background: var(--paper-2); }

.tree { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.tree--1 { padding-left: var(--space-4); margin-block: 2px var(--space-2); border-left: 1px solid var(--line); margin-left: 11px; }
.tree--2 { padding-left: var(--space-3); }
.tree__item { position: relative; }
.tree__btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: 7px var(--space-2) 7px var(--space-2); border: 0; border-radius: var(--r-sm); background: none; text-align: left;
  font-size: var(--step--1); color: var(--text-muted); transition: background-color var(--dur-1), color var(--dur-1);
}
.tree--0 > .tree__item > .tree__btn { font-weight: 700; color: var(--text); padding-left: 30px; }
.tree__btn--all { font-weight: 700; color: var(--text); }
.tree__btn small { font-size: 12px; font-weight: 600; color: var(--text-subtle); font-variant-numeric: tabular-nums; }
.tree__btn:hover { background: var(--paper-2); color: var(--text); }
.tree__btn[aria-pressed="true"] { background: var(--ink); color: var(--white); }
.tree__btn[aria-pressed="true"] small { color: rgb(255 255 255 / 0.7); }
.tree__toggle {
  position: absolute; left: 2px; top: 4px; z-index: 1; width: 26px; height: 26px; border: 0; border-radius: var(--r-sm); background: none;
  display: grid; place-items: center;
}
.tree__toggle::before { content: ""; width: 7px; height: 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; rotate: -45deg; transition: rotate var(--dur-2) var(--ease-out); }
.tree__toggle[aria-expanded="true"]::before { rotate: 45deg; translate: 0 -2px; }
.tree__toggle:hover { background: var(--paper-2); }
.tree--1 .has-kids > .tree__btn { padding-left: 30px; }
.tree__item:has(> .tree__btn[aria-pressed="true"]) > .tree__toggle { color: var(--white); }

/* 3D switch */
.rail__toggle { padding-bottom: var(--space-5); }
.switch { display: flex; align-items: center; gap: var(--space-3); cursor: pointer; font-size: var(--step--1); font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track { position: relative; width: 40px; height: 24px; border-radius: var(--r-pill); background: var(--line-strong); transition: background-color var(--dur-2); flex: none; }
.switch__track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--white); box-shadow: var(--shadow-1); transition: translate var(--dur-2) var(--ease-out); }
.switch input:checked + .switch__track { background: var(--indigo-600); }
.switch input:checked + .switch__track::after { translate: 16px 0; }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--focus); outline-offset: 3px; }
.switch small { color: var(--text-subtle); font-weight: 600; margin-left: 4px; }

/* Colour families */
.colours { display: grid; grid-template-columns: 1fr 1fr; gap: 2px var(--space-2); }
.colour { position: relative; display: flex; align-items: center; gap: var(--space-2); padding: 6px var(--space-2); border-radius: var(--r-sm); cursor: pointer; font-size: var(--step--2); font-weight: 600; min-width: 0; }
.colour:hover { background: var(--paper-2); }
.colour input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.colour__dot { width: 20px; height: 20px; border-radius: 50%; flex: none; background: var(--c); box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.14); transition: box-shadow var(--dur-1); }
.colour input:checked + .colour__dot { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--ink); }
.colour input:focus-visible + .colour__dot { outline: 2px solid var(--focus); outline-offset: 4px; }
.colour input:disabled ~ * { opacity: 0.4; }
.colour__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.colour small { margin-left: auto; color: var(--text-subtle); font-size: 11px; }
.check input:disabled ~ span { opacity: 0.45; }

/* ---------- Results ---------- */
.results__bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); padding-bottom: var(--space-4); border-bottom: 1px solid var(--line); }
.results__filters { display: none; }
.results__count { margin: 0 auto 0 0; font-size: var(--step--1); color: var(--text-muted); }
.results__count strong { color: var(--text); font-size: var(--step-0); }
.results__controls { display: flex; align-items: center; gap: var(--space-3); }
.select { position: relative; }
.select select {
  appearance: none; height: 40px; padding: 0 40px 0 var(--space-4); border-radius: var(--r-pill); border: 1px solid var(--line-strong);
  background: var(--white); font-size: var(--step--1); font-weight: 600; cursor: pointer;
}
.select::after { content: ""; position: absolute; right: 18px; top: 50%; width: 7px; height: 7px; border-right: 1.5px solid; border-bottom: 1.5px solid; rotate: 45deg; translate: 0 -70%; pointer-events: none; }
.density { display: inline-flex; padding: 3px; border-radius: var(--r-pill); background: var(--paper-2); }
.density button { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 var(--space-3); border: 0; border-radius: var(--r-pill); background: none; font-size: var(--step--2); font-weight: 700; color: var(--text-muted); }
.density button svg { width: 16px; height: 16px; }
.density button[aria-pressed="true"] { background: var(--white); color: var(--text); box-shadow: var(--shadow-1); }
.active-filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); padding-block: var(--space-4); min-height: 20px; }
.chip--remove { background: var(--indigo-50); border-color: transparent; }
.chip--remove:hover { border-color: var(--indigo-600); }
.active-filters .rail__clear { margin-left: var(--space-2); }

.results__grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(40px, 4vw, 64px) clamp(20px, 2vw, 32px); padding-top: var(--space-4); }
.results__grid[data-density="compact"] { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-6) var(--space-4); }
.results__grid > .empty { grid-column: 1 / -1; }
.results__grid .empty p { max-width: 52ch; margin: 0 auto var(--space-5); }
.results__grid .pcard--compact .pcard__actions .btn { padding-inline: var(--space-3); font-size: var(--step--2); }

@media (max-width: 1280px) {
  .results__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .results__grid[data-density="compact"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .cathead__search { flex-basis: 100%; }
  .cathead__search input { height: 56px; font-size: var(--step--1); }
  .cathead__divisions { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: calc(-1 * var(--gutter)); padding-inline: var(--gutter); }
  .divlink { flex: none; }
  .results__bar { gap: var(--space-3); }
  .results__count { order: 3; flex-basis: 100%; }
  .results__controls { margin-left: auto; }
  .density button span { display: none; }
}
@media (max-width: 560px) {
  .density { display: none; } /* phones always show two per row */
}

/* ---------- Quick view ---------- */
.qv { position: fixed; inset: 0; z-index: 95; }
.qv[hidden] { display: none; }
.qv__scrim { position: absolute; inset: 0; background: rgb(17 11 48 / 0.45); opacity: 0; transition: opacity var(--dur-2); }
.qv__panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(960px, 100%); background: var(--paper); display: grid; grid-template-rows: auto 1fr auto;
  translate: 100% 0; transition: translate var(--dur-3) var(--ease-out); box-shadow: var(--shadow-3); outline: none;
}
.qv.is-open .qv__scrim { opacity: 1; }
.qv.is-open .qv__panel { translate: 0 0; }
.qv__head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5) var(--space-4) var(--space-6); border-bottom: 1px solid var(--line); }
.qv__body { overflow: auto; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: var(--space-6); padding: var(--space-6); align-content: start; }
.qv__gallery { display: grid; gap: var(--space-3); align-content: start; }
.qv__main { aspect-ratio: 1; border-radius: var(--r-md); overflow: hidden; background: var(--paper-2); }
.qv__main img { width: 100%; height: 100%; object-fit: cover; scale: var(--crop, 1); }
.qv__main.is-specimen { background: #000; }
.qv__main.is-specimen img { object-fit: contain; }
.qv__swatchfill { display: block; width: 100%; height: 100%; }
.qv__thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-2); }
.qv__thumb { aspect-ratio: 1; padding: 0; border: 0; border-radius: var(--r-sm); overflow: hidden; background: var(--paper-2); opacity: 0.6; transition: opacity var(--dur-1); }
.qv__thumb.is-specimen { background: #000; }
.qv__thumb img { width: 100%; height: 100%; object-fit: cover; scale: var(--crop, 1); }
.qv__thumb.is-specimen img { object-fit: contain; }
.qv__thumb[aria-pressed="true"], .qv__thumb:hover { opacity: 1; box-shadow: inset 0 0 0 2px var(--ink); }
.qv__info { display: grid; gap: var(--space-4); align-content: start; }
.qv__title { font-size: var(--step-4); font-weight: 300; line-height: 1; }
.qv__title em { font-style: italic; }
.qv__code { margin: 0; font-size: var(--step--1); color: var(--text-muted); }
.qv__code .code { color: var(--accent-ink); }
.qv__summary { margin: 0; color: var(--text-muted); }
.qv__field { display: grid; gap: var(--space-3); padding-top: var(--space-4); border-top: 1px solid var(--line); }
.qv__label { margin: 0; display: flex; justify-content: space-between; gap: var(--space-3); font-size: var(--step--2); font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-subtle); }
.qv__label > span { text-transform: none; letter-spacing: 0; font-size: var(--step--1); font-weight: 600; color: var(--text); }
.qv__swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.qv__sizes { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.qv__sizes .chip { min-height: 32px; padding-inline: var(--space-3); }
.qv__specs { margin: 0; display: grid; gap: var(--space-3); padding-top: var(--space-4); border-top: 1px solid var(--line); }
.qv__specs div { display: grid; grid-template-columns: 96px 1fr; gap: var(--space-3); font-size: var(--step--1); }
.qv__specs dt { color: var(--text-subtle); font-weight: 600; }
.qv__specs dd { margin: 0; }
.qv__foot { display: flex; flex-wrap: wrap; gap: var(--space-3); padding: var(--space-4) var(--space-6); border-top: 1px solid var(--line); background: var(--paper); }
.qv__foot .btn { flex: 1 1 200px; }
@media (max-width: 760px) {
  .qv__body { grid-template-columns: 1fr; padding: var(--space-5); gap: var(--space-5); }
  .qv__head, .qv__foot { padding-inline: var(--space-5); }
}

/* ---------- Show more ---------- */
.results__more { grid-column: 1 / -1; display: grid; justify-items: center; gap: var(--space-3); padding-top: var(--space-5); border-top: 1px solid var(--line); }
.results__more p { margin: 0; font-size: var(--step--1); color: var(--text-subtle); }

/* ---------- Theme additions ---------- */
.tree a.tree__btn { text-decoration: none; }
.results__grid .pcard[hidden] { display: none; }
.results__empty[hidden] { display: none; }
.cathead__search input::-webkit-search-cancel-button { cursor: pointer; }
.cathead__search .icon { position: absolute; left: 22px; top: 50%; translate: 0 -50%; width: 20px; height: 20px; color: var(--ink-3); pointer-events: none; }
.qv__swatches .swatch { position: relative; }
.qv__main img, .qv__thumb img { display: block; }
.qv__dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--c); vertical-align: -1px; margin-right: 6px; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.14); }

/* Phones & tablets: no rail; a sticky Filter · Sort bar opens the bottom sheet. */
.mbar { display: none; }
@media (max-width: 1000px) {
  .catlayout { grid-template-columns: minmax(0, 1fr); padding-top: var(--space-4); }
  .rail, .results__sort { display: none; }
  .mbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: flex; align-items: center; justify-content: center; gap: var(--space-3);
    padding: var(--space-3) var(--gutter) calc(var(--space-3) + env(safe-area-inset-bottom));
    background: rgb(247 244 239 / 0.92); backdrop-filter: saturate(1.4) blur(14px); border-top: 1px solid var(--line);
  }
  .mbar__btn { min-height: 48px; flex: 0 1 320px; }
  .mbar__count { font-size: var(--step--1); color: var(--text-muted); white-space: nowrap; }
  body:has(.mbar) .site-footer { padding-bottom: calc(var(--space-6) + 76px + env(safe-area-inset-bottom)); }
  .qv { z-index: 115; }
}
@media (max-width: 640px) {
  .cathead__title { font-size: clamp(3rem, 15vw, 4.2rem); }
  .cathead__search input { font-size: 16px; }
  .results__count { order: 0; flex-basis: auto; }
  .results__bar { flex-wrap: nowrap; }
  .density button { height: 40px; }
  .qv__panel { width: 100%; }
  .qv__foot { padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom)); }
  .qv__swatches { gap: 12px; }
}
@media (pointer: coarse) {
  .tree__btn { min-height: 44px; }
  .qv__sizes .chip { min-height: 44px; }
}
@media (pointer: coarse) { .cathead__search kbd { display: none; } .cathead__search input { padding-right: var(--space-5); } }
