/* components/search.css — layout for partials/search.hbs; reacts to state
   set by search.js. Always on the menu panel's inverted ground, so colours
   are stated once (currentColor-derived tokens follow it).
   State: .nav-menu[data-search-active] — in use; link blocks hide, Cancel
            appears; empty, the poem shows at the menu's height
          .search__results[hidden] — not in use, or no query yet
          .search__clear[hidden] — query empty */

/* THE ROW — lands exactly where home's short bar was: same margins, padding
   and faint hairlines. A real border works here because the row sits inside
   the container's content box. */
.search__form {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-block: var(--space-3);
  /* Less the borders, so both rows are the same height. */
  padding-block: calc(var(--space-3) - var(--border-width));
  border-block: var(--border-width) solid var(--color-border-faint);
  transition: border-color var(--transition);
}

/* While results show, the gap moves inside the scroller (as padding), so
   results scroll right up to the rule. */
.search:has(.search__results:not([hidden])) .search__form {
  margin-block-end: 0;
}

/* Hairline: faint → hover → focus (the field's only focus indicator).
   Hover on real pointers only; placed before :focus-within so focus wins. */
@media (hover: hover) {
  .search__form:hover {
    border-color: var(--color-border-faint-hover);
  }
}

.search__form:focus-within {
  border-color: var(--color-border-faint-focus);
}

.search__label {
  display: flex;
  flex: none;
  align-items: center;
  cursor: text;
}

/* Keep at ≥16px: iOS zooms the page on smaller focused inputs. */
.search__input {
  flex: 1;
  min-inline-size: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  outline: none;
  appearance: none;
}

.search__input::placeholder {
  color: var(--color-fg-muted);
  opacity: 1; /* Firefox fades placeholders by default */
}

/* Hide the native clear button; .search__clear replaces it. */
.search__input::-webkit-search-cancel-button,
.search__input::-webkit-search-decoration {
  appearance: none;
}

.search__clear,
.search__cancel {
  flex: none;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

/* Restated so the display above can't override [hidden]. */
.search__clear[hidden] {
  display: none;
}

/* Cancel: only while results show, at every width. */
.search__cancel {
  display: none;
}

.nav-menu[data-search-active] .search__cancel {
  display: block;
}

/* THE RESULTS AREA — scrolls itself (the panel hangs from a sticky header,
   so page scrolling can't reach past the viewport).
   Height = 100dvh − --search-results-top (measured by search.js fit()) −
   --nav-menu-clearance. It deliberately stops short of Safari's bottom
   toolbar: Safari hit-tests just above it, and a sticky/fixed element there
   gets treated as a bottom bar, leaving an opaque band that persists after
   the panel closes (WebKit fixedContainerEdges). A fixed height, not a max,
   so the panel doesn't jump while results load. */
/* Top padding = the row's old bottom margin + --space-2. */
.search__results {
  block-size: calc(100vh - var(--search-results-top, 30vh) - var(--nav-menu-clearance));
  block-size: calc(100dvh - var(--search-results-top, 30dvh) - var(--nav-menu-clearance));
  padding-block: calc(var(--space-3) + var(--space-2)) var(--space-10);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.search__results[hidden] {
  display: none;
}

/* With results open, the panel's end padding would reach Safari's sample
   point; drop it. */
.nav-menu:has(.search__results:not([hidden])) .nav-menu__inner {
  padding-block-end: 0;
}

/* THE PAGE BEHIND THE RESULTS — hidden (visibility keeps layout and scroll)
   and body takes the panel colour, so the strip under Safari's toolbar reads
   as panel. body's background, not a fixed overlay, which Safari would
   treat as a bar. */
body:has(.search__results:not([hidden])) {
  background-color: var(--color-bg-invert);
}

body:has(.search__results:not([hidden])) > :not(.site-header) {
  visibility: hidden;
}
/* Panel link blocks make way for the results (the mobile brand stays). */
.nav-menu[data-search-active] .nav-menu__mobile,
.nav-menu[data-search-active] .nav-menu__columns {
  display: none;
}

/* THE TWO COLUMNS — Articles (capped at --search-articles) beside Topics
   and Authors (.search__aside), from --bp-md; stacked below. Not sticky: a
   long aside taller than the scroller would hide its own bottom. */
/* Same --space-10 between all groups, stacked or not. */
.search__hits {
  --search-articles: 50rem;

  display: grid;
  row-gap: var(--space-10);
}

@media (width >= 48rem) {
  .search__hits {
    grid-template-columns: minmax(0, var(--search-articles)) minmax(16rem, 1fr);
    column-gap: var(--space-16);
    align-items: start;
  }
}

.search__section + .search__section {
  margin-block-start: var(--space-10);
}

/* Keep in step with .nav-menu__trending-heading in site-header.css. */
.search__heading {
  margin: 0 0 var(--space-2);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-fg-muted);
}

/* In use with an empty field: a poem. --space-2 below the row's bottom
   margin (the results' top padding, which replaces that margin), so it
   starts where the first heading will. */
.search__prompt {
  display: none;
  padding-block-start: var(--space-2);
  font-family: var(--font-ui);
  color: var(--color-fg-muted);
}

/* As .search__message ("No results found."), but at full strength. */
.search__prompt-excerpt {
  color: var(--color-fg-invert);
  max-inline-size: var(--measure);
}

/* The heading's face. A <p>, so the heading's leading (an h2's, from the
   reset) is restated. */
.search__prompt-title {
  margin-block-start: var(--space-4);
  line-height: var(--leading-tight);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* As .search__message, a step back. */
.search__prompt-poet {
  margin-block-start: var(--space-1);
  color: var(--color-fg-soft);
}

.nav-menu[data-search-active] .search:has(.search__results[hidden]) .search__prompt {
  display: block;
}

/* Meanwhile the panel keeps the height it had as a menu, so the ground
   doesn't collapse to the row (--nav-menu-height: search.js setActive()). */
.nav-menu[data-search-active]:has(.search__results[hidden]) {
  min-block-size: var(--nav-menu-height, auto);
}

/* Tabular figures so the heading doesn't shift as the count changes. */
.search__count {
  margin-inline-start: var(--space-2);
  font-variant-numeric: tabular-nums;
}

.search__list {
  max-inline-size: var(--search-articles);
}

.search__message {
  font-family: var(--font-ui);
  color: var(--color-fg-muted);
}

/* Note shown when Algolia's 1,000-hit limit cut a group short. */
.search__section > .search__message {
  margin-block-start: var(--space-4);
  font-size: var(--text-sm);
}

/* LOAD MORE / SEE ALL / HIDE ALL — a small outline version of the header's
   Subscribe button. currentColor border, since the panel is always inverted. */
.search__more {
  margin-block-start: var(--space-4);
  padding: var(--space-1) var(--space-3);
  border: var(--border-width) solid currentColor;
  border-radius: var(--radius);
  background: none;
  color: inherit;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
}

/* Inverts in place on hover, as Subscribe does. Border stated too: it's
   currentColor, which the hover changes. */
@media (hover: hover) {
  .search__more:hover {
    border-color: var(--color-fg-invert);
    background-color: var(--color-fg-invert);
    color: var(--color-bg-invert);
  }
}

.search__more[aria-busy="true"] {
  cursor: progress;
}

/* Restated: an author row's display: flex would beat [hidden]. */
.search__section [hidden] {
  display: none;
}

/* A RESULT ROW — built by search.js. Text left, thumbnail right, in source
   order too. A grid, so the thumbnail
   column is held open even without an image and text widths match.
   --search-thumb: 100px, 160px from --bp-md (2× is Ghost's "s" size). */
.search-result {
  --search-thumb: 6.25rem;

  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--search-thumb);
  align-items: start;
  column-gap: var(--space-6);
  padding-block: var(--space-4);
  border-block-end: var(--border-width) solid var(--color-border-faint);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}

.search-result:last-child {
  border-block-end: 0;
}

.search-result__media {
  display: block;
}

.search-result__image {
  inline-size: var(--search-thumb);
  block-size: auto;
  aspect-ratio: var(--media-ratio-beside);
  object-fit: cover;
}

@media (width >= 48rem) {
  .search-result {
    --search-thumb: 10rem;

    column-gap: var(--space-12);
  }
}

.search-result__body {
  grid-column: 1;
}

/* HOVER — as post-card.css: hovering anywhere on the row dims its text, not
   the thumbnail. Pointer devices only. */
.search-result__body {
  transition: opacity var(--transition);
}

@media (hover: hover) {
  .search-result:hover .search-result__body {
    opacity: var(--card-hover-opacity);
  }
}

.search-result__link {
  display: block;
  text-decoration: none;
}

.search-result__title {
  margin: 0;
  font-family: var(--font-heading-alt);
  font-weight: var(--weight-heading-alt);
  font-size: var(--text-xl);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-normal);
}

/* Dimmed; matched words come back to full strength (end of file). */
.search-result__excerpt {
  margin: var(--space-1) 0 0;
  font-family: var(--font-body);
  line-height: var(--leading-snug);
  color: var(--color-fg-soft);
}

/* Name at full strength, date muted. */
.search-result__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  margin: var(--space-2) 0 0;
  font-family: var(--font-ui);
  letter-spacing: var(--tracking-slight);
}

.search-result__date {
  color: var(--color-fg-muted);
}

/* TAGS AND AUTHORS — name lists, same rhythm as the panel's nav lists. */
.search__terms {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  font-family: var(--font-ui);
}

.search__term-link {
  text-decoration: none;
}

.search__term-link:hover,
.search__term-link:focus-visible {
  text-decoration: underline;
  text-decoration-thickness: var(--link-underline-width);
}

/* AUTHORS — a grey circle, with a photo faded in only once search.js has
   confirmed it loaded and is big enough ([data-loaded]). Centred against
   the text, since most authors have no bio. */
.search__terms--authors {
  gap: var(--space-5);
}

.search__author {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

/* 5rem = AVATAR_SIZE in search.js — change both together. */
.search__author-media {
  flex: none;
  display: block;
  inline-size: 5rem;
  block-size: 5rem;
  overflow: hidden;
  border-radius: var(--radius-avatar, 50%);
  background-color: color-mix(in srgb, currentColor 15%, transparent);
}

.search__avatar {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity var(--transition);
}

.search__avatar[data-loaded] {
  opacity: 1;
}

.search__author-body {
  min-inline-size: 0;
}

.search__author-bio {
  margin: var(--space-1) 0 0;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  color: var(--color-fg-soft);
}

/* Matched words: a tint of the text colour, no weight change. */
.search__match {
  background-color: color-mix(in srgb, currentColor 15%, transparent);
  color: inherit;
}

/* Inside dimmed text, matches return to the panel's full text colour. */
.search-result__excerpt .search__match,
.search__author-bio .search__match {
  color: var(--color-fg-invert);
}
