/* ==========================================================
   Shop-Filter (Zalando-Stil): Seitenleiste, Toolbar, Karten
   ========================================================== */

:root {
  --spf-ink: #111;
  --spf-muted: #6b6b6b;
  --spf-line: #e6e6e6;
  --spf-soft: #f5f5f4;
  --spf-radius: 10px;
}

/* ---------- Layout ---------- */
.spf-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 36px;
  align-items: start;
}

.spf-sidebar {
  position: sticky;
  top: 90px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
}

.spf-sidebar-head,
.spf-open-filters,
.spf-backdrop,
.spf-apply { display: none; }

/* ---------- Filtergruppen ---------- */
.spf-group { border-bottom: 1px solid var(--spf-line); padding: 14px 0; }
.spf-group summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 15px;
  color: var(--spf-ink);
}
.spf-group summary::-webkit-details-marker { display: none; }
.spf-group summary::after {
  content: "";
  width: 8px; height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform .2s;
  margin-right: 4px;
}
.spf-group[open] summary::after { transform: rotate(-135deg); }
.spf-group > *:not(summary) { margin-top: 14px; }

/* Kategorien */
.spf-cat-list, .spf-cat-list ul { list-style: none; margin: 0; padding: 0; }
.spf-cat-list ul { margin-left: 20px; }
.spf-cat-list li { margin: 0; }
.spf-cat-list label {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 0; cursor: pointer; font-size: 14px; line-height: 1.3;
}
.spf-cat-list .spf-depth-0 > label { font-weight: 600; }
.spf-cat-list input[type=checkbox] {
  width: 17px; height: 17px; margin: 0; accent-color: var(--spf-ink); flex: none;
}

/* Schalter */
.spf-switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-size: 14px; }
.spf-switch input { position: absolute; opacity: 0; pointer-events: none; }
.spf-switch-ui {
  position: relative; width: 40px; height: 22px; flex: none;
  background: #cfcfcf; border-radius: 22px; transition: background .2s;
}
.spf-switch-ui::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; background: #fff; border-radius: 50%;
  transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.spf-switch input:checked + .spf-switch-ui { background: var(--spf-ink); }
.spf-switch input:checked + .spf-switch-ui::after { transform: translateX(18px); }
.spf-switch input:focus-visible + .spf-switch-ui { outline: 2px solid var(--spf-ink); outline-offset: 2px; }

/* Grössen-Chips */
.spf-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.spf-chip { position: relative; cursor: pointer; }
.spf-chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.spf-chip span {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 46px; height: 38px; padding: 0 12px;
  border: 1px solid #cfcfcf; border-radius: 8px;
  font-size: 13px; font-weight: 600; text-transform: uppercase;
  background: #fff; color: var(--spf-ink); transition: all .15s;
}
.spf-chip:hover span { border-color: var(--spf-ink); }
.spf-chip input:checked + span { background: var(--spf-ink); border-color: var(--spf-ink); color: #fff; }
.spf-chip input:focus-visible + span { outline: 2px solid var(--spf-ink); outline-offset: 2px; }

/* Farb-Punkte */
.spf-colors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; padding: 4px; }
.spf-color { position: relative; display: flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer; font-size: 14px; }
.spf-color input { position: absolute; opacity: 0; pointer-events: none; }
.spf-dot {
  flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--c);
  border: 1px solid rgba(0,0,0,.18); box-shadow: inset 0 0 0 2px #fff; transition: transform .15s;
}
.spf-color:hover .spf-dot { transform: scale(1.08); }
.spf-color input:checked + .spf-dot { outline: 2px solid var(--spf-ink); outline-offset: 2px; }
.spf-color input:focus-visible + .spf-dot { outline: 2px dashed var(--spf-ink); outline-offset: 2px; }

/* Optionen ohne Lagerbestand */
.spf-chip.is-unavailable, .spf-color.is-unavailable { opacity: .4; cursor: not-allowed; }
.spf-chip.is-unavailable span { text-decoration: line-through; border-style: dashed; }
.spf-chip.is-unavailable input, .spf-color.is-unavailable input { cursor: not-allowed; }
.spf-color.is-unavailable .spf-color-name { text-decoration: line-through; }

/* Preis */
.spf-price { display: flex; align-items: center; gap: 8px; }
.spf-price input {
  width: 100%; min-width: 0; padding: 9px 10px;
  border: 1px solid #cfcfcf; border-radius: 8px; font-size: 14px; background: #fff;
}
.spf-price input:focus { border-color: var(--spf-ink); outline: none; }

/* Aktionen */
.spf-actions { display: flex; gap: 10px; padding-top: 18px; }
.spf-reset {
  background: none !important; border: 0 !important; padding: 0 !important;
  color: var(--spf-muted) !important; text-decoration: underline; font-size: 13px; cursor: pointer;
}
.spf-reset:hover { color: var(--spf-ink) !important; }

/* ---------- Toolbar ---------- */
.spf-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding-bottom: 14px; border-bottom: 1px solid var(--spf-line); margin-bottom: 14px;
}
.spf-count { font-size: 14px; color: var(--spf-muted); flex: 1; }
.spf-sort select {
  padding: 9px 36px 9px 14px; border: 1px solid #cfcfcf; border-radius: 8px;
  background-color: #fff; font-size: 14px; cursor: pointer; color: var(--spf-ink);
}
.spf-open-filters {
  align-items: center; gap: 8px; padding: 9px 16px; border-radius: 8px;
  background: var(--spf-ink) !important; color: #fff !important; border: 0; font-size: 14px; cursor: pointer;
}

/* Aktive Filter */
.spf-active { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.spf-active:empty { display: none; }
.spf-chip-active, .spf-chip-reset {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px;
  border-radius: 999px; font-size: 13px; line-height: 1.2; cursor: pointer;
  background: var(--spf-soft) !important; color: var(--spf-ink) !important; border: 1px solid var(--spf-line) !important;
}
.spf-chip-active:hover { border-color: var(--spf-ink) !important; }
.spf-chip-active span { font-size: 16px; line-height: 1; }
.spf-chip-reset {
  background: none !important; border-color: transparent !important;
  color: var(--spf-muted) !important; text-decoration: underline;
}

/* ---------- Ergebnisse ---------- */
#spf-results { position: relative; min-height: 200px; }
#spf-results.loading ul.products { opacity: .35; pointer-events: none; transition: opacity .2s; }
#spf-results.loading::after {
  content: attr(data-loading);
  position: absolute; top: 80px; left: 50%; transform: translateX(-50%);
  background: #fff; padding: 10px 20px; border-radius: 8px;
  font-size: 14px; color: #333; box-shadow: 0 2px 10px rgba(0,0,0,.12); z-index: 5;
}
.spf-empty { padding: 40px 0; text-align: center; color: var(--spf-muted); }
.spf-products-empty { display: none !important; }

/* ---------- Produktkarten ---------- */
ul.products li.product { position: relative; }
ul.products li.product .astra-shop-thumbnail-wrap { position: relative; overflow: hidden; border-radius: var(--spf-radius); }
ul.products li.product .astra-shop-thumbnail-wrap img { transition: transform .35s ease, opacity .2s; }
ul.products li.product:hover .astra-shop-thumbnail-wrap img { transform: scale(1.03); }

li.product.outofstock .astra-shop-thumbnail-wrap img { opacity: .55; filter: grayscale(.6); }

.spf-variants { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 10px 0 4px; }
.spf-card-colors { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.spf-card-dot {
  position: relative; width: 18px; height: 18px; padding: 0 !important; min-width: 0 !important;
  border-radius: 50% !important; background: var(--c) !important;
  border: 1px solid rgba(0,0,0,.25) !important; cursor: pointer; transition: transform .15s;
}
.spf-card-dot:hover { transform: scale(1.15); }
.spf-card-dot.is-selected { outline: 2px solid var(--spf-ink); outline-offset: 2px; }
.spf-card-dot.is-out::after {
  content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1.5px;
  background: #888; transform: rotate(45deg); border-radius: 2px;
}

.spf-card-sizes { display: flex; gap: 3px; justify-content: center; flex-wrap: wrap; }
.spf-card-size {
  min-width: 22px; padding: 2px 4px; border: 1px solid #d5d5d5; border-radius: 4px; text-align: center;
  font-size: 10px; font-weight: 600; text-transform: uppercase; line-height: 1.5;
  color: var(--spf-ink); background: #fff;
}
.spf-card-size.is-out { color: #aaa; background: transparent; text-decoration: line-through; border-style: dashed; }
.spf-card-size.is-active { border-color: var(--spf-ink); background: var(--spf-ink); color: #fff; }
.spf-card-size.is-active.is-out { background: transparent; color: #aaa; }

/* ---------- Mobil / Tablet: Filter als Schublade ---------- */
@media (max-width: 921px) {
  .spf-layout { display: block; }
  .spf-open-filters { display: inline-flex; }

  .spf-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 100001;
    width: min(88vw, 380px); max-height: none; padding: 0 20px 100px;
    background: #fff; transform: translateX(-102%); visibility: hidden;
    transition: transform .28s ease, visibility 0s .28s; box-shadow: none;
  }
  body.spf-drawer-open .spf-sidebar {
    transform: none; visibility: visible; transition: transform .28s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
  }

  .spf-sidebar-head {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 2; background: #fff;
    padding: 18px 0; border-bottom: 1px solid var(--spf-line); font-size: 18px;
  }
  .spf-close.spf-close {
    background: none !important; border: 0 !important; font-size: 30px; line-height: 1;
    color: var(--spf-ink) !important; cursor: pointer; padding: 0 4px !important;
  }
  .spf-backdrop {
    display: block; position: fixed; inset: 0; z-index: 100000;
    background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .25s;
  }
  body.spf-drawer-open .spf-backdrop { opacity: 1; pointer-events: auto; }
  body.spf-drawer-open { overflow: hidden; }

  .spf-actions {
    position: fixed; bottom: 0; left: 0; width: min(88vw, 380px); box-sizing: border-box;
    padding: 14px 20px; background: #fff; border-top: 1px solid var(--spf-line);
    justify-content: space-between; align-items: center;
  }
  .spf-apply {
    display: inline-block; flex: 1; background: var(--spf-ink) !important; color: #fff !important;
    border: 0; border-radius: 8px; padding: 12px 18px !important; font-weight: 600; cursor: pointer;
    font-size: 15px !important; letter-spacing: 0 !important; text-transform: none !important; line-height: 1.2 !important;
  }
  .spf-count { font-size: 13px; }
  .spf-sort select { padding-right: 28px; }
}

@media (max-width: 544px) {
  .spf-toolbar { flex-wrap: wrap; }
  .spf-count { order: 3; flex-basis: 100%; }
  .spf-sort { margin-left: auto; }
  .spf-card-size { min-width: 24px; font-size: 10px; padding: 1px 4px; }
}

/* ---------- Bestehende Shop-Anpassungen (unverändert übernommen) ---------- */
.woocommerce .woocommerce-ordering { display: none; }

li span.current { color: white !important; }

.widget .wp-container-core-social-links-is-layout-15834411 { justify-content: unset; }
@media only screen and (max-width: 767px) {
  .widget .wp-container-core-social-links-is-layout-15834411 { justify-content: center; }
}

/* Theme-Buttonstile im Filter neutralisieren */
.spf-sidebar button, .spf-toolbar button, .spf-active button {
  letter-spacing: 0; text-transform: none; line-height: 1.2;
}
.spf-open-filters { font-size: 14px !important; font-weight: 600; }
.spf-chip-active { font-size: 13px !important; }

/* ---------- Karten gleich hoch, Buttons bündig am unteren Rand ---------- */
ul.products li.product { display: flex; flex-direction: column; height: 100%; }
ul.products li.product .astra-shop-summary-wrap { display: flex; flex-direction: column; flex: 1 1 auto; }
ul.products li.product .astra-shop-summary-wrap .button,
ul.products li.product > .button,
ul.products li.product .ast-shop-summary-wrap .button {
  margin-top: auto !important; align-self: stretch; text-align: center;
}
ul.products li.product .spf-variants { margin-bottom: 14px; }

/* ---------- Gleiche Linien in jeder Kartenreihe ---------- */
/* Bilder: einheitliches Format, egal welches Verhältnis das Foto hat */
ul.products li.product .astra-shop-thumbnail-wrap img {
  width: 100%; aspect-ratio: 1 / 1; object-fit: cover; object-position: center;
}
/* Titel: immer zwei Zeilen Platz, damit Preis und Varianten nicht springen */
ul.products li.product .woocommerce-loop-product__title {
  line-height: 1.3; min-height: 2.6em;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
}
/* Varianten direkt unter dem Preis (Titel hat feste Höhe, daher überall auf gleicher Linie) */
ul.products li.product .spf-variants { margin-top: 0; padding-top: 4px; }
ul.products li.product .price { margin-bottom: 0; }

/* ---------- Mobil: Endlos-Scrollen statt Seitenzahlen ---------- */
#spf-sentinel { min-height: 1px; text-align: center; color: var(--spf-muted); font-size: 14px; }
#spf-sentinel.is-loading { padding: 24px 0; }
@media (max-width: 921px) {
  body.spf-infinite #spf-results .woocommerce-pagination { display: none; }
}
