/* ==========================================================================
   CMS image zoom/pan viewer
   Applies to images inside .cmscontent. Loaded after assets/css/main.css.
   ========================================================================== */

.cmscontent img {
  cursor: zoom-in;
}

.cmscontent a > img {
  cursor: inherit;
}

.cmscontent img:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(0, 0, 0, 0.65);
}

body.cms-image-viewer-open {
  overflow: hidden;
}

/* Dialog shell ------------------------------------------------------------ */

.cms-image-viewer {
  --cms-image-viewer-fg: #fff;
  --cms-image-viewer-bg: rgba(10, 10, 10, 0.96);
  --cms-image-viewer-control-bg: rgba(255, 255, 255, 0.12);
  --cms-image-viewer-control-bg-hover: rgba(255, 255, 255, 0.22);
  --cms-image-viewer-control-border: rgba(255, 255, 255, 0.35);

  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  z-index: 100000;
  display: none;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: var(--cms-image-viewer-bg);
  color: var(--cms-image-viewer-fg);
  box-sizing: border-box;
  overscroll-behavior: contain;
  touch-action: none;
}

.cms-image-viewer[open] {
  display: flex;
  flex-direction: column;
}

.cms-image-viewer::backdrop {
  background: rgba(0, 0, 0, 0.9);
}

.cms-image-viewer *,
.cms-image-viewer *::before,
.cms-image-viewer *::after {
  box-sizing: border-box;
}

/* Toolbar ----------------------------------------------------------------- */

.cms-image-viewer__toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.65), rgba(0, 0, 0, 0));
}

.cms-image-viewer__button,
.cms-image-viewer__pan-button {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  border: 1px solid var(--cms-image-viewer-control-border);
  border-radius: 8px;
  background: var(--cms-image-viewer-control-bg);
  color: var(--cms-image-viewer-fg);
  box-shadow: none;
  font-family: inherit;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.cms-image-viewer__button {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  font-size: 22px;
}

.cms-image-viewer__button--text {
  padding: 0 14px;
  font-size: 14px;
}

.cms-image-viewer__button--close {
  font-size: 26px;
}

.cms-image-viewer__button:hover:not(:disabled),
.cms-image-viewer__pan-button:hover:not(:disabled) {
  background: var(--cms-image-viewer-control-bg-hover);
}

.cms-image-viewer__button:focus-visible,
.cms-image-viewer__pan-button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.cms-image-viewer__button:disabled,
.cms-image-viewer__pan-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.cms-image-viewer__zoom {
  min-width: 56px;
  color: var(--cms-image-viewer-fg);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  user-select: none;
}

/* Image stage ------------------------------------------------------------- */

.cms-image-viewer__stage {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  padding: 0 16px 16px;
  overflow: hidden;
}

.cms-image-viewer__canvas {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  cursor: default;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.cms-image-viewer__canvas.is-zoomed {
  cursor: grab;
}

.cms-image-viewer__canvas.is-panning {
  cursor: grabbing;
}

.cms-image-viewer__image {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.55);
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

/* Pan pad ----------------------------------------------------------------- */

.cms-image-viewer__pan {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, 42px);
  grid-template-rows: repeat(3, 42px);
  gap: 4px;
}

.cms-image-viewer__pan-button {
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 15px;
}

.cms-image-viewer__pan [data-cms-image-action="pan-up"] {
  grid-area: 1 / 2;
}

.cms-image-viewer__pan [data-cms-image-action="pan-left"] {
  grid-area: 2 / 1;
}

.cms-image-viewer__pan [data-cms-image-action="pan-right"] {
  grid-area: 2 / 3;
}

.cms-image-viewer__pan [data-cms-image-action="pan-down"] {
  grid-area: 3 / 2;
}

/* Hint -------------------------------------------------------------------- */

.cms-image-viewer__hint {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 3;
  max-width: calc(100% - 180px);
  margin: 0;
  padding: 0;
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  line-height: 1.4;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  user-select: none;
}

/* Responsive -------------------------------------------------------------- */

@media (max-width: 767px) {
  .cms-image-viewer__toolbar {
    gap: 5px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .cms-image-viewer__button {
    min-width: 40px;
    min-height: 40px;
    padding: 0 9px;
    font-size: 20px;
  }

  .cms-image-viewer__button--text {
    font-size: 13px;
  }

  .cms-image-viewer__zoom {
    min-width: 48px;
    font-size: 13px;
  }

  /* Zoomed images lay out at their natural size so CSS zoom stays sharp. */
  .cms-image-viewer__image.is-zoomed {
    max-width: none;
    max-height: none;
  }

  .cms-image-viewer__stage {
    padding: 0 8px 8px;
  }

  .cms-image-viewer__pan {
    right: 12px;
    bottom: 12px;
    grid-template-columns: repeat(3, 40px);
    grid-template-rows: repeat(3, 40px);
  }

  .cms-image-viewer__pan-button {
    width: 40px;
    height: 40px;
  }

  .cms-image-viewer__hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cms-image-viewer__button,
  .cms-image-viewer__pan-button {
    transition: none;
  }
}
