/* Widget de chat con IA - KME World Logistics */
#kme-chat-root {
  font-family: var(--font-body, 'Inter', sans-serif);
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
}

.kme-chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #101faf 0%, #0A192F 100%);
  color: #fff;
  border: none;
  box-shadow: 0 4px 20px rgba(16, 31, 175, 0.45);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: transform 0.2s, box-shadow 0.2s;
}
.kme-chat-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(16, 31, 175, 0.5);
}
.kme-chat-toggle:focus {
  outline: none;
}

.kme-chat-window {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 480px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: kme-chat-slide 0.25s ease;
}
@keyframes kme-chat-slide {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.kme-chat-header {
  background: linear-gradient(135deg, #101faf 0%, #0A192F 100%);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.kme-chat-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  flex-shrink: 0;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 4px;
}
.kme-chat-header-text {
  flex: 1;
  min-width: 0;
}
.kme-chat-header h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.kme-chat-header p {
  margin: 4px 0 0 0;
  font-size: 0.75rem;
  color: #fff;
  opacity: 1;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.kme-chat-close {
  margin-left: auto;
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.kme-chat-close:hover {
  background: rgba(255,255,255,0.3);
}

.kme-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8f9fa;
}

.kme-chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-wrap: break-word;
}
.kme-chat-msg.user {
  align-self: flex-end;
  background: #101faf;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.kme-chat-msg.bot {
  align-self: flex-start;
  background: #fff;
  color: #1a1a1a;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}
.kme-chat-msg.bot.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.kme-chat-typing {
  align-self: flex-start;
  padding: 10px 16px;
  background: #fff;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  border: 1px solid #e5e7eb;
}
.kme-chat-typing span {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  margin: 0 2px;
  animation: kme-chat-bounce 1.4s ease-in-out infinite both;
}
.kme-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.kme-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes kme-chat-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

.kme-chat-input-wrap {
  padding: 12px 16px;
  background: #fff;
  border-top: 1px solid #e5e7eb;
}
.kme-chat-input-wrap form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.kme-chat-input-wrap textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 22px;
  font-size: 0.9rem;
  resize: none;
  font-family: inherit;
}
.kme-chat-input-wrap textarea:focus {
  outline: none;
  border-color: #101faf;
  box-shadow: 0 0 0 2px rgba(16, 31, 175, 0.2);
}
.kme-chat-input-wrap button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #101faf;
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.kme-chat-input-wrap button:hover {
  background: #0A192F;
}
.kme-chat-input-wrap button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

@media (max-width: 480px) {
  #kme-chat-root { bottom: 16px; right: 16px; }
  .kme-chat-window { width: calc(100vw - 32px); right: -8px; }
}
