/* ============================================================================
   AI chat widget — reuses the site's existing design tokens (see style.css)
   so it looks like a native part of the site rather than a bolted-on tool.
   ============================================================================ */

.chatbot-launcher {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 60;
  height: 3.5rem;
  padding: 0 1.25rem;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: linear-gradient(135deg, var(--electric-500), var(--turquoise-500));
  color: #fff;
  box-shadow: 0 10px 30px rgba(52, 104, 224, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease, width 0.15s ease, padding 0.15s ease;
}

.chatbot-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 36px rgba(52, 104, 224, 0.42);
}

.chatbot-launcher svg {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
}

.chatbot-launcher-label {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
}

.chatbot-launcher .chatbot-launcher-icon--close {
  display: none;
}

/* Once the panel is open, the label/chat-icon give way to a plain circular
   close button — the "Agent" text is only there to grab attention while
   the widget is idle, not useful once the visitor is already chatting. */
.chatbot-widget.is-open .chatbot-launcher {
  width: 3.5rem;
  padding: 0;
}

.chatbot-widget.is-open .chatbot-launcher .chatbot-launcher-icon--chat,
.chatbot-widget.is-open .chatbot-launcher .chatbot-launcher-label {
  display: none;
}

.chatbot-widget.is-open .chatbot-launcher .chatbot-launcher-icon--close {
  display: block;
}

/* Keep clear of the mobile floating "Schedule a Free Consultation" bar. */
@media (max-width: 1023px) {
  .chatbot-launcher {
    bottom: 5.75rem;
  }
}

.chatbot-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 5.25rem;
  z-index: 60;
  width: min(23rem, calc(100vw - 2.5rem));
  height: min(32rem, calc(100vh - 8rem));
  background: #fff;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(10, 18, 38, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(0.75rem) scale(0.98);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

@media (max-width: 1023px) {
  .chatbot-panel {
    bottom: 9.75rem;
  }
}

/* Applied by chatbot.js on mobile whenever the on-screen keyboard is open —
   see updatePanelForViewport() there for why bottom/height alone (even with
   dvh) aren't reliable enough on iOS Safari once the keyboard is involved.
   --kb-top / --kb-height are set inline in px, computed from the actual
   window.visualViewport, so the whole panel — header included — always
   stays within the real visible area instead of scrolling off above it. */
.chatbot-panel.is-keyboard-adjusted {
  top: var(--kb-top);
  bottom: auto;
  height: var(--kb-height);
}

.chatbot-widget.is-open .chatbot-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.chatbot-header {
  background: var(--navy-900);
  color: #fff;
  padding: 0.9rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.chatbot-header-avatar {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--electric-400), var(--turquoise-400));
  flex-shrink: 0;
}

.chatbot-header-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.2;
}

.chatbot-header-subtitle {
  font-size: 0.75rem;
  color: var(--electric-300);
  margin-top: 0.1rem;
}

.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--mist-50);
}

.chatbot-msg {
  max-width: 85%;
  padding: 0.55rem 0.8rem;
  border-radius: 0.9rem;
  font-size: 0.85rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.chatbot-msg--assistant {
  align-self: flex-start;
  background: #fff;
  color: var(--navy-900);
  border: 1px solid var(--mist-200);
  border-bottom-left-radius: 0.25rem;
}

.chatbot-msg--user {
  align-self: flex-end;
  background: linear-gradient(90deg, var(--electric-500), var(--turquoise-500));
  color: #fff;
  border-bottom-right-radius: 0.25rem;
}

.chatbot-msg--error {
  align-self: center;
  background: #fef2f2;
  color: #b42318;
  border: 1px solid #fecaca;
  font-size: 0.78rem;
}

.chatbot-typing {
  align-self: flex-start;
  display: flex;
  gap: 0.25rem;
  padding: 0.6rem 0.85rem;
  background: #fff;
  border: 1px solid var(--mist-200);
  border-radius: 0.9rem;
  border-bottom-left-radius: 0.25rem;
}

.chatbot-typing span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: var(--radius-full);
  background: var(--navy-600);
  opacity: 0.4;
  animation: chatbot-bounce 1.1s infinite ease-in-out;
}

.chatbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatbot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-0.2rem); opacity: 1; }
}

.chatbot-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.7rem;
  border-top: 1px solid var(--mist-200);
  background: #fff;
}

.chatbot-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--mist-200);
  border-radius: 0.9rem;
  padding: 0.55rem 0.8rem;
  font-family: var(--font-sans);
  /* Must stay >= 16px: any focusable input under that triggers iOS Safari's
     auto-zoom-to-legibility on tap, which — combined with .chatbot-panel
     being position:fixed and sized off viewport units — left the panel
     visibly cropped after the zoom (reported on mobile, 2026-09-10). */
  font-size: 1rem;
  max-height: 5rem;
  color: var(--navy-900);
}

.chatbot-input:focus {
  outline: none;
  border-color: var(--electric-400);
}

.chatbot-send {
  flex-shrink: 0;
  width: 2.3rem;
  height: 2.3rem;
  border-radius: var(--radius-full);
  border: none;
  background: linear-gradient(135deg, var(--electric-500), var(--turquoise-500));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease;
}

.chatbot-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chatbot-send svg {
  width: 1.05rem;
  height: 1.05rem;
}

.chatbot-footer-note {
  font-size: 0.68rem;
  color: #94a3b8;
  text-align: center;
  padding: 0.4rem 0.7rem 0.65rem;
  background: #fff;
}

.chatbot-footer-note a {
  color: var(--electric-600);
}
