.sg-gallery {
  width: 100%;
  box-sizing: border-box;
}

.sg-gallery *,
.sg-gallery *::before,
.sg-gallery *::after {
  box-sizing: border-box;
}


.sg-archive-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin: 0 0 22px;
  padding: 16px;
  background: #f7f7f7;
  border: 1px solid #e3e3e3;
}

.sg-archive-filter {
  display: flex;
  flex: 1 1 150px;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  font-weight: 600;
}

.sg-archive-filter--search {
  flex: 2 1 240px;
}

.sg-archive-filter input,
.sg-archive-filter select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  font: inherit;
}

.sg-clear-filters {
  min-height: 42px;
  padding: 8px 14px;
  cursor: pointer;
}

.sg-detail[hidden] {
  display: none !important;
}


.sg-thumbs {
  display: grid;
  grid-template-columns: repeat(var(--sg-columns, 6), minmax(0, 1fr));
  gap: 12px;
}

.sg-thumb {
  position: relative;
  display: block;
  width: 100%;
  padding: 10px;
  border: 1px solid #d9d9d9;
  background: #fff;
  cursor: pointer;
  overflow: hidden;
  opacity: 0.9;
  transition: opacity 160ms ease, transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.sg-thumb:hover,
.sg-thumb:focus-visible,
.sg-thumb.is-active {
  opacity: 1;
  border-color: currentColor;
}

.sg-thumb:hover {
  transform: translateY(-2px);
}

.sg-thumb:focus-visible {
  outline: 3px solid currentColor;
  outline-offset: 3px;
}

.sg-thumb.is-active {
  box-shadow: 0 0 0 2px currentColor inset;
}

.sg-thumb__image {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  background: #fafafa;
}

.sg-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 28px;
}

.sg-pagination-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
}

.sg-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.sg-pagination[hidden] {
  display: none !important;
}

.sg-gallery .sg-page-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  min-width: 42px;
  height: 42px;
  margin: 0;
  padding: 0;
  border: 0 !important;
  border-radius: 3px;
  background: #f0f0f0 !important;
  color: #747474 !important;
  font: inherit;
  font-size: 14px !important;
  font-weight: 600 !important;
  line-height: 1 !important;
  text-decoration: none !important;
  box-shadow: none !important;
  cursor: pointer;
  appearance: none;
}

.sg-gallery .sg-page-button:hover,
.sg-gallery .sg-page-button:focus-visible {
  background: #e3e3e3 !important;
  color: #333 !important;
}

.sg-gallery .sg-page-button.is-current {
  background: #0d83f7 !important;
  color: #fff !important;
}

.sg-gallery .sg-page-button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.sg-gallery .sg-page-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.sg-gallery .sg-page-prev,
.sg-gallery .sg-page-next {
  font-size: 22px !important;
  font-weight: 700 !important;
}

.sg-gallery .sg-show-all-toggle {
  min-height: 42px;
  margin: 0;
  padding: 0 16px;
  border: 1px solid #d8d8d8 !important;
  border-radius: 3px;
  background: #fff !important;
  color: #555 !important;
  font: inherit;
  font-size: 14px !important;
  font-weight: 600 !important;
  line-height: 1 !important;
  box-shadow: none !important;
  cursor: pointer;
  appearance: none;
}

.sg-gallery .sg-show-all-toggle:hover,
.sg-gallery .sg-show-all-toggle:focus-visible {
  border-color: #999 !important;
  background: #f7f7f7 !important;
  color: #222 !important;
}

.sg-gallery .sg-show-all-toggle:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.sg-gallery .sg-show-all-toggle:disabled {
  cursor: wait;
  opacity: 0.7;
}

.sg-gallery .sg-show-all-toggle[hidden] {
  display: none !important;
}

.sg-status {
  min-height: 1.5em;
  margin: 0;
  font-size: 0.9em;
}

.sg-detail {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  align-items: start;
  gap: 24px;
  width: 100%;
  margin: 28px 0 0;
}


.sg-detail__nav {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

.sg-detail-nav-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid #d5d5d5;
  border-radius: 3px;
  background: #f3f3f3;
  color: inherit;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.2;
  cursor: pointer;
}

.sg-detail-nav-button:hover,
.sg-detail-nav-button:focus-visible {
  background: #e9e9e9;
  border-color: currentColor;
}

.sg-detail-nav-button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.sg-detail-nav-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.sg-detail__image-link {
  display: block;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: inherit;
  font: inherit;
  color: inherit;
  cursor: zoom-in;
  appearance: none;
}

.sg-detail__image-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  min-width: 0;
  padding: 24px;
  background: #f5f5f5;
  border: 1px solid #e3e3e3;
}

.sg-detail__image {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  object-fit: contain;
}

.sg-detail__content {
  min-width: 0;
  padding: clamp(20px, 3vw, 40px);
  background: #f8f8f8;
  border: 1px solid #e3e3e3;
}

.sg-gallery .sg-detail .sg-detail__title {
  margin: 0 0 0.7em !important;
  font-size: 1rem !important;
  line-height: 1.35 !important;
  font-weight: 600 !important;
}

.sg-detail__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.45em;
  margin: -0.25em 0 1em;
  color: #666;
  font-size: 0.9rem;
  line-height: 1.4;
}

.sg-detail__meta[hidden],
.sg-detail__publication[hidden],
.sg-detail__date[hidden],
.sg-detail__meta-separator[hidden] {
  display: none !important;
}


/* When an image has no Media Library Alt Text, there is no description to show.
   Put the generated publication/date title above the cutting and let the image
   use the full available width. */
.sg-detail.sg-detail--image-only {
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.sg-detail.sg-detail--image-only .sg-detail__content {
  order: 1;
  padding: 0;
  background: transparent;
  border: 0;
}

.sg-detail.sg-detail--image-only .sg-detail__image-link {
  order: 2;
  width: 100%;
}

.sg-detail.sg-detail--image-only .sg-detail__image-wrap {
  width: 100%;
}

.sg-detail.sg-detail--image-only .sg-detail__image {
  width: 100%;
  max-width: 100%;
  height: auto;
}

.sg-detail.sg-detail--image-only .sg-detail__description {
  display: none;
}

.sg-gallery .sg-detail.sg-detail--image-only .sg-detail__title {
  margin: 0 !important;
}

.sg-detail.sg-detail--image-only .sg-detail__meta {
  margin: 0.35em 0 0;
}

.sg-detail__description > :first-child {
  margin-top: 0;
}

.sg-detail__description > :last-child {
  margin-bottom: 0;
}

.sg-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: block;
  overflow: auto;
  padding: 64px 24px 24px;
  background: rgba(0, 0, 0, 0.85);
  text-align: center;
  overscroll-behavior: contain;
}

.sg-lightbox[hidden] {
  display: none;
}

/* Show the archival source at its intrinsic pixel dimensions. Large scans
   deliberately overflow the viewport so they can be read by scrolling at
   100% rather than being automatically reduced to fit the screen. */
.sg-lightbox__image {
  display: block;
  width: auto;
  height: auto;
  max-width: none !important;
  max-height: none !important;
  margin: 0 auto;
  object-fit: none;
  background: #fff;
}

.sg-lightbox__close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1;
  border: 0;
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.sg-empty {
  padding: 24px;
  background: #f5f5f5;
}

@media (max-width: 1100px) {
  .sg-thumbs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 800px) {
  .sg-archive-filter,
  .sg-archive-filter--search {
    flex: 1 1 calc(50% - 12px);
  }

  .sg-clear-filters {
    flex: 1 1 100%;
  }

  .sg-detail {
    grid-template-columns: 1fr;
  }

  .sg-thumbs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

}

@media (max-width: 520px) {
  .sg-archive-filter,
  .sg-archive-filter--search,
  .sg-clear-filters {
    flex: 1 1 100%;
  }

  .sg-thumbs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }


  .sg-detail__image-wrap,
  .sg-detail__content {
    padding: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sg-thumb {
    transition: none;
  }
}



/* TSCH_* National Archives items: the reference line is the only visible text.
   It sits directly above a full-width image; there is no title/meta/body panel. */
.sg-detail__reference {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 1rem;
  line-height: 1.4;
  font-weight: 600;
}

.sg-detail__reference[hidden] {
  display: none !important;
}

.sg-detail.sg-detail--reference-only {
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.sg-detail.sg-detail--reference-only .sg-detail__reference {
  order: 1;
  display: block;
  width: 100%;
}

.sg-detail.sg-detail--reference-only .sg-detail__image-link {
  order: 2;
  width: 100%;
}

.sg-detail.sg-detail--reference-only .sg-detail__content {
  display: none !important;
}

.sg-detail.sg-detail--reference-only .sg-detail__image-wrap,
.sg-detail.sg-detail--reference-only .sg-detail__image {
  width: 100%;
  max-width: 100%;
  height: auto;
}
