/* Header broker search (header.php [data-fxm-hsearch], assets/js/fxm-header-search.js).
   Result rows come from fxm-broker-picker.css (shared with the exposure form);
   this sheet only adds the header chrome around them.

   Desktop (>= 768px): a 40px trigger in the header's white-pill style. Opening
   morphs that circle into a full field (clip-path, right edge fixed) laid over
   the nav, with a results card hanging from the header's bottom edge and a light
   scrim over the page. Below 768px: a full-screen sheet with a Cancel button. */

.fxm-hsearch {
  --fxm-hsearch-w: 440px;
  --fxm-hsearch-primary: var(--color-primary, #4f34d9);
  --fxm-hsearch-ink: #1f2335;
  --fxm-hsearch-muted: #62677d;   /* 5.6:1 on white */
  --fxm-hsearch-faint: #8a90a3;
  --fxm-hsearch-line: #e6e4f0;
  --fxm-hsearch-accent: linear-gradient(90deg, #6c54f7 0%, #89dfd7 100%);
  --fxm-hsearch-ease: cubic-bezier(.2, .8, .2, 1);
  position: relative;
  display: flex;
  flex: none;
}
/* The script drives visibility through [hidden]; no display rule below may revive it. */
.fxm-hsearch [hidden] { display: none !important; }

/* ---------- trigger ---------- */
.fxm-hsearch__trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(79, 52, 217, .1);
  border-radius: 999px;
  background: rgba(255, 255, 255, .92);
  color: rgba(39, 46, 66, .62);
  box-shadow: 0 8px 20px -12px rgba(0, 0, 0, .1);
  cursor: pointer;
  transition: color .2s ease, border-color .2s ease, box-shadow .3s ease, transform .3s ease, opacity .12s ease, visibility 0s;
}
.fxm-hsearch__trigger:hover {
  color: var(--fxm-hsearch-primary);
  border-color: rgba(79, 52, 217, .22);
  box-shadow: 0 10px 24px -12px rgba(0, 0, 0, .12);
  transform: translateY(-2px);
}
.fxm-hsearch__trigger:focus-visible { outline: 2px solid var(--fxm-hsearch-primary); outline-offset: 2px; }
/* The opening field covers this exact spot; keep it out of the tab order meanwhile. */
.fxm-hsearch.is-open .fxm-hsearch__trigger {
  opacity: 0;
  visibility: hidden;
  transition: opacity .12s ease, visibility 0s linear .12s;
}

/* ---------- page scrim (below the 72px header) ---------- */
.fxm-hsearch__scrim {
  position: fixed;
  inset: 72px 0 0;
  z-index: 20;
  background: rgba(23, 20, 51, .16);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .2s ease;
}
.fxm-hsearch.is-open .fxm-hsearch__scrim { opacity: 1; }

/* ---------- field ---------- */
.fxm-hsearch__panel {
  position: absolute;
  z-index: 30;
  top: 50%;
  right: 0;
  width: var(--fxm-hsearch-w);
  translate: 0 -50%;
}
.fxm-hsearch__bar { display: flex; align-items: center; }
.fxm-hsearch__field {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  min-width: 0;
  height: 44px;
  padding: 0 8px 0 15px;
  border: 1px solid rgba(79, 52, 217, .34);
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(79, 52, 217, .09), 0 10px 24px -14px rgba(35, 26, 76, .35);
  /* Closed = only the trigger-sized circle at the right edge is visible. */
  clip-path: inset(0 0 0 calc(100% - 40px) round 999px);
  transition: clip-path .26s var(--fxm-hsearch-ease);
}
.fxm-hsearch.is-open .fxm-hsearch__field { clip-path: inset(-12px -12px -40px -12px round 999px); }
.fxm-hsearch__field > * { opacity: 0; transition: opacity .14s ease; }
.fxm-hsearch.is-open .fxm-hsearch__field > * { opacity: 1; transition-delay: .09s; }
.fxm-hsearch__icon { flex: none; color: var(--fxm-hsearch-primary); }
.fxm-hsearch__input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--fxm-hsearch-ink);
  font: inherit;
  font-size: 14px;
  text-overflow: ellipsis;   /* narrow desktop (768-1023px): the placeholder ends in "…" */
}
.fxm-hsearch__input::placeholder { color: #9aa0b4; opacity: 1; }
.fxm-hsearch__input::-webkit-search-cancel-button,
.fxm-hsearch__input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
.fxm-hsearch__clear {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #f2f1f8;
  color: var(--fxm-hsearch-muted);
  cursor: pointer;
  transition: background-color .16s ease, color .16s ease;
}
.fxm-hsearch__clear:hover { background: #ebe7fb; color: var(--fxm-hsearch-primary); }
.fxm-hsearch__clear:focus-visible { outline: 2px solid var(--fxm-hsearch-primary); outline-offset: 1px; }
.fxm-hsearch__kbd {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid #e3e1ee;
  border-bottom-width: 2px;
  border-radius: 6px;
  background: #fafaff;
  color: var(--fxm-hsearch-muted);
  font: 600 10.5px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.fxm-hsearch__kbd--esc { margin-right: 4px; }
.fxm-hsearch__cancel { display: none; }

/* ---------- results card ---------- */
.fxm-hsearch__drop {
  position: absolute;
  top: calc(100% + 14px);   /* the 44px field is centred in the 72px header: this is its bottom edge */
  right: 0;
  width: max(100%, 400px);
  overflow: hidden;
  border: 1px solid var(--fxm-hsearch-line);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 28px 56px -24px rgba(35, 26, 76, .32), 0 4px 12px -6px rgba(35, 26, 76, .08);
  opacity: 0;
  translate: 0 -6px;
  transition: opacity .18s ease .05s, translate .22s var(--fxm-hsearch-ease) .05s;
}
.fxm-hsearch.is-open .fxm-hsearch__drop { opacity: 1; translate: 0 0; }
@starting-style {
  .fxm-hsearch.is-open .fxm-hsearch__drop { opacity: 0; translate: 0 -6px; }
}
.fxm-hsearch__drop::before {
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: var(--fxm-hsearch-accent);
  content: "";
}
.fxm-hsearch__caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px 6px;
}
.fxm-hsearch__caption-text {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--fxm-hsearch-muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}
.fxm-hsearch__caption-text::before {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 2px;
  background: var(--fxm-hsearch-accent);
  content: "";
}
.fxm-hsearch__count {
  color: var(--fxm-hsearch-faint);
  font: 600 12px/1 var(--font-family-numeric, "Nunito", ui-sans-serif, system-ui, sans-serif);
  font-variant-numeric: tabular-nums;
}

/* Picker rows: same markup as the exposure form, re-seated inside the card. */
.fxm-hsearch .fxm-hsearch__list {
  position: static;
  max-height: min(392px, calc(100vh - 230px));
  max-height: min(392px, calc(100dvh - 230px));
  padding: 2px 8px 8px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.fxm-hsearch .fxm-broker-picker__option { position: relative; padding-right: 36px; }
/* "Opens a page" cue on the highlighted row. */
.fxm-hsearch .fxm-broker-picker__option::after {
  position: absolute;
  top: 50%;
  right: 12px;
  width: 14px;
  height: 14px;
  background: var(--fxm-hsearch-primary);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 6 6 6-6 6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 6 6 6-6 6'/%3E%3C/svg%3E") center / contain no-repeat;
  opacity: 0;
  translate: -4px -50%;
  transition: opacity .16s ease, translate .16s ease;
  content: "";
}
.fxm-hsearch .fxm-broker-picker__option:hover::after,
.fxm-hsearch .fxm-broker-picker__option.is-active::after { opacity: 1; translate: 0 -50%; }
.fxm-hsearch .fxm-broker-picker__score { font-family: var(--font-family-numeric, "Nunito", ui-sans-serif, system-ui, sans-serif); }
.fxm-hsearch .fxm-broker-picker__notice { padding: 18px 10px 14px; }

.fxm-hsearch__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px 10px 18px;
  border-top: 1px solid #efedf6;
  background: #fbfaff;
}
.fxm-hsearch__all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--fxm-hsearch-primary);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  text-decoration: none;
}
.fxm-hsearch__all > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fxm-hsearch__all > svg { flex: none; transition: translate .2s ease; }
.fxm-hsearch__all:hover > svg { translate: 3px 0; }
.fxm-hsearch__all:focus-visible { border-radius: 6px; outline: 2px solid var(--fxm-hsearch-primary); outline-offset: 3px; }
.fxm-hsearch__keys {
  display: flex;
  flex: none;
  gap: 12px;
  color: var(--fxm-hsearch-faint);
  font-size: 11px;
  line-height: 1;
}
.fxm-hsearch__keys > span { display: inline-flex; align-items: center; gap: 4px; }
.fxm-hsearch__keys .fxm-hsearch__kbd { min-width: 18px; height: 18px; padding: 0 4px; }
.fxm-hsearch.is-navigating .fxm-hsearch__drop { opacity: .6; pointer-events: none; }

/* Narrow desktop cards: drop the key legend before the link truncates. */
@media (max-width: 1023.98px) { .fxm-hsearch__keys { display: none; } }
@media (hover: none) { .fxm-hsearch__keys, .fxm-hsearch__kbd--esc { display: none; } }

/* The open field takes the nav's place. */
.fxm-site-header [data-fxm-mega-nav] { transition: opacity .18s ease, visibility 0s; }
.fxm-site-header.is-hsearch-open [data-fxm-mega-nav] {
  opacity: 0;
  visibility: hidden;
  transition: opacity .12s ease, visibility 0s linear .12s;
}

@media (prefers-reduced-motion: reduce) {
  .fxm-hsearch__trigger,
  .fxm-hsearch__scrim,
  .fxm-hsearch__field,
  .fxm-hsearch__field > *,
  .fxm-hsearch__drop,
  .fxm-hsearch .fxm-broker-picker__option::after,
  .fxm-site-header [data-fxm-mega-nav] { transition: none !important; }
  .fxm-hsearch__trigger:hover { transform: none; }
}

/* ---------- H5 (< 768px): full-screen sheet ---------- */
@media (max-width: 767.98px) {
  .fxm-hsearch__trigger {
    width: 38px;
    height: 38px;
    border: 1px solid #e8e6f5;
    border-radius: 12px;
    background: #fff;
    color: #272e42;
    box-shadow: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 160ms ease, transform 160ms ease;
  }
  .fxm-hsearch__trigger:hover { transform: none; box-shadow: none; }
  .fxm-hsearch__trigger:active { transform: scale(.94); background: #f4f2ff; }

  .fxm-hsearch__scrim { display: none !important; }
  .fxm-hsearch__panel {
    position: fixed;
    inset: 0;
    z-index: 60;           /* inside the header (z-50), above the tab bar (48) */
    display: flex;
    flex-direction: column;
    width: auto;
    padding-top: env(safe-area-inset-top);
    background: var(--fxm-m-surface, #fff);
    opacity: 0;
    translate: 0 10px;
    transition: opacity .18s ease, translate .22s var(--fxm-hsearch-ease);
  }
  .fxm-hsearch.is-open .fxm-hsearch__panel { opacity: 1; translate: 0 0; }

  .fxm-hsearch__bar {
    flex: none;
    gap: 4px;
    height: var(--fxm-m-header, 60px);
    padding: 0 6px 0 16px;
    border-bottom: 1px solid var(--fxm-m-line-soft, #efedf6);
  }
  .fxm-hsearch__field,
  .fxm-hsearch.is-open .fxm-hsearch__field {
    height: 42px;
    padding: 0 6px 0 12px;
    border: 1px solid transparent;
    border-radius: var(--fxm-m-r-md, 14px);
    background: var(--fxm-m-surface-2, #f5f4fa);
    box-shadow: none;
    clip-path: none;
    transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
  }
  .fxm-hsearch__field:focus-within {
    border-color: var(--fxm-m-primary, #4f34d9);
    background: #fff;
    box-shadow: 0 0 0 3px var(--fxm-m-primary-ring, rgba(79, 52, 217, .14));
  }
  .fxm-hsearch__field > *,
  .fxm-hsearch.is-open .fxm-hsearch__field > * { opacity: 1; transition: none; }
  .fxm-hsearch__input { font-size: 16px; }   /* 16px: no iOS zoom on focus */
  .fxm-hsearch__input::placeholder { color: var(--fxm-m-placeholder, #a0a5b8); }
  .fxm-hsearch__clear { width: 32px; height: 32px; }
  .fxm-hsearch__kbd--esc { display: none; }
  .fxm-hsearch__cancel {
    display: inline-flex !important;
    flex: none;
    align-items: center;
    height: 44px;
    padding: 0 10px;
    border: 0;
    background: none;
    color: var(--fxm-m-primary, #4f34d9);
    font-size: 15px;
    font-weight: 500;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
  }
  .fxm-hsearch__cancel:focus-visible { border-radius: 10px; outline: 2px solid var(--fxm-m-primary, #4f34d9); outline-offset: -2px; }

  /* The sheet body scrolls as one, so "view all" follows the last result
     instead of sitting at the bottom edge (behind the on-screen keyboard). */
  .fxm-hsearch__drop,
  .fxm-hsearch.is-open .fxm-hsearch__drop {
    position: static;
    display: block;
    flex: 1;
    min-height: 0;
    width: auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    opacity: 1;
    translate: none;
    transition: none;
  }
  .fxm-hsearch__drop::before { display: none; }
  .fxm-hsearch__caption { padding: 14px var(--fxm-m-gutter, 20px) 6px; }
  .fxm-hsearch .fxm-hsearch__list {
    max-height: none;
    overflow: visible;
    padding: 0 12px 4px;
  }
  .fxm-hsearch .fxm-broker-picker__option { padding-right: 30px; }
  .fxm-hsearch .fxm-broker-picker__option::after { right: 8px; }
  .fxm-hsearch__foot {
    margin: 0 12px calc(16px + env(safe-area-inset-bottom));
    padding: 4px 8px;
    border: 1px solid var(--fxm-m-line-soft, #efedf6);
    border-radius: var(--fxm-m-r-md, 14px);
  }
  .fxm-hsearch__all { min-height: 44px; font-size: 14px; }

  html.fxm-hsearch-locked,
  html.fxm-hsearch-locked body { overflow: hidden; }
}
