/* ==========================================================================
   MAGNETIE — Product Catalog & Showroom System (Function D)
   Styles the real ProductCard/ProductGrid component (used both to hydrate
   Function C's homepage preview shells and to build shop.html's showroom),
   the showroom page chrome (title/count/toolbar), and the filter/sort
   controls. Loaded on index.html (after home.css) and shop.html.

   The .product-card* rules intentionally mirror home.css's placeholder
   card exactly (same class names/values) rather than modifying Function
   C's stylesheet, so shop.html can load this file alone without pulling in
   home.css's hero/campaign/footer rules — see ARCHITECTURE.md "Function D"
   for the reasoning.
   ========================================================================== */

/* ==========================================================================
   PRODUCT CARD
   ========================================================================== */

.product-card {
  position: relative;
  display: block;
}

.product-card__link {
  display: block;
  color: inherit;
}

/* Frontend redesign: model photography on a clean white ground, no card
   chrome (no tint, radius or border); text set small and quiet beneath. */

.product-card__media {
  position: relative;
  aspect-ratio: 3 / 4;
  background: var(--color-surface);
  overflow: hidden;
}

/* No auto-crop/auto-zoom: every image is shown whole (object-fit: contain),
   letterboxed on the card's own background if its ratio doesn't exactly
   fill the 3:4 frame above — source photography is exported at whatever
   ratio the shoot used (currently 2:3 for FW26, 1:1 for SS26), and is
   shown as-is rather than being cropped/zoomed to force-fill the frame.
   The image stays transparent until data-loaded is set (on load/error) so
   it never flashes unstyled. */
.product-card__media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  opacity: 0;
  transition: opacity var(--duration-base) var(--ease-standard);
}

.product-card__media img[data-loaded] {
  opacity: 1;
}

.product-card--soldout .product-card__media img[data-loaded] {
  opacity: 0.45;
}

/* Badge: small text tag on white, not a filled block. */
.product-card__badge {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  padding: 2px 6px;
  background: var(--color-surface);
  color: var(--color-ink);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.product-card__badge--sale {
  color: var(--color-sale);
}

.product-card__badge--soldout {
  color: var(--color-ink-muted);
}

/* Heart sits over the image's top-right corner (absolute to the card). */
.product-card__wishlist {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  z-index: 1;
  display: flex;
  color: var(--color-ink);
}

.product-card__wishlist svg {
  width: 18px;
  height: 18px;
}

.product-card__wishlist:hover {
  color: var(--color-accent);
}

/* Info below the image (js/product-grid.js renderProductCard), in order:
   colour swatches | size range, name, price, promotion line, review score —
   small type so the image stays the bulk of the card. */
.product-card__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-top: var(--space-2);
}

.product-card__meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 18px;
}

.product-card__swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Colour dot with a white inner ring; a link to the product page with that
   colour chosen. */
.product-card__swatch {
  display: block;
  cursor: pointer;
  width: 18px;
  height: 18px;
  border: 2px solid var(--color-surface);
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 1px var(--color-line);
}

.product-card__sep {
  color: var(--color-line-strong);
  font-size: 0.75rem;
}

.product-card__sizes {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--color-ink-soft);
}

.product-card__name {
  font-size: var(--fs-small);
  font-weight: 400;
  line-height: var(--lh-snug);
  color: var(--color-ink);
}

.product-card__link:hover .product-card__name {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.product-card__price {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: var(--space-2);
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-ink);
}

.product-card__price-current--sale {
  color: var(--color-sale);
}

.product-card__price-original {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--color-ink-muted);
  text-decoration: line-through;
}

.product-card__promo {
  font-size: 0.75rem;
  color: var(--color-sale);
}

.product-card__rating {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.75rem;
  color: var(--color-ink-soft);
}

.product-card__rating-star {
  color: var(--color-ink);
}

.product-card__availability {
  font-size: 0.75rem;
  color: var(--color-ink-muted);
}

.product-card__availability--low {
  color: var(--color-sale);
}

/* ==========================================================================
   PRODUCT GRID
   ========================================================================== */

.product-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-7) var(--space-5);
}

@media (max-width: 1024px) {
  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Phones: two products per row (Uniqlo-style), tight gutters so the 3:4
   images stay large. */
@media (max-width: 768px) {
  .product-grid {
    gap: var(--space-6) var(--space-2);
  }
}

.product-grid__empty {
  padding-block: var(--space-9);
  text-align: center;
  color: var(--color-ink-soft);
}

.product-grid__empty p:first-child {
  font-family: var(--font-display);
  font-size: var(--fs-display-sm);
  color: var(--color-ink);
}

.product-grid__empty .showroom__clear {
  margin-top: var(--space-3);
}

/* Loading / error state while the grid waits on the catalog API. Spans the
   full grid width so it centers like .product-grid__empty. */
.product-grid__status {
  grid-column: 1 / -1;
  padding-block: var(--space-9);
  text-align: center;
  color: var(--color-ink-soft);
}

.product-grid__status .showroom__clear {
  margin-top: var(--space-3);
}

.product-grid__empty {
  grid-column: 1 / -1;
}

.showroom__more {
  display: flex;
  justify-content: center;
  margin-top: var(--space-5);
}

/* ==========================================================================
   SHOWROOM (shop.html)
   ========================================================================== */

/* No gap under the site header; the bottom matches the homepage's last
   product grid -> footer spacing. */
.showroom {
  padding-block: 0 var(--space-5);
  background: var(--color-surface);
}

/* Title + bar stick under the site header. Collapsed (scrolling down), the
   sticky top moves up by the title's height (--showroom-head-h, measured in
   js/product-grid.js) so the title slides under the header and only the bar
   shows; changing `top` never shifts the page layout. */
.showroom__sticky {
  position: sticky;
  top: calc(var(--header-height) + var(--announce-offset));
  z-index: calc(var(--z-header) - 1);
  margin-bottom: var(--space-5);
  background: var(--color-surface);
  transition: top var(--duration-base) var(--ease-standard);
}

.showroom__sticky.is-collapsed {
  top: calc(var(--header-height) + var(--announce-offset) - var(--showroom-head-h, 0px));
}

/* The filter drawer lives inside the bar; lift the whole block above the
   header while it is open so the drawer covers the full screen. */
body.has-filter-drawer .showroom__sticky {
  z-index: var(--z-modal);
}

.showroom__loading {
  min-height: 1.5em;
  font-size: var(--fs-small);
  color: var(--color-ink-soft);
}

/* header -> title gap = title -> item count gap (~24px): 24px above; 8px
   below + the bar's own ~15px above its centred count. */
.showroom__head {
  padding-block: var(--space-5) var(--space-2);
}

.showroom__title {
  font-size: var(--fs-display-lg);
}

/* ---------------- Bar: count | Sort by + Filter ----------------
   One compact row between hairlines (Uniqlo-style). The facets are not on
   the page; they open in the filter drawer below. */

.showroom__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 48px;
  border-block: var(--border-hairline);
}

.showroom__count {
  font-size: var(--fs-small);
  color: var(--color-ink-soft);
}

.showroom__toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-5);
}

.showroom__action {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--color-ink);
  cursor: pointer;
}

/* Small chevron after "Sort by" / "Filter". */
.showroom__action::after {
  content: "";
  width: 6px;
  height: 6px;
  margin: -3px 0 0 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
}

/* "Sort by" opens a small menu under the bar, in the site's type. */
.showroom__sort {
  position: relative;
  display: flex;
}

.showroom__sort-menu {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-width: 200px;
  padding-block: var(--space-2);
  background: var(--color-surface);
  border: var(--border-hairline);
  box-shadow: var(--shadow-card);
}

.showroom__sort-menu[hidden] {
  display: none;
}

.showroom__sort-option {
  padding: var(--space-2) var(--space-4);
  font-size: var(--fs-small);
  text-align: left;
  white-space: nowrap;
  color: var(--color-ink-soft);
}

.showroom__sort-option:hover,
.showroom__sort-option[aria-pressed="true"] {
  color: var(--color-ink);
}

.showroom__sort-option[aria-pressed="true"] {
  font-weight: 600;
}

.showroom__action:hover {
  color: var(--color-ink-soft);
}

.showroom__toolbar > .showroom__action .facet__count {
  order: 1;
}

.showroom__toolbar > .showroom__action::after {
  order: 2;
}

/* ---------------- Filter drawer ----------------
   Right-hand panel on desktop/tablet, full screen on phones. Facets are
   stacked <details> sections; a change applies immediately. */

.filter-drawer {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
}

.filter-drawer[hidden] {
  display: none;
}

.filter-drawer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 17, 17, 0.35);
}

.filter-drawer__panel {
  position: absolute;
  inset: 0 0 0 auto;
  display: flex;
  flex-direction: column;
  width: min(420px, 100%);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.filter-drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  border-bottom: var(--border-hairline);
}

.filter-drawer__title {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
}

.filter-drawer__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-right: calc(var(--space-3) * -1);
  font-size: 1.75rem;
  line-height: 1;
  color: var(--color-ink);
}

.filter-drawer__body {
  flex: 1;
  overflow-y: auto;
  padding-inline: var(--space-5);
}

.filter-drawer__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-top: var(--border-hairline);
}

.filter-drawer__done {
  flex: 1;
  max-width: 220px;
  padding: var(--space-3) var(--space-4);
  background: var(--color-ink);
  color: var(--color-surface);
  font-size: var(--fs-small);
  font-weight: 600;
}

.filter-drawer__done:hover {
  background: var(--color-ink-soft);
}

body.has-filter-drawer {
  overflow: hidden;
}

/* Facet sections inside the drawer */

.facet {
  border-bottom: var(--border-hairline);
}

.facet__summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 52px;
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--color-ink);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.facet__summary::-webkit-details-marker {
  display: none;
}

.facet__summary::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-right: 1.5px solid var(--color-ink-soft);
  border-bottom: 1.5px solid var(--color-ink-soft);
  transform: rotate(45deg);
  transition: transform var(--duration-fast) var(--ease-standard);
}

.facet[open] .facet__summary::after {
  transform: rotate(-135deg);
}

.facet__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding-inline: 3px;
  border-radius: var(--radius-pill);
  background: var(--color-ink);
  color: var(--color-surface);
  font-size: 0.625rem;
}

.facet__panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-bottom: var(--space-4);
}

.facet__option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-small);
  cursor: pointer;
}

.facet__option input {
  width: 16px;
  height: 16px;
  accent-color: var(--color-ink);
}

.facet__option-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--color-line);
}

/* Price: two range inputs on one track, 22px round handles. The inputs ignore
   the pointer so both handles stay reachable; only the handles take it. The
   fill starts half a handle in, where the handle's centre really is. */
.price-range {
  --handle: 22px;
  position: relative;
  height: 28px;
}

.price-range::before,
.price-range::after {
  content: "";
  position: absolute;
  top: 50%;
  height: 2px;
  margin-top: -1px;
}

.price-range::before {
  left: 0;
  right: 0;
  background: var(--color-line);
}

.price-range::after {
  left: calc(var(--handle) / 2 + (100% - var(--handle)) * var(--from));
  right: calc(var(--handle) / 2 + (100% - var(--handle)) * (1 - var(--to)));
  background: var(--color-ink);
}

.price-range input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}

.price-range input::-webkit-slider-thumb {
  width: var(--handle);
  height: var(--handle);
  border: 1.5px solid var(--color-ink);
  border-radius: 50%;
  background: var(--color-surface);
  cursor: grab;
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
}

.price-range input::-moz-range-thumb {
  box-sizing: border-box;
  width: var(--handle);
  height: var(--handle);
  border: 1.5px solid var(--color-ink);
  border-radius: 50%;
  background: var(--color-surface);
  cursor: grab;
  pointer-events: auto;
}

.price-range input::-moz-range-track {
  background: none;
}

.price-range__values {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-small);
  color: var(--color-ink-soft);
}

.showroom__clear {
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-nav);
  font-weight: 500;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--color-ink-soft);
  border-bottom: 1px solid transparent;
}

.showroom__clear:hover {
  color: var(--color-ink);
  border-color: var(--color-ink);
}

@media (max-width: 768px) {
  .showroom__title {
    font-size: var(--fs-display-sm);
  }

  .showroom__sticky {
    margin-bottom: var(--space-4);
  }

  .showroom__toolbar {
    gap: var(--space-4);
  }

  .filter-drawer__panel {
    width: 100%;
  }
}
