/* Phase 6c — shoppable image styles.
 * Reference: docs/phase-6-shoppable-image-spec.md §5 + the Bimber demo.
 * Markup it depends on: docs/phase-6-shoppable-image-spec.md §4 (also
 * reproduced in docs/reference/shoppable-image-target.html).
 */

.shoppable-image {
  margin: 1rem 0 1.5rem;
}

/* ─── The map: image + absolute-positioned pin children + CSS counter
       so .shoppable-image-pin-icon::before renders 1, 2, 3, ... ─────────── */

.shoppable-image-map {
  counter-reset: pin-counter;
  position: relative;
  display: block;
  border-radius: 0.5rem;
  overflow: hidden;
  background: #f5f5f5;
}

.shoppable-image-image {
  display: block;
  width: 100%;
  height: auto;
}

/* ─── Pin: the small filled circle with a number, surrounded by a
       continuously-pulsing ring. Two-element approach — the wrapper is
       absolutely positioned via the inline <style scoped> rule per pin. ── */

.shoppable-image-pin {
  position: absolute;
  width: 32px;
  height: 32px;
  transform: translate(-50%, -50%);
  cursor: pointer;
  counter-increment: pin-counter;
  z-index: 1;
}

.shoppable-image-pin-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  animation: shoppable-pin-pulse 2s ease-out infinite;
  pointer-events: none;
}

@keyframes shoppable-pin-pulse {
  0%   { transform: scale(1);   opacity: 0.7; }
  100% { transform: scale(2.4); opacity: 0;   }
}

.shoppable-image-pin-icon {
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: #fff;
  color: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  z-index: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.shoppable-image-pin-icon::before {
  content: counter(pin-counter);
}

/* On hover or keyboard focus, lift the pin and pause the pulse so the
   popup is the visual centerpiece. */
.shoppable-image-pin:hover,
.shoppable-image-pin:focus-within {
  z-index: 3;
}
.shoppable-image-pin:hover .shoppable-image-pin-pulse,
.shoppable-image-pin:focus-within .shoppable-image-pin-pulse {
  animation-play-state: paused;
  opacity: 0;
}

/* ─── Pin popup: hidden by default, shown on hover/focus-within. ─────── */

.shoppable-image-pin-body {
  position: absolute;
  top: 50%;
  left: calc(100% + 12px);
  transform: translateY(-50%);
  width: 240px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 0.875rem;
  z-index: 5;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 120ms ease, visibility 120ms ease;
}

.shoppable-image-pin:hover .shoppable-image-pin-body,
.shoppable-image-pin:focus-within .shoppable-image-pin-body,
.shoppable-image-pin.is-active .shoppable-image-pin-body {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Phase 6d §5.2 — position-aware popup variants. Modifier classes are
   applied at render time in templates/posts/_shoppable_image_full.html
   based on x_pct / y_pct thresholds.

   Default (middle): popup opens to the right, vertically centered (the
   rule above). Override below for the four edge cases.
   Combined modifiers (e.g. `.is-right.is-top`) anchor the popup to the
   correct corner. */

.shoppable-image-pin.is-right .shoppable-image-pin-body {
  left: auto;
  right: calc(100% + 12px);
}

.shoppable-image-pin.is-top .shoppable-image-pin-body {
  top: calc(100% + 12px);
  bottom: auto;
  transform: translateX(-50%);
  left: 50%;
  right: auto;
}
.shoppable-image-pin.is-top.is-right .shoppable-image-pin-body {
  left: auto; right: 0; transform: none;
}
.shoppable-image-pin.is-top.is-left .shoppable-image-pin-body {
  left: 0; right: auto; transform: none;
}

.shoppable-image-pin.is-bottom .shoppable-image-pin-body {
  top: auto;
  bottom: calc(100% + 12px);
  transform: translateX(-50%);
  left: 50%;
  right: auto;
}
.shoppable-image-pin.is-bottom.is-right .shoppable-image-pin-body {
  left: auto; right: 0; transform: none;
}
.shoppable-image-pin.is-bottom.is-left .shoppable-image-pin-body {
  left: 0; right: auto; transform: none;
}

/* Phase 6d — when activated via tap or keyboard Enter, lift the pin so
   the popup is on top of any neighboring pins. */
.shoppable-image-pin.is-active {
  z-index: 4;
}
.shoppable-image-pin.is-active .shoppable-image-pin-pulse {
  animation-play-state: paused;
  opacity: 0;
}

/* Keyboard focus indicator — make the focus ring visible on the pin
   itself (the inner icon already has a box-shadow but no outline). */
.shoppable-image-pin:focus-visible {
  outline: 3px solid var(--bs-primary, #0d6efd);
  outline-offset: 4px;
  border-radius: 50%;
}

.shoppable-image-pin-body .pin-thumb {
  margin: 0 0 0.5rem;
  text-align: center;
}

.shoppable-image-pin-body .pin-thumb img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 6px;
}

.shoppable-image-pin-body .pin-name {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  color: #111;
}

.shoppable-image-pin-body .pin-price {
  margin: 0 0 0.625rem;
  font-size: 0.9375rem;
  color: #555;
}

.shoppable-image-pin-body .pin-price .price-currency {
  margin-right: 1px;
}

.shoppable-image-pin-body .pin-url {
  display: block;
  width: 100%;
  background: #111;
  color: #fff;
  text-align: center;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 120ms ease;
}

.shoppable-image-pin-body .pin-url:hover {
  background: #333;
  color: #fff;
}

/* ─── Pins on/off toggle. Sits absolute bottom-right inside the map. ──── */

.shoppable-image-hideshow-btn {
  position: absolute;
  bottom: 0.75rem;
  right: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.625rem;
  background: rgba(0, 0, 0, 0.65);
  border-radius: 999px;
  color: #fff;
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
  z-index: 4;
  user-select: none;
}

.shoppable-image-hideshow-btn:hover {
  color: #fff;
  background: rgba(0, 0, 0, 0.78);
}

.shoppable-image-hideshow-btn .hideshow-track {
  position: relative;
  width: 32px;
  height: 16px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 999px;
  transition: background 120ms ease;
}

.shoppable-image-hideshow-btn .hideshow-dot {
  position: absolute;
  top: 2px;
  left: calc(100% - 14px);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #2c8a3e;
  transition: left 140ms ease, background 140ms ease;
}

/* When pins are off, slide the dot left and grey the track. */
.shoppable-image-map.pins-off .hideshow-dot {
  left: 2px;
  background: #b0b0b0;
}
.shoppable-image-map.pins-off .hideshow-track {
  background: rgba(255, 255, 255, 0.7);
}

/* And hide every pin marker. The fallback <ol> below the image still
   shows everything. */
.shoppable-image-map.pins-off .shoppable-image-pin {
  display: none;
}

/* ─── The fallback / SEO list below the image. ──────────────────────── */

.shoppable-image-items {
  margin: 1rem 0 0;
  padding-left: 1.25rem;
  font-size: 0.9375rem;
  color: #444;
}

.shoppable-image-item {
  margin-bottom: 0.25rem;
}

.shoppable-image-item a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted #999;
}

.shoppable-image-item a:hover {
  color: var(--bs-primary, #0d6efd);
  border-bottom-color: currentColor;
}

/* ─── Phase 6d — mobile (≤767px): bottom-sheet popup for active pins. ─
   :hover misfires on touch (sticky pseudo-state) so we suppress the
   hover popup at small viewports and only show the popup when the pin
   has the .is-active class set by the tap handler in shoppable-image.js. */

@media (max-width: 767.98px) {
  .shoppable-image-pin:hover .shoppable-image-pin-body,
  .shoppable-image-pin:focus-within .shoppable-image-pin-body {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  .shoppable-image-pin.is-active .shoppable-image-pin-body {
    position: fixed;
    inset: auto 0 0 0;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    transform: none;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
    padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom, 0));
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    z-index: 1050;
  }

  .shoppable-image-pin.is-active .shoppable-image-pin-body .pin-thumb img {
    width: 96px;
    height: 96px;
  }
}
