/* Chat widget — talks to /api/chat (functions/api/chat.js). Built by chat.js.
   Flat like the rest of the site: no borders, no shadows, no gradients.
   Tokens fall back to neutral values so the two files can move to another site. */
.cb {
  --cb-bg: #FCFBFB;            /* pearl */
  --cb-ink: #1b2b4a;
  --cb-ink-2: rgba(27, 43, 74, .62);
  --cb-fill: #ECEEF3;
  --cb-brand: var(--bg, #2f4d80);
  --cb-accent: var(--accent, #F7D794);
  --cb-radius: var(--radius, 32px);
  --cb-ease: var(--ease, cubic-bezier(.16, 1, .3, 1));
  font-family: var(--sans, system-ui, sans-serif);
}

/* ---------- launcher ---------- */
.cb-launch {
  position: fixed; right: 20px; bottom: 20px; z-index: 80;
  width: 60px; height: 60px; border: 0; padding: 0; border-radius: 18px;
  display: grid; place-items: center; cursor: pointer;
  background: var(--cb-bg); color: var(--cb-brand);
  transition: background 120ms steps(1), opacity 600ms var(--cb-ease), transform 500ms var(--cb-ease);
}
.cb-launch:hover { background: var(--cb-accent); }
.cb-launch:focus-visible, .cb-close:focus-visible, .cb-send:focus-visible, .cb-chip:focus-visible { outline: 3px solid var(--cb-accent); outline-offset: 3px; }
.cb-launch svg { width: 30px; height: 30px; }
.cb-launch .cb-dot { animation: cb-type 1.4s var(--cb-ease) 2.2s 2 both; }
.cb-launch .cb-dot:nth-child(3) { animation-delay: 2.35s; }
.cb-launch .cb-dot:nth-child(4) { animation-delay: 2.5s; }
@keyframes cb-type { 0%, 100% { transform: translateY(0); } 30% { transform: translateY(-2.5px); } }
html.js:not(.ready) .cb-launch { opacity: 0; pointer-events: none; transform: translateY(12px); }
.cb.is-open .cb-launch { opacity: 0; pointer-events: none; transform: scale(.85); }

/* ---------- panel ---------- */
.cb-panel {
  position: fixed; right: 20px; bottom: 20px; z-index: 81;
  width: min(400px, calc(100vw - 40px)); height: min(620px, calc(100dvh - 40px));
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: var(--cb-radius); background: var(--cb-bg); color: var(--cb-ink);
  opacity: 0; visibility: hidden; transform: translateY(16px) scale(.98); transform-origin: bottom right;
  transition: opacity 260ms var(--cb-ease), transform 420ms var(--cb-ease), visibility 0s linear 420ms;
}
.cb.is-open .cb-panel { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }

.cb-head { display: flex; align-items: center; gap: 12px; padding: 18px 18px 10px 22px; }
.cb-head img { width: 32px; height: 32px; border-radius: 50%; flex: none; }
.cb-title { flex: 1; margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em; line-height: 1.2; }
.cb-close { flex: none; width: 40px; height: 40px; border: 0; border-radius: 12px; background: transparent; color: var(--cb-ink); cursor: pointer; display: grid; place-items: center; }
.cb-close:hover { background: var(--cb-fill); }

.cb-log { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 8px 22px 16px; display: flex; flex-direction: column; gap: 14px; scrollbar-width: thin; }
.cb-msg { max-width: 88%; font-size: 16px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.cb-msg--bot { align-self: flex-start; }
.cb-msg--coffee { align-self: flex-start; background: #FFF3B0; color: #1a1200; padding: 10px 15px; border-radius: 18px 18px 18px 6px; font-size: 15px; animation: cb-nudge 600ms var(--cb-ease) 900ms both; }
.cb-msg--coffee a { font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
@keyframes cb-nudge { from { opacity: 0; transform: translateY(8px); } }
/* the hero figure opens the chat */
.cb-figure { cursor: pointer; }
.cb-msg--user { align-self: flex-end; background: var(--cb-brand); color: #FCFBFB; padding: 10px 15px; border-radius: 18px 18px 6px 18px; }
.cb-msg--error { align-self: flex-start; color: var(--cb-ink-2); }
.cb-msg a { color: var(--cb-brand); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
.cb-msg a:hover { background: var(--cb-accent); }

.cb-intro { font-size: 16px; line-height: 1.5; margin: 0; }
.cb-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.cb-chip { border: 0; border-radius: 12px; padding: 9px 13px; background: var(--cb-fill); color: var(--cb-ink); font: inherit; font-size: 15px; cursor: pointer; text-align: left; transition: background 120ms steps(1); }
.cb-chip:hover { background: var(--cb-accent); }
.cb-note { margin: 2px 0 0; font-size: 13px; line-height: 1.45; color: var(--cb-ink-2); }
.cb-note a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.cb-typing { display: inline-flex; gap: 5px; padding: 6px 0; }
.cb-typing i { width: 7px; height: 7px; background: var(--cb-ink-2); animation: cb-blink 1s infinite both; }
.cb-typing i:nth-child(2) { animation-delay: .15s; }
.cb-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes cb-blink { 0%, 100% { opacity: .25; } 40% { opacity: 1; } }

.cb-form { display: flex; align-items: flex-end; gap: 10px; padding: 12px 14px 14px 14px; }
.cb-input { flex: 1; min-height: 48px; max-height: 128px; resize: none; border: 0; border-radius: 14px; padding: 13px 15px; background: var(--cb-fill); color: var(--cb-ink); font: inherit; font-size: 16px; line-height: 1.4; }
.cb-input::placeholder { color: var(--cb-ink-2); }
.cb-input:focus { outline: 2px solid var(--cb-brand); outline-offset: 0; }
.cb-send { flex: none; width: 48px; height: 48px; border: 0; border-radius: 14px; background: var(--cb-brand); color: #FCFBFB; cursor: pointer; display: grid; place-items: center; transition: background 120ms steps(1); }
.cb-send:hover:not(:disabled) { background: var(--cb-accent); color: var(--cb-brand); }
.cb-send:disabled { opacity: .45; cursor: default; }

/* phones: the panel takes the screen, the page behind stays put */
@media (max-width: 560px) {
  .cb-launch { right: 16px; bottom: 16px; }
  .cb-panel { right: 8px; left: 8px; bottom: 8px; width: auto; height: calc(100dvh - 16px); }
  html.cb-lock, html.cb-lock body { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .cb-launch, .cb-panel { transition: none; }
  .cb-launch .cb-dot, .cb-typing i { animation: none; }
  .cb-typing i { opacity: .6; }
}
