/*
 * Image Grid Plugin — Stylesheet
 * Author:  WIXI MEDIA  https://wiximedia.co.za
 * Version: 1.1
 */

/* ─── Scoped reset ──────────────────────────────────── */
.ig-plugin *,
.ig-plugin *::before,
.ig-plugin *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── Host wrapper ──────────────────────────────────── */
.ig-plugin {
  --ig-radius-outer       : 16px;
  --ig-gap                : 4px;
  --ig-btn-bg             : #ffffff;
  --ig-btn-color          : #222222;
  --ig-btn-radius         : 8px;
  --ig-ease               : cubic-bezier(0.4, 0, 0.2, 1);
  --ig-hover-scale        : 1.055;
  --ig-hover-filter       : brightness(0.88);
  --ig-row-height         : 240px;
  --ig-mobile-hero-height : 260px;
  --ig-mobile-row-height  : 140px;
  width     : 100%;
  max-width : 1120px;
  margin    : 0 auto;
}

/* ═══════════════════════════════════════════════════════
   GRID
   grid-template-columns / rows are set by JS based on
   the smart layout engine. CSS only supplies the vars.
   ═══════════════════════════════════════════════════════ */
.ig-grid {
  display       : grid;
  gap           : var(--ig-gap);
  border-radius : var(--ig-radius-outer);
  overflow      : hidden;
  position      : relative;
  background    : transparent;
  width         : 100%;
}

/* ── Grid items ─────────────────────────────────────── */
.ig-item {
  position     : relative;
  overflow     : hidden;
  cursor       : pointer;
  align-self   : stretch;
  justify-self : stretch;
  min-width    : 0;
  min-height   : 0;
}

/* ── Image fill ─────────────────────────────────────── */
/* JS also applies these via setProperty('important')   */
.ig-plugin .ig-item > img {
  position        : absolute;
  inset           : 0;
  width           : 100%;
  height          : 100%;
  max-width       : none;
  max-height      : none;
  object-fit      : cover;
  object-position : center;
  display         : block;
  transition      : transform 0.45s var(--ig-ease), filter 0.45s var(--ig-ease);
  will-change     : transform;
}

.ig-item:hover > img {
  transform : scale(var(--ig-hover-scale));
  filter    : var(--ig-hover-filter);
}

.ig-item::after {
  content        : '';
  position       : absolute;
  inset          : 0;
  background     : transparent;
  transition     : background 0.15s ease;
  pointer-events : none;
  z-index        : 1;
}
.ig-item:active::after { background: rgba(255,255,255,.12); }

/* ── Skeleton shimmer ──────────────────────────────── */
.ig-item.ig-loading {
  background      : linear-gradient(90deg,#e8e8e8 25%,#f5f5f5 50%,#e8e8e8 75%);
  background-size : 400% 100%;
  animation       : ig-shimmer 1.4s infinite;
}
@keyframes ig-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ═══════════════════════════════════════════════════════
   HERO OVERLAY (title + description)
   ═══════════════════════════════════════════════════════ */
.ig-hero-overlay {
  position        : absolute;
  inset           : 0;
  display         : flex;
  flex-direction  : column;
  justify-content : flex-end;
  padding         : 28px 24px;
  background      : linear-gradient(to top, rgba(0,0,0,.62) 0%, rgba(0,0,0,.18) 55%, transparent 100%);
  pointer-events  : none;
  opacity         : 0;
  transform       : translateY(8px);
  transition      : opacity .38s var(--ig-ease), transform .38s var(--ig-ease);
  z-index         : 2;
}
.ig-item:first-child:hover .ig-hero-overlay,
.ig-hero-overlay.ig-overlay-always { opacity: 1; transform: translateY(0); }

.ig-hero-title {
  font-size: 22px; font-weight: 600; color: #fff;
  line-height: 1.25; letter-spacing: -.02em;
  text-shadow: 0 1px 8px rgba(0,0,0,.35); margin-bottom: 5px;
}
.ig-hero-desc {
  font-size: 14px; color: rgba(255,255,255,.82);
  line-height: 1.45; text-shadow: 0 1px 6px rgba(0,0,0,.3);
}

/* ═══════════════════════════════════════════════════════
   SHOW ALL BUTTON
   ═══════════════════════════════════════════════════════ */
.ig-btn-all {
  position       : absolute;
  bottom         : 16px;
  right          : 16px;
  background     : var(--ig-btn-bg);
  color          : var(--ig-btn-color);
  border         : 1.5px solid rgba(0,0,0,.16);
  border-radius  : var(--ig-btn-radius);
  padding        : 8px 16px;
  font-family    : inherit;
  font-size      : 13.5px;
  font-weight    : 600;
  cursor         : pointer;
  display        : flex;
  align-items    : center;
  gap            : 7px;
  white-space    : nowrap;
  letter-spacing : -.01em;
  box-shadow     : 0 2px 8px rgba(0,0,0,.14);
  z-index        : 6;
  transition     : background .2s var(--ig-ease), box-shadow .2s var(--ig-ease), transform .2s var(--ig-ease);
}
.ig-btn-all:hover  { box-shadow: 0 4px 16px rgba(0,0,0,.22); transform: translateY(-2px); }
.ig-btn-all:active { transform: translateY(0); }
.ig-btn-all svg    { flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════
   MOBILE  ≤ 640 px — HERO + 2×2 layout
   -------------------------------------------------------
   Overrides JS-set inline grid styles with !important so
   CSS always wins on small screens.

   grid-template-rows sets row 1 = hero height (explicit).
   grid-auto-rows     handles rows 2+ = right item height.
   This auto-adapts to any number of right items without
   hardcoding row counts.

   For odd right-item counts (1, 3, 5 right items), the
   last item spans both columns so there's never a gap.
   ═══════════════════════════════════════════════════════ */
@media (max-width: 640px) {

  .ig-grid {
    grid-template-columns : 1fr 1fr !important;
    grid-template-rows    : var(--ig-mobile-hero-height, 260px) !important;
    grid-auto-rows        : var(--ig-mobile-row-height, 140px) !important;
    border-radius         : var(--ig-radius-outer) !important;
  }

  /* Show all items */
  .ig-item { display: block !important; }

  /* Hero: full width, first row */
  .ig-item:first-child {
    grid-column : 1 / 3 !important;
    grid-row    : 1 !important;
  }

  /* All non-hero items: let CSS auto-place in 2-col grid */
  .ig-item:not(:first-child) {
    grid-column : auto !important;
    grid-row    : auto !important;
  }

  /* Span last item full-width when it would be alone in a row
     (right counts of 1, 3, or 5 are odd → last is alone)     */
  .ig-item:nth-child(2):last-child,
  .ig-item:nth-child(4):last-child,
  .ig-item:nth-child(6):last-child {
    grid-column : 1 / 3 !important;
  }

  /* Hide items beyond the 6th (hero + 5 right) on mobile */
  .ig-item:nth-child(n+7) { display: none !important; }

  /* Overlay always on for mobile hero */
  .ig-hero-overlay { opacity: 1 !important; transform: none !important; }
}

/* ═══════════════════════════════════════════════════════
   LIGHTBOX OVERLAY
   ═══════════════════════════════════════════════════════ */
.ig-overlay {
  position               : fixed;
  inset                  : 0;
  z-index                : 999999;
  display                : flex;
  flex-direction         : column;
  background             : rgba(0,0,0,.78);
  opacity                : 0;
  pointer-events         : none;
  transition             : opacity .3s var(--ig-ease), backdrop-filter .3s ease;
  backdrop-filter        : blur(0px);
  -webkit-backdrop-filter: blur(0px);
}
.ig-overlay.ig-open {
  opacity                : 1;
  pointer-events         : all;
  backdrop-filter        : blur(14px) saturate(1.5);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
}

/* ── Header ─────────────────────────────────────────── */
.ig-overlay-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 20px 24px 10px; flex-shrink: 0; gap: 16px;
  transform: translateY(-12px); opacity: 0;
  transition: transform .35s .05s var(--ig-ease), opacity .35s .05s ease;
}
.ig-overlay.ig-open .ig-overlay-header { transform: translateY(0); opacity: 1; }
.ig-overlay-meta  { flex: 1; min-width: 0; }
.ig-overlay-title {
  display: block; font-size: 15px; font-weight: 600; color: #fff;
  letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ig-overlay-desc {
  display: block; font-size: 13px; color: rgba(255,255,255,.6);
  margin-top: 3px; font-style: italic;
}
.ig-overlay-close {
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18);
  color: #fff; width: 38px; height: 38px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background .2s, transform .25s var(--ig-ease);
}
.ig-overlay-close:hover { background: rgba(255,255,255,.22); transform: rotate(90deg) scale(1.1); }

/* ── Viewer ─────────────────────────────────────────── */
.ig-viewer {
  flex: 1; display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden; padding: 0 72px; min-height: 0;
}

/* A/B crossfade stage */
.ig-stage {
  position: relative; display: flex; align-items: center;
  justify-content: center; width: 100%; height: 100%;
}
.ig-img {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  max-width: 100%; max-height: 100%;
  object-fit: contain; border-radius: 10px;
  box-shadow: 0 24px 80px rgba(0,0,0,.55);
  user-select: none; -webkit-user-drag: none;
}
.ig-img-a { opacity: 1; z-index: 2; transition: opacity .36s var(--ig-ease), transform .36s var(--ig-ease); }
.ig-img-b { opacity: 0; z-index: 1; transition: opacity .36s var(--ig-ease), transform .36s var(--ig-ease); }
.ig-stage.ig-show-b .ig-img-a { opacity: 0; z-index: 1; }
.ig-stage.ig-show-b .ig-img-b { opacity: 1; z-index: 2; }
.ig-img.ig-enter-from-right { transform: translate(calc(-50% + 40px), -50%); }
.ig-img.ig-enter-from-left  { transform: translate(calc(-50% - 40px), -50%); }
.ig-img.ig-exit-to-left     { transform: translate(calc(-50% - 24px), -50%); opacity: 0 !important; }
.ig-img.ig-exit-to-right    { transform: translate(calc(-50% + 24px), -50%); opacity: 0 !important; }
.ig-img-a.ig-initial        { transform: translate(-50%, calc(-50% + 14px)); opacity: 0; }
.ig-overlay.ig-open .ig-img-a.ig-initial { transform: translate(-50%,-50%); opacity:1; transition-delay:.08s; }

/* ── Nav arrows ─────────────────────────────────────── */
.ig-nav {
  position: absolute; top: 50%;
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(255,255,255,.12); border: 1.5px solid rgba(255,255,255,.25);
  color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center;
  z-index: 10; opacity: 0;
  transition: background .2s, border-color .2s, transform .3s .1s var(--ig-ease), opacity .3s .1s ease;
}
.ig-nav.ig-prev { transform: translateY(-50%) translateX(-8px);  left:  14px; }
.ig-nav.ig-next { transform: translateY(-50%) translateX(8px);   right: 14px; }
.ig-overlay.ig-open .ig-nav.ig-prev,
.ig-overlay.ig-open .ig-nav.ig-next { opacity:1; transform: translateY(-50%) translateX(0); }
.ig-overlay.ig-open .ig-nav:hover {
  background: rgba(255,255,255,.26); border-color: rgba(255,255,255,.5);
  transform: translateY(-50%) scale(1.1);
}
.ig-overlay.ig-open .ig-nav:active { transform: translateY(-50%) scale(.95); }

/* ── Counter ─────────────────────────────────────────── */
.ig-counter {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  color: rgba(255,255,255,.75); font-size: 12px; font-weight: 500;
  letter-spacing: .06em; background: rgba(0,0,0,.32); padding: 4px 14px;
  border-radius: 20px; backdrop-filter: blur(4px);
  opacity: 0; transition: opacity .3s .18s ease; white-space: nowrap;
}
.ig-overlay.ig-open .ig-counter { opacity: 1; }

/* ── Caption ─────────────────────────────────────────── */
.ig-caption {
  position: absolute; bottom: 44px; left: 50%; transform: translateX(-50%);
  color: rgba(255,255,255,.85); font-size: 13px; font-style: italic;
  text-align: center; max-width: 80%; opacity: 0;
  transition: opacity .3s .2s ease; pointer-events: none;
  text-shadow: 0 1px 4px rgba(0,0,0,.5); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.ig-overlay.ig-open .ig-caption { opacity: 1; }

/* ── Thumbnails ─────────────────────────────────────── */
.ig-thumbs {
  display: flex; gap: 8px; padding: 12px 24px 16px;
  overflow-x: auto; flex-shrink: 0; justify-content: center;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.25) transparent;
  transform: translateY(14px); opacity: 0;
  transition: transform .35s .12s var(--ig-ease), opacity .35s .12s ease;
}
.ig-overlay.ig-open .ig-thumbs      { transform: translateY(0); opacity: 1; }
.ig-thumbs::-webkit-scrollbar        { height: 3px; }
.ig-thumbs::-webkit-scrollbar-thumb  { background: rgba(255,255,255,.25); border-radius: 3px; }

.ig-thumb {
  position: relative; width: 72px; height: 52px;
  border-radius: 6px; overflow: hidden; cursor: pointer; flex-shrink: 0;
  border: 2.5px solid transparent; opacity: .48;
  transition: border-color .2s, opacity .2s, transform .2s var(--ig-ease), box-shadow .2s;
}
.ig-thumb > img {
  position: absolute !important; inset: 0 !important;
  width: 100% !important; height: 100% !important;
  max-width: none !important; max-height: none !important;
  object-fit: cover !important; display: block !important;
}
.ig-thumb:hover    { opacity: .82; transform: scale(1.06); }
.ig-thumb.ig-active {
  border-color: #fff; opacity: 1; box-shadow: 0 0 0 1px rgba(255,255,255,.4);
}

/* ── Keyboard hint ──────────────────────────────────── */
.ig-hint {
  text-align: center; color: rgba(255,255,255,.22); font-size: 11px;
  padding-bottom: 12px; letter-spacing: .05em; flex-shrink: 0;
}

/* ── Mobile lightbox ─────────────────────────────────── */
@media (max-width: 640px) {
  .ig-viewer      { padding: 0 46px; }
  .ig-nav         { width: 36px; height: 36px; }
  .ig-nav.ig-prev { left: 6px; }
  .ig-nav.ig-next { right: 6px; }
  .ig-hint        { display: none; }
  .ig-thumb       { width: 56px; height: 40px; }
}
