/* ==============================================
   Universal Search Bar
   Integrated into site header
   ============================================== */

/* Search Container - Standalone (legacy, for pages without header) */
.search-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  padding: var(--space-sm) var(--space-md);
  display: none; /* Hidden by default, header search is used instead */
}

.search-bar-inner {
  max-width: 800px;
  margin: 0 auto;
  position: relative;
}

/* Header-integrated search wrapper */
.header-search-wrapper {
  position: relative;
  width: 100%;
}

.header-search-wrapper .header-search-input {
  width: 100%;
  padding: var(--space-sm) var(--space-md) var(--space-sm) 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--font-sm);
  transition: all var(--transition-fast);
}

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

.header-search-wrapper .header-search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.header-search-wrapper .header-search-icon {
  position: absolute;
  left: var(--space-sm);
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.header-search-wrapper .header-search-shortcut {
  position: absolute;
  right: var(--space-sm);
  top: 50%;
  transform: translateY(-50%);
  padding: 2px 6px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  pointer-events: none;
}

.header-search-wrapper .search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: var(--space-xs);
  z-index: 400;
}

/* Search Input */
.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

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

.search-input {
  width: 100%;
  padding: var(--space-sm) var(--space-sm) var(--space-sm) 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--font-base);
  transition: all var(--transition-fast);
}

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

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Keyboard shortcut hint */
.search-shortcut {
  position: absolute;
  right: var(--space-sm);
  padding: 2px 6px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  pointer-events: none;
}

/* Search Results Dropdown */
.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: var(--space-xs);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 400px;
  overflow-y: auto;
  display: none;
  z-index: 101;
}

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

/* No results message */
.search-no-results {
  padding: var(--space-lg);
  text-align: center;
  color: var(--text-muted);
}

/* Result categories */
.search-category {
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-hover);
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

/* Individual result item */
.search-result {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-fast);
}

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

.search-result:hover,
.search-result.selected {
  background: var(--bg-hover);
}

.search-result-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--accent);
  margin-top: 2px;
}

.search-result-content {
  flex: 1;
  min-width: 0;
}

.search-result-title {
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.search-result-title mark {
  background: rgba(99, 102, 241, 0.3);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

.search-result-meta {
  font-size: var(--font-xs);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.search-result-subject {
  padding: 1px 6px;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 600;
}

/* Subject colors */
.search-result-subject.physics { color: #6366f1; }
.search-result-subject.chemistry { color: #10b981; }
.search-result-subject.biology { color: #f59e0b; }
.search-result-subject.history { color: #ef4444; }

/* Recent searches */
.search-recent {
  padding: var(--space-sm) var(--space-md);
}

.search-recent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}

.search-recent-title {
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.search-recent-clear {
  font-size: var(--font-xs);
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.search-recent-clear:hover {
  text-decoration: underline;
}

.search-recent-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) 0;
  color: var(--text-secondary);
  font-size: var(--font-sm);
  cursor: pointer;
}

.search-recent-item:hover {
  color: var(--text-primary);
}

.search-recent-icon {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

/* Loading state */
.search-loading {
  padding: var(--space-lg);
  text-align: center;
  color: var(--text-muted);
}

.search-loading::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-left: var(--space-sm);
  vertical-align: middle;
}

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

/* Mobile adjustments */
@media (max-width: 600px) {
  .search-bar {
    padding: var(--space-xs) var(--space-sm);
  }

  .search-shortcut {
    display: none;
  }

  .search-results {
    max-height: 300px;
  }

  .search-result {
    padding: var(--space-sm);
  }
}

/* Backdrop when search is open */
.search-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: all var(--transition-normal);
}

.search-backdrop.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
