/* ============================================
   AI Agent Chatbot — Chat Widget Styles v1.2
   ============================================ */

: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 (launcher anchor)
══════════════════════════════════════════ */
#aiac-root {
  position: fixed;
  bottom: 24px;
  z-index: 999998;
  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 BUTTON
══════════════════════════════════════════ */
#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;
  z-index: 999999; /* always on top */
}
#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 — DESKTOP (default)
══════════════════════════════════════════ */
#aiac-popup {
  position: absolute;
  bottom: calc(var(--aiac-launcher-size) + 12px);
  width: 370px;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - var(--aiac-launcher-size) - 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;
  max-height: calc(100vh - var(--aiac-launcher-size) - 48px) !important;
}
#aiac-popup.aiac-expanded .aiac-messages {
  max-height: calc(100vh - var(--aiac-launcher-size) - 48px - 70px - 60px - 35px) !important;
  min-height: 120px !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;
  flex-shrink: 0; /* never compress */
}
.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 1 0%;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 120px;
  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 LEAD 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);
  flex-shrink: 0;
}
#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);
  flex-shrink: 0;
}

/* Success message */
.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 & TABLET  (≤ 768px)
   Full-screen popup — same UX as desktop
   but uses the whole screen
══════════════════════════════════════════ */
@media screen and (max-width: 768px) {

  /* Root anchor — stay at corner */
  #aiac-root {
    bottom: 16px;
    right: 16px;
    left: auto;
  }
  #aiac-root[data-position="left"] {
    left: 16px;
    right: auto;
  }


  /* === FULL-SCREEN POPUP === */
  /* Matches when popup is inside #aiac-root or teleported to <body> */
  #aiac-root #aiac-popup,
  body > #aiac-popup {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    z-index: 99990 !important;
    /* NOTE: display is NOT set here — JS controls show/hide */
    flex-direction: column !important;
    overflow: hidden !important;
    animation: none !important;
  }

  /* Header — pinned at top, never compressed */
  .aiac-popup-header {
    flex-shrink: 0 !important;
    border-radius: 0 !important;
    padding: 12px 16px !important;
  }

  /* Make all header buttons easy to tap (44px min touch target) */
  .aiac-close-btn,
  .aiac-new-chat-btn,
  .aiac-expand-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 10px !important;
  }


  /* Expand button hidden — already full screen */
  #aiac-expand-btn {
    display: none !important;
  }

  /* Messages — fill all remaining space */
  .aiac-messages {
    flex: 1 1 auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow-y: auto !important;
  }

  /* Input bar + footer — pinned at bottom */
  .aiac-input-bar { flex-shrink: 0 !important; }
  .aiac-powered   { flex-shrink: 0 !important; }

  /* CTA form scrollable within the full-screen popup */
  .aiac-cta-form {
    max-height: 50vh !important;
    overflow-y: auto !important;
  }

  /* Expanded = same as normal on mobile */
  #aiac-root #aiac-popup.aiac-expanded,
  body > #aiac-popup.aiac-expanded {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
  }
  #aiac-root #aiac-popup.aiac-expanded .aiac-messages,
  body > #aiac-popup.aiac-expanded .aiac-messages {
    max-height: none !important;
    flex: 1 1 auto !important;
  }
}

/* ══════════════════════════════════════════
   OPTION / ACTION BUTTONS
══════════════════════════════════════════ */
.aiac-options-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
  animation: aiacFadeIn .3s ease;
}
.aiac-option-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border: 2px solid var(--aiac-accent);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(99,102,241,.05) 0%, rgba(99,102,241,.12) 100%);
  color: var(--aiac-text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s ease;
  text-align: left;
  font-family: inherit;
}
.aiac-option-btn:hover {
  background: var(--aiac-accent);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99,102,241,.3);
}
.aiac-option-btn:active { transform: scale(.97); }
.aiac-option-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.aiac-action-options { gap: 6px; }
.aiac-action-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border: 2px solid #22d3ee;
  border-radius: 12px;
  background: linear-gradient(135deg, #ecfeff 0%, #f0f9ff 100%);
  color: #0e7490;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s ease;
  text-align: left;
  font-family: inherit;
}
.aiac-action-btn:hover {
  background: linear-gradient(135deg, #cffafe 0%, #e0f2fe 100%);
  border-color: #06b6d4;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(6,182,212,.25);
}
.aiac-action-btn:active { transform: scale(.97); }
.aiac-action-label { flex: 1; }
.aiac-action-icon {
  font-size: 18px;
  flex-shrink: 0;
  margin-left: 8px;
}

/* ══════════════════════════════════════════
   IN-CHAT LEAD FORM (v1.3)
══════════════════════════════════════════ */
.aiac-inline-form {
  align-self: stretch;
  max-width: 100% !important;
  width: 100%;
  box-sizing: border-box;
  background: #fff;
  border: 1.5px solid var(--aiac-border, #e5e7eb);
  border-top: 4px solid var(--aiac-accent);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,.06);
  animation: aiacFadeIn .3s ease;
}
.aiac-inline-form-head { margin-bottom: 12px; }
.aiac-inline-form-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--aiac-accent-light);
  color: var(--aiac-accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
}
.aiac-inline-form h4 {
  margin: 8px 0 4px;
  font-size: 15px;
  font-weight: 700;
  color: var(--aiac-text, #111827);
}
.aiac-inline-form p {
  margin: 0;
  font-size: 12.5px;
  color: var(--aiac-muted, #6b7280);
  line-height: 1.45;
}
.aiac-inline-form .aiac-form-fields .aiac-invalid {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239,68,68,.12);
}
.aiac-form-error {
  color: #dc2626;
  font-size: 12px;
  margin-top: 8px;
  min-height: 0;
}
.aiac-form-error:empty { display: none; }
.aiac-inline-form .aiac-form-actions { margin-top: 12px; }
.aiac-inline-form .aiac-btn-primary:disabled { opacity: .6; cursor: wait; transform: none; }
.aiac-inline-form .aiac-success { text-align: center; padding: 6px 0; }
.aiac-inline-form .aiac-success h3 { margin: 6px 0 4px; font-size: 16px; }

.aiac-inline-cta,
.aiac-followup-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  animation: aiacFadeIn .3s ease;
}
.aiac-inline-cta .aiac-btn-primary,
.aiac-followup-btns .aiac-btn-primary,
.aiac-followup-btns .aiac-btn-outline {
  width: auto;
  padding: 8px 16px;
  font-size: 13px;
  background-clip: padding-box;
}
.aiac-followup-btns .aiac-btn-outline { background: #fff; display: inline-flex; align-items: center; }

.cal-msg-container { width: 82%; max-width: 100%; }
.aiac-cal-frame {
  margin-top: 10px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}
.aiac-cal-frame iframe { width: 100%; height: 350px; border: 0; display: block; }
