/* Search Component Styles - Inline Results Design */

.search-container {
  position: relative;
  width: 100%;
  margin: 0 auto var(--spacing-6) auto;
  box-sizing: border-box;
  z-index: 49; /* Ensure below nav-bar */
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 600px;
  margin: 0 auto;
}

.search-input {
  width: 100%;
  padding: var(--spacing-3) var(--spacing-4);
  padding-right: var(--spacing-8);
  font-size: var(--font-size-base);
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius-lg);
  background: white;
  color: var(--color-neutral-900);
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.search-input:focus {
  outline: none;
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 3px rgba(0, 112, 243, 0.1);
}

.search-clear {
  position: absolute;
  right: var(--spacing-3);
  display: none;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: none;
  border: none;
  color: var(--color-neutral-500);
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.search-clear:hover {
  background: var(--color-neutral-100);
  color: var(--color-neutral-900);
}

/* Inline results container */
.search-results {
  margin-top: var(--spacing-3);
  width: 100%;
  max-width: 100%;
  background: white;
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
  position: relative;
  z-index: 50; /* Ensure below nav-bar */
  display: none; /* Hide completely when not active */
}

.search-results.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  display: block; /* Show when active */
}

/* Close button */
.search-close {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: var(--spacing-3) var(--spacing-4);
  background: var(--color-neutral-50);
  border-bottom: var(--border-width) solid var(--border-color);
}

.search-close-button {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  padding: var(--spacing-2) var(--spacing-3);
  background: var(--color-neutral-100);
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius-md);
  color: var(--color-neutral-700);
  font-size: var(--font-size-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.search-close-button:hover {
  background: var(--color-neutral-200);
  color: var(--color-neutral-900);
}

.search-close-button:focus {
  outline: 2px solid var(--color-primary-500);
  outline-offset: 2px;
}

/* Results list */
.search-results-list {
  overflow: visible;
  padding: 0;
  transition: opacity 0.15s ease;
  width: 100%;
  box-sizing: border-box;
}

.search-result-item {
  border-bottom: var(--border-width) solid var(--border-color);
}

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

.search-result-link {
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-3);
  padding: var(--spacing-4);
  text-decoration: none;
  color: inherit;
  transition: background-color 0.2s ease;
}

.search-result-link:hover,
.search-result-link:focus {
  background: var(--color-neutral-50);
  outline: none;
}

.search-result-link:focus {
  box-shadow: inset 0 0 0 2px var(--color-primary-500);
}

/* Search result thumbnail */
.search-result-thumbnail {
  flex-shrink: 0;
  width: 80px;
  max-width: 15%; /* Don't exceed 15% of container width */
  height: 80px;
  border-radius: var(--border-radius-md);
  overflow: hidden;
  background: var(--color-neutral-200);
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
}

.search-result-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Search result content */
.search-result-content {
  flex: 1;
  min-width: 0; /* Allows proper text truncation */
}

/* When there's no image, let content use full width */
.search-result-item:not(.has-image) .search-result-link {
  display: block;
}

.search-result-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--color-neutral-900);
  margin: 0 0 var(--spacing-2) 0;
  line-height: var(--line-height-normal);
}

.search-result-excerpt {
  font-size: var(--font-size-base);
  color: var(--color-neutral-600);
  margin: 0 0 var(--spacing-2) 0;
  line-height: var(--line-height-relaxed);
}

.search-result-url {
  font-size: var(--font-size-sm);
  color: var(--color-primary-500);
  text-decoration: none;
}

.search-no-results,
.search-error,
.search-dev-message {
  padding: var(--spacing-6) var(--spacing-4);
  text-align: center;
  color: var(--color-neutral-500);
  font-size: var(--font-size-base);
}

.search-error {
  color: var(--color-secondary-500);
}

.search-dev-message {
  color: var(--color-primary-500);
  background: rgba(0, 112, 243, 0.05);
  border-radius: var(--border-radius-md);
  margin: var(--spacing-4);
}

.search-dev-message code {
  background: rgba(0, 112, 243, 0.1);
  padding: 2px 4px;
  border-radius: 3px;
  font-family: monospace;
  font-size: var(--font-size-sm);
}

/* Indicators */
.search-dev-indicator,
.search-fallback-indicator {
  padding: var(--spacing-3) var(--spacing-4);
  text-align: center;
  font-size: var(--font-size-sm);
  border-top: var(--border-width) solid var(--border-color);
  margin-top: auto;
}

.search-dev-indicator {
  background: rgba(0, 112, 243, 0.1);
  color: var(--color-primary-500);
}

.search-fallback-indicator {
  background: rgba(255, 165, 0, 0.1);
  color: #ff8c00;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .search-container {
    margin: 0 0 var(--spacing-4) 0;
    max-width: 100%;
  }

  .search-input {
    padding: var(--spacing-2) var(--spacing-3);
    padding-right: var(--spacing-6);
    font-size: var(--font-size-sm);
  }

  .search-results {
    margin-top: var(--spacing-2);
    border-radius: var(--border-radius-md);
    width: 100%;
    max-width: 100%;
  }

  .search-result-link {
    padding: var(--spacing-3);
    gap: var(--spacing-2);
  }

  /* Adjust thumbnail size for mobile */
  .search-result-thumbnail {
    width: 60px;
    max-width: 15%;
    height: 60px;
    min-width: 50px; /* Ensure it doesn't get too small */
  }

  .search-result-title {
    font-size: var(--font-size-base);
  }

  .search-result-excerpt {
    font-size: var(--font-size-sm);
  }

  .search-close-button {
    font-size: var(--font-size-xs);
    padding: var(--spacing-1) var(--spacing-2);
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .search-input {
    background: var(--color-neutral-100);
    color: var(--color-neutral-900);
    border-color: var(--color-neutral-500);
  }

  .search-results {
    background: var(--color-neutral-100);
    border-color: var(--color-neutral-500);
  }

  .search-close {
    background: var(--color-neutral-100);
    border-color: var(--color-neutral-500);
  }

  .search-close-button {
    background: var(--color-neutral-200);
    border-color: var(--color-neutral-600);
    color: var(--color-neutral-800);
  }

  .search-close-button:hover {
    background: var(--color-neutral-300);
    color: var(--color-neutral-900);
  }

  .search-result-link:hover,
  .search-result-link:focus {
    background: rgba(255, 255, 255, 0.1);
  }
}

/* Ensure nav-bar is always above search results */
.nav-bar {
  z-index: 200;
  position: sticky;
  top: 0;
}

/* Lower z-index for search results to stay under nav-bar */
.search-results {
  z-index: 50;
  position: relative;
}

/* If search-container is ever fixed or absolute, ensure it is below nav-bar */
.search-container {
  z-index: 49;
  position: relative;
}

/* Focus helpers */
.search-results.active .search-close-button,
.search-results.active .search-result-link {
  /* Ensure these elements are focusable when results are active */
  outline-offset: 2px;
}

/* Smooth scrolling for results */
.search-results-list {
  scroll-behavior: smooth;
}

/* Animation timing for reduced motion */
@media (prefers-reduced-motion: reduce) {
  .search-results {
    transition: none;
  }
}
