/* ============================================================
   AI CHATBOT WIDGET — Cyberpunk Glassmorphism Theme
   All classes prefixed with .kamal-ai- to avoid collision.
   References existing site custom properties — does NOT redefine them.
   ============================================================ */

/* -------------------------------------------------------
   ANIMATIONS
   ------------------------------------------------------- */

@keyframes kamal-ai-pulse {
  0%, 100% {
    box-shadow:
      0 0 12px rgba(124, 58, 237, 0.45),
      0 0 32px rgba(124, 58, 237, 0.18);
  }
  50% {
    box-shadow:
      0 0 20px rgba(124, 58, 237, 0.65),
      0 0 48px rgba(244, 114, 182, 0.28);
  }
}

@keyframes kamal-ai-bounce {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-7px);
    opacity: 1;
  }
}

@keyframes kamal-ai-slideUp {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

/* -------------------------------------------------------
   1. FAB — Floating Action Button
   ------------------------------------------------------- */

.kamal-ai-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9990;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-3) 100%);
  color: #fff;
  font-size: 1.45rem;
  line-height: 1;
  box-shadow:
    0 0 12px rgba(124, 58, 237, 0.45),
    0 0 32px rgba(124, 58, 237, 0.18),
    0 4px 14px rgba(0, 0, 0, 0.35);
  animation: kamal-ai-pulse 2.8s ease-in-out infinite;
  transition:
    transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.25s ease,
    visibility 0.25s ease;
  will-change: transform, box-shadow;
  -webkit-tap-highlight-color: transparent;
}

.kamal-ai-fab:hover {
  transform: scale(1.12);
}

.kamal-ai-fab:active {
  transform: scale(0.95);
}

/* Hide FAB when panel is open */
.kamal-ai-fab--open {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.6);
}

/* -------------------------------------------------------
   2. CHAT PANEL
   ------------------------------------------------------- */

.kamal-ai-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9990;
  width: 400px;
  height: 520px;
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Glassmorphism */
  background:
    linear-gradient(
      168deg,
      rgba(124, 58, 237, 0.06) 0%,
      rgba(6, 182, 212, 0.04) 40%,
      var(--glass) 100%
    );
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  backdrop-filter: blur(20px) saturate(1.3);

  /* Neon border + glow */
  border: 1px solid var(--glass-border);
  box-shadow:
    0 0 1px rgba(124, 58, 237, 0.5),
    0 0 40px rgba(124, 58, 237, 0.08),
    0 8px 32px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);

  /* Default hidden state */
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.97);
  transition:
    opacity 0.35s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: opacity, transform;
}

.kamal-ai-panel--open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  animation: kamal-ai-slideUp 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* -------------------------------------------------------
   3. PANEL HEADER
   ------------------------------------------------------- */

.kamal-ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
  background: linear-gradient(
    180deg,
    rgba(124, 58, 237, 0.06) 0%,
    transparent 100%
  );
}

.kamal-ai-header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kamal-ai-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 1.08rem;
  letter-spacing: 0.02em;
  background: linear-gradient(
    135deg,
    var(--accent-2) 0%,
    var(--accent) 50%,
    var(--accent-3) 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.3;
}

.kamal-ai-subtitle {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  opacity: 0.8;
}

.kamal-ai-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px;
  transition:
    background 0.2s ease,
    color 0.2s ease,
    transform 0.2s ease;
  flex-shrink: 0;
}

.kamal-ai-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--accent-3);
  transform: rotate(90deg);
}

/* -------------------------------------------------------
   4. MESSAGES AREA
   ------------------------------------------------------- */

.kamal-ai-messages {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 18px 16px 10px;
  scroll-behavior: smooth;
}

/* Custom scrollbar */
.kamal-ai-messages::-webkit-scrollbar {
  width: 5px;
}

.kamal-ai-messages::-webkit-scrollbar-track {
  background: transparent;
}

.kamal-ai-messages::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-radius: 10px;
}

.kamal-ai-messages {
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
}

/* -------------------------------------------------------
   5. MESSAGE BUBBLES
   ------------------------------------------------------- */

.kamal-ai-msg {
  max-width: 85%;
  padding: 11px 16px;
  border-radius: 18px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.88rem;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: kamal-ai-fadeIn 0.3s ease both;
}

/* User message */
.kamal-ai-msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-3) 100%);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow:
    0 2px 12px rgba(124, 58, 237, 0.22),
    0 0 20px rgba(244, 114, 182, 0.08);
}

/* AI message */
.kamal-ai-msg--ai {
  align-self: flex-start;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--text);
  border-bottom-left-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Error message */
.kamal-ai-msg--error {
  align-self: flex-start;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border-bottom-left-radius: 6px;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.06);
}

/* -------------------------------------------------------
   6. WELCOME MESSAGE
   ------------------------------------------------------- */

.kamal-ai-welcome {
  text-align: center;
  padding: 28px 20px 12px;
  color: var(--muted);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.84rem;
  line-height: 1.6;
  opacity: 0.85;
}

.kamal-ai-welcome strong {
  display: block;
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent-3));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* -------------------------------------------------------
   7. TYPING INDICATOR
   ------------------------------------------------------- */

.kamal-ai-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  padding: 12px 18px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
}

.kamal-ai-typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  animation: kamal-ai-bounce 1.2s ease-in-out infinite;
  will-change: transform, opacity;
}

.kamal-ai-typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.kamal-ai-typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

/* -------------------------------------------------------
   8. INPUT ROW
   ------------------------------------------------------- */

.kamal-ai-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
  background: linear-gradient(
    0deg,
    rgba(124, 58, 237, 0.04) 0%,
    transparent 100%
  );
}

#kamal-ai-input {
  flex: 1 1 0;
  height: 40px;
  padding: 0 16px;
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.85rem;
  outline: none;
  transition:
    border-color 0.25s ease,
    box-shadow 0.25s ease,
    background 0.25s ease;
}

#kamal-ai-input::placeholder {
  color: var(--muted);
  opacity: 0.55;
}

#kamal-ai-input:focus {
  border-color: rgba(124, 58, 237, 0.45);
  box-shadow: 0 0 12px rgba(124, 58, 237, 0.12);
  background: rgba(255, 255, 255, 0.05);
}

#kamal-ai-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#kamal-ai-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-3) 100%);
  color: #fff;
  font-size: 1.05rem;
  line-height: 1;
  transition:
    transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.2s ease,
    box-shadow 0.25s ease;
  box-shadow: 0 2px 10px rgba(124, 58, 237, 0.25);
}

#kamal-ai-send:hover {
  transform: scale(1.1);
  box-shadow:
    0 2px 16px rgba(124, 58, 237, 0.4),
    0 0 24px rgba(244, 114, 182, 0.15);
}

#kamal-ai-send:active {
  transform: scale(0.92);
}

#kamal-ai-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* -------------------------------------------------------
   9. RATE LIMIT MESSAGE
   ------------------------------------------------------- */

.kamal-ai-rate-limit {
  text-align: center;
  padding: 8px 16px 4px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.7;
  letter-spacing: 0.02em;
}

/* -------------------------------------------------------
   10. GREETING TRANSITION
   ------------------------------------------------------- */

.kamal-ai-greeting-fade {
  transition: opacity 0.6s ease;
  opacity: 0;
}

/* -------------------------------------------------------
   11. RESPONSIVE — Mobile ≤ 768px
   ------------------------------------------------------- */

@media (max-width: 768px) {
  .kamal-ai-panel {
    width: calc(100% - 16px);
    height: 70vh;
    max-height: 70vh;
    right: 8px;
    left: 8px;
    bottom: 8px;
    border-radius: 20px;
  }

  .kamal-ai-fab {
    bottom: 18px;
    right: 18px;
  }

  .kamal-ai-messages {
    padding: 14px 12px 8px;
  }

  .kamal-ai-msg {
    max-width: 90%;
    font-size: 0.85rem;
  }

  .kamal-ai-input-row {
    padding: 10px 10px 12px;
  }

  .kamal-ai-header {
    padding: 14px 14px 12px;
  }
}

/* -------------------------------------------------------
   12. ACCESSIBILITY — Reduced motion
   ------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .kamal-ai-fab,
  .kamal-ai-panel,
  .kamal-ai-msg,
  .kamal-ai-typing-dot,
  .kamal-ai-close {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  .kamal-ai-panel--open {
    animation: none;
  }
}
