/**
 * Search Autocomplete Styles
 */

.search-autocomplete-wrapper {
  position: relative;
}

.search-autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.2s ease;
  z-index: 9999;
  margin-top: 8px;
}

.search-autocomplete-dropdown.open {
  max-height: 480px;
  overflow-y: auto;
  overflow-x: visible;
  opacity: 1;
  transform: translateY(0);
  padding-top: 100px;
}

/* Reduce padding when only showing loading/empty state */
.search-autocomplete-dropdown.open:has(.search-autocomplete-loading),
.search-autocomplete-dropdown.open:has(.search-autocomplete-empty) {
  padding-top: 0;
}

/* Scrollbar styling */
.search-autocomplete-dropdown::-webkit-scrollbar {
  width: 8px;
}

.search-autocomplete-dropdown::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.search-autocomplete-dropdown::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

.search-autocomplete-dropdown::-webkit-scrollbar-thumb:hover {
  background: #555;
}

.search-autocomplete-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.search-autocomplete-item {
  cursor: pointer;
  transition: background-color 0.15s ease;
  border-bottom: 1px solid #f0f0f0;
}

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

.search-autocomplete-item:hover,
.search-autocomplete-item.selected {
  background-color: #f9f9f9;
}

.autocomplete-item-content {
  display: flex;
  align-items: flex-start;
  padding: 16px;
  gap: 16px;
}

.autocomplete-item-image {
  flex-shrink: 0;
  width: 100px;
  height: 100px;
  border-radius: 4px;
  overflow: hidden;
  background: #f0f0f0;
}

.autocomplete-item-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.autocomplete-item-text {
  flex: 1;
  min-width: 0;
}

.autocomplete-item-title {
  font-family: "Fabrikat Mono Bold", "Arial", "Helvetica", sans-serif;
  font-size: 18px;
  font-weight: 700;
  line-height: 120%;
  color: #000;
  margin-bottom: 8px;
  text-transform: uppercase;
}

/* Highlight matched text */
.autocomplete-item-title mark,
.autocomplete-item-title em {
  background-color: #fff9c4;
  font-style: normal;
  font-weight: 900;
  padding: 0 2px;
}

.autocomplete-item-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.autocomplete-item-type {
  font-family: "Fabrikat Mono", "Arial", "Helvetica", sans-serif;
  font-size: 13px;
  font-weight: 400;
  color: #5c5c5c;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.autocomplete-item-excerpt {
  font-family: "Archivo", "Times New Roman", serif;
  font-size: 15px;
  font-weight: 400;
  color: #676767;
  line-height: 150%;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Recipe type styling */
.search-autocomplete-item.recipe .autocomplete-item-type {
  color: #2e7d32;
}

/* Loading state */
.search-autocomplete-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 10px;
  color: #5c5c5c;
  font-family: "Fabrikat Mono", "Arial", "Helvetica", sans-serif;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #e0e0e0;
  border-top-color: #1c1b1f;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* Empty state */
.search-autocomplete-empty {
  padding: 20px;
  text-align: center;
  color: #5c5c5c;
  font-family: "Fabrikat Mono", "Arial", "Helvetica", sans-serif;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* View all results link */
.search-autocomplete-view-all {
  border-top: 2px solid #e0e0e0;
  background: #f9f9f9;
}

.view-all-link {
  display: block;
  padding: 12px 16px;
  text-align: center;
  font-family: "Fabrikat Mono Bold", "Arial", "Helvetica", sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: #000;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: background-color 0.15s ease;
}

.view-all-link:hover {
  background-color: #f0f0f0;
  color: #000;
}

/* Mobile optimizations */
@media screen and (max-width: 768px) {
  .search-autocomplete-dropdown.open {
    max-height: 360px;
    padding-top: 20px;
  }
  
  /* Also reduce padding for loading state on mobile */
  .search-autocomplete-dropdown.open:has(.search-autocomplete-loading),
  .search-autocomplete-dropdown.open:has(.search-autocomplete-empty) {
    padding-top: 0;
  }

  .autocomplete-item-content {
    padding: 10px 12px;
    gap: 10px;
  }

  .autocomplete-item-image {
    width: 50px;
    height: 50px;
  }

  .autocomplete-item-title {
    font-size: 14px;
  }

  .autocomplete-item-excerpt {
    font-size: 12px;
  }
}

/* Integration with existing search form styles */
.search-input {
  position: relative;
}

.search-input .search-autocomplete-wrapper {
  flex: 1;
  width: 100%;
  position: relative;
}

.search-input .search-autocomplete-wrapper input[type="text"] {
  width: 100%;
}

.search-input .search-autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: auto;
  width: 100%;
  z-index: 9999;
}

/* Override for search page - full width dropdown */
.searchform .search-input .search-autocomplete-dropdown {
  left: 0;
  right: 0;
  width: calc(100% + 32px); /* Account for search icon width */
  margin-left: -32px; /* Offset back to align with input start */
}

/* Ensure dropdown appears above other elements */
.search-section-header__form-container {
  position: relative;
  z-index: 100;
  overflow: visible;
}

.search-form {
  position: relative;
  z-index: 100;
  overflow: visible;
}

/* Adjust for search page layout */
.search-section .search-autocomplete-dropdown {
  border-radius: 4px;
  border: 1px solid #e0e0e0;
}

/* Make sure the search input wrapper has proper stacking */
.searchform {
  position: relative;
  z-index: 100;
  overflow: visible;
}

/* Ensure autocomplete works with the search page filters */
.search-section-header {
  position: relative;
  z-index: 50;
  overflow: visible;
}
}
