/* ChunkArc assistant widget.
 *
 * External file with no inline rules anywhere: the site runs a strict CSP
 * (style-src 'self'), so a style attribute would simply be dropped. Every
 * dynamic value the widget needs is therefore a class or a custom property
 * set on :root, never an inline declaration.
 *
 * The widget owns nothing outside .ca-chat-*, and reuses the site's tokens so
 * a change to the palette moves it too.
 */

:root {
  --ca-chat-panel: 420px;
  --ca-chat-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- Launcher ---------- */

.ca-chat-launcher {
  position: fixed;
  z-index: 70;
  right: clamp(14px, 3vw, 26px);
  bottom: clamp(14px, 3vw, 26px);
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  padding: 0;
  border: 1px solid rgba(94, 220, 255, 0.34);
  border-radius: 50%;
  background:
    radial-gradient(120% 120% at 30% 20%, rgba(94, 220, 255, 0.28), transparent 60%),
    linear-gradient(180deg, #0f2833 0%, #0a1a22 100%);
  box-shadow:
    0 10px 30px rgba(2, 7, 10, 0.55),
    0 0 0 0 rgba(94, 220, 255, 0.32);
  color: var(--cyan);
  cursor: pointer;
  transition:
    transform 220ms var(--ca-chat-ease),
    box-shadow 260ms ease,
    border-color 200ms ease,
    opacity 200ms ease,
    visibility 0s linear 200ms;
}

.ca-chat-launcher:hover,
.ca-chat-launcher:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(94, 220, 255, 0.6);
  box-shadow:
    0 14px 34px rgba(2, 7, 10, 0.6),
    0 0 0 6px rgba(94, 220, 255, 0.1);
}

.ca-chat-launcher:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.ca-chat-launcher:active {
  transform: translateY(0) scale(0.96);
}

.ca-chat-launcher svg {
  width: 23px;
  height: 23px;
  transition: transform 260ms var(--ca-chat-ease), opacity 160ms ease;
}

/* The icon swaps to a chevron while the panel is open, so the same control
   reads as "close" without moving or changing size. */
.ca-chat-launcher .ca-chat-icon-close {
  position: absolute;
  transform: rotate(-90deg) scale(0.6);
  opacity: 0;
}

.ca-chat-root.is-open .ca-chat-launcher .ca-chat-icon-open {
  transform: rotate(90deg) scale(0.6);
  opacity: 0;
}

.ca-chat-root.is-open .ca-chat-launcher .ca-chat-icon-close {
  transform: rotate(0) scale(1);
  opacity: 1;
}

/* The panel already has a labelled close button. Hiding the launcher while it
 * is open removes the competing close affordance and the visual overlap on a
 * compact viewport. */
.ca-chat-root.is-open .ca-chat-launcher {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px) scale(0.92);
}

/* One quiet pulse the first time a visitor lands, then never again. */
.ca-chat-launcher.is-new {
  animation: ca-chat-attention 2.8s ease-out 1.4s 2;
}

@keyframes ca-chat-attention {
  0%,
  100% {
    box-shadow:
      0 10px 30px rgba(2, 7, 10, 0.55),
      0 0 0 0 rgba(94, 220, 255, 0.32);
  }
  35% {
    box-shadow:
      0 10px 30px rgba(2, 7, 10, 0.55),
      0 0 0 12px rgba(94, 220, 255, 0);
  }
}

/* ---------- Panel ---------- */

.ca-chat-panel {
  position: fixed;
  z-index: 71;
  right: clamp(14px, 3vw, 26px);
  bottom: calc(clamp(14px, 3vw, 26px) + 66px);
  display: flex;
  flex-direction: column;
  width: min(var(--ca-chat-panel), calc(100vw - 28px));
  height: min(620px, calc(100vh - 132px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(63, 140, 255, 0.12), transparent 62%),
    linear-gradient(180deg, #0c1e26 0%, #081419 100%);
  box-shadow: 0 26px 70px rgba(2, 7, 10, 0.66);
  transform-origin: 100% 100%;
  transition:
    opacity 200ms ease,
    transform 320ms var(--ca-chat-ease),
    bottom 320ms var(--ca-chat-ease),
    visibility 320ms;
}

.ca-chat-root.is-open .ca-chat-panel {
  bottom: clamp(14px, 3vw, 26px);
}

.ca-chat-panel[hidden] {
  display: flex !important;
  visibility: hidden;
  opacity: 0;
  transform: translateY(14px) scale(0.96);
  pointer-events: none;
}

/* The first visit is a compact route selector, not an empty full-height chat
 * transcript. Once a question is asked the class is removed and the ordinary
 * scrolling conversation layout takes over. */
.ca-chat-panel.is-welcome {
  height: auto;
  max-height: min(560px, calc(100vh - 32px));
  max-height: min(560px, calc(100dvh - 32px));
}

.ca-chat-panel.is-welcome .ca-chat-log {
  flex: 0 1 auto;
  max-height: 348px;
}

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

.ca-chat-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 15px;
  border-bottom: 1px solid var(--line-2);
  background: rgba(255, 255, 255, 0.02);
}

.ca-chat-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(94, 220, 255, 0.28);
  border-radius: 9px;
  background: rgba(94, 220, 255, 0.1);
  color: var(--cyan);
}

.ca-chat-mark svg {
  width: 16px;
  height: 16px;
}

.ca-chat-titles {
  flex: 1;
  min-width: 0;
}

.ca-chat-title {
  margin: 0;
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 650;
  line-height: 1.25;
}

.ca-chat-sub {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.ca-chat-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, border-color 160ms ease;
}

.ca-chat-close:hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.ca-chat-close:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.ca-chat-close svg {
  width: 15px;
  height: 15px;
}

/* ---------- Log ---------- */

.ca-chat-log {
  flex: 1;
  /* Without this a flex child refuses to shrink below its content and the
     panel grows instead of the log scrolling. */
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 15px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}

.ca-chat-log::-webkit-scrollbar {
  width: 8px;
}

.ca-chat-log::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.16);
  background-clip: content-box;
}

.ca-chat-msg {
  max-width: 88%;
  margin: 0 0 10px;
  padding: 10px 13px;
  border: 1px solid var(--line-2);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--soft);
  font-size: 0.9rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  animation: ca-chat-in 260ms var(--ca-chat-ease) both;
}

.ca-chat-msg.is-user {
  margin-left: auto;
  border-color: rgba(94, 220, 255, 0.26);
  border-bottom-right-radius: 5px;
  background: rgba(94, 220, 255, 0.13);
  color: var(--text);
}

.ca-chat-msg.is-bot {
  border-bottom-left-radius: 5px;
}

.ca-chat-msg p {
  margin: 0 0 8px;
}

.ca-chat-msg p:last-child,
.ca-chat-msg ul:last-child {
  margin-bottom: 0;
}

.ca-chat-msg ul {
  margin: 0 0 8px;
  padding-left: 17px;
}

.ca-chat-msg li {
  margin: 0 0 3px;
}

.ca-chat-msg strong {
  color: var(--text);
  font-weight: 650;
}

.ca-chat-msg code {
  padding: 1px 5px;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  background: rgba(3, 10, 13, 0.55);
  color: var(--soft);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85em;
  overflow-wrap: anywhere;
}

.ca-chat-msg a {
  color: var(--cyan);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ca-chat-msg a:hover {
  text-decoration-thickness: 2px;
}

@keyframes ca-chat-in {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
}

/* ---------- Escalation ---------- */

.ca-chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: -2px 0 12px;
  animation: ca-chat-in 300ms var(--ca-chat-ease) 60ms both;
}

.ca-chat-action {
  padding: 7px 12px;
  border: 1px solid rgba(94, 220, 255, 0.3);
  border-radius: 999px;
  background: rgba(94, 220, 255, 0.08);
  color: var(--soft);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.ca-chat-action:hover {
  border-color: rgba(94, 220, 255, 0.55);
  background: rgba(94, 220, 255, 0.16);
  transform: translateY(-1px);
}

.ca-chat-action:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ---------- First-open guide ---------- */

.ca-chat-welcome {
  animation: ca-chat-in 260ms var(--ca-chat-ease) both;
}

.ca-chat-eyebrow,
.ca-chat-topic-label {
  margin: 0;
  color: var(--cyan);
  font-size: 0.67rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  line-height: 1.35;
  text-transform: uppercase;
}

.ca-chat-welcome-title {
  margin: 5px 0 0;
  color: var(--text);
  font-size: 1.12rem;
  font-weight: 680;
  letter-spacing: -0.02em;
  line-height: 1.22;
}

.ca-chat-welcome-body {
  margin: 8px 0 0;
  color: var(--soft);
  font-size: 0.84rem;
  line-height: 1.48;
}

.ca-chat-source {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  margin: 10px 0 15px;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.4;
}

.ca-chat-source::before {
  flex: none;
  width: 6px;
  height: 6px;
  margin-top: 0.28rem;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 3px rgba(94, 220, 255, 0.11);
  content: "";
}

.ca-chat-topic-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
}

.ca-chat-suggest {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.ca-chat-chip {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  min-height: 74px;
  padding: 10px 11px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--soft);
  font: inherit;
  text-align: left;
  cursor: pointer;
  animation: ca-chat-in 320ms var(--ca-chat-ease) both;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}

.ca-chat-chip:nth-child(2) {
  animation-delay: 60ms;
}

.ca-chat-chip:nth-child(3) {
  animation-delay: 120ms;
}

.ca-chat-chip:nth-child(4) {
  animation-delay: 180ms;
}

.ca-chat-chip:hover {
  border-color: rgba(94, 220, 255, 0.34);
  background: rgba(94, 220, 255, 0.07);
  transform: translateY(-1px);
}

.ca-chat-chip:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.ca-chat-chip-label,
.ca-chat-chip-detail {
  display: block;
  overflow-wrap: anywhere;
}

.ca-chat-chip-label {
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 650;
  line-height: 1.28;
}

.ca-chat-chip-detail {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.34;
}

/* ---------- Typing ---------- */

.ca-chat-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  width: max-content;
  margin: 0 0 10px;
  padding: 13px;
  border: 1px solid var(--line-2);
  border-radius: 13px;
  border-bottom-left-radius: 5px;
  background: rgba(255, 255, 255, 0.045);
  animation: ca-chat-in 200ms var(--ca-chat-ease) both;
}

.ca-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  opacity: 0.45;
  animation: ca-chat-dot 1.25s ease-in-out infinite;
}

.ca-chat-typing span:nth-child(2) {
  animation-delay: 0.16s;
}

.ca-chat-typing span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes ca-chat-dot {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

/* ---------- Composer ---------- */

.ca-chat-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 11px 12px;
  border-top: 1px solid var(--line-2);
  background: rgba(255, 255, 255, 0.02);
}

/* Auto-growing field. The wrapper is sized by a hidden copy of the text in a
   pseudo-element, and the textarea is stacked in the same grid cell — so the
   box follows the content without any script writing an inline height. */
.ca-chat-grow {
  position: relative;
  display: grid;
  flex: 1;
  min-width: 0;
  max-height: 108px;
  overflow-y: auto;
}

.ca-chat-grow::after {
  content: attr(data-value) " ";
  visibility: hidden;
  border-color: transparent;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Both boxes must measure identically or the mirror sizes to the wrong height.
   Width and style only: the colour is left to .ca-chat-input, which would
   otherwise lose to this more specific selector and render borderless. */
.ca-chat-grow::after,
.ca-chat-grow > .ca-chat-input {
  grid-area: 1 / 1 / 2 / 2;
  min-height: 40px;
  padding: 10px 12px;
  border-width: 1px;
  border-style: solid;
  font: inherit;
  font-size: 0.89rem;
  line-height: 1.45;
}

.ca-chat-input {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(3, 10, 13, 0.62);
  color: var(--text);
  font: inherit;
  font-size: 0.89rem;
  line-height: 1.45;
  resize: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.ca-chat-input::placeholder {
  color: rgba(159, 182, 192, 0.75);
}

.ca-chat-input:focus {
  border-color: rgba(94, 220, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(94, 220, 255, 0.12);
  outline: none;
}

.ca-chat-send {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(94, 220, 255, 0.34);
  border-radius: 11px;
  background: rgba(94, 220, 255, 0.14);
  color: var(--cyan);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease, opacity 160ms ease;
}

.ca-chat-send:hover:not(:disabled) {
  border-color: rgba(94, 220, 255, 0.6);
  background: rgba(94, 220, 255, 0.24);
  transform: translateY(-1px);
}

.ca-chat-send:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.ca-chat-send:disabled {
  opacity: 0.4;
  cursor: default;
}

.ca-chat-send svg {
  width: 17px;
  height: 17px;
}

.ca-chat-note {
  margin: 0;
  padding: 0 13px 10px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.4;
  text-align: center;
}

.ca-chat-note a {
  display: inline-flex;
  align-items: center;
  min-height: 46px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ca-chat-send { min-width: 46px; min-height: 46px; }

.ca-chat-note a:hover {
  color: var(--cyan);
}

/* ---------- Screen readers ---------- */

/* Public-site assistant: readable, quiet surfaces and persistent help routes. */
.ca-chat-panel {
  background: #0e181d;
  border-color: #34454d;
  border-radius: 12px;
  height: min(720px, calc(100dvh - 48px));
}
.ca-chat-panel.is-welcome { height: min(720px, calc(100dvh - 48px)); max-height: calc(100dvh - 48px); }
.ca-chat-panel.is-welcome .ca-chat-log { max-height: none; flex: 1; }
.ca-chat-head { padding: 12px 16px; background: #111f25; }
.ca-chat-mark { background: transparent; border: 0; box-shadow: none; }
.ca-chat-mark img { display: block; width: 32px; height: 32px; }
.ca-chat-title { font-size: 1rem; }
.ca-chat-sub { font-size: .8rem; color: #adbec7; }
.ca-chat-shortcuts { display: flex; flex-wrap: wrap; gap: 0 16px; padding: 4px 16px; border-bottom: 1px solid #2c3c44; flex: none; }
.ca-chat-shortcut { display: inline-flex; align-items: center; min-height: 44px; color: #62dbf6; font-size: .8rem; text-underline-offset: 3px; }
.ca-chat-shortcut:hover { text-decoration: underline; }
.ca-chat-log { padding: 20px 16px; }
.ca-chat-msg { font-size: .95rem; line-height: 1.65; border-radius: 8px; margin-bottom: 16px; }
.ca-chat-msg.is-bot { max-width: 100%; background: transparent; border-color: transparent; padding: 0 0 8px; }
.ca-chat-msg.is-user { background: #183842; border-color: #31535f; }
.ca-chat-msg ol { padding-left: 24px; margin: 8px 0; }
.ca-chat-msg ol:last-child { margin-bottom: 0; }
.ca-chat-msg li { padding-left: 4px; margin-bottom: 8px; }
.ca-chat-welcome-title { font-size: 1.3rem; line-height: 1.3; margin-top: 8px; }
.ca-chat-welcome-body { font-size: .94rem; line-height: 1.6; margin-bottom: 16px; }
.ca-chat-source { font-size: .8rem; color: #adbec7; margin-bottom: 20px; }
.ca-chat-chip { min-height: 88px; border-radius: 8px; padding: 12px; background: #15252c; }
.ca-chat-chip-label { font-size: .9rem; }
.ca-chat-chip-detail { font-size: .8rem; line-height: 1.45; color: #adbec7; }
.ca-chat-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0 16px; flex: none; }
.ca-chat-reset { background: transparent; border: 0; color: #adbec7; padding: 8px 0; min-height: 44px; font: inherit; font-size: .8rem; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.ca-chat-reset:disabled { opacity: .5; cursor: default; }
.ca-chat-counter { color: #adbec7; font-size: .75rem; font-variant-numeric: tabular-nums; }
.ca-chat-form { padding: 12px 16px; flex: none; }
.ca-chat-grow::after, .ca-chat-grow > .ca-chat-input { font-size: 16px; min-height: 46px; }
.ca-chat-input { border-radius: 8px; }
.ca-chat-send { border-radius: 8px; }
.ca-chat-safety { margin: 0; padding: 0 16px 4px; color: #adbec7; font-size: .75rem; line-height: 1.5; text-align: center; flex: none; }
.ca-chat-note { font-size: .75rem; padding: 0 16px 12px; flex: none; }
.ca-chat-note a { min-height: 0; display: inline; }
.ca-chat-action { min-height: 44px; display: inline-flex; align-items: center; border-radius: 8px; }
.ca-chat-root :is(button, a):focus-visible { outline: 2px solid #62dbf6; outline-offset: 3px; }

.ca-chat-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Phones ----------
 *
 * A 384px card floating over a 390px screen is just a worse full screen, so
 * below the breakpoint the panel becomes a sheet and the launcher hides while
 * it is open — the header close button is the only affordance needed.
 */

@media (max-width: 560px) {
  .ca-chat-panel {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 88vh;
    height: 88dvh;
    border-right: none;
    border-bottom: none;
    border-left: none;
    border-radius: 18px 18px 0 0;
    transform-origin: 50% 100%;
  }

  .ca-chat-panel[hidden] {
    transform: translateY(24px);
  }

  .ca-chat-root.is-open .ca-chat-panel {
    bottom: 0;
  }

  .ca-chat-panel.is-welcome {
    height: calc(100dvh - 16px);
    max-height: calc(100dvh - 16px);
  }

  .ca-chat-panel.is-welcome .ca-chat-log {
    max-height: none;
  }

  .ca-chat-log {
    padding: 14px;
  }

  .ca-chat-msg {
    max-width: 92%;
  }
}

@media (max-width: 359px) {
  .ca-chat-suggest {
    grid-template-columns: 1fr;
  }

  .ca-chat-panel.is-welcome .ca-chat-log {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .ca-chat-panel { height: calc(100dvh - 16px); max-height: calc(100dvh - 16px); }
  .ca-chat-note { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .ca-chat-head { padding: 8px 12px; }
  .ca-chat-shortcuts { padding-inline: 12px; gap: 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .ca-chat-launcher,
  .ca-chat-panel,
  .ca-chat-msg,
  .ca-chat-chip,
  .ca-chat-actions,
  .ca-chat-typing,
  .ca-chat-typing span,
  .ca-chat-launcher svg {
    animation: none !important;
    transition-duration: 1ms !important;
  }

  .ca-chat-panel[hidden] {
    transform: none;
  }
}
