/* ========================================
   FLOSYNC CHAT WIDGET
   Plain CSS (loaded as a static stylesheet, NOT Tailwind).
   All styles scoped under #flosync-chat-* / .flosync-chat-*.
   Brand: lime #c8ff00 on navy #11234b. RTL-aware via logical
   properties + [dir="rtl"] rules. Respects prefers-reduced-motion.
   ======================================== */

.flosync-chat-root {
  --flosync-chat-brand: #c8ff00;
  --flosync-chat-navy: #11234b;
  --flosync-chat-radius: 16px;
  --flosync-chat-z: 1100;
  font-family: "Noto Sans", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.flosync-chat-root.flosync-chat-disabled {
  display: none !important;
}

/* --- Floating bubble --- */
.flosync-chat-bubble {
  position: fixed;
  inset-block-end: 24px;
  inset-inline-end: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background-color: var(--flosync-chat-navy);
  color: var(--flosync-chat-brand);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  z-index: var(--flosync-chat-z);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.flosync-chat-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.32);
}

/* Hide the bubble while the panel is open (esp. mobile full-screen). */
.flosync-chat-root.flosync-chat-open .flosync-chat-bubble {
  opacity: 0;
  pointer-events: none;
}

/* --- Proactive teaser nudge --- */
/* A small speech bubble that floats just above the chat bubble. Hidden until
   JS adds .flosync-chat-teaser-visible, and hidden again whenever the panel
   opens. Anchored to the same inline-end edge so it sits over the chat bubble. */
.flosync-chat-teaser {
  position: fixed;
  inset-block-end: 94px;
  inset-inline-end: 24px;
  z-index: var(--flosync-chat-z);
  max-width: 220px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity 0.28s ease, transform 0.28s ease, visibility 0.28s ease;
}
[dir="rtl"] .flosync-chat-teaser { transform-origin: bottom left; }

.flosync-chat-teaser-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* The panel and the teaser are mutually exclusive: never nag over an open chat. */
.flosync-chat-root.flosync-chat-open .flosync-chat-teaser {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.flosync-chat-teaser-bubble {
  position: relative;
  display: block;
  width: 100%;
  background: #ffffff;
  color: var(--flosync-chat-navy);
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: start;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(17, 35, 75, 0.18);
  transition: background-color 0.15s, box-shadow 0.15s;
}
.flosync-chat-teaser-bubble:hover {
  background: #f8fafc;
  box-shadow: 0 8px 26px rgba(17, 35, 75, 0.24);
}

/* Little tail pointing down toward the chat bubble. */
.flosync-chat-teaser-bubble::after {
  content: "";
  position: absolute;
  inset-block-end: -6px;
  inset-inline-end: 20px;
  width: 13px;
  height: 13px;
  background: inherit;
  border-inline-end: 1px solid #e5e7eb;
  border-block-end: 1px solid #e5e7eb;
  transform: rotate(45deg);
}

/* Dismiss (×): small circular button overlapping the top inline-end corner. */
.flosync-chat-teaser-close {
  position: absolute;
  inset-block-start: -9px;
  inset-inline-end: -9px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  color: #64748b;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 2px 8px rgba(17, 35, 75, 0.18);
  transition: background-color 0.15s, color 0.15s;
}
.flosync-chat-teaser-close:hover {
  background: #f1f5f9;
  color: var(--flosync-chat-navy);
}

/* --- Panel --- */
.flosync-chat-panel {
  position: fixed;
  inset-block-end: 96px;
  inset-inline-end: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  border-radius: var(--flosync-chat-radius);
  background: #ffffff;
  box-shadow: 0 12px 40px rgba(17, 35, 75, 0.22);
  z-index: var(--flosync-chat-z);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s ease;
}

.flosync-chat-panel.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* --- Header --- */
.flosync-chat-header {
  background-color: var(--flosync-chat-navy);
  color: #ffffff;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.flosync-chat-title {
  font-weight: 600;
  font-size: 1rem;
}

.flosync-chat-close {
  background: none;
  border: none;
  color: #ffffff;
  cursor: pointer;
  padding: 4px;
  display: inline-flex;
  opacity: 0.85;
  transition: opacity 0.15s;
}
.flosync-chat-close:hover { opacity: 1; }

/* --- Messages --- */
.flosync-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
}

.flosync-chat-msg {
  max-width: 88%;
  font-size: 0.9rem;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.flosync-chat-msg-user {
  align-self: flex-end;
  background-color: var(--flosync-chat-navy);
  color: #ffffff;
  padding: 10px 14px;
  border-start-start-radius: 16px;
  border-start-end-radius: 16px;
  border-end-start-radius: 16px;
  border-end-end-radius: 4px;
}

.flosync-chat-msg-assistant {
  align-self: flex-start;
  background-color: #ffffff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  padding: 12px 14px;
  border-start-start-radius: 16px;
  border-start-end-radius: 16px;
  border-end-start-radius: 4px;
  border-end-end-radius: 16px;
}

.flosync-chat-text p { margin: 0 0 8px 0; }
.flosync-chat-text p:last-child { margin-bottom: 0; }
.flosync-chat-text strong { font-weight: 700; }
/* Re-assert list markers: the site's Tailwind Preflight resets
   `ol, ul { list-style: none }` globally, which would otherwise strip the
   bullets/numbers off lists the assistant renders inside the widget. */
.flosync-chat-text ul,
.flosync-chat-text ol { margin: 4px 0 8px; padding-inline-start: 20px; }
.flosync-chat-text ul { list-style: disc; }
.flosync-chat-text ol { list-style: decimal; }
.flosync-chat-text li { margin-bottom: 2px; }
.flosync-chat-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background-color: #eef2f7;
  padding: 1px 5px;
  border-radius: 4px;
}
.flosync-chat-text pre {
  background-color: #f3f5f8;
  border-radius: 6px;
  padding: 8px 10px;
  margin: 6px 0;
  overflow-x: auto;
}
.flosync-chat-text pre code { background: none; padding: 0; font-size: 0.82em; }
.flosync-chat-text a {
  color: var(--flosync-chat-navy);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.flosync-chat-text a:hover { text-decoration: none; }

/* --- Action + related page chips (uniform pill row) --- */
.flosync-chat-related {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.flosync-chat-chip {
  font-size: 0.8rem;
  background-color: #eef2f7;
  color: var(--flosync-chat-navy);
  padding: 5px 11px;
  border-radius: 999px;
  text-decoration: none;
  border: 1px solid #dbe2ea;
  transition: background-color 0.15s;
}
.flosync-chat-chip:hover { background-color: #dde6f0; }

/* Primary action chip: same pill shape as the rest, tinted brand-green to mark
   the direct answer (download / get started / contact). Always rendered first. */
.flosync-chat-chip-primary {
  background-color: var(--flosync-chat-brand);
  color: var(--flosync-chat-navy);
  border-color: var(--flosync-chat-brand);
  font-weight: 700;
}
.flosync-chat-chip-primary:hover {
  background-color: var(--flosync-chat-brand);
  filter: brightness(0.92);
}

/* Visually-hidden, but exposed to assistive tech (used to announce the full
   reply once while the visual text reveals word-by-word). */
.flosync-chat-sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Cross-language offer (reply language differs from the page) --- */
.flosync-chat-offer {
  margin-top: 10px;
  font-size: 0.78rem;
  color: #5b6470;
  line-height: 1.4;
}
.flosync-chat-offer-link {
  color: var(--flosync-chat-navy);
  text-decoration: underline;
  word-break: break-word;
}
.flosync-chat-offer-link:hover { color: #0c1a38; }

/* --- Suggested prompts --- */
.flosync-chat-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px;
}
.flosync-chat-prompts:empty { display: none; }
.flosync-chat-prompts:not(:empty) { padding-block: 8px 4px; }
.flosync-chat-prompt {
  font-size: 0.8rem;
  background: #ffffff;
  color: var(--flosync-chat-navy);
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.flosync-chat-prompt:hover {
  background: #f1f5f9;
  border-color: var(--flosync-chat-navy);
}

/* --- Typing indicator --- */
.flosync-chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background-color: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 16px 16px 16px 4px;
}
.flosync-chat-typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #9aa5b1;
  animation: flosync-chat-bounce 1.2s infinite;
}
.flosync-chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.flosync-chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes flosync-chat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* --- Input area --- */
.flosync-chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
  background: #ffffff;
}
.flosync-chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.flosync-chat-input {
  flex: 1;
  border: 1px solid #cbd5e1;
  border-radius: 22px;
  padding: 9px 16px;
  font-size: 0.9rem;
  line-height: 1.4;
  outline: none;
  resize: none;
  max-height: 120px;
  font-family: inherit;
  transition: border-color 0.2s;
}
.flosync-chat-input:focus { border-color: var(--flosync-chat-navy); }

.flosync-chat-send {
  background-color: var(--flosync-chat-navy);
  color: var(--flosync-chat-brand);
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: filter 0.15s;
}
.flosync-chat-send:hover { filter: brightness(1.15); }
.flosync-chat-send-disabled,
.flosync-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* The send arrow points to the inline-end; flip it in RTL. */
[dir="rtl"] .flosync-chat-send svg { transform: scaleX(-1); }

/* --- Disclaimer + privacy --- */
.flosync-chat-disclaimer {
  text-align: center;
  font-size: 0.68rem;
  color: #94a3b8;
  padding-top: 8px;
}
.flosync-chat-privacy {
  text-align: center;
  font-size: 0.66rem;
  color: #94a3b8;
  padding-top: 3px;
}
.flosync-chat-privacy a {
  color: #64748b;
  text-decoration: underline;
}

/* Turnstile mount is invisible by design; keep it out of layout flow. */
.flosync-chat-turnstile {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* --- Mobile: full-screen panel --- */
@media (max-width: 480px) {
  .flosync-chat-panel {
    inset-block-end: 0;
    inset-inline-start: 0;
    inset-inline-end: 0;
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .flosync-chat-bubble {
    inset-block-end: 16px;
    inset-inline-end: 16px;
    width: 54px;
    height: 54px;
  }
  .flosync-chat-teaser {
    inset-block-end: 80px;
    inset-inline-end: 16px;
  }
  /* iOS Safari auto-zooms (and never zooms back out) when a focused field's
     font-size is below 16px. Keep the input at 16px on mobile so tapping it to
     type does not zoom the panel and push the send button off-screen. */
  .flosync-chat-input {
    font-size: 16px;
  }
}

/* --- Focus indicators --- */
.flosync-chat-bubble:focus-visible,
.flosync-chat-close:focus-visible,
.flosync-chat-send:focus-visible,
.flosync-chat-prompt:focus-visible,
.flosync-chat-chip:focus-visible,
.flosync-chat-teaser-bubble:focus-visible,
.flosync-chat-teaser-close:focus-visible,
.flosync-chat-input:focus-visible {
  outline: 2px solid var(--flosync-chat-navy);
  outline-offset: 2px;
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  .flosync-chat-bubble,
  .flosync-chat-panel,
  .flosync-chat-teaser,
  .flosync-chat-typing-dot,
  .flosync-chat-chip,
  .flosync-chat-prompt,
  .flosync-chat-send {
    animation: none !important;
    transition: none !important;
  }
}
