/* ============================================================
   FluxFront — website agent widget
   Tokens only (css/tokens.css). Nothing here hardcodes a brand colour.

   Layering: the launcher and panel sit at 9000, deliberately BELOW the
   cookie banner (10000) so a consent decision is never covered by a chat
   bubble.
   ============================================================ */

.ffchat-root {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: var(--font-body);
  /* The root is a positioning frame, not a surface. On mobile it spans the
     full width, so without this it would swallow every tap in the bottom
     strip of the page with the chat CLOSED. Children opt back in. */
  pointer-events: none;
}

.ffchat-root > * { pointer-events: auto; }

/* ---- launcher ------------------------------------------------ */
.ffchat-launcher {
  position: relative;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  background: var(--brand-grad);
  box-shadow: 0 10px 28px rgb(var(--paper-shadow) / 0.22),
              0 2px 6px rgb(var(--paper-shadow) / 0.14);
  display: grid;
  place-items: center;
  color: #fff;
  transition: transform 180ms cubic-bezier(.2, .8, .2, 1),
              box-shadow 180ms ease;
}

.ffchat-launcher:hover { transform: translateY(-2px) scale(1.04); }
.ffchat-launcher:active { transform: translateY(0) scale(.97); }
.ffchat-launcher:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

/* The mark and the X occupy the same cell and cross-fade on open. */
.ffchat-launcher-mark,
.ffchat-launcher-close {
  grid-area: 1 / 1;
  transition: opacity 160ms ease, transform 220ms cubic-bezier(.2, .8, .2, 1);
}
.ffchat-launcher-mark { color: #fff; }
.ffchat-launcher-close { opacity: 0; transform: rotate(-90deg); color: #fff; }

.ffchat-launcher-open .ffchat-launcher-mark { opacity: 0; transform: rotate(90deg) scale(.6); }
.ffchat-launcher-open .ffchat-launcher-close { opacity: 1; transform: rotate(0); }

/* ---- nudge --------------------------------------------------- */
.ffchat-nudge {
  position: relative;
  max-width: 244px;
  background: var(--cream);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: 14px 14px 4px 14px;
  padding: 12px 14px;
  box-shadow: 0 10px 26px rgb(var(--paper-shadow) / 0.16);
  animation: ffchat-nudge-in 260ms cubic-bezier(.2, .8, .2, 1) both;
}

.ffchat-nudge-open {
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: .875rem;
  line-height: 1.45;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.ffchat-nudge-open:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }

.ffchat-nudge-dismiss {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: var(--cream);
  color: var(--ink-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}
.ffchat-nudge-dismiss:hover { color: var(--ink); }

@keyframes ffchat-nudge-in {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to   { opacity: 1; transform: none; }
}

/* ---- panel --------------------------------------------------- */
.ffchat-panel {
  width: 380px;
  max-width: calc(100vw - 32px);
  height: min(620px, calc(100vh - 140px));
  height: min(620px, calc(100dvh - 140px)); /* iOS: vh ignores the URL bar */
  background: var(--cream);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgb(var(--paper-shadow) / 0.24),
              0 4px 12px rgb(var(--paper-shadow) / 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(14px) scale(.96);
  transform-origin: bottom right;
  transition: opacity 200ms ease,
              transform 220ms cubic-bezier(.2, .8, .2, 1);
}

.ffchat-panel.ffchat-open { opacity: 1; transform: none; }
.ffchat-panel[hidden] { display: none; }

.ffchat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface);
}

.ffchat-avatar { border-radius: 9px; flex: none; }

.ffchat-head-text { display: flex; flex-direction: column; line-height: 1.25; }
.ffchat-head-text strong {
  font-family: var(--font-display);
  font-size: .975rem;
  color: var(--ink);
}
.ffchat-head-text span { font-size: .75rem; color: var(--ink-3); }

.ffchat-close {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: grid;
  place-items: center;
}
.ffchat-close:hover { color: var(--ink); background: var(--surface-2); }

.ffchat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ffchat-msg { display: flex; }
.ffchat-msg-agent { justify-content: flex-start; }
.ffchat-msg-you { justify-content: flex-end; }

.ffchat-bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: .9rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.ffchat-msg-agent .ffchat-bubble {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-bottom-left-radius: 5px;
}

.ffchat-msg-you .ffchat-bubble {
  background: var(--brand-grad);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.ffchat-bubble a { color: inherit; text-underline-offset: 2px; }
.ffchat-msg-agent .ffchat-bubble a { color: var(--teal-700); }

/* typing dots */
.ffchat-typing .ffchat-bubble { display: flex; gap: 4px; padding: 13px; }
.ffchat-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-3);
  animation: ffchat-blink 1.2s infinite ease-in-out both;
}
.ffchat-typing i:nth-child(2) { animation-delay: .16s; }
.ffchat-typing i:nth-child(3) { animation-delay: .32s; }

@keyframes ffchat-blink {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40%           { opacity: 1;   transform: translateY(-2px); }
}

/* ---- composer ------------------------------------------------ */
.ffchat-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--hairline);
  background: var(--cream);
}

.ffchat-input {
  flex: 1;
  border: 1px solid var(--hairline-2);
  border-radius: 999px;
  padding: 10px 14px;
  font: inherit;
  font-size: .9rem;
  color: var(--ink);
  background: var(--cream);
}
.ffchat-input:focus {
  outline: none;
  border-color: var(--teal-600);
  box-shadow: 0 0 0 3px var(--teal-wash);
}

.ffchat-send {
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--brand-grad);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.ffchat-send:hover { filter: brightness(1.05); }

.ffchat-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- mobile: the panel becomes a sheet ----------------------- */
@media (max-width: 600px) {
  .ffchat-root { right: 16px; bottom: 16px; left: 16px; align-items: flex-end; }
  .ffchat-panel {
    width: 100%;
    max-width: none;
    height: min(78vh, calc(100vh - 96px));
    height: min(78dvh, calc(100dvh - 96px));
    border-radius: 18px;
  }
  .ffchat-nudge { max-width: 100%; }
}

/* ---- reduced motion: state changes, no travel ---------------- */
@media (prefers-reduced-motion: reduce) {
  .ffchat-launcher,
  .ffchat-launcher-mark,
  .ffchat-launcher-close,
  .ffchat-panel {
    transition: opacity 120ms ease;
    transform: none !important;
  }
  .ffchat-nudge { animation: none; }
  .ffchat-typing i { animation: none; opacity: .5; }
  .ffchat-launcher:hover { transform: none; }
}
