/* Search Component Styles */

#map-search-input {
  padding-right: 2rem;
  background-color: rgb(var(--surface-rgb) / 90%);
  border: 1px solid rgb(var(--border-rgb) / 30%);
  color: var(--text-primary);
  transition: all 0.2s ease;
  position: relative;
  z-index: 1;
  border-radius: var(--radius-pill);
}

#map-search-input:focus {
  background-color: rgb(var(--surface-rgb) / 100%);
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
  color: var(--text-primary);
}

#map-search-input::placeholder {
  color: var(--text-tertiary);
}

/* Search results dropdown - positioned to avoid clipping */
.search-results-dropdown {
  position: fixed;
  max-height: min(400px, 50vh);
  overflow: hidden auto;
  background-color: rgb(var(--surface-rgb) / 96%);
  border: 1px solid rgb(var(--border-rgb) / 35%);
  border-radius: var(--radius-lg);
  box-shadow:
    0 8px 24px rgb(0 0 0 / 40%),
    0 4px 12px rgb(0 0 0 / 30%);
  z-index: var(--z-dropdown);
  backdrop-filter: blur(var(--blur-subtle));
  animation: slideInDown 0.2s ease-out;
  min-width: 280px;
  margin-top: 0.5rem;
  transition:
    opacity 0.15s ease,
    transform 0.15s ease;
  will-change: transform;
}

/* When dropdown appears above the input */
.search-results-dropdown.above {
  animation: slideInUp 0.2s ease-out;
}

.search-result-item {
  padding: 0.875rem 1.125rem;
  cursor: pointer;
  border-bottom: 1px solid rgb(var(--border-rgb) / 20%);
  transition: all 0.2s ease;
  color: var(--text-primary);
  position: relative;
}

.search-result-item:first-child {
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
}

.search-result-item:last-child {
  border-bottom: none;
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

.search-result-item:hover,
.search-result-item.active {
  background-color: rgb(var(--primary-rgb) / 18%);
  transform: translateX(2px);
}

.search-result-item:focus {
  outline: var(--focus-outline);
  outline-offset: -2px;
  box-shadow: var(--focus-ring);
  z-index: 1;
}

.search-result-title {
  font-weight: 600;
  font-size: var(--font-size-md);
  margin-bottom: 0.35rem;
  color: var(--text-primary);
  line-height: 1.4;
}

.search-result-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  line-clamp: 2;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-result-type {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  font-size: var(--font-size-xs);
  border-radius: var(--radius-pill);
  margin-right: 0.5rem;
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: var(--tracking-wide);
}

.search-result-type.place {
  background-color: rgb(var(--success-rgb) / 22%);
  color: var(--success);
}

.search-result-type.street {
  background-color: rgb(var(--info-rgb) / 22%);
  color: var(--info);
}

.search-result-type.address {
  background-color: rgb(var(--warning-rgb) / 22%);
  color: var(--warning);
}

.search-loading {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--font-size-md);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.search-no-results {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--font-size-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.search-no-results::before {
  content: "\f002";
  font-family: "Font Awesome 6 Free", sans-serif;
  font-weight: 900;
  font-size: var(--font-size-2xl);
  opacity: 0.5;
}

.search-error::before {
  content: "\f071";
  font-family: "Font Awesome 6 Free", sans-serif;
  font-weight: 900;
  font-size: var(--font-size-xl);
}

.search-error {
  padding: 1.5rem;
  text-align: center;
  color: var(--danger);
  font-size: var(--font-size-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

/* Keyboard navigation highlight */
.search-result-item[aria-selected="true"] {
  background-color: rgb(var(--primary-rgb) / 32%);
  outline: var(--focus-outline);
  outline-offset: -2px;
  z-index: 1;
}

/* Loading spinner for search */
.search-loading::before {
  content: "";
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgb(var(--text-rgb) / 28%);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 0.5rem;
  vertical-align: middle;
}

/* Scrollbar styling for dropdown */
.search-results-dropdown::-webkit-scrollbar {
  width: 6px;
}

.search-results-dropdown::-webkit-scrollbar-track {
  background: var(--surface-2);
  border-radius: var(--radius-pill);
}

.search-results-dropdown::-webkit-scrollbar-thumb {
  background: rgb(var(--border-rgb) / 35%);
  border-radius: var(--radius-pill);
}

.search-results-dropdown::-webkit-scrollbar-thumb:hover {
  background: rgb(var(--border-rgb) / 55%);
}

/* Responsive adjustments */
@media (width <= 768px) {
  .search-results-dropdown {
    max-height: min(350px, 40vh);
    min-width: 250px;
  }

  .search-result-item {
    padding: 0.75rem 0.875rem;
  }

  .search-result-title {
    font-size: var(--font-size-sm);
  }

  .search-result-subtitle {
    font-size: var(--font-size-sm);
  }
}

@media (width <= 480px) {
  .search-results-dropdown {
    max-height: min(300px, 35vh);
    left: 0.5rem;
    right: 0.5rem;
    width: calc(100vw - 1rem);
    min-width: unset;
  }

  .search-result-item {
    padding: 0.625rem 0.75rem;
  }
}

/* Dark/Light theme support */
html.light-mode body #map-search-input,
[data-bs-theme="light"] #map-search-input {
  background-color: var(--surface-1);
  border-color: var(--border-color);
  color: var(--text-primary);
}

html.light-mode body #map-search-input:focus,
[data-bs-theme="light"] #map-search-input:focus {
  background-color: var(--surface-1);
  border-color: var(--primary);
  color: var(--text-primary);
  box-shadow: var(--focus-ring);
}

html.light-mode body #map-search-input::placeholder,
[data-bs-theme="light"] #map-search-input::placeholder {
  color: var(--text-tertiary);
}

html.light-mode body .search-results-dropdown,
[data-bs-theme="light"] .search-results-dropdown {
  background-color: var(--surface-1);
  border-color: var(--border-color);
  box-shadow: var(--shadow-md);
}

html.light-mode body .search-result-item,
[data-bs-theme="light"] .search-result-item {
  color: var(--text-primary);
  border-bottom-color: var(--divider-color);
}

html.light-mode body .search-result-item:hover,
html.light-mode body .search-result-item.active,
[data-bs-theme="light"] .search-result-item:hover,
[data-bs-theme="light"] .search-result-item.active {
  background-color: rgb(var(--primary-rgb) / 12%);
}

html.light-mode body .search-result-title,
[data-bs-theme="light"] .search-result-title {
  color: var(--text-primary);
}

html.light-mode body .search-result-subtitle,
[data-bs-theme="light"] .search-result-subtitle {
  color: var(--text-secondary);
}

html.light-mode body .search-loading,
html.light-mode body .search-no-results,
[data-bs-theme="light"] .search-loading,
[data-bs-theme="light"] .search-no-results {
  color: var(--text-secondary);
}

html.light-mode body .search-error,
[data-bs-theme="light"] .search-error {
  color: var(--danger);
}

html.light-mode body .search-results-dropdown::-webkit-scrollbar-track,
[data-bs-theme="light"] .search-results-dropdown::-webkit-scrollbar-track {
  background: var(--surface-2);
}

html.light-mode body .search-results-dropdown::-webkit-scrollbar-thumb,
[data-bs-theme="light"] .search-results-dropdown::-webkit-scrollbar-thumb {
  background: rgb(var(--border-rgb) / 35%);
}

html.light-mode body .search-results-dropdown::-webkit-scrollbar-thumb:hover,
[data-bs-theme="light"] .search-results-dropdown::-webkit-scrollbar-thumb:hover {
  background: rgb(var(--border-rgb) / 55%);
}
