/*
 * BAS lightbox styles: the full-screen image viewer that the public gallery
 * and article images share (docs/style-system.md, ST-27, ST-55 to ST-59).
 * lightbox.js drives it. Every design value comes from the BAS tokens file
 * through var(--bas-...).
 */

body.bas-public-gallery-modal-open {
  overflow: hidden;
}

.bas-public-gallery__modal,
.bas-public-gallery__modal * {
  box-sizing: border-box;
}

/* Lightbox: near-black in both modes. Themes such as Twenty Twenty-One
   colour every <button> with high-specificity rules, so the lightbox
   controls mark their colours !important. */

.bas-public-gallery__modal[hidden] {
  display: none;
}

.bas-public-gallery__modal {
  align-items: stretch;
  background: var(--bas-lightbox-backdrop);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  padding: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 100000;
}

.bas-public-gallery__dialog {
  background: var(--bas-lightbox-bg);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  max-width: 100vw;
  overflow: hidden;
  position: relative;
  width: 100vw;
}

.bas-public-gallery__modal--details-open .bas-public-gallery__dialog {
  grid-template-columns: minmax(0, 1fr) clamp(320px, 24vw, 430px);
}

.bas-public-gallery__modal-image-wrap {
  align-items: center;
  background: var(--bas-lightbox-bg);
  display: flex;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

.bas-public-gallery__modal-image {
  display: block;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
  width: 100%;
}

.bas-public-gallery__nav,
.bas-public-gallery__icon-button,
.bas-public-gallery__detail-close {
  align-items: center;
  appearance: none;
  background: var(--bas-lightbox-control-bg) !important;
  border: 1px solid var(--bas-lightbox-control-border);
  border-radius: var(--bas-radius-pill);
  box-shadow: var(--bas-shadow-float);
  color: var(--bas-lightbox-control-text) !important;
  cursor: pointer;
  display: flex;
  justify-content: center;
  min-width: 0;
  padding: 0;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, color 0.16s ease, opacity 0.16s ease, transform 0.16s ease;
}

.bas-public-gallery__nav:hover,
.bas-public-gallery__nav:focus,
.bas-public-gallery__icon-button:hover,
.bas-public-gallery__icon-button:focus,
.bas-public-gallery__detail-close:hover,
.bas-public-gallery__detail-close:focus {
  background: var(--bas-lightbox-control-bg-hover) !important;
  border-color: var(--bas-lightbox-control-border-hover);
  box-shadow: var(--bas-shadow-float-hover);
  color: var(--bas-lightbox-control-text-hover) !important;
  outline: none;
}

.bas-public-gallery__control-icon {
  display: block;
  fill: none;
  flex: 0 0 auto;
  height: var(--bas-icon-lg);
  pointer-events: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
  width: var(--bas-icon-lg);
}

.bas-public-gallery__nav {
  height: var(--bas-icon-button-lg);
  opacity: 0.92;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: var(--bas-icon-button-lg);
  z-index: 2;
}

.bas-public-gallery__nav--prev:hover,
.bas-public-gallery__nav--prev:focus {
  transform: translate(-2px, -50%);
}

.bas-public-gallery__nav--next:hover,
.bas-public-gallery__nav--next:focus {
  transform: translate(2px, -50%);
}

.bas-public-gallery__nav--prev {
  left: var(--bas-space-4);
}

.bas-public-gallery__nav--next {
  right: var(--bas-space-4);
}

.bas-public-gallery__icon-button {
  height: var(--bas-icon-button);
  position: absolute;
  top: var(--bas-space-4);
  width: var(--bas-icon-button);
  z-index: 3;
}

.bas-public-gallery__icon-button .bas-public-gallery__control-icon,
.bas-public-gallery__detail-close .bas-public-gallery__control-icon {
  height: var(--bas-icon);
  width: var(--bas-icon);
}

.bas-public-gallery__close {
  right: var(--bas-space-4);
}

/* The information button sits left of the original-image link (ST-56). */
.bas-public-gallery__info {
  right: calc(var(--bas-space-4) + 2 * (var(--bas-icon-button) + var(--bas-space-2)));
}

.bas-public-gallery__modal--details-open .bas-public-gallery__info {
  display: none;
}

.bas-public-gallery__detail {
  background: var(--bas-surface);
  border-left: 1px solid var(--bas-rule);
  color: var(--bas-text);
  display: none;
  height: 100vh;
  max-height: 100vh;
  overflow: auto;
  padding: var(--bas-space-5);
}

.bas-public-gallery__modal--details-open .bas-public-gallery__detail {
  display: block;
}

.bas-public-gallery__detail-header {
  align-items: start;
  display: flex;
  gap: var(--bas-gap-group);
  justify-content: space-between;
  margin-bottom: var(--bas-gap-group);
}

.bas-public-gallery__detail h2 {
  color: var(--bas-heading);
  font-size: var(--bas-text-2xl);
  line-height: var(--bas-leading-tight);
  margin: 0;
}

.bas-public-gallery__detail-close {
  flex: 0 0 auto;
  height: var(--bas-icon-button);
  position: relative;
  width: var(--bas-icon-button);
}

/* Caption and original-image link: shown when the item supplies them. */

.bas-public-gallery__modal [hidden] {
  display: none !important;
}

.bas-public-gallery__original {
  right: calc(var(--bas-space-4) + var(--bas-icon-button) + var(--bas-space-2));
  text-decoration: none;
}

.bas-public-gallery__caption {
  background: var(--bas-lightbox-control-bg);
  border: 1px solid var(--bas-lightbox-control-border);
  border-radius: var(--bas-radius-md);
  bottom: var(--bas-space-4);
  color: var(--bas-lightbox-control-text);
  font-family: var(--bas-font-sans);
  font-size: var(--bas-text-sm);
  left: 50%;
  line-height: var(--bas-leading-snug);
  margin: 0;
  max-width: min(var(--bas-measure), calc(100% - 2 * var(--bas-space-4)));
  padding: var(--bas-space-2) var(--bas-space-3);
  position: absolute;
  transform: translateX(-50%);
  width: max-content;
  z-index: 2;
}

/* Article images that open the lightbox (ST-58). */

.bas-lightbox-trigger {
  cursor: zoom-in;
}

.bas-lightbox-trigger:focus {
  outline: none;
}

.bas-lightbox-trigger:focus-visible {
  box-shadow: var(--bas-shadow-focus);
  outline: 2px solid var(--bas-focus-border);
  outline-offset: 2px;
}

@media (max-width: 700px) {
  .bas-public-gallery__modal {
    padding: 0;
  }

  .bas-public-gallery__dialog,
  .bas-public-gallery__modal--details-open .bas-public-gallery__dialog {
    grid-template-columns: 1fr;
    height: 100vh;
    max-height: 100vh;
    max-width: 100vw;
    width: 100vw;
  }

  .bas-public-gallery__modal-image-wrap {
    height: 100vh;
    min-height: 0;
  }

  .bas-public-gallery__modal--details-open .bas-public-gallery__modal-image-wrap {
    height: 48vh;
    min-height: 240px;
  }

  .bas-public-gallery__modal-image {
    height: 100%;
    max-height: 100%;
    width: 100%;
  }

  .bas-public-gallery__nav {
    height: var(--bas-icon-button);
    width: var(--bas-icon-button);
  }

  .bas-public-gallery__nav--prev {
    left: var(--bas-space-3);
  }

  .bas-public-gallery__nav--next {
    right: var(--bas-space-3);
  }

  .bas-public-gallery__icon-button {
    top: var(--bas-space-3);
  }

  .bas-public-gallery__close {
    right: var(--bas-space-3);
  }

  .bas-public-gallery__info {
    right: calc(var(--bas-space-3) + 2 * (var(--bas-icon-button) + var(--bas-space-2)));
  }

  .bas-public-gallery__detail {
    height: 52vh;
    max-height: 52vh;
    padding: var(--bas-pad-card);
  }

  .bas-public-gallery__detail h2 {
    font-size: var(--bas-text-xl);
  }

  .bas-public-gallery__original {
    right: calc(var(--bas-space-3) + var(--bas-icon-button) + var(--bas-space-2));
  }

  .bas-public-gallery__caption {
    bottom: var(--bas-space-3);
    max-width: calc(100% - 2 * var(--bas-space-3));
  }
}
