/* Header search — the field, its key badge, the combobox popover, and the
 * narrow-viewport overlay row.
 *
 * Split out of style.css, which passed 800 lines when this surface landed —
 * same reason surfaces.css exists. Loaded AFTER style.css so it can lean on
 * the tokens and the focus ring defined there; nothing here is overridden by
 * a later sheet, because every selector is .hdr-*.
 */


/* ------------------------------------------------------- header search
 *
 * Search stopped being a page and became a capability. The field is the hero
 * field one size down: a rule you write on, no fill, no radius, no box. It
 * carries the auto margin, so the brand sits hard left and nav + theme sit
 * hard right with the field between them.
 */

.hdr-search {
  position: relative;
  flex: 1 1 180px; min-width: 0; max-width: 340px;
  margin-right: auto;
}

.hdr-field {
  display: flex; align-items: center; gap: 7px;
  min-height: 34px; padding: 0 0 2px;
  background: transparent;
  border: none; border-bottom: 1px solid var(--rule);
  border-radius: 0;
  transition-property: border-color, box-shadow;
  transition-duration: var(--fast);
  transition-timing-function: var(--ease-snap);
}
/* The rule IS the focus indicator for the wrapper; the input keeps the global
 * :focus-visible outline on top of it.
 *
 * The focused rule is 2px, but it is 1px of border plus 1px of inset shadow
 * rather than a border-width change. Animating border-width reflows the field
 * and everything after it in the bar; a shadow is composited. */
.hdr-field:hover { border-bottom-color: var(--text-mute); }
.hdr-field:focus-within {
  border-bottom-color: var(--accent);
  box-shadow: inset 0 -2px 0 -1px var(--accent);
}

.hdr-icon { color: var(--text-mute); font-size: 15px; line-height: 1; flex: none; }

.hdr-input {
  flex: 1; min-width: 0;
  background: none; border: none; outline: none;
  color: var(--text); font: inherit; font-size: var(--t-small);
}
.hdr-input::placeholder { color: var(--text-mute); }
.hdr-input::-webkit-search-cancel-button { appearance: none; }

/* A key hint, so it is set like a key. It gets out of the way the moment the
 * field is in use, and it never appears where there is no keyboard. */
.hdr-key {
  flex: none;
  padding: 1px 5px;
  border: 1px solid var(--rule-faint); border-radius: var(--radius-sm);
  color: var(--text-mute); font-family: var(--mono); font-size: var(--t-micro);
  line-height: 1.4;
}

/* The narrow-viewport trigger. Hidden above 720px, where the field itself fits. */
.hdr-toggle {
  display: none;
  place-items: center;
  width: 36px; height: 36px;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius);
  color: var(--text-dim); font-size: 17px; line-height: 1; cursor: pointer;
  transition-property: color, border-color; transition-duration: var(--fast);
}
.hdr-toggle:hover { color: var(--text); border-color: var(--rule); }

.hdr-panel {
  position: absolute; z-index: 45;
  top: calc(100% + 6px); left: 0;
  width: min(400px, calc(100vw - 2 * var(--gap)));
  max-height: min(66vh, 460px); overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  /* Transform and opacity only, so it stays on the compositor and never
   * reflows the bar. The blanket prefers-reduced-motion guard below collapses
   * it to 1ms — the panel still appears, it just does not travel. */
  animation: hdr-drop var(--fast) var(--ease-snap) both;
}
@keyframes hdr-drop {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

.hdr-group + .hdr-group { border-top: 1px solid var(--rule-faint); }
.hdr-group-label { padding: 8px var(--gap) 3px; }

.hdr-opt {
  display: flex; align-items: center; gap: var(--gap-sm);
  padding: 7px var(--gap);
  border-bottom: 1px solid var(--rule-faint);
  color: var(--text); font-size: var(--t-small);
  cursor: pointer;
}
.hdr-opt:last-child { border-bottom: none; }
/* Hover and keyboard produce the SAME highlight — a keyboard walk must not be
 * a second-class way to read this list. */
.hdr-opt:hover, .hdr-opt.is-active { background: var(--ink-wash); }
.hdr-opt.is-active { box-shadow: inset 2px 0 0 var(--accent); }

.hdr-opt-name {
  min-width: 0; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hdr-opt-id {
  flex: none; color: var(--text-mute);
  font-family: var(--mono); font-size: var(--t-micro);
}
.hdr-opt-side {
  flex: none; color: var(--text-mute);
  font-size: var(--t-micro); font-variant-numeric: tabular-nums;
}
.hdr-opt-all { color: var(--accent); font-weight: 550; }

.hdr-empty { padding: var(--gap); color: var(--text-mute); font-size: var(--t-small); }

/* Below 720px the field collapses to a button in the bar and expands as an
 * overlay row directly under it. --topbar-h never changes, so nothing shifts. */
@media (max-width: 720px) {
  .hdr-search { flex: none; max-width: none; }
  .hdr-key { display: none; }
  .hdr-toggle { display: inline-grid; }
  .hdr-dock { display: none; }
  .hdr-search.is-open .hdr-dock {
    display: block;
    position: fixed; z-index: 45;
    top: var(--topbar-h); left: 0; right: 0;
    padding: var(--gap-sm) var(--gap) var(--gap);
    background: var(--bg);
    border-bottom: 1px solid var(--rule);
  }
  .hdr-search.is-open .hdr-panel {
    position: static;
    width: auto; margin-top: var(--gap-sm);
    max-height: min(58vh, 420px);
  }
}