/* Search: the header trigger and the panel it opens. */

.search--trigger {
  width: 100%;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.search--trigger:hover {
  border-color: var(--surface-3);
  color: var(--ink);
}

.search__placeholder {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body:has(.search-dialog[open]) {
  overflow: hidden;
}

.search-dialog {
  --search-cols: 7;

  width: min(1200px, 100% - 48px);
  max-width: none;
  max-height: calc(100dvh - 96px);
  margin: 72px auto auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--surface-float);
  color: var(--ink);
  box-shadow: 0 24px 64px rgb(0 0 0 / calc(0.5 * var(--shade)));
  overflow: hidden;
}

/* Only the results scroll; the field stays put, as on the reference site. */
.search-dialog[open] {
  display: flex;
  flex-direction: column;
}

.search-dialog::backdrop {
  background: var(--veil);
}

.search-dialog__inner {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.search-dialog__head {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-5) var(--space-4);
}

.search-dialog__field {
  display: flex;
  flex: 1;
  align-items: center;
  gap: var(--space-3);
  height: 50px;
  padding: 0 var(--space-3) 0 var(--space-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--field);
  color: var(--ink-muted);
  box-shadow: 0 1px 3px rgb(0 0 0 / calc(0.2 * var(--shade)));
}

/* A field being typed in lights its edge in the focus colour. */
.search-dialog__field:focus-within {
  border-color: var(--focus);
}

.search-dialog__input {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}

.search-dialog__input::placeholder {
  color: var(--ink-muted);
  opacity: 1;
}

.search-dialog__input::-webkit-search-cancel-button {
  appearance: none;
}

.search-dialog__clear {
  padding: var(--space-1) var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.search-dialog__clear:hover {
  color: var(--ink);
}

/* Results frame */
.search-results {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-5);
  min-height: 0;
  padding: var(--space-1) var(--space-5) var(--space-5);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.search-results > * {
  flex-shrink: 0;
}

.search-results .segmented a,
.search-results .filter-chips a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--ink-muted);
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
}

.search-results .segmented a {
  height: 36px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-full);
  font-size: 14px;
}

.search-results .filter-chips a {
  height: 32px;
  padding: 0 var(--space-3);
  border-radius: 8px;
  background: var(--surface-1);
  font-size: 13px;
}

.search-results .segmented a[aria-current="true"],
.search-results .filter-chips a[aria-current="true"] {
  background: var(--selected);
  color: var(--ink);
}

.count-badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 11px;
  font-weight: 700;
}

.filter-chips .count-badge {
  background: var(--surface-0);
  color: var(--ink-muted);
}

.search-results__hint {
  margin: 0;
  color: var(--ink-muted);
  font-size: 14px;
}

.search-results__grid {
  display: grid;
  grid-template-columns: repeat(var(--search-cols), minmax(0, 1fr));
  gap: var(--space-4);
}

.search-results__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-8) 0;
  color: var(--ink-muted);
  text-align: center;
}

.search-results__empty p {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.search-results[busy] {
  opacity: 0.6;
  transition: opacity 0.15s;
}

@media (max-width: 1099px) {
  .search-dialog {
    --search-cols: 5;

    width: calc(100% - 32px);
    margin-top: 64px;
  }
}

/* Phone: a card above the tab bar, opened from the bar's search button (layout.css). */
@media (max-width: 767px) {
  .search-dialog {
    --search-cols: 3;
  }

  .search-dialog__head {
    padding: var(--space-4) var(--space-4) var(--space-3);
  }

  .search-results {
    gap: var(--space-4);
    padding: var(--space-1) var(--space-4) var(--space-6);
  }

  /* The card's shelves run on to its edge, so the next tile peeks in. */
  .search-results .shelf__row {
    margin-right: calc(-1 * var(--space-4));
    padding-right: var(--space-4);
  }

  .search-results__grid {
    gap: var(--space-3);
  }
}
