/* ==========================================================================
   WIDGET CHATBOT · NUEVOS POBLADORES (DIPUTACIÓN DE CÁCERES)
   Estilos completamente aislados para evitar conflictos con Tailwind o custom.css
   ========================================================================== */

#chatbotasistente-container {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1000;
  font-family: var(--font-secondary, system-ui, sans-serif);
}

#chatbotasistente-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-verde-principal, #176253), var(--color-azul, #244e75));
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  transition: transform .15s ease;
  margin-left: auto;
}

#chatbotasistente-icon:hover {
  transform: scale(1.06);
}

#chatbotasistente-icon.dragging {
  cursor: grabbing;
  transform: none;
}

#chatbotasistente-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

#chatbotasistente-icon .fallback {
  font-size: 30px;
  color: #ffffff;
}

#chatbotasistente-window {
  position: absolute;
  right: 0;
  bottom: 80px;
  width: 340px;
  height: 460px;
  background: var(--color-blanco, #ffffff);
  border: 1px solid rgba(23, 98, 83, 0.15);
  border-radius: var(--border-radius-md, 12px);
  box-shadow: 0 12px 36px rgba(0,0,0,.22);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 1001;
}

#chatbotasistente-window.open {
  display: flex;
}

#chatbotasistente-window.fullscreen {
  position: fixed;
  border-radius: 0;
  width: 100vw;
  height: 100vh;
  right: 0;
  bottom: 0;
}

#chatbotasistente-header {
  background: var(--color-verde-principal, #176253);
  color: #ffffff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-primary, sans-serif);
  font-weight: 700;
  cursor: move;
  user-select: none;
}

.chatbotasistente-controls {
  display: flex;
  gap: 4px;
}

.chatbotasistente-controls button {
  background: transparent;
  border: 0;
  color: #ffffff;
  cursor: pointer;
  font-size: 16px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.chatbotasistente-controls button:hover {
  background: rgba(255,255,255,.2);
}

#chatbotasistente-status {
  font-size: .7rem;
  font-weight: 500;
  opacity: .85;
  display: flex;
  align-items: center;
  gap: 5px;
}

#chatbotasistente-status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  display: inline-block;
}

#chatbotasistente-status.ok i { background: #4ade80; }
#chatbotasistente-status.bad i { background: #f87171; }
#chatbotasistente-status.wait i { background: var(--color-dorado-oficial, #d0a712); }

#chatbotasistente-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: var(--color-fondo, #faf9f6);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#chatbotasistente-messages .chat-message {
  max-width: 85%;
  padding: 8px 11px;
  border-radius: 12px;
  font-size: .9rem;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#chatbotasistente-messages .bot-message a {
  color: var(--color-verde-principal, #176253);
  text-decoration: underline;
}

#chatbotasistente-messages .bot-message strong {
  font-weight: 700;
}

#chatbotasistente-messages .user-message {
  align-self: flex-end;
  background: var(--color-verde-principal, #176253);
  color: #ffffff;
  border-bottom-right-radius: 3px;
}

#chatbotasistente-messages .bot-message {
  align-self: flex-start;
  background: var(--color-blanco, #ffffff);
  border: 1px solid rgba(23, 98, 83, 0.15);
  color: var(--color-gris, #505050);
  border-bottom-left-radius: 3px;
}

#chatbotasistente-messages .system-message {
  align-self: center;
  background: transparent;
  color: #697586;
  font-size: .75rem;
  text-align: center;
}

#chatbotasistente-messages .typing {
  color: #697586;
  font-style: italic;
}

#chatbotasistente-input-container {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid rgba(23, 98, 83, 0.15);
  background: var(--color-blanco, #ffffff);
}

#chatbotasistente-input {
  flex: 1;
  border: 1.5px solid #cbd2dc;
  border-radius: var(--border-radius-sm, 6px);
  padding: 9px 10px;
  font: inherit;
  font-size: .9rem;
  color: var(--color-gris, #505050);
  background-color: var(--color-blanco, #ffffff);
  outline: none;
  transition: border-color 0.2s ease;
}

#chatbotasistente-input:focus {
  border-color: var(--color-verde-principal, #176253);
  box-shadow: 0 0 0 3px rgba(23, 98, 83, 0.15);
}

#chatbotasistente-send {
  border: 0;
  border-radius: var(--border-radius-sm, 6px);
  background: var(--color-verde-principal, #176253);
  color: #ffffff;
  font-family: var(--font-primary, sans-serif);
  font-weight: 700;
  padding: 0 14px;
  cursor: pointer;
  transition: background 0.2s ease;
}

#chatbotasistente-send:hover {
  background: var(--color-verde-oscuro, #124d41);
}

#chatbotasistente-send:disabled {
  opacity: .5;
  cursor: not-allowed;
}

@media (max-width: 480px) {
  #chatbotasistente-window {
    width: calc(100vw - 24px);
    right: -12px;
    height: 70vh;
  }
}

/* ==========================================================================
   INDICADOR DE ESCRITURA (TYPING ANIMATION) - COMPACTO
   ========================================================================== */

.typing-indicator-container {
    margin-bottom: 8px !important; /* Forzar el mismo margen que los demás mensajes */
}

.typing-indicator-container {
    display: inline-flex;
    align-items: center;
}

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;          /* Espacio natural entre los puntos */
    height: 10px;      /* Altura para mantener la proporción de la línea */
}

.typing-indicator span {
    width: 6px;        /* Tamaño equilibrado dentro de la burbuja */
    height: 6px;
    background-color: var(--color-gris, #505050); /* Mismo tono que el texto del bot */
    border-radius: 50%;
    display: inline-block;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

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

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.4;
    } 
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ==========================================================================
   OPTIMIZACIÓN RESPONSIVE PARA MÓVILES
   ========================================================================== */

@media (max-width: 480px) {
  /* 1. Reducir el botón flotante principal para que no estorbe */
  #chatbotasistente-icon {
    width: 52px;
    height: 52px;
  }
  
  #chatbotasistente-icon .fallback {
    font-size: 24px;
  }

  /* 2. Ajustar la ventana del chat para pantallas pequeñas */
  #chatbotasistente-window {
    width: calc(100vw - 20px);
    height: 75vh;
    right: -10px;
    bottom: 70px;
    border-radius: 10px;
  }

  /* 3. Reducir padding y tamaños de fuente en la cabecera */
  #chatbotasistente-header {
    padding: 10px 12px;
    font-size: 0.95rem;
  }

  .chatbotasistente-controls button {
    width: 24px;
    height: 24px;
    font-size: 14px;
  }

  /* 4. Hacer los mensajes y el campo de texto más compactos */
  #chatbotasistente-messages {
    padding: 8px;
    gap: 6px;
  }

  #chatbotasistente-messages .chat-message {
    max-width: 90%;
    padding: 7px 10px;
    font-size: 0.85rem; /* Letra un poco más pequeña y legible en móvil */
  }

  #chatbotasistente-input-container {
    padding: 8px;
  }

  #chatbotasistente-input {
    padding: 7px 8px;
    font-size: 0.85rem;
  }

  #chatbotasistente-send {
    padding: 0 12px;
    font-size: 0.85rem;
  }
}