:root {
  color-scheme: light dark;
  --bg: #f6f7f9; --panel: #ffffff; --text: #1d2228; --muted: #69727d; --line: #dde1e6;
  --accent: #2f5fd0; --accent-text: #ffffff; --error: #b42318; --ok: #1a7f37; --warn: #b45309;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171b; --panel: #1c2026; --text: #e6e9ed; --muted: #98a1ac; --line: #2e343c; --accent: #7aa2ff; --accent-text: #0d1117; --error: #ff7b72; --ok: #56d364; --warn: #f0b429; }
  .card { box-shadow: 0 1px 2px rgb(0 0 0 / .35), 0 8px 28px rgb(0 0 0 / .45); }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
.card { max-width: 34rem; margin: 4rem auto; padding: 2.25rem; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 1px 2px rgb(0 0 0 / .04), 0 8px 28px rgb(0 0 0 / .06); }
.card h1 { margin: .15rem 0 .8rem; font-size: 1.5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
.button, .card button { display: inline-block; padding: .55rem 1rem; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-text); text-decoration: none; }
.card fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 1rem 0; padding: .85rem 1rem .95rem; background: var(--bg); }
.card label { display: block; margin: .35rem 0; }
.card input:not([type]) { font: inherit; padding: .55rem .7rem; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg); color: var(--text); }
.card :is(input, button, a):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hint { color: var(--muted); font-size: .9rem; }
.error { color: var(--error); }
.link { background: none; border: 0; color: var(--accent); padding: 0; }
.app { display: grid; grid-template-columns: 17rem 1fr; height: 100vh; }
nav { border-right: 1px solid var(--line); background: var(--panel); padding: 1rem; overflow: auto; }
nav header { display: flex; justify-content: space-between; align-items: center; }
.product { display: inline-flex; align-items: center; gap: .4rem; }
nav ul { list-style: none; padding: 0; margin: 1rem 0 .5rem; }
nav li button { width: 100%; text-align: left; background: none; border: 0; padding: .45rem .6rem; border-radius: 6px; color: var(--text); display: flex; align-items: center; gap: .5rem; }
nav li button .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
nav li button:hover { background: var(--bg); }
nav li button.selected { background: var(--bg); font-weight: 600; }
/* Activity is built in, not a chatbot: small caps in the accent colour, with an icon. */
nav li button.builtin { color: var(--accent); font-variant: small-caps; letter-spacing: .04em; font-weight: 600; border: 1px dashed var(--line); }
nav li button.builtin .icon { flex: none; }
#title.builtin { color: var(--accent); font-variant: small-caps; letter-spacing: .04em; }
nav li.group { margin: .9rem .6rem .3rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
nav li.empty { padding: .2rem .6rem; }
.dot { flex: none; width: .55rem; height: .55rem; border-radius: 50%; background: var(--presence-offline, #8c959f); }
.dot.listening { background: var(--presence-listening, #1a7f37); }
.dot.connected { background: var(--presence-connected, #54aeff); }
.badge { flex: none; min-width: 1.4rem; padding: 0 .35rem; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: .75rem; text-align: center; font-weight: 600; font-variant: normal; }
.offline-toggle { margin: 0 .6rem 1rem; font-size: .85rem; }
.connect code { display: block; word-break: break-all; padding: .4rem; background: var(--bg); border-radius: 6px; }
.connect h3 { font-size: .85rem; margin: 1rem 0 .3rem; }
.connections { margin: 0; }
.connections li { display: flex; flex-wrap: wrap; gap: .3rem; align-items: baseline; padding: .2rem 0; font-size: .9rem; }
.connections li .link { margin-left: auto; font-size: .85rem; }
.app main { display: flex; flex-direction: column; min-height: 0; padding: 1rem 1.25rem; gap: .5rem; }
.app main > header h2 { margin: 0; font-size: 1.15rem; }
.app main > header p { margin: .1rem 0 0; }
[hidden] { display: none !important; }
#search { display: flex; gap: .5rem; align-items: center; }
#search input { flex: 1; font: inherit; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); }
#searchinfo { margin: 0; }
#feed { flex: 1; overflow: auto; list-style: none; padding: 0; margin: .25rem 0; }
#feed > li.mail { padding: .65rem .5rem; border-bottom: 1px solid var(--line); }
#feed > li.mail.unread { border-left: 3px solid var(--accent); padding-left: .6rem; }
#feed > li.mail.archived { opacity: .7; }
#feed > li.empty { padding: 1rem .5rem; }
.mail .head { display: flex; flex-wrap: wrap; gap: .4rem; align-items: baseline; }
.mail .subject { overflow-wrap: anywhere; }
.chip { font-size: .72rem; padding: 0 .4rem; border-radius: 999px; background: var(--accent); color: var(--accent-text); }
.chip.muted { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.meta { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.mail p.text { margin: .35rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.mail p.snippet { margin: .3rem 0; font-size: .9rem; color: var(--muted); }
.mail p.snippet mark { background: rgb(250 204 21 / .35); color: var(--text); border-radius: 2px; padding: 0 .1rem; }
.mail p.files { margin: .35rem 0 0; font-size: .85rem; color: var(--muted); }
.mail-actions { display: flex; gap: 1rem; margin-top: .35rem; font-size: .85rem; }
/* Mail written in markdown (markdown.js). */
.md { margin-top: .2rem; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: .5rem 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: .8rem 0 .4rem; line-height: 1.25; }
.md h1 { font-size: 1.3rem; } .md h2 { font-size: 1.15rem; } .md h3 { font-size: 1.05rem; } .md h4, .md h5, .md h6 { font-size: 1rem; }
.md ul, .md ol { margin: .4rem 0; padding-left: 1.6rem; }
.md li > ul, .md li > ol { margin: .15rem 0; }
.md li.task { list-style: none; margin-left: -1.3rem; }
.md li.task > input { margin: 0 .4rem 0 0; vertical-align: -1px; }
.md code { font: .88em ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 .25rem; }
.md pre { margin: .5rem 0; padding: .6rem .75rem; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
.md pre code { background: none; border: 0; padding: 0; white-space: pre; overflow-wrap: normal; }
.md blockquote { margin: .5rem 0; padding: 0 .8rem; border-left: 3px solid var(--line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: .8rem 0; }
.md-table { overflow-x: auto; margin: .5rem 0; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--line); padding: .25rem .6rem; text-align: left; vertical-align: top; }
.md th { background: var(--bg); }
#compose { display: grid; gap: .4rem; border-top: 1px solid var(--line); padding-top: .6rem; }
#compose .row { display: flex; gap: .5rem; align-items: center; }
#compose .row label { width: 4rem; color: var(--muted); font-size: .9rem; }
#compose input, #compose select, #compose textarea { font: inherit; padding: .4rem .55rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); }
#compose .row input { flex: 1; min-width: 0; }
#compose .actions { display: flex; flex-direction: row; justify-content: space-between; align-items: center; margin-top: 0; }
#compose .actions button { flex: none; }
#compose button { border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-text); padding: .45rem 1.2rem; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 700px) {
  .app { grid-template-columns: 1fr; height: auto; }
  nav { border-right: 0; border-bottom: 1px solid var(--line); }
  .app main { height: 85vh; padding: 1rem 16px; }
  #compose .row label { width: 3.2rem; }
}

/* Chatbot traffic (traffic.js), ported from Glimpsed Chat's original view. */
:root { --presence-listening: #1a7f37; --presence-connected: #54aeff; --presence-offline: #8c959f; --ember: #e8590c; --line-strong: #aab2bb; }
@media (prefers-color-scheme: dark) { :root { --presence-listening: #3fb950; --presence-connected: #388bfd; --presence-offline: #6e7681; --ember: #ff8a3d; --line-strong: #4d5661; } }
.traffic-open { width: 100%; margin: 0 0 1rem; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); text-align: left; }
.traffic-open:hover { border-color: var(--accent); }
.traffic-dialog { width: min(1120px, 96vw); height: min(860px, 92dvh); padding: 1rem 1.25rem; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); display: none; flex-direction: column; overflow: hidden auto; }
.traffic-dialog[open] { display: flex; }
.traffic-dialog::backdrop { background: rgb(0 0 0 / .45); }
.traffic-dialog > header { display: flex; justify-content: space-between; align-items: center; }
.traffic-dialog h2 { margin: 0; font-size: 1.15rem; }
.traffic-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 18px; }
.traffic-bar .hint { margin: .3rem 0; }
.traffic-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; list-style: none; margin: 0; padding: 0; font-size: 12px; color: var(--muted); }
.traffic-legend li::before { content: ''; display: inline-block; box-sizing: border-box; width: 10px; height: 10px; margin-right: 6px; border-radius: 50%; vertical-align: -1px; background: var(--presence-offline); }
.traffic-legend [data-presence='listening']::before { background: var(--presence-listening); }
.traffic-legend [data-presence='connected']::before { background: var(--presence-connected); }
.traffic-legend [data-presence='person']::before { background: var(--panel); border: 2px solid var(--accent); }
.traffic-legend [data-presence='board']::before { background: var(--panel); border: 2px dashed var(--ember); }
.traffic-stage { position: relative; flex: 1; min-height: 240px; margin-top: 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); overflow: hidden; }
.traffic-graph { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; }
.traffic-empty { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; }
.traffic-graph .tnode { cursor: grab; touch-action: none; }
.traffic-graph.dragging, .traffic-graph.dragging .tnode { cursor: grabbing; }
.tnode .tring { fill: var(--presence-offline); stroke: var(--panel); stroke-width: 2; }
.tnode[data-presence='listening'] .tring { fill: var(--presence-listening); }
.tnode[data-presence='connected'] .tring { fill: var(--presence-connected); }
.tnode[data-presence='person'] .tring { fill: var(--panel); stroke: var(--accent); stroke-width: 2.5; }
.tnode[data-presence='board'] .tring { fill: var(--panel); stroke: var(--ember); stroke-width: 2.5; stroke-dasharray: 5 3; }
.tnode .tlabel { fill: var(--text); font: 600 11px system-ui, -apple-system, "Segoe UI", sans-serif; paint-order: stroke; stroke: var(--bg); stroke-width: 3px; }
.tnode .tcount { fill: #fff; font-weight: 700; pointer-events: none; paint-order: stroke; stroke: rgb(0 0 0 / .55); stroke-width: 2px; stroke-linejoin: round; font-variant-numeric: tabular-nums; }
.tnode[data-kind='person'] .tcount, .tnode[data-kind='board'] .tcount { fill: var(--text); stroke: none; }
.tnode:focus { outline: none; }
.tnode:focus-visible .tring, .tnode.dragging .tring { stroke: var(--accent); stroke-width: 3; }
.tnode.dragging .tlabel { fill: var(--accent); }
.tnode.ping .tring { animation: traffic-ping .7s ease-out; }
@keyframes traffic-ping { from { stroke: var(--ember); stroke-width: 9; } }
/* Directed edges: a shaft and an arrowhead share the group's colour, so a pulse lights both. */
.tedge { color: var(--line-strong); transition: color .5s; }
.tedge.hot { color: var(--ember); transition: none; }
.tline { stroke: currentColor; stroke-linecap: round; fill: none; }
.thead { fill: currentColor; stroke: none; }
.tpulse { fill: var(--ember); }
.traffic-timeline { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: .9rem; }
.traffic-timeline select { font: inherit; font-size: 12px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.traffic-strip { flex: 1; min-width: 0; height: 56px; }
.taxis { stroke: var(--line-strong); }
.tticklabel { fill: var(--muted); font: 10px system-ui, -apple-system, "Segoe UI", sans-serif; }
.tmark { fill: var(--accent); opacity: .8; }
.tmark.bot-to-bot { fill: var(--presence-listening); }
.traffic-log { max-height: 108px; overflow: hidden auto; margin: 8px 0 0; padding: 0; list-style: none; font-size: 12px; columns: 2 280px; }
.traffic-log li { display: flex; gap: 10px; padding: 2px 0; break-inside: avoid; }
.traffic-log time { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
#traffic-status:empty { display: none; }
@media (max-width: 700px) { .traffic-dialog { width: 100vw; height: 100dvh; max-width: none; max-height: none; border-radius: 0; padding: .75rem 16px; } .traffic-timeline { flex-wrap: wrap; } .traffic-strip { flex-basis: 100%; } }
@media (prefers-reduced-motion: reduce) { .tnode.ping .tring { animation: none; } .tedge { transition: none; } }
@media (forced-colors: active) { .traffic-legend li::before { forced-color-adjust: none; } .tnode .tring { stroke: CanvasText; } }

/* Sign-in, consent and device pages (/device): the small card pages. */
.brand { display: flex; align-items: center; gap: .4rem; margin: 0 0 .4rem; font-size: .8rem; font-weight: 600; letter-spacing: .07em; color: var(--muted); }
.mark { flex: none; color: var(--accent); }
.card h1 .mark { vertical-align: -.16em; margin-right: .18em; }
.vh { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }

/* The code a device is showing, to be matched by eye. */
.code-caption { margin: .75rem 0 0; text-align: center; color: var(--muted); font-size: .85rem; }
.code-chip { display: block; width: fit-content; max-width: 100%; margin: .3rem auto 1.1rem; padding: .5rem 1.5rem .5rem calc(1.5rem + .18em); font: 700 2.25rem/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .18em; text-align: center; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.code-chip .dash { color: var(--muted); }

/* The code-entry input: one large centred field. */
.card input.device-code { display: block; width: 100%; height: 3.25rem; margin: .2rem 0 1rem; padding: 0 .5rem; font: 600 1.6rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .28em; text-align: center; text-transform: uppercase; }
.card input.device-code[aria-invalid="true"] { border-color: var(--error); }

/* Inline alerts and the security callout. */
.alert, .callout { display: flex; gap: .55rem; align-items: flex-start; margin: 0 0 1rem; padding: .65rem .8rem; border: 1px solid var(--line); border-radius: 8px; font-size: .9rem; }
.alert { border-left: 3px solid var(--error); background: var(--bg); background: color-mix(in srgb, var(--error) 7%, var(--panel)); border-color: var(--line); border-color: color-mix(in srgb, var(--error) 30%, var(--line)); color: var(--text); }
.alert svg { flex: none; margin-top: .15rem; color: var(--error); }
.callout { margin: 1rem 0; border-left: 3px solid var(--warn); background: var(--bg); background: color-mix(in srgb, var(--warn) 8%, var(--panel)); border-color: var(--line); border-color: color-mix(in srgb, var(--warn) 35%, var(--line)); color: var(--text); }
.callout svg { flex: none; margin-top: .15rem; color: var(--warn); }

/* The shared chatbot chooser: a quiet panel. The "new" label wraps its name
   input so clicking the field re-selects the radio; the input is a block, so
   it sits on its own row under the radio text. */
.card legend { padding: 0 .35rem; color: var(--muted); font-size: .8rem; font-weight: 600; letter-spacing: .04em; }
.card .choice { display: block; margin: .45rem 0; }
.card .choice input[type="radio"] { margin-right: .45rem; accent-color: var(--accent); }
.card .field-name { display: block; width: 100%; max-width: 22rem; margin: .45rem 0 .8rem; }
.card .field-name.sub { width: calc(100% - 1.7rem); margin-left: 1.7rem; }
.hint.small { font-size: .8rem; }

.actions { display: flex; gap: .6rem; margin-top: 1rem; }
.actions button { flex: 1; }
.actions .secondary { background: var(--bg); color: var(--text); border: 1px solid var(--line-strong); }
@media (max-width: 480px) {
  .card { margin: 1.5rem 1rem; padding: 1.5rem 1.25rem; }
  .actions { flex-direction: column; }
}
.card-foot { margin-top: 1.4rem; padding-top: .9rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; }
.result { text-align: center; }
.result .result-icon { margin: 0 auto 1rem; }
.result .result-icon svg { width: 56px; height: 56px; }
