/* ============================================
   AI Agent Chatbot — Chat Widget Styles
   ============================================ */

:root {
  --aiac-accent:        #6366f1;
  --aiac-accent-dark:   #4f46e5;
  --aiac-accent-light:  #eef2ff;
  --aiac-text:          #1e1e2e;
  --aiac-muted:         #6b7280;
  --aiac-bg:            #ffffff;
  --aiac-surface:       #f9fafb;
  --aiac-border:        #e5e7eb;
  --aiac-radius:        16px;
  --aiac-shadow:        0 20px 60px rgba(0,0,0,.18), 0 4px 16px rgba(0,0,0,.08);
  --aiac-launcher-size: 60px;
}

/* ── ROOT WRAPPER ── */
#aiac-root {
  position: fixed;
  bottom: 24px;
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
#aiac-root[data-position="right"] { right: 24px; }
#aiac-root[data-position="left"]  { left:  24px; }

/* ── LAUNCHER ── */
#aiac-launcher {
  width:  var(--aiac-launcher-size);
  height: var(--aiac-launcher-size);
  border-radius: 50%;
  background: var(--aiac-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 6px 24px rgba(99,102,241,.45);
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .2s;
  position: relative;
  outline: none;
}
#aiac-launcher:hover  { transform: scale(1.1); box-shadow: 0 8px 32px rgba(99,102,241,.55); }
#aiac-launcher:active { transform: scale(.96); }

.aiac-badge {
  position: absolute;
  top: -3px; right: -3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

/* ── POPUP WINDOW ── */
#aiac-popup {
  position: absolute;
  bottom: calc(var(--aiac-launcher-size) + 12px);
  width: 370px;
  max-width: calc(100vw - 48px);
  background: var(--aiac-bg);
  border-radius: var(--aiac-radius);
  box-shadow: var(--aiac-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--aiac-border);
  animation: aiacSlideUp .28s cubic-bezier(.22,1,.36,1);
  transition: width 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
#aiac-popup.aiac-expanded {
  width: 750px !important;
  max-width: calc(100vw - 48px) !important;
}
#aiac-popup.aiac-expanded .aiac-messages {
  max-height: 480px !important;
  min-height: 380px !important;
}
#aiac-popup.aiac-expanded iframe {
  height: 480px !important;
}
#aiac-root[data-position="right"] #aiac-popup { right: 0; }
#aiac-root[data-position="left"]  #aiac-popup { left:  0; }

@keyframes aiacSlideUp {
  from { opacity: 0; transform: translateY(16px) scale(.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* ── HEADER ── */
.aiac-popup-header {
  background: var(--aiac-accent);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.aiac-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.aiac-header-info { flex: 1; }
.aiac-bot-name  { display: block; font-weight: 700; font-size: 15px; }
.aiac-status    { display: flex; align-items: center; gap: 5px; font-size: 12px; opacity: .85; }
.aiac-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #4ade80;
  animation: aiacPulse 2s infinite;
}
@keyframes aiacPulse {
  0%,100% { opacity: 1; }
  50%      { opacity: .4; }
}
.aiac-close-btn {
  background: none; border: none;
  color: #fff; cursor: pointer;
  opacity: .8; padding: 4px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, background .15s;
}
.aiac-expand-btn {
  background: none; border: none;
  color: #fff; cursor: pointer;
  opacity: .8; padding: 4px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, background .15s;
  margin-right: 4px;
}
.aiac-close-btn:hover,
.aiac-expand-btn:hover,
.aiac-new-chat-btn:hover { opacity: 1; background: rgba(255,255,255,.15); }
.aiac-new-chat-btn {
  background: none; border: none;
  color: #fff; cursor: pointer;
  opacity: .8; padding: 4px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, background .15s;
}

/* ── MESSAGES ── */
.aiac-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 280px;
  max-height: 340px;
  scroll-behavior: smooth;
}
.aiac-messages::-webkit-scrollbar { width: 4px; }
.aiac-messages::-webkit-scrollbar-track { background: transparent; }
.aiac-messages::-webkit-scrollbar-thumb { background: var(--aiac-border); border-radius: 4px; }

/* Bubbles */
.aiac-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  animation: aiacFadeIn .2s ease;
}
@keyframes aiacFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.aiac-msg-bot {
  background: var(--aiac-surface);
  color: var(--aiac-text);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  border: 1px solid var(--aiac-border);
}
.aiac-msg-user {
  background: var(--aiac-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}
.aiac-msg-error {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  align-self: flex-start;
}

/* Typing indicator */
.aiac-typing {
  display: flex; gap: 5px;
  align-items: center;
  padding: 12px 16px;
  background: var(--aiac-surface);
  border: 1px solid var(--aiac-border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  width: fit-content;
}
.aiac-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--aiac-accent);
  animation: aiacBounce 1.1s infinite;
}
.aiac-typing span:nth-child(2) { animation-delay: .18s; }
.aiac-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes aiacBounce {
  0%,60%,100% { transform: translateY(0); }
  30%          { transform: translateY(-6px); }
}

/* ── CTA FORM ── */
.aiac-cta-form {
  background: linear-gradient(135deg, var(--aiac-accent-light) 0%, #f0f0ff 100%);
  border-top: 1px solid var(--aiac-border);
  padding: 20px 18px;
  flex-shrink: 0;
  max-height: 420px;
  overflow-y: auto;
}
.aiac-cta-inner { text-align: center; }
.aiac-cta-icon  { font-size: 32px; margin-bottom: 8px; }
.aiac-cta-form h3 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
  color: var(--aiac-text);
}
.aiac-cta-form p {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--aiac-muted);
}
.aiac-form-fields {
  display: flex; flex-direction: column; gap: 8px;
  text-align: left;
}
.aiac-form-fields input,
.aiac-form-fields select,
.aiac-form-fields textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--aiac-border);
  border-radius: 9px;
  font-size: 13px;
  background: #fff;
  color: var(--aiac-text);
  transition: border-color .15s;
  box-sizing: border-box;
  font-family: inherit;
  resize: none;
}
.aiac-form-fields input:focus,
.aiac-form-fields select:focus,
.aiac-form-fields textarea:focus {
  outline: none;
  border-color: var(--aiac-accent);
  box-shadow: 0 0 0 3px var(--aiac-accent-light);
}
.aiac-form-actions {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 12px;
}
.aiac-btn-primary {
  width: 100%;
  padding: 11px;
  border-radius: 10px;
  border: none;
  background: var(--aiac-accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.aiac-btn-primary:hover { background: var(--aiac-accent-dark); transform: translateY(-1px); }
.aiac-btn-outline {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1.5px solid var(--aiac-accent);
  background: transparent;
  color: var(--aiac-accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: block;
  text-align: center;
  transition: background .15s;
}
.aiac-btn-outline:hover { background: var(--aiac-accent-light); }
.aiac-skip {
  background: none; border: none;
  color: var(--aiac-muted);
  font-size: 12px;
  cursor: pointer;
  margin-top: 10px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.aiac-skip:hover { color: var(--aiac-text); }

/* ── INPUT BAR ── */
.aiac-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--aiac-border);
  background: var(--aiac-bg);
}
#aiac-input {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--aiac-border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13.5px;
  line-height: 1.5;
  max-height: 100px;
  overflow-y: auto;
  font-family: inherit;
  color: var(--aiac-text);
  background: var(--aiac-surface);
  transition: border-color .15s;
}
#aiac-input:focus {
  outline: none;
  border-color: var(--aiac-accent);
  background: #fff;
}
#aiac-send {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--aiac-accent);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
#aiac-send:hover  { background: var(--aiac-accent-dark); }
#aiac-send:active { transform: scale(.92); }
#aiac-send:disabled { background: var(--aiac-border); cursor: not-allowed; }

.aiac-powered {
  text-align: center;
  font-size: 10.5px;
  color: var(--aiac-muted);
  margin: 0;
  padding: 4px 0 8px;
  border-top: 1px solid var(--aiac-border);
  background: var(--aiac-bg);
}

/* Success message after lead submit */
.aiac-success {
  text-align: center;
  padding: 24px 18px;
}
.aiac-success .aiac-success-icon { font-size: 40px; margin-bottom: 10px; }
.aiac-success h3 { margin: 0 0 6px; font-size: 16px; font-weight: 700; }
.aiac-success p  { margin: 0; font-size: 13px; color: var(--aiac-muted); }

/* ── MOBILE ── */
@media (max-width: 480px) {
  #aiac-root { bottom: 16px; }
  #aiac-root[data-position="right"] { right: 16px; }
  #aiac-root[data-position="left"]  { left:  16px; }
  #aiac-popup {
    width:  calc(100vw - 32px);
    bottom: calc(var(--aiac-launcher-size) + 8px);
  }
  /* Expanded mode = full screen on mobile */
  #aiac-popup.aiac-expanded {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    border-radius: 0 !important;
    z-index: 1000000;
  }
  #aiac-popup.aiac-expanded .aiac-messages {
    max-height: none !important;
    min-height: 0 !important;
    flex: 1 !important;
  }
}
