/**
 * VentasxMayor AI Chat Widget
 * Modular, responsive chat interface with LLM integration support
 */

:root {
  --vxm-chat-blue: #3B6DB8;
  --vxm-chat-green: #25d366;
  --vxm-chat-bg: #f5f6fb;
  --vxm-chat-dark: #1a1a1a;
  --vxm-chat-text: #2c2c2c;
  --vxm-chat-muted: #6B6C7E;
  --vxm-chat-shadow: 0 14px 40px rgba(15, 23, 42, 0.22);
  --vxm-chat-radius: 18px;
  --vxm-chat-z-launcher: 9998;
  --vxm-chat-z-window: 9999;
}

/* Launcher bubble (closed state) */
.vxm-chat-launcher {
  position: fixed;
  right: 30px;
  bottom: 30px; /* Position at the bottom */
  max-width: 320px;
  background: var(--vxm-white);
  border-radius: 20px;
  padding: 12px 16px 14px;
  box-shadow: var(--vxm-chat-shadow);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  transform-origin: right bottom;
  animation: vxm-launcher-in 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  z-index: var(--vxm-chat-z-launcher);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Mobile: Position chat launcher on right side */

.vxm-chat-launcher.is-hidden {
  display: none;
}

@keyframes vxm-launcher-in {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.9);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.vxm-chat-launcher:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.3);
}

.vxm-chat-launcher__emoji {
  font-size: 22px;
  line-height: 1;
  margin-top: 2px;
}

.vxm-chat-launcher__content {
  flex: 1;
}

.vxm-chat-launcher__title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 2px;
}

.vxm-chat-launcher__text {
  font-size: 13px;
  color: var(--vxm-chat-muted);
  line-height: 1.4;
}

.vxm-chat-launcher__close {
  border: none;
  background: transparent;
  font-size: 16px;
  color: #cbd5e1;
  cursor: pointer;
  margin-left: 8px;
  padding: 0;
  align-self: flex-start;
  transition: transform 0.16s ease, color 0.16s ease;
}

.vxm-chat-launcher__close:hover {
  color: #64748b;
  transform: scale(1.1);
}

/* Chat window (open state) */
.vxm-chat-window {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: min(420px, 100vw - 32px);
  height: 570px;
  max-height: calc(100vh - 80px);
  border-radius: 24px;
  background: #f9fafb;
  box-shadow: var(--vxm-chat-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: var(--vxm-chat-z-window);
}

.vxm-chat-window.is-visible {
  display: flex;
  animation: vxm-chat-in 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Mobile: Adjust chat window position and size */

@keyframes vxm-chat-in {
  0% {
    opacity: 0;
    transform: translateY(24px) scale(0.97);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Header */
.vxm-chat-window__header {
  position: relative;
  padding: 14px 16px 12px;
  background: linear-gradient(135deg, #020617, #020617 40%, #07111e 100%);
  color: #e2e8f0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.vxm-chat-window__header::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 30% -20%, rgba(71, 126, 207, 0.7), transparent 60%),
    radial-gradient(circle at 90% 130%, rgba(77, 198, 190, 0.7), transparent 60%);
  opacity: 0.75;
  mix-blend-mode: screen;
  pointer-events: none;
}

.vxm-chat-window__logo {
  position: relative;
  z-index: 1;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.vxm-chat-window__title-wrap {
  position: relative;
  z-index: 1;
  flex: 1;
}

.vxm-chat-window__title {
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.vxm-chat-window__badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.18);
  border: 1px solid rgba(45, 212, 191, 0.7);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.vxm-chat-window__subtitle {
  font-size: 12px;
  color: #cbd5f5;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.vxm-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.8);
  animation: vxm-pulse-status 1.8s infinite;
}

@keyframes vxm-pulse-status {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.8);
  }
  70% {
    transform: scale(1.15);
    box-shadow: 0 0 0 12px transparent;
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 transparent;
  }
}

.vxm-chat-window__close {
  position: relative;
  z-index: 1;
  border: none;
  background: rgba(15, 23, 42, 0.72);
  color: #cbd5e1;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.16s ease, transform 0.16s ease, color 0.16s ease;
}

.vxm-chat-window__close:hover {
  background: #0f172a;
  color: #f9fafb;
  transform: translateY(-1px) scale(1.02);
}

/* WhatsApp CTA bar */
.vxm-chat-window__cta {
  padding: 10px 14px;
  background: #0f172a;
  border-bottom: 1px solid rgba(15, 23, 42, 0.88);
  display: flex;
  justify-content: center;
}

.vxm-chat-window__cta-btn {
  border: none;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #ecfdf3;
  font-weight: 600;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(22, 163, 74, 0.55);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  transform-origin: center;
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

.vxm-whatsapp-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: white;
}

.vxm-chat-window__cta-btn:hover {
  transform: translateY(-1px) scale(1.01);
  filter: brightness(1.06);
  box-shadow: 0 14px 34px rgba(22, 163, 74, 0.7);
}

.vxm-chat-window__cta-btn:active {
  transform: translateY(1px) scale(0.99);
  box-shadow: 0 6px 16px rgba(22, 163, 74, 0.55);
}

/* Messages area */
.vxm-chat-window__messages {
  flex: 1;
  padding: 12px 14px;
  background: linear-gradient(180deg, #e5edff 0, #f9fafb 24%, #f9fafb 100%);
  overflow-y: auto;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
}

.vxm-day-label {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.15);
  color: var(--vxm-chat-muted);
  font-size: 11px;
  margin: 4px auto 10px;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
}

.vxm-message {
  max-width: 85%;
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.5;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.vxm-message--bot {
  align-self: flex-start;
  background: var(--vxm-white);
  border-radius: 16px 16px 16px 6px;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
}

.vxm-message--user {
  align-self: flex-end;
  background: var(--vxm-chat-blue);
  color: #f9fafb;
  border-radius: 16px 16px 6px 16px;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.4);
}

/* Message content (markdown formatting) */
.vxm-message__content {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Headers */
.vxm-message__content h1,
.vxm-message__content h2,
.vxm-message__content h3,
.vxm-message__content h4,
.vxm-message__content h5,
.vxm-message__content h6 {
  font-weight: 600;
  margin: 8px 0 4px 0;
  color: inherit;
  line-height: 1.3;
}

.vxm-message__content h1 {
  font-size: 18px;
  margin-top: 12px;
}

.vxm-message__content h2 {
  font-size: 16px;
  margin-top: 10px;
}

.vxm-message__content h3 {
  font-size: 15px;
}

.vxm-message__content h4 {
  font-size: 14px;
}

.vxm-message__content h5,
.vxm-message__content h6 {
  font-size: 13px;
}

.vxm-message__content strong {
  font-weight: 600;
  color: inherit;
}

.vxm-message__content em {
  font-style: italic;
}

.vxm-message__content code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
  font-size: 12px;
}

.vxm-message--user .vxm-message__content code {
  background: rgba(255, 255, 255, 0.2);
}

.vxm-message__content pre {
  background: rgba(0, 0, 0, 0.05);
  padding: 8px 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}

.vxm-message--user .vxm-message__content pre {
  background: rgba(255, 255, 255, 0.15);
}

.vxm-message__content pre code {
  background: none;
  padding: 0;
  font-size: 12px;
  display: block;
  white-space: pre;
}

.vxm-message__content ul,
.vxm-message__content ol {
  margin: 4px 0;
  padding-left: 20px;
}

.vxm-message__content li {
  margin: 2px 0;
}

.vxm-message__content a {
  color: var(--vxm-chat-blue);
  text-decoration: underline;
}

.vxm-message--user .vxm-message__content a {
  color: var(--vxm-white);
  text-decoration: underline;
}

.vxm-message__meta {
  font-size: 10px;
  color: #9ca3af;
  display: flex;
  gap: 6px;
  align-items: center;
}

.vxm-message--user .vxm-message__meta {
  color: #dbeafe;
  justify-content: flex-end;
}

.vxm-message__meta-chip {
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 999px;
  background: rgba(79, 70, 229, 0.08);
  color: var(--vxm-chat-blue);
}

.vxm-message__meta-chip--bot {
  background: rgba(16, 185, 129, 0.08);
  color: #0f766e;
}

/* Typing indicator */
.vxm-typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.04);
}

.vxm-typing__dots {
  display: inline-flex;
  gap: 3px;
}

.vxm-typing__dot {
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: #9ca3af;
  animation: vxm-typing 1.2s infinite;
}

.vxm-typing__dot:nth-child(2) {
  animation-delay: 0.15s;
}

.vxm-typing__dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes vxm-typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

/* Input area */
.vxm-chat-window__input {
  border-top: 1px solid #e5e7eb;
  padding: 8px 10px;
  background: var(--vxm-white);
  display: flex;
  align-items: center;
  gap: 8px;
}

.vxm-chat-window__input textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  max-height: 70px;
  padding: 8px 10px;
  border-radius: 999px;
  background: #f3f4f6;
  transition: box-shadow 0.16s ease, background 0.16s ease;
  overflow-y: auto;
  overflow-x: hidden;
  word-wrap: break-word;
}

.vxm-chat-window__input textarea:focus {
  background: var(--vxm-white);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.3),
    0 10px 20px rgba(15, 23, 42, 0.15);
}

.vxm-chat-window__input-btn,
.vxm-chat-window__input-mic {
  border: none;
  background: transparent;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.16s ease, transform 0.16s ease;
  font-size: 17px;
}

.vxm-chat-window__input-btn {
  background: linear-gradient(135deg, #3B6DB8, #2563eb);
  color: white;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.55);
}

.vxm-chat-window__input-btn:hover {
  transform: translateY(-1px) scale(1.01);
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.7);
}

.vxm-chat-window__input-btn:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.5);
}

.vxm-chat-window__input-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.vxm-chat-window__input-mic {
  color: #94a3b8;
}

.vxm-chat-window__input-mic:hover {
  background: #f3f4f6;
  transform: translateY(-1px);
  color: #475569;
}

/* Caption */
.vxm-caption {
  padding: 4px 16px 9px;
  font-size: 10px;
  color: #9ca3af;
  text-align: center;
  background: var(--vxm-white);
  border-top: 1px solid #e5e7eb;
}

/* Mobile responsive */

/* Loading state */
.vxm-message--loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Error state */
.vxm-message--error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.vxm-message--error .vxm-message__meta-chip {
  background: rgba(220, 38, 38, 0.1);
  color: #991b1b;
}

/* Action buttons for scheduling */
.vxm-action-buttons {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.vxm-action-btn {
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s ease;
  text-align: center;
  font-family: inherit;
  width: 100%;
}

.vxm-action-btn--primary {
  background: #ec4899;
  color: white;
}

.vxm-action-btn--primary:hover {
  background: #db2777;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(236, 72, 153, 0.3);
}

.vxm-action-btn--primary:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(236, 72, 153, 0.3);
}

.vxm-action-btn--secondary {
  background: white;
  color: #ec4899;
  border: 2px solid #ec4899;
}

.vxm-action-btn--secondary:hover {
  background: #fdf2f8;
  transform: translateY(-1px);
}

.vxm-action-btn--secondary:active {
  transform: translateY(0);
}

@media (max-width: 767px) {
  .vxm-chat-launcher {
    bottom: 20px;
    right: 20px;
    max-width: calc(100vw - 40px);
  }
  .vxm-chat-window {
    right: 16px;
    bottom: 16px;
    width: calc(100vw - 32px);
    height: calc(100vh - 140px);
    max-height: 600px;
  }
}

@media (max-width: 480px) {
  .vxm-chat-launcher {
    right: 16px;
    bottom: 16px;
    max-width: calc(100vw - 32px);
  }

  .vxm-chat-window {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
}
