/* Scoped improvements for Google Maps InfoWindow and custom overlays on GPX pages */

/* Ensure the scrollable wrapper in newer Maps API does not clip content */
.gm-style .gm-style-iw-d {
  overflow: visible !important;
  max-height: none !important; /* prevent inner scrollbars that hide content */
}

/* Give the content container enough room for two-column layouts */
.gm-style .gm-style-iw-c {
  max-width: 860px !important;
  min-height: 0 !important; /* override any global min-height */
  box-sizing: border-box;
}

/* Make images inside our panels responsive, without affecting map tiles */
.gm-style .image-box img,
.custom-info-overlay .image-box img {
  width: 100% !important;
  height: auto !important;
  display: block;
  border-radius: 6px;
}

/* Cap image height so text remains visible without forcing scrollbars */
.gm-style .image-box .overlay-container img,
.custom-info-overlay .image-box .overlay-container img {
  max-height: 280px;
  object-fit: cover;
}

/* Normalize legacy Bootstrap spacing and replace with flexible layout */
.gm-style .image-box .row.grid-space-0,
.custom-info-overlay .image-box .row.grid-space-0 {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: stretch;
}

.gm-style .image-box .col-md-6,
.custom-info-overlay .image-box .col-md-6 {
  float: none;
  width: auto;
  padding: 0 12px;
  box-sizing: border-box;
  flex: 1 1 300px;
  max-width: 50%;
}

@media (max-width: 640px) {
  .gm-style .gm-style-iw-c { max-width: 92vw !important; }
  .gm-style .image-box .row.grid-space-0,
  .custom-info-overlay .image-box .row.grid-space-0 {
    flex-direction: column;
    gap: 12px;
  }
  .gm-style .image-box .col-md-6,
  .custom-info-overlay .image-box .col-md-6 {
    flex: 1 1 100%;
    max-width: none;
    padding: 0;
  }
}

/* Tidy up typography and spacing */
.gm-style .image-box .body h3,
.custom-info-overlay .image-box .body h3 {
  margin-top: 6px;
  margin-bottom: 8px;
  font-size: 22px;
}
.gm-style .image-box .body p,
.custom-info-overlay .image-box .body p {
  margin: 0;
  line-height: 1.4;
  white-space: normal;
}

.gm-style .image-box .body,
.custom-info-overlay .image-box .body { overflow: visible; }

/* Custom overlay shell */
.custom-info-overlay {
  pointer-events: auto;
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 18px 36px rgba(31, 41, 55, 0.32);
  transform: translate(-50%, calc(-100% - 28px)) scale(0.98);
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  max-width: min(780px, 92vw);
  min-width: 280px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.25);
  z-index: 5;
}

.custom-info-overlay--visible {
  opacity: 1;
  transform: translate(-50%, calc(-100% - 32px)) scale(1);
}

.custom-info-overlay::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -18px;
  transform: translateX(-50%);
  border-width: 18px 16px 0 16px;
  border-style: solid;
  border-color: #ffffff transparent transparent transparent;
  filter: drop-shadow(0 12px 20px rgba(15, 23, 42, 0.15));
}

.custom-info-overlay__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.7);
  color: #ffffff;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  z-index: 1;
}

.custom-info-overlay__close:hover,
.custom-info-overlay__close:focus {
  background: rgba(15, 23, 42, 0.85);
  outline: none;
}

.custom-info-overlay__content {
  padding: 26px 28px;
  max-height: min(70vh, 560px);
  overflow-y: auto;
  scrollbar-width: thin;
}

.custom-info-overlay__stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.custom-info-overlay__marker .image-box {
  margin-bottom: 0;
}

@media (max-width: 640px) {
  .custom-info-overlay {
    max-width: 94vw;
    min-width: 0;
  }

  .custom-info-overlay__content {
    padding: 22px 20px;
    max-height: 70vh;
  }
}

.masonry-grid-fitrows{
  display:flex; flex-wrap:wrap;
  margin-left:-12px; margin-right:-12px;
  align-items:flex-start;                 /* do not stretch to container height */
  height:auto !important;                 /* override inline height:1166px */
}
.masonry-grid-fitrows > .masonry-grid-item{
  padding:12px; width:100%; display:flex;
}
@media (min-width:576px){ .masonry-grid-fitrows > .masonry-grid-item{width:50%} }
@media (min-width:992px){ .masonry-grid-fitrows > .masonry-grid-item{width:25%} }

/* CARD */
.masonry-grid-item .listing-item{
  display:flex; flex-direction:column; width:100%;
  background:var(--brand-primary-color);
  border-radius:4px; overflow:hidden;
  /* no min-height here */
}
.masonry-grid-item .listing-item:hover{background:var(--brand-secondary-color)}

/* BODY at bottom */
.masonry-grid-item .body{margin-top:auto; padding:16px}
.masonry-grid-item h3{margin:0}

/* Title = max 2 lines so all cards equal */
.masonry-grid-item h3 a{
  color:#fff; display:-webkit-box; -webkit-box-orient:vertical;
  -webkit-line-clamp:2; overflow:hidden;
  line-height:1.35; min-height:calc(1.35em * 2);
}