#site-search {
  width: 38rem;
  position: absolute;
  top: 0;
  border-radius: var(--wa-border-radius-l);
  padding: 0;
  margin: 0 auto;
  overflow: hidden;

  &::part(base) {
    margin-block: 10rem;
  }

  &::part(body) {
    padding: 0;
  }

  &::part(footer) {
    justify-content: center;
    gap: 0.5rem;
  }

  @media screen and (max-width: 900px) {
    max-width: calc(100% - 2rem);

    &::part(base) {
      margin-block: 1rem;
    }
  }
}

#site-search-container {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 20rem);

  @media screen and (max-width: 900px) {
    max-height: calc(100dvh - 2rem);
  }
}

/* Header */
header {
  flex: 0 0 auto;
  align-items: middle;
  /* Fixes an iOS Safari 16.4 bug that draws the parent element's border radius incorrectly when showing/hiding results */
  border-radius: var(--wa-border-radius-l);
}

#site-search.has-results header {
  border-start-start-radius: var(--wa-border-radius-l);
  border-start-end-radius: var(--wa-border-radius-l);
  border-end-start-radius: 0;
  border-end-end-radius: 0;
}

#site-search-input-wrapper {
  display: flex;
  align-items: center;
  margin-block-end: 0.5rem;
}

#site-search-input {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  font: inherit;
  font-size: 1.5rem;
  background: transparent;
  padding: 1rem 1rem 0.5rem 1rem;
  margin: 0;

  &::placeholder {
    color: var(--wa-color-text-quiet);
  }

  &:focus,
  &:focus-visible {
    outline: none;
  }
}

#site-search-input::-webkit-search-decoration,
#site-search-input::-webkit-search-cancel-button,
#site-search-input::-webkit-search-results-button,
#site-search-input::-webkit-search-results-decoration {
  display: none;
}

#site-search-input:focus,
#site-search-input:focus-visible {
  --wa-focus-ring: 0;
}

#site-search-body {
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
}

#site-search.has-results,
#site-search.no-results {
  #site-search-body {
    border-top: var(--wa-panel-border-style) var(--wa-panel-border-width) var(--wa-color-neutral-border-quiet);
  }
}

/* Results */
#site-search-listbox {
  line-height: 1.4;
  list-style: none;
  padding: 0;
  margin: 0;

  a {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    text-decoration: none;
    padding: 0.5rem 1.5rem;
  }

  a:focus-visible {
    outline: var(--wa-focus-ring);
    outline-offset: -2px;
  }

  @media (hover: hover) {
    li a:hover,
    li a:hover small {
      background-color: var(--wa-color-neutral-fill-normal);
    }
  }

  li[data-selected='true'] a,
  li[data-selected='true'] a * {
    outline: none;
    background-color: var(--wa-color-brand-fill-loud);
    color: var(--wa-color-brand-on-loud);
  }

  h3 {
    font-weight: var(--wa-font-weight-semibold);
    margin: 0;
  }

  small {
    display: block;
    color: var(--wa-color-text-quiet);
  }
}

#site-search.has-results #site-search-results {
  display: block;
}

/* Search results */
.site-search-result {
  padding: 0;
  margin: 0;

  .site-search-result-icon {
    flex: 0 0 auto;
    display: flex;
    width: 1.75rem;
    justify-content: center;

    wa-icon {
      font-size: 1.75rem;
      color: var(--wa-color-neutral-fill-loud);
    }
  }

  .site-search-result-title,
  .site-search-result-description,
  .site-search-result-url {
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .site-search-result-details {
    max-width: calc(100% - 4rem);
  }

  .site-search-result-title {
    font-size: 1.25rem;
    font-weight: var(--wa-font-weight-semibold);
    color: var(--wa-color-brand-on-normal);
  }

  .site-search-result-description {
    font-size: 0.875rem;
    color: var(--wa-color-text-normal);
  }

  .site-search-result-url {
    font-size: 0.875rem;
    color: var(--wa-color-text-quiet);
  }
}

/* Empty state */
#site-search-empty {
  display: none;
  text-align: center;
  font-size: 0.875rem;
  color: var(--wa-color-text-quiet);
  padding: 3rem 2rem;

  wa-icon {
    display: block;
    width: 2rem;
    height: 2rem;
    margin-inline: auto;
    margin-block-end: 0.5rem;
  }
}

#site-search.no-results #site-search-empty {
  display: block;
}

/* Footer */
#site-search footer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: row;
  justify-content: center;
  gap: 2rem;
  color: var(--wa-color-text-quiet);
  border-top: var(--wa-panel-border-style) var(--wa-panel-border-width) var(--wa-color-neutral-border-quiet);
  border-bottom-left-radius: var(--wa-border-radius-l);
  border-bottom-right-radius: var(--wa-border-radius-l);
  padding: 1rem;

  kbd {
    display: inline-flex;
    height: 1.35rem;
    justify-content: center;
    align-items: center;
    font-weight: var(--wa-font-weight-bold);

    &:last-of-type {
      margin-inline-end: 0.25rem;
    }

    > svg {
      width: 1em;
      height: 1em;
    }
  }
}
