/* Apartment Types Lightbox
   -------------------------------------------------------------------------- */

   :root {
    --apt-lb-bg: #FEFAF1;
    --apt-lb-surface: #ffffff;
    --apt-lb-text: #1c1c1c;
    --apt-lb-muted: #6f6a63;
    --apt-lb-border: rgba(0, 0, 0, 0.12);
    --apt-lb-shadow: 0 28px 90px rgba(0, 0, 0, 0.28);
    /*
      Dynamic media height trim.
      Default is 0 (no trim). The JS will increase this value only if the
      modal content would overflow vertically (to avoid a vertical scrollbar).
    */
    --apt-media-cut: 0px;
  }
  
  body.apt-lightbox-open {
    position: fixed;
    width: 100%;
    overflow: hidden;
  }
  
  .apt-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    color: var(--apt-lb-text);
  }
  
  .apt-lightbox.is-open {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
  }
  
  .apt-lightbox__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
  }
  
  .apt-lightbox__dialog {
    position: relative;
    width: min(1240px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    margin: 0;
    background: var(--apt-lb-bg);
    border-radius: 18px;
    box-shadow: var(--apt-lb-shadow);
    overflow: hidden;
  }
  
  .apt-lightbox__inner {
    position: relative;
    padding: 38px 18px 16px 18px;
    box-sizing: border-box;
    max-height: calc(100vh - 32px);
    /*
      Avoid showing a vertical scrollbar inside the modal.
      If an extreme viewport size makes it impossible to fit, JS will add
      .is-scrollable on the modal as a fallback.
    */
    overflow: hidden;
  }
  
  .apt-lightbox.is-scrollable .apt-lightbox__inner {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Close button (close.png) */
  .apt-lightbox__close {
    position: absolute;
    top: 10px;
    right: 8px;
    width: 44px;
    height: 44px;
    border: 0;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 3;
    line-height: 0;
    background: none !important;
    box-shadow: 0px 0px 0px 0px rgba(0,0,0,0) !important;
  }
  
  .apt-lightbox__close:hover {
    background: transparent;
  }
  
  .apt-lightbox__close:focus-visible {
    outline: 2px solid rgba(0, 0, 0, 0.55);
    outline-offset: 4px;
    border-radius: 10px;
  }
  
  .apt-lightbox__close-img {
    width: 28px;
    height: 28px;
    display: block;
    object-fit: contain;
  }
  
  .apt-lightbox__top {
    padding-top: 20px; /* leaves room for close button */
  }
  
  /* Carousel (custom, no Splide)
     3-up desktop: 25% / 50% / 25% using 1fr 2fr 1fr.
     -------------------------------------------------------------------------- */
  
  .apt-lightbox__media {
    position: relative;
  }
  
  .apt-lightbox__media-grid {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    gap: 14px;
    /* Allow horizontal swipe gestures on touch devices without causing page scroll. */
    touch-action: pan-y;
    /*
      Fixed media region height with optional dynamic trim (via --apt-media-cut).
      The max() guard prevents the carousel from collapsing to an unusable size.
    */
    height: max(160px, calc(clamp(220px, 55vh, 560px) - var(--apt-media-cut)));
    max-width: 100%;
  }
  
  /* ✅ Desktop: ensure gallery never gets trimmed below ~300px */
  @media (min-width: 901px) and (min-height: 650px) {
    .apt-lightbox__media-grid {
      height: max(300px, calc(clamp(220px, 55vh, 560px) - var(--apt-media-cut)));
    }
  }
  
  .apt-lightbox__image {
    border-radius: 14px;
    background: var(--apt-lb-surface);
    overflow: hidden;
    height: 100%;
    /* border: 2px solid rgba(0, 0, 0, 0.08); */
    box-shadow: 0 18px 55px rgba(0, 0, 0, 0.16);
    box-sizing: border-box;
    transition: opacity 220ms ease, transform 220ms ease;
    will-change: opacity, transform;
    -webkit-user-select: none;
    user-select: none;
  }
  
  .apt-lightbox__image img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    -webkit-user-drag: none;
  }
  
  .apt-lightbox__image--prev,
  .apt-lightbox__image--next {
    opacity: 0.86;
    filter: saturate(0.96);
  }
  
  .apt-lightbox__image--main {
    /* border-color: rgba(0, 0, 0, 0.18);
    box-shadow: 0 26px 80px rgba(0, 0, 0, 0.22); */
  }
  
  /* Smooth transitions between slides (custom carousel) */
  .apt-lightbox__media-grid.is-transitioning-next .apt-lightbox__image {
    opacity: 0;
    transform: translateX(-18px);
  }
  
  .apt-lightbox__media-grid.is-transitioning-prev .apt-lightbox__image {
    opacity: 0;
    transform: translateX(18px);
  }
  
  /* Prev/Next buttons (Splide-style markup) */
  .apt-lightbox__arrows {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
  }
  
  .apt-lightbox__arrows .splide__arrow {
    pointer-events: auto;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: var(--apt-lb-text);
  }
  
  .apt-lightbox__arrows .splide__arrow:hover {
    background: rgba(255, 255, 255, 1);
  }
  
  .apt-lightbox__arrows .splide__arrow svg {
    width: 18px;
    height: 18px;
    display: block;
    fill: currentColor;
  }
  
  .apt-lightbox__arrows .splide__arrow--prev {
    left: 10px;
  }
  
  .apt-lightbox__arrows .splide__arrow--next {
    right: 10px;
  }
  
  /* Provided SVG points right by default; flip the prev arrow. */
  .apt-lightbox__arrows .splide__arrow--prev svg {
    transform: rotate(180deg);
  }
  
  /* Thumbnails row */
  .apt-lightbox__thumbs {
    margin-top: 12px;
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 6px;
  }
  
  .apt-lightbox__thumbs::-webkit-scrollbar {
    height: 8px;
  }
  
  .apt-lightbox__thumbs::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 999px;
  }
  
  .apt-thumb {
    flex: 0 0 auto;
    width: 66px;
    height: 48px;
    border-radius: 10px;
    border: 2px solid transparent;
    background: rgba(255, 255, 255, 0.6);
    padding: 0;
    overflow: hidden;
    cursor: pointer;
  }
  
  .apt-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }
  
  .apt-thumb.is-active {
    border-color: rgba(0, 0, 0, 0.65);
  }
  
  /* Meta + stats */
  .apt-lightbox__meta {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 0px solid var(--apt-lb-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
  }
  
  /* Download Floorplan button */
  .apt-lightbox__download {
    display: none; /* shown only when a floorplan PDF exists */
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    padding: 13px 20px 13px 20px !important;
    border-radius: 8px;
    background: #2d1f1b;
    color: #ffffff;
    text-decoration: none;
    font-size: var(--global-kb-font-size-md);
    line-height: 1;
    border: 0;
    cursor: pointer;
    /* box-shadow: 0 10px 26px rgba(0, 0, 0, 0.18); */
  }
  
  .apt-lightbox__download:hover {
    background: #3a2924;
    color: #ffffff !important;
  }
  
  .apt-lightbox__download:focus-visible {
    outline: 2px solid rgba(0, 0, 0, 0.55);
    outline-offset: 3px;
    color: #ffffff !important;
  }
  
  .apt-lightbox__download:focus,
  .apt-lightbox__download:active {
    color: #ffffff !important;
  }
  
  .apt-lightbox__subtitle {
    color: var(--global-palette1);
    margin-bottom: 4px;
    font-size: var(--global-kb-font-size-md);
  }
  
  .apt-lightbox__title {
    font-size: var(--global-kb-font-size-lg);
    font-weight: 700;
    font-family: Idlewild, Helvetica, Arial;
    line-height: 1.1;
    color: var(--global-palette1);
  }
  
  .apt-lightbox__stats {
    margin-top: 12px;
    padding-top: 14px;
    border-top: 1px solid var(--apt-lb-border);
  }
  
  .apt-lightbox__stats:empty {
    display: none;
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }
  
  /* Apartment models table (repeater) */
  .apt-models-table-shell {
    border: 1px solid var(--apt-lb-border);
    border-radius: 16px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.03);
  }
  
  /* ✅ Updated: table scrolls vertically when needed (gallery height unchanged) */
  .apt-models-table-scroll {
    overflow-x: auto;
    overflow-y: auto;                      /* vertical scroll lives here */
    max-height: clamp(180px, 22vh, 240px); /* cap table height so it won't force media trimming */
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
  }
  
  /* Optional: scrollbar styling to match your theme */
  .apt-models-table-scroll::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  
  .apt-models-table-scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 999px;
  }
  
  .apt-models-table {
    width: 100%;
    min-width: 720px;
    border-collapse: separate;
    border-spacing: 0;
  }
  
  .apt-models-table th,
  .apt-models-table td {
    padding: 14px 16px;
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
  }
  
  .apt-models-table thead th {
    font-size: var(--global-kb-font-size-md);
    font-weight: 700;
    color: var(--global-palette1);
    background: rgba(0, 0, 0, 0.02);
    border-bottom: 1px solid var(--apt-lb-border);
    border-right: 1px solid var(--apt-lb-border);
  }
  
  .apt-models-table thead th:last-child {
    border-right: 0;
  }
  
  .apt-models-table tbody td {
    font-size: var(--global-kb-font-size-sm);
    border-bottom: 1px solid var(--apt-lb-border);
    border-right: 1px solid var(--apt-lb-border);
  }
  
  .apt-models-table tbody td:last-child {
    border-right: 0;
  }
  
  .apt-models-table tbody tr:last-child td {
    border-bottom: 0;
  }
  
  .apt-models-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.08);
    font-weight: 600;
  }
  
  /* Loading overlay */
  .apt-lightbox__loading {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(246, 241, 234, 0.92);
    backdrop-filter: blur(2px);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 10px;
    z-index: 4;
  }
  
  .apt-lightbox.is-loading .apt-lightbox__loading {
    display: flex;
  }
  
  .apt-lightbox__spinner {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 4px solid rgba(0, 0, 0, 0.12);
    border-top-color: rgba(0, 0, 0, 0.55);
    animation: apt-lb-spin 0.9s linear infinite;
  }
  
  @keyframes apt-lb-spin {
    to {
      transform: rotate(360deg);
    }
  }
  
  .apt-lightbox__loading-text {
    color: var(--apt-lb-muted);
    font-size: 14px;
  }
  
  /* Error state: reuse the loading overlay but show text-only (no spinner). */
  .apt-lightbox.is-error .apt-lightbox__spinner {
    display: none;
  }
  
  .apt-lightbox.is-error .apt-lightbox__loading-text a {
    color: var(--apt-lb-text);
    text-decoration: underline;
  }
  
  /* Responsive */
  @media (max-width: 1024px) {
    .apt-lightbox__title {
    }
  
    .apt-models-table {
      min-width: 680px;
    }
  }
  
  @media (max-width: 900px) {
    /* Hide the previous preview; show main + next */
    .apt-lightbox__media-grid {
      grid-template-columns: 2fr 1fr;
      height: max(160px, calc(clamp(220px, 50vh, 520px) - var(--apt-media-cut)));
    }
  
    .apt-lightbox__image--prev {
      display: none;
    }
  
    .apt-lightbox__arrows .splide__arrow--prev {
      left: 6px;
    }
  
    .apt-lightbox__arrows .splide__arrow--next {
      right: 6px;
    }
  }
  
  @media (max-width: 700px) {
    .apt-lightbox.is-open {
      /* Keep breathing room + account for iOS safe areas. */
      padding: 8px;
      padding-top: calc(10px + env(safe-area-inset-top));
      padding-right: calc(8px + env(safe-area-inset-right));
      padding-bottom: calc(10px + env(safe-area-inset-bottom));
      padding-left: calc(8px + env(safe-area-inset-left));
      align-items: flex-start;
    }
  
    .apt-lightbox__dialog {
      width: calc(100vw - 16px);
      /*
       * IMPORTANT:
       *  - Avoid 100vh on mobile (iOS Safari can exceed visible viewport).
       *  - Cap to 98% of the visible viewport via JS-set --apt-visible-vh98 (px).
       */
      max-height: calc(min(var(--apt-visible-vh98, 98svh), 98svh) - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
      margin: 0;
      border-radius: 14px;
    }
  
    .apt-lightbox__inner {
      padding: 14px;
      max-height: calc(min(var(--apt-visible-vh98, 98svh), 98svh) - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
    }
  
    @supports (height: 100dvh) {
      .apt-lightbox__dialog {
        max-height: calc(min(var(--apt-visible-vh98, 98dvh), 98dvh) - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
      }
      .apt-lightbox__inner {
        max-height: calc(min(var(--apt-visible-vh98, 98dvh), 98dvh) - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
      }
    }
  
    /* Single image only on small screens */
    .apt-lightbox__media-grid {
      grid-template-columns: 1fr;
      height: max(200px, calc(clamp(260px, 58vh, 520px) - var(--apt-media-cut)));
    }
  
    .apt-lightbox__image--next {
      display: none;
    }
  
    .apt-lightbox__arrows .splide__arrow {
      width: 40px;
      height: 40px;
    }
  
    .apt-lightbox__meta {
      flex-direction: column;
      align-items: flex-start;
    }
  
    .apt-lightbox__download {
      width: 100%;
      justify-content: center;
    }
  
    .apt-models-table {
      min-width: 640px;
    }
  
    .apt-models-table th,
    .apt-models-table td {
      padding: 12px 12px;
    }
  }