/* ==========================================================================
   CloudKnowledge AI & Blog Search Assistant - Chatbot Widget
   Design System: CloudKnowledge Modern (Glassmorphism, Azure Glow, Dark/Light)
   Author: Shivam Tiwari (CloudKnowledge.in)
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. Legacy Tawk.to Suppression
   -------------------------------------------------------------------------- */
#tawk-script,
.tawk-min-container,
.tawk-custom-color,
.tawk-button,
div[id*="tawk"],
div[class*="tawk"],
iframe[title*="chat widget"],
iframe[title*="tawk"] {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  z-index: -9999 !important;
}

/* --------------------------------------------------------------------------
   1. Floating Launcher Button
   -------------------------------------------------------------------------- */
.ck-chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
  color: #ffffff;
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 28px -4px rgba(14, 165, 233, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.2) inset;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99998;
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.ck-chat-launcher:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 14px 34px -4px rgba(14, 165, 233, 0.7), 0 0 0 2px rgba(56, 189, 248, 0.4);
}

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

/* Ripple / Pulse Aura */
.ck-chat-launcher::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border-radius: 50%;
  border: 2px solid rgba(56, 189, 248, 0.7);
  animation: ckLauncherPulse 2.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite;
  pointer-events: none;
}

@keyframes ckLauncherPulse {
  0% {
    transform: scale(1);
    opacity: 0.8;
  }
  70% {
    transform: scale(1.35);
    opacity: 0;
  }
  100% {
    transform: scale(1.4);
    opacity: 0;
  }
}

.ck-chat-launcher-icon {
  font-size: 26px;
  line-height: 1;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ck-chat-launcher.active .ck-chat-launcher-icon {
  transform: rotate(90deg) scale(0.9);
}

/* Launcher Tooltip / Prompt Badge */
.ck-chat-badge {
  position: absolute;
  top: -6px;
  right: -4px;
  background: #10b981;
  border: 2px solid var(--bg-surface, #0f172a);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: 0 0 10px #10b981;
}

.ck-chat-launcher-tooltip {
  position: absolute;
  right: 72px;
  background: var(--bg-surface-elevated, #1e293b);
  color: var(--text-primary, #f8fafc);
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 0 0 1px var(--border-light, rgba(255, 255, 255, 0.08));
  pointer-events: none;
  opacity: 1;
  transform: translateX(0);
  transition: opacity 0.3s ease, transform 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ck-chat-launcher.active .ck-chat-launcher-tooltip,
.ck-chat-launcher.tooltip-dismissed .ck-chat-launcher-tooltip {
  opacity: 0;
  transform: translateX(10px);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   2. Chat Window Container
   -------------------------------------------------------------------------- */
.ck-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 410px;
  max-width: calc(100vw - 32px);
  height: 640px;
  max-height: calc(100vh - 120px);
  background: var(--bg-surface, #0f172a);
  border: 1px solid var(--border-light, rgba(255, 255, 255, 0.12));
  border-radius: 22px;
  box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(56, 189, 248, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 99999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.28s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.28s;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.ck-chat-window.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* --------------------------------------------------------------------------
   3. Chat Header
   -------------------------------------------------------------------------- */
.ck-chat-header {
  padding: 16px 18px;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.7) 0%, rgba(15, 23, 42, 0.8) 100%);
  border-bottom: 1px solid var(--border-light, rgba(255, 255, 255, 0.08));
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.ck-chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ck-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
  flex-shrink: 0;
}

.ck-chat-header-text h3 {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text-primary, #f8fafc);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ck-chat-header-text .ck-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted, #94a3b8);
  margin-top: 2px;
}

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

.ck-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ck-chat-control-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary, #94a3b8);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
}

.ck-chat-control-btn:hover {
  background: var(--bg-surface-hover, #243247);
  color: var(--text-primary, #f8fafc);
}

/* --------------------------------------------------------------------------
   4. Quick Suggestion Chips
   -------------------------------------------------------------------------- */
.ck-chat-suggestions-bar {
  padding: 10px 16px;
  background: rgba(15, 23, 42, 0.4);
  border-bottom: 1px solid var(--border-light, rgba(255, 255, 255, 0.05));
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
  -ms-overflow-style: none;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.ck-chat-suggestions-bar::-webkit-scrollbar {
  display: none;
}

.ck-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 100px;
  background: var(--bg-surface-elevated, #1e293b);
  border: 1px solid var(--border-light, rgba(255, 255, 255, 0.1));
  color: var(--text-secondary, #cbd5e1);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  user-select: none;
}

.ck-chip:hover {
  background: rgba(14, 165, 233, 0.15);
  border-color: rgba(56, 189, 248, 0.4);
  color: var(--brand-azure, #38bdf8);
  transform: translateY(-1px);
}

/* --------------------------------------------------------------------------
   5. Message Thread
   -------------------------------------------------------------------------- */
.ck-chat-messages {
  flex-grow: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.ck-chat-messages::-webkit-scrollbar {
  width: 5px;
}

.ck-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.ck-msg-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: ckMsgAppear 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.ck-msg-wrapper.user {
  align-self: flex-end;
}

.ck-msg-wrapper.bot {
  align-self: flex-start;
}

.ck-msg-bubble {
  padding: 12px 16px;
  font-size: 0.88rem;
  line-height: 1.55;
  word-break: break-word;
}

.ck-msg-wrapper.user .ck-msg-bubble {
  background: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
  color: #ffffff;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);
}

.ck-msg-wrapper.bot .ck-msg-bubble {
  background: var(--bg-surface-elevated, #1e293b);
  color: var(--text-primary, #f8fafc);
  border: 1px solid var(--border-light, rgba(255, 255, 255, 0.08));
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* Markdown formatting inside Bot Bubble */
.ck-msg-bubble p {
  margin: 0 0 8px 0;
}

.ck-msg-bubble p:last-child {
  margin-bottom: 0;
}

.ck-msg-bubble strong {
  color: #38bdf8;
  font-weight: 700;
}

.ck-msg-bubble ul,
.ck-msg-bubble ol {
  margin: 6px 0 10px 18px;
  padding: 0;
}

.ck-msg-bubble li {
  margin-bottom: 4px;
}

.ck-msg-bubble code {
  font-family: var(--font-mono, monospace);
  font-size: 0.8rem;
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 6px;
  border-radius: 4px;
  color: #38bdf8;
}

.ck-msg-bubble pre {
  background: #080c14;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.78rem;
  margin: 8px 0;
}

.ck-msg-bubble pre code {
  background: transparent;
  padding: 0;
}

.ck-msg-time {
  font-size: 0.68rem;
  color: var(--text-muted, #64748b);
  margin-top: 4px;
  padding: 0 4px;
}

.ck-msg-wrapper.user .ck-msg-time {
  text-align: right;
}

/* --------------------------------------------------------------------------
   6. Blog Recommendation Cards Inside Chat
   -------------------------------------------------------------------------- */
.ck-blog-cards-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
  width: 100%;
}

.ck-blog-card {
  display: block;
  text-decoration: none;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border-light, rgba(255, 255, 255, 0.1));
  border-left: 3px solid #0ea5e9;
  border-radius: 12px;
  padding: 12px 14px;
  transition: all 0.22s ease;
  color: inherit;
}

.ck-blog-card:hover {
  background: var(--bg-surface-hover, #243247);
  border-color: rgba(56, 189, 248, 0.4);
  border-left-color: #38bdf8;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px -4px rgba(0, 0, 0, 0.4);
}

.ck-blog-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.ck-blog-card-cat {
  font-size: 0.68rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #38bdf8;
  background: rgba(14, 165, 233, 0.12);
  padding: 2px 8px;
  border-radius: 6px;
}

.ck-blog-card-time {
  font-size: 0.7rem;
  color: var(--text-muted, #64748b);
}

.ck-blog-card-title {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-primary, #f8fafc);
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ck-blog-card-snippet {
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--text-secondary, #94a3b8);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}

.ck-blog-card-cta {
  font-size: 0.74rem;
  font-weight: 600;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 4px;
}

.ck-blog-card:hover .ck-blog-card-cta span {
  transform: translateX(3px);
  transition: transform 0.2s ease;
}

/* --------------------------------------------------------------------------
   7. Typing Indicator
   -------------------------------------------------------------------------- */
.ck-typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: var(--bg-surface-elevated, #1e293b);
  border: 1px solid var(--border-light, rgba(255, 255, 255, 0.08));
  border-radius: 18px 18px 18px 4px;
  width: fit-content;
}

.ck-typing-dot {
  width: 7px;
  height: 7px;
  background: #38bdf8;
  border-radius: 50%;
  animation: ckTypingBounce 1.4s infinite ease-in-out both;
}

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

@keyframes ckTypingBounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1.1);
    opacity: 1;
  }
}

/* --------------------------------------------------------------------------
   8. Chat Input Bar
   -------------------------------------------------------------------------- */
.ck-chat-input-area {
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.95);
  border-top: 1px solid var(--border-light, rgba(255, 255, 255, 0.08));
  flex-shrink: 0;
}

.ck-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface-elevated, #1e293b);
  border: 1px solid var(--border-light, rgba(255, 255, 255, 0.12));
  border-radius: 14px;
  padding: 4px 6px 4px 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ck-chat-form:focus-within {
  border-color: rgba(56, 189, 248, 0.5);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.ck-chat-input {
  flex-grow: 1;
  background: transparent;
  border: none;
  color: var(--text-primary, #f8fafc);
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  padding: 8px 0;
}

.ck-chat-input::placeholder {
  color: var(--text-muted, #64748b);
  font-size: 0.82rem;
}

.ck-chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
  flex-shrink: 0;
}

.ck-chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ck-chat-send-btn:not(:disabled):hover {
  transform: scale(1.05);
}

.ck-chat-disclaimer {
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-muted, #64748b);
  margin-top: 8px;
}

/* --------------------------------------------------------------------------
   9. Light Mode Overrides
   -------------------------------------------------------------------------- */
[data-theme="light"] .ck-chat-window {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(14, 165, 233, 0.2);
}

[data-theme="light"] .ck-chat-header {
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .ck-chat-suggestions-bar {
  background: #f8fafc;
  border-bottom-color: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .ck-chip {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.1);
  color: #334155;
}

[data-theme="light"] .ck-msg-wrapper.bot .ck-msg-bubble {
  background: #f1f5f9;
  color: #0f172a;
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .ck-msg-bubble strong {
  color: #0284c7;
}

[data-theme="light"] .ck-msg-bubble code {
  background: rgba(0, 0, 0, 0.06);
  color: #0284c7;
}

[data-theme="light"] .ck-msg-bubble pre {
  background: #1e293b;
  color: #f8fafc;
}

[data-theme="light"] .ck-blog-card {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .ck-blog-card:hover {
  background: #f8fafc;
}

[data-theme="light"] .ck-chat-input-area {
  background: #ffffff;
  border-top-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .ck-chat-form {
  background: #f1f5f9;
  border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .ck-typing-indicator {
  background: #f1f5f9;
  border-color: rgba(0, 0, 0, 0.08);
}

/* --------------------------------------------------------------------------
   10. Mobile Responsive (<640px)
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .ck-chat-launcher {
    bottom: 18px;
    right: 18px;
    width: 54px;
    height: 54px;
  }

  .ck-chat-launcher-tooltip {
    display: none !important;
  }

  .ck-chat-window {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }

  .ck-chat-header {
    padding: 14px 16px;
  }

  .ck-chat-messages {
    padding: 14px 12px;
  }
}
