/* ============================================================
   AI FlowBot – chatbot.css
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
  --afb-primary:        #6C63FF;
  --afb-primary-dark:   #574fd6;
  --afb-primary-light:  #ede9ff;
  --afb-accent:         #ff6584;
  --afb-bg:             #ffffff;
  --afb-surface:        #f7f8fc;
  --afb-border:         #e8eaf0;
  --afb-text:           #1a1a2e;
  --afb-text-muted:     #6b7280;
  --afb-bot-bubble:     #f0effe;
  --afb-user-bubble:    #6C63FF;
  --afb-shadow:         0 8px 40px rgba(108,99,255,0.18);
  --afb-radius:         18px;
  --afb-radius-sm:      10px;
  --afb-font:           'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --afb-widget-w:       380px;
  --afb-widget-h:       580px;
  --afb-z:              999999;
}

/* ---------- Reset inside widget ---------- */
#afb-launcher *, #afb-widget * {
  box-sizing: border-box;
  margin: 0;
  padding:6px;
  font-family: var(--afb-font);
}

/* ============================================================
   LAUNCHER BUTTON
   ============================================================ */
#afb-launcher {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: var(--afb-z);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--afb-primary), #a78bfa);
  box-shadow: 0 6px 28px rgba(108,99,255,0.45);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), box-shadow 0.25s ease;
  outline: none;
  border: none;
  user-select: none;
}
#afb-launcher:hover {
  transform: scale(1.1);
  box-shadow: 0 10px 36px rgba(108,99,255,0.55);
}
#afb-launcher:active { transform: scale(0.96); }

.afb-launcher-icon {
  width: 28px;
  height: 28px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s, transform 0.2s;
}
.afb-launcher-icon svg { width: 100%; height: 100%; }

/* Notification badge */
.afb-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--afb-accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  animation: afb-pulse 2s infinite;
}
@keyframes afb-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.15); }
}

/* ============================================================
   WIDGET CONTAINER
   ============================================================ */
#afb-widget {
  position: fixed;
  bottom: 102px;
  right: 28px;
  z-index: var(--afb-z);
  width: var(--afb-widget-w);
  height: var(--afb-widget-h);
  background: var(--afb-bg);
  border-radius: var(--afb-radius);
  box-shadow: var(--afb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--afb-border);

  /* Hidden by default */
  opacity: 0;
  transform: translateY(24px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(.4,0,.2,1),
              transform 0.3s cubic-bezier(.34,1.56,.64,1);
}
#afb-widget.afb-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ============================================================
   HEADER
   ============================================================ */
.afb-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--afb-primary) 0%, #a78bfa 100%);
  color: #fff;
  flex-shrink: 0;
}
.afb-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
}
.afb-header-avatar svg { width: 40px; height: 40px; }
.afb-header-info { flex: 1; }
.afb-header-name {
  display: block;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}
.afb-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  opacity: 0.9;
  margin-top: 2px;
}
.afb-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  animation: afb-blink 2s infinite;
}
@keyframes afb-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}
.afb-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.85);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.afb-close-btn:hover { background: rgba(255,255,255,0.2); }
.afb-close-btn svg { width: 18px; height: 18px; }

/* ============================================================
   MESSAGES AREA
   ============================================================ */
.afb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
  background: var(--afb-surface);
}
.afb-messages::-webkit-scrollbar { width: 4px; }
.afb-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 99px; }

/* ---------- Message rows ---------- */
.afb-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 6px;
  animation: afb-msg-in 0.25s ease both;
}
.afb-msg-row.afb-bot  { justify-content: flex-start; }
.afb-msg-row.afb-user { justify-content: flex-end; }
@keyframes afb-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Bot avatar in message */
.afb-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--afb-primary), #a78bfa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  color: #fff;
}

/* Bubbles */
.afb-bubble {
  max-width: 78%;
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}
.afb-bot .afb-bubble {
  background: var(--afb-bot-bubble);
  color: var(--afb-text);
  border-bottom-left-radius: 4px;
}
.afb-user .afb-bubble {
  background: var(--afb-user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* ---------- Option buttons ---------- */
.afb-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 16px 10px 16px;
  animation: afb-msg-in 0.3s ease 0.1s both;
}
.afb-option-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1.5px solid var(--afb-primary);
  color: var(--afb-primary);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.18s ease;
  line-height: 1.35;
}
.afb-option-btn:hover {
  background: var(--afb-primary);
  color: #fff;
  transform: translateX(3px);
  border-color: var(--afb-primary);
}
.afb-option-btn .afb-opt-icon {
  font-size: 17px;
  flex-shrink: 0;
}
.afb-option-btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

/* Multi-select options */
.afb-options.afb-multi {
  flex-direction: column;
}
.afb-option-btn.afb-selected {
  background: var(--afb-primary-light);
  border-color: var(--afb-primary);
  color: var(--afb-primary-dark);
}
.afb-confirm-btn {
  margin: 4px 16px 10px;
  background: var(--afb-primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s;
  animation: afb-msg-in 0.3s ease both;
}
.afb-confirm-btn:hover { background: var(--afb-primary-dark); }

/* Link-style buttons */
.afb-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--afb-primary), #a78bfa);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.18s, transform 0.18s;
  margin: 3px 0;
}
.afb-link-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  color: #fff;
}
.afb-link-btn.afb-secondary {
  background: #fff;
  color: var(--afb-primary);
  border: 1.5px solid var(--afb-primary);
}
.afb-link-btn.afb-secondary:hover {
  background: var(--afb-primary-light);
  color: var(--afb-primary-dark);
}

/* CTA blocks */
.afb-cta-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 16px 14px;
  animation: afb-msg-in 0.3s ease 0.15s both;
}

/* ---------- Typing indicator ---------- */
.afb-typing {
  padding: 6px 16px 8px 52px;
  flex-shrink: 0;
}
.afb-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--afb-bot-bubble);
  padding: 9px 14px;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
}
.afb-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--afb-primary);
  opacity: 0.4;
  animation: afb-dot 1.2s infinite;
}
.afb-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.afb-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes afb-dot {
  0%, 100% { opacity: 0.4; transform: translateY(0); }
  50%       { opacity: 1;   transform: translateY(-4px); }
}

/* ============================================================
   FORM OVERLAY
   ============================================================ */
.afb-form-overlay {
  position: absolute;
  inset: 0;
  background: var(--afb-bg);
  z-index: 10;
  display: flex;
  flex-direction: column;
  animation: afb-slide-up 0.25s ease both;
  overflow-y: auto;
}
@keyframes afb-slide-up {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.afb-form-inner {
  padding: 20px 22px 24px;
  flex: 1;
}
.afb-form-back {
  background: none;
  border: none;
  color: var(--afb-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  margin-bottom: 16px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.afb-form-back:hover { text-decoration: underline; }
.afb-form-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--afb-text);
  margin-bottom: 5px;
}
.afb-form-subtitle {
  font-size: 13px;
  color: var(--afb-text-muted);
  margin-bottom: 18px;
  line-height: 1.5;
}

/* Fields */
.afb-field {
  margin-bottom: 14px;
}
.afb-field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--afb-text);
  margin-bottom: 5px;
}
.afb-field input {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--afb-border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--afb-text);
  background: var(--afb-surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.afb-field input:focus {
  border-color: var(--afb-primary);
  box-shadow: 0 0 0 3px rgba(108,99,255,0.12);
  background: #fff;
}
.afb-field input::placeholder { color: #b0b8c9; }
.afb-field-error {
  display: block;
  font-size: 11.5px;
  color: #ef4444;
  margin-top: 4px;
  min-height: 16px;
}
.afb-field.afb-invalid input { border-color: #ef4444; }

/* Submit button */
.afb-form-submit {
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, var(--afb-primary), #a78bfa);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}
.afb-form-submit:hover { opacity: 0.92; transform: translateY(-1px); }
.afb-form-submit:disabled { opacity: 0.6; cursor: default; transform: none; }

/* Spinner */
.afb-submit-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: afb-spin 0.7s linear infinite;
}
@keyframes afb-spin { to { transform: rotate(360deg); } }

.afb-form-privacy {
  text-align: center;
  font-size: 11.5px;
  color: var(--afb-text-muted);
  margin-top: 10px;
}

/* Success state */
.afb-form-success {
  text-align: center;
  padding: 30px 10px;
}
.afb-success-icon { font-size: 48px; margin-bottom: 12px; }
.afb-form-success h4 {
  font-size: 18px;
  font-weight: 700;
  color: var(--afb-text);
  margin-bottom: 8px;
}
.afb-form-success p {
  font-size: 14px;
  color: var(--afb-text-muted);
  line-height: 1.5;
}

/* ============================================================
   FOOTER
   ============================================================ */
.afb-footer {
  text-align: center;
  font-size: 11px;
  color: #c0c4ce;
  padding: 6px 0 9px;
  flex-shrink: 0;
  background: var(--afb-bg);
  border-top: 1px solid var(--afb-border);
}
.afb-footer strong { color: var(--afb-primary); }

/* ============================================================
   MOBILE RESPONSIVE
   ============================================================ */
@media (max-width: 480px) {
  :root {
    --afb-widget-w:  100vw;
    --afb-widget-h:  100dvh;
  }
  #afb-widget {
    bottom: 0;
    right: 0;
    border-radius: 0;
    border: none;
    height: 100dvh;
    width: 100vw;
  }
  #afb-launcher {
    bottom: 20px;
    right: 20px;
  }
}