/* =============================================
   CONNECT THE WORLD — Chatbot Widget
   ============================================= */

/* ---- Floating Trigger Button ---- */
.ctw-chat-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9000;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--primary, #1a6b5a);
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 28px rgba(26,107,90,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1),
              box-shadow 0.3s ease,
              background 0.25s ease;
  outline: none;
}
.ctw-chat-btn:hover {
  transform: scale(1.12);
  box-shadow: 0 10px 36px rgba(26,107,90,0.55);
  background: var(--primary-dark, #134e42);
}
.ctw-chat-btn svg { transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1); }
.ctw-chat-btn.is-open svg.icon-chat { display: none; }
.ctw-chat-btn:not(.is-open) svg.icon-close { display: none; }

/* Pulse ring on idle */
.ctw-chat-btn::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(26,107,90,0.4);
  animation: chatPulse 2.5s ease-out infinite;
}
@keyframes chatPulse {
  0%   { transform: scale(1);    opacity: 1; }
  70%  { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}
.ctw-chat-btn.is-open::before { animation: none; opacity: 0; }

/* Unread badge */
.ctw-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent, #f0a500);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  animation: badgePop 0.4s cubic-bezier(0.34,1.56,0.64,1) both;
  animation-delay: 1.5s;
}
@keyframes badgePop {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.ctw-badge.hidden { display: none; }

/* ---- Chat Panel ---- */
.ctw-panel {
  position: fixed;
  bottom: 100px;
  right: 28px;
  z-index: 8999;
  width: 360px;
  max-height: 520px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.38s cubic-bezier(0.22,0.61,0.36,1),
              opacity 0.32s ease;
  transform-origin: bottom right;
}
.ctw-panel.is-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

/* Header */
.ctw-header {
  background: linear-gradient(135deg, var(--primary, #1a6b5a), var(--primary-dark, #134e42));
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.ctw-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.25);
}
.ctw-header-info { flex: 1; }
.ctw-header-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  line-height: 1.2;
}
.ctw-header-status {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.75);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
.ctw-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  animation: statusBlink 2.5s ease-in-out infinite;
}
@keyframes statusBlink {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.4; }
}
.ctw-header-close {
  background: rgba(255,255,255,0.12);
  border: none;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background 0.2s ease, color 0.2s ease;
  flex-shrink: 0;
  line-height: 1;
}
.ctw-header-close:hover { background: rgba(255,255,255,0.22); color: #fff; }

/* Quick suggestions bar */
.ctw-suggestions {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  overflow-x: auto;
  flex-shrink: 0;
  background: #f8f9fc;
  border-bottom: 1px solid #e8eef0;
  scrollbar-width: none;
}
.ctw-suggestions::-webkit-scrollbar { display: none; }
.ctw-chip {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 16px;
  border: 1.5px solid var(--primary, #1a6b5a);
  background: transparent;
  color: var(--primary, #1a6b5a);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s cubic-bezier(0.34,1.56,0.64,1);
  white-space: nowrap;
}
.ctw-chip:hover {
  background: var(--primary, #1a6b5a);
  color: #fff;
  transform: translateY(-2px);
}

/* Messages area */
.ctw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.ctw-messages::-webkit-scrollbar { width: 4px; }
.ctw-messages::-webkit-scrollbar-track { background: transparent; }
.ctw-messages::-webkit-scrollbar-thumb { background: #d0dbd8; border-radius: 4px; }

/* Individual message bubbles */
.ctw-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: msgSlideIn 0.3s cubic-bezier(0.22,0.61,0.36,1) both;
}
@keyframes msgSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ctw-msg.user { flex-direction: row-reverse; }

.ctw-msg-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary, #1a6b5a);
  color: #fff;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 2px;
}
.ctw-msg.user .ctw-msg-icon {
  background: var(--accent, #f0a500);
}

.ctw-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #2a2a3e;
  background: #f0f4f2;
  border-bottom-left-radius: 4px;
}
.ctw-msg.user .ctw-bubble {
  background: var(--primary, #1a6b5a);
  color: #fff;
  border-bottom-left-radius: 18px;
  border-bottom-right-radius: 4px;
}
.ctw-bubble a {
  color: var(--accent, #f0a500);
  font-weight: 600;
  text-decoration: underline;
}
.ctw-msg.user .ctw-bubble a { color: #ffd97a; }

/* Timestamp */
.ctw-time {
  font-size: 0.68rem;
  color: #aab0b8;
  margin-top: 2px;
  text-align: right;
}
.ctw-msg:not(.user) .ctw-time { text-align: left; padding-left: 36px; }

/* Typing indicator */
.ctw-typing {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.ctw-typing-dots {
  background: #f0f4f2;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.ctw-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8898a4;
  animation: typingDot 1.2s ease-in-out infinite;
}
.ctw-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.ctw-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%,60%,100% { transform: translateY(0); opacity: 0.5; }
  30%          { transform: translateY(-5px); opacity: 1; }
}

/* Input area */
.ctw-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid #e8eef0;
  background: #fff;
  flex-shrink: 0;
}
.ctw-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #d8e4e0;
  border-radius: 24px;
  font-size: 0.875rem;
  outline: none;
  background: #f8f9fc;
  color: #2a2a3e;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
  resize: none;
  font-family: inherit;
}
.ctw-input:focus {
  border-color: var(--primary, #1a6b5a);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(26,107,90,0.1);
}
.ctw-input::placeholder { color: #aab0b8; }
.ctw-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary, #1a6b5a);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.22s cubic-bezier(0.34,1.56,0.64,1),
              background 0.22s ease,
              box-shadow 0.22s ease;
  box-shadow: 0 3px 10px rgba(26,107,90,0.3);
}
.ctw-send:hover {
  transform: scale(1.1);
  background: var(--primary-dark, #134e42);
  box-shadow: 0 5px 16px rgba(26,107,90,0.4);
}
.ctw-send:active { transform: scale(0.95); }
.ctw-send svg { color: #fff; }

/* Footer branding */
.ctw-footer {
  text-align: center;
  padding: 5px 0 8px;
  font-size: 0.68rem;
  color: #b0bec5;
  background: #fff;
  flex-shrink: 0;
}
.ctw-footer span { color: var(--primary, #1a6b5a); font-weight: 600; }

/* Mobile */
@media (max-width: 480px) {
  .ctw-panel {
    width: calc(100vw - 20px);
    right: 10px;
    bottom: 88px;
    max-height: calc(100vh - 120px);
  }
  .ctw-chat-btn { right: 16px; bottom: 20px; }
}
