/**
 * CSC Gallery - masonry grid + modal popup.
 */

.csc-gallery-masonry {
  column-width: var(--csc-gallery-column-width, 260px);
  column-gap: 1rem;
}

.csc-gallery-item {
  position: relative;
  break-inside: avoid;
  margin-bottom: 1rem;
}

.csc-gallery-trigger {
  display: block;
  position: relative;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  overflow: hidden;
  border-radius: 0.25rem;
}

.csc-gallery-trigger img {
  display: block;
  width: 100%;
  height: auto;
}

.csc-gallery-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.5rem 0.75rem;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.875rem;
  text-align: left;
  opacity: 0;
  transform: translateY(100%);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.csc-gallery-trigger:hover .csc-gallery-caption,
.csc-gallery-trigger:focus-visible .csc-gallery-caption,
.csc-gallery-trigger:focus-within .csc-gallery-caption {
  opacity: 1;
  transform: translateY(0);
}

.csc-gallery-edit-link {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #181818;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.csc-gallery-item:hover .csc-gallery-edit-link,
.csc-gallery-edit-link:focus-visible {
  opacity: 1;
}

/* Modal */

/*
 * Bootstrap's grid rule `.row > *` (width/max-width: 100%) matches this
 * modal whenever it renders as a direct child of a Views `.row` wrapper,
 * which makes its 100% width resolve against the theme's capped
 * container instead of the real viewport. Force full-viewport coverage
 * via inset so the dialog inside it can be centered reliably.
 */
.csc-gallery-modal.modal {
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  width: auto !important;
  height: auto !important;
  max-width: none !important;
}

.csc-gallery-modal .modal-dialog {
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  max-width: calc(100vw - 2rem);
  min-height: 100%;
  margin: 0 auto;
}

.csc-gallery-modal .modal-content {
  width: auto;
  background: transparent;
  border: 0;
}

.csc-gallery-modal-body {
  position: relative;
  padding: 0;
  text-align: center;
}

.csc-gallery-modal-image-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.csc-gallery-modal-image {
  display: block;
  max-width: 100%;
  max-height: var(--csc-gallery-modal-height, 90vh);
  object-fit: contain;
}

.csc-gallery-modal-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  text-align: left;
}

.csc-gallery-modal-caption:empty {
  display: none;
}

.csc-gallery-modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #181818;
  cursor: pointer;
}

.csc-gallery-modal-close-label {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translate(-50%, 0.25rem);
  white-space: nowrap;
  font-size: 0.75rem;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.csc-gallery-modal-close:hover .csc-gallery-modal-close-label,
.csc-gallery-modal-close:focus-visible .csc-gallery-modal-close-label {
  opacity: 1;
}

.csc-gallery-modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #181818;
  cursor: pointer;
}

.csc-gallery-modal-prev {
  left: 0.5rem;
}

.csc-gallery-modal-next {
  right: 0.5rem;
}
