/* ========================================================
   PAYTM VYAPAR AI CHATBOT — WCAG AAA UNIGNORABLE FLOATING COPILOT
   Dynamic Context & Memory, Hinglish/Hindi Speech, Glassmorphism
   Available across both Landing Page & Live Cockpit
   ======================================================== */

/* 1. Floating Launcher Icon in Bottom Right */
.chatbot-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #001233 0%, #002970 50%, #0056b3 100%);
  color: #ffffff;
  border: 2px solid #00baf2;
  box-shadow: 0 8px 25px rgba(0, 41, 112, 0.4), 0 0 20px rgba(0, 186, 242, 0.4);
  cursor: pointer;
  display: flex !important;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s ease;
  user-select: none;
}

.chatbot-launcher:hover {
  transform: scale(1.08) translateY(-3px);
  box-shadow: 0 12px 35px rgba(0, 41, 112, 0.5), 0 0 30px rgba(0, 186, 242, 0.65);
}

.chatbot-launcher:active {
  transform: scale(0.96);
}

.chatbot-launcher-icon {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chatbot-launcher-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

/* Online Pulse Dot on Launcher */
.chatbot-pulse-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #00d26a;
  border: 2.5px solid #001233;
  box-shadow: 0 0 8px #00d26a;
  animation: launcher-pulse 1.8s infinite;
}

@keyframes launcher-pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 210, 106, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(0, 210, 106, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 210, 106, 0); }
}

/* Launcher Tooltip */
.chatbot-launcher-tooltip {
  position: absolute;
  right: 72px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1.5px solid var(--border-glass);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 20, 50, 0.15);
  pointer-events: none;
  opacity: 0;
  transform: translateX(10px);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chatbot-launcher:hover .chatbot-launcher-tooltip {
  opacity: 1;
  transform: translateX(0);
}

/* 2. Floating Chatbot Window */
.chatbot-window {
  position: fixed;
  bottom: 96px;
  right: 26px;
  width: 410px;
  height: 600px;
  max-height: calc(100vh - 120px);
  max-width: calc(100vw - 40px);
  background: var(--bg-card);
  border: 1.5px solid var(--border-glass);
  border-radius: var(--radius-xl);
  box-shadow: 0 25px 65px rgba(0, 20, 50, 0.35), 0 0 35px rgba(0, 186, 242, 0.15);
  display: flex;
  flex-direction: column;
  z-index: 9998;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.94);
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.chatbot-window.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0) scale(1);
}

/* Chatbot Header */
.chatbot-header {
  padding: 1rem 1.3rem;
  background: linear-gradient(135deg, #001233 0%, #002970 70%, #004b99 100%);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1.5px solid rgba(0, 186, 242, 0.3);
  flex-shrink: 0;
}

.chatbot-header-left {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.chatbot-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #002970 0%, #00baf2 100%);
  border: 2px solid #00baf2;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 1.1rem;
  box-shadow: 0 0 12px rgba(0, 186, 242, 0.4);
  position: relative;
  flex-shrink: 0;
}

.chatbot-avatar-pulse {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: #00d26a;
  border-radius: 50%;
  border: 2px solid #001233;
}

.chatbot-title-box {
  line-height: 1.2;
}

.chatbot-title {
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.chatbot-subtitle {
  font-size: 0.74rem;
  color: #7dd3fc;
  font-weight: 600;
}

.chatbot-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.chatbot-header-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

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

/* 3. Real-Time App Context Banner */
.chatbot-context-strip {
  padding: 0.55rem 1rem;
  background: var(--bg-card-subtle);
  border-bottom: 1.5px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 700;
  flex-shrink: 0;
}

.chatbot-context-badges {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.context-mini-badge {
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.74rem;
  font-weight: 800;
}

.context-mini-badge.khata { background: #fee2e2; color: #991b1b; }
.context-mini-badge.stock { background: #fef3c7; color: #92400e; }
.context-mini-badge.loan { background: #dcfce7; color: #166534; }

[data-theme="dark"] .context-mini-badge.khata { background: rgba(239, 68, 68, 0.25); color: #fca5a5; }
[data-theme="dark"] .context-mini-badge.stock { background: rgba(245, 158, 11, 0.25); color: #fbbf24; }
[data-theme="dark"] .context-mini-badge.loan { background: rgba(16, 185, 129, 0.25); color: #34d399; }

/* 4. Chat Messages Scroll Area */
.chatbot-messages {
  flex: 1;
  padding: 1.1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  background: var(--bg-app);
}

.chat-bubble {
  max-width: 86%;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  line-height: 1.5;
  animation: bubbleFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  word-break: break-word;
}

@keyframes bubbleFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #002970 0%, #0056b3 100%);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 41, 112, 0.2);
  font-weight: 600;
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1.5px solid var(--border-glass);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.chat-bubble.assistant strong {
  color: #002970;
  font-weight: 800;
}

[data-theme="dark"] .chat-bubble.assistant strong {
  color: #38bdf8;
}

.chat-bubble-action-box {
  margin-top: 0.6rem;
  padding: 0.5rem 0.8rem;
  background: var(--bg-card-subtle);
  border-left: 3px solid #00baf2;
  border-radius: 0 6px 6px 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
}

/* Typing Indicator Animation */
.chat-typing-indicator {
  display: none;
  align-self: flex-start;
  background: var(--bg-card);
  border: 1.5px solid var(--border-glass);
  padding: 0.6rem 1rem;
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  gap: 5px;
  align-items: center;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #0056b3;
  animation: typing-bounce 1.3s infinite ease-in-out;
}

[data-theme="dark"] .typing-dot {
  background: #38bdf8;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* 5. Suggestion Chips Bar */
.chatbot-suggestions {
  padding: 0.5rem 0.8rem;
  background: var(--bg-card);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  white-space: nowrap;
  flex-shrink: 0;
}

.chatbot-suggestions::-webkit-scrollbar {
  height: 4px;
}

.chat-suggestion-chip {
  padding: 0.35rem 0.75rem;
  border-radius: 50px;
  border: 1.5px solid var(--border-glass);
  background: var(--bg-card-subtle);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  flex-shrink: 0;
}

.chat-suggestion-chip:hover {
  background: #002970;
  color: #ffffff;
  border-color: #002970;
  transform: translateY(-1px);
}

[data-theme="dark"] .chat-suggestion-chip:hover {
  background: var(--paytm-cyan);
  color: #001233;
  border-color: var(--paytm-cyan);
}

/* 6. Chat Input Form */
.chatbot-input-bar {
  padding: 0.8rem 1rem;
  background: var(--bg-card);
  border-top: 1.5px solid var(--border-glass);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.chatbot-text-input {
  flex: 1;
  background: var(--bg-card-subtle);
  border: 1.5px solid var(--border-glass);
  border-radius: 50px;
  padding: 0.65rem 1.1rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s ease;
}

.chatbot-text-input:focus {
  border-color: var(--border-focus);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(0, 86, 179, 0.15);
}

.chatbot-mic-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-card-subtle);
  border: 1.5px solid var(--border-glass);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chatbot-mic-btn:hover {
  background: #002970;
  color: #ffffff;
  border-color: #002970;
}

.chatbot-mic-btn.listening {
  background: #dc2626 !important;
  color: #ffffff !important;
  border-color: #f87171 !important;
  animation: pulse-mic 1s infinite alternate;
}

.chatbot-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #002970 0%, #0056b3 100%);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 41, 112, 0.25);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chatbot-send-btn:hover {
  transform: scale(1.08);
  background: linear-gradient(135deg, #001f54 0%, #004494 100%);
}

/* Responsive adjustments for Mobile */
@media (max-width: 768px) {
  /* Floating chatbot bubble launcher in bottom right */
  .chatbot-launcher {
    display: flex !important;
    position: fixed !important;
    bottom: 20px !important;
    right: 14px !important;
    width: 48px !important;
    height: 48px !important;
    border-radius: 50% !important;
    background: linear-gradient(135deg, #002970 0%, #00BAF2 100%) !important;
    box-shadow: 0 4px 14px rgba(0, 41, 112, 0.35) !important;
    z-index: 99999 !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
  }

  /* When inside cockpit on mobile, float cleanly above bottom nav bar (60px high) */
  body.in-cockpit .chatbot-launcher {
    bottom: 74px !important;
    right: 14px !important;
  }

  .chatbot-window {
    right: 8px !important;
    left: 8px !important;
    width: auto !important;
    bottom: 16px !important;
    height: calc(100vh - 84px) !important;
    max-height: 580px !important;
    border-radius: 16px !important;
    z-index: 100000 !important;
  }

  body.in-cockpit .chatbot-window {
    bottom: 72px !important;
  }
}
