/* Namespaced so the body-mounted widget is independent of app renders and styles. */
.fps {
  --fps-violet: #6439ee;
  --fps-ink: #282039;
  --fps-muted: #70677e;
  --fps-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  --fps-viewport-height: 100vh;
  --fps-viewport-width: 100vw;
  --fps-keyboard-inset: 0px;
  position: fixed;
  z-index: 90;
  right: max(20px, env(safe-area-inset-right, 0px));
  bottom: calc(var(--fps-bottom) + var(--fps-keyboard-inset));
  color-scheme: light;
  color: var(--fps-ink);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: left;
  letter-spacing: normal;
  -webkit-text-size-adjust: 100%;
}

@supports (height: 100dvh) {
  .fps { --fps-viewport-height: 100dvh; }
}

.fps *, .fps *::before, .fps *::after { box-sizing: border-box; }
.fps [hidden] { display: none !important; }
.fps button, .fps textarea, .fps a { font: inherit; letter-spacing: inherit; }
.fps button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
  touch-action: manipulation;
}
.fps button:disabled { opacity: .5; cursor: default; }
.fps :is(button, textarea, a, [tabindex]):focus-visible {
  outline: 3px solid #9b7bff;
  outline-offset: 3px;
}
.fps svg { width: 18px; height: 18px; flex: 0 0 18px; }
.fps p, .fps h2, .fps h3 { margin: 0; color: inherit; }
.fps p { line-height: 1.55; }

.fps .fps__launcher {
  min-height: 52px;
  padding: 8px 17px 8px 10px;
  border: 1px solid #ffffff30;
  border-radius: 999px;
  background: var(--fps-violet);
  color: #fff;
  box-shadow: 0 5px 18px #43279b30, 0 1px 3px #24144e1f;
  transition: background .16s ease, box-shadow .16s ease;
}
.fps__launcher-mark { width: 32px; height: 32px; padding: 3px; object-fit: contain; border-radius: 9px; background: #fff; }
.fps__panel {
  position: absolute;
  right: 0;
  bottom: 64px;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(var(--fps-viewport-width) - 40px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  height: 640px;
  max-height: max(0px, calc(var(--fps-viewport-height) - var(--fps-bottom) - 76px - env(safe-area-inset-top, 0px)));
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid #e6dff3;
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 18px 65px #34205c24, 0 2px 8px #34205c0a;
  isolation: isolate;
}
.fps__header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding: 16px 12px 14px 18px;
  background: linear-gradient(115deg, #faf8ff, #fff);
}
.fps__mark { width: 34px; height: 34px; object-fit: contain; flex: 0 0 34px; }
.fps__heading { flex: 1; min-width: 0; }
.fps .fps__title { font-size: 16px; font-weight: 700; line-height: 1.3; letter-spacing: -.3px; }
.fps .fps__assistant { margin-top: 3px; color: #7552ba; font-size: 14px; line-height: 1.4; }
.fps .fps__clear { padding: 8px; color: var(--fps-muted); font-weight: 500; }
.fps .fps__close { flex: 0 0 40px; width: 40px; padding: 0; color: var(--fps-muted); }
.fps .fps__disclosure {
  flex: 0 0 auto;
  padding: 11px 18px;
  border-top: 1px solid #eee8f7;
  border-bottom: 1px solid #eee8f7;
  background: #f8f5ff;
  color: #655873;
  font-size: 14px;
  line-height: 1.5;
}
.fps__scroll {
  flex: 1 1 auto;
  min-height: 72px;
  padding: 20px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #d5c8ef transparent;
  scroll-padding-block: 16px;
}
.fps__scroll:focus-visible { outline-offset: -4px !important; }
.fps .fps__welcome-title { font-size: 19px; line-height: 1.35; font-weight: 650; letter-spacing: -.45px; }
.fps .fps__intro { margin-top: 8px; color: var(--fps-muted); font-size: 14px; }
.fps__prompts { display: grid; justify-items: start; gap: 8px; margin-top: 18px; }
.fps .fps__prompt {
  max-width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid #e8def9;
  border-radius: 12px;
  background: #fcfaff;
  color: #5d3c9b;
  text-align: left;
  justify-content: flex-start;
  font-weight: 500;
}
.fps__messages { display: flex; flex-direction: column; gap: 16px; margin: 0; padding: 0; list-style: none; }
.fps__message { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; min-width: 0; }
.fps__author { padding: 0 3px; color: var(--fps-muted); font-size: 14px; }
.fps .fps__bubble {
  max-width: 94%;
  padding: 11px 14px;
  border: 1px solid #ece5f7;
  border-radius: 4px 16px 16px 16px;
  background: #f6f2fc;
  color: var(--fps-ink);
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  unicode-bidi: plaintext;
}
.fps__message--user { align-items: flex-end; }
.fps .fps__formatted { white-space: normal; line-height: 1.6; }
.fps .fps__formatted p { margin: 0 0 .7em; }
.fps .fps__formatted strong { font-weight: 700; color: #292039; }
.fps .fps__formatted em { font-style: italic; }
.fps .fps__formatted :is(ul,ol) { margin: .65em 0; padding-left: 1.3em; }
.fps .fps__formatted ul { list-style: disc outside; }
.fps .fps__formatted ol { list-style: decimal outside; }
.fps .fps__formatted li { display: list-item; padding-left: .1em; margin: .35em 0; }
.fps .fps__formatted li::marker { color: #7658b5; font-weight: 600; }
.fps .fps__formatted h4 { font-size: 1em; line-height: 1.4; margin: .9em 0 .45em; font-weight: 700; }
.fps .fps__formatted code { font: .9em/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: #e9e2f4; padding: .12em .3em; border-radius: 4px; overflow-wrap: anywhere; }
.fps .fps__formatted pre { white-space: pre-wrap; margin: .7em 0; padding: 10px; background: #e9e2f4; border-radius: 8px; }
.fps .fps__formatted pre code { padding: 0; background: none; }
.fps .fps__formatted a { color: #6439ee; text-decoration: underline; text-underline-offset: 2px; }
.fps .fps__formatted > :first-child { margin-top: 0; }
.fps .fps__formatted > :last-child { margin-bottom: 0; }
.fps .fps__message--user .fps__bubble {
  border-color: var(--fps-violet);
  border-radius: 16px 4px 16px 16px;
  background: var(--fps-violet);
  color: #fff;
}
.fps__sending { display: flex; align-items: center; gap: 9px; color: var(--fps-muted); font-size: 14px; }
.fps__dots { display: inline-flex; gap: 4px; flex: 0 0 auto; }
.fps__dots i { width: 5px; height: 5px; border-radius: 50%; background: #8c6bd2; animation: fps-pulse 1.3s ease-in-out infinite; }
.fps__dots i:nth-child(2) { animation-delay: .16s; }
.fps__dots i:nth-child(3) { animation-delay: .32s; }

.fps__composer { flex: 0 0 auto; margin: 0; padding: 12px 16px 10px; border-top: 1px solid #eee8f7; background: #fff; }
.fps .fps__error { margin-bottom: 10px; padding: 10px 12px; border-radius: 10px; background: #fff1ed; color: #893d27; font-size: 14px; }
.fps .fps__input {
  display: block;
  width: 100%;
  min-height: 66px;
  max-height: 140px;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #ded5ed;
  border-radius: 12px;
  background: #fff;
  color: var(--fps-ink);
  font-size: 16px;
  line-height: 1.5;
  resize: none;
  box-shadow: 0 1px 2px #33204405;
}
.fps__input::placeholder { color: #7f738c; opacity: 1; }
.fps__input[readonly] { background: #faf8fd; }
.fps__toolbar { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.fps__count { margin-right: auto; color: var(--fps-muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fps .fps__send { background: var(--fps-violet); color: #fff; padding-inline: 14px; }
.fps .fps__retry { padding-inline: 9px; color: #5f35ba; background: #f4efff; }
.fps__footer { flex: 0 0 auto; padding: 0 16px 12px; background: #fff; text-align: center; }
.fps__human {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 5px 3px;
  color: #635073;
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 3px;
  border-radius: 4px;
}
.fps__sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (hover: hover) {
  .fps .fps__launcher:hover, .fps .fps__send:hover:not(:disabled) { background: #542bd5; }
  .fps .fps__prompt:hover:not(:disabled), .fps .fps__retry:hover:not(:disabled) { background: #eee7ff; border-color: #d9c9f6; }
  .fps .fps__close:hover, .fps .fps__clear:hover:not(:disabled) { background: #f2ecfb; color: #513481; }
  .fps__human:hover { color: var(--fps-violet); }
}

@media (max-width: 850px) {
  .fps {
    --fps-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
  }
  .fps__panel {
    bottom: 0;
    width: min(400px, calc(var(--fps-viewport-width) - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
    max-height: max(0px, calc(var(--fps-viewport-height) - var(--fps-bottom) - 12px - env(safe-area-inset-top, 0px)));
    border-radius: 18px;
  }
  .fps--open .fps__launcher { display: none; }
  .fps--keyboard { --fps-bottom: 12px; }
  .fps--keyboard .fps__header { padding-block: 10px; }
  .fps--keyboard .fps__scroll { min-height: 40px; padding-block: 12px; }
}

@media (max-width: 380px) {
  .fps__header { padding-inline: 12px 8px; gap: 6px; }
  .fps__header .fps__mark { display: none; }
  .fps__toolbar { flex-wrap: wrap; }
  .fps__count { flex-grow: 1; }
  .fps__disclosure, .fps__scroll { padding-inline: 14px; }
}

@keyframes fps-pulse { 0%, 80%, 100% { opacity: .35; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .fps *, .fps *::before, .fps *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
