/* ==========================================================================
   Prajin AI Floating Chatbot Stylesheet
   Modern Glassmorphism, Theme-Aware, Mobile-Responsive
   ========================================================================== */

/* Launcher Trigger Button */
.ai-chat-launcher {
  position: fixed;
  right: 20px;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  z-index: 56;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 10px 30px -4px rgba(168, 85, 247, 0.5), 0 4px 12px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
  outline: none;
}

.ai-chat-launcher:hover {
  transform: translateY(-4px) scale(1.06);
  box-shadow: 0 14px 35px -2px rgba(168, 85, 247, 0.65), 0 6px 18px rgba(0, 0, 0, 0.4);
}

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

/* Pulsing halo around AI launcher */
.ai-chat-launcher::before {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid rgba(168, 85, 247, 0.7);
  animation: ai-pulse 2.2s cubic-bezier(0.24, 0, 0.38, 1) infinite;
  pointer-events: none;
}

@keyframes ai-pulse {
  0% { transform: scale(0.95); opacity: 0.9; }
  70% { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(1.45); opacity: 0; }
}

.ai-launcher-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease;
}

.ai-launcher-logo-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 50%;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}

.ai-launcher-icon svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.ai-chat-launcher.is-active .ai-icon-open {
  display: none;
}
.ai-chat-launcher:not(.is-active) .ai-icon-close {
  display: none;
}

/* Tooltip Badge */
.ai-launcher-tooltip {
  position: absolute;
  right: calc(100% + 14px);
  top: 50%;
  transform: translateY(-50%) translateX(8px);
  background: var(--bg2, #0d1226);
  color: var(--fg, #f8fafc);
  border: 1px solid var(--line, rgba(255, 255, 255, 0.12));
  padding: 8px 14px;
  border-radius: 999px;
  font: 600 13px var(--d, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
  letter-spacing: -0.01em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
  box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.ai-chat-launcher:hover .ai-launcher-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) translateX(0);
}

.ai-sparkle-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #a855f7;
  box-shadow: 0 0 10px #ec4899;
}

/* ==========================================================================
   Chat Window Panel
   ========================================================================== */
.ai-chat-panel {
  position: fixed;
  right: 20px;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  width: min(400px, calc(100vw - 32px));
  height: min(580px, calc(100vh - 120px));
  background: var(--bg, #050816);
  border: 1px solid var(--line, rgba(255, 255, 255, 0.12));
  border-radius: 20px;
  box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.75), 0 0 30px rgba(168, 85, 247, 0.15);
  z-index: 57;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.3s;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.ai-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Header */
.ai-chat-header {
  padding: 14px 16px;
  background: var(--bg2, #0d1226);
  border-bottom: 1px solid var(--line, rgba(255, 255, 255, 0.1));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ai-header-profile {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e1b4b, #312e81);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  border: 1.5px solid rgba(168, 85, 247, 0.4);
  overflow: visible;
}

.ai-avatar-img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 50%;
}

.ai-status-indicator {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--bg2, #0d1226);
}

.ai-header-info {
  display: flex;
  flex-direction: column;
}

.ai-header-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg, #f8fafc);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-tag {
  font-size: 9px;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(168, 85, 247, 0.2);
  color: #c084fc;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.ai-header-subtitle {
  font-size: 11px;
  color: var(--mut, #94a3b8);
}

.ai-close-btn {
  background: transparent;
  border: none;
  color: var(--mut, #94a3b8);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.ai-close-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg, #fff);
}

/* Chat Body (Messages) */
.ai-chat-body {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.ai-chat-body::-webkit-scrollbar {
  width: 6px;
}

.ai-chat-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

/* Message items */
.ai-msg {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  font-size: 13.5px;
  line-height: 1.5;
  animation: ai-msg-appear 0.25s ease-out forwards;
}

@keyframes ai-msg-appear {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #ffffff;
  padding: 10px 14px;
  border-radius: 16px 16px 3px 16px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.ai-msg.bot {
  align-self: flex-start;
  background: var(--bg2, #0d1226);
  color: var(--fg, #f8fafc);
  border: 1px solid var(--line, rgba(255, 255, 255, 0.08));
  padding: 12px 14px;
  border-radius: 16px 16px 16px 3px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.ai-msg.bot p {
  margin: 0 0 6px 0;
}
.ai-msg.bot p:last-child {
  margin-bottom: 0;
}
.ai-msg.bot a {
  color: #38bdf8;
  text-decoration: underline;
  word-break: break-all;
}

.ai-msg-time {
  font-size: 10px;
  color: var(--mut, #64748b);
  margin-top: 4px;
  align-self: flex-end;
}
.ai-msg.user .ai-msg-time {
  color: rgba(255, 255, 255, 0.7);
}

/* Typing Indicator */
.ai-typing-indicator {
  display: none;
  align-self: flex-start;
  background: var(--bg2, #0d1226);
  border: 1px solid var(--line, rgba(255, 255, 255, 0.08));
  padding: 10px 14px;
  border-radius: 16px 16px 16px 3px;
  align-items: center;
  gap: 5px;
}

.ai-typing-indicator.is-visible {
  display: flex;
}

.ai-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a855f7;
  animation: ai-blink 1.4s infinite ease-in-out both;
}

.ai-dot:nth-child(1) { animation-delay: -0.32s; }
.ai-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes ai-blink {
  0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Quick Suggestion Chips */
.ai-chips-container {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 16px;
  background: var(--bg, #050816);
  border-top: 1px solid var(--line, rgba(255, 255, 255, 0.05));
  scrollbar-width: none;
}
.ai-chips-container::-webkit-scrollbar {
  display: none;
}

.ai-chip {
  background: var(--bg2, #0d1226);
  border: 1px solid var(--line, rgba(255, 255, 255, 0.12));
  color: var(--fg, #cbd5e1);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ai-chip:hover {
  background: rgba(168, 85, 247, 0.2);
  border-color: rgba(168, 85, 247, 0.5);
  color: #fff;
}

/* Input Area */
.ai-chat-footer {
  padding: 10px 14px;
  background: var(--bg2, #0d1226);
  border-top: 1px solid var(--line, rgba(255, 255, 255, 0.1));
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-input-field {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line, rgba(255, 255, 255, 0.12));
  color: var(--fg, #f8fafc);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.ai-input-field:focus {
  border-color: #a855f7;
  background: rgba(255, 255, 255, 0.08);
}

.ai-send-btn {
  background: linear-gradient(135deg, #6366f1, #a855f7);
  border: none;
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.2s;
}

.ai-send-btn:hover {
  opacity: 0.92;
  transform: scale(1.05);
}

.ai-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.ai-send-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Mobile Responsive */
@media (max-width: 640px) {
  .ai-chat-launcher {
    width: 52px;
    height: 52px;
    right: 16px;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
  .ai-launcher-tooltip {
    display: none !important;
  }
  .ai-chat-panel {
    right: 8px;
    left: 8px;
    width: auto;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    height: min(520px, calc(100vh - 120px));
  }
}
