/* «Chat to Agents»: one calm page, light or dark by the visitor's own choice in the operating system.
   No web font, no framework, no images: everything here is text and colour. The six participant colours are the only loud thing, and
   each of them is used for one avatar, one name and the mention chips of that participant (never as the only sign of who said what:
   the name is always there too). The page is one column in the middle, as tall as the window, and only the chat scrolls. */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1b1f24;
  --ink-2: #59616b;
  --line: #dfe3e8;
  --line-2: #eef1f4;
  --accent: #2b4bd0;
  --accent-ink: #ffffff;
  --visitor: #e6ebf7;
  --system: #f2f0ea;
  --system-ink: #6b5f3f;
  --danger: #b3123c;
  --focus: #d9480f;
  --p0: #2b4bd0;
  --p1: #087f5b;
  --p2: #a8440a;
  --p3: #8f1d9c;
  --p4: #0b6f8c;
  --p5: #b3123c;
  --radius: 10px;
  --top: 3.4rem;                      /* the height of the header: what is left is the chat */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --panel: #1c2024;
    --ink: #e8eaed;
    --ink-2: #a3acb6;
    --line: #31373d;
    --line-2: #262b30;
    --accent: #8aa4ff;
    --accent-ink: #10131a;
    --visitor: #262d38;
    --system: #2a2721;
    --system-ink: #d3c39a;
    --danger: #ff8fa3;
    --focus: #ffb066;
    --p0: #9db4ff;
    --p1: #5fd0a4;
    --p2: #f0a35c;
    --p3: #e09ae8;
    --p4: #6fc9e0;
    --p5: #ff8fa3;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1 { font-size: 1.15rem; margin: 0; letter-spacing: 0.01em; }
h2 { font-size: 0.98rem; margin: 0; }
p { margin: 0.4rem 0; }

a { color: var(--accent); }
a:focus-visible, button:focus-visible, textarea:focus-visible, summary:focus-visible, input:focus-visible, .pick:focus-visible {
  outline: 2px solid var(--focus);
  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;
}

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: center; justify-content: space-between;
  padding: 0.7rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.wallet { display: flex; align-items: center; gap: 0.5rem; font-size: 0.92rem; }
.wallet-name { color: var(--ink-2); }
.wallet #wallet-text { font-weight: 600; }

main { max-width: 46rem; margin: 0 auto; padding: 0 0.8rem; }

/* ---------------------------------------------------------------- the page before a wallet */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.panel h2 { font-size: 1.2rem; margin-bottom: 0.6rem; }
.hint { color: var(--ink-2); font-size: 0.88rem; }
.note { background: var(--system); color: var(--system-ink); border-radius: var(--radius); padding: 0.5rem 0.7rem; }
.waiting { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; background: var(--system); color: var(--system-ink); border-radius: var(--radius); padding: 0.5rem 0.7rem; }
.left { color: var(--ink-2); font-variant-numeric: tabular-nums; }
/* the connect check code: the visitor compares it with the one his wallet shows, and allows only if they match (CONTRACT-DIRECT.md §3a) */
.check { flex-basis: 100%; display: flex; flex-direction: column; gap: 0.1rem; align-items: center; }
.check-code { font-size: 2rem; font-weight: 700; line-height: 1.1; letter-spacing: 0.45rem; text-indent: 0.45rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.check-line { font-size: 0.86rem; color: var(--ink-2); }
/* the «open on another device» block of the BYOA library, on a phone */
.byoa-crossdevice { background: var(--system); color: var(--system-ink); border-radius: var(--radius); padding: 0.5rem 0.7rem; }
.byoa-crossdevice h3 { margin: 0.2rem 0; font-size: 1rem; }
.byoa-crossdevice p { margin: 0.4rem 0; font-size: 0.9rem; }
.byoa-check-code { display: block; font-size: 2rem; font-weight: 700; line-height: 1.1; letter-spacing: 0.45rem; color: var(--ink); }
.byoa-link { width: 100%; box-sizing: border-box; font: 0.8rem ui-monospace, Consolas, monospace; }
.byoa-buttons { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.byoa-status:empty { display: none; }
.byoa-qr svg { width: 15rem; height: 15rem; max-width: 100%; }
details { margin-top: 0.8rem; }
summary { cursor: pointer; color: var(--ink-2); }
kbd { background: var(--line-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 0.3rem; font-size: 0.85em; }

/* ---------------------------------------------------------------- the chat: one column, as tall as the window */

/* the chat floats: a little room above and below, as if it were a window of its own */
#room { --gap: 0.9rem; height: calc(100vh - 2 * var(--gap)); height: calc(100dvh - 2 * var(--gap)); margin: var(--gap) 0; }

.chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 24rem;
  max-width: 46rem;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  padding: 0.15rem 0.4rem 0.15rem 0.8rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.chat-head h1 { color: var(--ink); font-weight: 700; letter-spacing: 0.01em; font-size: 0.86rem; }
.tools { display: flex; align-items: center; gap: 0.3rem; }
.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.5rem; height: 1.5rem; padding: 0;
  color: var(--ink-2); background: none; border: 1px solid transparent; border-radius: 8px;
}
.icon-button:hover:not(:disabled) { color: var(--ink); background: var(--line-2); border-color: var(--line); }

/* the only thing that scrolls: the log */
.log {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.7rem 0.8rem 0.3rem;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.messages { display: flex; flex-direction: column; gap: 0.5rem; }
.thinking { display: flex; flex-direction: column; gap: 0.35rem; }

/* ---------------------------------------------------------------- what was said */

.msg { max-width: 42rem; }
.msg .bubble {
  border: 1px solid var(--line-2);
  border-radius: 14px;
  padding: 0.45rem 0.7rem 0.35rem;
  background: var(--panel);
  overflow-wrap: anywhere;
}
.msg .body > :first-child { margin-top: 0; }
.msg .body > :last-child { margin-bottom: 0; }
.msg .body pre { background: var(--line-2); border-radius: 8px; padding: 0.5rem 0.6rem; overflow-x: auto; }
.msg .body code { background: var(--line-2); border-radius: 4px; padding: 0.05rem 0.25rem; font-size: 0.92em; }
.msg .body pre code { background: none; padding: 0; }
.msg .meta { margin: 0.2rem 0 0; font-size: 0.74rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.msg.visitor { align-self: flex-end; }
.msg.visitor .bubble { background: var(--visitor); border-color: transparent; border-bottom-right-radius: 4px; }

.msg.ai { display: flex; gap: 0.5rem; align-items: flex-start; }
.msg.ai .col { min-width: 0; }
.msg.ai .head { display: flex; gap: 0.4rem; align-items: baseline; margin: 0 0 0.15rem 0.2rem; }
.msg.ai .who { font-weight: 600; font-size: 0.9rem; }
.msg.ai .bubble { border-bottom-left-radius: 4px; }
.msg.ai .avatar {
  flex: 0 0 auto;
  width: 2rem; height: 2rem; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.76rem; font-weight: 700; letter-spacing: 0.02em;
  color: var(--panel);
  background: var(--p0);
}

.mark {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 0.35rem;
}

/* the colours: the name of a participant, its avatar and its dot — the words themselves stay the colour of ink */
.who.p0 { color: var(--p0); } .avatar.p0, .dot.p0 { background: var(--p0); }
.who.p1 { color: var(--p1); } .avatar.p1, .dot.p1 { background: var(--p1); }
.who.p2 { color: var(--p2); } .avatar.p2, .dot.p2 { background: var(--p2); }
.who.p3 { color: var(--p3); } .avatar.p3, .dot.p3 { background: var(--p3); }
.who.p4 { color: var(--p4); } .avatar.p4, .dot.p4 { background: var(--p4); }
.who.p5 { color: var(--p5); } .avatar.p5, .dot.p5 { background: var(--p5); }

/* a mention of somebody who is really here */
.mention {
  border-radius: 6px; padding: 0 0.25rem;
  background: var(--line-2);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 0.94em;
}
.mention.neutral { background: transparent; color: var(--ink-2); }
.mention.p0 { color: var(--p0); background: color-mix(in srgb, var(--p0) 14%, transparent); border-color: color-mix(in srgb, var(--p0) 55%, transparent); }
.mention.p1 { color: var(--p1); background: color-mix(in srgb, var(--p1) 14%, transparent); border-color: color-mix(in srgb, var(--p1) 55%, transparent); }
.mention.p2 { color: var(--p2); background: color-mix(in srgb, var(--p2) 14%, transparent); border-color: color-mix(in srgb, var(--p2) 55%, transparent); }
.mention.p3 { color: var(--p3); background: color-mix(in srgb, var(--p3) 14%, transparent); border-color: color-mix(in srgb, var(--p3) 55%, transparent); }
.mention.p4 { color: var(--p4); background: color-mix(in srgb, var(--p4) 14%, transparent); border-color: color-mix(in srgb, var(--p4) 55%, transparent); }
.mention.p5 { color: var(--p5); background: color-mix(in srgb, var(--p5) 14%, transparent); border-color: color-mix(in srgb, var(--p5) 55%, transparent); }

/* the room talking about itself: joined, left, stopped, a failure, the pause */
.sys {
  align-self: center;
  max-width: 34rem;
  text-align: center;
  font-size: 0.83rem;
  color: var(--ink-2);
  background: var(--system);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  margin: 0.1rem 0;
}
.sys .who { font-weight: 600; }
.sys .mention { font-size: 0.9em; }

/* ---------------------------------------------------------------- the participants that are working */

.think {
  align-self: flex-start;
  max-width: 34rem;
  padding: 0.1rem 0.2rem;
}
.think-head { display: flex; align-items: center; gap: 0.45rem; font-size: 0.86rem; }
.think-head .who { font-weight: 600; }
.muted { color: var(--ink-2); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.6rem; height: 1.6rem; padding: 0;
  color: var(--ink-2); background: none; border: 1px solid transparent; border-radius: 6px;
}
.icon:hover { color: var(--danger); background: var(--line-2); border-color: var(--line); }
.think .peek { margin-top: 0.2rem; background: var(--bg); border-style: dashed; }
.think .peek .body { font-size: 0.9rem; color: var(--ink-2); max-height: 8rem; overflow: hidden; }

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

.composer { position: relative; border-top: 1px solid var(--line); padding: 0.5rem 0.7rem 0.6rem; }
.write { display: flex; gap: 0.5rem; align-items: flex-end; }
.composer textarea {
  flex: 1 1 auto;
  resize: none;
  min-height: 2.6rem;
  max-height: 12rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}
.composer .hint { margin: 0.3rem 0 0 0.3rem; }

.mentions {
  position: absolute;
  left: 0.7rem; right: 0.7rem; bottom: calc(100% - 0.2rem);
  max-height: 13rem; overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.14);
  padding: 0.25rem;
  z-index: 6;
}
.pick {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.3rem 0.45rem; border-radius: 8px; cursor: pointer;
}
.pick.on, .pick:hover { background: var(--line-2); }
.dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--ink-2); flex: 0 0 auto; }
.dot.neutral { background: var(--ink-2); }
.pick-name { font-weight: 600; }
.pick-handle { color: var(--ink-2); font-size: 0.88rem; margin-left: auto; }

button {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { background: var(--danger); color: var(--panel); border-color: var(--danger); font-weight: 600; }

/* ---------------------------------------------------------------- the two questions */

.dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  padding: 1rem 1.1rem;
  max-width: 26rem;
}
.dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dialog h2 { font-size: 1.05rem; margin-bottom: 0.3rem; }
.dialog p { color: var(--ink-2); font-size: 0.92rem; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.9rem; }

footer { max-width: 52rem; margin: 0 auto; padding: 0.6rem 1rem 1.2rem; color: var(--ink-2); font-size: 0.85rem; }

/* ---------------------------------------------------------------- a phone */

@media (max-width: 640px) {
  main { padding: 0 0.4rem; }
  #room { --gap: 0.5rem; }
  .chat { max-width: 100%; }
  .msg { max-width: 100%; }
  .msg.ai .avatar { width: 1.7rem; height: 1.7rem; font-size: 0.68rem; }
  .sys { max-width: 100%; }
  .write { gap: 0.35rem; }
  .composer textarea { padding: 0.5rem 0.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
/* the hidden attribute must win over every display rule above (the room, the waiting note and the mention list are shown and hidden with it) */
[hidden] { display: none !important; }
/* the generic avatar rule above is more specific than .avatar.pN, so every avatar came out in the first colour: each one gets its own */
.msg.ai .avatar.p1 { background: var(--p1); }
.msg.ai .avatar.p2 { background: var(--p2); }
.msg.ai .avatar.p3 { background: var(--p3); }
.msg.ai .avatar.p4 { background: var(--p4); }
.msg.ai .avatar.p5 { background: var(--p5); }

/* the connection lives in the header of the chat, and the empty chat shows how to start */
.chat-head .wallet { font-size: 0.76rem; color: var(--ink-2); gap: 0; }
.chat-head #wallet-text { font-weight: 600; }
.head-button { padding: 0 0.6rem; height: 1.5rem; font-size: 0.78rem; border-radius: 8px; line-height: 1; }
.start { margin: auto; max-width: 24rem; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 0.35rem; padding: 1rem 0; }
.start p { margin: 0.15rem 0; }
.start .start-lead { font-size: 1rem; margin-bottom: 0.5rem; }
.start details { text-align: left; margin-top: 0.2rem; }
.start .waiting, .start .note { justify-content: center; }
#room:not(.connected) #messages, #room:not(.connected) #thinking { display: none; }
.composer textarea:disabled { opacity: 0.6; cursor: not-allowed; }

/* the promise the visitor most wants to hear, said first and big */
.start .privacy { display: flex; flex-direction: column; gap: 0.1rem; margin: 0.2rem 0 0.8rem; padding: 0.7rem 1rem; border: 1px solid var(--accent); border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.start .privacy strong { font-size: 1.15rem; line-height: 1.3; }
.start .privacy span { font-size: 1rem; }
