/* ============================================
   SmartB Academy - Chatbot Widget
   Floating chat bubble + chat window
   ============================================ */

/* --- Chat Toggle Button --- */
.chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 90px;
  z-index: 950;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--grad);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(15, 45, 69, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(15, 45, 69, 0.45);
}

.chat-toggle svg {
  width: 26px;
  height: 26px;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-toggle .chat-icon-close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg);
}

.chat-toggle[aria-expanded="true"] .chat-icon-open {
  opacity: 0;
  transform: rotate(90deg);
}

.chat-toggle[aria-expanded="true"] .chat-icon-close {
  opacity: 1;
  transform: rotate(0deg);
}

/* Pulse animation on first visit */
@keyframes chat-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(15, 45, 69, 0.35); }
  50% { box-shadow: 0 4px 20px rgba(15, 45, 69, 0.35), 0 0 0 12px rgba(23, 66, 99, 0.15); }
}

.chat-toggle.pulse {
  animation: chat-pulse 2s ease-in-out 3;
}

/* --- Chat Window --- */
.chat-window {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 951;
  width: 380px;
  height: 520px;
  max-height: calc(100vh - 120px);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
}

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

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

.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-header-avatar svg {
  width: 20px;
  height: 20px;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-header-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}

.chat-header-status {
  font-size: 12px;
  opacity: 0.8;
}

.chat-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

.chat-close svg {
  width: 20px;
  height: 20px;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* --- Message Bubbles --- */
.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
}

.chat-msg a {
  color: inherit;
  text-decoration: underline;
}

.chat-msg-bot {
  align-self: flex-start;
  background: var(--pure-white);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-msg-user {
  align-self: flex-end;
  background: var(--amber);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Markdown in bot messages */
.chat-msg-bot strong {
  font-weight: 700;
}

.chat-msg-bot ul, .chat-msg-bot ol {
  margin: 6px 0;
  padding-left: 18px;
}

.chat-msg-bot li {
  margin-bottom: 2px;
}

.chat-msg-bot p {
  margin: 0 0 6px;
}

.chat-msg-bot p:last-child {
  margin-bottom: 0;
}

/* --- Typing Indicator --- */
.chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background: var(--pure-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  border-bottom-left-radius: 4px;
  font-size: 13px;
  color: var(--muted);
}

.chat-typing-label {
  margin-right: 2px;
}

.chat-typing-dots {
  display: flex;
  gap: 4px;
}

.chat-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.chat-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* --- Quick Replies --- */
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 12px;
  flex-shrink: 0;
}

.chat-chip {
  padding: 7px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--pure-white);
  color: var(--blue-text);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  line-height: 1.3;
}

.chat-chip:hover {
  background: var(--bg);
  border-color: var(--amber);
}

/* --- Input Area --- */
.chat-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--pure-white);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s ease;
  min-height: 40px;
  resize: none;
}

.chat-input::placeholder {
  color: var(--muted);
}

.chat-input:focus {
  border-color: var(--amber);
}

.chat-send {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-btn);
  border: none;
  background: var(--amber);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.1s ease;
}

.chat-send:hover {
  background: var(--amber-d);
}

.chat-send:active {
  transform: scale(0.95);
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-send svg {
  width: 18px;
  height: 18px;
}

/* --- Footer --- */
.chat-footer {
  text-align: center;
  padding: 6px;
  font-size: 11px;
  color: var(--muted);
  background: var(--pure-white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* --- Error message --- */
.chat-msg-error {
  align-self: flex-start;
  background: #FFF3F3;
  color: #B91C1C;
  border: 1px solid #FECACA;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
}

/* --- Mobile Responsive --- */
@media (max-width: 480px) {
  .chat-toggle {
    right: 78px;
    bottom: 20px;
    width: 50px;
    height: 50px;
  }

  .chat-toggle svg {
    width: 22px;
    height: 22px;
  }

  .chat-window {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .chat-input {
    min-height: 44px;
    font-size: 16px; /* prevents iOS zoom */
  }

  .chat-send {
    width: 44px;
    height: 44px;
  }

  .chat-chip {
    font-size: 12px;
    padding: 6px 12px;
  }
}

/* Adjust WhatsApp float when chatbot exists */
@media (max-width: 480px) {
  .chat-window.open ~ .wa-float,
  .chat-window.open ~ a.wa-float {
    display: none;
  }
}
