/* Record search (account Trades header, left of Filter). Closed: a round
   magnifier the size of the header pills. Open: the same pill slides out
   leftwards into a field (the magnifier rides its left edge), drawn over
   the header so Filter / + Ledger / + Record never move. Its in-flow slot
   stays one circle wide; js/ui/record-search.js sets --trade-search-w to
   the room on the left (capped), or flips it to open rightwards when the
   slot wrapped to the start of a row. Transitions run only on a toggle
   (.is-anim), never when a repaint rebuilds an already-open field. Where
   one header row leaves too little room on the left, the magnifier moves
   onto a top row of its own (.search-top, css/accounts.css). */

#account-detail .section-head .trade-search {
  position: relative;
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
  margin-left: auto;
}
/* The search takes over the right-packing gap from Filter; Filter then
   sits as close to it as + Ledger / + Record sit to Filter (desktop
   tightening only, see accounts.css: phones already use that gap). */
#account-detail .section-head .trade-search + .filter-wrap { margin-left: 0; }
@media (min-width: 721px) {
  #account-detail .section-head .trade-search + .filter-wrap { margin-left: -0.35rem; }
}

.trade-search-box {
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: transparent;
  overflow: hidden;
}
.trade-search.opens-right .trade-search-box { right: auto; left: 0; }
.trade-search.has-query:not(.is-open) .trade-search-box {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}
.trade-search.has-query:not(.is-open) .trade-search-btn { color: var(--accent-ink); }
.trade-search.is-open .trade-search-box {
  /* Above the tools it may cover when it opens rightwards (Filter's wrap
     is positioned and comes later in the DOM). */
  z-index: 1;
  width: var(--trade-search-w, 16rem);
  background: var(--bg-soft);
}
.trade-search.is-open .trade-search-box:focus-within {
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.08);
}
.trade-search.is-anim .trade-search-box {
  transition: width 0.34s var(--ease), background 0.2s ease, border-color 0.16s ease, color 0.2s ease;
}

.trade-search .trade-search-btn {
  flex: 0 0 auto;
  width: calc(2.25rem - 2px);
  height: 100%;
  min-height: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
}
.trade-search .trade-search-btn:hover { background: transparent; }
.trade-search .trade-search-btn:active { transform: none; }
.trade-search .trade-search-btn svg { transition: transform 0.12s var(--ease); }
.trade-search .trade-search-btn:active svg { transform: scale(0.9); }
.trade-search .trade-search-btn:focus-visible { outline-offset: -3px; }

.trade-search .trade-search-input {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  height: 100%;
  min-height: 0;
  padding: 0 0.15rem 0 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: 0.85rem;
  opacity: 0;
  visibility: hidden;
  -webkit-appearance: none;
  appearance: none;
}
.trade-search.is-open .trade-search-input { opacity: 1; visibility: visible; }
.trade-search.is-anim.is-open .trade-search-input { transition: opacity 0.2s ease 0.1s; }
.trade-search .trade-search-input:focus,
.trade-search .trade-search-input:focus-visible { border: 0; box-shadow: none; outline: none; }
.trade-search .trade-search-input::placeholder { color: var(--muted-2); }
.trade-search .trade-search-input::-webkit-search-cancel-button,
.trade-search .trade-search-input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }

.trade-search .trade-search-clear {
  flex: 0 0 auto;
  width: 1.75rem;
  height: 1.75rem;
  min-height: 0;
  margin-right: 0.25rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  line-height: 0;
}
.trade-search .trade-search-clear svg { display: block; }
/* Hover tints only where a pointer hovers: on touch screens :hover sticks
   to the last tapped control. */
@media (hover: hover) {
  .trade-search:not(.is-open):not(.has-query) .trade-search-box:hover { background: var(--accent-soft); border-color: rgba(255, 255, 255, 0.24); }
  .trade-search .trade-search-clear:hover { background: var(--accent-soft); color: var(--text); }
}
.trade-search .trade-search-clear[hidden],
.trade-search:not(.is-open) .trade-search-clear { display: none; }

@media (prefers-reduced-motion: reduce) {
  .trade-search.is-anim .trade-search-box,
  .trade-search.is-anim.is-open .trade-search-input { transition: none; }
}

/* Phones: the field opens over the title (and Select), so it needs the
   page's full width of room; 16px text keeps iOS from zooming on focus;
   the clear button grows to a comfortable tap target. */
@media (max-width: 720px) {
  .trade-search .trade-search-input { font-size: 16px; }
  .trade-search .trade-search-clear { width: 2rem; height: 2rem; margin-right: 0.1rem; }
}
