/**
 * OctoChat AI — Widget CSS
 * Estilos del chat flotante para el frontend.
 */

/* ===== VARIABLES ===== */
:root {
  --octochat-primary: #4f46e5;
  --octochat-primary-dark: #3730a3;
  --octochat-primary-light: #4f46e51a;
  --octochat-radius: 16px;
  --octochat-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  --octochat-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== CONTENEDOR PRINCIPAL ===== */
.octochat {
  position: fixed;
  bottom: 24px;
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
.octochat[data-position="right"] { right: 24px; }
.octochat[data-position="left"] { left: 24px; }

/* ===== BOTÓN FLOTANTE (FAB) ===== */
.octochat__fab {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--octochat-primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--octochat-shadow);
  transition: all var(--octochat-transition);
  position: relative;
}
.octochat__fab:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}
.octochat__fab-icon {
  width: 28px;
  height: 28px;
  transition: all var(--octochat-transition);
  position: absolute;
}
.octochat__fab-icon--chat { opacity: 1; transform: rotate(0deg) scale(1); }
.octochat__fab-icon--close { opacity: 0; transform: rotate(-90deg) scale(0.5); }

.octochat--open .octochat__fab-icon--chat { opacity: 0; transform: rotate(90deg) scale(0.5); }
.octochat--open .octochat__fab-icon--close { opacity: 1; transform: rotate(0deg) scale(1); }

/* Pulso de atención (solo cuando está cerrado) */
.octochat:not(.octochat--open) .octochat__fab::after {
  content: '';
  position: absolute;
  top: -4px; right: -4px; bottom: -4px; left: -4px;
  border-radius: 50%;
  background: var(--octochat-primary);
  opacity: 0;
  animation: octochat-pulse 3s ease-in-out infinite;
  z-index: -1;
}

@keyframes octochat-pulse {
  0%, 100% { opacity: 0; transform: scale(1); }
  50% { opacity: 0.3; transform: scale(1.15); }
}

/* ===== VENTANA DE CHAT ===== */
.octochat__window {
  display: none;
  flex-direction: column;
  position: absolute;
  bottom: 76px;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: #ffffff;
  border-radius: var(--octochat-radius);
  box-shadow: var(--octochat-shadow);
  overflow: hidden;
  animation: octochat-slideUp 0.3s ease;
}
.octochat[data-position="right"] .octochat__window { right: 0; }
.octochat[data-position="left"] .octochat__window { left: 0; }

@keyframes octochat-slideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ===== HEADER ===== */
.octochat__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--octochat-primary), var(--octochat-primary-dark));
  color: white;
  flex-shrink: 0;
}
.octochat__header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.octochat__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.octochat__title { font-weight: 700; font-size: 15px; }
.octochat__status {
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 4px;
}
.octochat__status::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #34d399;
  display: inline-block;
}
.octochat__close {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity var(--octochat-transition);
  padding: 4px 8px;
  border-radius: 8px;
}
.octochat__close:hover { opacity: 1; background: rgba(255,255,255,0.15); }

/* ===== FORMULARIO DE LEAD ===== */
.octochat__lead-form {
  padding: 24px 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.octochat__lead-intro {
  text-align: center;
  margin-bottom: 20px;
}
.octochat__lead-intro p {
  font-size: 15px;
  color: #374151;
  margin: 0;
}
.octochat__field { margin-bottom: 12px; }
.octochat__field input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color var(--octochat-transition), box-shadow var(--octochat-transition);
  outline: none;
  background: #fafafa;
}
.octochat__field input:focus {
  border-color: var(--octochat-primary);
  box-shadow: 0 0 0 3px var(--octochat-primary-light);
  background: #fff;
}
.octochat__submit {
  width: 100%;
  padding: 12px;
  background: var(--octochat-primary);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--octochat-transition);
  font-family: inherit;
}
.octochat__submit:hover { background: var(--octochat-primary-dark); transform: translateY(-1px); }
.octochat__submit:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.octochat__privacy {
  text-align: center;
  font-size: 11px;
  color: #9ca3af;
  margin-top: 12px;
}

/* ===== ÁREA DE CHAT ===== */
.octochat__chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.octochat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  scroll-behavior: smooth;
}
.octochat__messages::-webkit-scrollbar { width: 4px; }
.octochat__messages::-webkit-scrollbar-track { background: transparent; }
.octochat__messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

/* ===== MENSAJES ===== */
.octochat__msg {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
}
.octochat__msg--user { align-items: flex-end; }
.octochat__msg--assistant { align-items: flex-start; }

.octochat__msg-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.5;
}
.octochat__msg--user .octochat__msg-bubble {
  background: var(--octochat-primary);
  color: white;
  border-bottom-right-radius: 4px;
}
.octochat__msg--assistant .octochat__msg-bubble {
  background: #f3f4f6;
  color: #1f2937;
  border-bottom-left-radius: 4px;
}
.octochat__msg-time {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 2px;
  padding: 0 4px;
}

/* ===== INDICADOR DE ESCRITURA ===== */
.octochat__typing .octochat__msg-bubble {
  display: flex;
  gap: 4px;
  padding: 12px 18px;
}
.octochat__dot {
  width: 8px;
  height: 8px;
  background: #9ca3af;
  border-radius: 50%;
  animation: octochat-bounce 1.4s ease-in-out infinite;
}
.octochat__dot:nth-child(2) { animation-delay: 0.2s; }
.octochat__dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes octochat-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ===== INPUT DE MENSAJE ===== */
.octochat__input-area {
  padding: 12px 16px;
  border-top: 1px solid #f3f4f6;
  background: #fafafa;
  flex-shrink: 0;
}
.octochat__input-area form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.octochat__input-area input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: white;
  transition: border-color var(--octochat-transition);
}
.octochat__input-area input:focus { border-color: var(--octochat-primary); }
#octochat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--octochat-primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--octochat-transition);
  flex-shrink: 0;
  padding: 0;
}
#octochat-send:hover:not(:disabled) { background: var(--octochat-primary-dark); transform: scale(1.05); }
#octochat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.octochat__send-icon {
  font-size: 18px;
  line-height: 1;
  display: block;
  transform: rotate(0deg);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .octochat { bottom: 16px; }
  .octochat[data-position="right"] { right: 16px; }
  .octochat[data-position="left"] { left: 16px; }
  .octochat__window {
    width: calc(100vw - 32px);
    height: calc(100vh - 120px);
    bottom: 72px;
  }
  .octochat__fab { width: 52px; height: 52px; }
  .octochat__fab-icon { width: 24px; height: 24px; }
}
