/* category-archive-layout-20261129 v3
   Approved typography and layout repair for YOCOOLING product-category
   archive pages, revised after visual QA of the first publish.

   v3: do not flatten <details.lc-supplier-series> with display:contents
   (Chrome keeps those as grid items, so each series stays one column).
   Visible cards are moved into .lc-catalog-pack after catalog render.
   Also loosen overflow so lazy images are not trapped in a clip box.

   v1 failures this file is written to prevent:
   - display:contents on .lc-catalog-type (and !important) overrode [hidden],
     so later type headings and off-page series leaked into one page-wide grid.
   - height:100% + align-items:stretch + margin-top:auto stretched cards to
     thousands of pixels, covering pagination/footer and breaking lazy-load.

   Scoped to the existing catalog; does not change default view, product
   architecture, or title/meta. */

/* ---- Sticky header clearance (do not invent a second scroller) ---- */

html {
  scroll-padding-top: calc(var(--lc-header-height, 68px) + 16px + var(--lc-admin-offset, 0px));
}

body.lc-green-site .site-main .lc-green-catalog,
body.lc-green-site .site-main .lc-catalog-toolbar,
body.lc-green-site .site-main .lc-catalog-type > h2,
body.lc-green-site .site-main .lc-result-count {
  scroll-margin-top: calc(var(--lc-header-height, 68px) + 16px + var(--lc-admin-offset, 0px));
}

/* Hidden must always win over display:contents flattening. */
body.lc-green-site .site-main .lc-green-catalog[data-view=cards] [hidden],
body.lc-green-site .site-main .lc-green-catalog[data-view=cards] [hidden] * {
  display: none !important;
}

/* ---- Toolbar typography and alignment (kept from v1; QA passed) ---- */

body.lc-green-site .site-main .lc-green-catalog .lc-catalog-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  box-sizing: border-box;
  width: 100%;
  margin-bottom: 24px;
  padding: 12px 20px;
  overflow: visible;
}

body.lc-green-site .site-main .lc-green-catalog .lc-catalog-toolbar .lc-result-count {
  margin: 0 auto 0 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 15px;
  line-height: 1.4;
  white-space: nowrap;
}

body.lc-green-site .site-main .lc-green-catalog .lc-catalog-toolbar [data-lc-filter-open] {
  margin-left: 0;
  flex: 0 0 auto;
}

body.lc-green-site .site-main .lc-green-catalog .lc-catalog-toolbar > label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  min-width: max-content;
  max-width: none;
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
}

body.lc-green-site .site-main .lc-green-catalog .lc-catalog-toolbar > label select,
body.lc-green-site .site-main .lc-green-catalog .lc-catalog-toolbar [data-lc-sort] {
  flex: 0 0 auto;
  width: auto;
  min-width: 10.5rem;
  max-width: 16rem;
  font-size: 14px;
}

body.lc-green-site .site-main .lc-green-catalog .lc-catalog-options {
  position: relative;
  flex: 0 0 auto;
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
}

body.lc-green-site .site-main .lc-green-catalog .lc-catalog-options > summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 4px 0 2px;
  font-size: 14px;
  line-height: 1.4;
  white-space: nowrap;
  cursor: pointer;
}

@media (max-width: 720px) {
  body.lc-green-site .site-main .lc-green-catalog .lc-catalog-toolbar {
    padding: 12px 16px;
    gap: 10px 12px;
  }
  body.lc-green-site .site-main .lc-green-catalog .lc-catalog-toolbar .lc-result-count {
    flex-basis: 100%;
    margin: 0;
  }
  body.lc-green-site .site-main .lc-green-catalog .lc-catalog-toolbar [data-lc-filter-open] {
    margin-left: 0;
  }
}

/* ---- Per-section pack grid; results and type sections stay in normal flow ---- */

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-green-catalog-main,
body.lc-green-site .site-main .lc-green-catalog[data-view=cards] [data-lc-results] {
  display: block;
  overflow: visible;
  max-width: 100%;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-catalog-type:not([hidden]) {
  display: block;
  margin: 0 0 28px;
  overflow: visible;
  max-width: 100%;
  min-width: 0;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-catalog-type[hidden] {
  display: none !important;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-catalog-type > h2 {
  display: block;
  margin: 0 0 16px;
  min-width: 0;
}

/* Visible cards are reparented here after render. This avoids display:contents
   on <details.lc-supplier-series>, which Chrome does not flatten into the
   parent grid (v2 packing failure). */
body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-catalog-type:not([hidden]) > .lc-catalog-pack {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: auto;
  grid-auto-flow: row;
  align-items: start;
  justify-items: stretch;
  gap: 24px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: visible;
}

/* Once the pack exists, hide the emptied series wrappers. Hidden rows remain
   in their original holders for the next render(). */
body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-catalog-type:has(> .lc-catalog-pack) > :is(
  .lc-supplier-series,
  [data-lc-series-group],
  .lc-buyer-table-wrap
) {
  display: none !important;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-supplier-series[hidden] {
  display: none !important;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] :is(
  .lc-supplier-series > summary,
  .lc-buyer-table thead,
  .lc-buyer-table .lc-buyer-thead,
  .lc-green-series-photos
) {
  display: none !important;
}

/* Cards are auto-height in normal flow. Do not use height:100%. */
body.lc-green-site .site-main .lc-green-catalog[data-view=cards] :is(
  [data-lc-row],
  .lc-catalog-product-row:not(.lc-buyer-thead > *)
) {
  display: flex;
  flex-direction: column;
  align-self: start;
  height: auto;
  max-height: none;
  min-height: 0;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 1px solid var(--lc-green-line, #cfe4d9);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--lc-card-shadow, none);
  overflow: hidden;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] [data-lc-row][hidden] {
  display: none !important;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-catalog-identity-cell {
  display: flex;
  flex-direction: column;
  flex: 0 1 auto;
  min-width: 0;
  width: auto;
  max-width: none;
  padding: 0;
  border: 0;
  background: transparent;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-catalog-product-entry {
  display: flex;
  flex-direction: column;
  flex: 0 1 auto;
  min-width: 0;
  align-items: stretch;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-green-catalog-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] :is(
  .lc-catalog-identity-cell > small,
  .lc-buyer-table [data-label],
  [data-lc-row] > [data-label],
  .lc-catalog-quote-cell
) {
  display: none !important;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-catalog-description-note {
  display: none !important;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-catalog-card-actions {
  margin-top: 8px;
  padding: 8px 24px 0;
  width: 100%;
  box-sizing: border-box;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-catalog-card-actions .lc-catalog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-catalog-compare-cell {
  display: block;
  order: 3;
  width: auto;
  max-width: none;
  align-self: stretch;
  border: 0;
  padding: 12px 24px 18px;
  text-align: left;
}

/* ---- Consistent image framing (kept from v1) ---- */

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-green-catalog-photo {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  width: 100%;
  height: auto;
  max-height: none;
  padding: 16px;
  overflow: hidden;
  background: #fff;
  box-sizing: border-box;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-green-catalog-photo > img {
  position: static;
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  aspect-ratio: auto !important;
  object-fit: contain;
  object-position: center center;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-green-catalog-card-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
  padding: 16px 24px 8px;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-green-catalog-summary {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  overflow: hidden;
  white-space: normal;
  text-overflow: ellipsis;
  font-size: 14px;
  line-height: 1.55;
}

/* ---- Tighter section and pagination spacing ---- */

body.lc-green-site .site-main .lc-green-catalog .lc-candidate-pages {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 24px 0 0;
  min-height: 0;
  position: relative;
  z-index: 1;
  background: transparent;
}

body.lc-green-site .site-main .lc-green-catalog .lc-candidate-pages[hidden] {
  display: none !important;
  margin: 0;
}

body.lc-green-site .site-main .lc-catalog-quote-strip {
  margin-top: 32px;
  padding-top: 24px;
  position: relative;
  z-index: 1;
}

/* ---- Table view after table-to-div promotion (do not change default view) ---- */

body.lc-green-site .site-main .lc-green-catalog[data-view=table] .lc-buyer-table-wrap {
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=table] .lc-buyer-table {
  display: table;
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  table-layout: auto;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=table] .lc-buyer-thead {
  display: table-header-group;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=table] .lc-buyer-tbody {
  display: table-row-group;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=table] .lc-buyer-table .lc-catalog-product-row,
body.lc-green-site .site-main .lc-green-catalog[data-view=table] .lc-buyer-thead > * {
  display: table-row;
  height: auto;
  border: 0;
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  overflow: visible;
}

body.lc-green-site .site-main .lc-green-catalog[data-view=table] .lc-buyer-table .lc-catalog-product-row > * {
  display: table-cell;
  vertical-align: top;
  text-align: left;
  padding: 14px 16px;
  border-bottom: 1px solid var(--lc-green-line, #d3dde2);
}

body.lc-green-site .site-main .lc-green-catalog[data-view=table] .lc-catalog-identity-cell {
  min-width: 280px;
}

@media (max-width: 1100px) {
  body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-catalog-type:not([hidden]) > .lc-catalog-pack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  body.lc-green-site .site-main .lc-green-catalog[data-view=cards] .lc-catalog-type:not([hidden]) > .lc-catalog-pack {
    grid-template-columns: 1fr;
  }
  body.lc-green-site .site-main .lc-green-catalog[data-view=table] .lc-buyer-table {
    min-width: 0;
  }
  body.lc-green-site .site-main .lc-green-catalog[data-view=table] .lc-catalog-identity-cell {
    min-width: 0;
  }
}
