/* ==========================================================================
   Premium Gallery widget
   BEM: .jsf-gallery, .jsf-gallery-item__*
   Layout switched via prefix classes: --layout-bento / --layout-grid /
   --layout-masonry / --layout-carousel. Hover/overlay/glass are
   independent prefix classes layered on top of any layout.
   ========================================================================== */

.jsf-gallery-wrap {
  position: relative;
  width: 100%;
}

.jsf-gallery {
  --jsf-gallery-gap: 16px;
  display: grid;
  gap: var(--jsf-gallery-gap);
  width: 100%;
  margin: 0 auto;
  list-style: none;
  padding: 0;
}

.jsf-gallery-item {
  position: relative;
  display: block;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.jsf-gallery-item__media {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--color-highlight);
}

.jsf-gallery-item__media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-slow), filter var(--transition), opacity var(--transition);
}

.jsf-gallery-item__caption {
  margin-top: var(--space-xs);
  font-size: var(--fs-small);
  color: var(--color-light);
  text-align: center;
}

/* ---------- Overlay ---------- */

.jsf-gallery-item__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-2xs);
  padding: var(--space-md);
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}

.jsf-gallery-item:hover .jsf-gallery-item__overlay,
.jsf-gallery-item:focus-visible .jsf-gallery-item__overlay {
  opacity: 1;
}

.jsf-gallery--overlay-dark .jsf-gallery-item__overlay { background: rgba(15, 23, 42, .7); }
.jsf-gallery--overlay-light .jsf-gallery-item__overlay { background: rgba(255, 255, 255, .8); }
.jsf-gallery--overlay-gradient .jsf-gallery-item__overlay { background: linear-gradient(0deg, rgba(15,23,42,.85) 0%, rgba(15,23,42,.1) 60%, transparent 100%); justify-content: flex-end; }
.jsf-gallery--overlay-glass .jsf-gallery-item__overlay {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}

.jsf-gallery-item__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(255, 255, 255, .6);
  color: var(--color-white);
}

.jsf-gallery-item__icon svg {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  max-width: none;
}

.jsf-gallery-item__title {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: var(--fw-bold);
}

.jsf-gallery-item__description {
  font-family: var(--font-body);
  font-size: var(--fs-small);
}

.jsf-gallery-item__button {
  margin-top: var(--space-xs);
}

/* Overlay reveal animation variants */

.jsf-gallery--overlay-anim-fade .jsf-gallery-item__overlay {
  transition: opacity var(--transition);
}

.jsf-gallery--overlay-anim-slide .jsf-gallery-item__overlay {
  transform: translateY(16px);
  transition: opacity var(--transition), transform var(--transition);
}

.jsf-gallery--overlay-anim-slide .jsf-gallery-item:hover .jsf-gallery-item__overlay {
  transform: translateY(0);
}

.jsf-gallery--overlay-anim-zoom .jsf-gallery-item__overlay {
  transform: scale(.9);
  transition: opacity var(--transition), transform var(--transition);
}

.jsf-gallery--overlay-anim-zoom .jsf-gallery-item:hover .jsf-gallery-item__overlay {
  transform: scale(1);
}

.jsf-gallery--overlay-anim-reveal .jsf-gallery-item__overlay {
  clip-path: inset(100% 0 0 0);
  opacity: 1;
  transition: clip-path var(--transition);
}

.jsf-gallery--overlay-anim-reveal .jsf-gallery-item:hover .jsf-gallery-item__overlay {
  clip-path: inset(0 0 0 0);
}

/* ---------- Hover effects ---------- */

.jsf-gallery--hover-zoom .jsf-gallery-item:hover .jsf-gallery-item__media img {
  transform: scale(1.08);
}

.jsf-gallery--hover-scale .jsf-gallery-item {
  transition: transform var(--transition);
}

.jsf-gallery--hover-scale .jsf-gallery-item:hover {
  transform: scale(1.03);
  z-index: 2;
}

.jsf-gallery--hover-lift .jsf-gallery-item {
  transition: transform var(--transition), box-shadow var(--transition);
}

.jsf-gallery--hover-lift .jsf-gallery-item:hover {
  transform: translateY(-8px);
  box-shadow: var(--shadow-medium);
  z-index: 2;
}

.jsf-gallery--hover-rotate .jsf-gallery-item:hover .jsf-gallery-item__media img {
  transform: scale(1.05) rotate(2deg);
}

.jsf-gallery--hover-blur .jsf-gallery-item:hover .jsf-gallery-item__media img {
  filter: blur(3px) brightness(.85);
}

.jsf-gallery--hover-fade .jsf-gallery-item:hover .jsf-gallery-item__media img {
  opacity: .6;
}

.jsf-gallery--hover-border-yes .jsf-gallery-item {
  box-shadow: inset 0 0 0 0 var(--color-secondary);
  transition: box-shadow var(--transition);
}

.jsf-gallery--hover-border-yes .jsf-gallery-item:hover {
  box-shadow: inset 0 0 0 2px var(--color-secondary);
}

.jsf-gallery--hover-glow-yes .jsf-gallery-item:hover {
  box-shadow: 0 0 30px 6px rgba(var(--color-secondary-rgb), .4);
}

/* ---------- Card ---------- */

.jsf-gallery--card-hover-lift-yes .jsf-gallery-item:hover {
  transform: translateY(-6px);
}

/* ---------- Glass card ---------- */

.jsf-gallery--glass-yes .jsf-gallery-item {
  border-radius: var(--radius-lg);
  padding: var(--space-xs);
}

.jsf-gallery--glass-hover-yes .jsf-gallery-item:hover {
  background-color: rgba(255, 255, 255, .7);
}

/* ---------- Accessibility ---------- */

.jsf-gallery-item:focus-visible {
  outline: 2px solid var(--color-secondary);
  outline-offset: 3px;
}

/* ---------- Entrance animation hook ---------- */

.jsf-animate {
  opacity: 0;
  animation-play-state: paused;
}

.jsf-animate.is-visible {
  animation-play-state: running;
}

/* ==========================================================================
   LAYOUT: Bento Grid (default)
   ========================================================================== */

.jsf-gallery--layout-bento .jsf-gallery {
  --jsf-bento-columns: 4;
  grid-template-columns: repeat(var(--jsf-bento-columns), 1fr);
  grid-auto-rows: 140px;
  grid-auto-flow: row;
}

.jsf-gallery--bento-dense-yes .jsf-gallery {
  grid-auto-flow: dense;
}

.jsf-gallery--layout-bento .jsf-gallery-item__media {
  height: 100%;
}

.jsf-gallery-item--span-large {
  grid-column: span 2;
  grid-row: span 2;
}

.jsf-gallery-item--span-wide {
  grid-column: span 2;
  grid-row: span 1;
}

.jsf-gallery-item--span-tall {
  grid-column: span 1;
  grid-row: span 2;
}

.jsf-gallery-item--span-normal {
  grid-column: span 1;
  grid-row: span 1;
}

/* ==========================================================================
   LAYOUT: Classic Grid
   ========================================================================== */

.jsf-gallery--layout-grid .jsf-gallery {
  grid-template-columns: repeat(4, 1fr);
}

.jsf-gallery--layout-grid .jsf-gallery-item__media {
  aspect-ratio: 1 / 1;
}

.jsf-gallery--equal-height-yes.jsf-gallery--layout-grid .jsf-gallery-item {
  height: 100%;
}

/* ==========================================================================
   LAYOUT: Masonry
   ========================================================================== */

.jsf-gallery--layout-masonry .jsf-gallery {
  display: block;
  column-count: 4;
  column-gap: var(--jsf-gallery-gap);
}

.jsf-gallery--layout-masonry .jsf-gallery-item {
  display: inline-block;
  width: 100%;
  margin-bottom: var(--jsf-gallery-gap);
  break-inside: avoid;
}

.jsf-gallery--layout-masonry:not(.jsf-gallery--masonry-variable-height-yes) .jsf-gallery-item__media {
  aspect-ratio: 1 / 1;
}

/* ==========================================================================
   LAYOUT: Carousel / Slider
   ========================================================================== */

.jsf-gallery--layout-carousel .jsf-gallery {
  display: flex;
  grid-template-columns: none;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.jsf-gallery--layout-carousel .jsf-gallery::-webkit-scrollbar {
  display: none;
}

.jsf-gallery--layout-carousel .jsf-gallery-item {
  flex: 0 0 calc((100% - (var(--jsf-gallery-gap) * 2)) / 3);
  scroll-snap-align: start;
}

.jsf-gallery--layout-carousel .jsf-gallery-item__media {
  aspect-ratio: 4 / 3;
}

.jsf-gallery-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--color-white);
  color: var(--color-heading);
  box-shadow: var(--shadow-medium);
  transition: transform var(--transition-fast), background-color var(--transition-fast);
}

.jsf-gallery-arrow svg {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  max-width: none;
}

.jsf-gallery-arrow:hover {
  background: var(--color-highlight);
  transform: translateY(-50%) scale(1.05);
}

.jsf-gallery-arrow--prev { left: -8px; }
.jsf-gallery-arrow--next { right: -8px; }

.jsf-gallery-dots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  margin-top: var(--space-md);
}

.jsf-gallery-dots__dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-border);
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.jsf-gallery-dots__dot.is-active {
  background: var(--color-primary);
  transform: scale(1.3);
}

/* ---------- Filters ---------- */

.jsf-gallery-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
}

.jsf-gallery-filters__btn {
  padding: var(--space-2xs) var(--space-md);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-body);
  font-family: var(--font-heading);
  font-size: var(--fs-small);
  font-weight: var(--fw-semibold);
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.jsf-gallery-filters__btn:hover {
  border-color: var(--color-secondary);
  color: var(--color-primary);
}

.jsf-gallery-filters__btn.is-active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-white);
}

.jsf-gallery-item.is-filtered-out {
  display: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 1024px) {
  .jsf-gallery--layout-bento .jsf-gallery { --jsf-bento-columns: 3; }
  .jsf-gallery--layout-grid .jsf-gallery { grid-template-columns: repeat(3, 1fr); }
  .jsf-gallery--layout-masonry .jsf-gallery { column-count: 3; }
  .jsf-gallery--layout-carousel .jsf-gallery-item { flex-basis: calc((100% - var(--jsf-gallery-gap)) / 2); }
}

@media (max-width: 767px) {
  .jsf-gallery--layout-bento .jsf-gallery { --jsf-bento-columns: 2; }
  .jsf-gallery--layout-grid .jsf-gallery { grid-template-columns: repeat(2, 1fr); }
  .jsf-gallery--layout-masonry .jsf-gallery { column-count: 2; }
  .jsf-gallery--layout-carousel .jsf-gallery-item { flex-basis: 85%; }

  .jsf-gallery-item--span-large,
  .jsf-gallery-item--span-wide {
    grid-column: span 2;
  }

  .jsf-gallery-arrow {
    width: 36px;
    height: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .jsf-gallery-item__media img,
  .jsf-gallery-item__overlay,
  .jsf-gallery-item,
  .jsf-animate {
    transition: none !important;
    animation: none !important;
  }
}
