:root {
  --navy: #1f3a5f;
  --steel: #2e5a8a;
  --ink: #1c2733;
  --bg: #f4f6f9;
  --line: #d9e0e8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.demo { max-width: 640px; margin: 48px auto; padding: 0 20px; }
.demo h1 { color: var(--navy); }
.tenant-row { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; }
.tenant-row input { padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; }

.widget {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 480px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(31, 58, 95, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.widget-header {
  background: var(--navy);
  color: #fff;
  padding: 14px 16px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.status { font-size: 11px; font-weight: 400; opacity: 0.85; }
.status[data-state="online"] { color: #8ef0b0; }
.status[data-state="offline"] { color: #ffb4a8; }
.status[data-state="connecting"] { color: #ffe08a; }

/* A message the customer has sent but the socket has not yet taken.
   Faded, not hidden: they can see it is theirs and that it has not
   gone yet, which is the honest state. */
.msg[data-state="pending"] { opacity: .55; }
/* We have stopped believing the socket is coming straight back. Still
   queued, still flushes on reconnect — but stop pretending. */
.msg[data-state="stalled"] { opacity: .55; border-right: 3px solid #f0a894; }
@media (prefers-reduced-motion: reduce) {
  .typing-indicator span { animation: none; }
}

.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }

/* AI disclosure banner. Full width and visually quiet, above the first
   message, so a customer sees it before typing without it reading as a reply.
   The widget also sets these inline, because a merchant page may still be
   serving a cached stylesheet that predates this rule. */
.ai-disclosure {
  padding: 6px 10px;
  border-radius: 6px;
  background: #f1f5f9;
  color: #475569;
  font-size: 11px;
  line-height: 1.4;
}

.msg {
  max-width: 80%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
}
.msg-user {
  align-self: flex-end;
  background: var(--steel);
  color: #fff;
  border-bottom-right-radius: 3px;
  white-space: pre-wrap;
}
.msg-agent {
  align-self: flex-start;
  background: #eef2f7;
  color: var(--ink);
  border-bottom-left-radius: 3px;
}
.msg-agent.escalated { background: #fff4e5; border: 1px solid #f0c894; }

/* Human operator messages — visually distinct from bot replies.
   Class names keep the old `agent` spelling on purpose: they are the contract
   with widget copies already cached on merchant storefronts. */
.msg-human-wrap { display: flex; flex-direction: column; gap: 3px; align-self: flex-start; }
.agent-badge { font-size: 10px; font-weight: 700; color: #2e5a8a; padding: 0 4px;
               text-transform: uppercase; letter-spacing: .05em; }
.msg-human-agent { background: #eff6ff; border: 1.5px solid #bfdbfe;
                   border-bottom-left-radius: 3px; color: #1e3a5f; }

/* Markdown rendered inside agent bubbles */
.msg-agent strong { font-weight: 700; }
.msg-agent em     { font-style: italic; }
.msg-agent code   { font-family: monospace; background: #dde4ed; padding: 1px 4px; border-radius: 3px; font-size: 13px; }
.msg-agent ul, .msg-agent ol { margin: 4px 0 4px 18px; padding: 0; }
.msg-agent li { margin-bottom: 2px; }
/* REM-12: links used to carry inline styles baked into the HTML string the old
   renderer concatenated. The renderer no longer emits HTML, so the styling moves
   here where it belongs. */
.msg-link { color: #3b82f6; text-decoration: underline; word-break: break-all; }

.composer { display: flex; gap: 8px; padding: 12px 12px 8px; border-top: 1px solid var(--line); }
.composer input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  transition: opacity 0.15s;
}
.composer input:disabled { opacity: 0.5; }
.composer button {
  background: var(--navy);
  color: #fff;
  border: 0;
  padding: 0 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
}
.composer button:hover:not(:disabled) { background: var(--steel); }
.composer button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Human handoff bar ────────────────────────────────────────────────────── */
.handoff-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 12px 10px;
  font-size: 12px;
  color: #6b7f94;
  transition: background 0.3s, color 0.3s;
}
.handoff-btn {
  background: none;
  border: none;
  color: var(--steel);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  transition: color 0.15s;
}
.handoff-btn:hover:not(:disabled) { color: var(--navy); }
.handoff-btn:disabled { color: #9aabb8; text-decoration: none; cursor: default; }
.handoff-bar.escalated {
  background: #f0faf4;
  color: #2d7a4f;
  font-weight: 500;
  font-size: 12px;
  justify-content: center;
}
.handoff-bar.escalated .handoff-btn { display: none; }
.new-chat-btn {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #2e5a8a;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 8px;
  font-family: inherit;
  transition: background .15s;
}
.new-chat-btn:hover { background: #dbeafe; }

/* ── Typing indicator ─────────────────────────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
}
.typing-indicator span {
  width: 7px;
  height: 7px;
  background: #9aabb8;
  border-radius: 50%;
  animation: typing-bounce 1.1s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.18s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0);   opacity: 0.45; }
  30%            { transform: translateY(-6px); opacity: 1;    }
}

/* In-channel CSAT prompt (PEP-003 WS-B). Rendered as its own block rather than
   a message bubble: it is a question about the conversation, not a turn in it,
   and it must not be mistaken for something the bot said. */
.csat-prompt {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid #dde4ed;
  border-radius: 12px;
  background: #fbfcfe;
}
.csat-ask { margin: 0; font-size: 13px; font-weight: 600; color: var(--ink); }
.csat-stars { display: flex; gap: 4px; }
.csat-star {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  padding: 0 2px;
  color: #cbd5e1;
}
.csat-star:hover:not(:disabled) { color: #f59e0b; }
.csat-star:disabled { cursor: default; }
.csat-comment {
  border: 1px solid #dde4ed;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
}
/* Answered: the stars stay visible as a record of what was sent, greyed out. */
.csat-done { opacity: .6; }
