/* ===================================
   SEARCH & FILTER ENHANCEMENTS
   =================================== */

/* Search Bar Container */
.search-container {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Animated Search Bar */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 24px;
  padding: 0.5rem 1rem;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.search-bar.expanded {
  background: var(--bg-secondary);
  border-color: var(--accent-primary);
  box-shadow: 0 4px 12px rgba(229, 9, 20, 0.2);
}

.search-bar input {
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  width: 0;
  opacity: 0;
  transition: width 0.3s ease, opacity 0.3s ease;
  padding: 0;
}

.search-bar.expanded input {
  width: 250px;
  opacity: 1;
  padding: 0 0.5rem;
}

.search-bar input::placeholder {
  color: var(--text-tertiary);
}

.search-icon {
  width: 20px;
  height: 20px;
  fill: var(--text-secondary);
  transition: fill 0.2s ease;
  flex-shrink: 0;
}

.search-bar.expanded .search-icon {
  fill: var(--accent-primary);
}

.search-clear {
  width: 20px;
  height: 20px;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.search-bar.has-value .search-clear {
  display: flex;
}

.search-clear:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Search Suggestions */
.search-suggestions {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-height: 400px;
  overflow-y: auto;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.search-suggestions.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.suggestion-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: background 0.2s ease;
  border-bottom: 1px solid var(--border-subtle);
}

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

.suggestion-item:hover {
  background: var(--bg-tertiary);
}

.suggestion-icon {
  width: 16px;
  height: 16px;
  fill: var(--text-tertiary);
  flex-shrink: 0;
}

.suggestion-text {
  flex: 1;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.suggestion-text mark {
  background: var(--accent-primary);
  color: white;
  padding: 0 2px;
  border-radius: 2px;
}

.suggestion-category {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Filter Section */
.filter-section {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 0;
  flex-wrap: wrap;
}

.filter-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Filter Chips */
.filter-chips {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex: 1;
}

.filter-chip {
  padding: 0.5rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}

.filter-chip:hover {
  background: var(--bg-card);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.filter-chip.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: white;
  box-shadow: 0 2px 8px rgba(229, 9, 20, 0.3);
}

.filter-chip-icon {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.filter-chip-remove {
  width: 16px;
  height: 16px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease;
}

.filter-chip.active .filter-chip-remove {
  display: flex;
}

.filter-chip-remove:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Sort Dropdown */
.sort-dropdown {
  position: relative;
}

.sort-button {
  padding: 0.5rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.sort-button:hover {
  background: var(--bg-card);
  border-color: rgba(255, 255, 255, 0.2);
}

.sort-button.active {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.sort-icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.sort-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  overflow: hidden;
}

.sort-menu.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.sort-option {
  padding: 0.75rem 1rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.2s ease;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.sort-option:hover {
  background: var(--bg-tertiary);
}

.sort-option.active {
  color: var(--accent-primary);
  background: rgba(229, 9, 20, 0.1);
}

.sort-option-check {
  width: 16px;
  height: 16px;
  fill: var(--accent-primary);
  opacity: 0;
}

.sort-option.active .sort-option-check {
  opacity: 1;
}

/* Active Filters Display */
.active-filters {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.5rem 0;
}

.active-filter-tag {
  padding: 0.375rem 0.75rem;
  background: rgba(229, 9, 20, 0.1);
  border: 1px solid var(--accent-primary);
  border-radius: 16px;
  font-size: 0.8rem;
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: filter-appear 0.3s ease;
}

@keyframes filter-appear {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.active-filter-remove {
  width: 14px;
  height: 14px;
  background: none;
  border: none;
  color: var(--accent-primary);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease;
}

.active-filter-remove:hover {
  background: rgba(229, 9, 20, 0.2);
}

.clear-all-filters {
  padding: 0.375rem 0.75rem;
  background: none;
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  color: var(--text-tertiary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.clear-all-filters:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* Results Count */
.results-count {
  font-size: 0.9rem;
  color: var(--text-tertiary);
  padding: 0.5rem 0;
}

.results-count strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Loading State for Filters */
.filter-loading {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-tertiary);
  font-size: 0.85rem;
}

.filter-loading .spinner-small {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  .search-bar.expanded input {
    width: 180px;
  }

  .filter-section {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .filter-chips {
    width: 100%;
  }

  .sort-dropdown {
    width: 100%;
  }

  .sort-button {
    width: 100%;
    justify-content: space-between;
  }

  .sort-menu {
    left: 0;
    right: 0;
  }
}

/* Accessibility */
.search-bar:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(229, 9, 20, 0.1);
}

.filter-chip:focus-visible,
.sort-button:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}
