/* Search wrapper */
.search-wrapper {
  position: relative;
  width: 100%;
  max-width: 584px;
  z-index: 10;
}

/* Search bar */
.search-bar-container {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 584px;
  height: 46px;
  border: 1px solid var(--search-border-color);
  border-radius: 24px;
  padding: 0 14px 0 16px;
  background-color: var(--bg-color);
  z-index: 11;
  position: relative;
}
.search-bar-container.is-dropdown-open {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

/* hover/focus */
.search-bar-container:hover,
.search-bar-container:focus-within {
  border-color: var(--search-focus-border-color);
  box-shadow: 0 1px 6px var(--search-shadow-color);
}

/* when dropdown open: remove focus shadow and restore border */
.search-bar-container.is-dropdown-open {
  box-shadow: none;
  border-color: var(--search-border-color);
}

/* icon & input */
.search-bar-container .search-icon {
  fill: var(--search-icon-color);
  width: 20px;
  height: 20px;
  margin-right: 8px;
  filter: var(--icon-filter);
  flex-shrink: 0; /* prevent icon from shrinking */
}
.search-bar-container input[type="text"] {
  flex-grow: 1;
  border: none;
  outline: none;
  font-size: 16px;
  background-color: transparent;
  height: 100%;
  color: var(--text-color);
  /* Added padding-right to make space for clear button */
  padding-right: 28px;
}

.clear-search-button {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  padding: 4px;
  border-radius: 50%;
  border: none;
  background-color: transparent;
  cursor: pointer;
  display: none; /* Hidden by default */
  align-items: center;
  justify-content: center;
}
.clear-search-button svg {
  fill: var(--search-icon-color);
  width: 16px;
  height: 16px;
}
@media (hover: hover) and (pointer: fine) {
    .clear-search-button:hover {
        background-color: var(--button-hover-bg-color);
    }
}

/* placeholder */
.search-bar-container input::placeholder {
  color: var(--search-placeholder-color);
  opacity: 1;
}
.search-bar-container input:-ms-input-placeholder {
  color: var(--search-placeholder-color);
}

/* Dropdown */
.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  background-color: var(--dropdown-bg);
  border: 1px solid var(--dropdown-border);
  border-top: none;
  border-bottom-left-radius: 24px;
  border-bottom-right-radius: 24px;
  box-shadow: 0 4px 6px var(--dropdown-shadow);
  /* Set fixed height to 260px */
  height: 260px;
  display: none; /* Start hidden */
  flex-direction: column; /* Stack scroll area and buttons */
  z-index: 9;
  /* Add overflow: hidden to clip the scrollbar */
  overflow: hidden;
}

/* Changed from display: none to override */
.search-bar-container.is-dropdown-open + .search-dropdown {
  display: flex; /* Use flex when open */
}

/* Scrollable content area */
#dropdown-scroll-content {
  flex-grow: 1; /* Take up all available space */
  overflow-y: auto; /* Add scrollbar if content overflows */
  /* Changed to padding-top only to remove bottom gap */
  padding-top: 6px;
}

#no-results-message {
  padding: 12px 20px;
  color: var(--text-color-muted);
  text-align: center;
  font-size: 14px;
}

.dropdown-item {
  display: block;
  padding: 10px 20px;
  text-decoration: none;
  color: var(--text-color);
  font-size: 14px;
}
.dropdown-item:hover {
  background-color: var(--dropdown-item-hover-bg);
}

.search-result-item {
  border-bottom: 1px solid var(--dropdown-border);
}

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

.search-result-link {
  display: block;
  padding: 12px 20px;
  text-decoration: none;
  color: var(--text-color);
}

.search-result-link:hover {
  background-color: var(--dropdown-item-hover-bg);
}

.search-result-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-color);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-result-snippet {
  font-size: 12px;
  color: var(--text-color-muted);
  line-height: 1.4;
}

.search-result-category {
  display: inline-block;
  font-size: 10px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: var(--button-bg-color);
  color: var(--button-text-color);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Buttons area inside dropdown */
.search-dropdown .button-container {
  display: flex;
  gap: 12px;
  justify-content: center;
  /* Balanced padding to reduce top gap */
  padding: 12px 20px;
  /* This !important is critical: it stops the container from stacking */
  flex-direction: row !important;
  width: auto !important;
  /* Ensure buttons don't shrink */
  flex-shrink: 0;
  border-top: 1px solid var(--dropdown-border);
  /* Override global margin */
  margin-top: 0;
}

/* This rule keeps the buttons at their natural width */
.search-dropdown .search-button {
  width: auto !important;
  flex: 0 0 auto;
}

/* Mobile tweak for dropdown buttons */
@media (max-width: 600px) {
  .search-dropdown .button-container {
    flex-direction: column; /* keep stacking on narrow screens */
    align-items: center; /* <— prevent width stretch */
    width: auto; /* override any inherited 100% */
  }
  .search-dropdown .search-button {
    width: auto !important; /* keep natural width */
    flex: 0 0 auto; /* don't grow/shrink */
    align-self: center; /* belt-and-suspenders */
  }
}

/*
  This block contains ALL transitions that depend on theme variables,
  preventing them from firing on page load.
*/
.theme-transitions-active .search-bar-container {
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.4s;
}
.theme-transitions-active .search-bar-container .search-icon {
  transition: fill 0.2s;
}
.theme-transitions-active .search-bar-container input[type="text"] {
  transition: color 0.2s;
}
.theme-transitions-active .search-dropdown {
  transition: background-color 0.4s, border-color 0.2s;
}
.theme-transitions-active .dropdown-item {
  transition: background-color 0.15s, color 0.2s;
}
.theme-transitions-active .search-result-link {
  transition: background-color 0.15s, color 0.2s;
}
.theme-transitions-active .search-result-title {
  transition: color 0.2s;
}
.theme-transitions-active .search-result-snippet {
  transition: color 0.2s;
}
.theme-transitions-active .search-result-category {
  transition: background-color 0.2s, color 0.2s;
}