/* ---------- Layout & Map Panel ---------- */
html, body { height: 100%; scroll-behavior: smooth; }

#map { height: 100vh; width: 100%; }

.map-page { position: relative; }

.map-panel {
  position: absolute;
  top: auto;
  bottom: 10vh; /* ~10% up from the bottom edge */
  left: 16px;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  width: 340px; /* slightly wider */
  max-width: 92vw; /* constrain on small screens */
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.map-panel .panel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  border: 0;
  padding: 10px 12px;
  border-radius: 12px 12px 0 0;
  cursor: pointer;
}
.map-panel .panel-toggle .chevron { transition: transform 0.2s ease; }
.map-panel.collapsed .panel-toggle { border-radius: 12px; }
.map-panel .panel-body { border-top: 1px solid rgba(255, 255, 255, 0.15); }
.map-panel.collapsed .panel-body { display: none; }

.map-panel .form-control,
.map-panel .btn {
  border-radius: 10px;
}

.leaflet-popup-content {
  width: min(92vw, 560px); /* responsive width capped for large screens */
  max-height: 72vh;        /* responsive height relative to viewport */
  overflow-y: auto;        /* scroll inside if content grows */
}

/* ---------- Hero Section ---------- */
.hero {
  position: relative;
  height: 100vh;
  overflow: hidden;
}

.hero-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  filter: brightness(0.65) contrast(1.1);
  transition: transform 0.8s ease-out;
}

.hero:hover .hero-img { transform: scale(1.03); }

.hero-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.65) 100%);
}

.hero .container {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  align-items: center;
}

/* ---------- Animation ---------- */
section {
  animation: fadeIn 1.2s ease both;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Scroll Cue ---------- */
.scroll-down {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.9rem;
  opacity: 0.8;
}
.arrow-down {
  width: 10px;
  height: 10px;
  border-left: 2px solid white;
  border-bottom: 2px solid white;
  transform: rotate(-45deg);
  margin: 0 auto;
  animation: bounce 1.5s infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0) rotate(-45deg); }
  50% { transform: translateY(5px) rotate(-45deg); }
}

/* ---------- Popup Styling ---------- */
.leaflet-popup-content strong {
  color: #222;
  font-weight: 600;
}
.leaflet-popup-content .text-secondary {
  color: #555 !important;
}
.leaflet-popup-content sub { font-size: 0.7em; }

/* Layout for metrics + thumbnail in popup */
.metrics-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.metrics-left {
  flex: 1 1 auto;
  min-width: 0;
}
.metrics-thumb {
  flex: 0 0 280px; /* expand timeline thumbnail further left */
}

/* Layout for top info + satellite thumbnail */
.info-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.info-left { flex: 1 1 auto; min-width: 0; }
.info-thumb { flex: 0 0 160px; }
.popup-sat .popup-thumb {
  display: block;
  width: 100%;
  max-width: 160px;
  height: 120px; /* reserve space */
  object-fit: cover;
  margin: 0 auto;
  border-radius: 8px;
  background: #111;
  border: 1px solid rgba(0,0,0,0.12);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* (removed) interactive mini-map container styles */

/* ---------- Popup Figure Thumbnail ---------- */
.popup-figure { margin: 6px 0 8px; text-align: center; }
.popup-figure .popup-thumb {
  display: block;
  width: 100%;
  max-width: 280px;            /* wider figure */
  height: 240px;               /* taller to span downward */
  object-fit: contain;
  margin: 0 auto;
  border-radius: 8px;
  background: #111;
  border: 1px solid rgba(0,0,0,0.12);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  cursor: pointer;
}
.popup-figure .hint { opacity: 0.7; font-size: 0.78rem; }

/* Bottom media row for thumbnails (timeline + satellite) */
.media-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 6px;
}
.media-item {
  flex: 0 0 160px;
}

/* ---------- Mobile optimizations (small screens) ---------- */
@media (max-width: 576px) {
  .leaflet-popup-content {
    width: 60vw;       /* a bit narrower on phones for comfort */
    max-height: 78vh;  /* reduce height a touch to avoid keyboard overlap */
  }

  .info-row,
  .metrics-row {
    flex-direction: column; /* stack sections vertically */
    gap: 8px;
  }

  .info-thumb,
  .metrics-thumb,
  .media-item {
    flex: 0 0 auto;   /* let thumbs size naturally */
    max-width: 100%;
  }

  /* Make thumbnails fluid and avoid fixed heights on very small screens */
  .popup-sat .popup-thumb,
  .popup-figure .popup-thumb {
    max-width: 100%;
    width: 100%;
    height: auto;     /* preserve aspect ratio and reduce vertical overflow */
  }

  /* Hide small helper hints to save space */
  .popup-figure .hint {
    display: none;
  }

  /* On very small screens, hide the thumbnails altogether */
  .media-row,
  .info-thumb,
  .metrics-thumb {
    display: none !important;
  }

  /* Show mobile-only buttons on small screens */
  .mobile-only { display: inline-block !important; }
}

/* ---------- Building Icon ---------- */
.building-icon {
  user-select: none;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.building-icon:hover {
  transform: translate(-50%, -50%) scale(1.15);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

/* ---------- High-contrast cluster icons ---------- */
.custom-cluster {
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  border: 3px solid #111;
  color: #fff;
  font-weight: 700;
  text-align: center;
}
.custom-cluster .cc-inner {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.custom-cluster span { font-size: 14px; line-height: 1; text-shadow: 0 1px 2px rgba(0,0,0,0.5); }

/* Tiers: small (<10), medium (10-49), large (>=50) */
.custom-cluster-small .cc-inner { background: #0d6efd; }  /* bright blue */
.custom-cluster-medium .cc-inner { background: #d63384; } /* magenta */
.custom-cluster-large .cc-inner { background: #fd7e14; }  /* orange */

/* ---------- Street View Button ---------- */
.leaflet-popup-content a.btn {
  display: inline-block;
  font-size: 0.85rem;
  padding: 4px 8px;
  border-radius: 6px;
  text-decoration: none;
  color: #0d6efd;
  border: 1px solid #0d6efd;
  transition: all 0.2s ease;
}
.leaflet-popup-content a.btn:hover {
  background-color: #0d6efd;
  color: #fff !important;
}

/* Hidden by default; shown only on small screens */
.mobile-only { display: none; }

/* ---------- Autocomplete (Mapbox) ---------- */
.autocomplete-menu {
  position: relative;
}
.autocomplete-menu .option-list {
  position: absolute;
  top: 2px;
  left: 0;
  right: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.92);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  max-height: 220px;
  overflow-y: auto;
}
.autocomplete-menu .option {
  padding: 6px 10px;
  font-size: 0.9rem;
  color: #fff;
  cursor: pointer;
}
.autocomplete-menu .option:hover {
  background: rgba(255,255,255,0.08);
}

/* ---------- Prominent search pin (pulsing) ---------- */
.search-pin {
  position: relative;
  width: 40px;
  height: 40px;
}
.search-pin .pin-dot {
  position: absolute;
  top: 50%; left: 50%;
  width: 20px; height: 20px;
  margin-left: -10px; margin-top: -10px;
  border-radius: 50%;
  background: #0d6efd; /* bootstrap primary blue */
  border: 2px solid #fff;
  box-shadow: 0 0 10px rgba(0,0,0,0.6);
}
.search-pin .pin-pulse {
  position: absolute;
  top: 50%; left: 50%;
  width: 40px; height: 40px;
  margin-left: -20px; margin-top: -20px;
  border-radius: 50%;
  border: 2px solid rgba(13,110,253,0.7);
  animation: pinPulse 1.6s ease-out infinite;
}
@keyframes pinPulse {
  0% { transform: scale(0.6); opacity: 0.8; }
  70% { transform: scale(1.6); opacity: 0.15; }
  100% { transform: scale(2.0); opacity: 0; }
}

.image-source {
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: 0.7rem;
  opacity: 0.6;
  z-index: 3;
  pointer-events: none; /* ensure it doesn’t block clicks */
}
.image-source:hover {
  opacity: 0.9;
}

/* ---------- Figure Overlay (Full-page Preview) ---------- */
.figure-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: none; /* toggled to flex when open */
  align-items: center;
  justify-content: center;
  z-index: 4000; /* above Leaflet popups */
}
.figure-overlay.open { display: flex; }
.figure-content {
  position: relative;
  max-width: 92vw;
  max-height: 92vh;
  box-shadow: 0 12px 30px rgba(0,0,0,0.5);
  border-radius: 10px;
  overflow: hidden;
}
.figure-content img {
  display: block;
  max-width: 92vw;
  max-height: 92vh;
  width: auto;
  height: auto;
  background: #111;
}
.figure-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  font-size: 28px;
  line-height: 1;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
}
.figure-close:hover { background: rgba(0,0,0,0.8); }

/* Extra small popup buttons */
.btn-tiny {
  font-size: 0.72rem !important;
  padding: 2px 6px !important;
  border-radius: 6px !important;
}

/* ---------- Legend control ---------- */
.legend {
  background: rgba(255, 255, 255, 0.92);
  color: #222;
  padding: 8px 10px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  font-size: 12px;
  line-height: 1.3;
}
.legend .legend-title {
  font-weight: 600;
  margin-bottom: 6px;
}
.legend .legend-row { margin: 2px 0; }
.legend .legend-key {
  display: inline-block;
  width: 16px;
  height: 12px;
  margin-right: 20px;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.15);
  vertical-align: -2px;
}

/* Nudge legend up ~10% from bottom when in the bottom area */
.leaflet-bottom .legend {
  margin-bottom: 20vh; /* ~20% up from page base */
}

/* Hide legend on smaller devices */
@media (max-width: 768px) {
  .legend { display: none !important; }
}

/* Hide base layer toggle on smaller screens to reduce clutter */
@media (max-width: 768px) {
  .leaflet-control-layers {
    display: none !important;
  }
}
