/* ═══════════════════════════════════════════════════════════════════════════
   BUSCADOR DEL UNIVERSO DE ACTIVOS — ver jgp_universe.js
   ═══════════════════════════════════════════════════════════════════════════
   Cuelga de las variables de tema de ui/theme.py (--ink, --surf, --rule…),
   así que sigue el modo claro/oscuro sin reglas duplicadas; sólo el verde de
   texto y el aviso de "Deshacer" cambian de valor en oscuro.

   El campo es type="search" a propósito: la regla global de index_string
   pinta borde, fondo y anillo verde a todo input[type="text"], y aquí la caja
   visible es el contenedor. Con type="text" salían dos cajas, una dentro de
   otra — el mismo defecto que ya se corrigió en el asistente.
   ═══════════════════════════════════════════════════════════════════════════ */

.jgp-uni {
  --uni-accent: #01BF63;
  --uni-accent-ink: #018F4A;
  --uni-ring: rgba(1, 191, 99, .26);
  --uni-hover: rgba(13, 18, 47, .07);
  --uni-pop-shadow: 0 6px 16px rgba(13, 18, 47, .10), 0 24px 60px rgba(13, 18, 47, .16);
  display: grid;
  gap: 16px;
}
[data-theme="dark"] .jgp-uni {
  --uni-accent-ink: #3ECF8E;
  --uni-ring: rgba(1, 191, 99, .32);
  --uni-hover: rgba(233, 236, 245, .085);
  --uni-pop-shadow: 0 6px 16px rgba(0, 0, 0, .35), 0 24px 60px rgba(0, 0, 0, .55);
}
.jgp-uni [hidden], .jgp-uni-toast[hidden] { display: none !important; }

/* El panel que contiene el menú abierto se pone encima de sus vecinos —
   mismo cinturón que el desplegable de Dash (ver index_string). */
.jgp-panel:has(.jgp-uni-pop:not([hidden])) { position: relative; z-index: 600; }

/* ── Campo ────────────────────────────────────────────────────────────── */
.jgp-uni-combo { position: relative; }
.jgp-uni-search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 46px;
  padding: 0 8px 0 14px;
  background: var(--surf);
  border: 1px solid var(--rule);
  border-radius: 12px;
  transition: border-color .18s cubic-bezier(.2, .8, .2, 1), box-shadow .18s cubic-bezier(.2, .8, .2, 1);
}
.jgp-uni-search:hover { border-color: #C7CDDC; }
[data-theme="dark"] .jgp-uni-search:hover { border-color: var(--subtle); }
.jgp-uni-search:focus-within {
  border-color: var(--uni-accent);
  box-shadow: 0 0 0 3px var(--uni-ring);
}
.jgp-uni-ic { flex: none; color: var(--subtle); }
.jgp-uni-search:focus-within .jgp-uni-ic { color: var(--uni-accent-ink); }
.jgp-uni-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: 500 14.5px/1 inherit;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
/* Sin caja propia, también al enfocar. index_string trae
   `:focus-visible { outline: 2px solid verde }` para toda la app, y como
   empata en especificidad con `.jgp-uni-input` y se carga DESPUÉS de
   assets/, ganaba: dibujaba un rectángulo verde dentro del anillo del
   contenedor (dos cajas). Se entra por el ID para ganarle sin depender del
   orden de carga — mismo arreglo que el campo del asistente (ed33505). */
#uni-picker-root .jgp-uni-input,
#uni-picker-root .jgp-uni-input:focus,
#uni-picker-root .jgp-uni-input:focus-visible,
#fi-picker-root .jgp-uni-input,
#fi-picker-root .jgp-uni-input:focus,
#fi-picker-root .jgp-uni-input:focus-visible {
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  outline: none !important;
}
.jgp-uni-input::-webkit-search-cancel-button,
.jgp-uni-input::-webkit-search-decoration { -webkit-appearance: none; }
.jgp-uni-input::placeholder { color: var(--subtle); font-weight: 400; }
.jgp-uni-iconbtn {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.jgp-uni-iconbtn:hover { background: var(--uni-hover); color: var(--ink); transform: none; }
.jgp-uni-iconbtn:focus-visible { outline: 2px solid var(--uni-accent); outline-offset: 1px; }

.jgp-uni-kbd {
  font: 500 11px/1 "JetBrains Mono", "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color: var(--muted);
  background: var(--surf-2);
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 3px 6px 2px;
  white-space: nowrap;
}
.jgp-uni-slash { margin-right: 4px; }

/* ── Menú ─────────────────────────────────────────────────────────────── */
.jgp-uni-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 950;
  background: var(--surf);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--uni-pop-shadow);
  overflow: hidden;
  animation: jgpUniIn .14s ease-out backwards;
}
@keyframes jgpUniIn { from { transform: translateY(-4px); opacity: .6; } }

.jgp-uni-seg {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule);
}
.jgp-uni-seg button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 500 12.5px/1 inherit;
  font-family: inherit;
  cursor: pointer;
  box-shadow: none;
}
.jgp-uni-seg button:hover { background: var(--uni-hover); color: var(--ink); transform: none; }
/* Píldora invertida del sistema: se voltea sola en oscuro. */
.jgp-uni-seg button[aria-pressed="true"] { background: var(--ink); color: var(--canvas); }
.jgp-uni-seg button:focus-visible { outline: 2px solid var(--uni-accent); outline-offset: 1px; }
.jgp-uni-ct {
  font: 500 11px/1 "JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace;
  opacity: .7;
  font-variant-numeric: tabular-nums;
}

.jgp-uni-list {
  position: relative;
  max-height: min(392px, 52vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 0 6px;
}
.jgp-uni-label {
  padding: 8px 16px 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--subtle);
}
.jgp-uni-note { padding: 16px; color: var(--muted); font-size: 13px; }
.jgp-uni-note b { color: var(--ink); font-weight: 600; }

.jgp-uni-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto 26px;
  align-items: center;
  gap: 12px;
  padding: 8px 14px 8px 16px;
  min-height: 54px;
  cursor: pointer;
  user-select: none;
}
.jgp-uni-row.is-active { background: var(--uni-hover); }
.jgp-uni-id { display: grid; min-width: 0; line-height: 1.3; }
.jgp-uni-tk {
  font: 600 13px/1.3 "JetBrains Mono", "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color: var(--ink);
  letter-spacing: -.1px;
}
.jgp-uni-nm {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.jgp-uni-row mark { background: transparent; color: var(--uni-accent-ink); font-weight: 700; }
.jgp-uni-meta { display: grid; justify-items: end; line-height: 1.3; min-width: 0; }
.jgp-uni-kind { font-size: 12px; font-weight: 500; color: var(--ink); white-space: nowrap; }
.jgp-uni-on { color: var(--uni-accent-ink); }
.jgp-uni-mkt { font-size: 11.5px; color: var(--subtle); white-space: nowrap; }
.jgp-uni-state {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  color: var(--muted);
  transition: background .15s, border-color .15s, color .15s;
}
.jgp-uni-row:hover .jgp-uni-state,
.jgp-uni-row.is-active .jgp-uni-state { border-color: var(--uni-accent); color: var(--uni-accent-ink); }
.jgp-uni-row.is-on .jgp-uni-state { background: var(--uni-accent); border-color: var(--uni-accent); color: #fff; }
.jgp-uni-row.is-custom .jgp-uni-nm { color: var(--ink); }

.jgp-uni-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 16px;
  padding: 9px 16px;
  border-top: 1px solid var(--rule);
  background: var(--surf-2);
  font-size: 12px;
  color: var(--muted);
}
.jgp-uni-foot-count { font-variant-numeric: tabular-nums; }
.jgp-uni-keys { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 6px; }
.jgp-uni-keys span { margin-right: 8px; }

/* ── Lo elegido ───────────────────────────────────────────────────────── */
.jgp-uni-tray { display: grid; gap: 12px; }
.jgp-uni-tray-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px 16px;
}
.jgp-uni-count { font-size: 13px; color: var(--muted); }
.jgp-uni-count strong {
  font: 600 13px/1 "JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.jgp-uni-mix { color: var(--subtle); }
.jgp-uni-link {
  border: 0;
  background: transparent;
  padding: 2px 4px;
  border-radius: 6px;
  color: var(--muted);
  font: 500 12.5px/1.2 inherit;
  font-family: inherit;
  cursor: pointer;
  box-shadow: none;
}
.jgp-uni-link:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; transform: none; }
.jgp-uni-link:focus-visible { outline: 2px solid var(--uni-accent); }
.jgp-uni-link:disabled { opacity: .4; pointer-events: none; }

.jgp-uni-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.jgp-uni-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 4px 0 5px;
  background: var(--surf-2);
  border: 1px solid var(--rule);
  border-radius: 999px;
}
.jgp-uni-chip .jgp-uni-tk { font-size: 12.5px; }
.jgp-uni-chip.is-custom { border-style: dashed; }
.jgp-uni-chip.is-new { animation: jgpUniChip .32s cubic-bezier(.2, .9, .3, 1.2) backwards; }
@keyframes jgpUniChip { from { transform: scale(.9); background: rgba(1, 191, 99, .14); } }
.jgp-uni-x {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--subtle);
  cursor: pointer;
  box-shadow: none;
}
.jgp-uni-x:hover { background: var(--uni-hover); color: var(--ink); transform: none; }
.jgp-uni-x:focus-visible { outline: 2px solid var(--uni-accent); }
.jgp-uni-empty {
  margin: 0;
  padding: 16px;
  border: 1px dashed var(--rule);
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.jgp-uni-sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ── Aviso con Deshacer ───────────────────────────────────────────────── */
.jgp-uni-toast {
  --uni-toast-bg: #0D122F;
  --uni-toast-ink: #F4F6FA;
  --uni-toast-accent: #3ECF8E;
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 8000;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 8px 8px 8px 16px;
  border-radius: 12px;
  background: var(--uni-toast-bg);
  color: var(--uni-toast-ink);
  box-shadow: 0 6px 16px rgba(13, 18, 47, .18), 0 24px 60px rgba(13, 18, 47, .22);
  font-size: 13px;
}
[data-theme="dark"] .jgp-uni-toast {
  --uni-toast-bg: #E9ECF5;
  --uni-toast-ink: #0D122F;
  --uni-toast-accent: #018F4A;
}
.jgp-uni-toast button {
  border: 0;
  border-radius: 8px;
  padding: 7px 10px;
  background: transparent;
  color: var(--uni-toast-accent);
  font: 600 13px/1 inherit;
  font-family: inherit;
  cursor: pointer;
  box-shadow: none;
}
.jgp-uni-toast button:hover { background: rgba(127, 127, 127, .16); transform: none; }
.jgp-uni-toast button:focus-visible { outline: 2px solid var(--uni-toast-accent); }

/* ── Renta Fija ───────────────────────────────────────────────────────── */
.jgp-uni-actions { display: flex; align-items: baseline; gap: 8px; }
.jgp-uni-sub { color: var(--subtle); }
.jgp-uni-yield {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: 600 13px/1.3 "JetBrains Mono", "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* "en vivo" con punto verde; "ref." apagado. La diferencia importa: sin token
   de Banxico los CETES son de referencia aunque los MBONOS sean del día. */
.jgp-uni-live, .jgp-uni-ref {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font: 500 10.5px/1 "Inter", system-ui, sans-serif;
  letter-spacing: .02em;
}
.jgp-uni-live { color: var(--uni-accent-ink); }
.jgp-uni-live::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--uni-accent);
  box-shadow: 0 0 0 3px rgba(1, 191, 99, .18);
}
.jgp-uni-ref { color: var(--subtle); }
.jgp-uni-flagc {
  display: inline-block;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(13, 18, 47, .10);
}
.jgp-uni-flagc img { width: 100%; height: 100%; object-fit: cover; display: block; }
.jgp-uni-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  border-radius: 50%;
  line-height: 1;
}
.jgp-uni-cy {
  font: 500 12px/1 "JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.jgp-uni-tkname { font-family: inherit; font-weight: 600; }
.jgp-uni-note-line { margin: 0; font-size: 12px; color: var(--subtle); }

/* Formulario de instrumento personalizado, plegado bajo el buscador. */
.jgp-fi-custom {
  margin-top: 14px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--surf);
}
.jgp-fi-custom-sum {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  list-style: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  border-radius: 12px;
}
.jgp-fi-custom-sum::-webkit-details-marker { display: none; }
.jgp-fi-custom-sum::before {
  content: "+";
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  border: 1px solid var(--rule);
  border-radius: 50%;
  color: var(--pos);
  font-weight: 700;
}
.jgp-fi-custom[open] > .jgp-fi-custom-sum::before { content: "–"; }
.jgp-fi-custom-sum:hover { background: var(--surf-2); }
.jgp-fi-custom-sum:focus-visible { outline: 2px solid #01BF63; outline-offset: 2px; }
.jgp-fi-custom-body { padding: 14px; border-top: 1px solid var(--rule); }

@media (max-width: 640px) {
  .jgp-uni-row { padding-inline: 12px; gap: 10px; }
  .jgp-uni-mkt, .jgp-uni-keys, .jgp-uni-slash, .jgp-uni-on, .jgp-uni-sub { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .jgp-uni-pop, .jgp-uni-chip.is-new { animation: none; }
  .jgp-uni-search, .jgp-uni-state { transition: none; }
}
