/**
 * Meilisearch Search Results Styles
 * Responsive, modern design for search functionality
 */

/* Search Box Wrapper for Autocomplete */
.search-box-wrapper {
  position: relative;
  flex: 1;
  max-width: 700px;
  width: 100%;
}

/* Autocomplete Dropdown */
.search-autocomplete {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.5rem;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  max-height: 500px;
  overflow-y: auto;
  z-index: 1000;
  animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Autocomplete Results */
.autocomplete-results {
  padding: 0.5rem 0;
}

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid #f0f5fa;
  transition: background 0.2s;
}

.autocomplete-item-image {
  width: 60px;
  height: 60px;
  min-width: 60px;
  background-size: cover;
  background-position: center;
  background-color: #f0f5fa;
  border-radius: 8px;
}

.autocomplete-item:hover {
  background: linear-gradient(135deg, rgba(106, 46, 152, 0.05) 0%, rgba(214, 41, 118, 0.05) 100%);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item-main {
  flex: 1;
}

.autocomplete-item-name {
  font-size: 1rem;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 0.25rem;
}

.autocomplete-item-name mark {
  background: rgba(255, 235, 59, 0.4);
  padding: 0 0.25rem;
  border-radius: 3px;
  font-weight: 700;
}

.autocomplete-item-meta {
  display: flex;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: #64748b;
}

.autocomplete-category {
  background: linear-gradient(135deg, #6a2e98 0%, #d62976 100%);
  color: white;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

.autocomplete-location {
  color: #64748b;
}

.autocomplete-item-rating {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.autocomplete-stars {
  font-size: 0.85rem;
  line-height: 1;
}

.autocomplete-score {
  font-weight: 600;
  color: #1e293b;
  font-size: 0.9rem;
}

/* Autocomplete Footer */
.autocomplete-footer {
  padding: 0.75rem 1rem;
  text-align: center;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  border-radius: 0 0 12px 12px;
}

.autocomplete-footer p {
  margin: 0;
  font-size: 0.85rem;
  color: #64748b;
  font-weight: 500;
}

/* No Results */
.autocomplete-no-results {
  padding: 2rem 1rem;
  text-align: center;
}

.autocomplete-no-results p {
  margin: 0;
  color: #64748b;
  font-size: 0.95rem;
}

/* Search Results Container */
.search-results-container {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 20px;
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Search Results Header */
.search-results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  flex-wrap: wrap;
  gap: 1rem;
}

.search-results-header h2 {
  color: #1e293b;
  font-size: 1.75rem;
  margin: 0;
  font-weight: 700;
}

.search-results-header p {
  color: #64748b;
  margin: 0.5rem 0 0 0;
  font-size: 0.95rem;
}

.clear-search-btn {
  padding: 0.5rem 1.25rem;
  background: linear-gradient(135deg, #6a2e98 0%, #d62976 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.clear-search-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(106, 46, 152, 0.3);
}

/* Search Results Grid */
.search-results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
  margin-bottom: 3rem;
}

/* Loading State */
.search-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(106, 46, 152, 0.1);
  border-top-color: #6a2e98;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.search-loading p {
  color: #64748b;
  font-size: 1.1rem;
  margin: 0;
}

/* Error State */
.search-error {
  background: #fef2f2;
  border: 2px solid #fecaca;
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  margin: 2rem 0;
}

.search-error h3 {
  color: #dc2626;
  margin: 0 0 1rem 0;
  font-size: 1.5rem;
}

.search-error p {
  color: #991b1b;
  margin: 0.5rem 0;
  line-height: 1.6;
}

/* Highlight matching text */
mark {
  background: rgba(255, 235, 59, 0.4);
  padding: 0 0.25rem;
  border-radius: 3px;
  font-weight: 600;
  color: inherit;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  .search-box-wrapper {
    max-width: 100%;
  }

  .search-autocomplete {
    max-height: 400px;
  }

  .autocomplete-item {
    flex-wrap: wrap;
  }

  .autocomplete-item-image {
    width: 50px;
    height: 50px;
    min-width: 50px;
  }

  .autocomplete-item-main {
    flex: 1;
    min-width: 150px;
  }

  .autocomplete-item-rating {
    width: 100%;
    justify-content: flex-start;
    margin-top: 0.5rem;
  }

  .autocomplete-item-meta {
    flex-direction: column;
    gap: 0.25rem;
  }

  .search-results-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .search-results-header h2 {
    font-size: 1.5rem;
  }

  .clear-search-btn {
    width: 100%;
  }

  .search-results-grid {
    grid-template-columns: 1fr;
  }
}

/* Integration with existing listing cards */
.search-results-grid .listing-card {
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Ensure smooth transitions */
.search-results-grid .listing-card:hover {
  transform: translateY(-5px);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Empty state */
.search-results-header:has(+ :empty) {
  margin-bottom: 0;
}

/* Search input focus enhancement */
#search-input:focus,
#location-input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(106, 46, 152, 0.1);
}

/* Accessibility improvements */
.search-results-container:focus-within {
  outline: 2px solid rgba(106, 46, 152, 0.5);
  outline-offset: 4px;
  border-radius: 8px;
}

/* Print styles */
@media print {
  .clear-search-btn,
  .search-loading,
  .search-error {
    display: none;
  }

  .search-results-grid {
    grid-template-columns: 1fr;
  }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
  .search-results-container {
    color: #e2e8f0;
  }

  .search-results-header {
    background: #1e293b;
    border: 1px solid #334155;
  }

  .search-results-header h2 {
    color: #f1f5f9;
  }

  .search-results-header p {
    color: #94a3b8;
  }

  .search-loading p {
    color: #94a3b8;
  }

  mark {
    background: rgba(255, 235, 59, 0.3);
    color: #fef3c7;
  }
}
