/* ==========================================================================
   CometX — site assistant
   A launcher, a panel, and the smoke animation behind the comet mark.
   All motion is disabled under prefers-reduced-motion.
   ========================================================================== */

.cx-chat {
  --chat-w: 396px;
  position: fixed;
  right: clamp(1rem, 3vw, 2rem);
  bottom: clamp(1rem, 3vw, 2rem);
  z-index: 90;
  font-family: "Source Serif 4", Georgia, serif;
}

/* ---------- Launcher ---------------------------------------------------- */
.cx-chat__launch {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  background: var(--ink);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: .7rem 1.25rem .7rem .7rem;
  cursor: pointer;
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: .95rem;
  font-weight: 600;
  letter-spacing: -.01em;
  box-shadow: 0 10px 30px rgba(12, 26, 46, .28);
  transition: transform .2s ease, box-shadow .2s ease;
}
.cx-chat__launch:hover { transform: translateY(-2px); box-shadow: 0 14px 38px rgba(12, 26, 46, .34); }
.cx-chat__launch:focus-visible { outline: 3px solid var(--b-cyan); outline-offset: 3px; }
.cx-chat.is-open .cx-chat__launch { display: none; }

.cx-chat__badge {
  position: absolute;
  top: -2px; right: -2px;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--b-lime);
  border: 2px solid var(--ink);
}

/* ---------- The mark, and the smoke behind it --------------------------- */
.cx-mark {
  position: relative;
  width: 34px; height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, .08);
}
.cx-mark svg { width: 24px; height: 24px; display: block; position: relative; z-index: 2; }

/* Three drifting plumes, only visible while the assistant is working. */
.cx-mark__smoke {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transition: opacity .5s ease;
  z-index: 1;
}
.cx-mark__smoke i {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(closest-side,
              rgba(255, 255, 255, .82), rgba(255, 255, 255, .34) 46%, transparent 72%);
  filter: blur(7px);
}
.cx-mark__smoke i:nth-child(1) { animation: smoke-a 4.2s ease-in-out infinite; }
.cx-mark__smoke i:nth-child(2) { animation: smoke-b 5.6s ease-in-out infinite .5s; }
.cx-mark__smoke i:nth-child(3) { animation: smoke-c 6.8s ease-in-out infinite 1.1s; }

.cx-chat.is-thinking .cx-mark__smoke,
.cx-chat__avatar.is-thinking .cx-mark__smoke { opacity: 1; }

@keyframes smoke-a {
  0%   { transform: translate3d(0,0,0) scale(.62); opacity: .18; }
  45%  { transform: translate3d(-9px,-13px,0) scale(1.06); opacity: .5; }
  100% { transform: translate3d(-16px,-24px,0) scale(1.34); opacity: 0; }
}
@keyframes smoke-b {
  0%   { transform: translate3d(0,0,0) scale(.54); opacity: .14; }
  50%  { transform: translate3d(8px,-12px,0) scale(1.02); opacity: .42; }
  100% { transform: translate3d(14px,-23px,0) scale(1.3); opacity: 0; }
}
@keyframes smoke-c {
  0%   { transform: translate3d(0,0,0) scale(.5); opacity: .12; }
  50%  { transform: translate3d(-2px,-15px,0) scale(.96); opacity: .36; }
  100% { transform: translate3d(3px,-27px,0) scale(1.26); opacity: 0; }
}

/* On a light panel the plumes need a soft grey edge to read at all. */
.cx-chat__avatar .cx-mark { background: var(--ink); width: 30px; height: 30px; }
.cx-chat__avatar .cx-mark svg { width: 20px; height: 20px; }

/* ---------- Panel ------------------------------------------------------- */
.cx-chat__panel {
  width: min(92vw, var(--chat-w));
  max-height: min(76vh, 620px);
  display: none;
  flex-direction: column;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(12, 26, 46, .26);
}
.cx-chat.is-open .cx-chat__panel {
  display: flex;
  animation: chat-in .28s cubic-bezier(.22,.68,.32,1) both;
}
@keyframes chat-in {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.cx-chat__head {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .85rem 1rem;
  background: var(--ink);
  color: #fff;
}
.cx-chat__head .cx-mark { background: rgba(255,255,255,.1); }
.cx-chat__title { flex: 1 1 auto; min-width: 0; }
.cx-chat__title b {
  display: block;
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: .98rem;
  letter-spacing: -.01em;
}
.cx-chat__title span {
  display: block;
  font-family: "IBM Plex Mono", monospace;
  font-size: .62rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #A9BBD2;
  margin-top: 1px;
}
.cx-chat__close {
  background: transparent;
  border: 0;
  color: #C6D2E2;
  font-size: 1.5rem;
  line-height: 1;
  padding: .25rem .5rem;
  border-radius: 4px;
  cursor: pointer;
}
.cx-chat__close:hover { background: rgba(255,255,255,.12); color: #fff; }

/* ---------- Log --------------------------------------------------------- */
.cx-chat__log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .8rem;
  background: var(--paper);
  scroll-behavior: smooth;
}
.cx-msg { display: flex; gap: .6rem; align-items: flex-start; max-width: 100%; }
.cx-msg__body {
  font-size: .95rem;
  line-height: 1.55;
  border-radius: 10px;
  padding: .7rem .85rem;
  max-width: 86%;
  animation: msg-in .3s cubic-bezier(.22,.68,.32,1) both;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.cx-msg--bot .cx-msg__body { background: var(--white); border: 1px solid var(--line); color: var(--ink); }
.cx-msg--user { flex-direction: row-reverse; }
.cx-msg--user .cx-msg__body { background: var(--ink); color: #fff; }
.cx-msg__body p { margin: 0 0 .6rem; }
.cx-msg__body p:last-child { margin-bottom: 0; }
.cx-msg__body a { color: var(--b-lime); font-weight: 600; }
.cx-msg--user .cx-msg__body a { color: #CFE08F; }
.cx-msg__body ul { margin: .4rem 0 0; padding-left: 1.1rem; }
.cx-msg__body li { margin-bottom: .3rem; }

/* Typing indicator */
.cx-typing { display: inline-flex; gap: 4px; align-items: center; padding: .2rem 0; }
.cx-typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--slate-2);
  animation: typing 1.2s ease-in-out infinite;
}
.cx-typing i:nth-child(2) { animation-delay: .16s; }
.cx-typing i:nth-child(3) { animation-delay: .32s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Suggested replies ------------------------------------------ */
.cx-chips { display: flex; flex-wrap: wrap; gap: .4rem; padding: 0 1rem .75rem; background: var(--paper); }
.cx-chip {
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: .82rem;
  font-weight: 500;
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px;
  padding: .42rem .8rem;
  cursor: pointer;
  transition: border-color .16s ease, color .16s ease, transform .16s ease;
}
.cx-chip:hover { border-color: var(--b-lime); color: #4E6615; transform: translateY(-1px); }

/* ---------- Composer ---------------------------------------------------- */
.cx-chat__form {
  display: flex;
  gap: .5rem;
  padding: .75rem;
  border-top: 1px solid var(--line);
  background: var(--white);
}
.cx-chat__form input {
  flex: 1 1 auto;
  min-width: 0;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: .95rem;
  color: var(--ink);
  border: 1px solid var(--slate-2);
  border-radius: 999px;
  padding: .6rem .9rem;
  background: var(--white);
}
.cx-chat__form input:focus { border-color: var(--b-lime); outline: 2px solid rgba(97,125,26,.18); }
.cx-chat__send {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .18s ease, transform .18s ease;
}
.cx-chat__send:hover { background: #4E6615; transform: scale(1.05); }
.cx-chat__send svg { width: 17px; height: 17px; fill: currentColor; }

.cx-chat__foot {
  padding: 0 1rem .7rem;
  background: var(--white);
  font-family: "IBM Plex Mono", monospace;
  font-size: .58rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--slate);
  text-align: center;
}

/* ---------- Inline handoff form ----------------------------------------- */
.cx-handoff { display: grid; gap: .55rem; margin-top: .6rem; }
.cx-handoff input, .cx-handoff textarea {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: .9rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .5rem .65rem;
  width: 100%;
  color: var(--ink);
  background: var(--white);
}
.cx-handoff textarea { min-height: 66px; resize: vertical; }
.cx-handoff button {
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: .88rem; font-weight: 600;
  background: var(--ink); color: #fff;
  border: 0; border-radius: 999px; padding: .55rem 1rem; cursor: pointer;
  justify-self: start;
}
.cx-handoff button:hover { background: #4E6615; }

.cx-status {
  display: inline-flex; align-items: center; gap: .4rem;
  font-family: "IBM Plex Mono", monospace; font-size: .62rem;
  letter-spacing: .1em; text-transform: uppercase; color: var(--slate);
}
.cx-status i { width: 7px; height: 7px; border-radius: 50%; background: var(--b-lime); flex: none; }
.cx-status.is-away i { background: var(--b-amber); }

@media (max-width: 480px) {
  .cx-chat { right: .75rem; bottom: .75rem; left: .75rem; }
  .cx-chat__panel { width: 100%; max-height: 74vh; }
  .cx-chat__launch { width: 100%; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  .cx-mark__smoke i,
  .cx-typing i { animation: none !important; }
  .cx-mark__smoke { opacity: 0 !important; }
  .cx-chat.is-open .cx-chat__panel,
  .cx-msg__body { animation: none !important; }
  .cx-chat__launch:hover, .cx-chat__send:hover { transform: none; }
}

@media print { .cx-chat { display: none !important; } }

/* Visually hidden, still announced — used for the assistant's field labels. */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Additions: presence, nudge, search results, live-chat button
   ========================================================================== */
.cx-presence {
  display: inline-flex !important;
  align-items: center;
  gap: .4rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: .6rem !important;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #A9BBD2 !important;
  margin-top: 2px;
}
.cx-presence i {
  width: 7px; height: 7px; border-radius: 50%;
  background: #8FD14F; flex: none;
  box-shadow: 0 0 0 0 rgba(143, 209, 79, .7);
  animation: pulse-dot 2.4s ease-out infinite;
}
.cx-presence.is-away i { background: #E9B872; animation: none; }
@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0 rgba(143, 209, 79, .55); }
  70%  { box-shadow: 0 0 0 7px rgba(143, 209, 79, 0); }
  100% { box-shadow: 0 0 0 0 rgba(143, 209, 79, 0); }
}

/* Dim secondary text inside a bubble */
.cx-msg__body .cx-dim { color: var(--slate); font-size: .86rem; line-height: 1.45; }
.cx-msg--user .cx-msg__body .cx-dim { color: #C6D2E2; }
.cx-msg__body ul li { margin-bottom: .55rem; }

/* Live chat button */
.cx-btn-live {
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: .9rem; font-weight: 600;
  background: #617D1A; color: #fff;
  border: 0; border-radius: 999px;
  padding: .55rem 1.1rem; cursor: pointer;
  display: inline-flex; align-items: center; gap: .5rem;
  transition: background .18s ease, transform .18s ease;
}
.cx-btn-live::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: #CFE08F; flex: none;
}
.cx-btn-live:hover { background: #4E6615; transform: translateY(-1px); }
.cx-btn-live:disabled { opacity: .7; cursor: default; transform: none; }

/* Proactive nudge */
.cx-nudge {
  position: relative;
  width: min(78vw, 270px);
  margin: 0 0 .7rem auto;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 3px solid var(--b-lime);
  border-radius: 10px;
  padding: .85rem 2rem .85rem 1rem;
  box-shadow: 0 12px 32px rgba(12, 26, 46, .18);
  cursor: pointer;
  animation: nudge-in .45s cubic-bezier(.22,.68,.32,1) both;
}
.cx-nudge[hidden] { display: none; }
.cx-nudge p {
  margin: 0;
  font-size: .9rem;
  line-height: 1.5;
  color: var(--ink-soft);
}
.cx-nudge__x {
  position: absolute; top: .3rem; right: .4rem;
  background: none; border: 0; cursor: pointer;
  font-size: 1.15rem; line-height: 1; color: var(--slate-2);
  padding: .25rem .4rem; border-radius: 4px;
}
.cx-nudge__x:hover { background: var(--frost); color: var(--ink); }
@keyframes nudge-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   Animated comet mark — used in the launcher, header and every bot bubble
   ========================================================================== */
.cx-mark svg { overflow: visible; }
.cx-mark__head { transform-origin: 27px 13px; }
.cx-mark__tail path { transform-origin: 20px 20px; }

@media (prefers-reduced-motion: no-preference) {
  /* Idle: the head breathes very slightly. */
  .cx-chat__launch .cx-mark__head { animation: head-breathe 4.5s ease-in-out infinite; }
  @keyframes head-breathe {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.09); }
  }

  /* Hover: the comet leans forward and the tail streaks. */
  .cx-chat__launch:hover .cx-mark__head { animation: head-dart .7s cubic-bezier(.22,.68,.32,1); }
  .cx-chat__launch:hover .cx-mark__tail path:nth-child(1) { animation: streak .7s ease-out; }
  .cx-chat__launch:hover .cx-mark__tail path:nth-child(2) { animation: streak .7s ease-out .06s; }
  .cx-chat__launch:hover .cx-mark__tail path:nth-child(3) { animation: streak .7s ease-out .12s; }
  @keyframes head-dart {
    0%   { transform: translate(0,0) scale(1); }
    40%  { transform: translate(2.5px,-2.5px) scale(1.14); }
    100% { transform: translate(0,0) scale(1); }
  }
  @keyframes streak {
    0%   { transform: translate(0,0); opacity: 1; }
    45%  { transform: translate(-3px,3px); opacity: .45; }
    100% { transform: translate(0,0); opacity: 1; }
  }

  /* Thinking: the head orbits gently while the smoke drifts. */
  .cx-chat.is-thinking .cx-chat__launch .cx-mark__head,
  .cx-chat__avatar.is-thinking .cx-mark__head { animation: head-orbit 2.4s ease-in-out infinite; }
  @keyframes head-orbit {
    0%, 100% { transform: translate(0,0) scale(1); }
    25%      { transform: translate(1.6px,-1.6px) scale(1.06); }
    75%      { transform: translate(-1.6px,1.2px) scale(.97); }
  }
}

/* ==========================================================================
   Persistent action bar
   "Talk to a person" is the one thing nobody should have to hunt for, so it
   sits above the conversation at all times rather than behind a suggestion.
   ========================================================================== */
.cx-chat__bar {
  display: flex;
  gap: .4rem;
  padding: .6rem .7rem;
  background: var(--frost);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.cx-bar-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: .78rem;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .4rem .7rem;
  cursor: pointer;
  transition: border-color .16s ease, color .16s ease, transform .16s ease;
}
.cx-bar-btn svg { width: 13px; height: 13px; fill: currentColor; }
.cx-bar-btn:hover { border-color: var(--b-lime); color: #4E6615; transform: translateY(-1px); }
#cx-bar-human {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
#cx-bar-human:hover { background: #4E6615; border-color: #4E6615; color: #fff; }
@media (prefers-reduced-motion: reduce) { .cx-bar-btn:hover { transform: none; } }
