/*
 * Storefront PLP (product listing page) styles — docs/webshop 06 §6 + §15.11.
 *
 * Page-scoped CSS loaded only by the PLP (host per-page asset pattern). EXTENDS
 * shop-tokens.css / shop-components.css (sh-* system) — references --sh-* /
 * host tokens, never hardcodes brand colors. Mobile-first: facets are a
 * bottom-sheet drawer on <lg and a sticky left rail on lg+; the results grid
 * reuses .sh-grid. Progressive enhancement — everything is usable without JS;
 * the drawer open/close + grid/list toggle are JS niceties (P2.5), and the
 * layout degrades to the facet form stacked above the grid when JS is absent.
 *
 * Breakpoints match shop-components.css: 576 / 768 / 1024(lg) / 1280.
 * Contrast verified against tokens (AA). Hand-authored, ?v= cache-busted.
 */

/* Screen-reader-only utility (labels for icon-only controls / swatches). */
.sh-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

/* =============================================================== *
 * Page header (H1 + count + intro)
 * =============================================================== */
.sh-plp { padding-block: var(--sh-space-5) var(--sh-space-8); }
.sh-plp__head { margin-bottom: var(--sh-space-4); }
.sh-plp__head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--sh-space-2) var(--sh-space-4);
}
.sh-plp__title {
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 700;
  line-height: 1.15;
  margin: 0;
}
.sh-plp__count { color: var(--c-muted); font-size: 14px; margin: 0; }
.sh-plp__intro {
  margin-top: var(--sh-space-3);
  color: var(--c-text);
  max-width: 70ch;
  line-height: 1.6;
}
.sh-plp__intro p:last-child { margin-bottom: 0; }

/* =============================================================== *
 * Toolbar (mobile Filter/Sort; desktop sort + grid/list toggle)
 * =============================================================== */
.sh-plp__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sh-space-3);
  flex-wrap: wrap;
  padding-block: var(--sh-space-3);
  border-block: 1px solid var(--c-border);
  position: sticky;
  top: var(--header-h, 0);
  background: var(--sh-surface);
  z-index: 5;
}
.sh-plp__toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--sh-space-3);
  margin-left: auto;
}

/* Filter toggle (opens the drawer on <lg; hidden on lg where rail is inline). */
.sh-plp__filter-toggle { position: relative; }
.sh-plp__filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding-inline: 6px;
  border-radius: var(--sh-radius-pill);
  background: var(--c-blue);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

/* Sort */
.sh-plp__sort { display: inline-flex; align-items: center; gap: var(--sh-space-2); }
.sh-plp__sort-label { font-size: 13px; color: var(--c-muted); white-space: nowrap; }
.sh-plp__sort-select {
  appearance: none;
  -webkit-appearance: none;
  min-height: 40px;
  padding: 6px 34px 6px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius, 8px);
  background: var(--sh-surface) url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='%23667085' d='M8 11L3 6h10z'/%3E%3C/svg%3E") no-repeat right 12px center;
  font-size: 14px;
  color: var(--c-text);
  cursor: pointer;
}

/* Grid / list toggle */
.sh-plp__view {
  display: inline-flex;
  border: 1px solid var(--c-border);
  border-radius: var(--radius, 8px);
  overflow: hidden;
}
.sh-plp__view-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-height: 40px;
  background: var(--sh-surface);
  color: var(--c-muted);
  border: 0;
  cursor: pointer;
}
.sh-plp__view-btn + .sh-plp__view-btn { border-left: 1px solid var(--c-border); }
.sh-plp__view-btn.is-active { background: var(--c-bg-soft); color: var(--c-text); }

/* =============================================================== *
 * Active-filter chips
 * =============================================================== */
.sh-plp__chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sh-space-2);
  padding-block: var(--sh-space-3);
}
.sh-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--sh-radius-pill);
  border: 1px solid var(--c-border);
  background: var(--c-bg-soft);
  color: var(--c-text);
  font-size: 13px;
  line-height: 1;
  text-decoration: none;
}
.sh-chip--active:hover { border-color: var(--sh-danger); color: var(--sh-danger); }
.sh-chip--active .bi { font-size: 15px; }
.sh-chip--clear {
  background: transparent;
  border-style: dashed;
  color: var(--c-blue);
}
.sh-chip--clear:hover { color: var(--c-blue-d, var(--c-navy)); }

/* =============================================================== *
 * Body layout (facet rail + results)
 * =============================================================== */
.sh-plp__body { display: block; margin-top: var(--sh-space-4); }
.sh-plp__grid { margin-top: 0; }

/* List view: card becomes a horizontal row (JS sets data-view="list"). */
.sh-plp__grid[data-view="list"] {
  grid-template-columns: 1fr;
  gap: var(--sh-space-3);
}
.sh-plp__grid[data-view="list"] .sh-card { flex-direction: row; }
.sh-plp__grid[data-view="list"] .sh-card__link { flex-direction: row; align-items: stretch; }
.sh-plp__grid[data-view="list"] .sh-card__media { flex: 0 0 40%; max-width: 220px; }
.sh-plp__grid[data-view="list"] .sh-card__body { flex: 1 1 auto; }
.sh-plp__grid[data-view="list"] .sh-card__desc { -webkit-line-clamp: 3; }

/* =============================================================== *
 * Facet rail / drawer
 * =============================================================== */
.sh-plp__facets {
  background: var(--sh-surface);
}
/* Drawer chrome (shown only when the panel is a mobile bottom-sheet). */
.sh-plp__facets-drawerhead {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: var(--sh-space-4);
  border-bottom: 1px solid var(--c-border);
}
.sh-plp__facets-drawertitle { font-weight: 700; font-size: 16px; }
.sh-plp__facets-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--sh-tap);
  height: var(--sh-tap);
  border: 0;
  background: transparent;
  color: var(--c-text);
  cursor: pointer;
}
.sh-plp__scrim {
  position: fixed;
  inset: 0;
  background: var(--sh-overlay);
  z-index: var(--sh-z-drawer);
}
.sh-plp__scrim[hidden] { display: none; }

/* Facet groups */
.sh-facets { display: flex; flex-direction: column; gap: var(--sh-space-2); }
.sh-facets__head { display: none; } /* desktop rail: title shown by section; mobile: drawer head */
.sh-facet {
  border-bottom: 1px solid var(--c-border);
  padding-block: var(--sh-space-2);
}
.sh-facet__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  padding-block: var(--sh-space-2);
  list-style: none;
}
.sh-facet__summary::-webkit-details-marker { display: none; }
.sh-facet__summary::after {
  content: "";
  width: 10px; height: 10px;
  border-right: 2px solid var(--c-muted);
  border-bottom: 2px solid var(--c-muted);
  transform: rotate(45deg);
  transition: transform var(--sh-dur) var(--ease, ease);
}
.sh-facet[open] > .sh-facet__summary::after { transform: rotate(-135deg); }

.sh-facet__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; }
.sh-facet__row { margin: 0; }
.sh-facet__opt {
  display: flex;
  align-items: center;
  gap: var(--sh-space-2);
  padding: 8px 4px;
  min-height: 36px;
  cursor: pointer;
  font-size: 14px;
}
.sh-facet__opt input { width: 16px; height: 16px; flex: 0 0 auto; accent-color: var(--c-blue); }
.sh-facet__opt-label { flex: 1 1 auto; }
.sh-facet__count { color: var(--c-muted); font-size: 12px; }
.sh-facet__opt.is-empty { opacity: .45; cursor: not-allowed; }

/* Price range */
.sh-facet__price { display: flex; align-items: center; gap: var(--sh-space-2); padding-block: var(--sh-space-2); }
.sh-facet__price-field { flex: 1 1 0; }
.sh-facet__price-field input {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius, 8px);
  font-size: 14px;
}
.sh-facet__price-sep { color: var(--c-muted); }

/* Swatches */
.sh-facet__swatches { list-style: none; margin: 0; padding: var(--sh-space-2) 0; display: flex; flex-wrap: wrap; gap: var(--sh-space-2); }
.sh-facet__swatch-row { margin: 0; }
.sh-swatch { display: inline-flex; cursor: pointer; position: relative; }
.sh-swatch input { position: absolute; opacity: 0; width: 0; height: 0; }
.sh-swatch__chip {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: 0 0 0 1px var(--c-border);
  display: inline-block;
}
.sh-swatch.is-checked .sh-swatch__chip { border-color: var(--sh-surface); box-shadow: 0 0 0 2px var(--c-blue); }
.sh-swatch.is-empty { opacity: .4; cursor: not-allowed; }
.sh-swatch input:focus-visible + .sh-swatch__chip { box-shadow: 0 0 0 3px var(--sh-focus); }

/* Facet actions (no-JS apply / clear) */
.sh-facets__actions {
  display: flex;
  gap: var(--sh-space-2);
  padding-top: var(--sh-space-3);
}
.sh-facets__apply { flex: 1 1 auto; }
.sh-facets__clear { flex: 0 0 auto; }

/* =============================================================== *
 * Pagination
 * =============================================================== */
.sh-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--sh-space-2);
  margin-top: var(--sh-space-7);
}
.sh-pagination__link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 40px;
  min-height: 40px;
  padding-inline: 12px;
  justify-content: center;
  border: 1px solid var(--c-border);
  border-radius: var(--radius, 8px);
  background: var(--sh-surface);
  color: var(--c-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}
.sh-pagination__link:hover { border-color: var(--c-blue); color: var(--c-blue); }
.sh-pagination__link.is-active {
  background: var(--c-blue);
  border-color: var(--c-blue);
  color: #fff;
  cursor: default;
}
.sh-pagination__gap { color: var(--c-muted); padding-inline: 4px; }

/* =============================================================== *
 * Empty state
 * =============================================================== */
.sh-plp__empty {
  text-align: center;
  padding: var(--sh-space-8) var(--sh-space-4);
  border: 1px dashed var(--c-border);
  border-radius: var(--radius-lg, 12px);
  background: var(--c-bg-soft);
}
.sh-plp__empty .bi { font-size: 40px; color: var(--c-muted); }
.sh-plp__empty h2 { margin: var(--sh-space-3) 0 var(--sh-space-2); font-size: 20px; }
.sh-plp__empty p { margin-bottom: var(--sh-space-4); }

/* =============================================================== *
 * Mobile: facets are a bottom-sheet drawer (hidden until opened)
 * =============================================================== */
@media (max-width: 1023.98px) {
  .sh-plp__facets {
    position: fixed;
    inset: auto 0 0 0;
    max-height: 85vh;
    overflow-y: auto;
    border-radius: var(--radius-lg, 12px) var(--radius-lg, 12px) 0 0;
    box-shadow: var(--shadow-lg, 0 -8px 30px rgba(0,0,0,.18));
    transform: translateY(100%);
    transition: transform var(--sh-dur) var(--ease, ease);
    z-index: calc(var(--sh-z-drawer) + 1);
    padding: 0 var(--sh-space-4) var(--sh-space-4);
  }
  .sh-plp[data-facets-open] .sh-plp__facets { transform: translateY(0); }
  .sh-plp__facets-drawerhead {
    display: flex;
    position: sticky;
    top: 0;
    background: var(--sh-surface);
    margin-inline: calc(-1 * var(--sh-space-4));
    padding-inline: var(--sh-space-4);
    z-index: 1;
  }
  /* No-JS safety: if the drawer never opens (JS off), keep facets reachable by
     rendering them inline instead of a fixed off-screen sheet. */
  .no-js .sh-plp__facets,
  html:not(.js) .sh-plp__facets {
    position: static;
    transform: none;
    max-height: none;
    box-shadow: none;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg, 12px);
    margin-bottom: var(--sh-space-4);
  }
  .no-js .sh-plp__facets-drawerhead,
  html:not(.js) .sh-plp__facets-drawerhead { display: none; }
}

/* =============================================================== *
 * Desktop (lg+): persistent left facet rail, no drawer chrome
 * =============================================================== */
@media (min-width: 1024px) {
  .sh-plp__body {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: var(--sh-space-6);
    align-items: start;
  }
  .sh-plp__facets {
    position: sticky;
    top: calc(var(--header-h, 0px) + var(--sh-space-4));
    max-height: calc(100vh - var(--header-h, 0px) - var(--sh-space-6));
    overflow-y: auto;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg, 12px);
    padding: var(--sh-space-4);
  }
  .sh-plp__facets-drawerhead { display: none; }
  .sh-plp__filter-toggle { display: none; }   /* rail is inline on desktop */
  .sh-plp__scrim { display: none !important; }
}

@media (min-width: 1280px) {
  .sh-plp__body { grid-template-columns: 300px 1fr; }
}

/* =============================================================== *
 * Reduced motion
 * =============================================================== */
@media (prefers-reduced-motion: reduce) {
  .sh-plp__facets,
  .sh-facet__summary::after { transition: none; }
}

/* =============================================================== *
 * Search (P2.4) — search box + autocomplete + no-results + recs.
 * Styles the sh-searchbox partial and the search results view.
 * =============================================================== */

/* ----- Search box (GET form → results page; combobox in P2.5) ----- */
.sh-searchbox {
  position: relative;
  width: 100%;
  margin: 0 0 var(--sh-space-4);
}
.sh-searchbox--bar { max-width: 640px; }
.sh-searchbox__field {
  display: flex;
  align-items: center;
  gap: var(--sh-space-2);
  background: var(--sh-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--sh-radius-pill);
  padding: 0 var(--sh-space-2) 0 var(--sh-space-4);
  transition: box-shadow var(--sh-dur), border-color var(--sh-dur);
}
.sh-searchbox__field:focus-within {
  border-color: var(--sh-focus);
  box-shadow: 0 0 0 3px var(--sh-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sh-focus) 30%, transparent);
}
.sh-searchbox__icon { color: var(--c-muted); font-size: 18px; flex: none; }
.sh-searchbox__input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  padding-block: var(--sh-space-3);
  font-size: 16px;                 /* >=16px avoids iOS zoom (host convention) */
  color: var(--c-text);
  outline: none;
  appearance: none;
}
.sh-searchbox__input::-webkit-search-cancel-button { -webkit-appearance: none; }
.sh-searchbox__input::placeholder { color: var(--c-muted); }
.sh-searchbox__submit {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: var(--sh-tap);
  min-height: var(--sh-tap);
  border: 0;
  border-radius: var(--sh-radius-pill);
  background: var(--c-blue);
  color: #fff;
  cursor: pointer;
  transition: background var(--sh-dur);
}
.sh-searchbox__submit:hover { background: var(--c-navy, #0a1733); }
.sh-searchbox__submit:focus-visible { outline: 3px solid var(--sh-focus); outline-offset: 2px; }

/* ----- Autocomplete dropdown (populated by shop-search.js in P2.5) ----- */
.sh-searchbox__suggest {
  position: absolute;
  z-index: var(--sh-z-drawer);
  top: calc(100% + var(--sh-space-1));
  left: 0;
  right: 0;
  margin: 0;
  padding: var(--sh-space-2);
  list-style: none;
  background: var(--sh-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg, 12px);
  box-shadow: var(--shadow-lg, 0 12px 32px rgba(10, 23, 51, .16));
  max-height: min(70vh, 480px);
  overflow-y: auto;
}
.sh-searchbox__suggest[hidden] { display: none; }
.sh-searchbox__suggest-group + .sh-searchbox__suggest-group { margin-top: var(--sh-space-2); }
.sh-searchbox__suggest-heading {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--c-muted);
  padding: var(--sh-space-2) var(--sh-space-3) var(--sh-space-1);
}
.sh-searchbox__suggest-item {
  display: flex;
  align-items: center;
  gap: var(--sh-space-3);
  padding: var(--sh-space-2) var(--sh-space-3);
  border-radius: var(--radius, 8px);
  color: var(--c-text);
  text-decoration: none;
  cursor: pointer;
}
.sh-searchbox__suggest-item:hover,
.sh-searchbox__suggest-item.is-active,
.sh-searchbox__suggest-item[aria-selected="true"] { background: var(--c-bg-soft); }
.sh-searchbox__suggest-thumb {
  flex: none;
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: var(--radius, 8px);
  background: var(--c-bg-soft);
}
.sh-searchbox__suggest-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sh-searchbox__suggest-price { flex: none; font-weight: 600; color: var(--sh-price); font-size: 14px; }

/* ----- Did-you-mean hint ----- */
.sh-search__didyoumean {
  margin: var(--sh-space-2) 0 0;
  color: var(--c-muted);
  font-size: 15px;
}
.sh-search__didyoumean a { color: var(--c-blue); text-decoration: underline; }

/* ----- No-results / empty-query state ----- */
.sh-search__empty {
  text-align: center;
  padding: var(--sh-space-8) var(--sh-space-4);
  border: 1px dashed var(--c-border);
  border-radius: var(--radius-lg, 12px);
  background: var(--c-bg-soft);
}
.sh-search__empty > .bi { font-size: 40px; color: var(--c-muted); display: block; margin-bottom: var(--sh-space-3); }
.sh-search__empty h2 { margin: 0 0 var(--sh-space-2); font-size: 20px; }
.sh-search__empty .muted { color: var(--c-muted); margin: 0 auto var(--sh-space-4); max-width: 46ch; }

/* ----- Recommendation rail on the no-results page ----- */
.sh-search__reco { margin-top: var(--sh-space-7); }
.sh-search__reco-title { font-size: 18px; margin: 0 0 var(--sh-space-4); }
.sh-search__reco-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sh-space-4);
}
@media (min-width: 768px) {
  .sh-search__reco-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1024px) {
  .sh-search__reco-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .sh-searchbox__field,
  .sh-searchbox__submit { transition: none; }
}
