/**
 * Custom styles for RD ContentMap popups and filters
 */

/* Custom Popup Styles */
:root {
  --rd-popup-width: 256px; /* Default width, can be overridden */
  --rd-popup-mobile-width: 90%;
}

/* Main popup container - applies to both old and dynamic maps */
.rd-content-map .mapboxgl-popup,
.rd-dynamic-map .mapboxgl-popup {
  --popup-width: var(--rd-popup-width, 300px);
  max-width: var(--popup-width);
  width: auto;
}

/* Popup content wrapper - applies to both old and dynamic maps */
.rd-content-map .mapboxgl-popup-content,
.rd-dynamic-map .mapboxgl-popup-content {
  padding: 0;
  border-radius: 8px;
  overflow: visible;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  width: var(--popup-width);
  max-width: 100%;
  box-sizing: border-box;
}

/* Popup content container */
.rd-popup-container {
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  border-radius: 8px;
}

/* Mobile-specific popup styles */
@media (max-width: 768px) {
  .rd-content-map .mapboxgl-popup,
  .rd-dynamic-map .mapboxgl-popup {
    max-width: var(--rd-popup-mobile-width, 90%);
    width: auto;
  }

  .rd-content-map .mapboxgl-popup-content,
  .rd-dynamic-map .mapboxgl-popup-content {
    width: 100%;
    max-width: 100%;
  }

  .rd-popup-image {
    min-height: 150px;
  }
}

.mapboxgl-popup-content {
  padding: 0 !important;
  border-radius: 8px !important;
  overflow: visible !important;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15) !important;
}

/* New Popup Layout */
.rd-map-popup {
  position: relative;
  width: 100%;
}

.rd-popup-container {
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* 1. Image on top */
.rd-popup-image {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3; /* 4:3 aspect ratio */
  overflow: hidden;
  background: #f5f5f5; /* Fallback background */
}

.rd-popup-image .rd-carousel-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.rd-popup-image .rd-carousel-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  /* Slight zoom to crop out letterboxing from 16:9 thumbnails in 4:3 container */
  transform: scale(1.1);
}

/* 2. Title */
.rd-popup-title {
  padding: 12px 12px 8px;
}

.rd-popup-title h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
  color: #333;
}

/* 3. Content/Excerpt */
.rd-popup-content {
  padding: 0 12px 12px;
}

.rd-popup-excerpt {
  font-size: 14px;
  line-height: 1.4;
  color: #555;
  margin: 0;
}

/* 4. Footer with more link and navigate */
.rd-popup-footer {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  gap: 12px;
  position: absolute;
  width: 100%;
  bottom: 0;
  z-index: 2;
}

/* Post type badge as full-width top bar */
.rd-popup-type-badge {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: #fff;
  padding: 6px 10px;
  min-height: 28px; /* Fixed height for consistent layout across post types */
  box-sizing: border-box;
  background-color: rgba(82, 197, 255, 0.3);
  z-index: 5;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.rd-popup-type-badge > div {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rd-popup-type-icon {
  width: 14px;
  height: 14px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  display: inline-block;
}

/* Navigation bar below the type badge - DEPRECATED, now in footer */
.rd-popup-nav-bar {
  display: none;
}

/* Custom close button styling */
.rd-popup-nav-button {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 0 12px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  color: white;
  background-color: rgba(82, 197, 255, 0.9) !important;
  font-size: 14px;
  gap: 8px;
}

.rd-popup-nav-button .rd-popup-nav-icon {
  width: 20px;
  height: 20px;
  color: white;
  background-image: url("data:image/svg+xml,%3Csvg width='64' height='64' viewBox='0 0 64 64' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='32' cy='32' r='30' stroke='currentColor' stroke-width='2' fill='none'/%3E%3Cpath d='M32 18 L42 42 L32 32 L22 42 Z' fill='currentColor'/%3E%3Ccircle cx='32' cy='32' r='2' fill='currentColor'/%3E%3C/svg%3E");
  background-image: url("data:image/svg+xml,%3Csvg width='64' height='64' viewBox='0 0 64 64' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='32' cy='32' r='30' stroke='%23ffffff' stroke-width='2' fill='none'/%3E%3Cpath d='M32 18 L42 42 L32 32 L22 42 Z' fill='%23ffffff'/%3E%3Ccircle cx='32' cy='32' r='2' fill='%23ffffff'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  display: block;
  flex-shrink: 0;
}

/* Hide the text visually but keep it accessible */
.rd-popup-nav-text {
  display: none !important;
}

.rd-popup-close-btn {
  background: none !important;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  opacity: 0.8;
  transition: opacity 0.2s;
}

.rd-popup-close-btn:hover {
  opacity: 1;
}

/* Hide the default Mapbox close button */
.mapboxgl-popup-close-button {
  display: none !important;
}

/* More link */
.rd-popup-more {
  display: flex;
  flex-direction: row;
  width: 100%;
  gap: 8px;
}

/* Dual button layout - spread to opposite corners */
.rd-popup-more-dual {
  justify-content: space-between;
}

/* Single button layout - align to the right */
.rd-popup-more-single {
  justify-content: flex-end;
}

.rd-popup-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 13px;
  text-decoration: none;
  background-color: #52c5ff;
  color: white;
  transition: all 0.2s;
}

.rd-popup-link:hover {
  background-color: #3ab0e9;
  color: white;
}

/* Secondary link (Mentioned in) */
.rd-popup-link-secondary {
  background-color: #f0f0f0;
  color: #555;
}

.rd-popup-link-secondary:hover {
  background-color: #e0e0e0;
  color: #333;
}

/* Navigate dropdown */
.rd-popup-navigate {
  position: relative;
  flex: 0 0 auto;
}

.rd-popup-nav-button {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: white;
  border: none;
  padding: 5px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.2s;
  color: #444;
}

.rd-popup-nav-button:hover {
  background-color: #e0e0e0;
}

.rd-popup-nav-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 5px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  display: none;
  min-width: 150px;
  z-index: 1000;
  overflow: hidden;
}

.rd-popup-nav-dropdown.active {
  display: block;
}

.rd-popup-nav-dropdown a {
  display: block;
  padding: 10px 12px;
  text-decoration: none;
  color: #333;
  font-size: 13px;
  border-bottom: 1px solid #f0f0f0;
}

.rd-popup-nav-dropdown a:last-child {
  border-bottom: none;
}

.rd-popup-nav-dropdown a:hover {
  background-color: #f5f5f5;
}

/* Responsive styles */
@media (min-width: 768px) {
  .mapboxgl-popup {
    max-width: 400px !important;
  }

  /* For wider screens, we could make the image side-by-side with content */
  .rd-popup-image img {
    max-height: 200px;
  }
}

@media (max-width: 767px) {
  .mapboxgl-popup {
    max-width: var(--rd-popup-mobile-width) !important;
  }

  .rd-popup-title h3 {
    font-size: 16px;
  }

  .rd-popup-excerpt {
    font-size: 13px;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    max-height: 4.2em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
  }

  /* Keep footer elements in one line */
  .rd-popup-footer {
    flex-wrap: nowrap;
    justify-content: space-between;
  }

  .rd-popup-type {
    max-width: 25%;
    font-size: 11px;
  }

  .rd-popup-more {
    margin: 0 2px;
  }
}

/* Additional Links Bar - Compact Badges with Dropdown */
.rd-popup-links-bar {
  border-top: 1px solid #e0e0e0;
  padding: 6px 10px;
  background-color: #fafafa;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  overflow: visible;
}

.rd-popup-links-group {
  position: relative;
  display: inline-block;
}

.rd-popup-links-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background-color: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  color: #333;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.rd-popup-links-badge:hover {
  background-color: #f0f7ff;
  border-color: #1a73e8;
  color: #1a73e8;
}

.rd-popup-links-badge:active {
  transform: scale(0.98);
}

.rd-popup-links-dropdown {
  display: none;
  position: fixed;
  background-color: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 200px;
  max-width: 280px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 10000;
}

.rd-popup-links-dropdown.active {
  display: block;
}

.rd-popup-links-dropdown a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: #333;
  text-decoration: none;
  font-size: 12px;
  border-bottom: 1px solid #f0f0f0;
  transition: background-color 0.15s;
}

.rd-popup-links-dropdown a:last-child {
  border-bottom: none;
}

.rd-popup-links-dropdown a:hover {
  background-color: #f0f7ff;
  color: #1a73e8;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .rd-popup-links-bar {
    padding: 5px 8px;
    gap: 5px;
  }

  .rd-popup-links-badge {
    font-size: 10px;
    padding: 3px 8px;
    gap: 3px;
  }

  .rd-popup-links-dropdown {
    min-width: 180px;
    max-width: 240px;
  }

  .rd-popup-links-dropdown a {
    font-size: 11px;
    padding: 7px 10px;
    gap: 6px;
  }
}

/* ==========================================================================
   Favorite Button Styles (Popup Context)
   ========================================================================== */

.rd-fav-location-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 4px;
  position: relative;
  padding: 0;
}

.rd-fav-location-btn:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

.rd-fav-location-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.rd-fav-location-btn--loading {
  opacity: 0.7;
  cursor: wait;
}

.rd-fav-location-btn .rd-fav-icon {
  transition: all 0.2s ease;
  color: #e74c3c;
  stroke: #e74c3c;
}

.rd-fav-location-btn--active .rd-fav-icon {
  fill: #e74c3c;
  stroke: #e74c3c;
}

/* +/- Indicator overlay - centered on heart, no background */
.rd-fav-location-btn .rd-fav-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 10px;
  font-weight: bold;
  color: white;
  text-shadow: 0 0 2px rgba(0,0,0,0.5);
  pointer-events: none;
  line-height: 1;
}

/* Popup-specific favorite button */
.rd-fav-location-btn--popup {
  width: 28px;
  height: 28px;
  margin-left: auto;
  margin-right: 8px;
}

.rd-fav-location-btn--popup .rd-fav-icon {
  width: 20px;
  height: 20px;
  stroke: #e74c3c;
}

.rd-fav-location-btn--popup.rd-fav-location-btn--active .rd-fav-icon {
  fill: #e74c3c;
}
