/* ==========================================================================\n   Revision 14 — authoritative responsive player layout + PDF.js catalog viewer\n   This file intentionally sits AFTER main.css so the current layout has one\n   coherent source of truth instead of another pile of viewport breakpoints.\n   ========================================================================== */

/* --- Catalog: render the real one-page PDF with PDF.js ------------------- */
.catalog-viewer {
  position: relative;
  width: 100%;
  min-width: 0;
  overflow: auto;
  background: #fff;
  color: #222;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}
#catalogCanvas {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  background: #fff;
}
.catalog-loading,
.catalog-error {
  min-height: 220px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 24px;
  background: #fff;
  color: #555;
  text-align: center;
  font-size: .82rem;
}
.catalog-error a { color: #111; font-weight: 800; }

/* The old iframe rules no longer participate. */
#catalogFrame { display: none !important; }

/* --- Index: faint vertical guides connect slanted headers to columns ----- */
@media (min-width: 901px) {
  .matrix-row .count-cell {
    border-left: 1px solid rgba(255,255,255,.035);
  }
  .matrix-row .count-cell:last-child {
    border-right: 1px solid rgba(255,255,255,.035);
  }
  .matrix-row .count-cell.column-hover {
    border-left-color: rgba(241,195,74,.20);
    border-right: 1px solid rgba(241,195,74,.20);
  }
}

/* --- One responsive decision, made from ACTUAL page-shell width in JS ---- */
.player-page .player-layout {
  margin-inline: auto !important;
  max-width: 100% !important;
  min-width: 0 !important;
  gap: 12px !important;
  overflow: visible !important;
}
.player-page .player-layout .video-column,
.player-page .player-layout .playlist-panel,
.player-page .player-layout .catalog-panel {
  min-width: 0 !important;
  max-width: none !important;
}

/* Ordinary desktop: Video + Playlist; Catalog drops underneath when present. */
@media (min-width: 901px) {
  .player-page .player-layout.layout-two-pane {
    display: grid !important;
    width: min(var(--v14-layout-width, 1180px), 100%) !important;
    grid-template-columns: minmax(0, 1fr) var(--v14-playlist-width, 320px) !important;
    grid-template-rows: auto auto !important;
    grid-template-areas:
      "video playlist"
      "catalog catalog" !important;
    align-items: start !important;
    justify-content: stretch !important;
  }
  .player-page .player-layout.layout-two-pane .video-column {
    grid-area: video !important;
    width: 100% !important;
    justify-self: stretch !important;
  }
  .player-page .player-layout.layout-two-pane .playlist-panel {
    grid-area: playlist !important;
    width: 100% !important;
    height: var(--video-stack-height, auto) !important;
    max-height: var(--video-stack-height, 720px) !important;
    justify-self: stretch !important;
  }
  .player-page .player-layout.layout-two-pane .catalog-panel:not([hidden]) {
    grid-area: catalog !important;
    width: min(780px, 100%) !important;
    height: auto !important;
    max-height: none !important;
    justify-self: center !important;
  }
  .player-page .player-layout.layout-two-pane .catalog-viewer {
    max-height: none !important;
  }
  .player-page .player-layout.layout-two-pane .catalog-expand-button {
    display: none !important;
  }

  /* True three-pane dashboard. The playlist is literally the next grid track
     after the video, so it cannot drift away from the player. */
  .player-page .player-layout.layout-three-pane:not(.catalog-expanded) {
    display: grid !important;
    width: min(var(--v14-layout-width, 1800px), 100%) !important;
    grid-template-columns:
      var(--v14-catalog-width, 400px)
      minmax(0, 1fr)
      var(--v14-playlist-width, 325px) !important;
    grid-template-areas: "catalog video playlist" !important;
    align-items: start !important;
    justify-content: stretch !important;
  }
  .player-page .player-layout.layout-three-pane:not(.catalog-expanded) .catalog-panel {
    grid-area: catalog !important;
    width: 100% !important;
    height: auto !important;
    max-height: var(--video-stack-height, 720px) !important;
    display: flex !important;
    flex-direction: column !important;
    align-self: start !important;
  }
  .player-page .player-layout.layout-three-pane:not(.catalog-expanded) .catalog-viewer {
    max-height: calc(var(--video-stack-height, 720px) - 50px) !important;
    flex: 0 1 auto !important;
  }
  .player-page .player-layout.layout-three-pane:not(.catalog-expanded) .video-column {
    grid-area: video !important;
    width: 100% !important;
    justify-self: stretch !important;
  }
  .player-page .player-layout.layout-three-pane:not(.catalog-expanded) .playlist-panel {
    grid-area: playlist !important;
    width: 100% !important;
    height: var(--video-stack-height, 720px) !important;
    max-height: var(--video-stack-height, 720px) !important;
    justify-self: stretch !important;
    margin-left: 0 !important;
  }
  .player-page .player-layout.layout-three-pane .catalog-expand-button {
    display: inline-flex !important;
  }

  /* Expanded consignment: meaningful, but not "WELCOME TO THE PEDIGREE".
     Catalog is capped near 720px; Video and Playlist become one equal-width
     right column and the playlist scrolls internally. */
  .player-page .player-layout.layout-three-pane.catalog-expanded {
    display: grid !important;
    width: min(var(--v14-expanded-layout-width, 1700px), 100%) !important;
    height: var(--player-row-max-height, 76dvh) !important;
    min-height: 500px !important;
    grid-template-columns: var(--v14-expanded-catalog-width, 680px) minmax(0, 1fr) !important;
    grid-template-rows: auto minmax(145px, 1fr) !important;
    grid-template-areas:
      "catalog video"
      "catalog playlist" !important;
    align-items: stretch !important;
    justify-content: stretch !important;
  }
  .player-page .player-layout.layout-three-pane.catalog-expanded .catalog-panel {
    grid-area: catalog !important;
    grid-row: 1 / span 2 !important;
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
    display: flex !important;
    flex-direction: column !important;
  }
  .player-page .player-layout.layout-three-pane.catalog-expanded .catalog-viewer {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: auto !important;
  }
  .player-page .player-layout.layout-three-pane.catalog-expanded .video-column {
    grid-area: video !important;
    width: 100% !important;
    max-width: none !important;
    align-self: start !important;
  }
  .player-page .player-layout.layout-three-pane.catalog-expanded .playlist-panel {
    grid-area: playlist !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 145px !important;
    max-height: none !important;
    align-self: stretch !important;
    justify-self: stretch !important;
  }
  .player-page .player-layout.layout-three-pane.catalog-expanded .playlist-scroll {
    min-height: 0 !important;
    overflow-y: auto !important;
  }

  /* Search-result pages have no playlist. Normal and expanded modes therefore
     get their own explicit geometry instead of borrowing consignment rules. */
  .search-result-page .player-layout.layout-search-split {
    display: grid !important;
    width: min(var(--v14-layout-width, 1700px), 100%) !important;
    grid-template-columns: var(--v14-catalog-width, 410px) minmax(0, 1fr) !important;
    grid-template-areas: "catalog video" !important;
    align-items: start !important;
  }
  .search-result-page .player-layout.layout-search-split .catalog-panel {
    grid-area: catalog !important;
    width: 100% !important;
    max-height: var(--video-stack-height, 720px) !important;
    display: flex !important;
    flex-direction: column !important;
  }
  .search-result-page .player-layout.layout-search-split .catalog-viewer {
    max-height: calc(var(--video-stack-height, 720px) - 50px) !important;
  }
  .search-result-page .player-layout.layout-search-split .video-column {
    grid-area: video !important;
    width: 100% !important;
    max-width: none !important;
  }
  .search-result-page .player-layout.layout-search-split .catalog-expand-button {
    display: inline-flex !important;
  }
  .search-result-page .player-layout.layout-search-split.catalog-expanded {
    width: min(var(--v14-expanded-layout-width, 1850px), 100%) !important;
    grid-template-columns: var(--v14-expanded-catalog-width, 680px) minmax(0, 1fr) !important;
    grid-template-areas: "catalog video" !important;
  }
  .search-result-page .player-layout.layout-search-split.catalog-expanded .catalog-panel {
    max-height: var(--video-stack-height, 760px) !important;
  }
  .search-result-page .player-layout.layout-search-split.catalog-expanded .catalog-viewer {
    max-height: calc(var(--video-stack-height, 760px) - 50px) !important;
  }

  .search-result-page .player-layout.layout-search-stack {
    display: grid !important;
    width: min(var(--player-max-width, 1100px), 100%) !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-areas: "video" "catalog" !important;
    gap: 12px !important;
  }
  .search-result-page .player-layout.layout-search-stack .video-column { grid-area: video !important; }
  .search-result-page .player-layout.layout-search-stack .catalog-panel {
    grid-area: catalog !important;
    width: min(780px, 100%) !important;
    justify-self: center !important;
  }
  .search-result-page .player-layout.layout-search-stack .catalog-expand-button {
    display: none !important;
  }
}

/* --- Mobile ------------------------------------------------------------- */
@media (max-width: 900px) {
  .player-page .player-layout.layout-mobile {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  .player-page .catalog-expand-button { display: none !important; }
  .player-page .catalog-panel.mobile-visible,
  .search-result-page .catalog-panel:not([hidden]) {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  .player-page .catalog-viewer {
    width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
    background: #fff !important;
  }
  .player-page #catalogCanvas {
    width: 100% !important;
    height: auto !important;
  }
}

@media (min-width: 901px) {
  .search-result-page .player-layout.layout-search-split.catalog-expanded {
    height: auto !important;
    min-height: 0 !important;
    grid-template-rows: auto !important;
    align-items: start !important;
  }
  .search-result-page .player-layout.layout-search-split.catalog-expanded .catalog-panel {
    grid-row: auto !important;
    height: auto !important;
    min-height: 0 !important;
    align-self: start !important;
  }
  .search-result-page .player-layout.layout-search-split.catalog-expanded .video-column {
    grid-area: video !important;
    align-self: start !important;
  }
}

/* ==========================================================================\n   Revision 15 — matrix alignment + row emphasis + hard catalog containment\n   ========================================================================== */

/* The PHP/SVG geometry and the CSS-grid body MUST use the same consignor track.
   Earlier body rules still hard-coded 230px while the SVG was calculated from
   220px, creating the visible ten-pixel drift in every sale column. */
@media (min-width: 901px) {
  .matrix-row {
    grid-template-columns: var(--consignor-col, 230px) repeat(var(--sale-count), var(--sale-col)) !important;
  }

  /* Row hover should identify the consignor just as clearly as the counts. */
  .matrix-row:hover .consignor-name-cell {
    background: rgba(241,195,74,.07) !important;
    box-shadow: inset 3px 0 0 rgba(241,195,74,.70);
  }
  .matrix-row:hover .consignor-name-cell a {
    color: #ffe485 !important;
  }
}

/* PDF.js canvases can briefly retain the width from the previous grid state
   while a ResizeObserver-driven rerender is pending. Never let that transient
   canvas width paint into the neighboring video track. The intrinsic bitmap
   stays high-resolution; CSS scales it to the live catalog pane. */
.catalog-panel,
.catalog-viewer {
  overflow-x: hidden !important;
}
#catalogCanvas {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
}

/* Keep all responsive tracks physically contained by the measured layout.
   This is deliberately class-based; JS chooses the class from the real page
   shell width, while these rules prevent legacy viewport rules from leaking in. */
@media (min-width: 901px) {
  .player-page .player-layout.layout-two-pane,
  .player-page .player-layout.layout-three-pane,
  .search-result-page .player-layout.layout-search-split,
  .search-result-page .player-layout.layout-search-stack {
    box-sizing: border-box !important;
    max-width: 100% !important;
    overflow: visible !important;
  }

  .player-page .player-layout.layout-three-pane:not(.catalog-expanded) {
    grid-template-columns:
      minmax(0, var(--v14-catalog-width, 400px))
      minmax(0, 1fr)
      minmax(0, var(--v14-playlist-width, 325px)) !important;
  }

  .player-page .player-layout.layout-three-pane:not(.catalog-expanded) .catalog-panel,
  .player-page .player-layout.layout-three-pane:not(.catalog-expanded) .catalog-viewer,
  .player-page .player-layout.layout-three-pane:not(.catalog-expanded) .video-column,
  .player-page .player-layout.layout-three-pane:not(.catalog-expanded) .playlist-panel {
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  .search-result-page .player-layout.layout-search-split {
    grid-template-columns: minmax(0, var(--v14-catalog-width, 410px)) minmax(0, 1fr) !important;
  }
}
