/* ══════════════════════════════════════════
   SAP Bot
   Animated widget with SAP knowledge
   ══════════════════════════════════════════ */

/* ── Cat Widget Button ── */
.cat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9990;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* ── Cat Avatar ── */
.cat-avatar {
  width: 64px;
  height: 64px;
  cursor: pointer;
  position: relative;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.3));
  animation: catIdle 3s ease-in-out infinite;
  transition: transform 0.2s ease;
}

.cat-avatar:hover {
  animation: catJump 0.4s ease forwards;
}

/* Cat idle floating animation */
@keyframes catIdle {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  25% { transform: translateY(-4px) rotate(-1deg); }
  75% { transform: translateY(-2px) rotate(1deg); }
}

/* ── Bot SVG Animations ── */
@keyframes blink {
  0%, 96%, 98%, 100% { transform: scaleY(1); }
  97%, 99% { transform: scaleY(0.1); }
}

.robot-eye {
  animation: blink 4s infinite;
  transform-origin: center;
}

/* Glow pulsing for the robot */
@keyframes glowPulse {
  0%, 100% { opacity: 0.15; }
  50% { opacity: 0.3; }
}

.cat-avatar svg circle[fill="url(#ai-grad)"] {
  animation: glowPulse 3s ease-in-out infinite;
}

/* Cat jump on click/hover */
@keyframes catJump {
  0% { transform: translateY(0); }
  40% { transform: translateY(-16px) scale(1.1); }
  70% { transform: translateY(-6px); }
  100% { transform: translateY(0); }
}

/* Attention animation that fires randomly */
.cat-avatar.cat-attention {
  animation: catAttention 0.6s ease;
}
@keyframes catAttention {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-10deg) scale(1.05); }
  40% { transform: rotate(10deg) scale(1.1); }
  60% { transform: rotate(-8deg); }
  80% { transform: rotate(5deg); }
}

/* Notification bubble */
.cat-notification {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: #FF5252;
  border-radius: 50%;
  border: 2px solid var(--bg-primary);
  animation: pulseBadge 1.5s ease infinite;
  display: none;
}
.cat-notification.show {
  display: block;
}
@keyframes pulseBadge {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.8; }
}

/* Avatar Container for Tooltip */
.avatar-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Tooltip */
.cat-tooltip {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: 8px;
  white-space: nowrap;
  box-shadow: var(--shadow-default);
  opacity: 0;
  transform: translateX(8px);
  transition: all 0.3s ease;
  pointer-events: none;
  font-weight: 500;
}
.avatar-container:hover .cat-tooltip {
  opacity: 1;
  transform: translateX(0);
}

/* ── Chat Window ── */
.cat-chat-window {
  position: fixed;
  bottom: 104px;
  right: 24px;
  width: 380px;
  height: 520px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: var(--shadow-hover);
  display: flex;
  flex-direction: column;
  z-index: 9989;
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transform-origin: bottom right;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cat-chat-window.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--accent-blue);
  color: #FFFFFF;
  flex-shrink: 0;
}

.chat-header-avatar {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  animation: catIdle 4s ease-in-out infinite;
}

.chat-header-info h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 2px 0;
  color: #FFFFFF;
}

.chat-header-info p {
  font-size: 0.75rem;
  opacity: 0.85;
  margin: 0;
  color: rgba(255,255,255,0.85);
}

.chat-close-btn {
  margin-left: auto;
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background 0.2s;
  flex-shrink: 0;
}
.chat-close-btn:hover {
  background: rgba(255,255,255,0.35);
}

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

.chat-messages::-webkit-scrollbar {
  width: 4px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 4px;
}

/* Message Bubbles */
.chat-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: msgSlideIn 0.3s ease;
}

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

.chat-msg.bot {
  flex-direction: row;
}
.chat-msg.user {
  flex-direction: row-reverse;
}

.msg-avatar {
  font-size: 1.1rem;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.msg-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
}

.chat-msg.bot .msg-bubble {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chat-msg.user .msg-bubble {
  background: var(--accent-blue);
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
}

/* Note link in bot reply */
.note-link-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--accent-blue);
  color: white;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  margin-top: 8px;
  text-decoration: none;
  transition: opacity 0.2s;
}
.note-link-chip:hover {
  opacity: 0.85;
  color: white;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}
.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingDot 1.2s ease infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Quick Reply Suggestions */
.chat-suggestions {
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
  border-top: 1px solid var(--border-subtle);
}

.suggestion-chip {
  padding: 5px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: 20px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-body);
}
.suggestion-chip:hover {
  background: var(--accent-blue);
  color: white;
  border-color: var(--accent-blue);
}

/* Chat Input */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
  background: var(--bg-secondary);
}

.chat-input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 24px;
  padding: 10px 16px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.2s;
}
.chat-input:focus {
  border-color: var(--accent-blue);
}
.chat-input::placeholder {
  color: var(--text-muted);
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-blue);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.chat-send-btn:hover {
  background: var(--accent-blue-hover);
  transform: scale(1.05);
}
.chat-send-btn:active {
  transform: scale(0.95);
}

/* Mobile responsive */
@media (max-width: 480px) {
  .cat-chat-window {
    width: calc(100vw - 32px);
    right: 16px;
    bottom: 96px;
    height: 480px;
  }
}

/* ── Joule Wave Hover Animation ── */
@keyframes waveUndulate {
  0%, 100% { transform: scaleY(1) translateY(0); }
  50% { transform: scaleY(1.05) translateY(-2px); }
}

@keyframes waveUndulateReverse {
  0%, 100% { transform: scaleY(1) translateY(0); }
  50% { transform: scaleY(0.95) translateY(2px); }
}

.cat-avatar:hover .joule-wave,
.chat-header-avatar:hover .joule-wave,
.msg-avatar:hover .joule-wave {
  animation: waveUndulate 1s ease-in-out infinite;
  transform-origin: center;
}

.cat-avatar:hover .joule-inner-wave,
.chat-header-avatar:hover .joule-inner-wave,
.msg-avatar:hover .joule-inner-wave {
  animation: waveUndulateReverse 1s ease-in-out infinite;
  transform-origin: center;
}

.cat-avatar:hover .joule-inner-wave-2,
.chat-header-avatar:hover .joule-inner-wave-2,
.msg-avatar:hover .joule-inner-wave-2 {
  animation: waveUndulate 1.2s ease-in-out infinite;
  transform-origin: center;
}

/* ══════════════════════════════════════════
   Responsive — Chat Widget Mobile
   ══════════════════════════════════════════ */
@media (max-width: 480px) {
  /* Full-screen chat on phones */
  .cat-chat-window {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    top: auto;
    width: 100%;
    height: 85vh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    transform: translateY(100%);
    transform-origin: bottom center;
    transition: transform 0.35s cubic-bezier(0.34, 1.2, 0.64, 1), opacity 0.2s ease;
    opacity: 1;
  }

  .cat-chat-window.open {
    transform: translateY(0);
    opacity: 1;
  }

  /* Bigger avatar on mobile */
  .cat-avatar {
    width: 56px;
    height: 56px;
  }

  /* Adjust widget position */
  .cat-widget {
    bottom: 16px;
    right: 16px;
  }

  /* Bigger touch target for messages */
  .chat-messages {
    padding: 12px 12px;
  }

  .msg-bubble {
    font-size: 0.88rem;
    line-height: 1.55;
  }

  /* Input area */
  .chat-input-area {
    padding: 10px 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .chat-input {
    font-size: 0.92rem;
  }
}
