/**
 * 999DEX SEARCH, FILTER & SORT - UI COMPONENTS
 *
 * Advanced search, filtering, and sorting interface matching pump.fun
 * Features: Real-time search, category filters, sort options, active badges
 *
 * Version: 1.0.0
 * Date: November 2, 2025
 * Agent: 19 - Search, Filter & Sort Implementation
 */

/* ========================================
   SEARCH BAR
   ======================================== */

.search-bar-container {
  position: relative;
  width: 100%;
  max-width: 600px;
  margin-bottom: var(--spacing-lg);
}

.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 16px;
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}

.search-input {
  width: 100%;
  height: 48px;
  padding: 0 48px 0 48px;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  transition: all var(--transition-normal) var(--ease-out);
}

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

.search-input:focus {
  outline: none;
  border-color: var(--accent-purple);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.search-clear {
  position: absolute;
  right: 12px;
  width: 32px;
  height: 32px;
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast) var(--ease-out);
  z-index: 1;
}

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

.search-input:not(:placeholder-shown) ~ .search-clear {
  display: flex;
}

/* Search Loading Spinner */
.search-loading {
  position: absolute;
  right: 16px;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(139, 92, 246, 0.3);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
  display: none;
}

.search-loading.active {
  display: block;
}

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

/* ========================================
   FILTER & SORT CONTROLS
   ======================================== */

.filter-sort-container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-md);
  align-items: center;
  margin-bottom: var(--spacing-lg);
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  align-items: center;
}

.filter-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  margin-right: var(--spacing-xs);
}

/* ========================================
   FILTER PILLS
   ======================================== */

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: 8px 16px;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-normal) var(--ease-out);
  user-select: none;
  white-space: nowrap;
}

.filter-pill:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-hover);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.filter-pill.active {
  background: var(--accent-purple);
  border-color: var(--accent-purple);
  color: var(--text-primary);
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.3);
}

.filter-pill.active:hover {
  background: #9333ea;
  border-color: #9333ea;
}

.filter-pill-icon {
  width: 14px;
  height: 14px;
  display: none;
}

.filter-pill.active .filter-pill-icon {
  display: block;
}

/* ========================================
   SORT DROPDOWN
   ======================================== */

.sort-dropdown {
  position: relative;
  min-width: 180px;
}

.sort-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-sm);
  width: 100%;
  height: 40px;
  padding: 0 16px;
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-normal) var(--ease-out);
}

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

.sort-button.active {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.sort-button-icon {
  width: 16px;
  height: 16px;
  transition: transform var(--transition-normal) var(--ease-out);
}

.sort-button.active .sort-button-icon {
  transform: rotate(180deg);
}

.sort-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2xl);
  padding: var(--spacing-xs);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--transition-normal) var(--ease-out);
}

.sort-dropdown.active .sort-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.sort-option {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 10px 12px;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast) var(--ease-out);
  width: 100%;
  text-align: left;
}

.sort-option:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.sort-option.active {
  background: rgba(139, 92, 246, 0.15);
  color: var(--accent-purple);
  font-weight: var(--font-weight-semibold);
}

.sort-option-icon {
  width: 16px;
  height: 16px;
  opacity: 0;
}

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

/* ========================================
   ACTIVE FILTERS BADGES
   ======================================== */

.active-filters-container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  align-items: center;
  margin-bottom: var(--spacing-lg);
  padding: var(--spacing-md);
  background: rgba(139, 92, 246, 0.05);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: var(--radius-lg);
  animation: slideDown var(--transition-normal) var(--ease-out);
}

.active-filters-container.hidden {
  display: none;
}

.active-filters-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
}

.active-filter-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: 6px 12px;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--accent-purple);
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: var(--radius-full);
  animation: scaleIn var(--transition-fast) var(--ease-out);
}

.active-filter-remove {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--accent-purple);
  cursor: pointer;
  padding: 0;
  transition: transform var(--transition-fast) var(--ease-out);
}

.active-filter-remove:hover {
  transform: scale(1.2);
}

.clear-all-filters {
  padding: 6px 12px;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast) var(--ease-out);
}

.clear-all-filters:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

/* ========================================
   RESULT COUNT
   ======================================== */

.result-count {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-bottom: var(--spacing-md);
}

.result-count-number {
  font-weight: var(--font-weight-semibold);
  color: var(--accent-purple);
}

/* ========================================
   NO RESULTS STATE
   ======================================== */

.no-results-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-4xl) var(--spacing-lg);
  text-align: center;
  animation: fadeIn var(--transition-normal) var(--ease-out);
}

.no-results-icon {
  width: 64px;
  height: 64px;
  margin-bottom: var(--spacing-lg);
  color: var(--text-muted);
  opacity: 0.5;
}

.no-results-title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin: 0 0 var(--spacing-sm) 0;
}

.no-results-message {
  font-size: var(--font-size-base);
  color: var(--text-secondary);
  margin: 0 0 var(--spacing-lg) 0;
  max-width: 400px;
}

.no-results-suggestions {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  text-align: left;
  margin-top: var(--spacing-md);
}

.no-results-suggestion {
  font-size: var(--font-size-sm);
  color: var(--text-tertiary);
}

.no-results-suggestion::before {
  content: '•';
  margin-right: var(--spacing-sm);
  color: var(--accent-purple);
}

/* ========================================
   ADVANCED FILTERS (EXPANDABLE)
   ======================================== */

.advanced-filters {
  margin-bottom: var(--spacing-lg);
}

.advanced-filters-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: 8px 16px;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-normal) var(--ease-out);
}

.advanced-filters-toggle:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.advanced-filters-toggle-icon {
  width: 16px;
  height: 16px;
  transition: transform var(--transition-normal) var(--ease-out);
}

.advanced-filters-toggle.active .advanced-filters-toggle-icon {
  transform: rotate(180deg);
}

.advanced-filters-panel {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: all var(--transition-normal) var(--ease-out);
}

.advanced-filters-toggle.active ~ .advanced-filters-panel {
  max-height: 500px;
  opacity: 1;
  margin-top: var(--spacing-md);
}

.advanced-filters-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--spacing-lg);
  padding: var(--spacing-lg);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
}

.advanced-filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.advanced-filter-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

/* Range Slider */
.range-slider {
  width: 100%;
}

.range-slider input[type="range"] {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.range-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent-purple);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--bg-primary);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.range-slider input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent-purple);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--bg-primary);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.range-value {
  margin-top: var(--spacing-xs);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  text-align: center;
}

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
  .search-bar-container {
    max-width: 100%;
  }

  .filter-sort-container {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-group {
    width: 100%;
  }

  .filter-pills {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .filter-pills::-webkit-scrollbar {
    display: none;
  }

  .sort-dropdown {
    width: 100%;
  }

  .sort-dropdown-menu {
    left: 0;
    right: 0;
    min-width: 100%;
  }

  .advanced-filters-content {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .search-input {
    height: 44px;
    padding: 0 44px 0 44px;
  }

  .filter-pill {
    padding: 6px 12px;
    font-size: var(--font-size-xs);
  }

  .active-filters-container {
    padding: var(--spacing-sm);
  }

  .result-count {
    font-size: var(--font-size-xs);
  }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

/* Focus visible styles */
.search-input:focus-visible,
.filter-pill:focus-visible,
.sort-button:focus-visible,
.sort-option:focus-visible,
.advanced-filters-toggle:focus-visible {
  outline: 2px solid var(--accent-purple);
  outline-offset: 2px;
}

/* Screen reader only text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .search-input,
  .filter-pill,
  .sort-button,
  .sort-dropdown-menu,
  .active-filters-container,
  .advanced-filters-panel {
    transition: none;
  }

  .search-loading {
    animation: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .filter-pill.active {
    border-width: 2px;
  }

  .search-input:focus {
    border-width: 2px;
  }
}
