/* Desktop: original layout */
.property-gallery {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  height: 600px;
  overflow: hidden !important;
}

.property-gallery.property-gallery--has-video {
  /* Make the featured media (video) take the freed space. */
  grid-template-columns: 2fr 1fr;
}

.property-gallery.property-gallery--has-video {
  /* Keep the original tile height to avoid thumbnails becoming too tall. */
  height: 520px;
}

.property-gallery .property-gallery__featured {
  height: 600px;
}

.property-gallery.property-gallery--has-video .property-gallery__featured {
  height: 520px;
}

.property-gallery .property-gallery__featured img {
  width: 100%;
  height: 600px;
  -o-object-fit: cover;
     object-fit: cover;
}

.property-gallery .property-gallery__featured .property-gallery__featured-media {
  width: 100%;
  height: 600px;
  position: relative;
  overflow: hidden;
}

.property-gallery.property-gallery--has-video .property-gallery__featured .property-gallery__featured-media {
  /* Fill the full tile height so the left side doesn't end early. */
  aspect-ratio: auto;
  height: 520px;
}

.property-gallery .property-gallery__featured video.property-gallery__featured-video {
  width: 100%;
  height: 600px;
  -o-object-fit: cover;
     object-fit: cover;
  display: block;
}

.property-gallery .property-gallery__featured iframe.property-gallery__featured-iframe {
  /* Fill the tile; the tile aspect ratio is handled by the container. */
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  transform: none;
  display: block;
  border: 0;
}

.property-gallery .property-gallery__thumb_big {
  height: 600px !important;
  width: 100%;
  -o-object-fit: cover;
     object-fit: cover;
}

.property-gallery .property-gallery__thumbs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: calc((600px - 12px) / 2) calc((600px - 12px) / 2);
  gap: 12px;
  height: 600px;
}

.property-gallery.property-gallery--has-video .property-gallery__thumbs {
  /* Only 2 thumbnails (right column) => render as a single column stack. */
  grid-template-columns: 1fr;
  --property-gallery-thumbs-height: 521px;
  height: var(--property-gallery-thumbs-height);
  grid-template-rows: calc((var(--property-gallery-thumbs-height) - 12px) / 2) calc((var(--property-gallery-thumbs-height) - 12px) / 2);
  align-self: center;
}

.property-gallery .property-gallery__thumbs .property-gallery__thumb {
  height: 100%;
  position: relative;
  overflow: hidden;
}

.property-gallery .property-gallery__thumbs .property-gallery__thumb img {
  width: 100%;
  height: 100%;
  -o-object-fit: cover;
     object-fit: cover;
}

/* Desktop: button inside last thumb */
.property-gallery__more-btn--desktop {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: #ffffff;
  background-color: #ca2a2a;
  padding: 0.5rem 1rem;
  text-decoration: none;
  transition: background-color 0.2s ease;
}

.property-gallery__more-btn--desktop:hover {
  color: #ffffff !important;
  background-color: #ca2a2ad8;
}

/* Mobile: hide desktop button */
.property-gallery__more-btn--mobile {
  display: none;
}

.property-gallery__more-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

/* Mobile: 2fr 1fr, 250px, 2 thumbs only, overlay button */
@media (max-width: 768px) {
  .property-gallery {
    grid-template-columns: 2fr 1fr;
    height: 250px;
    min-height: 250px;
  }

  .property-gallery .property-gallery__featured {
    height: 250px;
  }

  .property-gallery .property-gallery__featured img,
  .property-gallery .property-gallery__thumb_big {
    height: 250px;
  }

  .property-gallery .property-gallery__featured .property-gallery__featured-media {
    height: 250px;
  }

  .property-gallery .property-gallery__featured video.property-gallery__featured-video {
    height: 250px;
  }

  .property-gallery .property-gallery__featured iframe.property-gallery__featured-iframe {
    /* Keep aspect ratio on mobile too */
    height: 100%;
  }

  .property-gallery .property-gallery__thumb_big {
    height: 250px !important;
  }

  .property-gallery .property-gallery__thumbs {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
    height: 250px;
    position: relative;
  }

  /* Hide 3rd and 4th thumb on mobile */
  .property-gallery .property-gallery__thumbs .property-gallery__thumb:nth-child(3),
  .property-gallery .property-gallery__thumbs .property-gallery__thumb:nth-child(4) {
    display: none;
  }

  /* Hide button inside last visible thumb */
  .property-gallery__more-btn--desktop {
    display: none;
  }

  /* Show overlay button */
  .property-gallery__more-btn--mobile {
    display: inline-flex;
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: #ffffff;
    background-color: #ca2a2a;
    padding: 0.5rem 1rem;
    text-decoration: none;
    transition: background-color 0.2s ease;
    z-index: 2;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  .property-gallery__more-btn--mobile:hover {
    color: #ffffff !important;
    background-color: #ca2a2ad8;
  }

  .property-gallery.property-gallery--has-video {
    height: 250px;
  }

  .property-gallery.property-gallery--has-video .property-gallery__featured .property-gallery__featured-media {
    /* Ensure video keeps 16:9 and doesn't letterbox due to fixed heights. */
    aspect-ratio: 16 / 9;
    height: 250px;
  }

  .property-gallery.property-gallery--has-video .property-gallery__thumbs {
    height: 100%;
    grid-template-rows: calc((100% - 12px) / 2) calc((100% - 12px) / 2);
    align-self: stretch;
  }
}

@media (max-width: 480px) {
  .property-gallery {
    height: 200px;
    min-height: 200px;
  }

  .property-gallery .property-gallery__featured,
  .property-gallery .property-gallery__featured img,
  .property-gallery .property-gallery__thumb_big {
    height: 200px;
  }

  .property-gallery .property-gallery__featured .property-gallery__featured-media {
    height: 200px;
  }

  .property-gallery .property-gallery__featured video.property-gallery__featured-video {
    height: 200px;
  }

  .property-gallery .property-gallery__thumb_big {
    height: 200px !important;
  }

  .property-gallery .property-gallery__thumbs {
    height: 200px;
  }

  .property-gallery .property-gallery__featured iframe.property-gallery__featured-iframe {
    height: 100%;
  }

  .property-gallery__more-btn--mobile {
    font-size: 0.75rem;
    padding: 0.4rem 0.75rem;
  }

  .property-gallery.property-gallery--has-video {
    height: 200px;
  }

  .property-gallery.property-gallery--has-video .property-gallery__featured .property-gallery__featured-media {
    /* Ensure video keeps 16:9 and doesn't letterbox due to fixed heights. */
    aspect-ratio: 16 / 9;
    height: 200px;
  }

  .property-gallery.property-gallery--has-video .property-gallery__thumbs {
    height: 100%;
    grid-template-rows: calc((100% - 12px) / 2) calc((100% - 12px) / 2);
    align-self: stretch;
  }
}
