/* AI Chat Widget — EarlyMortgagePayoff.com */

#chat-toggle {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9999;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--gradient-btn);
  color: var(--text-white);
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(123, 92, 240, 0.45), 0 0 32px var(--accent-glow);
  transition: transform 200ms ease;
}
#chat-toggle:hover { transform: scale(1.06); }
#chat-toggle i { font-size: 1.35rem; }
#chat-toggle .chat-badge {
  position: absolute;
  top: 4px; right: 4px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--bg-dark);
  display: none;
}
#chat-toggle.has-unread .chat-badge { display: block; }
#chat-toggle .icon-close { display: none; }
#chat-toggle.is-open .icon-open { display: none; }
#chat-toggle.is-open .icon-close { display: inline; }

#chat-panel {
  position: fixed;
  right: 24px;
  bottom: 96px;
  z-index: 9998;
  width: 380px;
  height: 540px;
  max-height: calc(100vh - 120px);
  background: var(--bg-dark-2);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55), 0 0 40px rgba(123, 92, 240, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.95) translateY(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease, transform 250ms ease;
}
#chat-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1) translateY(0);
}

@media (max-width: 540px) {
  #chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 84px;
    height: calc(100vh - 110px);
  }
  #chat-toggle { right: 16px; bottom: 16px; }
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  height: 60px;
  border-bottom: 1px solid var(--border-dark);
  background: var(--bg-card-dark);
  flex-shrink: 0;
}
.chat-header-left { display: flex; align-items: center; gap: 10px; }
.chat-header-info { display: flex; flex-direction: column; gap: 2px; line-height: 1.2; }
.chat-header-info .name { color: var(--text-white); font-size: 0.92rem; font-weight: 500; }
.chat-header-info .status { color: var(--text-muted); font-size: 0.72rem; display: inline-flex; align-items: center; gap: 6px; }
.chat-header-info .status::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s ease-in-out infinite;
}
.chat-header-actions { display: flex; gap: 4px; }
.chat-header-actions button {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 200ms ease, color 200ms ease;
}
.chat-header-actions button:hover { background: rgba(255,255,255,0.06); color: var(--text-white); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 3px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

.chat-msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; animation: msgIn 240ms ease; }
.chat-msg.user { justify-content: flex-end; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg .avatar {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--gradient-btn);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--text-white);
  letter-spacing: 0.04em;
  box-shadow: 0 0 12px var(--accent-glow);
}
.chat-bubble {
  padding: 10px 14px;
  font-size: 0.92rem;
  line-height: 1.5;
  border-radius: 18px 18px 18px 4px;
  word-wrap: break-word;
  max-width: 78%;
}
.chat-msg.user .chat-bubble {
  background: var(--gradient-btn);
  color: var(--text-white);
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 4px 16px rgba(123, 92, 240, 0.25);
}
.chat-msg.assistant .chat-bubble {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-dark);
  color: var(--text-light);
}
.chat-bubble a { color: var(--accent-2); text-decoration: underline; text-underline-offset: 2px; }
.chat-bubble strong { color: var(--text-white); }
.chat-bubble ul { margin: 6px 0 6px 18px; padding: 0; }
.chat-bubble li { margin-bottom: 2px; }

.chat-time {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-muted);
  margin-top: 4px;
  letter-spacing: 0.04em;
}

.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-dark);
  border-radius: 18px 18px 18px 4px;
}
.chat-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-2);
  animation: typing 1.4s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

.chat-prompts {
  display: flex;
  gap: 8px;
  padding: 8px 12px 4px;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
.chat-prompts::-webkit-scrollbar { display: none; }
.chat-prompts button {
  flex-shrink: 0;
  background: var(--bg-card-dark);
  border: 1px solid var(--border-dark);
  color: var(--text-light);
  font-size: 0.78rem;
  padding: 6px 12px;
  border-radius: 100px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 200ms ease, color 200ms ease, background 200ms ease;
  font-family: var(--font-body);
}
.chat-prompts button:hover { border-color: var(--accent); color: var(--text-white); background: rgba(123, 92, 240, 0.1); }

.chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border-dark);
  flex-shrink: 0;
  background: var(--bg-dark-2);
}
.chat-input {
  flex: 1;
  background: var(--bg-card-dark);
  border: 1px solid var(--border-dark);
  border-radius: 18px;
  padding: 10px 14px;
  color: var(--text-white);
  font-size: 0.92rem;
  resize: none;
  outline: none;
  font-family: var(--font-body);
  line-height: 1.4;
  max-height: 90px;
  min-height: 40px;
}
.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-muted); }

.chat-send {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--gradient-btn);
  border: 0;
  color: var(--text-white);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 150ms ease, opacity 200ms ease;
}
.chat-send:hover:not(:disabled) { transform: scale(1.05); }
.chat-send:disabled { background: rgba(255,255,255,0.08); cursor: not-allowed; opacity: 0.5; }

.chat-rate-warning {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 8px;
}

/* Lead capture inline (after 3 messages) */
.chat-lead {
  background: rgba(123, 92, 240, 0.1);
  border: 1px solid rgba(123, 92, 240, 0.25);
  border-radius: var(--radius-md);
  padding: 12px;
  margin: 8px 0;
}
.chat-lead p { margin: 0 0 8px; color: var(--text-light); font-size: 0.85rem; }
.chat-lead form { display: flex; gap: 6px; }
.chat-lead input { flex: 1; padding: 8px 12px; border-radius: 100px; background: var(--bg-dark-2); border: 1px solid var(--border-dark); color: var(--text-white); font-size: 0.85rem; outline: none; }
.chat-lead input:focus { border-color: var(--accent); }
.chat-lead button { padding: 8px 14px; border-radius: 100px; border: 0; background: var(--gradient-btn); color: var(--text-white); font-size: 0.82rem; cursor: pointer; }
