/* ==========================================================================
   Maqueta · Ilustre Municipalidad de Pica
   chatbot.css — asistente virtual "Naranjín" (widget flotante)
   ========================================================================== */

.chatbot {
  --chat-bg: #f3f6fb;
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;
  z-index: 1060;
  font-family: var(--pm-font);
}

/* Mientras el menú móvil está abierto, el asistente se oculta */
body:has(.main-nav__panel.show) .chatbot,
body:has(.main-nav__panel.showing) .chatbot {
  visibility: hidden;
}

/* --------------------------------------------------------------------------
   1. Botón flotante
   -------------------------------------------------------------------------- */
.chatbot__launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 70px;
  height: 70px;
  padding: 0;
  border: 3px solid var(--pm-gold-500);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, #1E94B3 0%, var(--pm-navy-800) 75%);
  box-shadow: 0 12px 28px rgba(3, 12, 28, .45);
  transition: scale .2s ease, box-shadow .2s ease;
}

.chatbot__launcher:hover {
  scale: 1.06;
  box-shadow: 0 16px 34px rgba(3, 12, 28, .5);
}

.chatbot__launcher img {
  width: 60px;
  height: 60px;
  margin-top: 4px;
  transition: opacity .2s ease, scale .2s ease;
  animation: naranjin-bob 3.4s ease-in-out infinite;
}

.chatbot__launcher-close {
  position: absolute;
  color: #fff;
  font-size: 1.4rem;
  opacity: 0;
  scale: .6;
  transition: opacity .2s ease, scale .2s ease;
}

/* Onda que llama la atención al cargar la página */
.chatbot__launcher::after {
  content: "";
  position: absolute;
  inset: -3px;
  border: 3px solid var(--pm-gold-400);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  animation: chatbot-ping 2.4s ease-out 1.5s 3;
}

.chatbot.is-open .chatbot__launcher img {
  opacity: 0;
  scale: .6;
}

.chatbot.is-open .chatbot__launcher-close {
  opacity: 1;
  scale: 1;
}

.chatbot.is-open .chatbot__launcher::after {
  animation: none;
}

@keyframes naranjin-bob {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -3px; }
}

@keyframes chatbot-ping {
  0% { opacity: .8; scale: 1; }
  100% { opacity: 0; scale: 1.45; }
}

/* --------------------------------------------------------------------------
   2. Globo de bienvenida
   -------------------------------------------------------------------------- */
.chatbot__teaser {
  position: absolute;
  right: 84px;
  bottom: 12px;
  width: max-content;
  max-width: 240px;
  padding: .75rem 2.1rem .75rem 1rem;
  border-radius: 16px 16px 4px 16px;
  background: #fff;
  color: var(--pm-ink);
  font-size: .86rem;
  line-height: 1.35;
  box-shadow: 0 12px 30px rgba(3, 12, 28, .35);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  translate: 8px 0;
  transition: opacity .3s ease, translate .3s ease, visibility .3s;
}

.chatbot__teaser.is-visible {
  opacity: 1;
  visibility: visible;
  translate: 0 0;
}

.chatbot__teaser strong {
  display: block;
  color: var(--pm-blue-700);
}

.chatbot__teaser-close {
  position: absolute;
  top: .3rem;
  right: .3rem;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--pm-ink-soft);
  font-size: 1.1rem;
}

.chatbot__teaser-close:hover {
  background: var(--pm-blue-100);
  color: var(--pm-ink);
}

/* --------------------------------------------------------------------------
   3. Ventana del chat
   -------------------------------------------------------------------------- */
.chatbot__panel {
  position: absolute;
  right: 0;
  bottom: 88px;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 2rem));
  height: min(640px, calc(100vh - 120px));
  overflow: hidden;
  border-radius: 20px;
  background: var(--chat-bg);
  color: var(--pm-ink);
  box-shadow: 0 24px 60px rgba(3, 12, 28, .5);
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(.96);
  transform-origin: bottom right;
  transition: opacity .22s ease, transform .22s ease, visibility .22s;
}

.chatbot.is-open .chatbot__panel {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.chatbot__header {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .8rem .7rem .8rem 1rem;
  border-bottom: 3px solid var(--pm-gold-500);
  background: linear-gradient(120deg, var(--pm-blue-600) 0%, var(--pm-navy-800) 100%);
  color: #fff;
}

.chatbot__avatar {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .25);
}

/* Punto verde de "en línea" */
.chatbot__avatar::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 1px;
  width: 12px;
  height: 12px;
  border: 2px solid var(--pm-navy-800);
  border-radius: 50%;
  background: #3ddc84;
}

.chatbot__heading {
  flex: 1;
  min-width: 0;
}

.chatbot__title {
  margin: 0;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.1;
}

.chatbot__subtitle {
  margin: .15rem 0 0;
  color: rgba(255, 255, 255, .75);
  font-size: .74rem;
}

.chatbot__icon-btn {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  font-size: 1.05rem;
  transition: background-color .15s ease;
}

.chatbot__icon-btn:hover {
  background: rgba(255, 255, 255, .14);
}

.chatbot__log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: .5rem;
  padding: .75rem .9rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.chatbot__welcome {
  margin-bottom: .35rem;
  text-align: center;
}

.chatbot__welcome img {
  width: 92px;
  height: auto;
  animation: naranjin-bob 3.4s ease-in-out infinite;
}

.chatbot__welcome-title {
  margin: .25rem 0 .1rem;
  color: var(--pm-navy-800);
  font-size: 1.05rem;
  font-weight: 700;
}

.chatbot__welcome-text {
  max-width: 260px;
  margin: 0 auto;
  color: var(--pm-ink-soft);
  font-size: .82rem;
  line-height: 1.45;
}

/* --------------------------------------------------------------------------
   4. Mensajes, enlaces y sugerencias
   -------------------------------------------------------------------------- */
.chat-msg {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  max-width: 90%;
  animation: chat-in .28s ease both;
}

.chat-msg--bot {
  align-self: flex-start;
}

.chat-msg--user {
  align-self: flex-end;
}

.chat-msg__avatar {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  padding: 2px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(8, 33, 66, .12);
}

/* En mensajes seguidos del bot, el avatar se muestra solo una vez */
.chat-msg--bot + .chat-msg--bot .chat-msg__avatar {
  visibility: hidden;
}

.chat-msg__bubble {
  padding: .6rem .85rem;
  border-radius: 16px 16px 16px 4px;
  background: #fff;
  color: var(--pm-ink);
  font-size: .9rem;
  line-height: 1.45;
  box-shadow: 0 2px 8px rgba(8, 33, 66, .08);
  overflow-wrap: anywhere;
}

.chat-msg__bubble p {
  margin: 0;
}

.chat-msg__bubble ul {
  margin: .45rem 0 0;
  padding-left: 1.1rem;
}

.chat-msg__bubble li + li {
  margin-top: .15rem;
}

.chat-msg--user .chat-msg__bubble {
  border-radius: 16px 16px 4px 16px;
  background: var(--pm-blue-600);
  color: #fff;
}

.chat-links,
.chat-replies {
  display: flex;
  margin-left: 38px;
  animation: chat-in .28s ease both;
}

.chat-links {
  flex-direction: column;
  gap: .4rem;
  max-width: calc(90% - 38px);
}

.chat-link {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .55rem .75rem;
  border: 1px solid #d6e2f5;
  border-radius: 12px;
  background: #fff;
  color: var(--pm-blue-700);
  font-size: .85rem;
  font-weight: 600;
  transition: background-color .15s ease, border-color .15s ease;
}

.chat-link:hover {
  border-color: var(--pm-blue-500);
  background: var(--pm-blue-100);
  color: var(--pm-blue-700);
}

.chat-link > i:first-child {
  color: var(--pm-gold-600);
  font-size: 1rem;
}

.chat-link > i:last-child {
  margin-left: auto;
  font-size: 1.1rem;
}

.chat-replies {
  flex-wrap: wrap;
  gap: .4rem;
}

.chat-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .38rem .8rem;
  border: 1.5px solid var(--pm-blue-500);
  border-radius: 999px;
  background: #fff;
  color: var(--pm-blue-600);
  font-size: .8rem;
  font-weight: 600;
  transition: background-color .15s ease, color .15s ease;
}

.chat-chip:hover,
.chat-chip:focus-visible {
  background: var(--pm-blue-600);
  color: #fff;
}

/* "Escribiendo…" */
.chat-typing {
  display: inline-flex;
  gap: 4px;
  padding: .75rem .9rem;
}

.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--pm-blue-300);
  animation: chat-typing 1s ease-in-out infinite;
}

.chat-typing span:nth-child(2) {
  animation-delay: .15s;
}

.chat-typing span:nth-child(3) {
  animation-delay: .3s;
}

@keyframes chat-typing {
  0%, 80%, 100% { opacity: .35; translate: 0 0; }
  40% { opacity: 1; translate: 0 -4px; }
}

@keyframes chat-in {
  from { opacity: 0; translate: 0 8px; }
  to { opacity: 1; translate: 0 0; }
}

/* --------------------------------------------------------------------------
   5. Campo para escribir
   -------------------------------------------------------------------------- */
.chatbot__footer {
  padding: .7rem .8rem .55rem;
  border-top: 1px solid #e1e8f2;
  background: #fff;
}

.chatbot__form {
  display: flex;
  gap: .5rem;
}

.chatbot__form .form-control {
  padding: .55rem 1rem;
  border-color: #d3dceb;
  border-radius: 999px;
  font-size: .9rem;
}

.chatbot__form .form-control:focus {
  border-color: var(--pm-blue-400);
  box-shadow: 0 0 0 .2rem rgba(30, 148, 179, .18);
}

.chatbot__send {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--pm-gold-500);
  color: var(--pm-navy-900);
  font-size: 1.05rem;
  transition: background-color .15s ease, scale .15s ease;
}

.chatbot__send:hover {
  scale: 1.05;
  background: var(--pm-gold-400);
}

.chatbot__send:disabled {
  opacity: .6;
}

.chatbot__note {
  margin: .45rem 0 0;
  color: var(--pm-ink-soft);
  font-size: .68rem;
  text-align: center;
}

/* --------------------------------------------------------------------------
   6. Celular: el chat ocupa toda la pantalla
   -------------------------------------------------------------------------- */
@media (max-width: 575.98px) {
  .chatbot {
    right: .9rem;
    bottom: .9rem;
  }

  .chatbot__panel {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    border-radius: 0;
  }

  .chatbot.is-open .chatbot__launcher {
    visibility: hidden;
  }

  .chatbot__teaser {
    max-width: 200px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chatbot *,
  .chatbot *::after {
    animation: none !important;
    transition: none !important;
  }
}
