/* Robot de ayuda y página de preguntas frecuentes (src/robot.js, src/views/public-preguntas.js). */

/* ---------- Robot flotante ----------
   Va entre el contenido y el pie, «pegado» al borde inferior de la ventana (position: sticky): mientras se recorre
   la página flota abajo a la derecha y, al llegar al final, se queda arriba del pie, así nunca tapa los botones del
   pie (arrepentimiento, baja). Ocupa su alto al final de la página, para no tapar lo último del contenido.
   Queda por debajo de la barra superior (z-index 10) y de su menú de usuario. */
.robot {
  position: sticky; bottom: 20px; z-index: 9; height: 92px; margin: 0 24px 20px;
  display: flex; justify-content: flex-end; align-items: flex-end;
  pointer-events: none;
}
.robot > * { pointer-events: auto; }

.robot-btn {
  position: relative; width: 92px; height: 92px; padding: 0; border: 0; border-radius: 50%;
  background: none; cursor: pointer; color: var(--text);
}
.robot-img {
  display: block; width: 92px; height: 92px;
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, .55)) drop-shadow(0 0 12px rgba(53, 206, 255, .18));
  animation: robot-flota 2.4s ease-in-out 2;
}
/* Sombra de luz debajo: se achica cuando el robot sube. */
.robot-btn::after {
  content: ""; position: absolute; left: 24%; right: 24%; bottom: -8px; height: 10px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(53, 206, 255, .5), rgba(53, 206, 255, 0));
  animation: robot-sombra 2.4s ease-in-out 2;
}
/* Flota al aparecer (menos de 5 segundos, WCAG 2.2.2) y mientras el puntero o el foco están sobre él. */
.robot-btn:hover .robot-img, .robot-btn:focus-visible .robot-img { animation: robot-flota 2.4s ease-in-out infinite; }
.robot-btn:hover::after, .robot-btn:focus-visible::after { animation: robot-sombra 2.4s ease-in-out infinite; }
.robot-btn:hover .robot-img { filter: drop-shadow(0 10px 16px rgba(0, 0, 0, .55)) drop-shadow(0 0 18px rgba(53, 206, 255, .45)); }
.robot-btn:focus-visible { outline: var(--focus-ring); outline-offset: 4px; }

@keyframes robot-flota { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes robot-sombra { 0%, 100% { transform: scaleX(1); opacity: .9; } 50% { transform: scaleX(.72); opacity: .45; } }

/* Globo «¿Te ayudo?»: al pasar el puntero, con el foco y, una vez por sesión, al llegar a la pantalla. */
.robot-bubble {
  position: absolute; right: calc(100% + 6px); top: 20px; white-space: nowrap;
  padding: 7px 14px; border-radius: 999px; border: 1px solid rgba(53, 206, 255, .45);
  background: #1f2226; color: var(--text); font-size: 14.5px; font-weight: 600;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .5);
  opacity: 0; transform: translateX(6px); transition: opacity .2s ease, transform .2s ease; pointer-events: none;
}
.robot-btn:hover .robot-bubble, .robot-btn:focus-visible .robot-bubble, .robot.saluda .robot-bubble { opacity: 1; transform: none; }
.robot.abierto .robot-bubble { display: none; }

@media (prefers-reduced-motion: reduce) {
  .robot-img, .robot-btn::after, .robot-btn:hover .robot-img, .robot-btn:focus-visible .robot-img,
  .robot-btn:hover::after, .robot-btn:focus-visible::after { animation: none; }
  .robot-bubble { transition: none; }
}

/* ---------- Panel de ayuda (no modal) ----------
   Fijo a la ventana, arriba del robot, sin importar dónde quedó el robot en la página (al final de una página o en una
   página corta, el robot no está pegado al borde): con el panel abierto, el robot también se fija abajo a la derecha.
   Su alto deja libre la barra superior (hasta dos filas) para que nunca quede debajo de ella. */
.robot.abierto .robot-btn { position: fixed; right: 24px; bottom: 20px; }
.robot-panel {
  position: fixed; right: 24px; bottom: 126px;
  width: min(440px, calc(100vw - 48px)); max-height: min(680px, calc(100vh - 270px)); overflow: auto; overscroll-behavior: contain;
  border-radius: var(--radius); border: 1px solid var(--line-strong); background: #1a1c1f; box-shadow: var(--lift);
}
.robot-panel[hidden] { display: none; }
.robot-panel-head {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 12px;
  padding: 14px 14px 12px 16px; border-bottom: 1px solid var(--line); background: #1f2226;
}
.robot-panel-avatar { width: 48px; height: 48px; flex: 0 0 auto; }
.robot-panel-head > div { min-width: 0; flex: 1 1 auto; }
.robot-panel-head h2 { margin: 0; font-size: 18px; line-height: 1.25; }
.robot-panel-head h2:focus { outline: none; }
.robot-panel-head h2:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
.robot-kicker { margin: 0 0 2px; color: var(--accent); font-size: 12.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.robot-close {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
  border-radius: 10px; border: 1px solid var(--line-strong); background: var(--tile); color: var(--soft); cursor: pointer;
}
.robot-close:hover { color: var(--text); border-color: rgba(255, 255, 255, .3); }

.robot-panel-body { display: grid; gap: 12px; padding: 16px; font-size: 15px; line-height: 1.55; }
.robot-panel-body > p { margin: 0; color: var(--soft); }
.robot-panel-body h3 { margin: 8px 0 0; font-size: 15px; color: var(--text); }
.robot-panel-foot { margin: 6px 0 0; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); }

/* ---------- Bloques de ayuda (robot y preguntas frecuentes) ---------- */
.ayuda-items { display: grid; gap: 8px; }
.ayuda-item { border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #1f2226; }
.ayuda-item > summary {
  cursor: pointer; padding: 11px 14px; font-weight: 600; list-style-position: inside; border-radius: var(--radius-sm);
}
.ayuda-item > summary:focus-visible { outline: var(--focus-ring); outline-offset: -2px; }
.ayuda-item[open] > summary { border-bottom: 1px solid var(--line); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.ayuda-item-body { display: grid; gap: 10px; padding: 12px 14px 14px; color: var(--soft); }
.ayuda-item-body p, .faq-answer p { margin: 0; }
.ayuda-item-body .btn { justify-self: start; }
.ayuda-guia > summary { color: var(--accent); }
.ayuda-pasos { margin: 0; padding-left: 22px; display: grid; gap: 12px; }
.ayuda-pasos h4 { margin: 0 0 4px; font-size: 15px; color: var(--text); }
.ayuda-pasos li > :not(h4) + * { margin-top: 6px; }
.ayuda-lista { margin: 0; padding-left: 22px; display: grid; gap: 4px; }
.ayuda-codigo {
  margin: 0; padding: 10px 12px; overflow-x: auto; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--input); font-family: var(--mono); font-size: 13.5px; line-height: 1.6; color: #e6e8eb; white-space: pre;
}
.robot-panel code, .faq-answer code { font-family: var(--mono); font-size: .92em; color: #bae6fd; overflow-wrap: anywhere; }
.ayuda-codigo code { color: inherit; overflow-wrap: normal; }
.ayuda-pendiente { margin: 0; }
.ayuda-preguntas { margin: 0; padding-left: 20px; display: grid; gap: 6px; }

/* Con el robot en pantalla, el desplazamiento por foco deja su lugar libre: un control enfocado no queda debajo. */
html.con-robot { scroll-padding-bottom: 136px; }

@media (max-width: 700px) {
  .robot { height: 68px; margin: 0 12px 12px; bottom: 12px; }
  .robot-btn, .robot-img { width: 68px; height: 68px; }
  .robot-bubble { top: 12px; }
  .robot.abierto .robot-btn { right: 12px; bottom: 12px; }
  .robot-panel { left: 8px; right: 8px; bottom: 92px; width: auto; max-height: calc(100vh - 230px); }
  html.con-robot { scroll-padding-bottom: 100px; }
}
@supports (height: 100dvh) {
  .robot-panel { max-height: min(680px, calc(100dvh - 270px)); }
  @media (max-width: 700px) { .robot-panel { max-height: calc(100dvh - 230px); } }
}

/* ---------- Cabecera pública: enlace a las preguntas frecuentes ---------- */
/* «Preguntas frecuentes» de la cabecera pública: tarjeta con su ícono, como todo botón del portal. */
.topbar-link {
  display: inline-flex; align-items: center; gap: 10px; min-height: 46px; padding: 5px 12px 5px 5px; border-radius: 12px;
  color: var(--text); font-size: 14px; font-weight: 650; text-decoration: none;
  background: var(--raised); border: 1px solid var(--line); box-shadow: var(--lift);
}
.topbar-link > svg:first-child { flex: 0 0 auto; box-sizing: content-box; width: 16px; height: 16px; padding: 6px; border-radius: 8px; color: var(--soft); background: var(--tile); border: 1px solid var(--line-strong); }
.topbar-link:hover { border-color: var(--line-strong); background: linear-gradient(180deg, #25282d, #1e2125); }
@media (max-width: 560px) {
  .topbar-link { padding-right: 5px; }
  .topbar-panel { padding-right: 6px; }
  .topbar-link-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  /* Con «Instrucciones de uso» (GE-05) y la sesión iniciada, los botones y el idioma pueden no entrar en un renglón:
     pasan al siguiente, a la derecha, sin desplazamiento horizontal. */
  .topbar-public .topbar-end { flex-wrap: wrap; justify-content: flex-end; }
}

/* ---------- Página de preguntas frecuentes ---------- */
.faq-intro { display: flex; align-items: center; gap: 20px; padding: 20px; border-radius: var(--radius); margin-bottom: 20px; }
.faq-robot { width: 120px; height: 120px; flex: 0 0 auto; }
.faq-search { flex: 1 1 auto; display: grid; gap: 8px; min-width: 0; }
.faq-search label { font-weight: 600; }
.faq-search p { margin: 0; }
.faq-groups { display: grid; gap: 18px; }
.faq-group[hidden] { display: none; }
.faq-list { display: grid; gap: 8px; }
.faq-item { border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #1f2226; scroll-margin-top: 90px; }
.faq-item[hidden] { display: none; }
.faq-item > summary { cursor: pointer; padding: 12px 16px; font-weight: 600; border-radius: var(--radius-sm); }
.faq-item > summary:focus-visible { outline: var(--focus-ring); outline-offset: -2px; }
.faq-item[open] > summary { border-bottom: 1px solid var(--line); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.faq-answer { display: grid; gap: 10px; padding: 14px 16px 16px; color: var(--soft); line-height: 1.6; }
.faq-foot { margin-top: 20px; }
@media (max-width: 600px) {
  .faq-intro { flex-direction: column; align-items: stretch; text-align: left; }
  .faq-robot { width: 96px; height: 96px; align-self: center; }
}

/* Ventanas bajas y anchas (un teléfono apaisado): el panel va al costado del robot, debajo de la barra superior. */
@media (min-width: 701px) and (max-height: 560px) {
  .robot-panel { right: 128px; bottom: 20px; width: min(440px, calc(100vw - 180px)); max-height: calc(100vh - 150px); }
  @supports (height: 100dvh) { .robot-panel { max-height: calc(100dvh - 150px); } }
}

/* ---------- Acompañante: el robot junto al campo enfocado ----------
   Uno chico a la derecha de la etiqueta del campo (sin tapar la caja). Mientras está de visita, el robot grande se
   oculta. Llega con una animación corta (quieta con «reducir movimiento»). La nube con la ayuda del campo se abre al
   tocarlo, debajo del campo. */
.robot .robot-btn { transition: opacity .25s ease, transform .25s ease, visibility 0s linear 0s; }
.robot.de-visita:not(.abierto) .robot-btn { opacity: 0; transform: translateY(12px) scale(.85); visibility: hidden; transition: opacity .25s ease, transform .25s ease, visibility 0s linear .25s; }
.field.con-acompanante { position: relative; }
.field.con-acompanante > label { padding-right: 44px; }
.robot-mini {
  position: absolute; right: 0; top: -12px; z-index: 6; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%;
  background: none; cursor: pointer;
}
.robot-mini-img { display: block; width: 40px; height: 40px; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .5)) drop-shadow(0 0 10px rgba(53, 206, 255, .35)); }
.robot-mini.llega .robot-mini-img { animation: robot-llega .45s cubic-bezier(.2, .8, .3, 1.2) both, robot-saluda 1.2s ease-in-out .45s 1; }
@keyframes robot-llega { from { opacity: 0; transform: translate(28px, 18px) scale(.4); } to { opacity: 1; transform: none; } }
@keyframes robot-saluda { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-10deg); } 60% { transform: rotate(8deg); } }
.robot-mini:hover .robot-mini-img, .robot-mini[aria-expanded="true"] .robot-mini-img { filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .5)) drop-shadow(0 0 14px rgba(53, 206, 255, .7)); }
.robot-mini:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
.robot-mini-tip {
  position: absolute; right: calc(100% + 6px); top: 8px; white-space: nowrap; padding: 4px 10px; border-radius: 999px;
  border: 1px solid rgba(53, 206, 255, .45); background: #1f2226; color: var(--text); font-size: 13px; font-weight: 600;
  opacity: 0; transform: translateX(6px); transition: opacity .15s ease, transform .15s ease; pointer-events: none;
}
.robot-mini:hover .robot-mini-tip { opacity: 1; transform: none; }
.robot-mini[aria-expanded="true"] .robot-mini-tip { display: none; }
.robot-nube {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 7; width: min(400px, 100%); max-height: min(60vh, 460px); overflow: auto;
  border-radius: var(--radius-sm); border: 1px solid rgba(53, 206, 255, .45); background: #1a1c1f; box-shadow: var(--lift);
  font-size: 14.5px; line-height: 1.5;
}
.robot-nube[hidden] { display: none; }
.robot-nube-cabeza { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; border-bottom: 1px solid var(--line); background: #1f2226; }
.robot-nube-cabeza strong { flex: 1 1 auto; min-width: 0; }
.robot-nube-avatar { width: 28px; height: 28px; flex: 0 0 auto; }
.robot-nube-cuerpo { display: grid; gap: 8px; padding: 12px; color: var(--soft); }
.robot-nube-cuerpo p { margin: 0; }
.robot-nube-pie { margin: 0; padding: 0 12px 12px; }
@media (prefers-reduced-motion: reduce) {
  .robot-mini.llega .robot-mini-img { animation: none; }
  .robot .robot-btn, .robot.de-visita:not(.abierto) .robot-btn { transition: none; }
}
