/* ============================================================================
   Burton v8 — Search overlay
   ----------------------------------------------------------------------------
   Full-screen search modal triggered by the header search button (and the
   ⌘K / Ctrl+K keyboard shortcut). The overlay is always present in the DOM
   (after the .site-header in the template) but hidden via [hidden] until
   opened; this avoids any FOUC and keeps the markup discoverable for
   accessibility tooling.

   The overlay implements the WAI-ARIA combobox pattern:
   - role="combobox" on the input
   - role="listbox" on the results <ul>
   - aria-activedescendant points to the visually-highlighted result <li>
   - Esc closes, ↑↓ navigates results, Enter opens the active result
   ========================================================================= */

/* ── Overlay shell ───────────────────────────────────────────────────────── */

.search-overlay {
  /* Fixed full-viewport positioning so the overlay sits above all page
     content regardless of scroll position. z-index just above the
     sticky header (--z-header is typically 100). */
  position: fixed;
  inset: 0;
  z-index: 200;

  /* The overlay grid: panel anchored toward the top with a subtle
     vertical offset (12vh) — full-center feels too modal for a
     content-discovery tool, but pinning to the very top is jarring. */
  display: grid;
  grid-template-rows: 12vh 1fr;
  justify-items: center;

  /* Backdrop: dark scrim + slight blur. Keeps the page context visible
     so the overlay feels like a layer, not a navigation. */
  background: rgba(11, 18, 22, 0.55);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
  backdrop-filter: blur(8px) saturate(140%);

  /* Fade-in animation. Respects prefers-reduced-motion below. */
  opacity: 0;
  transition: opacity var(--duration-base, 200ms) var(--ease-out, ease-out);
}

/* When [hidden] is present, completely remove from layout. The
   transition above only runs when the overlay is actually rendered. */
.search-overlay[hidden] {
  display: none;
}

/* Open state — set by JS when the overlay is shown. */
.search-overlay.is-open {
  opacity: 1;
}

/* ── Panel (the floating card containing input + results) ────────────────── */

.search-overlay__panel {
  grid-row: 2;
  width: min(720px, calc(100vw - 32px));
  max-height: calc(88vh - 16px);

  display: flex;
  flex-direction: column;
  /* min-height keeps the empty/help state from collapsing too small */
  min-height: 200px;

  background: var(--color-bg, #f2fbf9);
  border: 1px solid var(--color-line, rgba(11, 18, 22, 0.1));
  border-radius: var(--radius-lg, 16px);
  box-shadow:
    0 24px 64px -16px rgba(11, 18, 22, 0.25),
    0 8px 24px -8px rgba(11, 18, 22, 0.15);

  overflow: hidden; /* clip rounded corners */

  /* Subtle scale-in pairing with the backdrop fade. Reduced-motion
     users get plain opacity below. */
  transform: translateY(-8px) scale(0.98);
  transition:
    transform var(--duration-base, 200ms) var(--ease-out, ease-out),
    opacity var(--duration-base, 200ms) var(--ease-out, ease-out);
  opacity: 0;
}

.search-overlay.is-open .search-overlay__panel {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* ── Input row ───────────────────────────────────────────────────────────── */

.search-overlay__input-row {
  display: flex;
  align-items: center;
  gap: var(--space-3, 12px);
  padding: var(--space-4, 16px) var(--space-5, 20px);
  border-bottom: 1px solid var(--color-line, rgba(11, 18, 22, 0.08));
  background: var(--color-surface, #ffffff);
}

.search-overlay__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--color-ink-muted, rgba(11, 18, 22, 0.55));
}

.search-overlay__input {
  flex: 1;
  min-width: 0; /* allow shrinking inside the flex row */
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 0;
  outline: 0;
  padding: 0;
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: var(--fs-md, 18px);
  font-weight: 500;
  color: var(--color-ink, #0b1216);
  line-height: 1.4;
}

.search-overlay__input::placeholder {
  color: var(--color-ink-muted, rgba(11, 18, 22, 0.45));
  font-weight: 400;
}

/* Close button — visible in the input row so users always know how to
   leave. The Esc key works too (and is announced via the kbd hint). */
.search-overlay__close {
  flex-shrink: 0;
  appearance: none;
  background: transparent;
  border: 1px solid var(--color-line, rgba(11, 18, 22, 0.15));
  color: var(--color-ink-muted, rgba(11, 18, 22, 0.55));
  padding: 4px 8px;
  border-radius: var(--radius-sm, 6px);
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: color 120ms ease-out, border-color 120ms ease-out;
}

.search-overlay__close:hover,
.search-overlay__close:focus-visible {
  color: var(--color-ink, #0b1216);
  border-color: var(--color-ink-muted, rgba(11, 18, 22, 0.4));
  outline: 0;
}

/* ── Results area (scrolling region) ─────────────────────────────────────── */

.search-overlay__results-wrap {
  flex: 1;
  min-height: 0; /* required so the flex child can scroll inside */
  overflow-y: auto;
  /* Subtle inset shadow at the top to hint scrollability when content
     overflows. Keeps the input row visually grounded. */
  background: var(--color-bg, #f2fbf9);
}

.search-overlay__results {
  list-style: none;
  margin: 0;
  padding: var(--space-2, 8px) 0;
}

/* ── Individual result ───────────────────────────────────────────────────── */

.search-overlay__result {
  /* The whole row is the click target. Anchor inside fills the cell. */
  padding: 0;
}

.search-overlay__result-link {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-3, 12px);
  padding: var(--space-3, 12px) var(--space-5, 20px);
  text-decoration: none;
  color: var(--color-ink, #0b1216);
  border-left: 3px solid transparent;
  transition:
    background 80ms ease-out,
    border-color 80ms ease-out;
}

/* Hover + keyboard-active (set by JS via aria-selected) share the same
   visual treatment. This is the standard combobox pattern: mouse hover
   and keyboard nav surface the same affordance. */
.search-overlay__result-link:hover,
.search-overlay__result-link:focus-visible,
.search-overlay__result[aria-selected="true"] .search-overlay__result-link {
  background: var(--color-surface, #ffffff);
  border-left-color: var(--color-accent, #00b3a4);
  outline: 0;
}

/* Type icon — post (article) vs page (calculator/tool). Subtle, just
   a visual disambiguator so users can spot the page type in results. */
.search-overlay__result-type {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--color-ink-muted, rgba(11, 18, 22, 0.5));
}

.search-overlay__result-text {
  min-width: 0; /* allow truncation in flex parent */
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-overlay__result-title {
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: var(--fs-base, 16px);
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-ink, #0b1216);
  /* Single-line ellipsis on long titles to keep result rows uniform. */
  display: -webkit-box;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-overlay__result-meta {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-ink-muted, rgba(11, 18, 22, 0.5));
  /* Excerpt is a thin secondary line; clip to one line. */
  display: -webkit-box;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Matched-term highlight injected by the JS scorer. <mark> already gets
   default yellow background in browsers — we override to a subtle
   accent tint that fits the brand palette. */
.search-overlay__result-title mark,
.search-overlay__result-meta mark {
  background: rgba(0, 179, 164, 0.18);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

/* Right-side hint — "Enter" key on the active result. */
.search-overlay__result-hint {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  font-weight: 600;
  color: var(--color-ink-muted, rgba(11, 18, 22, 0.4));
  letter-spacing: 0.05em;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 120ms ease-out;
}

.search-overlay__result[aria-selected="true"] .search-overlay__result-hint {
  opacity: 1;
  color: var(--color-accent, #00b3a4);
}

/* ── Empty / help / no-results states ────────────────────────────────────── */

.search-overlay__state {
  padding: var(--space-6, 24px) var(--space-5, 20px);
  text-align: center;
  color: var(--color-ink-muted, rgba(11, 18, 22, 0.55));
}

.search-overlay__state-title {
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: var(--fs-base, 16px);
  font-weight: 600;
  color: var(--color-ink, #0b1216);
  margin: 0 0 var(--space-2, 8px);
}

.search-overlay__state-text {
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: var(--fs-sm, 14px);
  line-height: 1.5;
  margin: 0;
}

/* ── Footer (keyboard hints) ─────────────────────────────────────────────── */

.search-overlay__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3, 12px);
  padding: var(--space-3, 12px) var(--space-5, 20px);
  border-top: 1px solid var(--color-line, rgba(11, 18, 22, 0.08));
  background: var(--color-surface, #ffffff);
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  color: var(--color-ink-muted, rgba(11, 18, 22, 0.5));
}

.search-overlay__hints {
  display: flex;
  align-items: center;
  gap: var(--space-4, 16px);
  flex-wrap: wrap;
}

.search-overlay__hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.search-overlay__kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border: 1px solid var(--color-line, rgba(11, 18, 22, 0.15));
  border-radius: 3px;
  background: var(--color-bg, #f2fbf9);
  font-family: var(--font-mono, monospace);
  font-size: 10px;
  font-weight: 600;
  color: var(--color-ink, #0b1216);
  line-height: 1;
}

.search-overlay__count {
  font-variant-numeric: tabular-nums;
}

/* ── Mobile adjustments ──────────────────────────────────────────────────── */

@media (max-width: 720px) {
  .search-overlay {
    /* Pin panel near the top on mobile so the on-screen keyboard
       doesn't shove it offscreen. */
    grid-template-rows: 6vh 1fr;
  }

  .search-overlay__panel {
    width: calc(100vw - 16px);
    max-height: calc(94vh - 16px);
    border-radius: var(--radius-md, 12px);
  }

  .search-overlay__input {
    font-size: 16px; /* iOS zoom prevention — 16px is the safe threshold */
  }

  .search-overlay__footer {
    /* The hints get noisy on small screens — keep only the result
       count visible. Touch users don't need keyboard hints anyway. */
    flex-direction: row-reverse;
  }

  .search-overlay__hints {
    display: none;
  }

  .search-overlay__result-link {
    padding-inline: var(--space-4, 16px);
  }
}

/* ── Reduced motion ──────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .search-overlay,
  .search-overlay__panel,
  .search-overlay__result-link,
  .search-overlay__result-hint {
    transition: none;
  }
  .search-overlay__panel {
    transform: none;
  }
}
