/* Front-end photo gallery. No third-party dependencies. */
.photo-gallery {
  --pg-border: #e5e7eb;
  --pg-muted: #6b7280;
  --pg-surface: #f8fafc;
  width: 100%;
  margin: 2rem 0;
  color: #111827;
}

.photo-gallery--initialized > .photo-gallery__items { display: none !important; }

.photo-gallery__layout {
  overflow: hidden;
  border: 1px solid var(--pg-border);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .06);
}

.photo-gallery__stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: clamp(220px, 42vw, 560px);
  max-height: 72vh;
  background: #111827;
  overflow: hidden;
  cursor: zoom-in;
  outline-offset: 4px;
}

.photo-gallery__stage-image {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 72vh;
  min-height: 220px;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.photo-gallery__stage-button,
.photo-gallery__thumb-scroll,
.photo-gallery__lightbox-button,
.photo-gallery__lightbox-close,
.photo-gallery__lightbox-thumb-scroll {
  display: inline-grid;
  place-items: center;
  border: 0;
  cursor: pointer;
  font: inherit;
  transition: background-color .18s ease, transform .18s ease, opacity .18s ease;
}

.photo-gallery__stage-button {
  position: absolute;
  z-index: 2;
  top: 50%;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: #fff;
  background: rgba(17, 24, 39, .62);
  font-size: 24px;
  line-height: 1;
  transform: translateY(-50%);
  opacity: .82;
}

.photo-gallery__stage-button:hover { background: rgba(17, 24, 39, .92); opacity: 1; }
.photo-gallery__stage-button:active { transform: translateY(-50%) scale(.96); }
.photo-gallery__stage-button--previous { left: 14px; }
.photo-gallery__stage-button--next { right: 14px; }

.photo-gallery__fullscreen-button {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  color: white;
  background: rgba(17, 24, 39, .62);
  cursor: pointer;
}
.photo-gallery__fullscreen-button:hover { background: rgba(17, 24, 39, .92); }
.photo-gallery__fullscreen-button svg { width: 21px; height: 21px; }

.photo-gallery__caption-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 10px 16px;
  color: var(--pg-muted);
  font-size: 13px;
}
.photo-gallery__caption { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-gallery__counter { flex: 0 0 auto; font-variant-numeric: tabular-nums; }

.photo-gallery__thumbbar {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  gap: 6px;
  align-items: center;
  padding: 10px;
  border-top: 1px solid var(--pg-border);
  background: var(--pg-surface);
}
.photo-gallery__thumb-scroll,
.photo-gallery__lightbox-thumb-scroll {
  width: 34px;
  height: 54px;
  border-radius: 9px;
  color: #374151;
  background: transparent;
  font-size: 24px;
}
.photo-gallery__thumb-scroll:hover,
.photo-gallery__lightbox-thumb-scroll:hover { background: #e5e7eb; }
.photo-gallery__thumb-scroll:disabled,
.photo-gallery__lightbox-thumb-scroll:disabled { opacity: .25; cursor: default; }

.photo-gallery__thumb-viewport,
.photo-gallery__lightbox-thumbs-viewport {
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
  scroll-behavior: smooth;
}
.photo-gallery__thumb-track,
.photo-gallery__lightbox-thumb-track {
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  min-width: 100%;
}
.photo-gallery__thumb {
  position: relative;
  display: block;
  flex: 0 0 76px;
  width: 76px;
  height: 58px;
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #e5e7eb;
  cursor: pointer;
  opacity: .76;
  transition: border-color .18s ease, opacity .18s ease, transform .18s ease;
}
.photo-gallery__thumb:hover { opacity: 1; transform: translateY(-1px); }
.photo-gallery__thumb[aria-current="true"] { border-color: #2563eb; opacity: 1; }
.photo-gallery__thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }

.photo-gallery__empty-state {
  margin: 0;
  padding: 22px;
  border: 1px dashed var(--pg-border);
  border-radius: 12px;
  color: var(--pg-muted);
  background: var(--pg-surface);
  text-align: center;
}

/* Full-screen lightbox overlay (works without the browser Fullscreen API). */
.photo-gallery__lightbox[hidden] { display: none !important; }
.photo-gallery__lightbox {
  position: fixed;
  z-index: 2147483000;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  color: #f9fafb;
  background: rgba(3, 7, 18, .98);
}
.photo-gallery__lightbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  padding: 0 4px 10px;
}
.photo-gallery__lightbox-meta { min-width: 0; }
.photo-gallery__lightbox-title { display: block; overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.photo-gallery__lightbox-counter { display: block; margin-top: 2px; color: #9ca3af; font-size: 12px; font-variant-numeric: tabular-nums; }
.photo-gallery__lightbox-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.photo-gallery__slideshow-label { display: flex; align-items: center; gap: 8px; color: #d1d5db; font-size: 12px; white-space: nowrap; }
.photo-gallery__slideshow-select {
  min-height: 34px;
  padding: 5px 28px 5px 10px;
  border: 1px solid #4b5563;
  border-radius: 8px;
  color: #f9fafb;
  background: #111827;
  font: inherit;
}
.photo-gallery__lightbox-close {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  color: #f9fafb;
  background: #1f2937;
  font-size: 27px;
  line-height: 1;
}
.photo-gallery__lightbox-close:hover { background: #374151; }
.photo-gallery__lightbox-main {
  position: relative;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  gap: 8px;
  align-items: center;
  min-height: 0;
}
.photo-gallery__lightbox-image-wrap { display: grid; place-items: center; min-width: 0; min-height: 0; height: 100%; }
.photo-gallery__lightbox-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}
.photo-gallery__lightbox-button {
  width: 46px;
  height: 54px;
  border-radius: 12px;
  color: #fff;
  background: rgba(31, 41, 55, .9);
  font-size: 29px;
}
.photo-gallery__lightbox-button:hover { background: #374151; }
.photo-gallery__lightbox-footer { display: grid; grid-template-columns: 34px minmax(0, 1fr) 34px; gap: 8px; align-items: center; padding-top: 12px; }
.photo-gallery__lightbox-thumb-scroll { color: #e5e7eb; }
.photo-gallery__lightbox-thumb { flex-basis: 82px; width: 82px; height: 60px; border-color: transparent; }
.photo-gallery__lightbox-thumb[aria-current="true"] { border-color: #60a5fa; }
body.photo-gallery-lightbox-open { overflow: hidden; }

.photo-gallery button:focus-visible,
.photo-gallery__lightbox button:focus-visible,
.photo-gallery__slideshow-select:focus-visible,
.photo-gallery__stage:focus-visible {
  outline: 3px solid #60a5fa;
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .photo-gallery { margin: 1.25rem 0; }
  .photo-gallery__layout { border-radius: 12px; }
  .photo-gallery__stage { min-height: 220px; max-height: 56vh; }
  .photo-gallery__stage-image { min-height: 220px; max-height: 56vh; }
  .photo-gallery__stage-button { width: 36px; height: 36px; font-size: 21px; }
  .photo-gallery__stage-button--previous { left: 8px; }
  .photo-gallery__stage-button--next { right: 8px; }
  .photo-gallery__thumbbar { grid-template-columns: 28px minmax(0, 1fr) 28px; gap: 2px; padding: 8px 6px; }
  .photo-gallery__thumb-scroll { width: 28px; }
  .photo-gallery__thumb { flex-basis: 64px; width: 64px; height: 50px; }
  .photo-gallery__lightbox { padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); }
  .photo-gallery__lightbox-header { align-items: flex-start; gap: 8px; }
  .photo-gallery__lightbox-actions { gap: 6px; }
  .photo-gallery__slideshow-label { flex-direction: column; align-items: flex-start; gap: 2px; }
  .photo-gallery__slideshow-select { min-height: 32px; max-width: 118px; }
  .photo-gallery__lightbox-main { grid-template-columns: 34px minmax(0, 1fr) 34px; gap: 2px; }
  .photo-gallery__lightbox-button { width: 32px; height: 44px; border-radius: 8px; font-size: 23px; }
  .photo-gallery__lightbox-footer { grid-template-columns: 26px minmax(0, 1fr) 26px; gap: 2px; }
  .photo-gallery__lightbox-thumb-scroll { width: 26px; }
  .photo-gallery__lightbox-thumb { flex-basis: 66px; width: 66px; height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  .photo-gallery *, .photo-gallery__lightbox * { scroll-behavior: auto !important; transition: none !important; }
}
