/*
 * The search results page: the search bar, the "Results for ..." heading, the tabs
 * with counts, the sort menu and the card grid. Ported from the designer's
 * prototype (styles.css) and adjusted to the Figma frames where they differ; each
 * adjustment is called out.
 *
 * `.search-results` carries the design tokens (search_shared.css). Inter is applied
 * to the chrome below, never to the whole page or the grid: the Swizzel and
 * learning-path cards in it are the same components Discover renders and must look
 * identical there.
 */

/* ------------------------------------------------------------------ page ---
 * 1024px of content, centred, with the design's 56px above and 128px below
 * (the prototype has 80 below). 32px between the bar, heading and results.
 * isolation: isolate so the sort menu's z-index stacks against the grid only.
 */
.search-results {
  display: flex;
  width: 100%;
  max-width: 1088px;
  box-sizing: border-box;
  flex-direction: column;
  gap: 32px;
  margin: 0 auto;
  padding: 56px 32px 128px;
  isolation: isolate;
}

/* The frame is the rest of the column; as a flex child of its own it keeps the same
 * 32px rhythm between the toolbar and the results, and grows so an empty state can
 * centre itself in the space that is left. (turbo-frame is display:inline by default.) */
.search-results-frame {
  display: flex;
  min-width: 0;
  flex: 1 0 auto;
  flex-direction: column;
  gap: 32px;
}

/* No results: the page fills the viewport and the message is centred between the
 * toolbar and 100px above the bottom (88 page padding + 12 on the message block),
 * which is where the design puts it. Below md the app shows a 64px top nav. */
.search-results.is-empty {
  min-height: calc(100dvh - 4rem);
  padding-bottom: 88px;
}

@media (min-width: 768px) {
  .search-results.is-empty { min-height: 100dvh; }
}

.search-results .home-search-empty { flex: 1 1 auto; }

/* --------------------------------------------------------------- the bar ---
 * 44px tall: 9px padding + the 1px border on each side around a 24px line.
 * (The prototype's 10px padding makes it 46.)
 */
.search-results-query {
  position: relative;
  z-index: 6;
  display: flex;
  width: 100%;
  box-sizing: border-box;
  align-items: center;
  gap: 12px;
  padding: 9px 11px;
  background: #fff;
  border: 1px solid rgb(0 0 0 / 6%);
  border-radius: 32px;
  box-shadow: 0 1px 2px rgb(3 7 18 / 5%);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-synthesis: none;
  transition: border-color 150ms ease-out;
}

.search-results-query:focus-within { border-color: rgb(0 0 0 / 12%); }

.search-results-query-icon {
  flex: 0 0 20px;
  color: var(--text-secondary);
}

.search-results-query input[type="search"] {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  height: auto;
  margin: 0;
  padding: 0;
  color: var(--text-primary);
  font: inherit;
  font-size: 16px;
  font-weight: 400;
  line-height: 24px;
  letter-spacing: -0.16px;
  background: transparent;
  border: 0;
  outline: 0;
}

.search-results-query input::placeholder {
  color: var(--text-quaternary);
  opacity: 1;
}

/* Our own clear (x) is the only one. */
.search-results-query input::-webkit-search-decoration,
.search-results-query input::-webkit-search-cancel-button,
.search-results-query input::-webkit-search-results-button,
.search-results-query input::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

.search-results-clear {
  display: grid;
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  place-items: center;
  padding: 0;
  color: var(--text-secondary);
  background: none;
  border: 0;
  cursor: pointer;
}

.search-results-clear[hidden] { display: none; }
.search-results-clear:hover { color: var(--text-primary); }

.search-results-clear:focus-visible {
  outline: 0;
  border-radius: 4px;
  box-shadow: 0 0 0 3px rgb(0 147 255 / 30%);
}

/* --------------------------------------------------------------- heading --- */
.search-results-title {
  position: relative;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding-top: 16px;
  color: var(--text-primary);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-synthesis: none;
  font-size: 32px;
  font-weight: 600;
  line-height: 40px;
  letter-spacing: -0.32px;
}

.search-results-kicker { color: var(--text-quaternary); }

/* A long single-word query must not push the page sideways. (When torph is
 * morphing it, the root is nowrap -- text_morph.js only runs it when it fits.) */
.search-results-query-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* --------------------------------------------------------------- toolbar --- */
.search-results-toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topic-tabs,
.search-sort,
.search-results-count {
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-synthesis: none;
}

/* Tabs with counts. Figma packs them with no gap (the prototype has 4px). They
 * scroll sideways on a phone; 3px of padding with a matching negative margin
 * keeps the focus ring of an edge tab from being clipped by that scroll box. */
.topic-tabs {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  gap: 0;
  padding: 3px;
  margin: -3px;
  overflow-x: auto;
  scrollbar-width: none;
  touch-action: pan-x;
}

.topic-tabs::-webkit-scrollbar { display: none; }

.topic-tabs-pill {
  position: absolute;
  /* left: 0 because the controller translates by the tab's offsetLeft, which
   * already includes the tablist's 3px of padding. */
  top: 3px;
  left: 0;
  z-index: 0;
  width: 0;
  height: 36px;
  background: var(--surface-subtle);
  border-radius: 10px;
  pointer-events: none;
  transform: translateX(0);
  transition:
    transform var(--tabs-dur) var(--tabs-ease),
    width var(--tabs-dur) var(--tabs-ease);
  will-change: transform, width;
}

.topic-tab {
  position: relative;
  z-index: 1;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  height: 36px;
  box-sizing: border-box;
  padding: 8px 12px;
  color: var(--text-tertiary);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  letter-spacing: -0.14px;
  white-space: nowrap;
  text-decoration: none;
  background: transparent;
  border-radius: 10px;
  transition: color var(--tabs-dur) var(--tabs-ease);
}

.topic-tab-count { color: var(--text-quaternary); }

.topic-tab:hover,
.topic-tab.active,
.topic-tab[aria-selected="true"] { color: var(--text-primary); }

.topic-tab.active .topic-tab-count,
.topic-tab[aria-selected="true"] .topic-tab-count { color: var(--text-tertiary); }

/* A tab that has just been clicked looks selected before the server's answer
 * arrives (data-pending, set by search_results_controller); the tab it is leaving
 * goes back to muted as the pill slides away. aria-selected itself does not change
 * until the new results are rendered. */
.topic-tab[data-pending] { color: var(--text-primary); }
.topic-tab[data-pending] .topic-tab-count { color: var(--text-tertiary); }

.topic-tabs[data-pending] .topic-tab[aria-selected="true"]:not([data-pending]) { color: var(--text-tertiary); }
.topic-tabs[data-pending] .topic-tab[aria-selected="true"]:not([data-pending]) .topic-tab-count { color: var(--text-quaternary); }

/* Until the controller has measured the pill, the active tab paints its own
 * highlight, so first paint is never a bare row of tabs. */
.topic-tabs:not(.is-ready) .topic-tab[aria-selected="true"] { background: var(--surface-subtle); }

.topic-tab:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px rgb(0 147 255 / 30%);
}

@media (forced-colors: active) {
  .topic-tab:focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }
}

/* ------------------------------------------------------------- sort menu ---
 * A 105x36 bordered button (padding 7 + the 1px border = 8) and a 224px menu. The
 * prototype's version is .menu-field-*, which clashes with the kit menu's rules in
 * home_hero.css, so these are .search-sort-*.
 */
.search-sort {
  position: relative;
  flex: 0 0 auto;
}

.search-sort-trigger {
  display: flex;
  box-sizing: border-box;
  align-items: center;
  gap: 2px;
  height: 36px;
  padding: 0 7px 0 11px;
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  letter-spacing: -0.14px;
  background: #fff;
  border: 1px solid var(--border-secondary);
  border-radius: 10px;
  cursor: pointer;
  transition:
    background-color 150ms ease-out,
    border-color 150ms ease-out;
}

.search-sort-trigger:hover { background: #fafafa; }

.search-sort-trigger[aria-expanded="true"] { background: #fff; }

.search-sort-trigger:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px rgb(0 147 255 / 30%);
}

.search-sort-trigger svg {
  flex: 0 0 20px;
  color: var(--text-secondary);
}

.search-sort-popover {
  position: absolute;
  top: calc(100% + 4px);
  right: -4px;
  z-index: 6;
  min-width: max(100%, 224px);
  max-width: 280px;
  box-sizing: border-box;
  padding: 4px;
  background: #fff;
  border: 1px solid var(--border-secondary);
  border-radius: 12px;
  box-shadow:
    0 8px 16px -3px rgb(0 0 0 / 4%),
    0 4px 6px -4px rgb(0 0 0 / 8%);
}

.search-sort-menu {
  display: flex;
  flex-direction: column;
}

.search-sort-option {
  display: flex;
  height: 36px;
  box-sizing: border-box;
  align-items: center;
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  letter-spacing: -0.14px;
  text-decoration: none;
  border-radius: 8px;
}

.search-sort-option:hover,
.search-sort-option:focus-visible,
.search-sort-option[aria-checked="true"] { background: var(--surface-subtle); }

.search-sort-option:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px rgb(0 147 255 / 30%);
}

/* --------------------------------------------------------- count and grid ---
 * "24 results", then 24px to the first row (8px of the count's own padding and the
 * grid's 16px row gap in the design). The body is a plain block, not a flex column,
 * so the lazily loaded pages that follow the grid keep their own 16px.
 */
.search-results-body { display: block; }

.search-results-count {
  margin: 0 0 24px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  letter-spacing: -0.14px;
}

.search-results-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

/* Cards share the row height, so mind cards and person cards line up; the card
 * components themselves fill their cell (width/min-width reset, as the prototype). */
.search-results-grid > * { min-width: 0; }

@media (max-width: 1100px) {
  .search-results-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .search-results { padding: 32px 16px 80px; }
}

@media (max-width: 720px) {
  .search-results-grid { grid-template-columns: minmax(0, 1fr); }

  .search-results-title {
    font-size: 24px;
    line-height: 32px;
    letter-spacing: -0.24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .topic-tabs-pill,
  .topic-tab,
  .search-sort-trigger,
  .search-results-query { transition: none !important; }
}
