/* Fisher Labs AI Assistant — floating chat widget */

.flai-root {
  position: fixed;
  z-index: 99999;
  /* The container is only a positioning anchor — never let it (or any empty
     space inside it) intercept clicks meant for the page. Only the actual
     launcher and panel opt back in, below. */
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  /* Fallbacks; overridden by an inline style from the theme accent. */
  --flai-accent: #0e686c;
  --flai-accent-strong: #0a5155;
  --flai-ink: #12162a;
  --flai-ink-soft: #5b6178;
  --flai-surface: #ffffff;
  --flai-surface-alt: #f5f7fb;
  --flai-border: #e4e7f0;
}

.flai-root.bottom-right { right: 24px; bottom: 24px; }
.flai-root.bottom-left  { left:  24px; bottom: 24px; }

.flai-root .flai-launcher,
.flai-root .flai-panel { pointer-events: auto; }

.flai-root .flai-launcher.flai-hidden { pointer-events: none !important; }

/* ── Launcher ── */
.flai-root .flai-launcher {
  background: var(--flai-accent) !important;
  color: #ffffff !important;
  border: 0 !important;
  border-radius: 20px !important;
  padding: 12px 20px !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 10px !important;
  cursor: pointer !important;
  box-shadow: 0 6px 18px rgba(14, 104, 108, 0.35) !important;
  font-weight: 600 !important;
  font-size: 14px !important;
  font-family: inherit !important;
  line-height: 1 !important;
  letter-spacing: -0.01em !important;
  transition: transform 200ms cubic-bezier(0.2, 0, 0, 1), box-shadow 200ms ease !important;
  margin: 0 !important;
  text-decoration: none !important;
  text-transform: none !important;
  min-height: auto !important;
  width: auto !important;
}

.flai-root .flai-launcher:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 10px 24px rgba(14, 104, 108, 0.45) !important;
}

.flai-root .flai-launcher:active { transform: translateY(0) !important; }

.flai-root .flai-launcher.flai-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: scale(0.85) translateY(4px) !important;
  /* Out of flow while the panel is open so the panel — anchored to the
     bottom — is the only thing that sets the widget's height. */
  position: absolute !important;
  right: 0 !important;
  bottom: 0 !important;
}

.flai-root.bottom-left .flai-launcher.flai-hidden {
  right: auto !important;
  left: 0 !important;
}

.flai-root .flai-launcher-icon {
  width: 20px !important;
  height: 20px !important;
  display: inline-flex !important;
  flex-shrink: 0 !important;
}

.flai-root .flai-launcher-icon svg { width: 100% !important; height: 100% !important; }

/* ── Idle launcher: speech balloon (left) + Lottie animation ── */
.flai-root .flai-launcher.flai-launcher-idle {
  position: relative !important;
  background: transparent !important;
  box-shadow: none !important;
  padding: 0 !important;
  border-radius: 0 !important;
  gap: 10px !important;
  align-items: flex-end !important;
  overflow: visible !important;
}

.flai-root .flai-launcher.flai-launcher-idle:hover {
  transform: translateY(-2px) !important;
  box-shadow: none !important;
}

.flai-root .flai-launcher-idle .flai-lottie {
  display: block;
  flex-shrink: 0;
  filter: drop-shadow(0 6px 16px rgba(18, 22, 42, 0.28));
}

.flai-root .flai-launcher-idle .flai-lottie svg {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.flai-root .flai-launcher-idle .flai-balloon {
  position: relative;
  max-width: 220px;
  margin-bottom: 8px;
  padding: 9px 13px;
  background: var(--flai-surface);
  color: var(--flai-ink) !important;
  border: 1px solid var(--flai-border);
  border-radius: 14px;
  font-size: 13px !important;
  font-weight: 500 !important;
  line-height: 1.4 !important;
  letter-spacing: 0 !important;
  text-align: left;
  white-space: normal;
  box-shadow: 0 8px 22px -10px rgba(18, 22, 42, 0.3);
  animation: flai-balloon-in 260ms cubic-bezier(0.2, 0, 0, 1);
}

/* Tail pointing right, toward the animation */
.flai-root .flai-launcher-idle .flai-balloon::after {
  content: "";
  position: absolute;
  right: -7px;
  bottom: 12px;
  width: 12px;
  height: 12px;
  background: var(--flai-surface);
  border-right: 1px solid var(--flai-border);
  border-bottom: 1px solid var(--flai-border);
  transform: rotate(-45deg);
}

.flai-root .flai-launcher-idle .flai-balloon-text::after {
  content: "▍";
  margin-left: 1px;
  opacity: 0.5;
  animation: flai-caret 1s steps(1) infinite;
}

@keyframes flai-balloon-in {
  from { opacity: 0; transform: translateY(4px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes flai-caret { 50% { opacity: 0; } }

/* ── Collapsed balloon → unread badge on the animation ── */
.flai-root .flai-launcher-idle .flai-balloon.flai-balloon-collapsed {
  opacity: 0;
  transform: translateY(2px) scale(0.9);
  pointer-events: none;
  max-width: 0;
  max-height: 0;
  margin: 0;
  padding: 0;
  border-width: 0;
  overflow: hidden;
  transition: opacity 200ms ease, transform 200ms ease;
}

.flai-root .flai-launcher-idle .flai-badge {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #e8362f;
  color: #fff !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  line-height: 20px !important;
  text-align: center;
  box-shadow: 0 0 0 2px var(--flai-surface, #fff), 0 4px 10px -2px rgba(232, 54, 47, 0.6);
  animation: flai-badge-pop 260ms cubic-bezier(0.2, 0, 0, 1);
}

@keyframes flai-badge-pop {
  from { opacity: 0; transform: scale(0.4); }
  to   { opacity: 1; transform: scale(1); }
}

/* On a left-anchored widget the balloon still sits to the left of the
   animation; nudge the cluster so it doesn't run off-screen. */
.flai-root.bottom-left .flai-launcher-idle { justify-content: flex-start; }

.flai-root.rounded .flai-launcher,
.flai-root.rounded .flai-panel { border-radius: 20px !important; }

.flai-root.square .flai-launcher,
.flai-root.square .flai-panel { border-radius: 8px !important; }

/* ── Panel ── */
.flai-root .flai-panel {
  width: min(94vw, 400px);
  height: 560px;
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  background: var(--flai-surface);
  border: 1px solid var(--flai-border);
  margin-top: 12px;
  display: none;
  overflow: hidden;
  box-shadow: 0 20px 40px -12px rgba(18, 22, 42, 0.28);
}

.flai-root .flai-panel.is-open {
  display: grid !important;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  /* The hidden launcher is out of flow while open, so drop the gap it used
     to need. */
  margin-top: 0;
  overscroll-behavior: contain;
  animation: flai-pop 200ms cubic-bezier(0.2, 0, 0, 1);
}

@keyframes flai-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Header ── */
.flai-root .flai-header {
  background: var(--flai-accent);
  color: #ffffff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.flai-root .flai-header-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

.flai-root .flai-close {
  width: 30px !important;
  height: 30px !important;
  border: none !important;
  border-radius: 8px !important;
  background: rgba(255, 255, 255, 0.16) !important;
  color: #ffffff !important;
  line-height: 1 !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: background 150ms ease !important;
  padding: 0 !important;
  margin: 0 !important;
  box-shadow: none !important;
  min-width: auto !important;
}

.flai-root .flai-close:hover { background: rgba(255, 255, 255, 0.28) !important; }

/* ── Feed ── */
.flai-root .flai-feed {
  padding: 20px 16px;
  /* !important so a host theme's global element rules can't turn the
     transcript's own scrollbar off and push the overflow onto the page. */
  overflow-y: auto !important;
  /* Without this the grid track refuses to shrink below its content, so the
     feed grows past the panel instead of scrolling and older messages become
     unreachable. */
  min-height: 0 !important;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--flai-surface);
  scroll-behavior: smooth;
}

.flai-root .flai-feed::-webkit-scrollbar { width: 5px; }
.flai-root .flai-feed::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

.flai-root .flai-msg {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
}

.flai-root .flai-msg-user { align-items: flex-end; }
.flai-root .flai-msg-bot { align-items: flex-start; }

.flai-root .flai-bubble {
  display: inline-block;
  max-width: 85%;
  padding: 10px 14px;
  line-height: 1.5;
  font-size: 14px;
  word-wrap: break-word;
}

/* One text size for the whole reply, whatever the host theme sets on p / li /
   blockquote and regardless of nesting. */
.flai-root .flai-bubble,
.flai-root .flai-bubble * {
  font-size: 14px !important;
  line-height: 1.5 !important;
  font-family: inherit !important;
}

.flai-root .flai-msg-user .flai-bubble {
  background: var(--flai-accent);
  color: #ffffff;
  border-radius: 16px 16px 4px 16px;
}

.flai-root .flai-msg-bot .flai-bubble {
  background: var(--flai-surface-alt);
  color: var(--flai-ink);
  border-radius: 16px 16px 16px 4px;
}

.flai-root .flai-msg-bot .flai-bubble a { color: var(--flai-accent-strong); }

/* Rich text inside a reply (Markdown → HTML) */
.flai-root .flai-bubble > :first-child { margin-top: 0; }
.flai-root .flai-bubble > :last-child { margin-bottom: 0; }
.flai-root .flai-bubble p { margin: 0 0 8px; }
.flai-root .flai-bubble ul,
.flai-root .flai-bubble ol { margin: 6px 0; padding-left: 20px; }
.flai-root .flai-bubble li { margin: 2px 0; }
.flai-root .flai-bubble blockquote {
  margin: 6px 0;
  padding-left: 10px;
  border-left: 2px solid var(--flai-border);
}
.flai-root .flai-bubble code {
  background: rgba(18, 22, 42, 0.08);
  border-radius: 4px;
  padding: 1px 5px;
}
.flai-root .flai-msg-user .flai-bubble code { background: rgba(255, 255, 255, 0.22); }

/* Typing indicator */
.flai-root .flai-typing .flai-bubble {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.flai-root .flai-typing .flai-bubble span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--flai-ink-soft);
  animation: flai-blink 1.2s infinite ease-in-out both;
}
.flai-root .flai-typing .flai-bubble span:nth-child(2) { animation-delay: 0.15s; }
.flai-root .flai-typing .flai-bubble span:nth-child(3) { animation-delay: 0.3s; }
@keyframes flai-blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

/* ── WhatsApp CTA ── */
.flai-root .flai-action-wrap { margin-top: 10px; }

.flai-root .flai-wa-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--flai-accent-strong) !important;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--flai-border);
  transition: background 150ms ease;
}

.flai-root .flai-wa-btn:hover { background: var(--flai-surface-alt); }

/* ── Suggestions ── */
.flai-root .flai-suggestions {
  padding: 12px 16px;
  border-top: 1px solid var(--flai-border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--flai-surface);
}

/* ── Persistent WhatsApp bar ── */
.flai-root .flai-wa-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 16px 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #25d366;
  color: #073b25 !important;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: filter 150ms ease;
}

.flai-root .flai-wa-bar:hover { filter: brightness(1.06); }
.flai-root .flai-wa-bar svg { flex-shrink: 0; }

.flai-root .flai-suggestion {
  border: 1px solid var(--flai-border);
  background: var(--flai-surface);
  color: var(--flai-ink);
  border-radius: 40px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 150ms ease;
}

.flai-root .flai-suggestion:hover {
  background: var(--flai-surface-alt);
  border-color: var(--flai-accent);
  color: var(--flai-accent-strong);
}

/* ── Form ── */
.flai-root .flai-form {
  display: block;
  padding: 12px 16px;
  border-top: 1px solid var(--flai-border);
  background: var(--flai-surface);
}

.flai-root .flai-input-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.flai-root .flai-input {
  flex: 1;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 10px 14px;
  min-height: 44px;
  max-height: 100px;
  line-height: 1.5;
  resize: none;
  font-family: inherit;
  font-size: 14px;
  color: var(--flai-ink);
  background: var(--flai-surface);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.flai-root .flai-input:focus {
  outline: none;
  border-color: var(--flai-accent);
  box-shadow: 0 0 0 3px rgba(14, 104, 108, 0.15);
}

/* Honeypot — visually removed, still in the DOM */
.flai-root .flai-hp {
  position: absolute !important;
  left: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.flai-root .flai-send {
  flex-shrink: 0 !important;
  width: 44px !important;
  height: 44px !important;
  border: none !important;
  background: var(--flai-accent) !important;
  color: #ffffff !important;
  border-radius: 12px !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: transform 200ms ease, box-shadow 200ms ease !important;
  box-shadow: 0 2px 8px rgba(14, 104, 108, 0.30) !important;
  padding: 0 !important;
  margin: 0 !important;
  line-height: 1 !important;
  font-size: 0 !important;
  min-width: auto !important;
}

.flai-root .flai-send:hover:not(:disabled) {
  transform: scale(1.03) !important;
  box-shadow: 0 4px 14px rgba(14, 104, 108, 0.42) !important;
}

.flai-root .flai-send:disabled { opacity: 0.55 !important; cursor: default !important; }
.flai-root .flai-send svg { width: 20px !important; height: 20px !important; display: block !important; }

/* ── End chat ── */
.flai-root .flai-end-chat {
  margin: 8px 0 0 0 !important;
  padding: 4px 8px !important;
  border: 1px solid var(--flai-border) !important;
  background: transparent !important;
  color: var(--flai-ink-soft) !important;
  font-size: 10px !important;
  font-weight: 600 !important;
  font-family: inherit !important;
  line-height: 1.2 !important;
  border-radius: 6px !important;
  cursor: pointer !important;
  width: auto !important;
  min-width: 0 !important;
  min-height: 0 !important;
  display: inline-block !important;
  transition: all 150ms ease !important;
  text-transform: none !important;
  box-shadow: none !important;
}

.flai-root .flai-end-chat:hover { background: var(--flai-surface-alt) !important; color: var(--flai-ink) !important; }

.flai-root .flai-end-confirm {
  display: none;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--flai-border);
  background: var(--flai-surface-alt);
  border-radius: 8px;
}

.flai-root .flai-end-confirm.is-open { display: block; }

.flai-root .flai-end-confirm-text { margin: 0; color: var(--flai-ink); font-size: 12px; line-height: 1.4; }

.flai-root .flai-end-confirm-actions { margin-top: 8px; display: flex; gap: 8px; }

.flai-root .flai-end-confirm-cancel,
.flai-root .flai-end-confirm-ok {
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.flai-root .flai-end-confirm-cancel { background: var(--flai-border); color: var(--flai-ink); }
.flai-root .flai-end-confirm-ok { background: var(--flai-accent); color: #ffffff; }

/* ── Mobile ── */
@media (max-width: 600px) {
  .flai-root.bottom-right, .flai-root.bottom-left { right: 12px; bottom: 12px; }
  .flai-root.bottom-left { left: 12px; right: auto; }
  .flai-root .flai-panel {
    width: calc(100vw - 24px);
    height: 78vh;
    height: 78dvh;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }
  .flai-root .flai-bubble { max-width: 90%; }
  /* Below 16px, iOS Safari auto-zooms the whole page on focus - the exact
     symptom reported ("stretches out of the viewport ... when I click the
     chat box"): tapping the input zooms the page, and the fixed-position
     panel doesn't track that zoom correctly, so it visually overflows.
     16px is the documented threshold where Safari stops doing this. */
  .flai-root .flai-input { font-size: 16px; }
}

/* ── Dark scheme ── */
@media (prefers-color-scheme: dark) {
  .flai-root:not([data-flai-theme="light"]) {
    --flai-ink: #e8eaf2;
    --flai-ink-soft: #9aa1b8;
    --flai-surface: #12162a;
    --flai-surface-alt: #1c2136;
    --flai-border: #2b3150;
  }
  .flai-root:not([data-flai-theme="light"]) .flai-input { background: #1c2136; border-color: #2b3150; }
}
