/* Gallery coordinate grids: keep row context during local horizontal scrolling. */
main.content :is(#gallery-memories, #gallery-trauma).gallery-coordinate-table table {
  overflow: clip;
}

main.content :is(#gallery-memories, #gallery-trauma).gallery-coordinate-table table > tbody > tr:last-child > td:last-child {
  border-end-end-radius: calc(var(--pw-radius-md) - 1px);
}

main.content :is(#gallery-memories, #gallery-trauma).gallery-coordinate-table table > tbody > tr:last-child > td:last-child.gallery-cell-target::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-inline-end: 2px solid var(--pw-accent-hover);
  border-block-end: 2px solid var(--pw-accent-hover);
  border-end-end-radius: calc(var(--pw-radius-md) - 1px);
}

main.content :is(#gallery-memories, #gallery-trauma).gallery-coordinate-table table > :is(thead, tbody) > tr > :first-child {
  position: sticky;
  inset-inline-start: 0;
  z-index: 2;
  background-color: var(--pw-surface);
  border-inline-end-color: var(--pw-border-strong);
}

main.content :is(#gallery-memories, #gallery-trauma).gallery-coordinate-table table > thead > tr > :first-child {
  z-index: 3;
  background-color: var(--pw-table-head);
}

main.content :is(#gallery-memories, #gallery-trauma).gallery-coordinate-table table > tbody > tr:nth-child(even) > :first-child {
  background-color: var(--pw-table-stripe);
}

main.content :is(#gallery-memories, #gallery-trauma).gallery-coordinate-table table > tbody > tr:hover > :first-child {
  background-color: var(--pw-table-hover);
}

/* Locator creates these scrollers only after linking the source tables. */
#gallery-trigger-index .gallery-trigger-group .gallery-trigger-table-scroll,
#gallery-non-gallery-index .gallery-non-gallery-table-scroll {
  container: pw-gallery-records / inline-size;
}

@container pw-gallery-records (max-width: 46rem) {
  #gallery-trigger-index .gallery-trigger-group .gallery-trigger-table-scroll table,
  #gallery-non-gallery-index .gallery-non-gallery-table-scroll table {
    display: block;
    width: 100% !important;
    min-width: 0;
    max-width: 100% !important;
    margin: 0.35rem 0 1rem;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    table-layout: auto !important;
    overflow: visible;
  }

  #gallery-trigger-index .gallery-trigger-group .gallery-trigger-table-scroll colgroup,
  #gallery-non-gallery-index .gallery-non-gallery-table-scroll colgroup {
    display: none;
  }

  #gallery-trigger-index .gallery-trigger-group .gallery-trigger-table-scroll thead,
  #gallery-non-gallery-index .gallery-non-gallery-table-scroll thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  #gallery-trigger-index .gallery-trigger-group .gallery-trigger-table-scroll tbody,
  #gallery-non-gallery-index .gallery-non-gallery-table-scroll tbody {
    display: block;
  }

  #gallery-trigger-index .gallery-trigger-group .gallery-trigger-table-scroll tbody > tr,
  #gallery-non-gallery-index .gallery-non-gallery-table-scroll tbody > tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, min(9rem, 38%));
    gap: 0.25rem 0.65rem;
    padding: 0.68rem 0 0.75rem;
    background: transparent !important;
    border-bottom: 1px solid var(--pw-border);
  }

  #gallery-trigger-index .gallery-trigger-group .gallery-trigger-table-scroll tbody > tr:first-child,
  #gallery-non-gallery-index .gallery-non-gallery-table-scroll tbody > tr:first-child {
    border-top: 1px solid var(--pw-border);
  }

  #gallery-trigger-index .gallery-trigger-group .gallery-trigger-table-scroll tbody > tr > td,
  #gallery-non-gallery-index.gallery-non-gallery-index .gallery-non-gallery-table-scroll tbody > tr > td {
    display: block;
    width: auto !important;
    min-width: 0;
    padding: 0 !important;
    border: 0;
    overflow-wrap: anywhere;
  }

  #gallery-trigger-index .gallery-trigger-group .gallery-trigger-table-scroll tbody > tr > td:nth-child(2),
  #gallery-non-gallery-index .gallery-non-gallery-table-scroll tbody > tr > td:nth-child(2) {
    display: none;
  }

  #gallery-trigger-index .gallery-trigger-group .gallery-trigger-table-scroll tbody > tr > td:first-child,
  #gallery-non-gallery-index .gallery-non-gallery-table-scroll tbody > tr > td:first-child {
    grid-column: 1;
    grid-row: 1;
    font-weight: 650;
  }

  #gallery-trigger-index .gallery-trigger-group .gallery-trigger-table-scroll tbody > tr > td:nth-child(3),
  #gallery-non-gallery-index.gallery-non-gallery-index .gallery-non-gallery-table-scroll tbody > tr > td:nth-child(3) {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    width: 100% !important;
    text-align: right !important;
    color: var(--pw-text-soft);
    font-size: 0.82rem;
    line-height: 1.35;
  }

  #gallery-trigger-index .gallery-trigger-group .gallery-trigger-table-scroll tbody > tr > td:nth-child(4),
  #gallery-non-gallery-index .gallery-non-gallery-table-scroll tbody > tr > td:nth-child(4) {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 0.88rem;
    line-height: 1.48;
  }
}
