/* =========================================================
   MB Media Gallery (refactored)
   Goals:
   - Gallery should NEVER cover the site header / dropdown menus
   - Keep arrows clickable and above media
   - Keep modal above everything
   - Tabs centered above media
   - Counter + "View Larger Image" on same line
   - "View Larger Image" ONLY when Images tab is active
   - Reduced gap between counter/link row and title
   ========================================================= */

/* ---------------------------------------------------------
   0) Root + sane defaults
   --------------------------------------------------------- */

.mb-media-gallery {
  position: relative;
  z-index: 1 !important; /* keep below header/menu layers */
}

/* IMPORTANT:
   We hide the link by default and only show it when the JS marks
   the gallery as "images" via .mb-media-gallery--images.
   This avoids relying on brittle inline-style selectors. */
.mb-media-gallery__view-larger {
  display: none !important;
}

/* Show link only when Images tab is active (JS must toggle these classes) */
.mb-media-gallery.mb-media-gallery--images .mb-media-gallery__view-larger {
  display: inline-block !important;
}

/* If you haven't added the JS class toggles yet, this keeps the old behavior as fallback:
   - When JS does .hide() it sets display:none inline, so this will still work.
   - We match BOTH "display:none" and "display: none". */
.mb-media-gallery__view-larger[style*="display:none"],
.mb-media-gallery__view-larger[style*="display: none"] {
  display: none !important;
}

/* ---------------------------------------------------------
   1) Stacking order fixes
   --------------------------------------------------------- */

/* The gallery should not "win" the stacking contest */
.mb-media-gallery__container {
  margin-top: 20px;
  margin-left: 0px !important;
  margin-right: 0px !important;
  position: relative;
  z-index: 0 !important; /* below header dropdowns */
}

.mb-media-gallery__viewer {
  position: relative !important;
}

/* Tabs and content keep modest z-index */
.mb-media-gallery__tabs,
.mb-media-gallery__images,
.mb-media-gallery__videos {
  position: relative;
  z-index: 1 !important;
}

/* Viewer contents sit at base level; arrows sit above. */
.mb-media-gallery__images,
.mb-media-gallery__videos {
  position: absolute;
  inset: 0;
}

/* Keep arrows above the media, but still below header dropdowns */
.mb-media-gallery__arrow {
  position: absolute;
  z-index: 2 !important;
}

/* ---------------------------------------------------------
   2) Layout + responsiveness
   TABS CENTERED ABOVE MEDIA
   --------------------------------------------------------- */

.mb-media-gallery__tabs {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;

  visibility: visible !important;
  opacity: 1 !important;

  gap: 10px;
  margin: 0 auto 10px auto;
  border-bottom: 2px solid #e0e0e0;
  background: transparent;

  width: 100%;
  max-width: 600px; /* prevent tabs stretching too wide */
}

.mb-media-gallery__tab {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;

  flex: 1;
  max-width: 250px;
  margin-bottom: 10px;

  padding: 1rem;
  background: #DE7A39 !important; /* orange */
  color: #ffffff !important;

  border: none;
  border-bottom: 3px solid transparent;

  cursor: pointer;

  font-size: 16px;
  font-weight: 400;
  text-align: center;

  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  position: relative;
  bottom: -2px;
}

.mb-media-gallery__tab:hover {
  transform: translateY(-1px);
}

.mb-media-gallery__tab:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.mb-media-gallery__tab.active,
.mb-media-gallery__tab--images.active,
.mb-media-gallery__tab--videos.active {
  background: #008345 !important; /* green */
  color: #ffffff !important;
  font-weight: 700 !important;
  border-bottom-color: #008345 !important;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Ensure containers don't overflow oddly */
.mb-media-gallery__videos,
.mb-media-gallery__images {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

/* Images */
.mb-media-gallery__image {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Video wrapper – keeps iframe responsive */
.mb-media-gallery__video-wrapper {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}

/* iframe always fills wrapper */
.mb-media-gallery__video-wrapper iframe,
.mb-media-gallery__iframe {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  border: none;
}

/* ---------------------------------------------------------
   3) Counter + "View Larger Image" + Title
   Counter and link on same line, title below with reduced gap
   --------------------------------------------------------- */

.mb-media-gallery__info {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;

  gap: 2px !important; /* tighter spacing */
  padding: 12px 15px !important;

  background: #f8f8f8 !important;
  border-top: 1px solid #e0e0e0 !important;

  text-align: center !important;
}

/* Counter + link on the same line */
.mb-media-gallery__counter-row {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 12px !important;
  flex-wrap: wrap !important;
  order: 1 !important;
}

/* Counter container */
.mb-media-gallery__counter {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 4px !important;

  font-size: 13px !important;
  font-weight: 600 !important;
  color: #007A3D !important;
  white-space: nowrap !important;
  margin: 0 !important;
}

/* Counter numbers */
.mb-media-gallery__current,
.mb-media-gallery__total {
  font-weight: 700 !important;
  color: #008345 !important;
}

/* "View Larger Image" link styles (visibility controlled above) */
.mb-media-gallery__view-larger {
  font-size: 13px !important;
  font-weight: 600 !important;
  color: #0066CC !important;
  text-decoration: underline !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  margin: 0 !important;
}

.mb-media-gallery__view-larger:hover {
  color: #0052A3 !important;
  text-decoration: none !important;
}

/* Title below counter/link */
.mb-media-gallery__title {
  display: block !important;

  font-size: 14px !important;
  font-weight: 600 !important;
  color: #333 !important;

  margin: 0 !important;
  width: 100% !important;
  text-align: center !important;

  flex: none !important;
  order: 2 !important;
}

/* ---------------------------------------------------------
   4) Modal (full-size image)
   --------------------------------------------------------- */

.mb-media-gallery-modal {
  position: fixed;
  inset: 0;
  z-index: 99999; /* above nav & gallery */
  display: none;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.mb-media-gallery-modal.is-open {
  display: flex;
}

.mb-media-gallery-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.mb-media-gallery-modal__dialog {
  position: relative;
  z-index: 1;
  max-width: 90vw;
  max-height: 90vh;
  background: #111;
  border-radius: 12px;
  padding: 0.75rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);

  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.mb-media-gallery-modal__image-wrapper {
  flex: 1 1 auto;
  min-height: 200px;
  max-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mb-media-gallery-modal__image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.mb-media-gallery-modal__buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.mb-media-gallery-modal__save,
.mb-media-gallery-modal__close {
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: 0.9rem;
  line-height: 1.2;
  cursor: pointer;
  border: 1px solid #ccc;
  text-decoration: none;
}

.mb-media-gallery-modal__save {
  display: none; /* intentionally hidden */
  background: #008345;
  color: #fff;
  border-color: #008345;
}

.mb-media-gallery-modal__save:hover {
  background: #006c39;
  border-color: #006c39;
}

.mb-media-gallery-modal__close {
  background: #f1f1f1;
  color: #222;
}

.mb-media-gallery-modal__close:hover {
  background: #e2e2e2;
}

/* ---------------------------------------------------------
   5) Mobile tweaks
   --------------------------------------------------------- */

@media (max-width: 600px) {
  .mb-media-gallery__tabs {
    gap: 6px;
    margin: 0 auto 8px auto;
    max-width: 100%;
  }

  .mb-media-gallery__tab {
    margin-bottom: 8px;
    padding: 0.60rem;
    font-size: 12px;
  }

  .mb-media-gallery__tab.active {
    font-size: 14px;
  }

  .mb-media-gallery__info {
    padding: 10px 12px !important;
    gap: 2px !important;
  }

  .mb-media-gallery__counter-row {
    gap: 10px !important;
  }

  .mb-media-gallery__counter {
    font-size: 12px !important;
  }

  .mb-media-gallery__title {
    font-size: 13px !important;
  }

  .mb-media-gallery__view-larger {
    font-size: 12px !important;
    font-weight: 700 !important;
  }

  .mb-media-gallery-modal__dialog {
    width: 94vw;
    padding: 0.6rem;
  }

  .mb-media-gallery-modal__buttons {
    flex-wrap: wrap;
    justify-content: center;
  }
}

@media (max-width: 767px) {
  .mb-media-gallery__tabs {
    max-width: 500px;
  }

  .mb-media-gallery__tab {
    font-size: 14px;
    padding: 0.75rem;
  }
}
