/**
 * Image Gallery — LineageCare Pack PRO
 *
 * FIXED:
 *  - Removed .lceap-lb-active { display:flex } — JS now sets display:flex
 *    directly; the old class caused jQuery fadeIn to override with display:block.
 *  - Removed body.lceap-modal-body-lock — replaced by JS ScrollLock utility.
 *  - Added .lceap-lb-loading and .lceap-lb-error states for the image wrap.
 *  - Buttons (prev/next/close/counter) use position:fixed safely because the
 *    lightbox itself is now appended to <body> by JS, away from any Elementor
 *    transforms.
 */

/* ── Grid Layout ─────────────────────────────────────────────── */
.lceap-gallery-wrap {
  width: 100%;
}

.lceap-gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.lceap-gallery-masonry {
  column-count: 3;
  column-gap: 12px;
}

.lceap-gallery-masonry .lceap-gallery-item {
  break-inside: avoid;
  margin-bottom: 12px;
}

/* ── Gallery Item ────────────────────────────────────────────── */
.lceap-gallery-item {
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
}

.lceap-gallery-img-wrap {
  position: relative;
  overflow: hidden;
  display: block;
  width: 100%;
  aspect-ratio: 1/1;
  background: #f9f9fb;
}

.lceap-gallery-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.45s ease;
}

/* ── Hover Effects ───────────────────────────────────────────── */
.lceap-gallery-hover-zoom .lceap-gallery-img-wrap:hover img,
.lceap-gallery-hover-zoom-overlay .lceap-gallery-img-wrap:hover img,
.lceap-gallery-hover-slide-up .lceap-gallery-img-wrap:hover img {
  transform: scale(1.07);
}

/* Overlay */
.lceap-gallery-overlay {
  position: absolute;
  inset: 0;
  background: rgba(233, 69, 96, 0.75);
  opacity: 0;
  transition: opacity 0.35s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  z-index: 2;
}

/* Hide overlay entirely when the Elementor toggle is off (display:none injected via selector) */
.lceap-gallery-overlay[style*="display: none"],
.lceap-gallery-overlay[style*="display:none"] {
  display: none !important;
}

.lceap-gallery-hover-zoom-overlay .lceap-gallery-img-wrap:hover .lceap-gallery-overlay {
  opacity: 1;
}

/* Slide up caption */
.lceap-gallery-hover-slide-up .lceap-gallery-overlay {
  align-items: flex-start;
  justify-content: flex-end;
  padding: 20px 16px;
  background: linear-gradient(to top, rgba(0,0,0,0.75), transparent);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.lceap-gallery-hover-slide-up .lceap-gallery-img-wrap:hover .lceap-gallery-overlay {
  opacity: 1;
  transform: translateY(0);
}

.lceap-gallery-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.lceap-gallery-zoom-icon {
  width: 48px;
  height: 48px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  backdrop-filter: blur(4px);
}

.lceap-gallery-caption {
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  max-width: 180px;
  line-height: 1.4;
}

/* Lightbox trigger — invisible clickable layer */
.lceap-gallery-lightbox-trigger {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: block;
}

/* ── LIGHTBOX MODAL ──────────────────────────────────────────── */
/*
  display:none by default.
  JS sets display:flex directly via .css({ display:'flex' })
  and animates opacity — no CSS class needed.
  The lightbox is appended to <body> by JS so position:fixed
  works correctly regardless of Elementor ancestor transforms.
*/
.lceap-lightbox {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: none;
  align-items: center;
  justify-content: center;
  /* Prevent accidental text selection during touch swipe gestures */
  -webkit-user-select: none;
  user-select: none;
}

/* ── Backdrop ────────────────────────────────────────────────── */
.lceap-lb-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 0;
}

/* ── Dialog shell ────────────────────────────────────────────── */
.lceap-lb-dialog {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100dvh;
  padding: 12px;
  box-sizing: border-box;
  pointer-events: none; /* let clicks fall through to backdrop */
}

/* ── Image wrap ──────────────────────────────────────────────── */
.lceap-lb-img-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 90vw;
  max-height: calc(100dvh - 24px);
  pointer-events: auto;
  position: relative;
}

/* Loading state — subtle pulse on the wrap */
.lceap-lb-img-wrap.lceap-lb-loading::after {
  content: '';
  display: block;
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: #fff;
  border-radius: 50%;
  animation: lceap-lb-spin 0.75s linear infinite;
  position: absolute;
}

/* Error state */
.lceap-lb-img-wrap.lceap-lb-error::after {
  content: 'Image unavailable';
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.55);
  font-size: 14px;
  min-width: 180px;
}

@keyframes lceap-lb-spin {
  to { transform: rotate(360deg); }
}

.lceap-lb-img {
  max-width: 90vw;
  max-height: 82dvh;
  border-radius: 8px;
  object-fit: contain;
  display: block;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  pointer-events: auto;
  /* Hint GPU compositing for opacity fade-in animation */
  will-change: opacity;
}

/* ── Close button ────────────────────────────────────────────── */
.lceap-lb-close {
  position: fixed;
  top: 20px;
  right: 24px;
  width: 44px;
  height: 44px;
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 50%;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.2s;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: auto;
}
.lceap-lb-close:hover { background: #e94560; }

/* ── Prev / Next ─────────────────────────────────────────────── */
.lceap-lb-prev,
.lceap-lb-next {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.2s, transform 0.2s;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: auto;
}
.lceap-lb-prev { left: 20px; }
.lceap-lb-next { right: 20px; }
.lceap-lb-prev:hover {
  background: rgba(233,69,96,0.65);
  transform: translateY(-50%) scale(1.08);
}
.lceap-lb-next:hover {
  background: rgba(233,69,96,0.65);
  transform: translateY(-50%) scale(1.08);
}

/* ── Counter ─────────────────────────────────────────────────── */
.lceap-lb-counter {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.5);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  z-index: 10;
  pointer-events: none;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .lceap-gallery-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .lceap-gallery-masonry { column-count: 2 !important; }
  .lceap-lb-prev { left: 8px; }
  .lceap-lb-next { right: 8px; }
  .lceap-lb-img { max-height: 78dvh; }
}
@media (max-width: 480px) {
  .lceap-gallery-grid { grid-template-columns: 1fr !important; }
  .lceap-gallery-masonry { column-count: 1 !important; }
  .lceap-lb-close { top: 12px; right: 12px; }
}

/* ── Focus-visible accessibility ────────────────────────────── */
.lceap-lb-close:focus-visible,
.lceap-lb-prev:focus-visible,
.lceap-lb-next:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}
.lceap-gallery-lightbox-trigger:focus-visible {
  outline: 2px solid var(--lceap-primary, #e94560);
  outline-offset: 2px;
  border-radius: 4px;
}
