/**
 * Bengal SSG Default Theme
 * Search Component
 *
 * Search UI placeholder for future search integration.
 * Works without JavaScript (form submission).
 * Can be enhanced with JS for live search.
 */

/* ============================================
   SEARCH CONTAINER
   ============================================ */

.search {
  position: relative;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

.search--inline {
  max-width: 100%;
}

/* ============================================
   SEARCH FORM
   ============================================ */

.search__form {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.search__input-wrapper {
  position: relative;
  flex: 1;
}

.search__icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: var(--color-text-tertiary);
  pointer-events: none;
}

.search__input {
  width: 100%;
  padding: 0.875rem 1rem 0.875rem 3rem;
  font-size: var(--text-body);
  font-family: inherit;
  color: var(--color-text-primary);
  background-color: var(--color-bg-elevated);
  border: 2px solid var(--color-border);
  border-radius: var(--border-radius-large);
  box-shadow: var(--elevation-subtle);
  transition: all var(--transition-fast);
  appearance: none;
}

.search__input::placeholder {
  color: var(--color-text-tertiary);
}

.search__input:hover {
  border-color: var(--color-border-dark);
}

.search__input:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

/* Clear Button */
.search__clear {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: color var(--transition-fast);
}

.search__clear:hover {
  color: var(--color-text-primary);
}

.search__input:not(:placeholder-shown) ~ .search__clear {
  display: flex;
}

/* Submit Button (optional, can be hidden if JS search is used) */
.search__submit {
  padding: 0.875rem 1.5rem;
  font-size: var(--text-body-small);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-inverse);
  background-color: var(--color-primary);
  border: none;
  border-radius: var(--border-radius-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.search__submit:hover {
  background-color: var(--color-primary-hover);
  box-shadow: var(--elevation-low);
  transform: translateY(-1px);
}

.search__submit:active {
  transform: translateY(0);
}

.search__submit:focus-visible {
  outline: 2px solid var(--color-border-focus);
  outline-offset: 2px;
}

/* ============================================
   SEARCH RESULTS DROPDOWN (for JS integration)
   ============================================ */

.search__results {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  max-height: 400px;
  overflow-y: auto;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-large);
  box-shadow: var(--elevation-popover);
  z-index: var(--z-dropdown);
  display: none;
}

.search__results--visible {
  display: block;
}

.search__results-list {
  list-style: none;
  padding: 0.5rem;
  margin: 0;
}

.search__result-item {
  margin: 0;
}

.search__result-link {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem;
  border-radius: var(--border-radius-medium);
  text-decoration: none;
  color: inherit;
  transition: background-color var(--transition-fast);
}

.search__result-link:hover,
.search__result-link:focus {
  background-color: var(--color-bg-hover);
}

.search__result-title {
  font-size: var(--text-body-small);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  margin: 0;
}

.search__result-excerpt {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search__result-highlight {
  background-color: rgba(255, 215, 0, 0.3);
  font-weight: var(--font-weight-semibold);
  padding: 0 0.125rem;
  border-radius: 2px;
}

[data-theme="dark"] .search__result-highlight {
  background-color: rgba(255, 215, 0, 0.2);
}

.search__no-results {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--color-text-tertiary);
  font-size: var(--text-body-small);
}

/* ============================================
   SEARCH IN HEADER
   ============================================ */

.header-search {
  max-width: 400px;
  margin: 0;
}

.header-search .search__input {
  padding: 0.625rem 1rem 0.625rem 2.5rem;
  font-size: var(--text-body-small);
}

.header-search .search__icon {
  width: 16px;
  height: 16px;
  left: 0.75rem;
}

/* ============================================
   SEARCH IN DOCS LAYOUT
   ============================================ */

.docs-search {
  margin-bottom: 1.5rem;
}

.docs-search .search__input {
  font-size: var(--text-body-small);
}

/* ============================================
   KEYBOARD SHORTCUTS HINT
   ============================================ */

.search__shortcut {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 0.25rem;
  align-items: center;
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  pointer-events: none;
}

.search__shortcut kbd {
  padding: 0.125rem 0.375rem;
  font-size: var(--text-xxs);
  font-family: var(--font-family-code);
  background-color: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  box-shadow: 0 1px 0 var(--color-border-dark);
}

.search__input:focus ~ .search__shortcut {
  display: none;
}

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

@media (max-width: 768px) {
  .search__submit {
    padding: 0.875rem 1rem;
  }

  .header-search {
    max-width: 100%;
  }

  .search__shortcut {
    display: none; /* Hide keyboard hints on mobile */
  }
}

@media (max-width: 640px) {
  .search__form {
    flex-direction: column;
  }

  .search__submit {
    width: 100%;
  }

  .search__input {
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    font-size: var(--text-body-small);
  }

  .search__icon {
    width: 18px;
    height: 18px;
    left: 0.75rem;
  }
}

/* ============================================
   KEYBOARD NAVIGATION
   ============================================ */

.user-is-tabbing .search__input:focus-visible {
  outline: 2px solid var(--color-border-focus);
  outline-offset: 2px;
}

.user-is-tabbing .search__result-link:focus-visible {
  outline: 2px solid var(--color-border-focus);
  outline-offset: -2px;
}

/* ============================================
   LOADING STATE
   ============================================ */

.search--loading .search__icon {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: translateY(-50%) rotate(0deg);
  }
  to {
    transform: translateY(-50%) rotate(360deg);
  }
}
