/* =========================================
   COLLECTIONS PAGE STYLES
========================================= */

.collection-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: calc(var(--topbar-h) + 20px) 20px var(--gap-section-sm) 20px;
  /* topbar + 20px gap */
}

/* --- Header Section --- */
/* Full-width row spanning both grid columns (see grid-column below). Desktop: title
   centred on the page, aligned with the topbar logo. Mobile: title left, filter icon
   right (overrides in the media query). */
.collection-header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 15px;
  margin-bottom: 20px;
}

.collection-heading {
  min-width: 0;
  /* let a long title wrap instead of pushing the icon off-screen */
  text-align: center;
  /* desktop default; mobile resets to left */
}

/* Posh Palace: the collection's name as written, large and light, centred */
.collection-title {
  font-size: 2.4rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--color-ink);
}

/* Empty on a collection with no blurb — the :empty rule collapses the gap. */
.collection-desc {
  margin: 6px auto 0;
  /* auto keeps the blurb block centred under the title */
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-light, #666);
  max-width: 60ch;
  /* Honour the line breaks typed in the admin — otherwise a two-line blurb collapses
     to one line when the newline renders as whitespace. */
  white-space: pre-line;
}

.collection-desc:empty {
  display: none;
}

/* Filter icon — the mobile trigger for the off-canvas panel. Hidden on desktop,
   where the sidebar is always visible so a trigger would do nothing. */
.btn-filter-icon {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border-color);
  background: var(--bg-color);
  color: var(--color-ink);
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 1rem;
}

.btn-filter-label {
  font-family: var(--font-primary);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Sort select — a panel control, so it fills its filter-group width. Shared with
   new-arrivals.html. */
.sort-select {
  width: 100%;
  font-family: var(--font-primary);
  font-size: 0.82rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 10px 32px 10px 14px;
  border: 1px solid var(--text-color);
  background-color: var(--bg-color);
  color: var(--text-color);
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23111111' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  border-radius: 2px;
}

/* Grid while a new sort/filter result is on its way */
.product-grid.is-loading {
  opacity: 0.45;
  pointer-events: none;
  transition: opacity 0.15s;
}

/* --- Active (non-default) filters, each removable --- */
.active-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.active-filters[hidden] {
  display: none;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border-color, #ddd);
  background: var(--surface-subtle, #f7f7f7);
  color: var(--text-color);
  border-radius: 999px;
  font-family: var(--font-primary);
  font-size: 0.78rem;
  cursor: pointer;
}

.filter-chip:hover {
  border-color: var(--text-color);
}

.filter-chip-clear {
  border: none;
  background: none;
  text-decoration: underline;
  color: var(--gray-500);
  padding: 5px 4px;
}

/* --- Content Layout --- */
.collection-content {
  display: grid;
  grid-template-columns: 240px 1fr;
  column-gap: 40px;
  row-gap: 0;
  /* header supplies its own bottom spacing */
  align-items: start;
}

/* Beside the sidebar the page already has its margins, so the grid adds none of its own */
@media (min-width: 993px) {
  .collection-content .product-grid {
    padding: 0 0 8px;
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1280px) {
  .collection-content .product-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Header spans both columns so the title centres on the page (aligned with the
   topbar logo), then the sidebar + grid flow into the next row. */
.collection-header {
  grid-column: 1 / -1;
}

/* --- Sidebar Filters --- */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--overlay-scrim);
  z-index: 999;
}

.sidebar-overlay.active {
  display: block;
}

/* Filter panel header: title + X button on same line (mobile only) */
.filter-panel-header {
  display: none;
}

.sidebar-close-btn {
  display: none;
}

.collection-sidebar {
  position: sticky;
  /* Stick just under the fixed header (topbar + announcement bar). Tied to the same
     --announce-h the topbar uses, so it tracks whether the bar is present. A flat
     100px sat BELOW the content top once the header moved into the products column,
     leaving a gap — the content must clear this value for the sidebar to rest flush. */
  top: calc(var(--topbar-h) + 8px);
}

.filter-group {
  margin-bottom: 30px;
}

.filter-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 15px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.filter-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.filter-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--gray-700);
  cursor: pointer;
  transition: color 0.2s ease;
}

.filter-label:hover {
  color: var(--text-color);
}

.filter-label input[type="checkbox"],
.filter-label input[type="radio"] {
  accent-color: var(--text-color);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.product-count {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--gray-500);
}

/* --- Collection Navigation Links --- */
.collection-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 0.85rem;
  color: var(--gray-700);
  text-decoration: none;
  border-bottom: 1px solid var(--surface-muted);
  transition: color 0.15s;
  font-weight: 400;
}

.collection-nav-link::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--gray-300);
  border-radius: 50%;
  flex-shrink: 0;
  transition: all 0.15s;
}

.collection-nav-link.active {
  color: var(--text-color);
  font-weight: 600;
}

.collection-nav-link.active::before {
  border-color: var(--text-color);
  background: var(--text-color);
  box-shadow: inset 0 0 0 3px var(--bg-color);
}

.collection-nav-link:hover {
  color: var(--text-color);
}

.collection-nav-link:hover::before {
  border-color: var(--gray-500);
}

/* --- Filter Footer (Clear filters link) --- */
.filter-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
  text-align: center;
}

/* --- Nested filter groups (parent → children) --- */
.filter-group-nested {
  margin-bottom: 2px;
}

/* Parent row: radio label LEFT + expand button RIGHT */
.filter-parent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.filter-parent-label {
  flex: 1;
}

.filter-parent-label strong {
  font-weight: 600;
  color: var(--color-ink);
}

/* + / − expand button */
.filter-accordion-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  width: 24px;
  height: 24px;
  font-size: 1rem;
  line-height: 1;
  color: var(--gray-400);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  padding: 0;
}

.filter-accordion-btn:hover {
  color: var(--text-strong);
  border-color: var(--gray-400);
  background: var(--surface-subtle);
}

/* Children: hidden by default, shown via JS toggle */
.filter-children {
  padding-left: 16px;
  margin-top: 6px;
  flex-direction: column;
  gap: 8px;
  border-left: 2px solid var(--surface-alt);
  display: none;
  /* JS sets display:flex when open */
}

.filter-child-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  transition: color 0.15s;
}

.filter-child-label:hover {
  color: var(--text-color);
}

.clear-filters-link {
  font-size: 0.8rem;
  color: var(--gray-500);
  text-decoration: underline;
  cursor: pointer;
  transition: color 0.15s;
}

.clear-filters-link:hover {
  color: var(--text-color);
}

/* --- Mobile Responsive --- */
@media (max-width: 992px) {
  .collection-container {
    padding: calc(var(--topbar-h) + 20px) 0 var(--gap-section-sm) 0;
    /* Keep top padding, remove horizontal for edge-to-edge */
  }

  .collection-content {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .collection-header {
    flex-direction: row;
    justify-content: space-between;
    /* title left, filter icon far right */
    align-items: center;
    padding: 0 20px 15px 20px;
    margin-bottom: 16px;
    /* Add padding back to header since container lost it */
  }

  /* Mobile reads left-to-right — the centred desktop treatment does not fit here. */
  .collection-heading {
    text-align: left;
  }

  .collection-desc {
    margin: 6px 0 0;
    max-width: none;
  }

  /* The icon appears only here — on mobile the sidebar is off-canvas. */
  .btn-filter-icon {
    display: flex;
  }

  .active-filters {
    padding: 0 20px;
  }

  .collection-title {
    font-size: 1.6rem;
    letter-spacing: -0.03em;
  }

  /* Off-canvas Sidebar */
  .collection-sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    /* Hidden to the left */
    width: 85%;
    max-width: 320px;
    height: 100vh;
    background: var(--bg-color);
    z-index: 1000;
    padding: 20px 24px 30px;
    overflow-y: auto;
    transition: left 0.3s ease;
    border: none;
    margin: 0;
  }

  .collection-sidebar.active {
    left: 0;
  }

  /* Header row: "Filters" label + X button on same line */
  .filter-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 16px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
  }

  .filter-panel-title {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--color-ink);
  }

  .sidebar-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: static;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-color);
    padding: 4px;
    line-height: 1;
  }
}

/* =========================================
   COLLECTION INDEX PAGE
   SSR — functions/collection/index.js
   body[data-page="collection-index"]
========================================= */

/* Section heading — "Shop by Collection" */
.coll-index-heading {
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  text-transform: none;
  text-align: center;
  color: var(--text-color);
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}

/* 2-col grid (mobile) → 4-col (desktop) — the same gutters as the product grid */
.coll-index-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px 12px;
  padding: 0 14px;
}

@media (min-width: 769px) {
  .coll-index-grid {
    gap: 28px 24px;
    padding: 0;
  }
}

@media (min-width: 769px) {
  .coll-index-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Individual collection card */
.coll-index-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  background: var(--bg-color);
  cursor: pointer;
}

/* Image wrapper — portrait 4:5 ratio */
.coll-index-card-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: var(--radius-card);
  background-color: var(--surface-alt);
}

.coll-index-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.45s ease;
}

@media (hover: hover) {
  .coll-index-card:hover .coll-index-card-img {
    transform: scale(1.04);
  }
}

/* No-image placeholder */
.coll-index-card-img-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--gray-400);
}

/* Card text: name + item count */
.coll-index-card-info {
  padding: 12px 2px 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.coll-index-card-name {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--color-ink);
  line-height: 1.3;
}

.coll-index-card-count {
  font-size: 0.82rem;
  color: var(--text-muted);
}