/* ===========================================================================
   Conversational chat widget — TwinFold styling
   ===========================================================================
   Every selector is scoped under #tfc-chat and every class carries the
   tfc-chat- prefix, so a docked widget that renders on every page cannot bleed
   into the theme around it. There are deliberately no html/body rules.

   Palette follows static/css/legacy-form.css (brand blue #0c5081, accent
   orange #f05a2b, pill buttons, soft cards) so the widget reads as part of the
   site rather than as a third-party embed. Blue carries the chrome — launcher,
   header, the visitor's own bubbles — and orange is reserved for the single
   primary call to action at the end of the conversation.

   The brand colour is exposed as both a hex and an "r, g, b" triple: the
   launcher shadow, the attention pulse and the choice-button hover all need it
   at partial alpha, and the reference sheet hardcoded the colour in those five
   places, which is exactly how a rebrand ends up half-finished.

   Behaviour lives in static/js/chat-funnel.js; markup in
   templates/partials/chat_funnel.html.
   =========================================================================== */

#tfc-chat {
  --tfc-chat-brand: #0c5081;
  --tfc-chat-brand-dark: #06304f;
  --tfc-chat-brand-rgb: 12, 80, 129;
  --tfc-chat-accent: #f05a2b;
  --tfc-chat-accent-dark: #d64717;
  --tfc-chat-accent-rgb: 240, 90, 43;
  --tfc-chat-ink: #051c2e;
  --tfc-chat-text: #3e4555;
  --tfc-chat-muted: #8d97ad;
  --tfc-chat-rule: #e4e9f0;
  --tfc-chat-paper: #f6f8fb;
  --tfc-chat-danger: #c0392b;
  --tfc-chat-radius: 18px;
  /* No font stack on purpose: the site loads its own, and the widget should
     inherit it rather than announce itself with a different face. */
}

#tfc-chat *,
#tfc-chat *::before,
#tfc-chat *::after { box-sizing: border-box; }

/* Form controls do not inherit the page font by default. */
#tfc-chat button,
#tfc-chat input,
#tfc-chat select,
#tfc-chat textarea { font-family: inherit; }

/* Focus is moved around programmatically (open, per step, close), so keyboard
   users need to be able to see where it landed. */
#tfc-chat :focus-visible {
  outline: 3px solid rgba(var(--tfc-chat-accent-rgb), 0.55);
  outline-offset: 2px;
}
/* ...except the dialog itself, which is only focused to announce it. */
#tfc-chat .tfc-chat-app:focus,
#tfc-chat .tfc-chat-app:focus-visible { outline: none; }

/* ---- Floating launcher bubble ------------------------------------------ */

#tfc-chat .tfc-chat-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--tfc-chat-brand), var(--tfc-chat-brand-dark));
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 20px rgba(var(--tfc-chat-brand-rgb), 0.45);
  z-index: 2147483000;
  transition: transform 0.15s, box-shadow 0.15s;
}
#tfc-chat .tfc-chat-launcher:hover {
  transform: scale(1.06);
  box-shadow: 0 8px 24px rgba(var(--tfc-chat-brand-rgb), 0.55);
}
#tfc-chat .tfc-chat-launcher .tfc-chat-launcher-close { display: none; }
/* Open widget: the launcher becomes an X. */
#tfc-chat.tfc-chat-open .tfc-chat-launcher .tfc-chat-launcher-open { display: none; }
#tfc-chat.tfc-chat-open .tfc-chat-launcher .tfc-chat-launcher-close { display: block; }

/* Gentle attention pulse until first opened. */
#tfc-chat .tfc-chat-launcher.tfc-chat-pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(var(--tfc-chat-brand-rgb), 0.5);
  animation: tfc-chat-pulse 2s infinite;
}
@keyframes tfc-chat-pulse {
  70%  { box-shadow: 0 0 0 14px rgba(var(--tfc-chat-brand-rgb), 0); }
  100% { box-shadow: 0 0 0 0 rgba(var(--tfc-chat-brand-rgb), 0); }
}

/* ---- Teaser popup ------------------------------------------------------- */

#tfc-chat .tfc-chat-teaser {
  position: fixed;
  right: 20px;
  bottom: 92px;
  /* Size to the message so it stays on one line, but never wider than the
     viewport (small phones fall back to wrapping via the media query below). */
  width: max-content;
  max-width: calc(100vw - 40px);
  background: #fff;
  border-radius: 16px;
  padding: 16px 16px 14px;
  box-shadow: 0 10px 34px rgba(5, 28, 46, 0.22);
  z-index: 2147482999;
  animation: tfc-chat-pop 0.2s ease-out;
  cursor: pointer;
}
#tfc-chat .tfc-chat-teaser[hidden] { display: none; }

#tfc-chat .tfc-chat-teaser-badge {
  position: absolute;
  top: -8px;
  left: -8px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--tfc-chat-accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(5, 28, 46, 0.2);
}
#tfc-chat .tfc-chat-teaser-badge[hidden] { display: none; }

#tfc-chat .tfc-chat-teaser-text {
  font-size: 15px;
  line-height: 1.4;
  color: var(--tfc-chat-ink);
  margin-bottom: 12px;
  white-space: nowrap;   /* keep the question on a single line */
  padding-right: 14px;   /* clear the close (x) button */
}
/* On narrow phones let it wrap again so it cannot overflow the screen. */
@media (max-width: 380px) {
  #tfc-chat .tfc-chat-teaser-text { white-space: normal; padding-right: 0; }
}

#tfc-chat .tfc-chat-teaser-close {
  position: absolute;
  top: 8px;
  right: 10px;
  border: none;
  background: none;
  font-size: 18px;
  line-height: 1;
  color: var(--tfc-chat-muted);
  cursor: pointer;
}
#tfc-chat .tfc-chat-teaser-close:hover { color: var(--tfc-chat-text); }

#tfc-chat .tfc-chat-teaser-actions { display: flex; gap: 8px; }
/* No quick-reply buttons: drop the empty actions row and the gap above it so
   the teaser is a tidy single-line nudge. */
#tfc-chat .tfc-chat-teaser-actions:empty { display: none; }
#tfc-chat .tfc-chat-teaser:has(.tfc-chat-teaser-actions:empty) .tfc-chat-teaser-text {
  margin-bottom: 0;
}

#tfc-chat .tfc-chat-teaser-btn {
  flex: 1 1 0;
  appearance: none;
  border: 1.5px solid var(--tfc-chat-brand);
  background: #fff;
  color: var(--tfc-chat-brand);
  padding: 9px 14px;
  border-radius: 60px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
#tfc-chat .tfc-chat-teaser-btn:hover {
  background: var(--tfc-chat-brand);
  color: #fff;
}

/* ---- Chat shell — docked bottom-right, hidden until opened -------------- */

#tfc-chat .tfc-chat-app {
  position: fixed;
  right: 20px;
  bottom: 92px;
  display: flex;
  flex-direction: column;
  width: 380px;
  height: min(620px, calc(100dvh - 112px));
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(5, 28, 46, 0.24);
  z-index: 2147483001;
  transform-origin: bottom right;
  animation: tfc-chat-slide-up 0.22s ease-out;
}
#tfc-chat .tfc-chat-app[hidden] { display: none; }

@keyframes tfc-chat-slide-up {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* On phones the open chat takes the full screen. */
@media (max-width: 480px) {
  #tfc-chat .tfc-chat-app {
    right: 0;
    bottom: 0;
    left: 0;
    top: 0;
    width: 100%;
    height: 100dvh;
    border-radius: 0;
  }
}

/* ---- Header ------------------------------------------------------------- */

#tfc-chat .tfc-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--tfc-chat-brand), var(--tfc-chat-brand-dark));
  color: #fff;
  flex: 0 0 auto;
}
#tfc-chat .tfc-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
}
#tfc-chat .tfc-chat-header-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  flex: 1 1 auto;
  min-width: 0;
}
#tfc-chat .tfc-chat-title { font-weight: 600; font-size: 15px; }
#tfc-chat .tfc-chat-status {
  font-size: 12px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 5px;
}
#tfc-chat .tfc-chat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
}
#tfc-chat .tfc-chat-min {
  border: none;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}
#tfc-chat .tfc-chat-min:hover { background: rgba(255, 255, 255, 0.32); }

/* ---- Message area ------------------------------------------------------- */

#tfc-chat .tfc-chat-window {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--tfc-chat-paper);
  scroll-behavior: smooth;
}

#tfc-chat .tfc-chat-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--tfc-chat-radius);
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  animation: tfc-chat-pop 0.18s ease-out;
}
@keyframes tfc-chat-pop {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
#tfc-chat .tfc-chat-msg.tfc-chat-bot {
  align-self: flex-start;
  background: #fff;
  color: var(--tfc-chat-text);
  border: 1px solid var(--tfc-chat-rule);
  border-bottom-left-radius: 5px;
}
#tfc-chat .tfc-chat-msg.tfc-chat-user {
  align-self: flex-end;
  background: var(--tfc-chat-brand);
  color: #fff;
  border-bottom-right-radius: 5px;
}

/* Typing indicator */
#tfc-chat .tfc-chat-typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--tfc-chat-rule);
  border-radius: var(--tfc-chat-radius);
  border-bottom-left-radius: 5px;
  padding: 12px 16px;
  display: inline-flex;
  gap: 4px;
}
#tfc-chat .tfc-chat-typing span {
  width: 7px;
  height: 7px;
  background: var(--tfc-chat-muted);
  border-radius: 50%;
  animation: tfc-chat-blink 1.2s infinite ease-in-out both;
}
#tfc-chat .tfc-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
#tfc-chat .tfc-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes tfc-chat-blink {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* ---- Input bar ---------------------------------------------------------- */

#tfc-chat .tfc-chat-input-bar {
  flex: 0 0 auto;
  padding: 12px;
  border-top: 1px solid var(--tfc-chat-rule);
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Button choices */
#tfc-chat .tfc-chat-choices { display: flex; flex-direction: column; gap: 8px; }
#tfc-chat .tfc-chat-choice-btn {
  appearance: none;
  border: 1.5px solid var(--tfc-chat-brand);
  background: #fff;
  color: var(--tfc-chat-brand);
  padding: 12px 16px;
  border-radius: 60px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.05s, box-shadow 0.15s;
}
#tfc-chat .tfc-chat-choice-btn:hover {
  background: var(--tfc-chat-brand);
  color: #fff;
  box-shadow: 0 4px 12px rgba(var(--tfc-chat-brand-rgb), 0.28);
}
#tfc-chat .tfc-chat-choice-btn:active { transform: scale(0.98); }
#tfc-chat .tfc-chat-choice-btn:disabled {
  opacity: 0.45;
  cursor: default;
  background: #fff;
  color: var(--tfc-chat-brand);
  box-shadow: none;
}

/* Text input row */
#tfc-chat .tfc-chat-text-row { display: flex; gap: 8px; }
#tfc-chat .tfc-chat-text-row input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 12px 16px;
  border: 1.5px solid var(--tfc-chat-rule);
  border-radius: 60px;
  background: #fff;
  color: var(--tfc-chat-text);
  font-size: 16px; /* 16px avoids iOS zoom-on-focus */
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#tfc-chat .tfc-chat-text-row input:focus {
  border-color: var(--tfc-chat-brand);
  box-shadow: 0 0 0 3px rgba(var(--tfc-chat-brand-rgb), 0.15);
}
#tfc-chat .tfc-chat-text-row button {
  flex: 0 0 auto;
  border: none;
  background: var(--tfc-chat-brand);
  color: #fff;
  padding: 0 20px;
  border-radius: 60px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
#tfc-chat .tfc-chat-text-row button:hover { background: var(--tfc-chat-brand-dark); }
#tfc-chat .tfc-chat-text-row button:disabled { opacity: 0.5; cursor: default; }

/* Per-step validation message. role="alert" in the markup, so it announces as
   soon as it gains text; empty it collapses and takes no room. */
#tfc-chat .tfc-chat-field-error {
  padding-left: 16px;
  font-size: 13px;
  color: var(--tfc-chat-danger);
}
#tfc-chat .tfc-chat-field-error:empty { display: none; }

/* ---- Consent (TCPA opt-in) ---------------------------------------------- */

#tfc-chat .tfc-chat-consent {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0;
  background: var(--tfc-chat-paper);
  border: 1px solid var(--tfc-chat-rule);
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
}
#tfc-chat .tfc-chat-consent-check {
  margin-top: 2px;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: var(--tfc-chat-brand);
  cursor: pointer;
}
#tfc-chat .tfc-chat-consent-text {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--tfc-chat-muted);
}

/* ---- Final call to action ----------------------------------------------- */

#tfc-chat .tfc-chat-cta-btn {
  display: block;
  text-align: center;
  text-decoration: none;
  background: var(--tfc-chat-accent);
  color: #fff;
  padding: 14px 18px;
  border-radius: 60px;
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(var(--tfc-chat-accent-rgb), 0.3);
  transition: background 0.15s, box-shadow 0.15s;
}
#tfc-chat .tfc-chat-cta-btn:hover,
#tfc-chat .tfc-chat-cta-btn:focus {
  background: var(--tfc-chat-accent-dark);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 8px 20px rgba(var(--tfc-chat-accent-rgb), 0.38);
}

/* ---- "Captured lead" card, preview mode only (?chat=preview) ------------ */

#tfc-chat .tfc-chat-summary {
  align-self: stretch;
  background: #fff;
  border: 1px solid var(--tfc-chat-rule);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14px;
  animation: tfc-chat-pop 0.18s ease-out;
}
#tfc-chat .tfc-chat-summary-title {
  font-weight: 700;
  color: var(--tfc-chat-brand);
  margin-bottom: 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
#tfc-chat .tfc-chat-summary-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px solid var(--tfc-chat-rule);
}
#tfc-chat .tfc-chat-summary-row:last-child { border-bottom: none; }
#tfc-chat .tfc-chat-summary-key { color: var(--tfc-chat-muted); }
#tfc-chat .tfc-chat-summary-val {
  color: var(--tfc-chat-ink);
  font-weight: 600;
  text-align: right;
  word-break: break-word;
}

/* ---- Reduced motion ------------------------------------------------------
   Same approach as static/css/legacy-form.css: switch the motion off, keep the
   layout identical. The typing dots stop blinking but stay visible, so the
   indicator still reads as "the bot is composing". */

@media (prefers-reduced-motion: reduce) {
  #tfc-chat .tfc-chat-launcher.tfc-chat-pulse::after,
  #tfc-chat .tfc-chat-teaser,
  #tfc-chat .tfc-chat-app,
  #tfc-chat .tfc-chat-msg,
  #tfc-chat .tfc-chat-summary { animation: none; }

  #tfc-chat .tfc-chat-typing span {
    animation: none;
    opacity: 1;
    transform: none;
  }

  #tfc-chat .tfc-chat-launcher,
  #tfc-chat .tfc-chat-teaser-btn,
  #tfc-chat .tfc-chat-choice-btn,
  #tfc-chat .tfc-chat-cta-btn,
  #tfc-chat .tfc-chat-text-row input,
  #tfc-chat .tfc-chat-text-row button { transition: none; }

  #tfc-chat .tfc-chat-launcher:hover { transform: none; }
  #tfc-chat .tfc-chat-window { scroll-behavior: auto; }
}
