/* Algolia typeahead dropdown for ExDoc-generated pages. Loaded via
   _scripts/otp_add_headers.sh into every OTP doc page. Class names
   are prefixed `alg-` to avoid collision with ExDoc's own classes. */

/* Hide ExDoc's Lunr autocomplete UI on pages where we provide an
   Algolia typeahead. The exdoc:autocomplete=off meta covers newer
   ExDoc bundles; this CSS rule is the fallback for older ones that
   still render the container regardless. */

.autocomplete {
  display: none !important;
}

.alg-dropdown {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 55px;
  z-index: 200;
  background: var(--autocompleteBackground, #fff);
  border: 1px solid var(--autocompleteBorder, rgba(3, 9, 19, 0.1));
  border-radius: var(--borderRadius-base, 8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  max-height: 480px;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  font-size: 0.9rem;
  color: var(--textBody, #1a202c);
}

.alg-dropdown[hidden] {
  display: none;
}

/* Scope pills row at the top of the dropdown. Only rendered on
   pages where the app context exists; hidden on umbrella pages. */
.alg-scope {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--suggestionBorder, rgba(0, 0, 0, 0.06));
  font-size: 0.75em;
  opacity: 0.85;
}

.alg-scope-pill {
  appearance: none;
  border: 1px solid var(--suggestionBorder, rgba(0, 0, 0, 0.12));
  background: transparent;
  color: inherit;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: inherit;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.4;
}

.alg-scope-pill:hover {
  background: var(--autocompleteHover, rgba(0, 0, 0, 0.04));
}

.alg-scope-pill.alg-active {
  background: var(--mainLight, #a2003e);
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}

.alg-empty a {
  color: var(--mainLight, #a2003e);
}

.alg-results {
  padding: 4px 0;
}

.alg-hit {
  display: block;
  padding: 10px 16px;
  text-decoration: none;
  color: var(--textHeaders, #1a202c);
  border-top: 1px solid var(--suggestionBorder, rgba(0, 0, 0, 0.06));
  transition: background-color 0.1s ease;
}

.alg-hit:first-child {
  border-top: 0;
}

.alg-hit:hover,
.alg-hit.alg-selected {
  background: var(--autocompleteHover, rgba(0, 0, 0, 0.04));
  text-decoration: none;
}

.alg-hit-title {
  font-weight: 600;
  line-height: 1.3;
}

.alg-hit-excerpt {
  margin-top: 4px;
  font-size: 0.82em;
  opacity: 0.8;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Algolia's highlight markers come back as
   <span class="algolia-docsearch-suggestion--highlight">. */

.alg-empty {
  padding: 14px 16px;
  opacity: 0.7;
  font-size: 0.9em;
}

.alg-empty.alg-loading::after {
  content: '';
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -1px;
  animation: alg-spin 0.8s linear infinite;
}

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

/* Footer row — required "Search by Algolia" attribution plus an
   optional keyboard-hint span. */
.alg-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  border-top: 1px solid var(--suggestionBorder, rgba(0, 0, 0, 0.06));
  font-size: 0.72em;
  letter-spacing: 0.02em;
  color: var(--textBody, #4a5568);
  background: var(--autocompleteSelected, rgba(0, 0, 0, 0.02));
}

.alg-footer-hint {
  opacity: 0.7;
}

.alg-footer-hint kbd {
  font-family: inherit;
  font-size: 0.92em;
  padding: 1px 5px;
  margin: 0 1px;
  background: var(--autocompleteLabelBack, rgba(0, 0, 0, 0.06));
  border: 1px solid var(--suggestionBorder, rgba(0, 0, 0, 0.12));
  border-radius: 3px;
}

.alg-footer-attribution {
  margin-left: auto;
  text-decoration: none;
  color: inherit;
  opacity: 0.7;
}

.alg-footer-attribution:hover {
  opacity: 1;
  text-decoration: none;
}

.alg-footer-attribution strong {
  font-weight: 700;
  color: #003dff;
}

/* Dark theme — ExDoc toggles via body.dark or [data-theme=dark] */
body.dark .alg-footer-attribution strong,
[data-theme="dark"] .alg-footer-attribution strong {
  color: #5468ff;
}
