/*
 * TreX Image Lightbox
 * Frontend styles for CKEditor embedded images and the lightbox viewer.
 */

/* --------------------------------------------------------------------------
 * Embedded image trigger
 * -------------------------------------------------------------------------- */

/* The marker only stores lightbox metadata; it does not change the layout. */
.trex-image-lightbox-marker {
  display: contents;
}

.trex-image-lightbox__trigger {
  cursor: zoom-in;
}

.trex-image-lightbox__trigger:focus-visible {
  outline: 3px solid currentColor;
  outline-offset: 3px;
}

/* Keep the icon inside the rendered embedded entity. */
.trex-image-lightbox-marker > .embedded-entity,
.embedded-entity[data-lightbox] {
  position: relative;
  overflow: hidden;
  border-radius: 2.5px;
}

/* Do not enlarge, move, fade, or animate the image on hover. */
.trex-image-lightbox-marker > .embedded-entity img,
.embedded-entity[data-lightbox] img,
.trex-image-lightbox-marker > .embedded-entity:hover img,
.trex-image-lightbox-marker > .embedded-entity:focus-within img,
.embedded-entity[data-lightbox]:hover img,
.embedded-entity[data-lightbox]:focus-within img {
  display: block;
  opacity: 1;
  transform: none !important;
  transition: none;
}

/* Expand icon shown in the lower-right corner. */
.trex-image-lightbox-marker > .embedded-entity::after,
.embedded-entity[data-lightbox]::after {
  content: "⛶";
  position: absolute;
  right: 10px;
  bottom: 8px;
  z-index: 2;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.68);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.trex-image-lightbox-marker > .embedded-entity:hover::after,
.trex-image-lightbox-marker > .embedded-entity:focus-within::after,
.embedded-entity[data-lightbox]:hover::after,
.embedded-entity[data-lightbox]:focus-within::after {
  opacity: 1;
  transform: translateY(0);
}

/* --------------------------------------------------------------------------
 * Lightbox overlay
 * -------------------------------------------------------------------------- */

body.tilb-open {
  overflow: hidden;
}

#tilb,
#tilb * {
  box-sizing: border-box;
}

#tilb {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;

  /* 2vw + 96vw + 2vw = 100vw. */
  padding: 3vh 2vw;

  background: rgba(0, 0, 0, 0.82);
}

#tilb[hidden] {
  display: none;
}

#tilb .tilb__backdrop {
  position: absolute;
  inset: 0;
}

/*
 * Uses almost the entire viewport without reaching 100%.
 * There is no fixed 960px limit.
 */
#tilb .tilb__dialog {
  position: relative;
  z-index: 1;
  width: 96vw;
  height: 94vh;
  height: 94dvh;
  max-width: 96vw;
  max-height: 94vh;
  max-height: 94dvh;
  overflow: hidden;
  border-radius: 12px;
  background: #111;
  box-shadow: 0 14px 48px rgba(0, 0, 0, 0.45);
  font-family: inherit;
}

#tilb .tilb__items {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#tilb .tilb__item {
  position: relative;
  display: none;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  background: #111;
}

#tilb .tilb__item.is-active {
  display: flex;
  align-items: center;
  justify-content: center;
}

/*
 * The image uses all available dialog space while preserving its proportions.
 * object-fit: contain prevents cropping.
 */
#tilb .tilb__item img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  margin: 0;
  object-fit: contain;
  object-position: center;
}

/* --------------------------------------------------------------------------
 * Loading state
 * -------------------------------------------------------------------------- */

@keyframes tilb-skeleton {
  0% {
    background-position: 100% 0;
  }

  100% {
    background-position: 0 0;
  }
}

#tilb .tilb__item::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(90deg, #202020 0%, #303030 50%, #202020 100%);
  background-size: 200% 100%;
  animation: tilb-skeleton 1.1s linear infinite;
  opacity: 0;
  pointer-events: none;
}

#tilb .tilb__item.is-loading::before {
  opacity: 1;
}

/* --------------------------------------------------------------------------
 * Caption and counter
 * -------------------------------------------------------------------------- */

#tilb .tilb__caption {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 46px;
  padding: 10px 16px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 0.9rem;
  line-height: 1.35;
}

#tilb .tilb__counter {
  flex: 0 0 auto;
  font-weight: 700;
}

#tilb .tilb__text {
  min-width: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
 * Controls
 * -------------------------------------------------------------------------- */

#tilb .tilb__close,
#tilb .tilb__nav {
  border: 0;
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#tilb .tilb__close {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 999px;
  background: rgba(17, 17, 17, 0.88);
  font-size: 30px;
  line-height: 1;
}

#tilb .tilb__nav {
  position: absolute;
  top: 50%;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.58);
  font-size: 30px;
  line-height: 1;
}

#tilb .tilb__prev {
  left: 14px;
}

#tilb .tilb__next {
  right: 14px;
}

#tilb .tilb__close:hover,
#tilb .tilb__close:focus-visible,
#tilb .tilb__nav:hover,
#tilb .tilb__nav:focus-visible {
  background: rgba(0, 0, 0, 0.82);
}

#tilb .tilb__close:focus-visible,
#tilb .tilb__nav:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

#tilb.is-single .tilb__nav,
#tilb.is-single .tilb__counter {
  display: none;
}

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

@media (max-width: 768px) {
  #tilb {
    padding: 2vh 2vw;
  }

  #tilb .tilb__dialog {
    width: 96vw;
    height: 96vh;
    height: 96dvh;
    max-width: 96vw;
    max-height: 96vh;
    max-height: 96dvh;
    border-radius: 9px;
  }

  #tilb .tilb__close {
    top: 9px;
    right: 9px;
    width: 42px;
    height: 42px;
  }

  #tilb .tilb__nav {
    width: 42px;
    height: 42px;
  }

  #tilb .tilb__prev {
    left: 8px;
  }

  #tilb .tilb__next {
    right: 8px;
  }

  #tilb .tilb__caption {
    gap: 0.6rem;
    min-height: 44px;
    padding: 9px 12px;
    font-size: 0.82rem;
  }

  /* Touch devices do not have a reliable hover state. */
  .trex-image-lightbox-marker > .embedded-entity::after,
  .embedded-entity[data-lightbox]::after {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .trex-image-lightbox-marker > .embedded-entity::after,
  .embedded-entity[data-lightbox]::after,
  #tilb .tilb__item::before {
    animation: none;
    transition: none;
  }
}
