/* ==========================================================================
   Chat en vivo — burbuja flotante y panel de conversación
   ========================================================================== */

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

/* ---- Burbuja flotante --------------------------------------------------- */
.chat-burbuja {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .6rem;
}

.chat-burbuja__boton {
  position: relative;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(145deg, #1b4a57 0%, #0f2b33 100%);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px rgba(15, 43, 51, .32), 0 2px 6px rgba(15, 43, 51, .2);
  transition: transform .2s ease, box-shadow .2s ease;
}
.chat-burbuja__boton:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 10px 26px rgba(15, 43, 51, .38);
}
.chat-burbuja__boton:active { transform: scale(.97); }
.chat-burbuja__boton:focus-visible {
  outline: 3px solid var(--dorado, #c9a227);
  outline-offset: 3px;
}

.chat-burbuja__ico-abrir,
.chat-burbuja__ico-cerrar {
  width: 27px; height: 27px;
  grid-area: 1 / 1;
  transition: opacity .18s ease, transform .25s ease;
}
.chat-burbuja__ico-cerrar { opacity: 0; transform: rotate(-90deg) scale(.7); }
.chat-abierto .chat-burbuja__ico-abrir { opacity: 0; transform: rotate(90deg) scale(.7); }
.chat-abierto .chat-burbuja__ico-cerrar { opacity: 1; transform: none; }

.chat-burbuja__punto {
  position: absolute;
  top: 4px; right: 4px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--rojo, #dc2626);
  border: 2px solid #fff;
  animation: chat-pulso 1.6s ease-in-out infinite;
}
@keyframes chat-pulso {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.18); opacity: .78; }
}

/* ---- Aviso automático --------------------------------------------------- */
.chat-burbuja__aviso {
  position: relative;
  max-width: 230px;
  padding: .7rem 2rem .7rem .9rem;
  background: #fff;
  border: 1px solid #e6e1d7;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(15, 43, 51, .16);
  font-size: .87rem;
  line-height: 1.4;
  color: var(--texto, #14232a);
  animation: chat-aparecer .32s ease;
}
.chat-burbuja__aviso::after {
  content: "";
  position: absolute;
  right: 22px; bottom: -7px;
  width: 12px; height: 12px;
  background: #fff;
  border-right: 1px solid #e6e1d7;
  border-bottom: 1px solid #e6e1d7;
  transform: rotate(45deg);
}
.chat-burbuja__cerrar-aviso {
  position: absolute;
  top: .25rem; right: .35rem;
  width: 22px; height: 22px;
  border: 0; background: transparent;
  font-size: 1.1rem; line-height: 1;
  color: #8a9aa1;
  cursor: pointer;
  border-radius: 50%;
}
.chat-burbuja__cerrar-aviso:hover { background: #f1ece1; color: #4a5a60; }

@keyframes chat-aparecer {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to { opacity: 1; transform: none; }
}

/* ---- Panel ------------------------------------------------------------- */
.chat-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 6rem;
  z-index: 901;
  width: min(380px, calc(100vw - 2rem));
  height: min(560px, calc(100vh - 8rem));
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid #e6e1d7;
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(15, 43, 51, .22), 0 4px 14px rgba(15, 43, 51, .1);
  overflow: hidden;
  animation: chat-panel-entrar .24s cubic-bezier(.3, .9, .4, 1);
}
.chat-panel[hidden] { display: none; }

@keyframes chat-panel-entrar {
  from { opacity: 0; transform: translateY(16px) scale(.97); }
  to { opacity: 1; transform: none; }
}

.chat-panel__cabecera {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  padding: .8rem .9rem;
  background: linear-gradient(150deg, #123a45 0%, #0f2b33 100%);
  color: #fff;
  flex: 0 0 auto;
}
.chat-panel__identidad { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.chat-panel__avatar {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .14);
  color: var(--dorado, #c9a227);
}
.chat-panel__avatar svg { width: 20px; height: 20px; }
.chat-panel__titulo {
  margin: 0;
  font-size: .95rem;
  font-weight: 650;
  letter-spacing: -.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-panel__estado {
  margin: 0;
  font-size: .74rem;
  color: rgba(255, 255, 255, .68);
}
.chat-panel__cerrar {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  cursor: pointer;
}
.chat-panel__cerrar:hover { background: rgba(255, 255, 255, .22); }
.chat-panel__cerrar svg { width: 16px; height: 16px; }

/* ---- Mensajes ---------------------------------------------------------- */
.chat-panel__mensajes {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem .9rem .4rem;
  background: #f7f5f0;
  display: flex;
  flex-direction: column;
  gap: .55rem;
  scroll-behavior: smooth;
}
.chat-panel__mensajes::-webkit-scrollbar { width: 6px; }
.chat-panel__mensajes::-webkit-scrollbar-thumb {
  background: #d7d0c2;
  border-radius: 3px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: chat-aparecer .2s ease;
}
.chat-msg--mio { align-self: flex-end; align-items: flex-end; }
.chat-msg--otro { align-self: flex-start; align-items: flex-start; }

.chat-msg__globo {
  padding: .6rem .8rem;
  border-radius: 14px;
  font-size: .885rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg--mio .chat-msg__globo {
  background: var(--marca, #0f2b33);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg--otro .chat-msg__globo {
  background: #fff;
  color: var(--texto, #14232a);
  border: 1px solid #e6e1d7;
  border-bottom-left-radius: 4px;
}

/* Enlace de la reserva dentro del mensaje del bot ------------------------- */
.chat-msg__enlace {
  color: var(--marca, #0f2b33);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.chat-msg__enlace:hover { color: var(--marca-clara, #1b4a57); }
.chat-msg__hora {
  margin-top: .18rem;
  font-size: .68rem;
  color: #93a3aa;
  padding: 0 .25rem;
}

.chat-msg--sistema {
  align-self: center;
  max-width: 92%;
  margin: .15rem 0;
  padding: .35rem .7rem;
  font-size: .75rem;
  line-height: 1.4;
  text-align: center;
  color: #6b7c85;
  background: #efece4;
  border-radius: 999px;
}

/* ---- Sugerencias ------------------------------------------------------- */
.chat-panel__sugerencias {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: .38rem;
  padding: .5rem .9rem;
  background: #f7f5f0;
  border-top: 1px solid #ece8df;
}
.chat-panel__sugerencias:empty { display: none; }

.chat-sugerencia {
  padding: .38rem .7rem;
  border: 1px solid #d9d2c4;
  border-radius: 999px;
  background: #fff;
  color: var(--marca-clara, #1b4a57);
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.chat-sugerencia:hover { background: #f1ece1; border-color: #c9a227; }

/* ---- Formulario -------------------------------------------------------- */
.chat-panel__form {
  flex: 0 0 auto;
  display: flex;
  gap: .45rem;
  padding: .7rem .8rem;
  background: #fff;
  border-top: 1px solid #ece8df;
}
.chat-panel__input {
  flex: 1 1 auto;
  min-width: 0;
  padding: .62rem .8rem;
  border: 1px solid #ddd6c8;
  border-radius: 999px;
  font: inherit;
  font-size: .89rem;
  color: var(--texto, #14232a);
  background: #fbfaf7;
}
.chat-panel__input:focus {
  outline: 2px solid rgba(201, 162, 39, .45);
  outline-offset: 1px;
  border-color: var(--dorado, #c9a227);
  background: #fff;
}
.chat-panel__enviar {
  flex: 0 0 42px;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--marca, #0f2b33);
  color: #fff;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
}
.chat-panel__enviar:hover { background: var(--marca-clara, #1b4a57); }
.chat-panel__enviar:active { transform: scale(.94); }
.chat-panel__enviar:disabled { opacity: .5; cursor: default; }
.chat-panel__enviar svg { width: 18px; height: 18px; }

/* ---- Adaptación a móvil ------------------------------------------------ */
@media (max-width: 560px) {
  .chat-burbuja { right: .85rem; bottom: .85rem; }
  .chat-burbuja__boton { width: 54px; height: 54px; }
  .chat-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: min(82vh, 620px);
    border-radius: 18px 18px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }
  .chat-msg { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel,
  .chat-msg,
  .chat-burbuja__aviso { animation: none; }
  .chat-panel__mensajes { scroll-behavior: auto; }
}

/* ==========================================================================
   Controles de voz del chat
   ========================================================================== */

/* ---- Botón de micrófono (dictar) --------------------------------------- */
.chat-panel__voz {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid #ddd6c8;
  border-radius: 50%;
  background: #fbfaf7;
  color: #5b6f78;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.chat-panel__voz:hover {
  background: #f1ece1;
  color: var(--marca, #0f2b33);
  border-color: #c9a227;
}
.chat-panel__voz svg { width: 19px; height: 19px; }

/* Dictando: rojo y pulsante para que se note que escucha. */
.chat-panel__voz.is-escuchando {
  background: #dc2626;
  border-color: #b91c1c;
  color: #fff;
  animation: chat-mic-pulso 1.3s ease-in-out infinite;
}
@keyframes chat-mic-pulso {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .55); }
  50%      { box-shadow: 0 0 0 9px rgba(220, 38, 38, 0); }
}

/* ---- Barra inferior: activar la lectura -------------------------------- */
.chat-panel__voz-barra {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .4rem .8rem .55rem;
  background: #fff;
}

.chat-voz-toggle {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .34rem .7rem;
  border: 1px solid #ddd6c8;
  border-radius: 999px;
  background: #fbfaf7;
  color: #5b6f78;
  font: inherit;
  font-size: .78rem;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.chat-voz-toggle:hover { background: #f1ece1; color: var(--marca, #0f2b33); }
.chat-voz-toggle svg { width: 15px; height: 15px; }

.chat-voz-toggle.is-activo {
  background: var(--marca, #0f2b33);
  border-color: var(--marca, #0f2b33);
  color: #fff;
}
.chat-voz-toggle.is-activo:hover { background: #1b4a57; color: #fff; }

/* ---- Modo manos libres ------------------------------------------------- */
.chat-voz-manos {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .34rem .7rem;
  border: 1px solid #ddd6c8;
  border-radius: 999px;
  background: #fbfaf7;
  color: #5b6f78;
  font: inherit;
  font-size: .78rem;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.chat-voz-manos:hover { background: #f1ece1; color: var(--marca, #0f2b33); }
.chat-voz-manos svg { width: 15px; height: 15px; }
.chat-voz-manos[hidden] { display: none; }

.chat-voz-manos.is-activo {
  background: #b3261e;
  border-color: #b3261e;
  color: #fff;
}
.chat-voz-manos.is-activo:hover { background: #93201a; color: #fff; }

.chat-voz-estado {
  font-size: .75rem;
  color: var(--marca-clara, #1b4a57);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55%;
}
.chat-voz-estado[hidden] { display: none; }

/* ---- Móvil ------------------------------------------------------------- */
@media (max-width: 560px) {
  .chat-panel__voz { flex: 0 0 40px; width: 40px; height: 40px; }
  .chat-voz-toggle { font-size: .74rem; padding: .3rem .6rem; }
  .chat-voz-manos { font-size: .74rem; padding: .3rem .6rem; }
  .chat-voz-manos span { display: none; }
  .chat-voz-estado { max-width: 45%; font-size: .7rem; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel__voz.is-escuchando { animation: none; }
}
