:root {
  --background: #f8f9fa;
  --paragraphs: #5b5753;
  --heading: #151414;
  --accent-1: #E6C547;
  --accent-2: #F4D761;
  --light: #fefaf7;
  --shadow: rgba(51, 48, 44, .05);
  --border: #ded2c5;
  --transport-primary: #E6C547;
  --transport-secondary: #666666;
  --transport-dark: #333333;
}

.body-islmex {
  background-color: #fff;
  margin: 0;
  padding: 0;
  font-family: Arial, sans-serif;
}

/* ========== CONTENEDOR PADRE PRINCIPAL ========== */
.chatbot-widget {
  position: fixed;
  bottom: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  padding: 20px;
  z-index: 1000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ========== GLOBO DE AYUDA ========== */
.help-bubble {
  background: white;
  border: 2px solid var(--transport-primary);
  border-radius: 20px 20px 4px 20px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  padding: 8px 15px;
  color: var(--transport-dark);
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  animation: bounce 6s infinite;
}

@keyframes bounce {

  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }

  40% {
    transform: translateY(-3px);
  }

  60% {
    transform: translateY(-3px);
  }
}

/* ========== BOTÓN PRINCIPAL DEL CHATBOT ========== */
.chat-button {
  background: #fcca00;
  border: 3px solid white;
  box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.chat-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(230, 197, 71, 0.6);
  border-color: var(--transport-primary);
}

.chat-button:active {
  transform: scale(0.95);
}

.button-icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

/* ========== VENTANA PRINCIPAL DEL CHAT ========== */
.chat-window {
  background: white;
  border-radius: 5px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border);
  width: 400px;
  height: 500px;
  display: none;
  flex-direction: column;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transition: all 0.3s ease;
  margin-bottom: 20px;
  visibility: hidden;
}

.chat-window.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
  display: flex;
}

/* ========== HEADER DEL CHAT ========== */
.chat-header {
  background: linear-gradient(100deg, #e4d186, #e7c63d);
  color: var(--transport-dark);
  padding: 15px 20px;
  border-radius: 5px 5px 0 0;
  font-weight: 600;
  font-size: 14px;
  text-align: center;
}

/* ========== ÁREA DE CONVERSACIÓN ========== */
.chat-messages {
  flex: 1;
  overflow-y: scroll;
  padding: 15px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
  background: none;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: linear-gradient(45deg, var(--transport-primary), var(--accent-2));
  border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(45deg, var(--accent-2), var(--transport-primary));
}

/* ========== BURBUJAS DE MENSAJES ========== */
.message-bubble {
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin-bottom: 12px;
  max-width: 85%;
  position: relative;
  width: fit-content;
  min-height: 40px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  animation: slideIn 0.3s ease-out;
}

/* Mensajes del bot */
.message-bubble.bot {
  background: linear-gradient(135deg, var(--transport-secondary), var(--transport-dark));
  border-radius: 4px 18px 18px 18px;
  margin-left: 0;
  margin-right: auto;
}


/* Mensajes del usuario */
.message-bubble:not(.bot):not(.error) {
  background: linear-gradient(135deg, var(--transport-primary), var(--accent-2));
  color: var(--transport-dark);
  margin-left: auto;
  margin-right: 0;
  border-radius: 18px 4px 18px 18px;
}

/* Primer mensaje especial */
.message-bubble.first {
  margin-top: 5px;
}

/* ========== TEXTO DE MENSAJES ========== */
.message-text {
  color: var(--light);
  word-break: break-word;
  overflow-wrap: break-word;
  margin: 0;
  line-height: 1.4;
}

.message-bubble:not(.bot) .message-text {
  color: var(--transport-dark);
}

/* ========== BURBUJA DE PENSAMIENTO ========== */
.thinking-bubble {
  background: linear-gradient(135deg, var(--transport-secondary), var(--transport-dark));
  border-radius: 4px 18px 18px 18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin-bottom: 12px;
  max-width: 85%;
  position: relative;
  width: fit-content;
  min-height: 40px;
  padding: 15px 20px;
  display: flex;
  align-items: center;
  margin-left: 0;
  margin-right: auto;
}

.thinking-dots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.thinking-dot {
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  animation: thinkingPulse 1.4s infinite ease-in-out;
}

.thinking-dot:nth-child(1) {
  animation-delay: 0ms;
}

.thinking-dot:nth-child(2) {
  animation-delay: 200ms;
}

.thinking-dot:nth-child(3) {
  animation-delay: 400ms;
}

@keyframes thinkingPulse {

  0%,
  60%,
  100% {
    transform: scale(1);
    opacity: 0.7;
  }

  30% {
    transform: scale(1.3);
    opacity: 1;
  }
}

/* ========== FORMULARIO DE ENTRADA ========== */
.chat-input-container {
  padding: 15px;
  background: var(--light);
  border-radius: 0 0 20px 20px;
  border-top: 1px solid var(--border);
}

.input-form {
  display: flex;
  gap: 0;
}

.message-input {
  flex: 1;
  border: 2px solid var(--border);
  border-radius: 25px 0 0 25px;
  padding: 12px 15px;
  transition: border-color 0.3s ease;
  background: white;
  color: black;
  outline: none;
}

.message-input:focus {
  border-color: var(--transport-primary);
  box-shadow: 0 0 0 3px rgba(230, 197, 71, 0.2);
}

.send-button {
  background: linear-gradient(135deg, var(--transport-primary), var(--accent-2));
  border-radius: 0 25px 25px 0;
  color: var(--transport-dark);
  border: none;
  transition: all 0.3s ease;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  font-size: 2rem;
  padding: 2rem;
}

.send-button:hover:not(.disabled-button) {
  background: linear-gradient(135deg, var(--accent-2), var(--transport-primary));
  transform: translateY(-1px);
}

/* ========== ESTADOS ESPECIALES ========== */
.disabled-button {
  background: #ccc !important;
  opacity: 0.6 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
}

.send-button.disabled-button {
  position: relative;
}

.send-button.disabled-button::after {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid var(--transport-dark);
  border-top: 2px solid transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

/* ========== ANIMACIONES ========== */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* ========== RESPONSIVE DESIGN ========== */

/* Tablets */
@media screen and (max-width: 1024px) {
  .chatbot-widget {
    padding: 15px;
    font-size: 14px;
  }

  .chat-window {
    width: 350px;
    height: 450px;
  }

  .help-bubble {
    font-size: 13px;
    padding: 6px 12px;
  }
}

/* Móviles grandes */
@media screen and (max-width: 768px) {
  .chatbot-widget {
    padding: 10px;
  }

  .chat-window {
    width: calc(100vw - 40px);
    max-width: 350px;
    height: 400px;
    margin-bottom: 15px;
  }

  .chat-button {
    width: 55px;
    height: 55px;
  }

  .button-icon {
    width: 35px;
    height: 35px;
  }

  .help-bubble {
    font-size: 13px;
    padding: 5px 10px;
    text-align: center;
  }

  .send-button {
    min-width: 25px;
  }
}

/* Móviles pequeños */
@media screen and (max-width: 480px) {
  .chatbot-widget {
    padding: 8px;
    font-size: 12px;
  }

  .chat-window {
    width: calc(100vw - 30px);
    height: 350px;
    margin-bottom: 10px;
  }

  .chat-button {
    width: 50px;
    height: 50px;
  }

  .button-icon {
    width: 22px;
    height: 22px;
  }

  .help-bubble {
    font-size: 11px;
    padding: 4px 8px;
  }

  .chat-header {
    padding: 12px 15px;
    font-size: 13px;
  }

  .chat-messages {
    padding: 10px;
  }

  .chat-input-container {
    padding: 10px;
  }

  .message-input,
  .send-button {
    padding: 10px 12px;
    font-size: 12px;
  }
}

.chatbot-controls {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 15px;
}



/* ========== BOTÓN DE HISTORIAL ========== */
.history-button {
  background: #f6f6f6;
  border: 3px solid white;
  box-shadow: 0 4px 20px rgba(108, 117, 125, 0.4);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  display: none;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s ease;
  color: #5f5f5f;
  font-size: 20px;
  visibility: hidden;
  border: 2px solid gray;
  border-radius: 2px solid gray;
}

.history-button.authorized {
  display: flex;
  visibility: visible;
}

.history-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(108, 117, 125, 0.6);
}

/* ========== VENTANA DEL HISTORIAL ========== */
.history-window {
  background: white;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border);
  width: 500px;
  height: 600px;
  position: absolute;
  bottom: 80px;
  right: 0;
  display: none;
  flex-direction: column;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transition: all 0.3s ease;
  visibility: hidden;
  z-index: 999;
}

.history-window.show {
  display: flex;
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
  margin-bottom: 2rem;
}

.history-header {
  background: linear-gradient(135deg, #95bcdf, #005b9f);
  color: white;
  padding: 15px 20px;
  border-radius: 20px 20px 0 0;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 15px;
}

.history-back-btn {
  background: none;
  border: none;
  color: white;
  font-size: 16px;
  cursor: pointer;
  padding: 5px;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.3s ease;
}

.history-back-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.history-title {
  flex: 1;
  text-align: center;
  font-weight: bold;
  font-size: 18px;
}

.history-list-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.history-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 15px;
  color: var(--paragraphs);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top: 3px solid #6c757d;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.history-list::-webkit-scrollbar {
  width: 5px;
}

.history-list::-webkit-scrollbar-thumb {
  background: linear-gradient(45deg, #6c757d, #5a6268);
  border-radius: 10px;
}

.history-chat-item {
  padding: 15px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.history-chat-item:hover {
  background-color: rgba(108, 117, 125, 0.1);
}

.history-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--paragraphs);
  margin-bottom: 5px;
}

.history-chat-id {
  font-weight: 600;
  color: #343131;
}

.history-chat-date {
  font-size: 11px;
}

.history-chat-preview {
  font-size: 14px;
  color: var(--heading);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 15px;
  color: var(--paragraphs);
}

.history-empty i {
  font-size: 48px;
  opacity: 0.5;
}

.history-conversation-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.history-conversation-messages {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  scroll-behavior: smooth;
  background: #f0f0f0;
}

.history-conversation-messages::-webkit-scrollbar {
  width: 5px;
}

.history-conversation-messages::-webkit-scrollbar-thumb {
  background: linear-gradient(45deg, #6c757d, #5a6268);
  border-radius: 10px;
}

.history-message-bubble {
  border-radius: 18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin-bottom: 12px;
  max-width: 85%;
  padding: 12px 18px;
  display: block;
}

.history-message-bubble.user {
  background: linear-gradient(135deg, var(--transport-primary), var(--accent-2));
  color: var(--transport-dark);
  margin-left: 0;
  margin-right: auto;
  border-radius: 4px 18px 18px 18px;
}

.history-message-bubble.bot {
  background: linear-gradient(135deg, var(--transport-secondary), var(--transport-dark));
  color: white;
  margin-left: auto;
  margin-right: 0;
  border-radius: 18px 4px 18px 18px;
}

.history-message-text {
  word-break: break-word;
  overflow-wrap: break-word;
  margin: 0;
  line-height: 1.4;
  font-size: 14px;
}

.history-message-time {
  font-size: 10px;
  opacity: 0.7;
  margin-top: 5px;
  text-align: right;
}

@media screen and (max-width: 768px) {
  .history-window {
    width: calc(100vw - 40px);
    max-width: 400px;
    height: 550px;
    right: 20px;
    bottom: 70px;
  }

  .history-button {
    width: 45px;
    height: 45px;
    font-size: 16px;
  }
}