/*
 * The chat page inside the iframe: the launcher while minimised, the chat
 * panel while open. --accent, --on-accent, --accent-ink (the accent made
 * readable on the panel, for text and lines) and --accent-edge (a line around
 * the shapes filled with an accent about the panel's own colour, else none)
 * come from the widget's config;
 * --gap, --launcher, --inset and the --callout ones from the screen size
 * (frame.js). The page's own background is transparent, so the host page
 * shows around the panel.
 */
:root {
  --bg: #ffffff;
  --ink: #14161b;
  --muted: #5d6470;
  --line: #e4e6ea;
  --bubble: #f1f2f4;
  --notice: #fdf3dc;
  --notice-ink: #6b4500;
  --accent: #2e5bd8;
  --accent-ink: #2e5bd8;
  --accent-edge: transparent;
  --on-accent: #ffffff;
  --gap: 24px;
  --launcher: 56px;
  --inset: 20px;
  --callout-width: 260px;
  --callout-gap: 12px;
  --callout-y: 20px;
  --msg-icon: 28px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #16181d;
  --ink: #eceef2;
  --muted: #a2a8b3;
  --line: #2b2f37;
  --bubble: #23262d;
  --notice: #3a2f17;
  --notice-ink: #f6dfa8;
}
/*
 * Dark controls and scrollbars inside the chat, but never on the page itself:
 * when the page's colour scheme differs from the iframe's (normal, set by the
 * embed code), browsers paint the whole iframe opaque.
 */
[data-theme='dark'] .panel,
[data-theme='dark'] .callout {
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
  background: transparent;
  overflow: hidden;
}
body {
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button,
textarea {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* The launcher sits in the iframe's corner, which the embed script puts in the page's corner. */
.launcher {
  position: fixed;
  display: grid;
  place-items: center;
  width: var(--launcher);
  height: var(--launcher);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow:
    0 6px 18px rgba(15, 18, 26, 0.24),
    0 1px 3px rgba(15, 18, 26, 0.18);
  transition:
    transform 0.16s ease,
    opacity 0.16s ease;
  -webkit-tap-highlight-color: transparent;
}
.launcher:hover {
  transform: scale(1.06);
}
.launcher:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
.launcher img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.launcher[hidden] {
  display: none;
}
[data-corner='bottom-right'] .launcher {
  right: var(--inset);
  bottom: var(--inset);
}
[data-corner='bottom-left'] .launcher {
  left: var(--inset);
  bottom: var(--inset);
}
[data-corner='top-right'] .launcher {
  right: var(--inset);
  top: var(--inset);
}
[data-corner='top-left'] .launcher {
  left: var(--inset);
  top: var(--inset);
}
[data-state='open'] .launcher {
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none;
}

/*
 * The launcher text: the company's words over its assistant label ("AI
 * assistant" unless the company set one), beside the launcher on the side
 * away from the edge. It wraps at --callout-width, and frame.js sizes the
 * iframe to fit it. It fades out after the workspace's seconds (.leaving),
 * and the iframe shrinks back to the launcher.
 */
.callout {
  position: fixed;
  width: max-content;
  max-width: var(--callout-width);
  padding: 9px 14px 10px;
  border-radius: 14px;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.3;
  overflow-wrap: anywhere;
  cursor: pointer;
  box-shadow:
    0 6px 18px rgba(15, 18, 26, 0.18),
    0 1px 3px rgba(15, 18, 26, 0.14);
  -webkit-tap-highlight-color: transparent;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
}
.callout.leaving {
  opacity: 0;
  transform: scale(0.96);
  pointer-events: none;
}
.callout[hidden],
[data-state='open'] .callout {
  display: none;
}
.callout strong {
  display: block;
  font-size: 15px;
  font-weight: 700;
}
.callout span {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  color: var(--muted);
}
[data-size='mobile'] .callout strong {
  font-size: 14px;
}
[data-size='mobile'] .callout span {
  font-size: 12px;
}
/* It shrinks toward the launcher as it fades. */
[data-corner$='right'] .callout {
  right: calc(var(--inset) + var(--launcher) + var(--callout-gap));
  transform-origin: right center;
}
[data-corner$='left'] .callout {
  left: calc(var(--inset) + var(--launcher) + var(--callout-gap));
  transform-origin: left center;
}
[data-corner^='bottom'] .callout {
  bottom: var(--callout-y);
}
[data-corner^='top'] .callout {
  top: var(--callout-y);
}

/* The open chat: the panel with the gap around it that the shadow needs. */
.panel {
  position: fixed;
  inset: var(--gap);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 16px;
  background: var(--bg);
  box-shadow:
    0 18px 50px rgba(15, 18, 26, 0.28),
    0 2px 8px rgba(15, 18, 26, 0.12);
}
.panel[hidden] {
  display: none;
}
[data-size='mobile'] .panel {
  inset: 0;
  border-radius: 0;
  box-shadow: none;
}

.head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px 14px 16px;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: inset 0 -1px 0 var(--accent-edge);
}
[data-size='mobile'] .head {
  padding-top: max(14px, env(safe-area-inset-top));
}
.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  overflow: hidden;
  border-radius: 50%;
  background: color-mix(in srgb, var(--on-accent) 16%, transparent);
}
.avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.who {
  flex: 1;
  min-width: 0;
}
.who h1 {
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.25;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.who p {
  margin: 0;
  font-size: 12px;
  opacity: 0.82;
}
.close {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}
.close:hover {
  background: color-mix(in srgb, var(--on-accent) 14%, transparent);
}
.close:focus-visible {
  outline-color: var(--on-accent);
}

.log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}
/* A message: an assistant's has the icon on its left, level with the bubble's last line. */
.msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 85%;
}
.msg.assistant {
  align-self: flex-start;
}
.msg.visitor {
  align-self: flex-end;
}
.msg .avatar {
  width: var(--msg-icon);
  height: var(--msg-icon);
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 0 0 1px var(--accent-edge);
}
.bubble {
  min-width: 0;
  padding: 9px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.assistant .bubble {
  background: var(--bubble);
  border-bottom-left-radius: 6px;
}
.visitor .bubble {
  background: var(--accent);
  color: var(--on-accent);
  border-bottom-right-radius: 6px;
  box-shadow: inset 0 0 0 1px var(--accent-edge);
}
.msg a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* The assistant's options: buttons under its reply, lined up with the bubble. Tapping one sends it. */
.options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 92%;
  margin: -2px 0 4px calc(var(--msg-icon) + 8px);
}
.options button {
  padding: 7px 13px;
  border: 1.5px solid var(--accent-ink);
  border-radius: 999px;
  background: var(--bg);
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.options button:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent-ink) 12%, var(--bg));
}
.options button:disabled {
  cursor: default;
}
.options.used button {
  border-color: var(--line);
  color: var(--muted);
  opacity: 0.7;
}

/* The parts plugins add under a reply (README.md "Plugins"), drawn by v2/parts/*.js. */
.parts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 92%;
  margin: -2px 0 4px calc(var(--msg-icon) + 8px);
}
.parts:empty {
  display: none;
}

.typing {
  display: flex;
  gap: 4px;
  padding: 14px 14px;
}
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) {
  animation-delay: 0.15s;
}
.typing span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

.notice {
  margin: 0 12px 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--notice);
  color: var(--notice-ink);
  font-size: 13px;
}
.notice[hidden] {
  display: none;
}
.compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}
[data-size='mobile'] .compose {
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.compose textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  /* 16px keeps iOS from zooming in when the box gets focus. */
  font-size: 16px;
  line-height: 1.4;
  resize: none;
}
.compose textarea:focus {
  outline: none;
  border-color: var(--accent-ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-ink) 24%, transparent);
}
.compose textarea:disabled {
  opacity: 0.7;
}
.compose button {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: inset 0 0 0 1px var(--accent-edge);
  cursor: pointer;
}
.compose button:disabled {
  opacity: 0.5;
  cursor: default;
}

@media (prefers-reduced-motion: reduce) {
  .launcher,
  .callout,
  .typing span {
    transition: none;
    animation: none;
  }
  .typing span {
    opacity: 0.6;
  }
}
