.segw-gallery {
  display: grid;
  grid-template-columns: repeat(var(--segw-columns, 6), minmax(0, 1fr));
  gap: var(--segw-gap, 5px);
  width: 100%;
  clear: both;
  position: relative;
  overflow: visible;
}

.segw-empty {
  padding: 16px;
  border: 1px dashed currentColor;
  opacity: 0.75;
}

.segw-gallery__item {
  display: block;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  position: relative;
}

.segw-gallery__media {
  display: block;
  width: 100%;
  aspect-ratio: var(--segw-ratio, 1 / 1);
  overflow: hidden;
  background: #f2f2f2;
  position: relative;
}

.segw-gallery .segw-gallery__image {
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  object-fit: cover !important;
  object-position: center center !important;
}

.segw-gallery__caption {
  display: block;
  margin-top: 0.5em;
  font-size: 0.875em;
  line-height: 1.35;
}

@media (max-width: 1024px) {
  .segw-gallery {
    grid-template-columns: repeat(var(--segw-columns-tablet, 4), minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  .segw-gallery {
    grid-template-columns: repeat(var(--segw-columns-mobile, 3), minmax(0, 1fr));
  }
}

body.segw-lightbox-open {
  overflow: hidden;
  touch-action: none;
}

.segw-lightbox {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.9);
  overflow: hidden;
  overscroll-behavior: contain;
  -webkit-user-select: none;
  user-select: none;
}

.segw-lightbox.is-open {
  display: flex;
}

.segw-lightbox__stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(calc(100vw - 48px), 1380px);
  max-width: 1380px;
  max-height: calc(100vh - 48px);
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
}

.segw-lightbox__image {
  display: block;
  max-width: min(100%, 1380px);
  max-height: calc(100vh - 190px);
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center center;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform, opacity;
  touch-action: pan-y;
  cursor: grab;
}

.segw-lightbox.is-dragging .segw-lightbox__image {
  cursor: grabbing;
}

.segw-lightbox:not(.has-meta) .segw-lightbox__image {
  max-height: calc(100vh - 116px);
}

.segw-lightbox.is-single-image.has-meta .segw-lightbox__image {
  max-height: calc(100vh - 134px);
}

.segw-lightbox.is-single-image:not(.has-meta) .segw-lightbox__image {
  max-height: calc(100vh - 70px);
}

.segw-lightbox__meta {
  order: -1;
  width: 100%;
  max-width: 1380px;
  color: #fff;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0 16px 2px;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
}

.segw-lightbox__meta[hidden] {
  display: none;
}

.segw-lightbox__page-title {
  margin: 0 0 4px;
  color: #fff;
  font-size: clamp(20px, 2.2vw, 30px);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 0.01em;
  text-align: center;
}

.segw-lightbox__page-title[hidden] {
  display: none;
}

.segw-lightbox__title {
  margin: 0;
  color: rgba(255, 255, 255, 0.88);
  font-size: clamp(15px, 1.2vw, 18px);
  font-weight: 500;
  line-height: 1.35;
  text-align: center;
}

.segw-lightbox__title[hidden] {
  display: none;
}

.segw-lightbox__button {
  position: relative;
  border: 0;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  flex: 0 0 auto;
}

.segw-lightbox__nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  width: 100%;
  max-width: 1380px;
  padding: 2px 16px 0;
}

.segw-lightbox__nav[hidden] {
  display: none;
}

.segw-lightbox__button:hover,
.segw-lightbox__button:focus {
  background: rgba(255, 255, 255, 0.3);
  outline: 2px solid rgba(255, 255, 255, 0.75);
  outline-offset: 2px;
}

.segw-lightbox__close {
  position: absolute;
  top: 18px;
  right: 18px;
}

.segw-lightbox__prev,
.segw-lightbox__next {
  position: relative;
  inset: auto;
  transform: none;
}

.segw-lightbox__button[hidden] {
  display: none;
}

@media (pointer: coarse) {
  .segw-lightbox__button {
    width: 52px;
    height: 52px;
  }

  .segw-lightbox__stage,
  .segw-lightbox__image {
    touch-action: pan-y;
  }
}

@media (max-width: 767px) {
  .segw-lightbox {
    padding: 0;
    align-items: center;
    justify-content: center;
  }

  .segw-lightbox__stage {
    width: 100vw;
    max-width: 100vw;
    max-height: 100vh;
    gap: 8px;
  }

  .segw-lightbox__image {
    max-width: 100vw;
    width: 100vw;
    max-height: calc(100vh - 196px);
  }

  .segw-lightbox:not(.has-meta) .segw-lightbox__image {
    max-height: calc(100vh - 68px);
  }

  .segw-lightbox.is-single-image.has-meta .segw-lightbox__image {
    max-height: calc(100vh - 128px);
  }

  .segw-lightbox.is-single-image:not(.has-meta) .segw-lightbox__image {
    max-height: 100vh;
  }

  .segw-lightbox__meta {
    width: 100vw;
    max-width: 100vw;
    padding: 54px 16px 2px;
  }

  .segw-lightbox__page-title {
    font-size: clamp(21px, 6vw, 30px);
    font-weight: 800;
    line-height: 1.12;
  }

  .segw-lightbox__title {
    font-size: 15px;
    line-height: 1.3;
  }

  .segw-lightbox__close {
    top: 10px;
    right: 10px;
  }

  .segw-lightbox__nav {
    gap: 16px;
    padding: 0 16px 10px;
  }

  .segw-lightbox__prev,
  .segw-lightbox__next {
    position: relative;
    inset: auto;
    transform: none;
  }
}
