/* ===========================================================================
   The agent: the floating panel on every page, and the full console at /demo.

   Both use the same markup ids so one client (chat.js) drives both. Anything
   here that only applies to one of the two is namespaced with --panel or
   .console, never duplicated.
   ========================================================================= */

/* --- thread --------------------------------------------------------------- */

.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(11, 18, 32, .16) transparent;
}
.thread::-webkit-scrollbar { width: 7px; }
.thread::-webkit-scrollbar-thumb { background: rgba(11, 18, 32, .16); border-radius: 99px; }
.thread::-webkit-scrollbar-track { background: transparent; }

.msg { display: flex; gap: 10px; align-items: flex-start; }

.msg__who {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-family: "JetBrains Mono", monospace;
  font-size: .58rem; font-weight: 600; letter-spacing: .04em;
  background: var(--ink); color: #fff;
  margin-top: 2px;
}
.msg--op .msg__who { background: var(--soft-2); color: var(--muted); }
.msg--error .msg__who { background: #FEE4E2; color: #B42318; }

.msg__body {
  background: var(--soft);
  border-radius: 14px;
  border-top-left-radius: 5px;
  padding: 11px 14px;
  font-size: .89rem;
  line-height: 1.6;
  color: var(--ink-soft);
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
}
.msg__body p + p { margin-top: .7em; }
.msg__body ul { margin: .6em 0 0; padding-left: 18px; }
.msg__body li { margin-top: .32em; }
.msg__body strong { color: var(--ink); font-weight: 600; }
.msg__body code {
  font-family: "JetBrains Mono", monospace;
  font-size: .82em;
  background: rgba(11, 18, 32, .06);
  padding: 1px 5px; border-radius: 4px;
}
.msg__body a { color: var(--blue-ink); text-decoration: underline; text-underline-offset: 2px; }

.msg__meta {
  display: block;
  margin-top: 7px;
  font-family: "JetBrains Mono", monospace;
  font-size: .6rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted-2);
}

/* The visitor's own message sits the other way round, so the column reads as
   a conversation rather than a log. */
.msg--op { flex-direction: row-reverse; }
.msg--op .msg__body {
  background: var(--ink);
  color: #fff;
  border-top-left-radius: 14px;
  border-top-right-radius: 5px;
}

.msg--error .msg__body { background: #FEF3F2; color: #B42318; }

.msg--intro .msg__body { background: var(--blue-wash); color: var(--ink-soft); }

/* Caret while an answer types itself in. */
.msg__body.is-typing > :last-child::after {
  content: "";
  display: inline-block;
  width: 2px; height: .85em;
  margin-left: 2px;
  vertical-align: -1px;
  background: var(--blue);
  animation: chat-caret 1s steps(1) infinite;
}
@keyframes chat-caret { 50% { opacity: 0; } }

.dots { display: inline-flex; gap: 4px; align-items: center; padding: 3px 0; }
.dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--muted-2);
  animation: chat-bob 1.3s ease-in-out infinite;
}
.dots span:nth-child(2) { animation-delay: .16s; }
.dots span:nth-child(3) { animation-delay: .32s; }
@keyframes chat-bob {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* --- starter chips -------------------------------------------------------- */

.chips { display: grid; gap: 8px; }
.chips--panel { grid-template-columns: 1fr; }

.chip {
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 11px 13px;
  cursor: pointer;
  display: block;
  width: 100%;
  transition: border-color .16s var(--ease), transform .16s var(--ease),
              box-shadow .16s var(--ease);
}
.chip:hover {
  border-color: rgba(37, 99, 235, .35);
  transform: translateY(-1px);
  box-shadow: var(--lift-1);
}
.chip b {
  display: block;
  font-size: .85rem; font-weight: 500; letter-spacing: -.012em;
  color: var(--ink);
}
.chip span {
  display: block;
  margin-top: 2px;
  font-size: .78rem;
  color: var(--muted-2);
  line-height: 1.45;
}

/* --- composer ------------------------------------------------------------- */

.composer {
  border-top: 1px solid var(--line-soft);
  padding: 12px 14px 13px;
  background: var(--card);
  flex: none;
}

.composer__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--soft);
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  padding: 8px 8px 8px 13px;
  transition: border-color .16s var(--ease), background .16s var(--ease);
}
.composer__form:focus-within {
  border-color: rgba(37, 99, 235, .4);
  background: var(--card);
}

.composer__form textarea {
  flex: 1;
  border: 0;
  background: transparent;
  resize: none;
  font: inherit;
  font-size: .89rem;
  line-height: 1.5;
  color: var(--ink);
  padding: 6px 0;
  max-height: 160px;
  outline: none;
}
.composer__form textarea::placeholder { color: var(--muted-2); }

.composer__actions { display: flex; align-items: center; gap: 6px; flex: none; }

.icon-btn {
  width: 34px; height: 34px;
  border-radius: 999px;
  border: 1px solid var(--line-soft);
  background: var(--card);
  display: grid; place-items: center;
  cursor: pointer;
  color: var(--muted);
  transition: color .16s var(--ease), border-color .16s var(--ease), background .16s var(--ease);
}
.icon-btn:hover { color: var(--ink); border-color: var(--line); }
.icon-btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn.is-recording {
  color: #fff; background: #D92D20; border-color: #D92D20;
  animation: chat-pulse 1.4s ease-in-out infinite;
}
@keyframes chat-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217, 45, 32, .4); }
  50%      { box-shadow: 0 0 0 7px rgba(217, 45, 32, 0); }
}

#send:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

.composer__status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 9px;
  min-height: 15px;
}
.composer__status .mono {
  font-size: .62rem;
  letter-spacing: .07em;
  color: var(--muted-2);
  line-height: 1.4;
  text-transform: none;
  flex: 1;
  min-width: 0;
}
.composer__status .is-live { color: var(--blue-ink); }
.composer__status .is-alert { color: #B42318; }

.shimmer {
  background: linear-gradient(90deg, var(--muted-2) 20%, var(--blue) 42%, var(--muted-2) 64%);
  background-size: 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: chat-shimmer 1.9s linear infinite;
}
@keyframes chat-shimmer {
  0%   { background-position: 130% 0; }
  100% { background-position: -30% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .shimmer { animation: none; -webkit-text-fill-color: currentColor; }
}

.chatpanel__reset {
  border: 0;
  background: none;
  color: var(--muted-2);
  font-size: .74rem;
  cursor: pointer;
  padding: 2px 0;
  flex: none;
  transition: color .16s var(--ease);
}
.chatpanel__reset:hover { color: var(--ink); text-decoration: underline; }

/* --- language switch ------------------------------------------------------ */

.langs { display: flex; gap: 5px; margin-top: 10px; }
.lang {
  border: 1px solid var(--line-soft);
  background: transparent;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: .74rem;
  color: var(--muted);
  cursor: pointer;
  transition: background .16s var(--ease), color .16s var(--ease), border-color .16s var(--ease);
}
.lang:hover { color: var(--ink); }
.lang.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

/* --- floating launcher ---------------------------------------------------- */

.chatfab {
  position: fixed;
  right: 22px; bottom: 22px;
  z-index: 120;
  width: 56px; height: 56px;
  border-radius: 999px;
  border: 0;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--lift-3);
  transition: transform .22s var(--ease), background .22s var(--ease);
}
.chatfab:hover { transform: translateY(-2px) scale(1.03); }
.chatfab svg { width: 25px; height: 25px; grid-area: 1 / 1; transition: opacity .18s var(--ease), transform .22s var(--ease); }
.chatfab__close { opacity: 0; transform: rotate(-45deg) scale(.8); width: 21px; height: 21px; }
.chatfab.is-open .chatfab__icon { opacity: 0; transform: rotate(45deg) scale(.8); }
.chatfab.is-open .chatfab__close { opacity: 1; transform: none; }

/* The one pulse on the page. It stops once the panel has been opened, because
   after that it is nagging rather than pointing. */
.chatfab__ping {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--ink);
  opacity: .25;
  animation: chat-ping 2.6s var(--ease) infinite;
  pointer-events: none;
}
.chatfab.is-open .chatfab__ping { display: none; }
@keyframes chat-ping {
  0%        { transform: scale(1);    opacity: .25; }
  60%, 100% { transform: scale(1.55); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .chatfab__ping { animation: none; opacity: 0; } }

/* --- floating panel ------------------------------------------------------- */

.chatpanel {
  position: fixed;
  right: 22px;
  bottom: 90px;
  z-index: 121;
  width: min(390px, calc(100vw - 32px));
  height: min(600px, calc(100vh - 130px));
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: 20px;
  box-shadow: var(--lift-3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chat-rise .24s var(--ease);
}
.chatpanel[hidden] { display: none; }

@keyframes chat-rise {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
  to   { opacity: 1; transform: none; }
}

.chatpanel__head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line-soft);
  flex: none;
  background: var(--card);
}
.chatpanel__avatar {
  width: 32px; height: 32px;
  border-radius: 10px;
  overflow: hidden;
  flex: none;
  display: grid; place-items: center;
}
.chatpanel__avatar img { width: 100%; height: 100%; }
.chatpanel__id { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.chatpanel__id b { font-size: .88rem; font-weight: 600; letter-spacing: -.015em; }
.chatpanel__id span {
  display: flex; align-items: center; gap: 6px;
  font-size: .72rem; color: var(--muted-2);
}
.chatpanel__id i {
  width: 6px; height: 6px; border-radius: 50%;
  background: #22C55E;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, .15);
  flex: none;
}
.chatpanel__x {
  margin-left: auto;
  width: 30px; height: 30px;
  border: 0; background: transparent;
  border-radius: 8px;
  color: var(--muted-2);
  cursor: pointer;
  display: grid; place-items: center;
  flex: none;
  transition: background .16s var(--ease), color .16s var(--ease);
}
.chatpanel__x:hover { background: var(--soft); color: var(--ink); }
.chatpanel__x svg { width: 16px; height: 16px; }

.chatpanel__body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

@media (max-width: 560px) {
  .chatpanel {
    right: 10px; left: 10px;
    bottom: 84px;
    width: auto;
    height: min(72vh, calc(100vh - 110px));
  }
  .chatfab { right: 16px; bottom: 16px; width: 52px; height: 52px; }
  /* A phone keyboard plus a full-width panel leaves nothing of the page
     behind it, so stop the page scrolling underneath. */
  body.chat-open { overflow: hidden; }
}

/* ===========================================================================
   /demo — the full console
   ========================================================================= */

.console { padding: 128px 0 96px; position: relative; isolation: isolate; }
.console__sky {
  position: absolute; inset: 0 0 auto 0; height: 600px; z-index: -1;
  background:
    radial-gradient(116% 70% at 50% 2%, #4C9DD5 0%, #74B8E4 16%, #9ED0EE 34%,
                    #C6E3F7 58%, rgba(250, 250, 249, 0) 86%),
    linear-gradient(180deg, #4A9BD4 0%, #78BBE6 15%, #A5D3F0 33%, #CDE6F8 55%,
                    #EBF4FC 80%, var(--paper) 100%);
}

.console__grid {
  display: grid;
  grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr);
  gap: 56px;
  align-items: start;
}

.console__aside { display: flex; flex-direction: column; gap: 30px; position: sticky; top: 108px; }
.console__aside h1 { font-size: clamp(1.9rem, 3.4vw, 2.5rem); }
.console__aside > div > p { margin-top: 18px; color: var(--muted); font-size: .96rem; line-height: 1.62; }

/* The rotating example question. Fixed height so the column below it does not
   jog every time the phrase changes length. */
.console__try {
  margin-top: 14px;
  font-size: .9rem;
  color: var(--muted);
  min-height: 3.2em;
}
.console__try .tw { color: var(--ink-soft); font-weight: 500; }

.console__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; background: var(--line-soft); border: 1px solid var(--line-soft); border-radius: var(--radius); overflow: hidden; }
.console__list li {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  align-items: baseline;
  background: var(--card);
  padding: 13px 16px;
}
.console__list b {
  font-family: "JetBrains Mono", monospace;
  font-size: .68rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--blue-ink); font-weight: 600;
}
.console__list span { font-size: .87rem; color: var(--muted); line-height: 1.5; }

.console__limit {
  background: var(--soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  font-size: .86rem;
  line-height: 1.6;
  color: var(--muted);
}
.console__limit b { display: block; color: var(--ink); font-weight: 600; margin-bottom: 5px; font-size: .9rem; }

.console__shell {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--lift-2);
  display: flex;
  flex-direction: column;
  height: min(720px, calc(100vh - 170px));
  min-height: 520px;
  overflow: hidden;
}
.console__shell .chatpanel__head { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.console__shell .chips { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 1080px) {
  .console__grid { grid-template-columns: 1fr; gap: 40px; }
  .console__aside { position: static; }
  .console { padding-top: 116px; }
}

@media (max-width: 640px) {
  .console__shell { height: min(640px, calc(100vh - 140px)); }
  .console__shell .chips { grid-template-columns: 1fr; }
  .console__list li { grid-template-columns: 1fr; gap: 3px; }
}
