/* Search field in the header and the Lunr search results (@jmix-framework/lunr-extension). */

.search-field {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.search-field::before {
  content: "";
  position: absolute;
  left: 0.65rem;
  width: 0.9rem;
  height: 0.9rem;
  background-color: var(--color-text-muted);
  mask: var(--icon-search) center / contain no-repeat;
  pointer-events: none;
}

#search-input {
  width: 18rem;
  height: 2.25rem;
  padding: 0 2.1rem;
  border: 1px solid var(--color-control-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-subtle);
  color: var(--color-text);
  font: inherit;
  font-size: 0.8rem;
  line-height: 1.5;
}

#search-input::placeholder {
  color: var(--color-text-muted);
  opacity: 1;
}

#search-input:hover {
  background: var(--color-surface-hover);
}

#search-input:focus {
  border-color: var(--color-accent);
  background: var(--color-surface);
}

.search-kbd {
  position: absolute;
  right: 0.55rem;
  padding: 0 0.35rem;
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font: 400 0.68rem/1.35 var(--monospace-font-family);
  pointer-events: none;
}

#search-input:focus + .search-kbd {
  display: none;
}

@media screen and (max-width: 1023.5px) {
  .search-field,
  #search-input {
    width: 100%;
  }

  #search-input {
    /* 16px or more, or iOS Safari zooms in when the field gets focus (the old inline style did this) */
    font-size: 1rem;
  }

  .search-kbd {
    /* the / shortcut is meant for keyboards, so the hint stays on wide screens */
    display: none;
  }
}

.search-result-dropdown-menu {
  position: absolute;
  z-index: 100;
  top: 100%;
  right: 0;
  left: inherit;
  display: block;
  min-width: 500px;
  max-width: 600px;
  height: auto;
  margin: 0.5rem 0 0;
  padding: 0;
  border: none;
  border-radius: var(--radius-lg);
  background: transparent;
  box-shadow: var(--shadow-menu);
  text-align: left;
}

@media screen and (max-width: 768px) {
  .search-result-dropdown-menu {
    min-width: calc(100vw - 3.75rem);
  }
}

.search-result-dataset {
  position: relative;
  overflow: auto;
  max-height: calc(100vh - 5.25rem);
  padding: 0.25rem 0.75rem 0.75rem;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
}

.search-result-component-header {
  padding: 0.5rem 0 0.25rem;
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 500;
}

.search-result-highlight {
  padding: 0.1em 0.05em;
  background: var(--color-accent-tint);
  color: var(--color-accent);
  font-weight: 600;
}

.search-result-item {
  display: flex;
  margin: 0.5rem 0;
  font-size: 1rem;
}

.search-result-document-title {
  position: relative;
  width: 33%;
  padding: 0.25rem 0.5rem 0.25rem 0;
  border-right: 1px solid var(--color-line);
  color: var(--color-text-muted);
  font-size: 0.8rem;
  text-align: right;
  overflow-wrap: break-word;
}

.search-result-document-hit {
  flex: 1;
  color: var(--color-text);
  font-size: 0.75em;
  font-weight: 400;
}

.search-result-document-hit > a {
  display: block;
  margin-bottom: 0.25rem;
  padding: 0.5rem 0 0.5rem 1rem;
  border-radius: var(--radius-md);
  color: inherit;
}

.search-result-document-hit > a:hover {
  background: var(--color-surface-hover);
  text-decoration: none;
}

@media screen and (max-width: 1023.5px) {
  /* the menu panel scrolls on small screens and would clip the results: let them hang over the page below it */
  .navbar-menu {
    overflow: visible;
  }

  /* the panel starts lower here, below the field in the open menu, so it gets less height */
  .search-result-dataset {
    max-height: calc(100vh - 8rem);
  }
}

@media (forced-colors: active) {
  #search-input,
  .search-result-dataset {
    border-color: CanvasText;
  }

  .search-field::before {
    forced-color-adjust: none;
    background-color: GrayText;
  }
}
