/* Site search — public styles. Self-contained (no Tailwind), loaded by the module on every public
 * page. A design restyles it by setting the --ls-search-* variables anywhere up the tree (:root,
 * html.dark, its header); the module only ever READS them, with its own light/dark defaults as
 * fallbacks (the --_ls-* values below), so the design's values win whatever the stylesheet order.
 *
 *   --ls-search-fg          icon and text colour of the trigger (inherits the surrounding text)
 *   --ls-search-fg-strong   titles in the panel            --ls-search-bg      field and panel background
 *   --ls-search-muted       excerpts, counts                --ls-search-line    borders
 *   --ls-search-accent      focus ring, "see all", the floating button
 *   --ls-search-hover       hovered / keyboard-selected row --ls-search-mark    highlighted query words
 *   --ls-search-radius      corner radius (10px)            --ls-search-size    trigger button size (40px)
 *   --ls-search-field-w     the expanded field (260px)      --ls-search-panel-w the dropdown (520px)
 *   --ls-search-font        font-family (inherits)          --ls-search-z       z-index (1100)
 *   --ls-search-shadow      the dropdown's shadow
 *
 * Dark mode follows the platform's html.dark class. */

.ls-search, .ls-search-panel, .ls-search-fab, .ls-search-page {
  --_ls-bg: #ffffff;
  --_ls-fg: #111827;
  --_ls-muted: #6b7280;
  --_ls-line: rgba(17, 24, 39, .14);
  --_ls-hover: rgba(17, 24, 39, .06);
  --_ls-mark: rgba(250, 204, 21, .45);
  --_ls-accent: #2563eb;
  --_ls-shadow: 0 14px 44px rgba(0, 0, 0, .18);
  --_ls-panel-w: 520px;
}
html.dark .ls-search, html.dark .ls-search-panel, html.dark .ls-search-fab, html.dark .ls-search-page {
  --_ls-bg: #111827;
  --_ls-fg: #f3f4f6;
  --_ls-muted: #9ca3af;
  --_ls-line: rgba(255, 255, 255, .14);
  --_ls-hover: rgba(255, 255, 255, .07);
  --_ls-mark: rgba(250, 204, 21, .28);
  --_ls-shadow: 0 14px 44px rgba(0, 0, 0, .55);
}

/* ------------------------------------------------------------ the trigger: icon + collapsed field */
.ls-search { position: relative; display: inline-flex; align-items: center; color: var(--ls-search-fg, inherit); font-family: var(--ls-search-font, inherit); vertical-align: middle; }
.ls-search__toggle { display: inline-flex; align-items: center; justify-content: center; width: var(--ls-search-size, 40px); height: var(--ls-search-size, 40px); margin: 0; padding: 0; border: 0; border-radius: 8px; background: transparent; color: inherit; cursor: pointer; line-height: 1; -webkit-tap-highlight-color: transparent; }
.ls-search__toggle:hover, .ls-search.is-open .ls-search__toggle { color: var(--ls-search-accent, var(--_ls-accent)); }
.ls-search__toggle:focus-visible { outline: 2px solid var(--ls-search-accent, var(--_ls-accent)); outline-offset: 2px; }
.ls-search__icon { display: block; }
.ls-search__form { display: none; position: absolute; top: 50%; z-index: var(--ls-search-z, 1100); margin: 0; transform: translateY(-50%); }
.ls-search--expand-left .ls-search__form { right: calc(100% + 4px); }
.ls-search--expand-right .ls-search__form { left: calc(100% + 4px); }
.ls-search--expand-down .ls-search__form { top: calc(100% + 6px); right: 0; transform: none; }
.ls-search.is-open:not(.is-overlay) .ls-search__form { display: block; animation: ls-search-in .14s ease-out; }
.ls-search__input { display: block; width: var(--ls-search-field-w, 260px); max-width: calc(100vw - 72px); height: var(--ls-search-size, 40px); margin: 0; padding: 0 36px 0 12px; box-sizing: border-box; border: 1px solid var(--ls-search-line, var(--_ls-line)); border-radius: var(--ls-search-radius, 10px); background: var(--ls-search-bg, var(--_ls-bg)); color: var(--ls-search-fg-strong, var(--_ls-fg)); font: inherit; font-size: 16px; line-height: normal; box-shadow: var(--ls-search-shadow, var(--_ls-shadow)); outline: none; -webkit-appearance: none; appearance: none; }
.ls-search__input::placeholder { color: var(--ls-search-muted, var(--_ls-muted)); opacity: 1; }
.ls-search__input:focus { border-color: var(--ls-search-accent, var(--_ls-accent)); }
.ls-search__input::-webkit-search-cancel-button, .ls-search__input::-webkit-search-decoration { -webkit-appearance: none; display: none; }
.ls-search__close { position: absolute; top: 50%; right: 5px; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; margin: 0; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--ls-search-muted, var(--_ls-muted)); cursor: pointer; transform: translateY(-50%); }
.ls-search__close:hover { color: var(--ls-search-fg-strong, var(--_ls-fg)); background: var(--ls-search-hover, var(--_ls-hover)); }
.ls-search--button .ls-search__form { display: none !important; }

/* ------------------------------------------------------------ the floating button (optional) */
.ls-search-fab { position: fixed; right: 18px; bottom: 18px; z-index: calc(var(--ls-search-z, 1100) - 1); display: inline-flex; align-items: center; justify-content: center; width: 52px; height: 52px; margin: 0; padding: 0; border: 0; border-radius: 50%; background: var(--ls-search-accent, var(--_ls-accent)); color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.ls-search-fab:hover { filter: brightness(1.08); }
.ls-search-fab:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ------------------------------------------------------------ the panel: dropdown on wide screens */
.ls-search-panel { position: absolute; z-index: var(--ls-search-z, 1100); display: flex; flex-direction: column; width: min(var(--ls-search-panel-w, var(--_ls-panel-w)), calc(100vw - 24px)); max-height: min(70vh, 640px); box-sizing: border-box; border: 1px solid var(--ls-search-line, var(--_ls-line)); border-radius: var(--ls-search-radius, 10px); background: var(--ls-search-bg, var(--_ls-bg)); color: var(--ls-search-fg-strong, var(--_ls-fg)); font-family: var(--ls-search-font, inherit); box-shadow: var(--ls-search-shadow, var(--_ls-shadow)); overflow: hidden; text-align: left; }
.ls-search-panel[hidden] { display: none; }
.ls-search-panel__bar { display: none; }
.ls-search-panel__body { flex: 1 1 auto; min-height: 0; padding: 6px; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.ls-search__status, .ls-search__empty { margin: 0; padding: 16px 12px; color: var(--ls-search-muted, var(--_ls-muted)); font-size: 14px; text-align: center; }
.ls-search-panel[aria-busy="true"] .ls-search-panel__body { opacity: .6; }

/* ------------------------------------------------------------ the panel: full screen on phones, and for the floating button */
.ls-search-panel--overlay { position: fixed; inset: 0; width: auto; max-width: none; max-height: none; border: 0; border-radius: 0; box-shadow: none; }
.ls-search-panel--overlay .ls-search-panel__bar { position: sticky; top: 0; z-index: 1; display: flex; flex: 0 0 auto; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--ls-search-line, var(--_ls-line)); background: var(--ls-search-bg, var(--_ls-bg)); }
.ls-search-panel__bar .ls-search__icon { flex: 0 0 auto; color: var(--ls-search-muted, var(--_ls-muted)); }
.ls-search-panel__bar-input { flex: 1 1 auto; min-width: 0; height: 44px; margin: 0; padding: 0 12px; box-sizing: border-box; border: 1px solid var(--ls-search-line, var(--_ls-line)); border-radius: var(--ls-search-radius, 10px); background: transparent; color: inherit; font: inherit; font-size: 16px; outline: none; -webkit-appearance: none; appearance: none; }
.ls-search-panel__bar-input:focus { border-color: var(--ls-search-accent, var(--_ls-accent)); }
.ls-search-panel__bar-input::-webkit-search-cancel-button, .ls-search-panel__bar-input::-webkit-search-decoration { -webkit-appearance: none; display: none; }
.ls-search-panel__bar-close { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; margin: 0; padding: 0; border: 0; border-radius: 8px; background: transparent; color: inherit; cursor: pointer; }
.ls-search-panel__bar-close:hover { background: var(--ls-search-hover, var(--_ls-hover)); }
.ls-search-panel--overlay .ls-search-panel__body { padding: 8px 10px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
body.ls-search-lock { overflow: hidden; }

/* ------------------------------------------------------------ the results */
.ls-search__legend { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 6px 8px; }
.ls-search__chip { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 5px 10px; border: 1px solid var(--ls-search-line, var(--_ls-line)); border-radius: 999px; background: transparent; color: inherit; font: inherit; font-size: 12px; line-height: 1.2; cursor: pointer; }
.ls-search__chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--ls-c, #888); }
.ls-search__chip b { font-weight: 600; color: var(--ls-search-muted, var(--_ls-muted)); }
.ls-search__chip:hover { background: var(--ls-search-hover, var(--_ls-hover)); }
.ls-search__chip[aria-pressed="true"] { background: var(--ls-c, #888); border-color: var(--ls-c, #888); color: #fff; }
.ls-search__chip[aria-pressed="true"] i { background: #fff; }
.ls-search__chip[aria-pressed="true"] b { color: rgba(255, 255, 255, .85); }
.ls-search__list { margin: 0; padding: 0; list-style: none; }
.ls-search__item { margin: 0; padding: 0; }
.ls-search__item.is-hidden { display: none; }
.ls-search__link { display: flex; align-items: center; gap: 10px; margin: 2px 0; padding: 6px 10px 6px 8px; border-left: 3px solid var(--ls-c, #888); border-radius: 8px; color: inherit; text-decoration: none; }
.ls-search__link:hover, .ls-search__link.is-active { background: var(--ls-search-hover, var(--_ls-hover)); color: inherit; text-decoration: none; }
.ls-search__link:focus-visible { outline: 2px solid var(--ls-search-accent, var(--_ls-accent)); outline-offset: -2px; }
.ls-search__thumb { position: relative; flex: 0 0 44px; display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 8px; background: var(--ls-search-hover, var(--_ls-hover)); overflow: hidden; }
.ls-search__thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.ls-search__thumb--ph { color: var(--ls-c, #888); font-size: 18px; font-weight: 700; }
.ls-search__thumb--ph::before { content: ""; position: absolute; inset: 0; background: var(--ls-c, #888); opacity: .14; }
.ls-search__body { flex: 1 1 auto; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ls-search__title { font-size: 15px; font-weight: 600; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ls-search__excerpt { font-size: 12.5px; line-height: 1.3; color: var(--ls-search-muted, var(--_ls-muted)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ls-search__meta { flex: 0 0 auto; font-size: 12px; color: var(--ls-search-muted, var(--_ls-muted)); white-space: nowrap; }
.ls-search__mark { padding: 0 1px; border-radius: 2px; background: var(--ls-search-mark, var(--_ls-mark)); color: inherit; }
.ls-search__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ls-search__more { display: block; margin: 4px 6px 2px; padding: 10px; border-top: 1px solid var(--ls-search-line, var(--_ls-line)); color: var(--ls-search-accent, var(--_ls-accent)); font-size: 13px; text-align: center; text-decoration: none; }
.ls-search__more:hover { text-decoration: underline; }
.ls-search__more b { margin-left: 4px; }
/* on the full-screen panel there is room for two lines but none sideways */
.ls-search-panel--overlay .ls-search__title, .ls-search-panel--overlay .ls-search__excerpt, .ls-search-page .ls-search__title, .ls-search-page .ls-search__excerpt { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ls-search-panel--overlay .ls-search__meta { display: none; }

/* ------------------------------------------------------------ the /search page */
.ls-search-page { max-width: 760px; margin: 0 auto; padding: 24px 16px 48px; box-sizing: border-box; color: var(--ls-search-fg-strong, inherit); }
.ls-search-page__form { display: flex; gap: 8px; margin: 0 0 18px; }
.ls-search-page__input { flex: 1 1 auto; min-width: 0; height: 46px; padding: 0 14px; box-sizing: border-box; border: 1px solid var(--ls-search-line, var(--_ls-line)); border-radius: var(--ls-search-radius, 10px); background: var(--ls-search-bg, var(--_ls-bg)); color: var(--ls-search-fg-strong, var(--_ls-fg)); font: inherit; font-size: 16px; outline: none; -webkit-appearance: none; appearance: none; }
.ls-search-page__input:focus { border-color: var(--ls-search-accent, var(--_ls-accent)); }
.ls-search-page__btn { display: inline-flex; align-items: center; gap: 8px; height: 46px; padding: 0 16px; border: 0; border-radius: var(--ls-search-radius, 10px); background: var(--ls-search-accent, var(--_ls-accent)); color: #fff; font: inherit; font-size: 15px; cursor: pointer; }
.ls-search-page__count { margin: 0 0 10px; font-size: 15px; font-weight: 500; color: var(--ls-search-muted, var(--_ls-muted)); }
.ls-search-page .ls-search__link { padding: 9px 12px 9px 10px; }
.ls-search-page .ls-search__thumb { flex-basis: 56px; width: 56px; height: 56px; }

@keyframes ls-search-in { from { opacity: 0; transform: translateY(-50%) translateX(6px); } to { opacity: 1; transform: translateY(-50%) translateX(0); } }
.ls-search--expand-down.is-open:not(.is-overlay) .ls-search__form { animation: none; }
@media (prefers-reduced-motion: reduce) { .ls-search.is-open .ls-search__form { animation: none; } }
@media print { .ls-search, .ls-search-panel, .ls-search-fab { display: none !important; } }
