/* ===========================================================================
   V2W LP common - service gallery

   Pair of lib/gallery.mjs (markup) and assets/gallery.mjs (runtime). Class names are
   all `gallery*`, so the sheet does not need the `.lp` scope to stay out of the way
   of the page's own CSS.

   Tokens come from assets/common.css (--accent, --accent-dark, --ink, --muted,
   --line, --line-strong, --surface, --accent-wash, --radius, --shadow-*); each one
   has a fallback, so the component also works on a page that does not load the
   common sheet. Load order: common.css, then this file.
   =========================================================================== */

/* ------------------------------------------------------------ inline strip --- */

.gallery {
  --gallery-accent: var(--accent, #3661f5);
  --gallery-line: var(--line, #e3e9f5);
  --gallery-line-strong: var(--line-strong, #ccd7ec);
  --gallery-surface: var(--surface, #ffffff);
  --gallery-ink: var(--ink, #14223a);
  --gallery-muted: var(--muted, #5f6d86);
  --gallery-radius: var(--radius, 8px);
  --gallery-wash: var(--accent-wash, rgba(54, 97, 245, .14));
  margin-top: 4px;
}

.gallery-track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(112px, 1fr);
  gap: 8px;
  margin: 0;
  padding: 2px 0 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  list-style: none;
}

.gallery-item {
  margin: 0;
  padding: 0;
  scroll-snap-align: start;
  list-style: none;
}

.gallery-thumb {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--gallery-line);
  border-radius: var(--gallery-radius);
  background: var(--gallery-surface);
  overflow: hidden;
  cursor: zoom-in;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.gallery-thumb img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.gallery-thumb:hover {
  border-color: var(--gallery-line-strong);
  transform: translateY(-1px);
}

.gallery-thumb[aria-current="true"] {
  border-color: var(--gallery-accent);
  box-shadow: 0 0 0 3px var(--gallery-wash);
}

.gallery-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 2px;
}

.gallery-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--gallery-line-strong);
  border-radius: var(--gallery-radius);
  background: var(--gallery-surface);
  color: var(--gallery-ink);
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background-color .15s ease;
}

.gallery-btn:hover {
  border-color: var(--gallery-accent);
  color: var(--gallery-accent);
}

.gallery-status {
  margin: 0;
  color: var(--gallery-muted);
  font-size: .92rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* ----------------------------------------------------------- zoom viewer ----- */

.gallery-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  grid-template-columns: minmax(52px, auto) minmax(0, 1fr) minmax(52px, auto);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "bar bar bar"
    "prev image next";
  gap: 8px;
  padding: clamp(10px, 2vw, 20px);
  padding-bottom: max(clamp(10px, 2vw, 20px), env(safe-area-inset-bottom, 0px));
  background: rgba(7, 9, 16, .94);
  color: #f4f6fb;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* the runtime toggles the hidden attribute; the grid above must not win over it */
.gallery-modal[hidden] { display: none !important; }

.gallery-modal__bar {
  grid-area: bar;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
}

.gallery-modal__count {
  margin: 0;
  color: #cdd5e6;
  font-size: .95rem;
  font-variant-numeric: tabular-nums;
}

.gallery-modal__btn,
.gallery-modal__nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .26);
  border-radius: var(--radius, 8px);
  background: rgba(255, 255, 255, .06);
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease;
}

.gallery-modal__btn:hover,
.gallery-modal__nav:hover {
  background: rgba(255, 255, 255, .14);
  border-color: rgba(255, 255, 255, .5);
}

.gallery-modal__prev { grid-area: prev; align-self: center; }
.gallery-modal__next { grid-area: next; align-self: center; }

.gallery-modal__image {
  grid-area: image;
  align-self: center;
  justify-self: center;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  transform: scale(var(--gallery-zoom, 1));
  transform-origin: center center;
  transition: transform .16s ease;
}

/* --------------------------------------------------------------- focus ------- */

.gallery-thumb:focus-visible,
.gallery-btn:focus-visible,
.gallery-modal__btn:focus-visible,
.gallery-modal__nav:focus-visible {
  outline: 2px solid var(--accent, #3661f5);
  outline-offset: 2px;
}

.gallery-modal__btn:focus-visible,
.gallery-modal__nav:focus-visible {
  outline-color: #ffd9a8;
}

/* ----------------------------------------------------------- responsive ------ */

@media (max-width: 1000px) {
  .gallery-track { grid-auto-columns: minmax(104px, 1fr); }
}

@media (max-width: 760px) {
  .gallery-track {
    grid-auto-columns: minmax(96px, 42%);
    gap: 6px;
  }

  .gallery-modal {
    grid-template-columns: 48px minmax(0, 1fr) 48px;
    gap: 6px;
  }

  .gallery-modal__nav { min-width: 44px; }
  .gallery-modal__count { font-size: .88rem; }
}

@media (max-width: 420px) {
  .gallery-track { grid-auto-columns: minmax(88px, 64%); }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-thumb,
  .gallery-btn,
  .gallery-modal__btn,
  .gallery-modal__nav,
  .gallery-modal__image { transition: none; }

  .gallery-thumb:hover { transform: none; }
}
