/* ==========================================================================
   BaaSx AI Copilot Widget Stylesheet
   Fully responsive across mobile (iOS/Android) and desktop viewports
   ========================================================================== */

/* 1. Floating Action Trigger Button (Bottom Right) */
.baasx-copilot-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9990;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #f59e0b 100%);
  color: #ffffff;
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  border-radius: 9999px;
  box-shadow: 0 10px 30px rgba(79, 70, 229, 0.45), 0 0 25px rgba(245, 158, 11, 0.3);
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.88rem;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.baasx-copilot-trigger:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 14px 38px rgba(79, 70, 229, 0.6), 0 0 35px rgba(245, 158, 11, 0.45);
  border-color: rgba(255, 255, 255, 0.5);
}

.baasx-copilot-trigger:active {
  transform: translateY(1px) scale(0.98);
}

.baasx-copilot-badge-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.baasx-copilot-bot-svg {
  width: 22px;
  height: 22px;
  stroke: #ffffff;
  transition: transform 0.3s ease;
}

.baasx-copilot-trigger:hover .baasx-copilot-bot-svg {
  transform: rotate(10deg);
}

.baasx-copilot-beacon {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: #34d399;
  border: 1.5px solid #1e1b4b;
  border-radius: 50%;
  box-shadow: 0 0 8px #34d399;
  animation: baasxBeaconPulse 2s infinite;
}

@keyframes baasxBeaconPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.6; }
}

.baasx-copilot-label {
  white-space: nowrap;
}

.baasx-copilot-sparkle-svg {
  width: 16px;
  height: 16px;
  fill: #fde047;
  animation: baasxSparkleSpin 4s linear infinite;
}

@keyframes baasxSparkleSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* 2. Interactive Copilot Card / Drawer Modal */
.baasx-copilot-modal {
  position: fixed;
  bottom: 84px;
  right: 24px;
  z-index: 9995;
  width: 440px;
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 100px);
  max-height: calc(100vh - 100px);
  background: rgba(13, 19, 33, 0.96);
  border: 1.5px solid rgba(99, 102, 241, 0.4);
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8), 0 0 40px rgba(79, 70, 229, 0.25);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: baasxCopilotSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #f3f4f6;
}

@keyframes baasxCopilotSlideIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Header */
.baasx-copilot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.baasx-copilot-header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.baasx-copilot-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
  flex-shrink: 0;
}

.baasx-copilot-avatar svg {
  width: 20px;
  height: 20px;
}

.baasx-copilot-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.baasx-copilot-title {
  font-size: 0.96rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.2px;
}

.baasx-copilot-tag {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 2px 7px;
  background: rgba(245, 158, 11, 0.16);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 10px;
}

.baasx-copilot-status {
  font-size: 0.73rem;
  color: #94a3b8;
  margin-top: 1px;
}

.baasx-copilot-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.baasx-copilot-btn-icon {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.4rem;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.baasx-copilot-btn-icon:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

/* Conversation Thread */
.baasx-copilot-messages {
  flex: 1 1 auto;
  min-height: 140px;
  max-height: 360px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overscroll-behavior: contain;
}

.baasx-copilot-msg {
  display: flex;
  gap: 10px;
  max-width: 90%;
  animation: baasxMsgFade 0.2s ease-out;
}

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

.baasx-copilot-msg-ai {
  align-self: flex-start;
}

.baasx-copilot-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.baasx-copilot-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: #fff;
  flex-shrink: 0;
  margin-top: 2px;
}

.baasx-copilot-msg-user .baasx-copilot-msg-avatar {
  background: #3b82f6;
}

.baasx-copilot-bubble {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 0.83rem;
  line-height: 1.5;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  word-break: break-word;
}

.baasx-copilot-msg-ai .baasx-copilot-bubble {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: #e2e8f0;
}

.baasx-copilot-msg-user .baasx-copilot-bubble {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.baasx-copilot-bubble strong {
  color: #38bdf8;
  font-weight: 700;
}

.baasx-copilot-bubble a {
  color: #00f0ff;
  text-decoration: underline;
  font-weight: 600;
}

.baasx-copilot-bubble code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: rgba(255, 255, 255, 0.12);
  padding: 1px 5px;
  border-radius: 4px;
  color: #fde047;
  font-size: 0.78rem;
}

/* Quick Prompt Chips */
.baasx-copilot-quick-prompts {
  padding: 8px 16px 12px;
  background: rgba(255, 255, 255, 0.01);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}

.baasx-copilot-chips-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.baasx-copilot-chips-scroll::-webkit-scrollbar {
  display: none;
}

.baasx-copilot-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.baasx-copilot-chip:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.5);
  color: #ffffff;
  transform: translateY(-1px);
}

/* Voice Active Bar */
.baasx-copilot-voice-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(239, 68, 68, 0.12);
  border-top: 1px solid rgba(239, 68, 68, 0.3);
  font-size: 0.78rem;
  color: #fca5a5;
  flex-shrink: 0;
}

.baasx-copilot-voice-pulse {
  width: 10px;
  height: 10px;
  background: #ef4444;
  border-radius: 50%;
  animation: baasxVoicePulse 1s infinite;
  display: inline-block;
  margin-right: 8px;
}

@keyframes baasxVoicePulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.5); opacity: 0.4; }
}

.baasx-copilot-voice-stop-btn {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fee2e2;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

/* Input Row */
.baasx-copilot-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 16px;
  background: rgba(13, 19, 33, 0.98);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.baasx-copilot-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 10px 14px;
  color: #ffffff;
  /* 16px font-size prevents iOS Safari auto-zoom on input focus */
  font-size: 16px;
  outline: none;
  transition: all 0.2s ease;
  box-sizing: border-box;
}

.baasx-copilot-input::placeholder {
  color: #64748b;
  font-size: 0.84rem;
}

.baasx-copilot-input:focus {
  border-color: #6366f1;
  background: rgba(255, 255, 255, 0.09);
  box-shadow: 0 0 14px rgba(99, 102, 241, 0.25);
}

.baasx-copilot-mic-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.baasx-copilot-mic-btn svg {
  width: 18px;
  height: 18px;
}

.baasx-copilot-mic-btn:hover {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fbbf24;
}

.baasx-copilot-mic-btn.active {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
  color: #ef4444;
  animation: baasxMicActive 1.2s infinite;
}

@keyframes baasxMicActive {
  0%, 100% { box-shadow: 0 0 0 rgba(239, 68, 68, 0); }
  50% { box-shadow: 0 0 14px rgba(239, 68, 68, 0.5); }
}

.baasx-copilot-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.baasx-copilot-send-btn svg {
  width: 17px;
  height: 17px;
  margin-left: 1px;
}

.baasx-copilot-send-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.5);
}

.baasx-copilot-send-btn:active {
  transform: translateY(1px);
}

/* ==========================================================================
   Mobile Responsive Adjustments
   ========================================================================== */

@media (max-width: 640px) {
  .baasx-copilot-trigger {
    bottom: max(16px, env(safe-area-inset-bottom));
    right: 16px;
    padding: 10px 16px;
    font-size: 0.78rem;
    gap: 8px;
  }

  .baasx-copilot-bot-svg {
    width: 20px;
    height: 20px;
  }

  .baasx-copilot-modal {
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    max-height: calc(88dvh);
    max-height: calc(88vh);
    border-radius: 20px;
  }

  .baasx-copilot-header {
    padding: 12px 16px;
  }

  .baasx-copilot-avatar {
    width: 32px;
    height: 32px;
  }

  .baasx-copilot-avatar svg {
    width: 17px;
    height: 17px;
  }

  .baasx-copilot-title {
    font-size: 0.88rem;
  }

  .baasx-copilot-messages {
    padding: 12px;
    max-height: calc(50dvh);
    max-height: calc(50vh);
  }

  .baasx-copilot-bubble {
    font-size: 0.8rem;
    padding: 9px 12px;
  }

  .baasx-copilot-quick-prompts {
    padding: 6px 12px 10px;
  }

  .baasx-copilot-input-row {
    padding: 10px 12px max(12px, env(safe-area-inset-bottom));
  }

  .baasx-copilot-input {
    padding: 8px 12px;
  }
}
