/* ============================================================
   C'era una volta — Faceted filters (PLP).
   Loaded only on shop + product taxonomy archives (cuv-facets).
   B&W editorial system. Reuses theme.css tokens; does NOT
   restyle .pcard (theme.css owns the card).
   ============================================================ */

/* ---- Two-column layout ------------------------------------ */
.plp-layout {
  display: flex;
  align-items: flex-start;
  gap: 56px;
  padding-top: 10px;
}

.plp-facets {
  flex: 0 0 264px;
  width: 264px;
  position: sticky;
  top: 100px;
  align-self: flex-start;
  padding-right: 8px;
}

.plp-results {
  flex: 1 1 auto;
  min-width: 0; /* let the grid shrink instead of overflowing */
}

/* The grid (ul.products, display:grid from plp.css) lives inside the
   narrower results column. Re-declare 4/3/2 columns scoped here so it
   reflows at the reduced width without touching plp.css. We only set
   grid-template-columns — card internals stay owned by theme.css. */
.plp-results ul.products,
.plp-results.woocommerce ul.products {
  grid-template-columns: repeat(3, 1fr);
  gap: 28px 18px;
}

@media (max-width: 1200px) {
  .plp-results ul.products {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ---- Sidebar form ----------------------------------------- */
.cuv-facets {
  font-family: var(--font-sans);
}

.cuv-facets__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 14px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--line-strong);
}

.cuv-facets__heading {
  color: var(--ink);
  font-size: 11px;
}

.cuv-facets__reset {
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid transparent;
  transition: color .18s, border-color .18s;
}
.cuv-facets__reset:hover {
  color: var(--ink);
  border-color: var(--ink);
}

/* ---- Accordion section ------------------------------------ */
.cuv-facet {
  border-bottom: 1px solid var(--line);
}

.cuv-facet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
  padding: 16px 0;
  user-select: none;
}
.cuv-facet__head::-webkit-details-marker { display: none; }

.cuv-facet__title {
  color: var(--ink);
  font-size: 10.5px;
}

.cuv-facet__chev {
  width: 9px;
  height: 9px;
  border-right: 1.2px solid var(--ink);
  border-bottom: 1.2px solid var(--ink);
  transform: rotate(45deg);
  transition: transform .2s var(--ease);
  margin-right: 2px;
  margin-top: -3px;
}
.cuv-facet[open] > .cuv-facet__head .cuv-facet__chev {
  transform: rotate(-135deg);
  margin-top: 2px;
}

.cuv-facet__body {
  padding: 2px 0 18px;
}

/* ---- Search box inside a facet ---------------------------- */
.cuv-facet__search {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 300;
  color: var(--ink);
  padding: 9px 11px;
  margin-bottom: 12px;
  transition: border-color .18s;
}
.cuv-facet__search::placeholder { color: var(--muted); }
.cuv-facet__search:focus { outline: none; border-color: var(--ink); }

/* ---- Option list ------------------------------------------ */
.cuv-facet__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 11px;
  max-height: 280px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.cuv-facet__item.is-hidden { display: none; }
.cuv-facet__item.is-filtered { display: none; }

/* ---- Custom checkbox -------------------------------------- */
.cuv-check {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 300;
  color: var(--ink-2);
  line-height: 1.3;
}
.cuv-check:hover { color: var(--ink); }

.cuv-check input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.cuv-check__box {
  flex: 0 0 15px;
  width: 15px;
  height: 15px;
  border: 1px solid var(--ink);
  background: var(--paper);
  position: relative;
  transition: background .15s;
}
.cuv-check input:checked + .cuv-check__box {
  background: var(--ink);
}
.cuv-check input:checked + .cuv-check__box::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border-right: 1.6px solid var(--paper);
  border-bottom: 1.6px solid var(--paper);
  transform: rotate(45deg);
}
.cuv-check input:focus-visible + .cuv-check__box {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.cuv-check__label {
  flex: 1 1 auto;
  min-width: 0;
}

.cuv-facet__count {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  font-weight: 300;
}

/* ---- "Mostra tutte" expander ------------------------------ */
.cuv-facet__more {
  margin-top: 12px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink);
  border-bottom: 1px solid var(--ink);
  padding-bottom: 2px;
}
.cuv-facet__more:hover { color: var(--muted); border-color: var(--muted); }

/* ---- Price facet ------------------------------------------ */
.cuv-price { padding-top: 4px; }

.cuv-price__track {
  position: relative;
  height: 2px;
  background: var(--line);
  margin: 6px 2px 18px;
}
.cuv-price__fill {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 100%;
  background: var(--ink);
}

.cuv-price__inputs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cuv-price__field { flex: 1 1 0; min-width: 0; }
.cuv-price__field input {
  width: 100%;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 0;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 300;
  color: var(--ink);
  padding: 9px 10px;
  transition: border-color .18s;
}
.cuv-price__field input::placeholder { color: var(--muted); }
.cuv-price__field input:focus { outline: none; border-color: var(--ink); }
/* strip number spinners */
.cuv-price__field input::-webkit-outer-spin-button,
.cuv-price__field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cuv-price__field input[type=number] { -moz-appearance: textfield; }

.cuv-price__dash { color: var(--muted); font-size: 12px; }

/* ---- Apply button ----------------------------------------- */
.cuv-facets__actions {
  margin-top: 22px;
}
.cuv-facets__apply {
  width: 100%;
  text-align: center;
  font-size: 11px;
  padding: 13px 20px;
}

/* ---- Active chips (results column top) -------------------- */
.cuv-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.cuv-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-2);
  transition: border-color .18s, color .18s;
  line-height: 1.3;
}
.cuv-chip:hover { border-color: var(--ink); color: var(--ink); }
.cuv-chip__x { font-size: 13px; line-height: 1; color: var(--muted); }
.cuv-chip:hover .cuv-chip__x { color: var(--ink); }

.cuv-chip--clear {
  border-color: transparent;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 1px solid var(--muted);
  padding: 6px 2px;
}
.cuv-chip--clear:hover { color: var(--ink); border-bottom-color: var(--ink); }

/* ---- Empty state ------------------------------------------ */
.cuv-facets__empty {
  padding: 60px 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ---- Loading state on results ----------------------------- */
.plp-results.is-loading {
  opacity: .45;
  pointer-events: none;
  transition: opacity .15s;
}

/* ---- Mobile "Filtri" toggle button ------------------------ */
.plp-filtri-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 0;
  font-family: var(--font-sans);
  font-size: 11px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink);
  padding: 11px 22px;
  cursor: pointer;
  margin-bottom: 18px;
}
.plp-filtri-toggle::before {
  content: "";
  width: 14px;
  height: 10px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='10' viewBox='0 0 14 10'%3E%3Cpath d='M0 1h14M2 5h10M5 9h4' stroke='%230d0d0d' stroke-width='1.2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
}

/* close (X) inside the drawer — hidden on desktop */
.plp-facets__close {
  display: none;
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
}

/* backdrop hidden on desktop */
.plp-facets-backdrop { display: none; }

/* ============================================================
   RESPONSIVE — off-canvas drawer below 1024px [M6: raised from 900px]
   ============================================================ */
@media (max-width: 1024px) {
  .plp-layout {
    display: block;
  }

  .plp-filtri-toggle { display: inline-flex; }

  .plp-facets {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 320px;
    max-width: 86vw;
    background: var(--paper);
    z-index: 1200;
    padding: 56px 22px 28px;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform .3s var(--ease);
    box-shadow: 0 0 0 100vmax rgba(13, 13, 13, 0);
  }
  .plp-facets.is-open {
    transform: translateX(0);
  }

  .plp-facets__close { display: block; }

  .plp-facets-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(13, 13, 13, .42);
    z-index: 1190;
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s var(--ease), visibility .25s var(--ease);
  }
  .plp-facets-backdrop.is-open {
    opacity: 1;
    visibility: visible;
  }

  body.cuv-facets-open {
    overflow: hidden;
  }

  .plp-results ul.products {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .plp-results ul.products {
    grid-template-columns: repeat(2, 1fr);
  }
}
