/*
 * Always set the map height explicitly to define the size of the div element
 * that contains the map.
 */

/* Map container layout */
.map-container {
  display: grid;
  grid-template-columns: 1fr 350px;
  gap: var(--space-8);
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

#sites {
  position: relative;
}

/* Fullscreen styles for the sites container */
#sites:fullscreen,
#sites:-webkit-full-screen,
#sites:-moz-full-screen,
#sites:-ms-fullscreen {
  width: 100vw;
  height: 100vh;
  background: white;
}

#sites:fullscreen #map,
#sites:-webkit-full-screen #map,
#sites:-moz-full-screen #map,
#sites:-ms-fullscreen #map {
  width: 100%;
  height: 100%;
  border-radius: 0;
}

@media (max-width: 1024px) {
  .map-container {
    grid-template-columns: 1fr;
    gap: var(--space-6);
  }
}

#map {
  width: 100%;
  height: 750px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}

@media (max-width: 768px) {
  #map {
    height: 500px;
  }
}

/* Site list sidebar */
.sites-sidebar {
  background: white;
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  height: 750px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
}

@media (max-width: 768px) {
  .sites-sidebar {
    height: 400px;
  }
}

.sites-sidebar h2 {
  margin-bottom: var(--space-6);
  color: var(--site-primary-b-dark);
  font-family: 'Controwell Script', cursive;
  font-size: 1.8rem;
  font-weight: normal;
  border-bottom: 2px solid #e5e7eb;
  padding-bottom: var(--space-2);
  flex-shrink: 0;
}

.sites-sidebar ol {
  list-style: none;
  padding: 2px var(--space-2) 0 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
}

/* Custom scrollbar styling */
.sites-sidebar ol::-webkit-scrollbar {
  width: 6px;
}

.sites-sidebar ol::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 3px;
}

.sites-sidebar ol::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.sites-sidebar ol::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.site-list-item {
  padding: 1rem;
  margin-bottom: 0.75rem;
  background: #f9fafb;
  border-radius: 0.75rem;
  border: 1px solid #e5e7eb;
  cursor: pointer;
  transition: all 0.2s ease;
}

/* Hover state for sidebar items - lighter background */
.site-list-item:hover {
  background: var(--site-highlight-background);
  border-color: var(--site-primary-b);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(79, 49, 125, 0.2);
}

/* Highlight effect for sidebar items when triggered by map marker hover or click events */
/* This should be darker than :hover and must come after to override */
.site-list-item.highlighted,
.site-list-item.highlighted:hover {
  background: var(--mhd-light-lighter);
  border-color: var(--site-primary-b);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(79, 49, 125, 0.2);
}

.site-list-item:active {
  background: var(--mhd-light-lighter);
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(79, 49, 125, 0.15);
}

.site-list-item h4 {
  margin: 0 0 0.5rem 0;
  color: #1f2937;
  font-size: 1.3rem;
  transition: color 0.2s ease;
}

.site-list-item:hover h4 {
  color: var(--site-primary-b-dark);
}

.site-list-item p {
  margin: 0;
  color: var(--site-secondary-text);
  font-size: 0.9rem;
}

.site-list-item .architectural-style {
  color: var(--site-secondary-text);
  font-size: 0.9rem;
}

/* HTML marker styles */
.marker-tag {
  background: linear-gradient(135deg, var(--site-primary-a) 0%, var(--site-primary-a-light) 50%, var(--site-primary-a) 100%);
  border-radius: 0.75rem;
  color: var(--site-primary-b);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  position: absolute;
  box-shadow: 0 4px 12px rgba(255, 185, 32, 0.3);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  display: inline-block;
  min-width: fit-content;
  width: auto;
  z-index: 1000;
}

.marker-tag:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(255, 185, 32, 0.4);
}

/* Default bubble pointer (bottom center) */
.marker-tag::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, 0);
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid var(--site-primary-b);
}

/* Bubble positioned to the right of icon */
.marker-tag.bubble-right::after {
  left: 0;
  top: 50%;
  transform: translate(-100%, -50%);
  border-left: 8px solid var(--site-primary-b);
  border-right: none;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}

/* Bubble positioned to the left of icon */
.marker-tag.bubble-left::after {
  right: 0;
  left: auto;
  top: 50%;
  transform: translate(100%, -50%);
  border-right: 8px solid var(--site-primary-b);
  border-left: none;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}

/* Custom map markers */
.custom-marker {
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.custom-marker:hover {
  transform: scale(1.1);
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.4));
}

.custom-marker .house-icon {
  transition: all 0.2s ease;
}

.custom-marker:hover .house-icon {
  transform: scale(1.1);
}

/* Map-specific Modal Styles */
.site-modal-map-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 750px;
  /* Match map height exactly */
  z-index: 1000;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
  border-radius: 1rem;
  /* Match map border-radius */
  box-sizing: border-box;
}

/* Fullscreen Modal Styles */
.site-modal-map-overlay.fullscreen-modal {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background-color: rgba(0, 0, 0, 0.9);
}

/* When the modal itself is fullscreen */
.site-modal-map-overlay:fullscreen,
.site-modal-map-overlay:-webkit-full-screen,
.site-modal-map-overlay:-moz-full-screen,
.site-modal-map-overlay:-ms-fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  padding: 2rem;
  align-items: center;
  justify-content: center;
}

/* Adjust modal content when modal is fullscreen */
.site-modal-map-overlay:fullscreen .modal-content-map,
.site-modal-map-overlay:-webkit-full-screen .modal-content-map,
.site-modal-map-overlay:-moz-full-screen .modal-content-map,
.site-modal-map-overlay:-ms-fullscreen .modal-content-map {
  width: 90vw;
  height: 90vh;
  max-width: 1200px;
  max-height: 900px;
}

.modal-backdrop-map {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  border-radius: 1rem;
}

/* Ensure backdrop doesn't interfere in fullscreen mode */
.site-modal-map-overlay.fullscreen-modal .modal-backdrop-map {
  border-radius: 0;
  background: rgba(0, 0, 0, 0.85);
}

.modal-content-map {
  position: relative;
  background: white;
  border-radius: 1rem;
  width: 100%;
  height: 100%;
  overflow: hidden;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
  animation: modalSlideIn 0.3s ease-out;
  display: flex;
  flex-direction: column;
}

/* Fullscreen Modal Content */
.site-modal-map-overlay.fullscreen-modal .modal-content-map {
  width: 90vw;
  height: 90vh;
  max-width: 1200px;
  max-height: 900px;
}

/* Original Modal Styles (for backward compatibility) */
.site-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  box-sizing: border-box;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: white;
  border-radius: 1rem;
  max-width: 900px;
  max-height: 90vh;
  width: 100%;
  overflow: hidden;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
  animation: modalSlideIn 0.3s ease-out;
  margin: auto;
  display: flex;
  flex-direction: column;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-50px) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-popover);
}

.modal-close {
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid rgba(30, 58, 138, 0.1);
  border-radius: var(--radius-full);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--site-primary-b);
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-md);
}

.modal-close:hover {
  background: var(--site-primary-b);
  color: white;
  border-color: var(--site-primary-b);
  transform: scale(1.1) rotate(90deg);
  box-shadow: var(--shadow-lg);
}

.modal-close i {
  font-size: 1.25rem;
}

.modal-body {
  overflow-y: auto;
  flex: 1;
  padding: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

/* Loading and Error States */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem;
  font-size: 1.2rem;
  color: #6b7280;
}

.loading-spinner i {
  margin-right: 0.75rem;
  font-size: 1.5rem;
}

.error-message {
  padding: 4rem;
  text-align: center;
  color: #dc2626;
  font-size: 1.1rem;
}

/* Modal Site Content */
.site-modal-detail {
  padding: 0;
}

.modal-site-header {
  position: sticky;
  top: 0;
  background: rgba(255, 251, 235, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-bottom: 2px solid var(--site-primary-a);
  box-shadow: var(--shadow-md);
  color: var(--site-primary-b-dark);
  padding: var(--space-2) var(--space-10) var(--space-2) var(--space-16);
  margin: -1px -1px var(--space-6) -1px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: var(--z-sticky);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  position: relative;
}

.modal-close-button {
  position: absolute;
  top: 0.75rem;
  left: var(--space-4);
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid rgba(30, 58, 138, 0.1);
  font-size: 1.5rem;
  color: var(--site-primary-b-dark);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-full);
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 20;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.modal-close-button:hover {
  background: var(--site-primary-b);
  color: white;
  border-color: var(--site-primary-b);
  transform: scale(1.1);
  box-shadow: var(--shadow-md);
}

.modal-close-button span {
  line-height: 1;
  font-weight: normal;
}

.modal-site-header-left {
  flex: 1;
  text-align: left;
  margin-left: 0;
  margin-top: 0.15rem;
}

.modal-site-header h2 {
  margin: 0 0 0.15rem 0;
  font-family: 'Controwell Script', cursive;
  font-size: 1.8rem;
  font-weight: normal;
  color: var(--site-primary-b-dark);
  line-height: 1.1;
}

.modal-site-style {
  font-size: 1.1rem;
  color: var(--site-primary-b);
  font-weight: 500;
  margin: 0;
  padding-left: 2rem;
  opacity: 0.9;
  align-self: flex-end;
}

.modal-site-header-details {
  display: flex;
  flex-direction: column;
  text-align: right;
  gap: 0.2rem;
  margin-right: 0;
  margin-top: 0;
  min-width: 200px;
}

.modal-site-address {
  font-size: 1.4rem;
  opacity: 0.9;
  margin: 0;
  color: var(--site-primary-b-dark);
  font-family: 'Controwell Script', cursive;
  font-weight: 500;
}

.modal-site-year {
  font-size: 1.1rem;
  color: var(--site-primary-b);
  font-weight: 500;
  margin: 0;
  opacity: 0.9;
}

.modal-site-content {
  padding: var(--space-8);
  flex: 1;
  overflow-y: auto;
  /* Smooth scrolling */
  scroll-behavior: smooth;
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--site-primary-a) #f1f5f9;
}

.modal-site-content::-webkit-scrollbar {
  width: 8px;
}

.modal-site-content::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: var(--radius-sm);
}

.modal-site-content::-webkit-scrollbar-thumb {
  background: var(--site-primary-a);
  border-radius: var(--radius-sm);
}

.modal-site-content::-webkit-scrollbar-thumb:hover {
  background: var(--site-primary-b);
}

.modal-content-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-8);
  height: 100%;
}

.modal-main-content {
  overflow-y: auto;
}

.modal-sidebar-content {
  overflow-y: auto;
}

/* Street gallery styling for modal context */
.modal-site-content .image-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  width: 100%;
  height: auto;
  overflow: hidden;
  background: #f3f4f6;
  margin-bottom: 2rem;
}

.modal-site-content .gallery-image-link {
  flex: 1 1 calc(33.333% - 6px);
  max-width: calc(33.333% - 6px);
  min-height: 250px;
  display: flex;
  align-items: stretch;
  position: relative;
  text-decoration: none;
  transition: transform 0.3s ease;
  border: 3px solid white;
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* When 3 or fewer images, let them expand to fill space */
.modal-site-content .image-gallery .gallery-image-link:first-child:nth-last-child(1),
.modal-site-content .image-gallery .gallery-image-link:first-child:nth-last-child(2),
.modal-site-content .image-gallery .gallery-image-link:first-child:nth-last-child(2) ~ .gallery-image-link,
.modal-site-content .image-gallery .gallery-image-link:first-child:nth-last-child(3),
.modal-site-content .image-gallery .gallery-image-link:first-child:nth-last-child(3) ~ .gallery-image-link {
  max-width: none;
}

/* When exactly 4 images, show 2x2 grid */
.modal-site-content .image-gallery .gallery-image-link:first-child:nth-last-child(4),
.modal-site-content .image-gallery .gallery-image-link:first-child:nth-last-child(4) ~ .gallery-image-link {
  flex: 1 1 calc(50% - 5px);
  max-width: calc(50% - 5px);
}

.modal-site-content .gallery-image-link:hover {
  transform: scale(1.05);
}

.modal-site-content .gallery-image-link::after {
  content: "🔗";
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal-site-content .gallery-image-link:hover::after {
  opacity: 1;
}

.modal-site-content .gallery-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Legacy modal image gallery for fallback */
.modal-image-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 2rem;
  justify-content: center;
}

.modal-gallery-item {
  flex: 0 0 auto;
  width: 250px;
}

.modal-gallery-item.featured {
  width: 100%;
  max-width: 500px;
}

.modal-gallery-image {
  width: 100%;
  height: 400px;
  object-fit: cover;
  border-radius: 0.75rem;
  cursor: pointer;
  transition: transform 0.2s ease;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  display: block;
}

.modal-gallery-item.featured .modal-gallery-image {
  height: 360px;
  max-width: 500px;
  width: 100%;
}

.modal-gallery-image:hover {
  transform: scale(1.02);
}

.modal-site-description {
  margin-bottom: 2rem;
}

.modal-site-description h4,
.modal-site-details h4 {
  color: #1f2937;
  margin-bottom: 1rem;
  font-family: 'Controwell Script', cursive;
  font-size: 1.5rem;
  font-weight: normal;
}

.modal-site-description p {
  color: #4b5563;
  line-height: 1.7;
}

.description-content {
  margin: 0;
}

.description-paragraph {
  color: #4b5563;
  line-height: 1.7;
  margin: 0 0 1rem 0;
  text-indent: 2rem;
  /* Add paragraph indentation */
}

.description-paragraph:last-child {
  margin-bottom: 0;
}

.modal-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}

.coordinates {
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.9rem;
  background: rgba(0, 0, 0, 0.05);
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  color: var(--site-primary-b-dark);
}

.modal-detail-item {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  padding: 0.75rem;
  background: #f9fafb;
  border-radius: 0.5rem;
}

.modal-detail-label {
  font-weight: 600;
  color: #374151;
}

.modal-detail-value {
  color: #6b7280;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .site-modal {
    padding: 1rem;
    align-items: flex-start;
    padding-top: 2rem;
  }

  .modal-content {
    max-height: 95vh;
    margin-top: 0;
  }

  .modal-site-header {
    padding: 1rem 1.5rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .modal-site-header h2 {
    font-size: 1.8rem;
  }

  .modal-site-header-left {
    margin-left: 0;
    text-align: center;
  }

  .modal-site-header-details {
    text-align: center;
    margin-right: 0;
    min-width: auto;
  }

  .modal-site-style {
    font-size: 0.95rem;
  }

  .modal-site-year {
    font-size: 0.95rem;
  }

  .modal-site-address {
    font-size: 1.3rem;
  }

  .modal-site-content {
    padding: 1.5rem;
  }

  .modal-image-gallery {
    justify-content: center;
  }

  .modal-gallery-item {
    width: 100%;
    max-width: 300px;
  }

  .modal-detail-item {
    grid-template-columns: 1fr;
  }

  /* Map modal responsive */
  .site-modal-map-overlay {
    height: 500px;
    /* Match mobile map height exactly */
    padding: 0.5rem;
  }

  .modal-content-map {
    max-width: 100%;
    max-height: 95%;
  }

  /* Fullscreen modal responsive */
  .site-modal-map-overlay.fullscreen-modal {
    padding: 1rem;
  }

  .site-modal-map-overlay.fullscreen-modal .modal-content-map {
    width: 95vw;
    height: 95vh;
    max-width: none;
  }

  .modal-content-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .modal-image-gallery {
    justify-content: center;
  }

  .modal-gallery-item.featured .modal-gallery-image {
    height: 300px;
    max-width: 100%;
  }

  .modal-site-content .image-gallery {
    gap: 4px;
  }

  .modal-site-content .gallery-image-link {
    flex: 0 0 calc(50% - 5px);
    min-height: 180px;
  }
}

/* Animation Keyframes */
@keyframes backgroundShift {

  0%,
  100% {
    background-position: center, 0 0;
  }

  50% {
    background-position: center, -60px -30px;
  }
}

@keyframes gradientFloat {
  0% {
    background-position: 30% 70%, 70% 30%, 90% 80%;
  }

  100% {
    background-position: 70% 30%, 30% 70%, 10% 20%;
  }
}

@keyframes titleShimmer {

  0%,
  100% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }
}

@keyframes titleFloat {

  0%,
  100% {
    transform: translateY(0px) scale(1);
  }

  50% {
    transform: translateY(-3px) scale(1.02);
  }
}
