/* AI Lead Chat Widget */
:root {
  --ailc-primary:   #1a7fe8;
  --ailc-secondary: #0d5cb8;
  --ailc-radius:    16px;
  --ailc-shadow:    0 8px 32px rgba(0,0,0,.18);
  --ailc-font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#ailc-container * { box-sizing: border-box !important; font-family: var(--ailc-font) !important; }
/* Messages area — these divs must NEVER have theme padding/margin */
#ailc-messages > div { margin: 0 !important; padding: 0 !important; border: none !important; background: none !important; list-style: none !important; }



/* ── Window ─────────────────────────────────────────────────────────────── */
#ailc-window {
  display: none;
  flex-direction: column !important;
  width: 360px !important;
  height: 520px;
  max-height: 80vh;
  max-width: calc(100vw - 32px) !important;
  background: #fff !important;
  border-radius: var(--ailc-radius) !important;
  box-shadow: var(--ailc-shadow) !important;
  overflow: hidden !important;
  margin-bottom: 16px !important;
  opacity: 0;
  transform: translateY(20px) scale(.95);
  transition: opacity .25s ease, transform .25s ease;
  padding: 0 !important;
  box-sizing: border-box !important;
}
#ailc-window.ailc-open {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ── Header ─────────────────────────────────────────────────────────────── */
#ailc-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--ailc-primary), var(--ailc-secondary));
  color: #fff;
  flex-shrink: 0;
}
.ailc-bot-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.5);
  object-fit: cover;
  flex-shrink: 0;
}
.ailc-avatar-default {
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.25);
  font-size: 18px; font-weight: 700; color: #fff;
}
.ailc-head-info { flex: 1; }
.ailc-head-name { font-weight: 700; font-size: 15px; }
.ailc-head-status { font-size: 12px; opacity: .85; display: flex; align-items: center; gap: 5px; margin-top: 2px; }
.ailc-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #4ade80;
  box-shadow: 0 0 0 2px rgba(74,222,128,.3);
  animation: ailc-pulse 2s infinite;
}
@keyframes ailc-pulse {
  0%,100% { box-shadow: 0 0 0 2px rgba(74,222,128,.3); }
  50%      { box-shadow: 0 0 0 5px rgba(74,222,128,.1); }
}
#ailc-close {
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,.8); font-size: 18px; line-height: 1;
  padding: 4px; border-radius: 50%;
  transition: background .15s, color .15s;
}
#ailc-close:hover { background: rgba(255,255,255,.2); color: #fff; }

/* ── Messages ───────────────────────────────────────────────────────────── */
#ailc-messages {
  flex: 1 1 auto !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding: 16px 14px !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 10px !important;
  background: #f8f9fd !important;
  scroll-behavior: smooth !important;
  box-sizing: border-box !important;
  min-height: 0 !important;
  list-style: none !important;
}
/* ── Elementor + Divi + Astra isolation — targeted resets only ─────────── */
/* NEVER use all:initial — it resets position:fixed and breaks the widget  */

/* Reinforce the container's positioning — prevent ANY theme from moving it */
#ailc-container {
  position: fixed !important;
  bottom: 24px !important;
  z-index: 999999 !important;
  display: inline-block !important;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  background: none !important;
  border: none !important;
  float: none !important;
  transform: none !important;
  max-width: none !important;
}
#ailc-container.ailc-right { right: 24px !important; left: auto !important; }
#ailc-container.ailc-left  { left: 24px !important; right: auto !important; }

/* Prevent Elementor/Astra/Divi from stretching internal elements */
.elementor #ailc-container *,
.elementor-widget #ailc-container *,
.et_pb_section #ailc-container *,
.et_builder_inner_content #ailc-container *,
.ast-container #ailc-container *,
.site-content #ailc-container * {
  box-sizing: border-box !important;
  float: none !important;
}

/* Reset any .ailc-msg div so theme margins/padding can't break layout */
#ailc-container .ailc-msg {
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  background: none !important;
  list-style: none !important;
}
#ailc-messages::-webkit-scrollbar { width: 4px; }
#ailc-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

.ailc-msg {
  display: flex !important;
  width: 100% !important;
  max-width: 100% !important;
  gap: 7px !important;
  align-items: flex-end !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  background: none !important;
  list-style: none !important;
}
.ailc-msg-bot  { justify-content: flex-start !important; }
.ailc-msg-user { justify-content: flex-end !important; }

.ailc-message-stack {
  display: flex !important;
  flex-direction: column !important;
  max-width: min(82%, 300px) !important;
  min-width: 0 !important;
}
.ailc-msg-bot .ailc-message-stack  { align-items: flex-start !important; }
.ailc-msg-user .ailc-message-stack { align-items: flex-end !important; }

.ailc-msg-label {
  margin: 0 8px 3px !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  color: #6b7280 !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  line-height: 1.2 !important;
  max-width: 100% !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}
.ailc-msg-user .ailc-msg-label { color: var(--ailc-primary) !important; }

.ailc-msg-avatar {
  width: 24px !important;
  height: 24px !important;
  min-width: 24px !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: var(--ailc-primary) !important;
  color: #fff !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  line-height: 1 !important;
  box-shadow: 0 1px 3px rgba(0,0,0,.12) !important;
  overflow: hidden !important;
  flex: 0 0 24px !important;
}
.ailc-msg-avatar img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  display: block !important;
}

.ailc-bubble {
  position: relative !important;
  padding: 10px 14px !important;
  border-radius: 18px !important;
  font-size: 14px !important;
  line-height: 1.5 !important;
  word-break: normal !important;
  overflow-wrap: anywhere !important;
  white-space: pre-wrap !important;
  box-sizing: border-box !important;
  display: inline-block !important;
  width: auto !important;
  min-width: 0 !important;
  max-width: 100% !important;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
  margin: 0 !important;
}
.ailc-bubble::after {
  content: '' !important;
  position: absolute !important;
  bottom: 0 !important;
  width: 10px !important;
  height: 10px !important;
  background: inherit !important;
}
.ailc-bubble-bot {
  background: #fff !important;
  color: #1f2937 !important;
  border-bottom-left-radius: 5px !important;
  box-shadow: 0 1px 4px rgba(0,0,0,.08) !important;
}
.ailc-bubble-bot::after {
  left: -4px !important;
  clip-path: polygon(100% 0, 0 100%, 100% 100%) !important;
}
.ailc-bubble-user {
  background: var(--ailc-primary) !important;
  color: #fff !important;
  border-bottom-right-radius: 5px !important;
}
.ailc-bubble-user::after {
  right: -4px !important;
  clip-path: polygon(0 0, 0 100%, 100% 100%) !important;
}

/* typing indicator */
.ailc-typing { display: flex; align-items: center; gap: 4px; padding: 12px 16px; }
.ailc-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: #9ca3af;
  animation: ailc-blink 1.2s infinite;
}
.ailc-typing span:nth-child(2) { animation-delay: .2s; }
.ailc-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes ailc-blink {
  0%,80%,100% { opacity: .3; transform: scale(1); }
  40%          { opacity: 1;  transform: scale(1.3); }
}

/* quick replies */
#ailc-container .ailc-quick-replies {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 8px !important;
  margin-top: 6px !important;
  padding: 0 !important;
}
#ailc-container .ailc-quick-btn {
  all: unset !important;
  display: inline-block !important;
  padding: 10px 18px !important;
  border: 1.5px solid var(--ailc-primary) !important;
  background: transparent !important;
  color: var(--ailc-primary) !important;
  border-radius: 24px !important;
  font-size: 13px !important;
  font-family: var(--ailc-font) !important;
  font-weight: 500 !important;
  line-height: 1.4 !important;
  cursor: pointer !important;
  transition: background .15s, color .15s !important;
  white-space: normal !important;
  word-break: break-word !important;
  box-sizing: border-box !important;
  text-align: left !important;
}
#ailc-container .ailc-quick-btn:hover,
#ailc-container .ailc-quick-btn:focus {
  background: var(--ailc-primary) !important;
  color: #fff !important;
  outline: none !important;
}

/* ── Privacy ────────────────────────────────────────────────────────────── */
#ailc-privacy {
  padding: 6px 14px;
  font-size: 11px;
  color: #9ca3af;
  text-align: center;
  background: #f8f9fd;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
  margin-top: 10px;
}

/* ── Footer / Input ─────────────────────────────────────────────────────── */
#ailc-foot {
  padding: 10px 12px 8px;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
}
#ailc-input-wrap { position: relative !important; display: block !important; padding-right: 48px !important; }
#ailc-input {
  width: 100% !important; display: block !important;
  border: 1.5px solid #e5e7eb !important; border-radius: 24px !important;
  padding: 9px 48px 9px 16px !important; font-size: 14px !important; outline: none !important;
  transition: border-color .15s !important;
  background: #f9fafb !important;
  box-sizing: border-box !important;
}
#ailc-input:focus { border-color: var(--ailc-primary); background: #fff; }
#ailc-input:disabled { opacity: .6; cursor: not-allowed; }
#ailc-send {
  position: absolute !important;
  top: 50% !important; right: 5px !important;
  transform: translateY(-50%) !important;
  width: 38px !important; height: 38px !important;
  min-width: 38px !important; min-height: 38px !important;
  max-width: 38px !important; max-height: 38px !important;
  border-radius: 50% !important;
  background: var(--ailc-primary) !important;
  border: none !important; cursor: pointer !important;
  display: flex !important; align-items: center !important; justify-content: center !important;
  transition: background .15s !important;
  padding: 0 !important; margin: 0 !important;
  box-shadow: none !important; line-height: 1 !important;
  overflow: hidden !important; z-index: 1 !important;
}
#ailc-send:hover { background: var(--ailc-secondary) !important; transform: scale(1.05); }
#ailc-send[data-disabled] { opacity: .5 !important; cursor: not-allowed !important; }
#ailc-send svg { width: 18px !important; height: 18px !important; fill: #fff !important; display: block !important; flex-shrink: 0 !important; pointer-events: none !important; }

#ailc-branding { text-align: center; font-size: 10px; color: #d1d5db; margin-top: 5px; }
#ailc-branding strong { color: #9ca3af; }
#ailc-branding a { color: inherit; text-decoration: none; }
#ailc-branding a:hover { color: #6b7280; }

/* ── Bubble button ──────────────────────────────────────────────────────── */
#ailc-bubble {
  width: 58px; height: 58px; border-radius: 50%;
  background: linear-gradient(135deg, var(--ailc-primary), var(--ailc-secondary));
  border: none; cursor: pointer;
  box-shadow: 0 4px 20px rgba(99,102,241,.5);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: transform .2s, box-shadow .2s;
}
#ailc-bubble:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(99,102,241,.6); }
.ailc-bubble-icon { display: flex; }
.ailc-bubble-icon svg { width: 26px; height: 26px; fill: #fff; }

#ailc-badge {
  position: absolute; top: -2px; right: -2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #ef4444; color: #fff;
  font-size: 11px; font-weight: 700;
  display: none; align-items: center; justify-content: center;
  border: 2px solid #fff;
  animation: ailc-pop .3s ease;
}
@keyframes ailc-pop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* bounce animation */
@keyframes ailc-bounce {
  0%,100% { transform: scale(1); }
  30%     { transform: scale(1.15); }
  60%     { transform: scale(.95); }
}
#ailc-bubble.ailc-bounce { animation: ailc-bounce .6s ease; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #ailc-container {
    bottom: 12px !important;
    max-width: calc(100vw - 24px) !important;
  }
  #ailc-container.ailc-right { right: 12px !important; left: auto !important; }
  #ailc-container.ailc-left  { left:  12px !important; right: auto !important; }
  #ailc-window {
    width: calc(100vw - 24px) !important;
    height: min(520px, calc(100dvh - 92px)) !important;
    max-height: calc(100dvh - 92px) !important;
    margin-bottom: 12px !important;
  }
  #ailc-head { padding: 12px 14px !important; }
  #ailc-messages { padding: 14px 12px !important; }
  .ailc-message-stack { max-width: 84% !important; }
  .ailc-msg-avatar { width: 22px !important; height: 22px !important; min-width: 22px !important; flex-basis: 22px !important; }
  .ailc-bubble { font-size: 13.5px !important; line-height: 1.45 !important; }
}

@media (max-width: 360px) {
  .ailc-message-stack { max-width: 86% !important; }
  #ailc-foot { padding: 9px 10px 7px !important; }
}

/* ── GDPR Consent ───────────────────────────────────────────────────────── */
#ailc-consent-bar {
  padding: 14px 16px;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
}
#ailc-consent-bar p {
  font-size: 12px;
  color: #374151;
  margin-bottom: 10px;
  line-height: 1.5;
}
#ailc-consent-bar a { color: var(--ailc-primary); }
#ailc-consent-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: #374151;
  cursor: pointer;
  line-height: 1.5;
  margin-bottom: 10px;
}
#ailc-consent-label input[type=checkbox] {
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--ailc-primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}
#ailc-consent-accept {
  width: 100%;
  padding: 9px;
  background: var(--ailc-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
#ailc-consent-accept:disabled {
  opacity: .45;
  cursor: not-allowed;
}
#ailc-consent-accept:not(:disabled):hover { background: var(--ailc-secondary); }
