/* Public gallery */
.public-gallery {
  margin: 18px 0 26px;
  min-width: 0;
}

.public-gallery-main,
.public-gallery-thumb,
.public-gallery-more {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  font: inherit;
}

.public-gallery-main {
  display: block;
  width: 100%;
}

.public-gallery-main img {
  display: block;
  width: 100%;
}

/*
 * Original gallery items stay in the DOM as the data source for the fullscreen
 * viewer. When JavaScript creates the inline swipe carousel, the legacy main
 * preview is hidden and the carousel becomes the visible public presentation.
 */
.public-gallery-strip {
  display: none;
}

.public-gallery.has-swipe-carousel > .public-gallery-main,
.public-gallery.has-swipe-carousel > figure {
  display: none;
}

.public-gallery-swipe {
  width: 100%;
  min-width: 0;
}

.public-gallery-swipe-track {
  display: flex;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border-radius: 22px;
  touch-action: pan-x pan-y;
}

.public-gallery-swipe-track::-webkit-scrollbar {
  display: none;
}

.public-gallery-swipe-slide {
  display: block;
  width: 100%;
  min-width: 100%;
  flex: 0 0 100%;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 22px;
  background: transparent;
  cursor: zoom-in;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.public-gallery-swipe-slide img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 520px;
  object-fit: cover;
  border-radius: 22px;
  user-select: none;
  -webkit-user-drag: none;
}

.public-gallery-swipe-dots {
  display: flex;
  gap: 7px;
  align-items: center;
  justify-content: center;
  min-height: 18px;
  margin-top: 10px;
}

.public-gallery-swipe-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(117, 108, 98, 0.32);
  transition:
    width 160ms ease,
    background 160ms ease;
}

.public-gallery-swipe-dot.is-active {
  width: 18px;
  background: var(--accent);
}

.public-gallery-swipe-hint {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.public-gallery-thumb {
  width: 88px;
  height: 66px;
  flex: 0 0 88px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.public-gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.public-gallery-more {
  min-width: 120px;
  min-height: 66px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(250, 247, 242, 0.94);
  color: var(--accent-hover);
  font-size: 0.82rem;
  font-weight: 800;
  box-shadow: var(--shadow-soft);
}

.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(24, 20, 17, 0.94);
  color: #fff;
  touch-action: pan-y;
}

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

.gallery-lightbox-stage {
  position: relative;
  width: min(1120px, 100%);
  max-height: calc(100vh - 44px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.gallery-lightbox-image {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 150px);
  object-fit: contain;
  border-radius: 16px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.35);
}

.gallery-lightbox-caption {
  max-width: 760px;
  margin: 14px auto 0;
  color: rgba(255, 255, 255, 0.9);
  text-align: center;
  font-size: 0.95rem;
}

.gallery-lightbox-close,
.gallery-lightbox-prev,
.gallery-lightbox-next {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(20, 18, 16, 0.58);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.gallery-lightbox-close {
  top: 0;
  right: 0;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  font-size: 24px;
}

.gallery-lightbox-prev,
.gallery-lightbox-next {
  top: 50%;
  width: 48px;
  height: 48px;
  transform: translateY(-50%);
  border-radius: 999px;
  font-size: 26px;
}

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

.gallery-lightbox-counter {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(20, 18, 16, 0.55);
  font-size: 0.8rem;
  font-weight: 800;
  backdrop-filter: blur(8px);
}

body.gallery-lightbox-open {
  overflow: hidden;
}

/* Admin gallery */
.gallery-admin-header {
  align-items: center;
}

.gallery-upload-form {
  margin-bottom: 34px;
}

.gallery-admin-section {
  margin-top: 34px;
}

.gallery-admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.gallery-admin-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(250, 247, 242, 0.96);
  box-shadow: var(--shadow-soft);
}

.gallery-admin-card.is-dragging {
  opacity: 0.55;
  transform: scale(0.985);
}

.gallery-admin-image-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 15px;
  background: var(--surface-2);
}

.gallery-admin-image-wrap img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.gallery-admin-position,
.gallery-drag-handle {
  position: absolute;
  top: 10px;
  border-radius: 999px;
  background: rgba(42, 36, 31, 0.82);
  color: white;
  backdrop-filter: blur(8px);
}

.gallery-admin-position {
  left: 10px;
  min-width: 30px;
  padding: 5px 9px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 800;
}

.gallery-drag-handle {
  right: 10px;
  min-width: 38px;
  height: 34px;
  border: 0;
  cursor: grab;
  font-size: 18px;
}

.gallery-drag-handle:active {
  cursor: grabbing;
}

.gallery-caption-form {
  display: grid;
  gap: 10px;
  margin: 14px 0 10px;
}

.gallery-caption-form label {
  display: grid;
  gap: 7px;
}

.gallery-caption-form label span {
  font-size: 12px;
  font-weight: 800;
  color: #51483f;
}

.gallery-caption-form input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid #d6cabd;
  border-radius: 12px;
  background: #fffdf9;
  color: var(--text);
  font: inherit;
}

.gallery-manage-button {
  margin-left: 0;
}

.admin-toolbar:has(.gallery-manage-button) .back-link {
  margin-right: auto;
}

/*
 * Object images are managed only through the gallery. Legacy cover_image_url
 * is retained as a fallback for older records, but the admin UI no longer
 * offers a separate cover upload/preview. The first gallery image is the cover.
 */
form[action^="/admin/museums/"] label:has(input[name="cover_image"]),
#object-builder-form label:has(input[name="cover_image"]) {
  display: none !important;
}

.object-current-media > .media-status-card:first-child {
  display: none !important;
}

.object-current-media {
  grid-template-columns: 1fr !important;
}

@media (max-width: 640px) {
  .gallery-admin-grid {
    grid-template-columns: 1fr;
  }

  .public-gallery-swipe-track,
  .public-gallery-swipe-slide,
  .public-gallery-swipe-slide img {
    border-radius: 18px;
  }

  .public-gallery-swipe-slide img {
    width: 100%;
    max-height: none;
    aspect-ratio: 4 / 3;
    object-fit: cover;
  }

  .public-gallery-swipe-hint {
    font-size: 10px;
  }

  .gallery-lightbox {
    padding: 10px;
  }

  .gallery-lightbox-image {
    max-height: calc(100vh - 120px);
    border-radius: 12px;
  }

  .gallery-lightbox-prev,
  .gallery-lightbox-next {
    width: 42px;
    height: 42px;
  }

  .gallery-lightbox-prev {
    left: 2px;
  }
  .gallery-lightbox-next {
    right: 2px;
  }
}
