/* Slide «search»: barra de consulta, consultas de ejemplo, resultados con su insignia de puntaje y de relaciones y similares, y el detalle de cada resultado.
   js/demos/search.js añade rs-live a la tarjeta cuando la demostración está en marcha: sin esa clase (sin JavaScript o con «reducir movimiento») todo se ve en su estado final. */
[data-demo="search"] { position: relative; }

.searchbox {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 600;
  min-height: 24px;
}
.searchbox svg { width: 18px; height: 18px; color: var(--accent); flex: none; }
/* Cursor mientras se escribe la consulta */
.is-typing .searchbox [data-role="query"]::after { content: ""; display: inline-block; width: 2px; height: 1.1em; margin-left: 2px; vertical-align: -0.18em; background: var(--accent); animation: rs-caret 0.8s steps(1) infinite; }
@keyframes rs-caret { 50% { opacity: 0; } }
/* Al arrancar la secuencia, la barra está sola en el centro de la tarjeta (con una sombra suave) y las consultas y los resultados aún no se ven */
.rs-live .searchbox { position: relative; z-index: 3; will-change: transform; }
.rs-live.is-intro .searchbox { box-shadow: 0 16px 40px -12px rgba(15, 23, 42, 0.35); }
.rs-live .queries, .rs-live [data-role="results"] { transition: opacity 0.5s ease; }
.rs-live.is-intro .queries, .rs-live.is-intro [data-role="results"] { opacity: 0; visibility: hidden; }

.queries { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.queries button {
  cursor: pointer;
  font: 600 0.8rem "Plus Jakarta Sans", sans-serif;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
}
.queries button[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.result {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-top: 10px;
  transition: opacity 0.5s ease, transform 0.5s ease, box-shadow 0.25s, border-color 0.25s;
}
.result.has-pop { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rs-live .result.rs-pending { opacity: 0; transform: translateY(14px); }
.result header { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 700; margin-bottom: 6px; }
/* Título con el icono de su tipo (audio, PDF...): mismos colores y formas que las pestañas de la slide de lectura */
.result header > div { display: flex; align-items: center; gap: 10px; min-width: 0; }
.res-ico { display: grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--ic); color: #fff; font: 800 0.52rem "Plus Jakarta Sans", sans-serif; letter-spacing: 0.02em; }
.res-ico svg { width: 15px; height: 15px; fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.res-ico--pdf { --ic: #e5484d; }
.res-ico--word { --ic: #2b6cd1; }
.res-ico--audio { --ic: #e0568a; }
.res-ico--image { --ic: #f59e0b; }
.res-ico--excel { --ic: #1f9d55; }
.res-ico--whatsapp { --ic: #22a559; }
.res-ico--db { --ic: #0ea5b7; }
.res-ico--social { --ic: #6366f1; }
/* Variante pequeña (detalle de relacionados y similares) */
.res-ico--sm { width: 18px; height: 18px; border-radius: 6px; font-size: 0.4rem; }
.res-ico--sm svg { width: 11px; height: 11px; stroke-width: 2.4; }
.res-name { min-width: 0; }

/* Ubicación (pág. 1, min 14:32) y puntaje de relevancia, este como insignia: verde desde 90, azul desde 80 y ámbar por debajo */
.result header > .rs-meta { flex: none; gap: 8px; }
.rs-where { color: var(--muted); font-weight: 600; font-size: 0.82rem; white-space: nowrap; }
.rs-score {
  display: inline-flex;
  gap: 3px;
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--sc) 16%, transparent);
  color: color-mix(in srgb, var(--sc) 78%, var(--ink));
  font: 800 0.78rem "Plus Jakarta Sans", sans-serif;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.rs-score--hi { --sc: #1f9d55; }
.rs-score--mid { --sc: var(--accent); }
.rs-score--lo { --sc: #d99100; }

.result p { font-size: 0.92rem; margin: 0; }
.meter { height: 5px; border-radius: 3px; background: var(--line); margin-top: 10px; overflow: hidden; }
.meter i { display: block; width: var(--w, 0); height: 100%; background: linear-gradient(90deg, var(--accent), var(--teal)); transition: width 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) 0.15s; }
.rs-live .result:not(.in) .meter i { width: 0; }

/* Insignias de relaciones y de similares (se pulsan para ver el detalle) */
.rs-badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.rs-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px 4px 8px;
  border: 1px solid color-mix(in srgb, var(--bc) 42%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--bc) 11%, var(--bg));
  color: color-mix(in srgb, var(--bc) 72%, var(--ink));
  font: 700 0.74rem "Plus Jakarta Sans", sans-serif;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.rs-badge:hover, .rs-badge[aria-expanded="true"] { background: color-mix(in srgb, var(--bc) 22%, var(--bg)); }
.rs-badge:focus-visible { outline: 2px solid var(--bc); outline-offset: 2px; }
.rs-badge svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rs-badge b { font-weight: 800; }
.rs-badge--rel { --bc: var(--teal); }
.rs-badge--sim { --bc: #8b5cf6; }
.rs-live .result:not(.in) .rs-badge { opacity: 0; transform: scale(0.8); }
.rs-live .result.in .rs-badge { animation: rs-badge-in 0.5s cubic-bezier(0.3, 1.4, 0.5, 1) both 1.2s; }
.rs-live .result.in .rs-badge--sim { animation-delay: 1.7s; }
@keyframes rs-badge-in { from { opacity: 0; transform: scale(0.8); } }

/* Detalle de un resultado: contenido relacionado (a la izquierda) y similar con su % de similitud (a la derecha) */
.rs-pop {
  position: absolute;
  z-index: 6;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 14px;
  padding: 11px 14px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  box-shadow: 0 18px 44px -12px rgba(15, 23, 42, 0.38);
}
.rs-pop[hidden] { display: none; }
.rs-pop.open { animation: rs-pop-in 0.22s ease-out; }
@keyframes rs-pop-in { from { opacity: 0; transform: translateY(6px); } }
.rs-pop::after {
  content: "";
  position: absolute;
  left: var(--caret, 50%);
  width: 12px;
  height: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  transform: translateX(-50%) rotate(45deg);
}
.rs-pop[data-side="below"]::after { top: -7px; border-right: 0; border-bottom: 0; }
.rs-pop[data-side="above"]::after { bottom: -7px; border-left: 0; border-top: 0; }
.rs-sec h4 { display: flex; align-items: center; gap: 6px; margin: 0 0 6px; padding-bottom: 4px; border-bottom: 2px solid transparent; color: var(--muted); font: 800 0.62rem "Plus Jakarta Sans", sans-serif; letter-spacing: 0.08em; text-transform: uppercase; }
.rs-sec h4 b { padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 0.64rem; letter-spacing: 0; }
.rs-sec.is-focus h4 { border-bottom-color: var(--accent); color: var(--ink); }
.rs-sec ul { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.rs-sec li { display: flex; align-items: center; gap: 7px; min-width: 0; font-size: 0.76rem; font-weight: 600; line-height: 1.25; }
.rs-sec .rs-item > span:not(.res-ico) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rs-more { padding-left: 30px; color: var(--muted); font-weight: 700; }
.rs-sim li { position: relative; padding-bottom: 6px; }
.rs-sim .rs-item > span:not(.res-ico) { flex: 1; }
.rs-sim li b { flex: none; margin-left: auto; padding: 1px 7px; border-radius: 999px; background: color-mix(in srgb, #8b5cf6 16%, transparent); color: color-mix(in srgb, #8b5cf6 75%, var(--ink)); font-size: 0.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
/* Barra de similitud bajo cada elemento */
.rs-sim li i { position: absolute; left: 30px; right: 5px; bottom: 0; pointer-events: none; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.rs-sim li i::before { content: ""; display: block; width: var(--p); height: 100%; background: #8b5cf6; }
/* Al abrirse, los elementos entran uno a uno y las barras se llenan */
.rs-pop.open .rs-sec li { animation: rs-li-in 0.45s both; animation-delay: calc(var(--n) * 170ms + 150ms); }
.rs-pop.open .rs-sec + .rs-sec li { animation-delay: calc(var(--n) * 170ms + 1000ms); }
.rs-pop.open .rs-sim li i::before { animation: rs-bar 1.3s cubic-bezier(0.2, 0.8, 0.2, 1) both; animation-delay: calc(var(--n) * 170ms + 1300ms); }
@keyframes rs-li-in { from { opacity: 0; transform: translateX(-6px); } }
@keyframes rs-bar { from { width: 0; } }

/* Cada contenido del detalle se pulsa: aparece en la lista de resultados */
.rs-item { display: flex; align-items: center; gap: 7px; flex: 1; min-width: 0; margin: 0 -5px; padding: 2px 5px; border: 0; border-radius: 7px; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; transition: background 0.15s; }
.rs-item:hover { background: var(--accent-soft); }
.rs-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* La lista de resultados se desplaza si se le añaden contenidos (su alto lo fija js/demos/search.js); el relleno lateral deja sitio al aro de los resultados con detalle abierto */
[data-role="results"] { height: 300px; overflow-y: auto; overflow-x: hidden; margin-inline: -4px; padding-inline: 4px; scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--accent) 45%, transparent) transparent;
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 26px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 26px), transparent); }
/* Al llegar al final de la lista ya no hay desvanecido */
[data-role="results"].is-end { -webkit-mask-image: none; mask-image: none; }
/* Resultados pequeños: una línea de título y una de fragmento, para que quepan varios y se note que hay muchos */
.result--sm { padding: 8px 12px; margin-top: 7px; border-radius: 11px; }
.result--sm header { margin-bottom: 2px; }
.result--sm header > div { gap: 8px; }
.result--sm .res-ico { width: 20px; height: 20px; border-radius: 6px; font-size: 0.44rem; }
.result--sm .res-ico svg { width: 12px; height: 12px; }
.result--sm .res-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.86rem; }
.result--sm .rs-where { font-size: 0.72rem; }
.result--sm .rs-score { padding: 1px 8px; font-size: 0.7rem; }
.result--sm p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.78rem; }
/* La eficiencia, como la muestran los buscadores: «Se encontraron 35 documentos en 1,6 segundos» */
.rs-found { display: flex; align-items: center; gap: 8px; margin: 10px 2px 0; color: var(--muted); font-size: 0.8rem; font-weight: 600; transition: opacity 0.4s; }
.rs-found::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: #1f9d55; }
.rs-found b { color: var(--ink); font-variant-numeric: tabular-nums; }
.rs-found.is-off, .rs-live.is-intro .rs-found { opacity: 0; }
/* Contenido añadido desde el detalle: entra arriba con un destello y dice de dónde viene */
.result.rs-added { animation: rs-added-in 0.45s ease-out; }
.result.rs-flash { box-shadow: 0 0 0 3px var(--accent-soft); animation: rs-added-in 0.45s ease-out, rs-flash 1.8s ease-out; }
.rs-from { margin: 0 0 4px; color: var(--muted); font-size: 0.72rem; font-weight: 700; }
.rs-score--rel { --sc: var(--teal); }
.rs-score--sim { --sc: #8b5cf6; }
@keyframes rs-added-in { from { opacity: 0; transform: translateY(-12px); } }
@keyframes rs-flash { 0% { background: color-mix(in srgb, var(--accent) 16%, var(--bg2)); } 100% { background: var(--bg2); } }

@media (max-width: 520px) {
  .result header { flex-wrap: wrap; }
  .result--sm header { flex-wrap: nowrap; }
  .rs-pop { grid-template-columns: 1fr; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .rs-pop.open, .rs-pop.open .rs-sec li, .rs-pop.open .rs-sim li i::before, .rs-live .result.in .rs-badge, .result.rs-added, .result.rs-flash { animation: none; }
  .meter i, .result { transition: none; }
}
