/* ─── Afina Chatbot Widget v1.0 ─────────────────────────────────────────────
   Design: refined navy/blue, clean modern chat UI, smooth animations
   ─────────────────────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
  --ac-primary:      #1B2A4A;
  --ac-accent:       #2563EB;
  --ac-accent-light: #EFF6FF;
  --ac-text:         #1E293B;
  --ac-text-muted:   #64748B;
  --ac-border:       #E2E8F0;
  --ac-bg:           #FFFFFF;
  --ac-bot-bg:       #F1F5F9;
  --ac-user-bg:      var(--ac-accent);
  --ac-user-text:    #FFFFFF;
  --ac-shadow:       0 20px 60px rgba(0,0,0,.18), 0 4px 16px rgba(0,0,0,.08);
  --ac-radius:       20px;
  --ac-font:         'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --ac-w:            380px;
  --ac-h:            560px;
}

/* ── Container ─────────────────────────────────────────────────────────────── */
#afina-chatbot-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999999;
  font-family: var(--ac-font);
}

/* ── Bubble button ──────────────────────────────────────────────────────────── */
.ac-bubble {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--ac-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(27,42,74,.4);
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .25s;
  position: relative;
  border: none;
  outline: none;
}

.ac-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(27,42,74,.5);
}

.ac-bubble.ac-active {
  background: var(--ac-accent);
}

.ac-bubble-icon {
  width: 26px;
  height: 26px;
  color: white;
  transition: opacity .2s, transform .2s;
}

/* Notification badge */
.ac-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  background: #EF4444;
  color: white;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  animation: ac-pulse 2s infinite;
}

@keyframes ac-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.15); }
}

/* ── Window ────────────────────────────────────────────────────────────────── */
.ac-window {
  position: absolute;
  bottom: 74px;
  right: 0;
  width: var(--ac-w);
  height: var(--ac-h);
  background: var(--ac-bg);
  border-radius: var(--ac-radius);
  box-shadow: var(--ac-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: scale(.92) translateY(16px);
  pointer-events: none;
  transition: opacity .28s cubic-bezier(.4,0,.2,1), transform .28s cubic-bezier(.34,1.56,.64,1);
  border: 1px solid rgba(255,255,255,.1);
}

.ac-window.ac-open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: all;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.ac-header {
  background: var(--ac-primary);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

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

.ac-header-avatar svg {
  width: 22px;
  height: 22px;
  color: white;
}

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

.ac-header-name {
  display: block;
  font-weight: 600;
  font-size: 15px;
  color: white;
  line-height: 1.3;
}

.ac-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: rgba(255,255,255,.7);
}

.ac-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22C55E;
  box-shadow: 0 0 0 2px rgba(34,197,94,.3);
  animation: ac-pulse 2.5s infinite;
}

.ac-minimize-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: rgba(255,255,255,.7);
  border-radius: 6px;
  transition: background .15s, color .15s;
  display: flex;
  align-items: center;
}

.ac-minimize-btn:hover { background: rgba(255,255,255,.12); color: white; }
.ac-minimize-btn svg   { width: 18px; height: 18px; }

/* ── Body / messages area ───────────────────────────────────────────────────── */
.ac-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.ac-body::-webkit-scrollbar       { width: 4px; }
.ac-body::-webkit-scrollbar-track { background: transparent; }
.ac-body::-webkit-scrollbar-thumb { background: var(--ac-border); border-radius: 4px; }

/* ── Consent screen ─────────────────────────────────────────────────────────── */
.ac-consent {
  text-align: center;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.ac-consent-icon { font-size: 36px; }

.ac-consent p {
  font-size: 14px;
  color: var(--ac-text-muted);
  line-height: 1.5;
  margin: 0;
}

/* ── Message rows ────────────────────────────────────────────────────────────── */
.ac-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 8px;
}

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

.ac-avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ac-primary);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ac-avatar-sm svg {
  width: 16px;
  height: 16px;
  color: white;
}

/* ── Bubbles ──────────────────────────────────────────────────────────────────── */
.ac-bubble-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
}

.ac-bubble-bot {
  background: var(--ac-bot-bg);
  color: var(--ac-text);
  border-bottom-left-radius: 4px;
}

.ac-bubble-user {
  background: var(--ac-accent);
  color: var(--ac-user-text);
  border-bottom-right-radius: 4px;
}

.ac-msg-animate {
  animation: ac-fade-up .22s ease-out both;
}

@keyframes ac-fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Typing indicator ────────────────────────────────────────────────────────── */
.ac-typing-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 8px;
}

.ac-typing-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  height: 20px;
}

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

.ac-typing-dots span:nth-child(2) { animation-delay: .15s; }
.ac-typing-dots span:nth-child(3) { animation-delay: .30s; }

@keyframes ac-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* ── System messages ─────────────────────────────────────────────────────────── */
.ac-system-msg {
  text-align: center; margin: 6px 0;
  font-size: 11px; color: #64748B;
  background: #F8FAFC; border: 1px solid #E2E8F0;
  border-radius: 20px; padding: 4px 12px;
  display: inline-block; width: auto; max-width: 90%; margin-left: auto; margin-right: auto;
}

/* ── Handoff banner ──────────────────────────────────────────────────────────── */
.ac-handoff-banner {
  margin: 0 12px 8px;
  background: #FEF3C7; border: 1px solid #FCD34D;
  border-radius: 10px; padding: 10px 14px;
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: #92400E;
  animation: ac-fade-up .25s ease-out both;
}
.ac-handoff-cta {
  margin-left: auto; background: #D97706; color: white;
  border: none; border-radius: 7px; padding: 6px 12px;
  font-size: 12px; font-weight: 700; cursor: pointer;
  font-family: var(--ac-font); white-space: nowrap;
  transition: background .15s;
}
.ac-handoff-cta:hover { background: #B45309; }

/* ── Sources ──────────────────────────────────────────────────────────────────── */
.ac-sources {
  font-size: 11px;
  color: var(--ac-text-muted);
  margin-left: 36px;
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.ac-sources-label { font-weight: 500; }

.ac-source-link {
  color: var(--ac-accent);
  text-decoration: none;
}

.ac-source-link:hover { text-decoration: underline; }

/* ── Quick replies ────────────────────────────────────────────────────────────── */
.ac-quick-replies {
  padding: 6px 14px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ac-qr-btn {
  background: var(--ac-accent-light);
  border: 1px solid #BFDBFE;
  color: var(--ac-accent);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  font-family: var(--ac-font);
  white-space: nowrap;
}

.ac-qr-btn:hover {
  background: #DBEAFE;
  border-color: var(--ac-accent);
  transform: translateY(-1px);
}

/* ── Footer ───────────────────────────────────────────────────────────────────── */
.ac-footer {
  border-top: 1px solid var(--ac-border);
  padding: 10px 14px 10px;
  flex-shrink: 0;
}

.ac-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.ac-input {
  flex: 1;
  border: 1.5px solid var(--ac-border);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: var(--ac-font);
  color: var(--ac-text);
  background: var(--ac-bg);
  resize: none;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  max-height: 120px;
  line-height: 1.45;
}

.ac-input:focus {
  border-color: var(--ac-accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.ac-input:disabled {
  background: var(--ac-bot-bg);
  color: var(--ac-text-muted);
}

.ac-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--ac-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}

.ac-send-btn:hover   { background: #1D4ED8; transform: scale(1.06); }
.ac-send-btn:disabled { background: var(--ac-border); cursor: not-allowed; transform: none; }
.ac-send-btn svg     { width: 16px; height: 16px; color: white; }

.ac-footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

.ac-powered {
  font-size: 10px;
  color: var(--ac-text-muted);
  opacity: .6;
}

.ac-handoff-link {
  background: none;
  border: none;
  color: var(--ac-accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--ac-font);
  padding: 0;
  text-decoration: underline;
  transition: opacity .15s;
}

.ac-handoff-link:hover { opacity: .8; }

/* ── Buttons ──────────────────────────────────────────────────────────────────── */
.ac-btn {
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--ac-font);
  border: none;
  transition: transform .1s, opacity .15s;
  width: 100%;
}

.ac-btn:hover { transform: translateY(-1px); }

.ac-btn-primary {
  background: var(--ac-accent);
  color: white;
}

.ac-btn-ghost {
  background: transparent;
  color: var(--ac-text-muted);
  text-decoration: underline;
}

/* ── CSAT ────────────────────────────────────────────────────────────────────── */
.ac-csat {
  text-align: center;
  padding: 14px 10px;
  background: var(--ac-accent-light);
  border-radius: 12px;
  margin-bottom: 8px;
}

.ac-csat p {
  font-size: 13px;
  color: var(--ac-text);
  margin: 0 0 10px;
  font-weight: 500;
}

.ac-stars {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.ac-star-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  transition: transform .1s;
  padding: 2px;
}

.ac-star-btn:hover { transform: scale(1.3); }

/* ── Responsive (mobile) ──────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #afina-chatbot-root {
    bottom: 0;
    right: 0;
    left: 0;
  }

  .ac-bubble {
    bottom: 16px;
    right: 16px;
    position: fixed;
  }

  .ac-window {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    bottom: 0;
    right: 0;
    border-radius: 0;
    transform: translateY(100%);
  }

  .ac-window.ac-open {
    transform: translateY(0);
  }
}
