/* Asistente del consultorio: lanzador, barra móvil y panel de chat. */

.lanzador {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  display: inline-flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 22px 0 18px;
  background: var(--marino); color: #fff; border: 0; border-radius: 999px; font-weight: 600; font-size: 0.9375rem;
  box-shadow: 0 10px 28px -10px rgba(20, 45, 70, 0.55);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease), background-color 0.25s var(--ease);
}
.lanzador:hover { background: var(--azul); }
.lanzador .icono { width: 22px; height: 22px; }
.lanzador.oculto { opacity: 0; pointer-events: none; transform: translateY(8px); visibility: hidden; }

.barra-movil { display: none; }

.chat {
  position: fixed; right: 20px; bottom: 20px; z-index: 80;
  display: none; flex-direction: column;
  width: min(400px, calc(100vw - 24px)); height: min(660px, calc(100dvh - 40px));
  background: #fff; border: 1px solid var(--linea); border-radius: 20px; overflow: hidden;
  box-shadow: 0 24px 60px -18px rgba(20, 45, 70, 0.45);
}
.chat.abierto { display: flex; animation: chat-entra 0.3s var(--ease); }
@keyframes chat-entra { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.chat__cabeza { flex: none; display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 16px; background: var(--marino); color: #fff; }
.chat__avatar { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); }
.chat__avatar svg { width: 24px; height: 16px; }
.chat__titulos { flex: 1; min-width: 0; line-height: 1.25; }
.chat__titulos h2 { color: #fff; font-size: 0.9375rem; font-weight: 600; letter-spacing: 0; }
.chat__titulos p { font-size: 0.8125rem; color: rgba(255, 255, 255, 0.84); }
.chat__cerrar { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 999px; background: transparent; color: #fff; }
.chat__cerrar:hover { background: rgba(255, 255, 255, 0.16); }
.chat__cerrar:focus-visible { outline-color: #fff; }

/* Una única zona desplazable: mensajes, opciones de la pregunta actual y resumen */
.chat__cuerpo { position: relative; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 14px 12px; display: flex; flex-direction: column; gap: 10px; background: #fff; }
.chat__cuerpo:focus-visible { outline-offset: -3px; }
.msg { display: flex; align-items: flex-start; gap: 8px; max-width: 100%; }
.msg--usuario { justify-content: flex-end; }
.msg__avatar { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 999px; background: var(--fondo); color: var(--marino); }
.msg__avatar svg { width: 18px; height: 12px; }
.msg__burbuja { padding: 9px 13px; border-radius: 16px; font-size: 0.9375rem; line-height: 1.45; max-width: 84%; overflow-wrap: anywhere; }
.msg--asistente .msg__burbuja { background: var(--fondo); color: var(--texto); border-top-left-radius: 6px; }
.msg--usuario .msg__burbuja { background: var(--azul); color: #fff; border-top-right-radius: 6px; }
.msg--nota .msg__burbuja { background: #fff; border: 1px solid var(--linea-fuerte); }
.msg--urgencia .msg__burbuja { background: #FFF4E5; color: #5B3300; border: 1px solid #E8B56B; max-width: 90%; }

.chat__opciones { display: grid; gap: 8px; padding-left: 36px; }
.chat__grupo { display: flex; flex-wrap: wrap; gap: 8px; }
.chat__grupo-titulo { width: 100%; font-size: 0.8125rem; color: var(--suave); }
.chat__tipo { font-size: 0.875rem; color: var(--suave); display: flex; flex-wrap: wrap; align-items: center; gap: 0 4px; }
.chat__tipo strong { color: var(--marino); font-weight: 600; }
.chip { min-height: 44px; padding: 6px 16px; border-radius: 22px; background: #fff; color: var(--azul); border: 1.5px solid var(--azul); font-size: 0.9375rem; font-weight: 600; line-height: 1.25; transition: background-color 0.2s var(--ease), color 0.2s var(--ease); text-align: center; max-width: 100%; overflow-wrap: anywhere; }
.chip:hover { background: var(--azul); color: #fff; }
.chip[aria-pressed='true'] { background: var(--azul); color: #fff; }
.chip--suave { border-color: var(--borde-control); color: var(--marino); }
.chip--suave:hover { background: var(--fondo); color: var(--marino); }

.chat__pie { flex: none; padding: 8px 14px 6px; border-top: 1px solid var(--linea); background: #fff; }
.chat__form { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.chat__form input { flex: 1; min-width: 0; min-height: 46px; padding: 0 16px; border: 1.5px solid var(--borde-control); border-radius: 999px; background: var(--fondo-suave); font-size: 1rem; }
.chat__form input::placeholder { color: var(--suave); opacity: 1; }
.chat__form input:focus { outline: 0; border-color: var(--azul); box-shadow: 0 0 0 3px rgba(53, 106, 151, 0.18); background: #fff; }
.chat__enviar { flex: none; width: 46px; height: 46px; display: grid; place-items: center; border: 0; border-radius: 999px; background: var(--azul); color: #fff; }
.chat__enviar:hover { background: var(--marino); }
.chat__enviar .icono { width: 22px; height: 22px; }
.chat__enlaces { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0 12px; }
.chat__urgencia { min-height: 44px; padding: 0; border: 0; background: none; font-size: 0.875rem; font-weight: 700; color: #9A3B00; text-decoration: underline; text-underline-offset: 3px; text-align: left; }
.chat__aux { display: flex; gap: 0 16px; margin-left: auto; }
.chat__enlace { min-height: 44px; padding: 0; border: 0; background: none; font-size: 0.8125rem; font-weight: 500; color: var(--suave); text-decoration: underline; text-underline-offset: 3px; }
.chat__enlace:hover { color: var(--marino); }
.chat__tipo .chat__enlace { min-height: 44px; color: var(--azul); font-weight: 600; font-size: 0.875rem; }

/* Resumen compacto: valores completos y un «Cambiar» por dato */
.resumen { display: grid; gap: 12px; padding: 4px 2px 4px; }
.resumen__lista { display: grid; border: 1.5px solid var(--linea-fuerte); border-radius: 14px; overflow: hidden; }
.resumen__fila { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 8px; padding: 6px 6px 6px 14px; }
.resumen__fila + .resumen__fila { border-top: 1px solid var(--linea); }
.resumen__fila dt { grid-column: 1; font-size: 0.8125rem; color: var(--suave); }
.resumen__fila dd { grid-column: 1; margin: 0; font-size: 0.9375rem; font-weight: 600; color: var(--marino); overflow-wrap: anywhere; }
.resumen__cambiar { grid-column: 2; grid-row: 1 / span 2; min-height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: none; font-size: 0.875rem; font-weight: 600; color: var(--azul); text-decoration: underline; text-underline-offset: 3px; }
.resumen__cambiar:hover { background: var(--fondo-suave); }
.resumen__editor { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0 6px; }
.resumen__editor .chip { min-height: 44px; font-size: 0.875rem; padding: 6px 14px; }
.resumen__detalle summary { display: inline-flex; align-items: center; min-height: 44px; font-size: 0.875rem; font-weight: 600; color: var(--azul); cursor: pointer; }
.resumen__previa { margin: 0; padding: 10px 14px; border-left: 3px solid var(--azul); background: var(--fondo); border-radius: 0 10px 10px 0; font-size: 0.875rem; line-height: 1.5; color: var(--texto); overflow-wrap: anywhere; }
.resumen__botones { display: flex; flex-wrap: wrap; gap: 8px; }
.resumen__botones .boton { flex: 1 1 auto; min-height: 48px; }
.resumen__nota { font-size: 0.8125rem; color: var(--suave); }
.resumen__copiado { font-size: 0.875rem; font-weight: 600; color: #1D6B3F; }
.resumen__copiado:empty { display: none; }

/* Poca altura: cabecera y pie más compactos para dejar lugar a la conversación */
@media (max-height: 560px) {
  .chat__cabeza { padding-block: 4px; }
  .chat__avatar { display: none; }
  .chat__titulos p { font-size: 0.75rem; }
  .chat__cuerpo { padding-top: 10px; }
  .chat__pie { padding-top: 6px; padding-bottom: 2px; }
}

/* Móvil: panel amplio, fondo aislado y barra inferior con espacio reservado */
@media (max-width: 899px) {
  .lanzador { display: none; }
  .js body { padding-bottom: 72px; }
  .barra-movil {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
    padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom)); background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--linea); backdrop-filter: blur(8px);
  }
  .barra-movil .boton { min-height: 48px; padding: 0 12px; font-size: 0.9375rem; }
  .chat {
    left: 6px; right: 6px; width: auto; bottom: auto;
    top: calc(var(--vv-arriba, 0px) + 6px);
    height: calc(var(--vv-alto, 100dvh) - 6px);
    border-radius: 18px 18px 0 0;
  }
  .chat__opciones { padding-left: 0; }
}
@media (min-width: 900px) { .barra-movil { display: none !important; } }
@media (prefers-reduced-motion: reduce) { .chat.abierto { animation: none; } }

@media (max-width: 379px) {
  .chat__avatar { display: none; }
  .chat__cabeza { padding-left: 14px; }
}

.boton--whatsapp { width: 100%; }
.boton--whatsapp .icono { width: 22px; height: 22px; }
