/* Gallery-only layout: changing the photograph must not move its controls. */
#im-gallery-main-open {
  --hi-stage-height: min(580px, 60vh);
  --hi-stage-height: min(580px, 60svh);
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: var(--hi-stage-height);
  min-height: 0;
  padding: 0;
  overflow: hidden;
  isolation: isolate;
}

/* Reserve the whole dialog, including the caption row, before an image loads. */
#im-lightbox,
#v31-lightbox {
  --hi-dialog-height: min(900px, calc(100vh - 32px));
  --hi-dialog-height: min(900px, calc(100svh - 32px));
  --hi-stage-height: calc(var(--hi-dialog-height) - 180px);
  box-sizing: border-box;
  height: var(--hi-dialog-height);
  max-height: var(--hi-dialog-height);
  padding: 20px;
  overflow: hidden;
}

#im-lightbox[open],
#v31-lightbox[open] {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 44px var(--hi-stage-height) 64px;
  gap: 14px;
  align-content: center;
}

#im-lightbox .im-lightbox-top,
#im-lightbox .im-lightbox-bottom,
#v31-lightbox > div:not(.hi-gallery-stage),
#v31-lightbox > footer {
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  height: 100%;
  margin: 0;
  padding: 0;
  align-items: center;
}

#im-lightbox .im-lightbox-bottom,
#v31-lightbox > footer {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  gap: 14px;
}

#im-lightbox-caption,
#v31-lightbox #v31-photo-caption {
  min-width: 0;
  max-height: 100%;
  overflow: auto;
  overflow-wrap: anywhere;
  text-align: center;
  margin: 0;
}

#im-lightbox .hi-gallery-stage,
#v31-lightbox .hi-gallery-stage {
  position: relative;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  width: 100%;
  height: var(--hi-stage-height);
  min-width: 0;
  min-height: 0;
  padding: 0 !important;
  margin: 0;
  overflow: hidden;
  isolation: isolate;
  background: #080808 !important;
}

/* Keep the existing crop coordinates; contain the complete crop in the stage. */
#im-gallery-main-open > .v36-photo-window,
#im-lightbox .hi-gallery-stage > .v36-photo-window,
#v31-lightbox .hi-gallery-stage > .v36-photo-window {
  width: min(100%, calc(var(--hi-stage-height) * var(--photo-ratio)));
  height: auto;
  max-height: none;
  aspect-ratio: var(--photo-ratio);
  margin: 0;
  justify-self: center;
  align-self: center;
}

/* Albums have uncropped images; this also covers photos without a crop entry. */
#im-gallery-main-open > img,
#im-lightbox .hi-gallery-stage > img,
#v31-lightbox .hi-gallery-stage > #v31-large-photo {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  aspect-ratio: auto;
  object-fit: contain;
  object-position: center;
  margin: 0;
}

/* Only the status changes during loading; retain the previous decoded photo. */
#im-gallery-main-open[aria-busy="true"]::after,
.hi-gallery-stage[aria-busy="true"]::after {
  content: "Načítám…";
  position: absolute;
  z-index: 3;
  left: 12px;
  bottom: 12px;
  padding: 6px 9px;
  border-radius: 3px;
  background: #fffffff0;
  color: #333;
  font: 12px/1.4 Arial, sans-serif;
  pointer-events: none;
}

#im-gallery-main-open[data-empty="true"] > img,
#im-gallery-main-open[data-empty="true"] > .v36-photo-window,
.hi-gallery-stage[data-empty="true"] > img,
.hi-gallery-stage[data-empty="true"] > .v36-photo-window {
  visibility: hidden;
}

#im-gallery-main-open .hi-gallery-error,
.hi-gallery-stage .hi-gallery-error {
  position: absolute;
  z-index: 4;
  inset: auto 16px 16px;
  padding: 12px;
  border-radius: 3px;
  background: #fffffff0;
  color: #333;
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
}

.hi-gallery-error[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  #im-gallery-main-open {
    --hi-stage-height: min(calc((100vw - 32px) * .75), 50vh);
    --hi-stage-height: min(calc((100vw - 32px) * .75), 50svh);
  }

  #im-lightbox,
  #v31-lightbox {
    --hi-dialog-height: calc(100vh - 16px);
    --hi-dialog-height: calc(100svh - 16px);
    --hi-stage-height: calc(var(--hi-dialog-height) - 154px);
    width: calc(100% - 16px);
    padding: 12px;
  }

  #im-lightbox[open],
  #v31-lightbox[open] {
    grid-template-rows: 44px var(--hi-stage-height) 64px;
    gap: 10px;
  }

  #im-lightbox .im-lightbox-bottom,
  #v31-lightbox > footer {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 10px;
  }

  #v31-lightbox > div:not(.hi-gallery-stage) {
    gap: 8px;
  }

  #v31-lightbox > div:not(.hi-gallery-stage) > strong {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  #v31-lightbox #v31-original-photo {
    font-size: 11px;
  }
}

/* A horizontal swipe changes photos; vertical scrolling and zoom stay native. */
#im-gallery-main-open,.hi-gallery-stage{touch-action:pan-y pinch-zoom}
/* Replacing an image must not make browser scroll anchoring move the page. */
#model-detail [data-section="galerie"],#im-lightbox,#v31-lightbox{overflow-anchor:none}
