/* Search wrapper for positioning */
.search-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* Search backdrop */
.search-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 1000;
}

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

/* Search container */
.search-container {
  position: fixed;
  opacity: 0;
  visibility: hidden;
  left: 50%;
  top: 80px;
  transform: translateX(-50%);
  z-index: 1001;
  width: 90%;
  max-width: 600px;
  background-color: var(--background);
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 8px 24px var(--shadow-color);
  transition: all 0.2s ease;
  box-sizing: border-box;
}

.search-container.active {
  opacity: 1;
  visibility: visible;
}

/* Search input styling */
#search {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  font-family: inherit;
  border-radius: 8px;
  border: 2px solid var(--border-color);
  outline: none;
  background-color: var(--background);
  color: var(--color);
  box-shadow: inset 0 2px 4px var(--shadow-color);
  transition: all 0.2s ease;
  box-sizing: border-box;
  position: relative;
}

#search:focus {
  border-color: var(--maincolor);
  box-shadow: 0 0 0 2px var(--maincolor-alpha);
}

/* Loading state animation */
.search-container.loading #search {
  background-image: linear-gradient(45deg, 
    var(--background) 25%, 
    var(--hover-background) 25%, 
    var(--hover-background) 50%, 
    var(--background) 50%, 
    var(--background) 75%, 
    var(--hover-background) 75%, 
    var(--hover-background) 100%
  );
  background-size: 20px 20px;
  animation: search-loading 1s linear infinite;
}

@keyframes search-loading {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 20px 0;
  }
}

/* Search icon styling */
.search-icon {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 6px;
  transition: all 0.2s ease;
  text-decoration: none !important;
  border-bottom: none !important;
  margin: -4px;
}

.search-icon:hover {
  background-color: var(--hover-background);
  transform: scale(1.05);
}

.search-icon:active {
  transform: scale(0.95);
}

.search-icon svg {
  width: 18px;
  height: 18px;
  color: var(--color);
  opacity: 0.7;
  transition: all 0.2s ease;
}

.search-icon:hover svg {
  opacity: 1;
  color: var(--maincolor);
}

/* Search results container */
.search-results {
  opacity: 0;
  visibility: hidden;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 100%;
  max-height: 60vh;
  overflow-y: auto;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  background-color: var(--background);
  box-shadow: 0 8px 24px var(--shadow-color);
  z-index: 1001;
  transition: all 0.2s ease;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
  box-sizing: border-box;
}

/* Webkit scrollbar styling */
.search-results::-webkit-scrollbar {
  width: 8px;
}

.search-results::-webkit-scrollbar-track {
  background: transparent;
}

.search-results::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 4px;
  border: 2px solid var(--background);
}

/* Search results items */
.search-results__items {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

/* Individual search result item */
.search-results__item {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  transition: all 0.2s ease;
}

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

.search-results__item a {
  display: block;
  color: var(--color);
  text-decoration: none !important;
  border-bottom: none !important;
  transition: all 0.2s ease;
  padding: 4px;
  margin: -4px;
  border-radius: 4px;
  outline: none;
}

.search-results__item a:focus {
  background-color: var(--maincolor-alpha);
  box-shadow: 0 0 0 2px var(--maincolor);
}

.search-results__item a:focus:not(:focus-visible) {
  box-shadow: none;
}

/* Search result title */
.search-results__title {
  font-size: 1.1em;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--maincolor);
}

/* Search result description */
.search-results__description {
  font-size: 0.9em;
  color: var(--secondary-color);
  line-height: 1.4;
}

/* Highlighted text */
.search-results__highlight {
  background-color: rgba(100, 149, 237, 0.15); /* Cornflower blue with low opacity */
  color: var(--color); /* Use the main text color instead of accent color */
  font-weight: 500;
  border-radius: 2px;
  padding: 0 2px;
}

/* Dark mode override */
@media (prefers-color-scheme: dark) {
  .search-results__highlight {
    background-color: rgba(100, 149, 237, 0.2); /* Slightly higher opacity for dark mode */
  }
}

/* No results message */
.search-results__empty {
  padding: 16px;
  text-align: center;
  color: var(--secondary-color);
  font-style: italic;
  animation: fadeIn 0.3s ease;
}

.search-results__empty strong {
  color: var(--color);
  font-style: normal;
}

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

/* Mobile responsiveness */
@media (max-width: 768px) {
  .search-container {
    width: 95%;
    padding: 12px;
    top: 60px;
  }

  #search {
    font-size: 14px;
    padding: 10px 14px;
  }

  .search-results__title {
    font-size: 1em;
  }

  .search-results__description {
    font-size: 0.85em;
  }
}