/* ==========================================================================
   MCF Chat Widget — Asistente IA con RAG (n8n)
   Paleta MCF: vino #9B0E26
   ========================================================================== */

#chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#chat-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #9B0E26;
  border: none;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(155, 14, 38, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s, background 0.2s;
  margin-left: auto;
}
#chat-toggle:hover { background: #7A0B1E; transform: scale(1.05); }
#chat-toggle svg { width: 28px; height: 28px; fill: white; }

#chat-box {
  display: none;
  flex-direction: column;
  width: 360px;
  max-width: calc(100vw - 48px);
  height: 540px;
  max-height: calc(100vh - 120px);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  margin-bottom: 12px;
}
#chat-box.open { display: flex; }

#chat-header {
  background: #9B0E26;
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
#chat-header .avatar {
  width: 36px; height: 36px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
#chat-header .info { flex: 1; min-width: 0; }
#chat-header .info strong {
  display: block;
  font-size: 15px;
  font-family: 'Playfair Display', serif;
  font-weight: 600;
}
#chat-header .info span { font-size: 12px; opacity: 0.85; }
#chat-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  opacity: 0.75;
  padding: 0;
  width: 28px;
  height: 28px;
}
#chat-close:hover { opacity: 1; }

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fbe9ed;
}

.msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}
.msg.bot {
  background: white;
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  align-self: flex-start;
}
.msg.user {
  background: #9B0E26;
  color: white;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}
.msg.loading {
  background: white;
  align-self: flex-start;
  padding: 12px 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.typing-dots span {
  display: inline-block;
  width: 6px; height: 6px;
  background: #9B0E26;
  border-radius: 50%;
  margin: 0 2px;
  animation: chat-bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

#chat-footer {
  padding: 12px 16px;
  background: white;
  border-top: 1px solid #ececec;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
#chat-input {
  flex: 1;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  resize: none;
  outline: none;
  font-family: inherit;
  max-height: 100px;
  transition: border-color 0.2s;
}
#chat-input:focus { border-color: #9B0E26; }
#chat-send {
  width: 40px; height: 40px;
  background: #9B0E26;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
#chat-send:hover { background: #7A0B1E; }
#chat-send:disabled { background: #d1aeb6; cursor: not-allowed; }
#chat-send svg { width: 18px; height: 18px; fill: white; }

/* En pantallas pequeñas: el widget ocupa el ancho disponible */
@media (max-width: 480px) {
  #chat-widget { bottom: 16px; right: 16px; }
  #chat-box { width: calc(100vw - 32px); }
}
