/**
 * Thread-side gestures: search inside the open conversation and the press-and-
 * hold message menu.
 *
 * Owned by track T8 of the wa-inbox-pwa run. Created empty by T1 so the <link>
 * in index.html could be written once, before any other track opened that file.
 *
 * Linked AFTER /css/admin-whatsapp.css on purpose, so a rule here at equal
 * specificity wins on link order and needs no !important. It stays far above
 * /css/admin-person.css. The "admin" prefix is load-bearing: it is the only
 * thing scripts/bundle-css.mjs partitions on, and a differently named file
 * would ship the whole admin panel's CSS to every marketing visitor.
 *
 * Every colour here is a `--wa-*` token declared on `.admin-layout:has(.wai-page)`
 * in admin-whatsapp.css, so the dark set follows for free and nothing needs a
 * second definition. Logical properties only: the panel is an RTL island, so
 * inline-start is the physical RIGHT.
 *
 * NOTHING IN HERE MAY ADD `transform`, `filter`, `backdrop-filter`, `contain`
 * or `will-change` to `.wai-thread` or any of its ancestors. AdminSheet renders
 * in place with `position: fixed` and no Teleport, and three sheets live inside
 * `.wai-thread` - a transformed ancestor becomes their containing block and
 * they open trapped inside its box.
 */

/* ══════════════════════════════════════════════════════════════════════════
   D29 - find inside the open conversation
   ══════════════════════════════════════════════════════════════════════════ */

/* The bar REPLACES the header rather than adding a fifth grid row.
   `.wai-thread` is `grid-template-rows: auto auto minmax(0, 1fr) auto` with
   every row assigned explicitly (admin-whatsapp.css), so an unassigned child
   auto-places into an implicit fifth row UNDER the composer, and a real fifth
   row would take its height out of the conversation. `grid-row: 1` is therefore
   not decoration - without it the bar renders below the message box.

   `min-height` rather than a fixed height: at 1024px and below the stylesheet
   forces every `.wai-page input` to 16px as an iOS zoom guard, which grows the
   field to about 39px, and the notes wrap onto a second line of their own. */
.wai-thread > .wai-thread__find {
  grid-row: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm, 8px);
  min-height: 56px;
  padding: 6px 10px;
  background: var(--wa-header);
  border-block-end: 1px solid var(--wa-line);
}

.wai-thread__find-close,
.wai-thread__find-step,
.wai-thread__find-open {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--radius-full, 980px);
  background: none;
  color: var(--wa-ink-2);
  font-size: 0.95rem;
  cursor: pointer;
}

.wai-thread__find-close:hover,
.wai-thread__find-step:hover:not(:disabled),
.wai-thread__find-open:hover {
  background: var(--wa-sunken);
  color: var(--wa-ink);
}

.wai-thread__find-step:disabled {
  opacity: 0.35;
  cursor: default;
}

/* The accent at 3.01:1 is a FILL and never a thin glyph, so every ring in this
   panel takes --wa-green-ink. */
.wai-thread__find-close:focus-visible,
.wai-thread__find-step:focus-visible,
.wai-thread__find-open:focus-visible {
  outline: 2px solid var(--wa-green-ink);
  outline-offset: 2px;
}

.wai-thread__find-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-full, 980px);
  background: var(--wa-raised);
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--wa-ink);
}

.wai-thread__find-input:focus {
  outline: none;
  border-color: var(--wa-green-line);
}

/* Tabular figures so the count does not jitter as it walks 9/12 to 10/12. */
.wai-thread__find-count {
  flex: none;
  font-family: var(--font-mono, monospace);
  font-size: 0.74rem;
  color: var(--wa-ink-2);
  font-variant-numeric: tabular-nums;
}

/* A full-width line of its own, so a disclosure never squeezes the field down
   to nothing on a 390px phone. Two of them can be present at once. */
.wai-thread__find-note {
  flex: 0 0 100%;
  margin: 0;
  padding: 0 6px 2px;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--wa-ink-3);
}

.wai-thread__find-load {
  padding: 0;
  border: 0;
  background: none;
  color: var(--wa-green-ink);
  font-family: var(--font-body);
  font-size: 0.72rem;
  text-decoration: underline;
  cursor: pointer;
}

.wai-thread__find-load:disabled {
  opacity: 0.5;
  cursor: default;
}

.wai-thread__find-load:focus-visible {
  outline: 2px solid var(--wa-green-ink);
  outline-offset: 2px;
}

/* ── The match highlight ────────────────────────────────────────────────────

   BUBBLE-LEVEL, never inside the text. A message body is rendered by
   `WaFormattedText`, which interpolates every segment and never uses `v-html` -
   that ban is one of the folder's cheapest rules to break. Wrapping matched
   substrings in `<mark>` would mean either `v-html` (forbidden outright) or
   threading a highlight term through the formatter and re-splitting every
   segment, in a component several specs pin.

   An inset box-shadow rather than a pseudo-element, because both of the
   bubble's pseudo-elements are taken: `::before` is the speaker-run tail and
   `::after` is the jump-to-original flash. An inset shadow paints over the
   background and under the text, which is exactly a wash.

   --wa-green-wash-2 (the accent at 20%) and NOT --wa-green-wash: the latter is
   the opaque #D9FDD3 that IS the outgoing bubble's own background, so a wash
   painted in it would be completely invisible on every message we sent. */
.wai-bubble--match {
  box-shadow: var(--wa-shadow-sm), inset 0 0 0 999px var(--wa-green-wash-2);
}

/* Every hit gets the wash; the one the steppers are standing on gets a ring as
   well, so a scroll that stops inside a run of matches still says which one it
   stopped at. */
.wai-bubble--match-current {
  box-shadow:
    var(--wa-shadow-sm),
    inset 0 0 0 999px var(--wa-green-wash-2),
    0 0 0 2px var(--wa-green-ink);
}

/* ══════════════════════════════════════════════════════════════════════════
   D31 - press and hold a message
   ══════════════════════════════════════════════════════════════════════════ */

.wai-msgmenu {
  display: flex;
  flex-direction: column;
}

/* Deliberately the same measurements as every other sheet menu in the inbox:
   52px rows, a 12px gap, the body face. One menu look for the whole panel. */
.wai-msgmenu__item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 0 8px;
  border: 0;
  background: none;
  font-family: var(--font-body);
  font-size: 0.92rem;
  color: var(--wa-ink);
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}

.wai-msgmenu__item:hover {
  background: var(--wa-hover);
}

.wai-msgmenu__item:focus-visible {
  outline: 2px solid var(--wa-green-ink);
  outline-offset: -2px;
}

.wai-msgmenu__item i {
  flex: none;
  width: 20px;
  text-align: center;
  color: var(--wa-ink-3);
}

.wai-msgmenu__empty {
  margin: 0;
  padding: 12px 8px;
  font-size: 0.85rem;
  color: var(--wa-ink-2);
}

/* ── The pane's own transient line ──────────────────────────────────────────

   Shares the transcript's grid cell rather than taking a row, exactly like
   `.wai-thread__jump`: a line that reserved height would push the newest
   message up by its own size every time a copy succeeded. Sharing a cell is
   what needs the column pinned as well as the row, and `.wai-thread > *` in
   admin-whatsapp.css already pins every child to column 1.

   z-index 4 puts it level with the jump pill and far below every sheet
   (1040/1050): it is a notice, never a layer. */
.wai-thread > .wai-thread__toast {
  grid-row: 3;
  align-self: end;
  justify-self: center;
  z-index: 4;
  max-width: min(90%, 420px);
  margin: 0 0 12px;
  padding: 9px 14px;
  border-radius: var(--radius-md, 12px);
  background: var(--wa-ink);
  color: var(--wa-panel);
  font-size: 0.82rem;
  line-height: 1.35;
  text-align: center;
  box-shadow: var(--wa-shadow-lg);
  pointer-events: none;
}

.wai-thread__toast--error {
  background: var(--wa-danger-ink);
  /* The ink that sits on a filled accent. It flips to near-black in the dark
     set, so this must never be a literal #fff. */
  color: var(--wa-on-accent);
}

/* ── The text-selection collision ───────────────────────────────────────────

   On a coarse pointer a hold on message text starts the platform's selection
   callout, which fights the 450ms hold and wins about half the time. Suppress
   it, and ONLY here: on a mouse, selecting part of a message and copying it is
   how staff have always lifted a line into a note, taking that away buys
   nothing, and the menu is on `contextmenu` there anyway.

   The cost on a phone is that a hold copies the WHOLE body rather than a
   selection, which is what WhatsApp does too. */
@media (hover: none) {
  .wai-bubble {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  /* The one exception. A phone number, an order code or a link inside a message
     is exactly the thing staff select by hand, and it is short enough that the
     whole-body copy is the wrong tool. */
  .wai-bubble a,
  .wai-bubble__text--caption {
    -webkit-user-select: text;
    user-select: text;
  }
}

/* The file's register of every control that could grow a transition. None of
   these declares one today; the list is what stops the next one shipping
   without an answer for a reader who asked for less movement. */
@media (prefers-reduced-motion: reduce) {
  .wai-thread__find-close,
  .wai-thread__find-step,
  .wai-thread__find-open,
  .wai-thread__find-load,
  .wai-msgmenu__item,
  .wai-thread__toast {
    transition: none;
  }
}
