/* ==========================================================================
   products-index — the list view of the collection. The SAME cards as the
   gallery are restyled as rows when .products-gallery[data-view="index"]
   (set by <collection-view>), so one list serves both views. Row = number | title | designer | material | code.
   Desktop with a mouse: no thumbnails, a large image follows the cursor.
   Touch / tablet: a small thumbnail per row. Without JS: gallery view.
   ========================================================================== */

/* gallery view: the index-only parts stay hidden */
.product-card__num {
  display: none;
}

.product-card__material {
  display: none;
}

.products-gallery[data-view='index'] .products-gallery__grid {
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  border-bottom: var(--border-hairline);
  counter-reset: row;
}

/* undo the gallery rhythm (spans, offsets, ratios) for every card */
.products-gallery[data-view='index'] .products-gallery__grid .products-gallery__item {
  grid-column: auto;
  margin-top: 0;
  counter-increment: row;
}

.products-gallery[data-view='index'] .product-card {
  position: relative;
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr) auto;
  grid-template-areas:
    'thumb title code'
    'thumb sub sub';
  gap: var(--space-3xs) var(--space-sm);
  align-items: center;
  padding-block: var(--space-sm);
  border-top: var(--border-hairline);
  transition: background-color var(--duration-fast) var(--ease-out);
}

.products-gallery[data-view='index'] .product-card__body {
  display: contents;
}

.products-gallery[data-view='index'] .product-card__media {
  --image-ratio: 1 / 1;

  grid-area: thumb;
  border-radius: var(--radius-sm);
}

.products-gallery[data-view='index'] .product-card__badges {
  display: none;
}

.products-gallery[data-view='index'] .product-card__title {
  grid-area: title;
  font-size: var(--text-lg);
}

.products-gallery[data-view='index'] .product-card__meta {
  grid-area: code;
  justify-self: end;
}

/* Phones: the material sits under the title */
.products-gallery[data-view='index'] .product-card__material {
  display: block;
  grid-area: sub;
}

.products-gallery[data-view='index'] .product-card__vendor {
  display: none;
  grid-area: vendor;
}

/* Tablet and up: all columns */
@media (min-width: 48em) {
  .products-gallery[data-view='index'] .product-card {
    grid-template-columns: 4rem minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) 7rem;
    grid-template-areas: 'thumb title vendor material code';
    gap: var(--space-md);
    padding-block: var(--space-md);
  }

  .products-gallery[data-view='index'] .product-card__title {
    font-size: var(--text-xl);
  }

  .products-gallery[data-view='index'] .product-card__vendor,
  .products-gallery[data-view='index'] .product-card__material {
    display: block;
  }

  .products-gallery[data-view='index'] .product-card__material {
    grid-area: material;
  }
}

/* Desktop with a mouse: number instead of thumbnail, image follows the cursor */
@media (min-width: 64em) and (hover: hover) and (pointer: fine) {
  .products-gallery[data-view='index'] .product-card {
    grid-template-columns: 3rem minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) 8rem;
    grid-template-areas: 'num title vendor material code';
  }

  .products-gallery[data-view='index'] .product-card__media {
    display: none;
  }

  .products-gallery[data-view='index'] .product-card__num {
    display: block;
    grid-area: num;
  }

  .products-gallery[data-view='index'] .product-card__num::before {
    content: counter(row, decimal-leading-zero);
  }

  .products-gallery[data-view='index'] .product-card:hover,
  .products-gallery[data-view='index'] .product-card:focus-within {
    background-color: var(--palette-lime);
    color: var(--palette-ink);
  }

  .products-gallery[data-view='index'] .product-card:hover .caption--muted,
  .products-gallery[data-view='index'] .product-card:focus-within .caption--muted {
    color: var(--palette-ink);
  }
}

/* The floating preview (created by collection-view.js) */
.products-index__preview {
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--z-modal);
  display: none;
  width: 16rem;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity var(--duration-fast) var(--ease-out),
    transform 140ms var(--ease-out);
}

.products-index__preview .image {
  --image-ratio: 4 / 5;

  box-shadow: var(--shadow-md);
}

.products-index__preview.is-visible {
  opacity: 1;
}

@media (min-width: 64em) and (hover: hover) and (pointer: fine) {
  .products-index__preview {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  .products-index__preview {
    transition: opacity var(--duration-fast) linear;
  }
}
