/* Site search: advanced search box, live suggestions, filter panel, results.
   Used on every public page (header search) and the blog listing pages. */
:root {
  --sx-ink: #0F1B33; --sx-text: #3A465C; --sx-muted: #56627A; --sx-accent: #2456E0; --sx-accent-dark: #1A3FA8;
  --sx-soft: rgba(36, 86, 224, 0.09); --sx-line: #D6DCE6; --sx-bg: #F5F7FB; --sx-mark: #FFE58A;
}

/* ---------- Box ---------- */
.advanced-search-box.sx-box { background: var(--sx-bg); border: 1px solid var(--sx-line); border-radius: 18px; padding: 18px; margin-bottom: 28px; }
.sx-main { display: flex; gap: 10px; }
.sx-field { position: relative; flex: 1; min-width: 0; }
.sx-box .sx-field input[type="search"] {
  width: 100%; height: 52px; padding: 0 84px 0 46px; border: 1.5px solid var(--sx-line); border-radius: 14px;
  font-size: 16px; color: var(--sx-ink); background: #fff; box-sizing: border-box; -webkit-appearance: none; appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
.sx-box .sx-field input[type="search"]::-webkit-search-cancel-button { display: none; }
.sx-box .sx-field input[type="search"]:focus { outline: none; border-color: var(--sx-accent); box-shadow: 0 0 0 4px var(--sx-soft); }
.sx-field-icon { position: absolute; left: 17px; top: 18px; color: var(--sx-muted); font-size: 15px; pointer-events: none; }
.sx-kbd { position: absolute; right: 14px; top: 14px; min-width: 24px; height: 24px; display: grid; place-items: center; font: 600 12px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--sx-muted); border: 1px solid var(--sx-line); border-bottom-width: 2px; border-radius: 6px; background: var(--sx-bg); }
.sx-field:focus-within .sx-kbd { display: none; }
.sx-clear { position: absolute; right: 8px; top: 8px; width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; color: var(--sx-muted); cursor: pointer; font-size: 16px; }
.sx-clear:hover { background: var(--sx-bg); color: var(--sx-ink); }
.sx-field:has(.sx-clear:not([hidden])) .sx-kbd { display: none; }
.sx-submit { display: inline-flex; align-items: center; gap: 8px; height: 52px; padding: 0 24px; border: 0; border-radius: 14px; background: var(--sx-ink); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .15s; }
.sx-submit:hover { background: var(--sx-accent); }
.sx-box :focus-visible { outline: 3px solid var(--sx-accent); outline-offset: 2px; }

.sx-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 12px; }
.sx-toggle, .sx-tips-toggle { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px; border: 1px solid var(--sx-line); border-radius: 999px; background: #fff; color: var(--sx-ink); font-size: 13.5px; font-weight: 600; cursor: pointer; }
.sx-toggle:hover, .sx-tips-toggle:hover, .sx-toggle[aria-expanded="true"] { border-color: var(--sx-accent); color: var(--sx-accent); }
.sx-tips-toggle { margin-left: auto; border-color: transparent; background: transparent; color: var(--sx-muted); font-weight: 500; }
.sx-count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--sx-accent); color: #fff; font-size: 11.5px; display: inline-grid; place-items: center; }
.sx-scope { display: inline-flex; padding: 3px; border-radius: 999px; background: #fff; border: 1px solid var(--sx-line); }
.sx-scope label { position: relative; cursor: pointer; }
.sx-scope input { position: absolute; opacity: 0; pointer-events: none; }
.sx-scope span { display: block; padding: 5px 13px; border-radius: 999px; font-size: 13px; font-weight: 500; color: var(--sx-muted); }
.sx-scope input:checked + span { background: var(--sx-ink); color: #fff; }
.sx-scope input:focus-visible + span { outline: 3px solid var(--sx-accent); outline-offset: 1px; }

.sx-tips { margin-top: 12px; padding: 14px 18px; border-radius: 14px; background: #fff; border: 1px dashed var(--sx-line); font-size: 14px; color: var(--sx-text); }
.sx-tips ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.sx-tips code { font: 13px ui-monospace, Menlo, Consolas, monospace; background: var(--sx-soft); color: var(--sx-accent-dark); padding: 1px 6px; border-radius: 6px; }
.sx-tips kbd, .sx-pop-foot kbd { font: 600 11px ui-monospace, Menlo, Consolas, monospace; border: 1px solid var(--sx-line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: var(--sx-bg); }

.sx-panel { margin-top: 14px; padding: 16px; border-radius: 14px; background: #fff; border: 1px solid var(--sx-line); }
.sx-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.sx-control { display: grid; gap: 5px; font-size: 12px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--sx-muted); }
.sx-control select, .sx-control input[type="date"] { height: 40px; padding: 0 10px; border: 1px solid var(--sx-line); border-radius: 10px; background: #fff; color: var(--sx-ink); font-size: 14px; text-transform: none; letter-spacing: 0; font-weight: 400; width: 100%; box-sizing: border-box; }
.sx-control select:focus, .sx-control input:focus { outline: none; border-color: var(--sx-accent); box-shadow: 0 0 0 3px var(--sx-soft); }
.sx-range { grid-template-columns: 1fr 1fr; gap: 8px; }
.sx-range[hidden] { display: none; }
.sx-range label { display: grid; gap: 5px; }
.sx-panel-actions { display: flex; align-items: center; gap: 14px; margin-top: 14px; }
.sx-apply { height: 40px; padding: 0 18px; border: 0; border-radius: 10px; background: var(--sx-ink); color: #fff; font-weight: 600; font-size: 14px; cursor: pointer; }
.sx-apply:hover { background: var(--sx-accent); }
.sx-reset { font-size: 14px; color: var(--sx-muted); }

.sx-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.sx-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--sx-soft); color: var(--sx-accent-dark); font-size: 13px; font-weight: 600; text-decoration: none !important; }
.sx-chip:hover { background: var(--sx-accent); color: #fff; }
.sx-chip i { font-size: 11px; opacity: .8; }
.sx-chip-clear { font-size: 13px; color: var(--sx-muted); margin-left: 4px; }

/* ---------- Suggestions dropdown ---------- */
.sx-pop { position: absolute; z-index: 1200; left: 0; right: 0; top: calc(100% + 8px); max-height: min(70vh, 560px); overflow-y: auto; background: #fff; border: 1px solid var(--sx-line); border-radius: 16px; box-shadow: 0 24px 60px rgba(15, 27, 51, .18); padding: 8px; text-align: left; }
.sx-pop[hidden] { display: none; }
.sx-pop-label { padding: 8px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--sx-muted); }
.sx-opt { display: flex; gap: 12px; align-items: flex-start; padding: 10px; border-radius: 12px; color: var(--sx-ink) !important; text-decoration: none !important; cursor: pointer; }
.sx-opt:hover, .sx-opt.is-active { background: var(--sx-bg); }
.sx-opt.is-active { box-shadow: inset 3px 0 0 var(--sx-accent); }
.sx-opt-img { width: 56px; height: 42px; flex: none; border-radius: 8px; object-fit: cover; background: var(--sx-bg); }
.sx-opt-ico { width: 32px; height: 32px; flex: none; border-radius: 9px; display: grid; place-items: center; background: var(--sx-soft); color: var(--sx-accent); font-size: 13px; }
.sx-opt-body { min-width: 0; flex: 1; }
.sx-opt-title { display: block; font-weight: 600; font-size: 14.5px; line-height: 1.35; }
.sx-opt-meta { display: block; font-size: 12px; color: var(--sx-muted); margin-top: 2px; }
.sx-opt-snip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 13px; color: var(--sx-text); margin-top: 3px; line-height: 1.45; }
.sx-pop-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 10px 8px; }
.sx-pop-chip { padding: 5px 11px; border-radius: 999px; border: 1px solid var(--sx-line); font-size: 13px; color: var(--sx-ink) !important; text-decoration: none !important; background: #fff; }
.sx-pop-chip:hover, .sx-pop-chip.is-active { border-color: var(--sx-accent); color: var(--sx-accent) !important; background: var(--sx-soft); }
.sx-pop-empty { padding: 14px 10px; font-size: 14px; color: var(--sx-text); }
.sx-pop-empty a { font-weight: 600; }
.sx-pop-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 4px; padding: 10px; border-top: 1px solid var(--sx-line); font-size: 12px; color: var(--sx-muted); }
.sx-pop-all { font-weight: 600; font-size: 13.5px; color: var(--sx-accent) !important; }
.sx-pop-loading { padding: 14px 10px; font-size: 13.5px; color: var(--sx-muted); }
.sx-recent-row { display: flex; align-items: center; }
.sx-recent-row .sx-opt { flex: 1; align-items: center; }
.sx-recent-del { border: 0; background: transparent; color: var(--sx-muted); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; }
.sx-recent-del:hover { background: var(--sx-bg); color: var(--sx-ink); }
mark, .sx-pop mark { background: var(--sx-mark); color: inherit; padding: 0 2px; border-radius: 3px; }

/* ---------- Header search ---------- */
.nav-search-form .sx-field input[type="search"] { width: 280px; height: 40px; border: 1px solid var(--sx-line); border-radius: 10px; padding: 0 12px; font-size: 14px; box-sizing: border-box; -webkit-appearance: none; appearance: none; }
.nav-search-form .sx-field input[type="search"]:focus { outline: none; border-color: var(--sx-accent); box-shadow: 0 0 0 3px var(--sx-soft); }
.nav-search-form .sx-pop { position: fixed; left: auto; width: min(440px, calc(100vw - 24px)); /* top/right set by site-search.js */ }

/* ---------- Results page ---------- */
.sx-results-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; margin: 0 0 6px; }
.sx-results-head h1 { font-size: 22px; margin: 0; color: var(--sx-ink); }
.sx-results-head .sx-meta { font-size: 13px; color: var(--sx-muted); }
.sx-dym { margin: 4px 0 14px; font-size: 15px; color: var(--sx-text); }
.sx-dym a { font-weight: 700; font-style: italic; }
.sx-fuzzy-note { font-size: 13.5px; color: var(--sx-muted); margin: 2px 0 12px; }
.sx-facets { display: grid; gap: 8px; margin: 10px 0 24px; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--sx-line); }
.sx-facet-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.sx-facet-row > span { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--sx-muted); margin-right: 4px; min-width: 84px; }
.sx-facet { display: inline-flex; gap: 6px; align-items: center; padding: 4px 11px; border-radius: 999px; border: 1px solid var(--sx-line); font-size: 13px; color: var(--sx-ink) !important; text-decoration: none !important; background: #fff; }
.sx-facet b { font-weight: 600; color: var(--sx-muted); font-size: 12px; }
.sx-facet:hover { border-color: var(--sx-accent); }
.sx-facet.is-on { background: var(--sx-ink); border-color: var(--sx-ink); color: #fff !important; }
.sx-facet.is-on b { color: #C3CCDD; }
.sx-result-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sx-tag { font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--sx-bg); color: var(--sx-muted) !important; text-decoration: none !important; }
.sx-tag:hover { color: var(--sx-accent) !important; }
.sx-tag.is-hit { background: var(--sx-mark); color: var(--sx-ink) !important; }
.sx-empty { text-align: center; padding: 36px 20px; border: 1px dashed var(--sx-line); border-radius: 18px; color: var(--sx-text); }
.sx-empty h2 { font-size: 20px; color: var(--sx-ink); margin: 0 0 8px; }
.sx-empty ul { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 4px; font-size: 14px; }
.sx-empty .sx-pop-chips { justify-content: center; margin-top: 14px; }

@media (max-width: 640px) {
  .advanced-search-box.sx-box { padding: 14px; }
  .sx-main { flex-direction: column; }
  .sx-submit { justify-content: center; }
  .sx-kbd { display: none; }
  .sx-tips-toggle { margin-left: 0; }
  .sx-grid { grid-template-columns: 1fr; }
  .sx-opt-img { display: none; }
  .sx-pop-foot > span { display: none; }
  .sx-pop-foot { justify-content: flex-end; }
  .nav-search-form .sx-field input[type="search"] { width: 170px; }
  .sx-facet-row > span { min-width: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { .sx-box *, .sx-pop * { transition: none !important; } }

/* ======================================================================
   v3: search window, inline completion, voice, sections, pages, highlights
   ====================================================================== */

/* Inline completion: grey text drawn behind a transparent input */
.sx-field { isolation: isolate; }
.sx-ghost { position: absolute; inset: 0; z-index: 0; pointer-events: none; white-space: pre; overflow: hidden; color: #9AA4B6; box-sizing: border-box; }
.sx-ghost-typed { color: transparent; }
.sx-box .sx-field { background: #fff; border-radius: 14px; }
.sx-box .sx-field input[type="search"] { position: relative; z-index: 1; background: transparent; padding-right: 128px; }
.sx-box .sx-ghost { padding: 0 128px 0 47.5px; font-size: 16px; line-height: 52px; }
.sx-field-icon { z-index: 2; }

/* Voice */
.sx-mic { position: absolute; z-index: 2; right: 48px; top: 8px; width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; color: var(--sx-muted); cursor: pointer; font-size: 15px; }
.sx-mic:hover { background: var(--sx-bg); color: var(--sx-ink); }
.sx-mic.is-listening { color: #fff; background: #D93636; animation: sx-pulse 1.2s ease-in-out infinite; }
@keyframes sx-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(217, 54, 54, .45); } 50% { box-shadow: 0 0 0 7px rgba(217, 54, 54, 0); } }
.sx-clear, .sx-kbd { z-index: 2; }
.sx-box .sx-mic:not([hidden]) ~ .sx-kbd { right: 92px; }

/* Loading indicator on the search icon */
.is-loading .sx-field-icon { animation: sx-spin .8s linear infinite; color: var(--sx-accent); }
@keyframes sx-spin { to { transform: rotate(360deg); } }

/* Section deep links */
.sx-opt-sub { margin-left: 46px; padding-top: 6px; padding-bottom: 6px; }
.sx-opt-sub .sx-opt-ico { width: 26px; height: 26px; font-size: 11px; border-radius: 7px; }
.sx-opt-sub .sx-opt-title { font-size: 13.5px; font-weight: 500; }
.sx-opt-sub .sx-opt-meta { margin: 0 0 1px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.sx-sections { list-style: none; margin: 10px 0 0; padding: 0 0 0 4px; display: grid; gap: 4px; border-left: 2px solid var(--sx-line); }
.sx-sections a { display: inline-flex; gap: 8px; align-items: baseline; padding: 2px 10px; font-size: 14px; color: var(--sx-accent-dark); }
.sx-sections i { font-size: 11px; color: var(--sx-muted); }

/* Pages on the results page */
.sx-page-hits { display: grid; gap: 8px; margin: 0 0 26px; padding: 14px; border-radius: 14px; background: var(--sx-bg); border: 1px solid var(--sx-line); }
.sx-page-hits-label { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--sx-muted); }
.sx-page-hit { display: flex; gap: 12px; align-items: flex-start; padding: 10px; border-radius: 12px; background: #fff; border: 1px solid var(--sx-line); color: var(--sx-ink) !important; text-decoration: none !important; }
.sx-page-hit:hover { border-color: var(--sx-accent); }
.sx-page-hit strong { display: block; font-size: 15px; }
.sx-page-hit small { display: block; font-size: 13px; color: var(--sx-text); margin-top: 2px; }

/* Search window */
html.sx-lock { overflow: hidden; }
.sxp { position: fixed; inset: 0; z-index: 3000; display: flex; justify-content: center; align-items: flex-start; padding: 9vh 16px 16px; }
.sxp[hidden] { display: none; }
.sxp-backdrop { position: absolute; inset: 0; background: rgba(10, 20, 48, .55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: sx-fade .15s ease-out; }
.sxp-panel { position: relative; width: min(720px, 100%); max-height: 82vh; display: flex; flex-direction: column; background: #fff; border-radius: 20px; box-shadow: 0 40px 100px rgba(10, 20, 48, .45); overflow: hidden; animation: sx-rise .18s ease-out; }
@keyframes sx-fade { from { opacity: 0; } }
@keyframes sx-rise { from { opacity: 0; transform: translateY(10px) scale(.985); } }
.sxp-form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.sxp-field { flex: none; border-bottom: 1px solid var(--sx-line); background: #fff; }
.sxp-field input[type="search"] { position: relative; z-index: 1; width: 100%; height: 64px; border: 0; background: transparent; padding: 0 168px 0 54px; font-size: 18px; color: var(--sx-ink); box-sizing: border-box; -webkit-appearance: none; appearance: none; }
.sxp-field input[type="search"]::-webkit-search-cancel-button { display: none; }
.sxp-field input[type="search"]:focus { outline: none; }
.sxp-field .sx-ghost { padding: 0 168px 0 54px; font-size: 18px; line-height: 64px; }
.sxp-field .sx-field-icon { left: 22px; top: 23px; font-size: 17px; }
.sxp-field .sx-clear { top: 14px; right: 66px; }
.sxp-field .sx-mic { top: 14px; right: 106px; }
.sxp-esc { position: absolute; z-index: 2; right: 14px; top: 18px; height: 28px; padding: 0 9px; border: 1px solid var(--sx-line); border-bottom-width: 2px; border-radius: 7px; background: var(--sx-bg); color: var(--sx-muted); font: 600 12px ui-monospace, Menlo, Consolas, monospace; cursor: pointer; }
.sxp-esc:hover { color: var(--sx-ink); }
.sxp-tabs { flex: none; display: flex; align-items: center; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--sx-line); overflow-x: auto; }
.sxp-tabs [role="tab"] { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border: 0; border-radius: 999px; background: transparent; color: var(--sx-muted); font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.sxp-tabs [role="tab"]:hover { color: var(--sx-ink); background: var(--sx-bg); }
.sxp-tabs [role="tab"][aria-selected="true"] { background: var(--sx-ink); color: #fff; }
.sxp-tabs [role="tab"] b { font-size: 11px; font-weight: 700; opacity: .75; }
.sxp-tabs [role="tab"] b:empty { display: none; }
.sxp-advanced { margin-left: auto; font-size: 13px; font-weight: 600; white-space: nowrap; color: var(--sx-accent) !important; }
.sxp-results.sx-pop { position: static; max-height: none; flex: 1; min-height: 0; border: 0; border-radius: 0; box-shadow: none; padding: 8px 10px; overflow-y: auto; }
.sxp-results .sx-pop-foot { position: sticky; bottom: -8px; background: #fff; }
.sx-pop[data-filter] .sx-pop-empty,
.sx-pop[data-filter="articles"] .sx-group:not([data-group="articles"]),
.sx-pop[data-filter="pages"] .sx-group:not([data-group="pages"]),
.sx-pop[data-filter="topics"] .sx-group:not([data-group="topics"]) { display: none; }
.sxp :focus-visible { outline: 3px solid var(--sx-accent); outline-offset: 2px; }

/* Highlights on the article page */
mark.sx-hit { background: var(--sx-mark); color: inherit; border-radius: 3px; padding: 0 2px; scroll-margin: 120px; }
mark.sx-hit.is-current { background: #FFB020; box-shadow: 0 0 0 2px #FFB020; }
.sx-hitbar { position: fixed; z-index: 2500; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 16px; border-radius: 999px; background: var(--sx-ink); color: #fff; box-shadow: 0 16px 40px rgba(10, 20, 48, .35); font-size: 14px; max-width: calc(100vw - 24px); box-sizing: border-box; }
.sx-hitbar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 6px; }
.sx-hitbar strong { color: #FFE58A; }
.sx-hitbar button { width: 34px; height: 34px; flex: none; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .1); color: #fff; cursor: pointer; }
.sx-hitbar button:hover { background: rgba(255, 255, 255, .22); }

@media (max-width: 640px) {
  .sxp { padding: 0; }
  .sxp-panel { width: 100%; max-height: none; height: 100%; border-radius: 0; }
  .sxp-field input[type="search"], .sxp-field .sx-ghost { padding-right: 150px; padding-left: 48px; font-size: 16px; }
  .sxp-field .sx-field-icon { left: 18px; }
  .sxp-advanced { display: none; }
  .sx-opt-sub { margin-left: 18px; }
  .sx-box .sx-field input[type="search"], .sx-box .sx-ghost { padding-right: 90px; }
}
@media (prefers-reduced-motion: reduce) {
  .sxp-backdrop, .sxp-panel { animation: none; }
  .is-loading .sx-field-icon, .sx-mic.is-listening { animation: none; }
}

/* Completion text must use exactly the same font as the input to line up */
.sx-field input[type="search"], .sx-ghost { font-family: inherit; letter-spacing: normal; }
