/* ==========================================================================
   CalcWorker AI Floating Widget & Flash Animation
   ========================================================================== */

#cw-ai-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
}

/* 1. Floating Action Launcher Button */
.cw-ai-launcher {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e40af, #2563eb, #1d4ed8);
  border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 10px 25px -3px rgba(37, 99, 235, 0.5), 0 4px 10px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s ease;
  overflow: hidden;
  user-select: none;
}

.cw-ai-launcher:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 14px 30px -2px rgba(37, 99, 235, 0.65), 0 6px 14px rgba(0, 0, 0, 0.4);
  border-color: rgba(255, 255, 255, 0.4);
}

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

/* Eye-Catching Shimmer / Flash Wave across Logo (Every 11-12 Seconds) */
.cw-ai-launcher::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    60deg,
    rgba(255, 255, 255, 0) 20%,
    rgba(255, 255, 255, 0.15) 35%,
    rgba(255, 255, 255, 0.85) 50%,
    rgba(255, 255, 255, 0.15) 65%,
    rgba(255, 255, 255, 0) 80%
  );
  transform: translateX(-160%) rotate(25deg);
  animation: cw-flash-wave 11s infinite cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

@keyframes cw-flash-wave {
  0%, 75%, 100% {
    transform: translateX(-160%) rotate(25deg);
    opacity: 0;
  }
  80% {
    opacity: 1;
  }
  88% {
    transform: translateX(160%) rotate(25deg);
    opacity: 1;
  }
  89% {
    opacity: 0;
  }
}

/* Glowing Pulsing Border Ring */
.cw-ai-pulse-ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(59, 130, 246, 0.45);
  animation: cw-pulse 3s infinite ease-out;
  pointer-events: none;
}

@keyframes cw-pulse {
  0% {
    transform: scale(0.95);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.1);
    opacity: 0;
  }
  100% {
    transform: scale(0.95);
    opacity: 0;
  }
}

/* Inner Badge Icon (Calculator + AI Sparkle) */
.cw-ai-badge-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: #ffffff;
}

.cw-ai-badge-svg {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* Tooltip Badge on Hover */
.cw-ai-tooltip {
  position: absolute;
  right: 74px;
  background: #0f172a;
  color: #f8fafc;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid #334155;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  opacity: 0;
  transform: translateX(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

/* 2. Chat Window Drawer */
.cw-ai-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: #090d16;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  box-shadow: 0 20px 45px -5px rgba(0, 0, 0, 0.7), 0 0 20px rgba(37, 99, 235, 0.2);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: cw-slide-up 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  backdrop-filter: blur(12px);
}

.cw-ai-window.open {
  display: flex;
}

@keyframes cw-slide-up {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Header */
.cw-ai-header {
  padding: 14px 18px;
  background: linear-gradient(135deg, #111827, #1e293b);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cw-ai-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cw-ai-avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #2563eb;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.1rem;
}

.cw-ai-title-wrap {
  display: flex;
  flex-direction: column;
}

.cw-ai-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #f8fafc;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cw-ai-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.cw-ai-subtitle {
  font-size: 0.72rem;
  color: #94a3b8;
}

.cw-ai-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.cw-ai-btn-icon {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  line-height: 1;
  transition: all 0.15s;
}

.cw-ai-btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

/* Quick Prompt Suggestions */
.cw-ai-chips {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  background: #0f172a;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  overflow-x: auto;
  scrollbar-width: none;
}

.cw-ai-chips::-webkit-scrollbar {
  display: none;
}

.cw-ai-chip {
  padding: 5px 11px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s;
}

.cw-ai-chip:hover {
  background: #2563eb;
  border-color: #2563eb;
  color: #ffffff;
}

/* Messages Box */
.cw-ai-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cw-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.55;
  word-break: break-word;
}

.cw-msg.user {
  align-self: flex-end;
  background: #2563eb;
  color: #ffffff;
  border-bottom-right-radius: 3px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.cw-msg.bot {
  align-self: flex-start;
  background: #1e293b;
  color: #f1f5f9;
  border-bottom-left-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.cw-msg.bot a {
  color: #60a5fa;
  font-weight: 600;
  text-decoration: underline;
}

.cw-msg.bot a:hover {
  color: #93c5fd;
}

.cw-msg.bot ul, .cw-msg.bot ol {
  margin: 6px 0 6px 18px;
}

.cw-msg.bot li {
  margin-bottom: 4px;
}

.cw-msg.bot code {
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.84rem;
}

/* Typing Indicator */
.cw-ai-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: #1e293b;
  border-radius: 12px;
  width: fit-content;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.cw-ai-dot {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: cw-dot-pulse 1.4s infinite ease-in-out;
}

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

@keyframes cw-dot-pulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; background: #60a5fa; }
}

/* Input Bar */
.cw-ai-input-bar {
  padding: 12px;
  background: #0f172a;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  gap: 8px;
  align-items: center;
}

.cw-ai-input {
  flex: 1;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 14px;
  color: #ffffff;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
}

.cw-ai-input:focus {
  border-color: #2563eb;
}

.cw-ai-send-btn {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cw-ai-send-btn:hover {
  opacity: 0.9;
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
  #cw-ai-root {
    bottom: 18px;
    right: 18px;
  }
  .cw-ai-window {
    width: calc(100vw - 28px);
    height: calc(100vh - 100px);
    bottom: 74px;
    right: 0;
  }
}
