/* Story 18.6 (Bot de apoyo), Fase 4: el widget (templates/components/support_bot.html.twig, public/tml/support-bot.js).
   Estilos propios con el prefijo tml-bot-: sirven igual en los layouts nuevos (tml.css) y en los viejos (Bootstrap).
   - Esquina inferior derecha; sube con el aviso de abajo que este visible (instalar la app, notificaciones o huella:
     --bottom-notice-offset, de public/js/bottom-notices.js).
   - z-index 1030: por encima de la guia (hasta 1003) y por debajo del fondo de los modales de Bootstrap (1040), del
     menu del celular (1100) y del aviso de cookies.
   - El Triple Apoyo (contact/triple_apoyo_chat.css) sigue en right: 90px; no se toca.
   - 18/10: con el boton "Ayuda" la burbuja de Triple Apoyo se oculta y su chat se abre desde el menu (ver abajo). */
.tml-bot {
  --tml-bot-primary: #1E40AF;
  --tml-bot-deep: #172554;
  --tml-bot-soft: #EEF3FF;
  --tml-bot-growth: #10B981;
  --tml-bot-ink: #0F172A;
  --tml-bot-muted: #475569;
  --tml-bot-line: #E2E8F0;
  --tml-bot-bg: #F7F9FC;
  --tml-bot-danger: #B42318;
  --tml-bot-bottom: calc(20px + var(--bottom-notice-offset, 0px));
  position: fixed;
  right: 20px;
  bottom: var(--tml-bot-bottom);
  z-index: 1030;
  font-family: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--tml-bot-ink);
  text-align: left;
}
.tml-bot *, .tml-bot *::before, .tml-bot *::after { box-sizing: border-box; }
.tml-bot[hidden], .tml-bot [hidden] { display: none !important; }
.tml-bot p { margin: 0; }
.tml-bot button { font-family: inherit; }

/* El boton "Ayuda" (18/10, Nelson, artefacto "Botón único de ayuda"): en el celular, redondo con el auricular y la
   etiqueta "Ayuda" a su izquierda; desde 768px, ancho con el texto adentro. Abierto (menu, bot o equipo), una X y
   "Cerrar". Reemplaza las 2 burbujas de la Story 9.12. */
.tml-bot-bubble { position: relative; z-index: 1; width: 56px; height: 56px; padding: 0; border-radius: 999px; border: 2px solid #FFFFFF; background: var(--tml-bot-deep); color: #FFFFFF; display: inline-flex; align-items: center; justify-content: center; gap: 10px; cursor: pointer; font-family: inherit; box-shadow: 0 10px 24px rgba(15, 23, 42, .22); transition: transform .2s, background-color .2s; }
.tml-bot-bubble:hover { background: var(--tml-bot-primary); transform: translateY(-2px); }
.tml-bot-bubble:focus { outline: none; }
.tml-bot-bubble:focus-visible { outline: 3px solid var(--tml-bot-growth); outline-offset: 3px; }
.tml-bot-icon-close, .tml-bot-tag-close { display: none; }
.tml-bot-any-open .tml-bot-icon-help, .tml-bot-any-open .tml-bot-tag-help { display: none; }
.tml-bot-any-open .tml-bot-icon-close { display: block; }
.tml-bot-any-open .tml-bot-tag-close { display: inline; }
.tml-bot-tag { position: absolute; right: calc(100% + 8px); top: 50%; transform: translateY(-50%); white-space: nowrap; padding: 4px 12px; border-radius: 999px; background: #FFFFFF; color: var(--tml-bot-deep); border: 1px solid var(--tml-bot-line); font-size: 13px; font-weight: 600; box-shadow: 0 4px 12px rgba(15, 23, 42, .12); pointer-events: none; }
.tml-bot-any-open .tml-bot-tag { display: none; }
/* Los mensajes sin leer del equipo */
.tml-bot-unseen { position: absolute; top: -6px; right: -6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; border: 2px solid #FFFFFF; background: var(--tml-bot-danger); color: #FFFFFF; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.tml-bot-any-open .tml-bot-unseen { display: none; }

@media (min-width: 768px) {
  .tml-bot-bubble { width: auto; padding: 0 22px 0 16px; font-size: 16px; font-weight: 600; }
  .tml-bot-tag { position: static; transform: none; padding: 0; border: 0; background: none; color: inherit; box-shadow: none; font-size: 16px; }
  .tml-bot-any-open .tml-bot-tag { display: inline; }
  .tml-bot-unseen { position: static; border: 0; line-height: 22px; }
}

/* El menu "¿Con quién quieres hablar?" (solo con el chat de Triple Apoyo en la pagina). En el celular oscurece la pagina
   detras; en escritorio no. */
.tml-bot-scrim { position: fixed; inset: 0; background: rgba(15, 23, 42, .38); }
.tml-bot-menu { position: absolute; z-index: 1; right: 0; bottom: 70px; width: 310px; max-width: calc(100vw - 32px); padding: 14px; display: flex; flex-direction: column; gap: 10px; background: #FFFFFF; border: 1px solid var(--tml-bot-line); border-radius: 18px; box-shadow: 0 24px 60px rgba(15, 23, 42, .25); }
.tml-bot .tml-bot-menu-title { margin: 0 4px 2px; font-size: 15px; font-weight: 700; color: var(--tml-bot-deep); }
.tml-bot-option { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 10px 12px; border: 1px solid var(--tml-bot-line); border-radius: 14px; background: #FFFFFF; color: var(--tml-bot-ink); text-align: left; font-family: inherit; cursor: pointer; }
.tml-bot-option:hover, .tml-bot-option:focus-visible { outline: none; border-color: var(--tml-bot-primary); box-shadow: 0 0 0 3px rgba(30, 64, 175, .15); }
.tml-bot-option-icon { flex: none; width: 44px; height: 44px; border-radius: 12px; background: var(--tml-bot-soft); color: var(--tml-bot-deep); display: inline-flex; align-items: center; justify-content: center; }
.tml-bot-option-team .tml-bot-option-icon { background: #F1EDFB; color: #5435B0; }
.tml-bot-option-text { flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tml-bot-option-name { font-size: 15px; font-weight: 600; }
.tml-bot-option-desc { font-size: 13px; color: var(--tml-bot-muted); }
.tml-bot-option-unseen { flex: none; padding: 2px 8px; border-radius: 999px; background: var(--tml-bot-danger); color: #FFFFFF; font-size: 12px; font-weight: 700; white-space: nowrap; }
@media (min-width: 768px) {
  .tml-bot-scrim { display: none !important; }
  .tml-bot-menu { width: 340px; }
}

/* Con el boton "Ayuda" la burbuja morada de Triple Apoyo no se ve: su chat se abre desde "Tu equipo" (support-bot.js) */
body.tml-help-unified #contactChat .chat-btn, body.tml-help-unified #contactChat #global-unseen { display: none !important; }

/* El final de la pagina deja libre el lugar del boton: nada queda debajo de el (#315). #485: en todos los contextos
   donde esta el boton, tambien en el sitio publico (antes solo en el panel y el Carrusel). La red social (Framework7,
   #framework7-root) tiene su propio alto y no lo necesita. Suma lo que sube el boton con el aviso de abajo visible
   (--bottom-notice-offset). */
body:not(:has(#framework7-root)):has(.tml-bot) { padding-bottom: calc(88px + var(--bottom-notice-offset, 0px)); }

/* El panel */
.tml-bot-panel { position: absolute; right: 0; bottom: 70px; width: 380px; max-width: calc(100vw - 32px); max-height: calc(100vh - 110px - var(--bottom-notice-offset, 0px)); display: flex; flex-direction: column; background: #FFFFFF; border: 1px solid var(--tml-bot-line); border-radius: 18px; box-shadow: 0 24px 60px rgba(15, 23, 42, .25); overflow: hidden; }
.tml-bot-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 14px 14px 18px; background: var(--tml-bot-deep); color: #FFFFFF; }
.tml-bot .tml-bot-title { font-size: 17px; font-weight: 700; color: #FFFFFF; }
.tml-bot .tml-bot-sub { font-size: 13px; color: rgba(255, 255, 255, .8); }
.tml-bot-close { flex: none; width: 40px; height: 40px; padding: 0; border: none; border-radius: 10px; background: transparent; color: #FFFFFF; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.tml-bot-close:hover { background: rgba(255, 255, 255, .15); }
.tml-bot-close:focus-visible { outline: 3px solid var(--tml-bot-growth); outline-offset: 0; }

.tml-bot-notice { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.tml-bot .tml-bot-notice-title { font-weight: 700; color: var(--tml-bot-deep); }
.tml-bot-notice p { color: var(--tml-bot-muted); }

.tml-bot-body { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; overflow-y: auto; background: var(--tml-bot-bg); }
.tml-bot-log { display: flex; flex-direction: column; gap: 8px; padding: 14px; min-height: 160px; }
.tml-bot-msg { display: flex; }
.tml-bot-msg-text { padding: 9px 13px; border-radius: 14px; max-width: 85%; white-space: pre-line; overflow-wrap: anywhere; }
.tml-bot-msg-bot .tml-bot-msg-text { background: var(--tml-bot-soft); color: var(--tml-bot-ink); border-top-left-radius: 4px; }
.tml-bot-msg-user { justify-content: flex-end; }
.tml-bot-msg-user .tml-bot-msg-text { background: var(--tml-bot-primary); color: #FFFFFF; border-top-right-radius: 4px; }
.tml-bot-msg-wait .tml-bot-msg-text { color: var(--tml-bot-muted); font-style: italic; }
.tml-bot-faqs { display: flex; flex-wrap: wrap; gap: 6px; }
.tml-bot .tml-bot-faqs-title { width: 100%; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--tml-bot-muted); }
.tml-bot-chip { min-height: 36px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--tml-bot-primary); background: #FFFFFF; color: var(--tml-bot-primary); font-size: 14px; text-align: left; cursor: pointer; }
.tml-bot-chip:hover, .tml-bot-chip:focus-visible { background: var(--tml-bot-soft); outline: none; box-shadow: 0 0 0 3px rgba(30, 64, 175, .18); }
.tml-bot-chip-leave { border-color: #047857; color: #047857; }

/* El mensaje a soporte */
.tml-bot-form { margin: 0 14px 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: #FFFFFF; border: 1px solid var(--tml-bot-line); border-radius: 14px; }
.tml-bot .tml-bot-form-title { font-weight: 700; color: var(--tml-bot-deep); }
.tml-bot .tml-bot-form-note { font-size: 13px; color: var(--tml-bot-muted); }
.tml-bot-guest { display: flex; flex-direction: column; gap: 10px; }
.tml-bot-field { display: flex; flex-direction: column; gap: 4px; margin: 0; font-size: 13px; font-weight: 600; color: var(--tml-bot-ink); }
.tml-bot-field input, .tml-bot-field textarea { width: 100%; min-height: 42px; margin: 0; padding: 8px 12px; border: 1px solid var(--tml-bot-line); border-radius: 10px; background: #FFFFFF; color: var(--tml-bot-ink); font-size: 16px; font-weight: 400; line-height: 1.4; font-family: inherit; }
.tml-bot-field textarea { resize: vertical; min-height: 72px; }
.tml-bot-field input:focus, .tml-bot-field textarea:focus { outline: none; border-color: var(--tml-bot-primary); box-shadow: 0 0 0 3px rgba(30, 64, 175, .15); }
.tml-bot [aria-invalid="true"] { border: 2px solid var(--tml-bot-danger); }
.tml-bot-consent { display: flex; align-items: flex-start; gap: 8px; margin: 0; font-size: 13px; font-weight: 400; color: var(--tml-bot-muted); }
.tml-bot-consent input { flex: none; width: 18px; height: 18px; margin: 2px 0 0; }
.tml-bot-consent input[aria-invalid="true"] { outline: 2px solid var(--tml-bot-danger); outline-offset: 2px; }
.tml-bot-consent a { color: var(--tml-bot-primary); text-decoration: underline; }
.tml-bot .tml-bot-form-error { font-size: 13px; color: var(--tml-bot-danger); }
.tml-bot-hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.tml-bot-btn { min-height: 44px; padding: 0 18px; border: none; border-radius: 10px; background: var(--tml-bot-primary); color: #FFFFFF; font-size: 15px; font-weight: 600; cursor: pointer; }
.tml-bot-btn:hover { background: var(--tml-bot-deep); }
.tml-bot-btn:focus-visible { outline: 3px solid var(--tml-bot-growth); outline-offset: 2px; }
.tml-bot-btn[disabled], .tml-bot-send[disabled] { opacity: .6; cursor: progress; }

/* La pregunta */
.tml-bot-ask { position: sticky; bottom: 0; display: flex; gap: 8px; margin: auto 0 0; padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px)); background: #FFFFFF; border-top: 1px solid var(--tml-bot-line); }
.tml-bot-ask input { flex: 1 1 auto; min-width: 0; min-height: 44px; margin: 0; padding: 0 12px; border: 1px solid var(--tml-bot-line); border-radius: 10px; background: #FFFFFF; color: var(--tml-bot-ink); font-size: 16px; font-family: inherit; }
.tml-bot-ask input:focus { outline: none; border-color: var(--tml-bot-primary); box-shadow: 0 0 0 3px rgba(30, 64, 175, .15); }
.tml-bot-send { flex: none; width: 44px; height: 44px; padding: 0; border: none; border-radius: 10px; background: var(--tml-bot-primary); color: #FFFFFF; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.tml-bot-send:hover { background: var(--tml-bot-deep); }
.tml-bot-send:focus-visible { outline: 3px solid var(--tml-bot-growth); outline-offset: 2px; }

.tml-bot-sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Celular: el panel nunca pasa del ancho de la pantalla (sin scroll horizontal) */
@media (max-width: 640px) {
  .tml-bot-panel { width: calc(100vw - 32px); max-height: calc(100vh - 100px - var(--bottom-notice-offset, 0px)); max-height: calc(100dvh - 100px - var(--bottom-notice-offset, 0px)); }
}
@media (prefers-reduced-motion: reduce) { .tml-bot-bubble { transition: none; } }

/* 18/10 (Nelson): con el chat del bot abierto, el widget queda por encima de todo (la Guia rapida, las vistas de la red
   social, el panel "Mas") y el fondo oscuro tapa la pagina, en el celular y en escritorio: no se toca lo de atras y al
   tocarlo se cierra el chat. La X del boton y el panel quedan encima del fondo. */
.tml-bot.tml-bot-open, body:has(#framework7-root) .tml-bot.tml-bot-open { z-index: 7000; }
.tml-bot.tml-bot-open .tml-bot-scrim { display: block !important; }
.tml-bot-panel { z-index: 1; }
.tml-bot.tml-bot-open .tml-bot-scrim { background: rgba(15, 23, 42, .5); }

/* 19/10 (Nelson, celular): con varias preguntas se desplazaba todo el cuerpo del panel y la caja de preguntar, "sticky",
   quedaba a mitad de los mensajes; ademas support-bot.js baja la lista (log.scrollTop) y la que se desplazaba era el cuerpo,
   asi que nunca llegaba al ultimo mensaje. Ahora solo se desplaza la lista de mensajes; el formulario para hablar con una
   persona (si esta abierto) y la caja de preguntar quedan fijos abajo, como en cualquier chat. */
.tml-bot-body { overflow: hidden; }
.tml-bot-log { flex: 1 1 auto; min-height: 96px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.tml-bot-form { flex: none; max-height: 55%; overflow-y: auto; }
.tml-bot-ask { position: static; flex: none; margin-top: 0; }
/* 19/10 (Nelson): una pregunta ya respondida no se repite (support-bot.js). La pregunta frecuente ya hecha lleva ✓ y un tono
   mas suave; al tocarla, el chat sube a su respuesta y la resalta un momento. */
.tml-bot-chip.is-asked { background: var(--tml-bot-bg); color: var(--tml-bot-muted); border-color: var(--tml-bot-line); }
.tml-bot-chip.is-asked::before { content: "✓ "; color: var(--tml-bot-growth); font-weight: 700; }
.tml-bot-msg-flash .tml-bot-msg-text { animation: tml-bot-flash 1.6s ease-out; }
@keyframes tml-bot-flash { 0%, 35% { box-shadow: 0 0 0 3px rgba(16, 185, 129, .55); background: #ECFDF5; } 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); } }
@media (prefers-reduced-motion: reduce) { .tml-bot-msg-flash .tml-bot-msg-text { animation: none; box-shadow: 0 0 0 3px rgba(16, 185, 129, .55); } }
