/* Global search: the open pill, the results panel under it, the full-screen sheet on a phone.
 * Built by js/ui/search.js; the closed pill in the header is in css/shell.css.
 */

.search-root { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
.search-root > * { pointer-events: auto; }
/* On a laptop the box and the panel position themselves; the wrapper adds nothing. */
.search-head { display: contents; }

/* ---- the box: the pill, open ---- */

.search-box {
  position: fixed; display: flex; align-items: center; gap: var(--space-8); height: 42px; padding: 0 var(--space-16);
  border-radius: var(--radius-pill); background: var(--card); border: 1px solid var(--accent);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .08); color: var(--muted);
}
/* While it is open, the closed pill underneath is hidden, so its edge never shows around the open box
   (owner's feedback, 17 Nov: "it sits over itself and pokes out to the right"). */
#search-btn[aria-expanded="true"] { visibility: hidden; }
.search-box > .material-symbols-rounded { font-size: 20px; vertical-align: 0; flex: none; }
.search-input {
  flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; color: var(--text);
  font: 500 14px var(--font-family); padding: 0;
}
.search-input::placeholder { color: var(--muted); opacity: 1; }
/* The box already shows the focus (an accent edge and a halo), so the field inside does not draw a
   second ring. test/a11y-static.mjs allows exactly this: a wrapper that rings on :focus-within. */
/* One clean ring: the outline sits right on the edge rather than a gap away from it. */
.search-box:focus-within { outline: 2px solid var(--accent); outline-offset: 0; }
.search-input:focus-visible { outline: 0; }

/* ---- the panel ---- */

.search-panel {
  position: fixed; width: min(600px, calc(100vw - 32px)); max-height: min(72vh, 600px);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-card);
  box-shadow: var(--shadow-lg);
}
.search-list { overflow-y: auto; padding-bottom: var(--space-8); overscroll-behavior: contain; }
.search-list[hidden], .search-note[hidden], .search-foot[hidden] { display: none; }

.rg-h {
  display: flex; align-items: center; gap: var(--space-8); padding: var(--space-16) var(--space-24) var(--space-8); font-size: 12.5px; font-weight: 700; color: var(--muted);
}
.rg-count { font-weight: 600; font-variant-numeric: tabular-nums; }
.search-row {
  display: flex; align-items: center; gap: var(--space-16); min-height: 44px; padding: var(--space-8) var(--space-24); font-size: 14.5px;
  cursor: pointer; color: var(--text);
}
.search-row.on { background: var(--accent-soft); }
.search-row-icon { display: inline-flex; width: 20px; flex: none; color: var(--muted); }
.search-row-icon .material-symbols-rounded { font-size: 20px; vertical-align: 0; }
.search-row-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* The letters that matched: bold and in the accent, so it is weight as well as colour. */
.search-row mark { background: transparent; color: var(--accent-dark); font-weight: 800; }
.search-row .rm { flex: 0 1 45%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; text-align: right; margin-left: auto; }
.search-more .search-row-title { color: var(--accent-dark); font-weight: 700; font-size: 13.5px; }

.search-note { padding: var(--space-24) var(--space-24); }
.search-note-title { margin: 0; font-weight: 700; font-size: 15px; }
.search-note-text { margin: var(--space-4) 0 0; color: var(--muted); font-size: 14px; line-height: 1.5; }

.search-foot {
  display: flex; align-items: center; gap: var(--space-16); padding: var(--space-16) var(--space-24); border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--muted);
}
.search-hints { display: flex; gap: var(--space-16); flex-wrap: wrap; }
.search-count { margin-left: auto; white-space: nowrap; }

/* ---- the outline a chosen result gets on its page ---- */

.search-hit { scroll-margin-top: 150px; outline: 2px solid var(--accent); outline-offset: 4px; border-radius: var(--radius); background: var(--accent-soft); transition: background .6s ease; }
@media (prefers-reduced-motion: reduce) { .search-hit { transition: none; } }

/* ---- the phone: a full-screen sheet, no scrim, the box at the top with Cancel ---- */

@media (max-width: 640px) {
  .search-root.is-sheet { background: var(--bg); display: flex; flex-direction: column; pointer-events: auto; }
  .search-root.is-sheet .search-head {
    display: flex; align-items: center; gap: var(--space-4); flex: none;
    padding: max(var(--space-16), env(safe-area-inset-top)) var(--space-16) var(--space-8) var(--space-24);
  }
  .search-root.is-sheet .search-box { position: static; flex: 1; min-width: 0; height: 48px; width: auto !important; }
  .search-root.is-sheet .search-input { font-size: 16px; }
  .search-cancel {
    flex: none; min-height: 44px; min-width: 44px; padding: 0 var(--space-8); border: 0; background: transparent;
    color: var(--accent-dark); font: 700 15px var(--font-family); border-radius: var(--radius-pill);
  }
  .search-root.is-sheet .search-panel {
    position: static; width: auto; max-height: none; flex: 1; min-height: 0; border: 0; border-radius: 0;
    box-shadow: none; background: transparent;
  }
  .search-root.is-sheet .rg-h, .search-root.is-sheet .search-row, .search-root.is-sheet .search-note { padding-left: var(--space-24); padding-right: var(--space-24); }
  .search-root.is-sheet .search-row { min-height: 52px; border-radius: var(--radius); margin: 0 var(--space-8); padding-left: var(--space-16); padding-right: var(--space-16); }
  .search-root.is-sheet .rg-h { padding-left: var(--space-24); }
  .search-root.is-sheet .search-foot { display: none; }
}
