/* ==========================================================================
   Full-screen vehicle image viewer
   Loaded after style.css so it can reuse the existing design tokens.
   ========================================================================== */

/* The overlay's open state is driven by `display` rather than an
   opacity/visibility transition. A transition can be left un-run (background
   tab, stalled compositor, reduced-motion), which would strand the gallery at
   its closed computed state and make the photo unreachable. `display` has no
   intermediate value, so the viewer is always exactly open or exactly closed.
   Motion lives on the photo transform instead, whose resting state is correct. */
.vw {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: none;
  flex-direction: column;
  background: rgba(8, 8, 10, .985);
  color: #f5f5f7;
  font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  /* Block pull-to-refresh and overscroll history gestures on the overlay. */
  overscroll-behavior: none;
}

/* Pinned on <html> while the viewer is open so no scroll container underneath
   can be dragged into a back/forward navigation. */
html.vw-scroll-lock,
html.vw-scroll-lock body {
  overscroll-behavior: none;
}

/* The chat launcher sits at z-index 999999, above this overlay. Hide it while
   the gallery is open so nothing floats on top of the photo. */
html.vw-scroll-lock #ca-launcher {
  display: none;
}

.vw.vw-open {
  display: flex;
}

/* ---------- Top bar ---------- */
.vw-top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
}

.vw-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-family: 'Archivo', system-ui, sans-serif;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .02em;
}

.vw-count {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #c6c6d0;
  background: rgba(255, 255, 255, .07);
  border: 1px solid var(--line-strong);
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.vw-iconbtn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .07);
  border: 1px solid var(--line-strong);
  color: #f5f5f7;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
  transition: background .2s ease, color .2s ease, border-color .2s ease;
}
.vw-iconbtn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #0a0a0a;
}
.vw-iconbtn,
.vw-nav,
.vw-thumbs img {
  /* Controls must never be treated as gesture sources or double-tap targets. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

.vw-iconbtn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Stage ---------- */
.vw-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}
.vw-stage.is-zoomed { cursor: grab; }
.vw-stage.is-dragging { cursor: grabbing; }

.vw-img {
  position: absolute;
  inset: 0;
  margin: auto;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform .22s cubic-bezier(.2, .8, .2, 1);
  cursor: inherit;
}
.vw-img.is-dragging { transition: none; }

/* Prev / next */
.vw-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 16, 20, .72);
  border: 1px solid rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 17px;
  border-radius: 50%;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background .2s ease, color .2s ease;
}
.vw-nav:hover { background: var(--accent); color: #0a0a0a; border-color: var(--accent); }
.vw-nav:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Kept clear of the screen edges: a touch that starts in the browser's
   edge-swipe zone can be claimed for Back/Forward navigation. */
.vw-nav.prev { left: max(18px, env(safe-area-inset-left)); }
.vw-nav.next { right: max(18px, env(safe-area-inset-right)); }
.vw-nav[hidden] { display: none; }

/* ---------- Bottom bar ---------- */
.vw-bottom {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.vw-thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  padding: 2px;
}
.vw-thumbs[hidden] { display: none; }
.vw-thumbs img {
  flex: 0 0 auto;
  width: 62px;
  height: 46px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid transparent;
  opacity: .5;
  cursor: pointer;
  transition: opacity .2s ease, border-color .2s ease;
}
.vw-thumbs img:hover { opacity: .85; }
.vw-thumbs img.is-active {
  opacity: 1;
  border-color: var(--accent);
}

.vw-tools {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.vw-zoomval {
  min-width: 58px;
  text-align: center;
  font-size: 12.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #c6c6d0;
}

.vw-hint {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, .42);
}

/* ---------- Entry points: hint that the photo opens full-screen ---------- */
.car-card-img { cursor: zoom-in; }
#modalMainImg { cursor: zoom-in; }

.car-zoom-hint {
  position: absolute;
  top: 14px;
  right: 14px;
  left: auto;
  transform: none;
  z-index: 3;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(8, 8, 10, .62);
  border: 1px solid rgba(255, 255, 255, .2);
  color: #fff;
  font-size: 14px;
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity .2s ease, background .2s ease, color .2s ease;
}
.car-card-img:hover .car-zoom-hint,
.car-card-img:focus-within .car-zoom-hint { opacity: 1; transform: none; }
.car-zoom-hint:hover { background: var(--accent); color: #0a0a0a; }

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .vw-top { padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); gap: 10px; }
  .vw-title { font-size: 14px; }
  .vw-count { font-size: 12.5px; padding: 5px 10px; }
  .vw-iconbtn { width: 42px; height: 42px; }
  .vw-nav { width: 44px; height: 44px; font-size: 15px; }
  .vw-nav.prev { left: max(14px, env(safe-area-inset-left)); }
  .vw-nav.next { right: max(14px, env(safe-area-inset-right)); }
  .vw-thumbs img { width: 54px; height: 40px; }
  .vw-bottom { gap: 8px; padding: 8px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .vw-hint { display: none; }
  .car-zoom-hint { opacity: 1; width: 34px; height: 34px; font-size: 13px; top: 10px; right: 10px; }
}

/* Landscape phones have very little vertical room: drop the secondary chrome
   so the photo keeps the space. */
@media (max-height: 560px) {
  .vw-top { padding: 6px 10px; padding-top: calc(6px + env(safe-area-inset-top)); }
  .vw-iconbtn { width: 36px; height: 36px; font-size: 13px; }
  .vw-nav { width: 40px; height: 40px; font-size: 14px; }
  .vw-thumbs { display: none; }
  .vw-hint { display: none; }
  .vw-bottom { gap: 6px; padding: 6px 10px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .vw-zoomval { font-size: 12px; min-width: 48px; }
}

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