/* ============================================
   SolidMotion Chatbot — Premium Widget
   Glass morphism · Fluid motion · Brand-native
   ============================================ */

/* --- Ambient Keyframes --- */
@keyframes cb-pulse-ring {
  0% { transform: scale(1); opacity: 0.5; }
  70% { transform: scale(1.65); opacity: 0; }
  100% { transform: scale(1.65); opacity: 0; }
}

@keyframes cb-breathe {
  0%, 100% { box-shadow: 0 4px 24px rgba(4, 157, 255, 0.3), 0 0 0 0 rgba(4, 157, 255, 0.15); }
  50% { box-shadow: 0 6px 32px rgba(4, 157, 255, 0.45), 0 0 0 8px rgba(4, 157, 255, 0); }
}

@keyframes cb-msg-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes cb-fade-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cb-dot-wave {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-7px); opacity: 1; }
}

@keyframes cb-shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}

@keyframes cb-gradient-drift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* --- Toggle Button --- */
.chatbot-toggle {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #049DFF 0%, #6366f1 55%, #a855f7 100%);
  background-size: 200% 200%;
  animation: cb-breathe 3.5s ease-in-out infinite, cb-gradient-drift 6s ease infinite;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-tap-highlight-color: transparent;
}

/* Pulse ring behind toggle */
.chatbot-toggle::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(4, 157, 255, 0.4);
  animation: cb-pulse-ring 2.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  pointer-events: none;
}

.chatbot-toggle.active::before {
  animation: none;
  opacity: 0;
}

/* Online dot on toggle */
.chatbot-toggle::after {
  content: '';
  position: absolute;
  top: 1px;
  right: 1px;
  width: 15px;
  height: 15px;
  background: #22c55e;
  border-radius: 50%;
  border: 2.5px solid #fff;
  transition: opacity 0.35s ease, transform 0.35s ease;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

.chatbot-toggle.active::after {
  opacity: 0;
  transform: scale(0.5);
}

.chatbot-toggle:hover {
  transform: scale(1.1);
}

.chatbot-toggle:active {
  transform: scale(0.93);
}

.chatbot-toggle svg {
  width: 26px;
  height: 26px;
  fill: #fff;
  transition: opacity 0.25s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15));
}

.chatbot-toggle .chatbot-icon-close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}

.chatbot-toggle.active .chatbot-icon-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.6);
}

.chatbot-toggle.active .chatbot-icon-close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* --- Chat Window --- */
.chatbot-window {
  position: fixed;
  bottom: 104px;
  right: 28px;
  width: 390px;
  max-width: calc(100vw - 24px);
  height: 540px;
  max-height: calc(100vh - 130px);
  border-radius: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(24px) scale(0.92);
  transform-origin: bottom right;
  transition:
    opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
    visibility 0.4s;
  /* Glass card */
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.12),
    0 8px 32px rgba(4, 157, 255, 0.06),
    0 0 0 1px rgba(0, 0, 0, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.chatbot-window.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* --- Header --- */
.chatbot-header {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  /* Gradient header with glass overlay */
  background: linear-gradient(135deg, #049DFF 0%, #5558e8 50%, #9344e0 100%);
  background-size: 200% 200%;
  animation: cb-gradient-drift 8s ease infinite;
}

/* Subtle noise texture overlay on header */
.chatbot-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
}

/* Decorative mesh glow */
.chatbot-header::after {
  content: '';
  position: absolute;
  width: 120px;
  height: 120px;
  background: radial-gradient(circle, rgba(168, 85, 247, 0.3), transparent 70%);
  top: -40px;
  right: -20px;
  border-radius: 50%;
  pointer-events: none;
}

.chatbot-header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.chatbot-header-avatar svg {
  width: 22px;
  height: 22px;
  fill: #fff;
}

.chatbot-header-info {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.chatbot-header-name {
  font-family: 'Space Grotesk', 'DM Sans', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.chatbot-header-status {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.72rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.chatbot-header-status::before {
  content: '';
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
}

.chatbot-header-close {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  padding: 6px;
  border-radius: 10px;
  transition: background 0.2s ease, transform 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  backdrop-filter: blur(4px);
}

.chatbot-header-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.chatbot-header-close:active {
  transform: scale(0.92);
}

.chatbot-header-close svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

/* --- Messages Area --- */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, #f0f3f8 0%, #F5F7FA 40%, #F5F7FA 100%);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

/* Custom scrollbar */
.chatbot-messages::-webkit-scrollbar {
  width: 4px;
}
.chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(4, 157, 255, 0.15);
  border-radius: 10px;
}
.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(4, 157, 255, 0.3);
}

/* --- Message Bubbles --- */
.chatbot-msg {
  max-width: 82%;
  padding: 11px 15px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.875rem;
  line-height: 1.6;
  color: #1a1a2e;
  animation: cb-msg-in 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.chatbot-msg.bot {
  align-self: flex-start;
  background: #fff;
  border-radius: 18px 18px 18px 6px;
  border: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04), 0 0 0 0.5px rgba(0, 0, 0, 0.02);
}

.chatbot-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #049DFF 0%, #5a63f0 100%);
  color: #fff;
  border-radius: 18px 18px 6px 18px;
  box-shadow: 0 2px 12px rgba(4, 157, 255, 0.2);
}

/* Links in bot messages */
.chatbot-msg.bot a {
  color: #049DFF;
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1px solid rgba(4, 157, 255, 0.25);
  transition: border-color 0.2s ease;
}

.chatbot-msg.bot a:hover {
  border-color: #049DFF;
}

/* --- Typing Indicator --- */
.chatbot-typing {
  align-self: flex-start;
  display: none;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  background: #fff;
  border-radius: 18px 18px 18px 6px;
  border: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  animation: cb-msg-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.chatbot-typing.visible {
  display: flex;
}

.chatbot-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(135deg, #049DFF, #6366f1);
  animation: cb-dot-wave 1.4s ease-in-out infinite;
}

.chatbot-typing-dot:nth-child(2) {
  animation-delay: 0.16s;
}

.chatbot-typing-dot:nth-child(3) {
  animation-delay: 0.32s;
}

/* --- Quick Reply Chips --- */
.chatbot-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 16px 10px;
  background: #F5F7FA;
}

.chatbot-chip {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 8px 15px;
  border-radius: 100px;
  border: 1px solid rgba(4, 157, 255, 0.22);
  background: #fff;
  color: #3b5bdb;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
  animation: cb-fade-up 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.chatbot-chip:nth-child(1) { animation-delay: 0.05s; }
.chatbot-chip:nth-child(2) { animation-delay: 0.1s; }
.chatbot-chip:nth-child(3) { animation-delay: 0.15s; }
.chatbot-chip:nth-child(4) { animation-delay: 0.2s; }

.chatbot-chip:hover {
  background: linear-gradient(135deg, rgba(4, 157, 255, 0.08), rgba(99, 102, 241, 0.06));
  border-color: rgba(4, 157, 255, 0.45);
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(4, 157, 255, 0.1);
}

.chatbot-chip:active {
  transform: scale(0.97);
}

/* --- Input Area --- */
.chatbot-input-area {
  padding: 12px 14px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(0, 0, 0, 0.04);
  flex-shrink: 0;
}

.chatbot-input {
  flex: 1;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.875rem;
  padding: 11px 16px;
  border: 1.5px solid rgba(0, 0, 0, 0.08);
  border-radius: 16px;
  background: #F5F7FA;
  color: #0A0A0A;
  outline: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
  resize: none;
  min-height: 42px;
  max-height: 84px;
  line-height: 1.45;
}

.chatbot-input::placeholder {
  color: rgba(10, 10, 10, 0.36);
  font-weight: 400;
}

.chatbot-input:focus {
  border-color: rgba(4, 157, 255, 0.45);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(4, 157, 255, 0.08);
}

.chatbot-send {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, #049DFF, #6366f1);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
  box-shadow: 0 2px 10px rgba(4, 157, 255, 0.25);
}

.chatbot-send:hover:not(:disabled) {
  transform: scale(1.06);
  box-shadow: 0 4px 16px rgba(4, 157, 255, 0.35);
}

.chatbot-send:active:not(:disabled) {
  transform: scale(0.93);
}

.chatbot-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.chatbot-send svg {
  width: 18px;
  height: 18px;
  fill: #fff;
  transition: transform 0.2s ease;
}

.chatbot-send:hover:not(:disabled) svg {
  transform: translateX(1px);
}

/* --- Branding Footer --- */
.chatbot-branding {
  text-align: center;
  padding: 7px 8px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: rgba(10, 10, 10, 0.3);
  background: rgba(255, 255, 255, 0.6);
  border-top: 1px solid rgba(0, 0, 0, 0.03);
}

/* --- Mobile --- */
@media (max-width: 480px) {
  .chatbot-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  .chatbot-toggle {
    bottom: 18px;
    right: 18px;
    width: 56px;
    height: 56px;
  }

  .chatbot-toggle svg {
    width: 24px;
    height: 24px;
  }

  .chatbot-header {
    padding: 16px 18px;
    padding-top: max(16px, env(safe-area-inset-top));
  }

  .chatbot-messages {
    padding: 16px 14px 10px;
  }

  .chatbot-input-area {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  .chatbot-toggle,
  .chatbot-toggle::before,
  .chatbot-typing-dot,
  .chatbot-chip,
  .chatbot-msg {
    animation: none !important;
  }

  .chatbot-window {
    transition-duration: 0.15s !important;
  }
}
