/* ==========================================================================
   gallery.css — Reefsea photo gallery component (Phase 4.4 pilot)
   --------------------------------------------------------------------------
   Namespaced .rsg-* only. Loaded ONLY on pages whose head-meta.html links it
   (?v= cache-bump convention applies — see site-src/README.md). Grid markup
   is generated by tools/build_galleries.py; the viewer <dialog> is created
   by /assets/gallery.js at runtime.

   Design language: neutral, photography-first. Echoes the legacy
   .portfolio-gallery affordances (subtle zoom on hover) with the brand blue
   (#008fd5, --color-brand) reserved for focus states. No url() assets.
   ========================================================================== */

/* --- Gallery container ------------------------------------------------- */

.rsg-gallery {
  margin: 0 0 20px;
}

/* --- Hero (first photo on design pages) --------------------------------
   Natural width up to the column width; never upscaled (width:auto +
   max-width caps at the smaller of intrinsic and container width). */

.rsg-hero {
  display: block;
  margin: 0 0 8px;
  overflow: hidden;
  border: 1px solid #e9e9e9;
  border-radius: 3px;
  background: #f5f5f5;
}

.rsg-hero img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  transition: transform 0.3s ease;
}

/* --- Thumbnail grid ----------------------------------------------------- */

.rsg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
}

/* Small-cell variant for grids whose only available thumbnails are the
   legacy 150x150 crops (capri-series "additional design features"). */
.rsg-grid--small {
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
}

/* Awards grids sit in half-width columns with 640-800px sources. */
.rsg-awards .rsg-grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

/* --- Grid items --------------------------------------------------------- */

.rsg-item {
  position: relative;
  display: block;
  cursor: zoom-in;
}

.rsg-grid .rsg-item {
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid #e9e9e9;
  border-radius: 3px;
  background: #f5f5f5;
}

.rsg-grid .rsg-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.rsg-item:hover img,
.rsg-item:focus-visible img {
  transform: scale(1.06);
}

.rsg-hero:hover img,
.rsg-hero:focus-visible img {
  transform: scale(1.02);
}

.rsg-item:focus-visible {
  outline: 2px solid #008fd5;
  outline-offset: 2px;
}

/* Keyboard reveal for design-services' legacy portfolio cards retrofitted as
   RSG lightbox triggers. Mirrors the frozen site.css hover state. */
.full-width-portfolio.projects-container[data-rsg-gallery][data-rsg-kind="design-services"] .project:focus-within .project-hover {
  -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
  filter: alpha(opacity=100);
  -moz-opacity: 1;
  -khtml-opacity: 1;
  opacity: 1;
}

.full-width-portfolio.projects-container[data-rsg-gallery][data-rsg-kind="design-services"] .project.style2:focus-within .project-hover .project-buttons a {
  bottom: 0;
  opacity: 1;
  transition-delay: 0s, .2s, .2s;
  -webkit-transition-delay: 0s, .2s, .2s;
  -moz-transition-delay: 0s, .2s, .2s;
}

.full-width-portfolio.projects-container[data-rsg-gallery][data-rsg-kind="design-services"] .project.style2:focus-within .project-hover .project-buttons a + a {
  transition-delay: 0s, .4s, .4s;
  -webkit-transition-delay: 0s, .4s, .4s;
  -moz-transition-delay: 0s, .4s, .4s;
}

/* Floorplans: keep the whole drawing visible instead of centre-cropping. */
.rsg-grid .rsg-item--contain img {
  object-fit: contain;
  background: #fff;
}

/* --- Fullscreen viewer (shared <dialog>, created by gallery.js) ---------
   The dialog itself is the near-black full-viewport surface; the image is
   centred on it and rendered fit-to-image: width/height attributes carry
   the intrinsic size, CSS width:auto/height:auto uses it, and the max-*
   caps only ever shrink. Upscaling is impossible by construction. */

.rsg-viewer {
  --rsg-viewer-top-space: 64px;
  --rsg-viewer-bar-space: 86px;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  background: rgba(9, 12, 16, 0.97);
  color: #fff;
  font-family: 'Open Sans', Helvetica, 'Segoe UI', Arial, sans-serif;
  /* Non-selectable: a click-drag or double-click otherwise paints the native
     text-selection highlight (a translucent blue wash) over the fullscreen
     photo. Nothing here is meant to be selected. */
  -webkit-user-select: none;
  user-select: none;
}

.rsg-viewer * {
  -webkit-user-select: none;
  user-select: none;
}

/* Same guard on grid thumbnails: a double-click to open (or a drag) would
   otherwise select the thumbnail and carry the highlight into the viewer. */
.rsg-grid .rsg-item,
.rsg-viewer-img {
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
}

.rsg-viewer::backdrop {
  background: rgba(9, 12, 16, 0.85);
}

.rsg-viewer-stage {
  position: absolute;
  inset: var(--rsg-viewer-top-space) 0 var(--rsg-viewer-bar-space);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  /* Horizontal swipes are handled in JS; keep vertical scroll native. */
  touch-action: pan-y;
}

.rsg-viewer-figure {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
  pointer-events: none; /* backdrop clicks fall through to the stage */
}

.rsg-viewer-img {
  width: auto;
  height: auto;
  max-width: calc(100vw - 24px);
  max-height: calc(
    100vh - var(--rsg-viewer-top-space) - var(--rsg-viewer-bar-space)
  );
  pointer-events: auto;
  background: #14181d;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
}

/* --- Viewer controls (>= 44px hit areas) -------------------------------- */

.rsg-viewer-btn {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
}

.rsg-viewer-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

.rsg-viewer-btn:focus-visible {
  outline: 2px solid #008fd5;
  outline-offset: 2px;
}

.rsg-viewer-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rsg-viewer-prev {
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.rsg-viewer-next {
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.rsg-viewer-close {
  top: 10px;
  right: 10px;
}

/* --- Caption + counter bar ---------------------------------------------- */

.rsg-viewer-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  min-height: var(--rsg-viewer-bar-space);
  padding: 28px 60px 12px;
  box-sizing: border-box;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  color: #d6dde2;
  background: linear-gradient(rgba(9, 12, 16, 0), rgba(9, 12, 16, 0.75));
  pointer-events: none;
}

.rsg-viewer-caption {
  min-width: 0;
  overflow-wrap: anywhere;
}

.rsg-viewer-counter {
  white-space: nowrap;
  color: #93a6b0;
}

.rsg-viewer-status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Body scroll lock while the viewer is open (belt-and-braces on top of the
   native modal behaviour, which does not lock scroll in all engines). */
body.rsg-viewer-open {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .rsg-item img,
  .rsg-hero img {
    transition: none;
  }
}

@media (max-width: 480px) {
  .rsg-viewer {
    --rsg-viewer-top-space: 62px;
    --rsg-viewer-bar-space: 132px;
  }

  .rsg-viewer-bar {
    align-items: flex-start;
    gap: 8px;
    padding: 24px 16px 14px;
  }

  .rsg-viewer-caption {
    flex: 1 1 auto;
  }

  .rsg-viewer-counter {
    flex: 0 0 auto;
  }
}
