/* ==========================================================================
   OstuGrupp — AJAX shop filters
   Premium filter sidebar (desktop) + off-canvas panel (mobile),
   active-filter chips, price slider, loading skeleton, load-more.
   Uses the design tokens from main.css.
   ========================================================================== */

/* ==========================================================================
   Two-column shop layout
   ========================================================================== */
.ostu-shop-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
  align-items: start;
}
@media (min-width: 1024px) {
  .ostu-shop-layout { grid-template-columns: 280px 1fr; }
}

.ostu-shop-main { min-width: 0; } /* let the grid shrink within the column */

/* The toolbar + grid + pagination that WooCommerce prints live inside main.
   Pull the result-count toolbar tight to the top of the column. */
.ostu-shop-main .ostu-shop-toolbar { margin-top: 0; }

/* ==========================================================================
   Sidebar shell (desktop default; becomes off-canvas < 1024px)
   ========================================================================== */
.ostu-filters {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 6px 0;
  position: sticky;
  top: 96px;
  align-self: start;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 112px);
}

.ostu-filters__head {
  display: none; /* only shown in the mobile off-canvas */
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.ostu-filters__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  color: var(--slate-dark);
}
.ostu-filters__close {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 26px; line-height: 1; color: var(--slate);
  background: var(--muted); border: 1px solid var(--border); border-radius: 10px;
  transition: background .2s ease, color .2s ease;
}
.ostu-filters__close:hover { background: #fee2e2; color: #dc2626; border-color: #fecaca; }

.ostu-filters__form {
  padding: 4px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ==========================================================================
   Active-filter chips
   ========================================================================== */
.ostu-filters__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.ostu-filters__chips[hidden] { display: none; }

.ostu-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(5,150,105,.08);
  color: var(--green-dark);
  border: 1px solid rgba(5,150,105,.22);
  border-radius: 999px;
  padding: 5px 10px 5px 12px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.4;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.ostu-chip:hover { background: rgba(5,150,105,.14); border-color: rgba(5,150,105,.4); transform: translateY(-1px); }
.ostu-chip__x {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(5,150,105,.18); color: var(--green-dark);
  font-size: 14px; line-height: 1; flex-shrink: 0;
}
.ostu-chip:hover .ostu-chip__x { background: var(--green); color: #fff; }

.ostu-chip--clear {
  background: transparent;
  color: var(--slate-500);
  border-color: var(--border);
}
.ostu-chip--clear:hover { background: var(--muted); color: var(--slate-dark); border-color: var(--slate-300); }

/* ==========================================================================
   Filter groups
   ========================================================================== */
.ostu-filter-group {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}
.ostu-filter-group:last-child { border-bottom: 0; }
.ostu-filter-group__title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--slate-dark);
  margin: 0 0 12px;
}

.ostu-filter-options {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  max-height: 240px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.ostu-filter-options::-webkit-scrollbar { width: 8px; }
.ostu-filter-options::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

.ostu-filter-option label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--slate-600);
  transition: background .15s ease, color .15s ease;
}
.ostu-filter-option label:hover { background: var(--muted); color: var(--slate-dark); }

.ostu-filter-option__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ostu-filter-option__count {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--slate-500);
  background: var(--muted);
  border-radius: 999px;
  padding: 1px 8px;
}

/* Custom checkbox */
.ostu-filter-cb {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  width: 19px; height: 19px;
  border: 1.5px solid var(--slate-300);
  border-radius: 6px;
  background: #fff;
  display: inline-grid;
  place-content: center;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.ostu-filter-cb::before {
  content: "";
  width: 10px; height: 10px;
  transform: scale(0);
  transition: transform .15s ease;
  background: #fff;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
.ostu-filter-cb:checked {
  background: var(--green);
  border-color: var(--green);
}
.ostu-filter-cb:checked::before { transform: scale(1); }
.ostu-filter-cb:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.ostu-filter-option label:has(.ostu-filter-cb:checked) {
  color: var(--slate-dark);
  font-weight: 600;
}

/* ==========================================================================
   Price slider + fields
   ========================================================================== */
.ostu-price-slider {
  position: relative;
  height: 28px;
  margin: 6px 4px 16px;
}
.ostu-price-slider__track {
  position: absolute;
  top: 50%; left: 0; right: 0;
  height: 4px;
  transform: translateY(-50%);
  background: var(--border);
  border-radius: 999px;
}
.ostu-price-slider__range {
  position: absolute;
  top: 50%; height: 4px;
  transform: translateY(-50%);
  background: var(--green);
  border-radius: 999px;
}
/* Both range inputs stacked; thumbs interactive, tracks transparent */
.ostu-price-slider__input {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 28px;
  margin: 0;
  background: transparent;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}
.ostu-price-slider__input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  pointer-events: all;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--green);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.ostu-price-slider__input::-webkit-slider-thumb:hover { transform: scale(1.12); box-shadow: var(--shadow-green); }
.ostu-price-slider__input::-moz-range-thumb {
  pointer-events: all;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--green);
  box-shadow: var(--shadow-card);
  cursor: pointer;
}
.ostu-price-slider__input::-webkit-slider-runnable-track { background: transparent; }
.ostu-price-slider__input::-moz-range-track { background: transparent; }
/* Keyboard focus ring on the slider thumbs (focus lands on the range input). */
.ostu-price-slider__input:focus-visible { outline: none; }
.ostu-price-slider__input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--green); }
.ostu-price-slider__input:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--green); }

.ostu-price-fields {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.ostu-price-field { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.ostu-price-field__label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--slate-500);
}
.ostu-price-field__wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.ostu-price-field__wrap input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 30px 9px 12px;
  font: inherit;
  font-weight: 600;
  color: var(--slate-dark);
  background: #fff;
  font-variant-numeric: tabular-nums;
  min-width: 0;
}
.ostu-price-field__wrap input:focus {
  outline: 2px solid var(--green);
  outline-offset: 1px;
  border-color: var(--green);
}
.ostu-price-field__wrap input::-webkit-outer-spin-button,
.ostu-price-field__wrap input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ostu-price-field__cur {
  position: absolute;
  right: 11px;
  font-size: 13px;
  font-weight: 600;
  color: var(--slate-500);
  pointer-events: none;
}
.ostu-price-fields__sep { color: var(--slate-300); padding-bottom: 9px; font-weight: 700; }

.ostu-price-apply {
  margin-top: 12px;
  width: 100%;
  background: var(--muted);
  color: var(--slate-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 14px;
  font-weight: 600;
  font-size: 13.5px;
  transition: background .2s ease, border-color .2s ease, color .2s ease;
}
.ostu-price-apply:hover { background: var(--green); color: #fff; border-color: var(--green); }

/* ==========================================================================
   Sidebar footer (mobile off-canvas action bar)
   ========================================================================== */
.ostu-filters__foot {
  display: none; /* shown only in off-canvas */
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: #fff;
}
.ostu-filters__foot .ostu-filters__clear {
  flex-shrink: 0;
  background: var(--muted);
  color: var(--slate);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 16px;
  min-height: 48px;
  font-weight: 600;
  transition: background .2s ease, color .2s ease;
}
.ostu-filters__foot .ostu-filters__clear:hover { background: #fee2e2; color: #dc2626; border-color: #fecaca; }
.ostu-filters__foot .ostu-filters__apply { flex: 1; }

/* ==========================================================================
   Mobile trigger button
   ========================================================================== */
.ostu-filters-mobile-trigger {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: #fff;
  color: var(--slate-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 0 18px;
  min-height: 48px;
  font-weight: 600;
  font-size: 14.5px;
  transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}
.ostu-filters-mobile-trigger:hover { border-color: rgba(5,150,105,.5); color: var(--green); transform: translateY(-1px); }
.ostu-filters-mobile-trigger svg { color: var(--green); }
.ostu-filters-mobile-trigger__count {
  background: var(--green);
  color: #fff;
  border-radius: 999px;
  min-width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; padding: 0 6px;
}

@media (min-width: 1024px) {
  .ostu-filters-mobile-trigger { display: none; }
}

/* ==========================================================================
   Backdrop (mobile off-canvas)
   ========================================================================== */
.ostu-filters-backdrop {
  position: fixed; inset: 0; z-index: 1190;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .28s ease;
}
.ostu-filters-backdrop[hidden] { display: none; }
.ostu-filters-backdrop.is-visible { opacity: 1; }

/* ==========================================================================
   Off-canvas behaviour < 1024px
   ========================================================================== */
@media (max-width: 1023.98px) {
  .ostu-filters {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1200;
    width: min(380px, 88vw);
    max-height: none;
    border-radius: 0;
    border: 0;
    box-shadow: 0 0 60px -10px rgba(15,23,42,.4);
    padding: 0;
    transform: translateX(-100%);
    /* transform alone leaves the panel FOCUSABLE while it is off-screen: tabbing
       from the shop grid walked through 24 invisible stops (every checkbox, both
       price inputs, the apply and clear buttons) before returning to the page.
       visibility:hidden takes it out of the tab order; the 0s .3s delay lets it
       stay visible for the whole slide-out, so nothing changes on screen. */
    visibility: hidden;
    transition: transform .3s cubic-bezier(.4,0,.2,1), visibility 0s .3s;
  }
  .ostu-filters.is-open { transform: translateX(0); visibility: visible; transition-delay: 0s; }
  .ostu-filters__head { display: flex; }
  .ostu-filters__foot { display: flex; position: sticky; bottom: 0; }
  .ostu-filters__form { flex: 1; }
  body.ostu-filters-open { overflow: hidden; }

  /* Roomier tap targets inside the off-canvas: the option rows and the price
     fields are easier to hit on a phone. The option max-height is also relaxed
     so the list uses the full panel height rather than a tight 240px scroller. */
  .ostu-filter-option label { padding: 11px 8px; font-size: 15px; }
  .ostu-filter-options { max-height: none; }
  .ostu-price-field__wrap input { padding-block: 12px; }
}

@media (min-width: 1024px) {
  /* The clear-all chip handles desktop clearing; off-canvas chrome hidden. */
  .ostu-filters-backdrop { display: none !important; }
}

/* ==========================================================================
   Load-more
   ========================================================================== */
.ostu-load-more {
  display: flex;
  justify-content: center;
  margin-top: 32px;
}
.ostu-load-more[hidden] { display: none; }
.ostu-load-more .js-ostu-load-more-btn { min-width: 240px; }
.ostu-load-more__done {
  color: var(--slate-500);
  font-size: 14px;
  font-weight: 600;
  padding: 12px 0;
}

/* ==========================================================================
   Loading state + skeleton
   ========================================================================== */
.ostu-shop-main.is-loading .woocommerce ul.products,
.ostu-shop-main.is-loading ul.products {
  opacity: .45;
  pointer-events: none;
  transition: opacity .2s ease;
}

.ostu-skeleton {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin: 24px 0 0;
  list-style: none;
  padding: 0;
}
@media (min-width: 768px) { .ostu-skeleton { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1024px) { .ostu-skeleton { grid-template-columns: repeat(4, 1fr); } }
.ostu-skeleton[hidden] { display: none; }

.ostu-skeleton__card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.ostu-skeleton__img { aspect-ratio: 1 / 1; background: var(--muted); }
.ostu-skeleton__body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.ostu-skeleton__line { height: 12px; border-radius: 6px; background: var(--muted); }
.ostu-skeleton__line--title { width: 92%; }
.ostu-skeleton__line--sub { width: 60%; }
.ostu-skeleton__line--price { width: 40%; height: 18px; margin-top: 4px; }

.ostu-skeleton__img,
.ostu-skeleton__line {
  position: relative;
  overflow: hidden;
}
.ostu-skeleton__img::after,
.ostu-skeleton__line::after {
  content: "";
  position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.65), transparent);
  animation: ostu-shimmer 1.3s infinite;
}
@keyframes ostu-shimmer {
  100% { transform: translateX(100%); }
}
@media (prefers-reduced-motion: reduce) {
  .ostu-skeleton__img::after, .ostu-skeleton__line::after { animation: none; }
}

/* ==========================================================================
   Inline spinner on buttons
   ========================================================================== */
.ostu-spinner {
  display: inline-block;
  width: 15px; height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: ostu-spin .7s linear infinite;
  vertical-align: -2px;
  margin-right: 8px;
}
@keyframes ostu-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ostu-spinner { animation-duration: 1.6s; } }

.is-busy { opacity: .8; pointer-events: none; }
