/* ==========================================================================
   Regioonilehed Utilities — Kliendileht Carousel
   ========================================================================== */

/*
  Responsive visible slides — driven by the carousel's OWN width via
  container queries (and mirrored in JS via carousel.offsetWidth):
    ≥ 900 px  →  4 slides
    480–899 px →  2 slides
    < 480 px   →  1 slide

  Slide width formula:
    width = (container - (N-1) × gap) / N   where gap = 16px

    1 slide: calc(100% - 16px)   [8px breathing room each side]
    2 slides: calc(50% - 8px)
    4 slides: calc(25% - 12px)
*/

/* ── Container context ──────────────────────────────────────────────────── */
.kl-carousel {
  container-type: inline-size;
  container-name: kl-carousel;

  position: relative;
  width: 100%;
  overflow: hidden;
  padding-bottom: 1rem;
  cursor: grab;
}

.kl-carousel:active {
  cursor: grabbing;
}

/* Track — single row, no wrap, driven by JS transform */
.kl-track {
  display: flex;
  flex-wrap: nowrap;
  gap: 16px;
  transition: transform 0.42s cubic-bezier(0.25, 0.8, 0.25, 1);
  will-change: transform;
}

/* ── Individual slide ───────────────────────────────────────────────────── */

/* Default: 1 slide visible */
.kl-slide {
  flex: 0 0 auto;
  width: calc(100% - 16px);
  max-width: none;
  display: block;
  border-radius: .25rem;
  overflow: hidden;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.25s ease-in-out;
  opacity: .5;
  pointer-events: none;
  user-select: none; /* prevent text selection while dragging */
  -webkit-user-select: none;
}

/* 2 slides: width = (100% - 1×16px) / 2 = calc(50% - 8px) */
@container kl-carousel (min-width: 320px) {
  .kl-slide {
    width: calc(50% - 12px);
  }
}

@container kl-carousel (min-width: 500px) {
  .kl-slide {
    width: calc(33% - 12px);
  }
}

/* 4 slides: width = (100% - 3×16px) / 4 = calc(25% - 12px) */
@container kl-carousel (min-width: 768px) {
  .kl-slide {
    width: calc(25% - 12px);
  }
}

.kl-slide.is-active {
  opacity: 1;
  pointer-events: auto;
}

.kl-slide img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 11 / 18;
  object-fit: cover;
  -webkit-user-drag: none;
  user-drag: none;
  pointer-events: none;
}

.kl-slide.is-active:hover {
  opacity: .9;
}

/* ── Prev / Next buttons ────────────────────────────────────────────────── */
.kl-btn {
  position: absolute;
  top: 45%;
  transform: translateY(-45%);
  z-index: 10;
  background: rgba(255, 255, 255, 0.92);
  border: none;
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s ease, box-shadow 0.18s ease;
  color: #222;
  padding: 0;
}

.kl-btn:hover {
  background: var(--blue-hover);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.kl-btn--prev { left:  16px; }
.kl-btn--next { right: 16px; }

/* ── Dot indicators ─────────────────────────────────────────────────────── */
.kl-dots {
  display: flex;
  justify-content: center;
  gap: .5rem;
  margin-top: 1.5rem;
}

.kl-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.2);
  transition: background 0.2s ease, transform 0.2s ease;
  cursor: pointer;
  border: none;
  padding: 0;
}

.kl-dot.is-active {
  background: var(--blue-hover);
  transform: scale(1.3);
}

/* ── Accessibility & reduced motion ────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .kl-track, .kl-slide { transition: none; }
}
