/**
 * Map Search Overlay Styles
 * Theme-aware styling for the map search feature
 */

/* Search Backdrop - Full Viewport Coverage */
.map-search-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1002;
  opacity: 0;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: opacity;
}

.map-search-backdrop:not(.hidden) {
  opacity: 1;
}

.map-search-backdrop.hidden {
  opacity: 0;
}

/* Search Overlay Container - Positioned relative to search toggle or viewport center when collapsed */
.map-search-overlay {
  position: fixed;
  /* top position will be set dynamically by JavaScript */
  right: 4rem; /* Default right-aligned position */
  z-index: 1003;
  width: 320px;
  height: 400px;
  max-width: 90vw;
  pointer-events: auto;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

.map-search-overlay:not(.hidden) {
  transform: translateX(0);
}

.map-search-overlay.hidden {
  transform: translateX(100%);
}

/* Search Container - Glassmorphism Design */
.map-search-container {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 0.75rem; /* Round all four corners */
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.map-search-container:focus-within {
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.15),
    0 4px 12px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* Dark theme - Pure black with purple accents */
html.dark .map-search-container {
  background: rgba(0, 0, 0, 0.95);
  border-color: rgba(147, 51, 234, 0.2); /* Purple accent border */
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* Search Input Wrapper */
.map-search-input-wrapper {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  gap: 12px;
  border-bottom: 1px solid var(--theme-toggle-border, rgba(0,0,0,0.06));
  flex-shrink: 0;
}

html.dark .map-search-input-wrapper {
  border-color: rgba(255, 255, 255, 0.06);
}

/* Search Icon */
.map-search-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: var(--site-text, #666);
  opacity: 0.6;
}

.map-search-icon svg {
  width: 100%;
  height: 100%;
}

/* Search Input */
.map-search-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--site-text, #000);
  font-size: 15px;
  padding: 8px 4px;
  outline: none;
  min-width: 0;
}

.map-search-input::placeholder {
  color: var(--site-text, #666);
  opacity: 0.5;
}

html.dark .map-search-input {
  color: var(--site-text, #fff);
}

html.dark .map-search-input::placeholder {
  color: var(--site-text, #999);
  opacity: 0.5;
}

/* Clear Button */
.map-search-clear {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border: none;
  background: rgba(128, 128, 128, 0.2);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--site-text, #666);
  font-size: 16px;
  line-height: 1;
  transition: background-color 0.15s ease, transform 0.15s ease;
  touch-action: manipulation;
}

.map-search-clear:hover {
  background: rgba(128, 128, 128, 0.3);
  transform: scale(1.1);
}

.map-search-clear.hidden {
  display: none;
}

/* Search Results */
.map-search-results {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  padding: 8px 0;
}

.map-search-results.hidden {
  display: none;
}

.map-search-results::-webkit-scrollbar {
  width: 6px;
}

.map-search-results::-webkit-scrollbar-track {
  background: transparent;
}

.map-search-results::-webkit-scrollbar-thumb {
  background: rgba(128, 128, 128, 0.3);
  border-radius: 3px;
}

/* Result Item */
.search-result-item {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  gap: 12px;
  cursor: pointer;
  transition: background-color 0.12s ease;
  border-bottom: 1px solid rgba(128, 128, 128, 0.1);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item.search-result-highlighted,
.search-result-item.search-result-touched {
  background: rgba(220, 38, 38, 0.08);
}

html.dark .search-result-item:hover,
html.dark .search-result-item.search-result-highlighted {
  background: rgba(220, 38, 38, 0.15);
}

/* Location Icon */
.search-result-location-icon {
  flex-shrink: 0;
  font-size: 16px;
  margin-right: 8px;
  opacity: 0.7;
}

/* Result Text */
.search-result-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-result-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--site-text, #000);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html.dark .search-result-name {
  color: var(--site-text, #fff);
}

.search-result-sub {
  font-size: 12px;
  color: var(--site-text, #666);
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html.dark .search-result-sub {
  color: var(--site-text, #aaa);
}

/* Loading State */
.search-result-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  color: var(--site-text, #666);
  font-size: 14px;
}

.search-loading-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(220, 38, 38, 0.2);
  border-top-color: var(--accent-color, #dc2626);
  border-radius: 50%;
  animation: searchSpin 0.8s linear infinite;
}

@keyframes searchSpin {
  to { transform: rotate(360deg); }
}

/* Error State */
.search-result-error {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  color: #dc2626;
  font-size: 13px;
  text-align: center;
}

/* Empty State */
.search-result-empty {
  padding: 20px;
  text-align: center;
  color: var(--site-text, #666);
  font-size: 13px;
  opacity: 0.8;
}

/* Focus visible styles for keyboard navigation */
.search-result-item:focus-visible {
  outline: 2px solid var(--accent-color, #dc2626);
  outline-offset: -2px;
}

.map-search-input:focus-visible {
  outline: 2px solid var(--accent-color, #dc2626);
  outline-offset: 2px;
}

/* Mobile Responsive with touch target optimization */
@media (max-width: 640px) {
  .map-search-overlay {
    top: calc(50vh - 175px); /* Center 350px drawer in viewport */
    width: 320px;
    max-width: 85vw;
    height: 350px;
  }
  
  .map-search-container {
    border-radius: 0.5rem; /* Round all four corners on tablet */
  }
  
  .map-search-input {
    font-size: 16px; /* Prevent iOS zoom on focus */
    padding: 12px 8px; /* Larger touch target */
  }
  
  /* Minimum 44px touch targets per WCAG 2.1 */
  .search-result-item {
    min-height: 44px;
    padding: 14px 16px;
    touch-action: manipulation; /* Prevent double-tap zoom */
  }
  
  .map-search-clear {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }
  
  /* Increase text size for readability on mobile */
  .search-result-name {
    font-size: 15px;
  }
  
  .search-result-sub {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .map-search-overlay {
    top: calc(50vh - 150px); /* Center 300px drawer in viewport */
    width: 300px;
    max-width: 90vw;
    height: 300px;
  }
  
  .map-search-container {
    border-radius: 0.5rem; /* Round all four corners on mobile */
  }
  
  .search-result-item {
    padding: 12px 16px;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .search-result-item:hover,
  .search-result-item.search-result-highlighted {
    background: rgba(220, 38, 38, 0.2);
    outline: 1px solid var(--accent-color, #dc2626);
  }
  
  .map-search-container {
    border-width: 2px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .search-loading-spinner {
    animation: none;
  }
  
  .search-result-item {
    transition: none;
  }
  
  .map-search-clear {
    transition: none;
  }
}
