/* Native dialog photo viewer. Closed dialogs keep their native display:none. */
dialog.photo-lightbox {
  position: fixed;
  inset: 0;
  width: min(1160px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  height: min(860px, calc(100vh - 32px));
  height: min(860px, calc(100dvh - 32px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  min-width: 0;
  min-height: 0;
  margin: auto;
  padding: 0;
  border: 1px solid #ffffff38;
  border-radius: 26px;
  overflow: hidden;
  overscroll-behavior: contain;
  color: var(--ink, #1d1d1f);
  background: #fff;
  font-family: var(--font-body, "Alibaba PuHuiTi", sans-serif);
  font-weight: 600;
  box-shadow: 0 30px 100px #0005;
}

dialog.photo-lightbox[open] {
  display: block;
}

dialog.photo-lightbox::backdrop {
  background: #101418cf;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

dialog.photo-lightbox .lightbox-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* Neither the shell nor dialog scrolls: this row always stays in view. */
dialog.photo-lightbox .lightbox-toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-width: 0;
  min-height: 76px;
  padding: 16px 22px;
  border-bottom: 1px solid #e9e9ed;
  background: #fff;
}

dialog.photo-lightbox .lightbox-toolbar h2 {
  min-width: 0;
  margin: 0;
  color: #1d1d1f;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -.018em;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

dialog.photo-lightbox .lightbox-close {
  position: relative;
  float: none;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 11px;
  min-width: 96px;
  min-height: 44px;
  margin: 0;
  padding: 9px 15px;
  border: 0;
  border-radius: 999px;
  color: #1d1d1f;
  background: #f0f0f3;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 160ms ease;
}

dialog.photo-lightbox .lightbox-close span:last-child {
  display: inline-block;
  font-size: 25px;
  font-weight: 600;
  line-height: 1;
}

dialog.photo-lightbox .lightbox-close:hover {
  background: #e4e4e9;
}

dialog.photo-lightbox .lightbox-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: clamp(14px, 2.5vw, 32px);
  overflow: hidden;
  background: #f5f5f7;
}

dialog.photo-lightbox #lightbox-image {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  mix-blend-mode: multiply;
}

dialog.photo-lightbox #lightbox-status {
  position: absolute;
  bottom: 16px;
  left: 50%;
  max-width: calc(100% - 28px);
  margin: 0;
  padding: 10px 16px;
  border-radius: 16px;
  color: #1d1d1f;
  background: #fffffff2;
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
  overflow-wrap: anywhere;
  transform: translateX(-50%);
}

dialog.photo-lightbox .lightbox-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 22px;
  min-width: 0;
  min-height: 78px;
  padding: 16px 22px;
  border-top: 1px solid #e9e9ed;
  background: #fff;
}

/* Only a long caption can scroll; it cannot displace the close toolbar. */
dialog.photo-lightbox #lightbox-caption {
  min-width: 0;
  min-height: 0;
  max-height: 4.8em;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  margin: 0;
  padding-right: 4px;
  color: var(--muted, #6e6e73);
  font-size: 14px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

dialog.photo-lightbox .lightbox-navigation {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

dialog.photo-lightbox .lightbox-navigation button {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 1px solid #dcdce1;
  border-radius: 50%;
  color: #1d1d1f;
  background: #fff;
  font-family: inherit;
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease;
}

dialog.photo-lightbox .lightbox-navigation button:hover:not(:disabled) {
  border-color: #b8cfd4;
  background: #f0f5f6;
}

dialog.photo-lightbox .lightbox-navigation button:disabled {
  opacity: .35;
  cursor: default;
}

dialog.photo-lightbox #lightbox-counter {
  min-width: 50px;
  color: #6e6e73;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

dialog.photo-lightbox button:focus-visible {
  outline: 3px solid var(--cyan-dark, #007f91);
  outline-offset: 3px;
}

/* Fit the main photo's new link wrapper without affecting thumbnail links. */
.machine-page .machine-main-photo {
  position: relative;
}

.machine-page .machine-main-photo > .machine-photo-open {
  position: relative;
  display: grid;
  place-items: center;
  align-self: stretch;
  justify-self: stretch;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: inherit;
  color: inherit;
  text-decoration: none;
  cursor: zoom-in;
}

.machine-page .machine-main-photo > .machine-photo-open > img {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-height: 590px;
  object-fit: contain;
  object-position: center;
  mix-blend-mode: multiply;
}

.machine-page .machine-main-photo .machine-photo-hint {
  position: absolute;
  z-index: 1;
  right: 10px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  max-width: calc(100% - 20px);
  padding: 8px 13px;
  border: 1px solid #ffffffa8;
  border-radius: 999px;
  color: #1d1d1f;
  background: #ffffffdc;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
  pointer-events: none;
}

@media (max-width: 900px) {
  .machine-page .machine-main-photo > .machine-photo-open > img {
    max-height: 500px;
  }
}

@media (max-width: 600px) {
  dialog.photo-lightbox {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    border-radius: 20px;
  }

  dialog.photo-lightbox .lightbox-toolbar {
    min-height: 72px;
    gap: 12px;
    padding: 14px;
  }

  dialog.photo-lightbox .lightbox-toolbar h2 {
    font-size: 15px;
    line-height: 1.4;
    letter-spacing: -.01em;
  }

  dialog.photo-lightbox .lightbox-close {
    min-width: 90px;
    min-height: 44px;
    padding-inline: 13px;
    font-size: 13px;
    gap: 9px;
  }

  dialog.photo-lightbox .lightbox-stage {
    padding: 12px;
  }

  dialog.photo-lightbox .lightbox-footer {
    min-height: 76px;
    gap: 12px;
    padding: 14px;
  }

  dialog.photo-lightbox #lightbox-caption {
    font-size: 12px;
    line-height: 1.6;
    max-height: 4.8em;
  }

  dialog.photo-lightbox .lightbox-navigation {
    gap: 6px;
  }

  dialog.photo-lightbox #lightbox-counter {
    min-width: 46px;
    font-size: 12px;
  }

  .machine-page .machine-main-photo .machine-photo-hint {
    right: 7px;
    bottom: 7px;
    padding: 7px 11px;
    font-size: 12px;
  }
}

/* Portrait phones keep a useful image area; very short landscape viewports
   may shrink this track so the close button and navigation remain visible. */
@media (max-width: 600px) and (min-height: 480px) {
  dialog.photo-lightbox .lightbox-stage {
    min-height: 200px;
  }
}

@media (max-height: 440px) {
  dialog.photo-lightbox .lightbox-toolbar {
    min-height: 60px;
    padding-block: 8px;
  }

  dialog.photo-lightbox .lightbox-footer {
    min-height: 60px;
    padding-block: 8px;
  }

  dialog.photo-lightbox #lightbox-caption {
    max-height: 3.2em;
  }
}

@media (prefers-reduced-motion: reduce) {
  dialog.photo-lightbox .lightbox-close,
  dialog.photo-lightbox .lightbox-navigation button {
    transition: none;
  }
}
