/* ============================================================
   CQC AI CHAT WIDGET
   Powered by Brandscapers Africa
   ============================================================ */

/* ---- Container ---- */
#cqc-chat-widget {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  font-family: 'Poppins', sans-serif;
  transform: none !important;
}

/* ---- FAB Button ---- */
#cqc-chat-fab {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--primary, #566c83);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 4px 20px rgba(86, 108, 131, 0.45);
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
  position: relative;
  outline: none;
}

#cqc-chat-fab:hover {
  background: var(--primary-dark, #3d5166);
  transform: scale(1.07);
  box-shadow: 0 6px 28px rgba(86, 108, 131, 0.55);
}

#cqc-chat-fab .fab-icon-open  { display: block; }
#cqc-chat-fab .fab-icon-close { display: none; }
#cqc-chat-fab.open .fab-icon-open  { display: none; }
#cqc-chat-fab.open .fab-icon-close { display: block; }

/* Pulse ring — draws attention on first load */
#cqc-chat-fab::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(86, 108, 131, 0.45);
  animation: cqc-pulse 2s ease-out 1.5s 2;
  opacity: 0;
}

@keyframes cqc-pulse {
  0%   { transform: scale(1);   opacity: 0.7; }
  100% { transform: scale(1.55); opacity: 0;   }
}

/* Unread badge */
#cqc-fab-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent, #c98766);
  border: 2px solid #fff;
  font-size: 0.6rem;
  font-weight: 700;
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
}
#cqc-fab-badge.visible { display: flex; }

/* ---- Chat Panel ---- */
#cqc-chat-panel {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 370px;
  max-height: 570px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 12px 48px rgba(30, 42, 56, 0.18), 0 2px 8px rgba(30, 42, 56, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* hidden until opened */
  opacity: 0;
  transform: scale(0.9) translateY(16px);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#cqc-chat-panel.visible {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: all;
}

/* ---- Header ---- */
.cqc-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--primary, #566c83);
  color: #fff;
  flex-shrink: 0;
}

.cqc-chat-avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.cqc-chat-header-info { flex: 1; }

.cqc-chat-header-info strong {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
}

.cqc-chat-header-info span {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.75);
  margin-top: 1px;
}

.cqc-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5bcea5;
  display: inline-block;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(91,206,165,0.3);
}

#cqc-chat-close-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  transition: background 0.2s;
  flex-shrink: 0;
}

#cqc-chat-close-btn:hover { background: rgba(255,255,255,0.28); }

/* ---- Messages Area ---- */
#cqc-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

#cqc-chat-messages::-webkit-scrollbar { width: 4px; }
#cqc-chat-messages::-webkit-scrollbar-track { background: transparent; }
#cqc-chat-messages::-webkit-scrollbar-thumb { background: #dde2e8; border-radius: 4px; }

/* Message rows */
.cqc-msg-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: cqc-msg-in 0.2s ease;
}

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

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

.cqc-msg-icon {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  background: var(--primary, #566c83);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
}

.cqc-msg-row.user .cqc-msg-icon {
  background: var(--accent, #c98766);
}

/* Bubble */
.cqc-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--dark, #1e2a38);
  background: #f2f4f8;
  border: 1px solid #e8eaef;
  word-break: break-word;
}

.cqc-msg-row.user .cqc-bubble {
  background: var(--primary, #566c83);
  color: #fff;
  border-color: transparent;
  border-bottom-right-radius: 4px;
}

.cqc-msg-row.assistant .cqc-bubble {
  border-bottom-left-radius: 4px;
}

/* Markdown renders inside bubbles */
.cqc-bubble strong { font-weight: 700; }
.cqc-bubble em { font-style: italic; }
.cqc-bubble ul { padding-left: 16px; margin: 6px 0; }
.cqc-bubble li { margin-bottom: 3px; }
.cqc-bubble a { color: var(--accent, #c98766); text-decoration: underline; }
.cqc-msg-row.user .cqc-bubble a { color: rgba(255,255,255,0.85); }

/* ---- Typing Indicator ---- */
.cqc-typing-bubble {
  background: #f2f4f8;
  border: 1px solid #e8eaef;
  padding: 10px 14px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.cqc-typing-bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8fa0b4;
  display: inline-block;
  animation: cqc-bounce 1.2s infinite ease-in-out;
}

.cqc-typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.cqc-typing-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes cqc-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-6px); }
}

/* ---- Suggestion Chips ---- */
#cqc-suggestions {
  padding: 0 12px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

.cqc-chip {
  font-family: 'Poppins', sans-serif;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--primary, #566c83);
  background: rgba(86, 108, 131, 0.07);
  border: 1px solid rgba(86, 108, 131, 0.2);
  border-radius: 50px;
  padding: 5px 12px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  white-space: nowrap;
}

.cqc-chip:hover {
  background: var(--primary, #566c83);
  border-color: var(--primary, #566c83);
  color: #fff;
}

/* ---- Input Row ---- */
.cqc-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid #eef0f4;
  background: #fff;
  flex-shrink: 0;
}

#cqc-chat-input {
  flex: 1;
  font-family: 'Poppins', sans-serif;
  font-size: 0.82rem;
  border: 1px solid #e0e4ea;
  border-radius: 50px;
  padding: 9px 16px;
  outline: none;
  color: var(--dark, #1e2a38);
  background: #f8f9fc;
  transition: border-color 0.2s;
}

#cqc-chat-input:focus { border-color: var(--primary, #566c83); background: #fff; }
#cqc-chat-input::placeholder { color: #9aaab8; }
#cqc-chat-input:disabled { opacity: 0.6; cursor: not-allowed; }

#cqc-chat-send {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 50%;
  background: var(--primary, #566c83);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: background 0.2s, transform 0.15s;
  flex-shrink: 0;
}

#cqc-chat-send:hover:not(:disabled) { background: var(--primary-dark, #3d5166); transform: scale(1.08); }
#cqc-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Footer ---- */
.cqc-chat-footer {
  text-align: center;
  font-size: 0.67rem;
  color: #9aaab8;
  padding: 6px 16px 10px;
  border-top: 1px solid #f0f2f5;
  flex-shrink: 0;
  letter-spacing: 0.2px;
}

.cqc-chat-footer strong {
  color: var(--accent, #c98766);
  font-weight: 600;
}

/* Error message */
.cqc-error-msg {
  font-size: 0.75rem;
  color: #c0392b;
  background: #fdf3f2;
  border: 1px solid #f5c6c2;
  border-radius: 8px;
  padding: 8px 12px;
  margin: 4px 0;
  text-align: center;
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
  #cqc-chat-widget { bottom: 16px; right: 16px; }
  #cqc-chat-panel { width: calc(100vw - 32px); max-height: 75vh; right: 0; }
}
