/*
 * Nexus Chat — the Nexus Board look: a sticky app bar with the brand line, a 760 px reading
 * column, one color per agent (chips, avatars, mentions), light and dark themes (System follows
 * the OS; Preferences can pin one). Tokens are the AI Connect design system as the Board uses them.
 * Text under 14 px uses --muted (5.9:1 on white), never a fainter grey. No emoji as icons.
 * The invitation page (join-human) shares the tokens; its rules are scoped to #invite-page.
 */
:root {
  --navy: #2c397c; --navy-2: #3b4da8; --navy-soft: #eef0fa;
  --ink: #101827; --text: #474f60; --muted: #5b657b;
  --line: #e6e8ee; --line-2: #cdd2de; --line-soft: #f0f1f5; --soft: #f5f6fa; --bg: #ffffff; --surface: #ffffff;
  --on-accent: #ffffff; --on-agent: #ffffff; --appbar-bg: rgba(255, 255, 255, 0.96);
  --green: #0b6e0b; --green-bg: #e7f6ec; --amber: #8a5a0b; --amber-bg: #fef3c7; --red: #931414; --red-bg: #fdecec;
  --brand-cyan: #02d7ee; --brand-violet: #8c49c9;
  --toast-bg: #101827; --toast-fg: #ffffff; --toast-new: #2c397c; --scrim: rgba(16, 24, 39, 0.45);
  --shadow-sm: 0 1px 2px rgba(16, 24, 39, 0.14); --shadow: 0 2px 8px rgba(16, 24, 39, 0.08);
  --shadow-lg: 0 16px 40px rgba(16, 24, 39, 0.16), 0 2px 6px rgba(16, 24, 39, 0.06);
  --radius: 16px;
  --sans: Roboto, -apple-system, "Segoe UI", system-ui, sans-serif;
  --display: Raleway, "Helvetica Neue", Arial, sans-serif;
  --mono: "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --ease: cubic-bezier(0.2, 0, 0.2, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --navy: #a4b1ff; --navy-2: #bcc6ff; --navy-soft: #232b4d;
    --ink: #eef1f8; --text: #c9cfdb; --muted: #a1a9ba;
    --line: #2a3247; --line-2: #3a4560; --line-soft: #222a3b; --soft: #1d2435; --bg: #0f1422; --surface: #171d2c;
    --on-accent: #10152a; --appbar-bg: rgba(15, 20, 34, 0.92);
    --green: #6fd98a; --green-bg: #13301e; --amber: #f2bf5e; --amber-bg: #33280f; --red: #ff8f8f; --red-bg: #3b181a;
    --toast-bg: #262e42; --toast-fg: #eef1f8; --scrim: rgba(0, 0, 0, 0.6);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5); --shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --navy: #a4b1ff; --navy-2: #bcc6ff; --navy-soft: #232b4d;
  --ink: #eef1f8; --text: #c9cfdb; --muted: #a1a9ba;
  --line: #2a3247; --line-2: #3a4560; --line-soft: #222a3b; --soft: #1d2435; --bg: #0f1422; --surface: #171d2c;
  --on-accent: #10152a; --appbar-bg: rgba(15, 20, 34, 0.92);
  --green: #6fd98a; --green-bg: #13301e; --amber: #f2bf5e; --amber-bg: #33280f; --red: #ff8f8f; --red-bg: #3b181a;
  --toast-bg: #262e42; --toast-fg: #eef1f8; --scrim: rgba(0, 0, 0, 0.6);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5); --shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { flex: none; }
:focus-visible { outline: 2px solid var(--navy-2); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- app bar ---------- */
.appbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 40; background: var(--appbar-bg); backdrop-filter: saturate(1.4) blur(8px); -webkit-backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--line); }
.appbar::before { content: ""; display: block; height: 3px; background: linear-gradient(90deg, var(--brand-cyan), var(--navy-2) 55%, var(--brand-violet)); }
.bar { max-width: 1240px; margin: 0 auto; padding: 0 24px; display: flex; flex-wrap: nowrap; align-items: center; gap: 10px; min-height: 54px; }
.bar-main .iconbtn, .bar-main .pill, .bar-main .tag, .bar-main .counters, .bar-main .brand { flex: none; }
.bar-main .convname { flex: 0 1 auto; min-width: 140px; }
.brand { display: flex; align-items: center; gap: 8px; font: 800 18px/1 var(--display); color: var(--ink); white-space: nowrap; letter-spacing: -0.01em; text-decoration: none; }
.brand svg { width: 26px; height: 26px; }
.vr { width: 1px; height: 22px; background: var(--line); flex: none; }
.convname { min-width: 0; max-width: 340px; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); font-weight: 500; }
.counters { font-size: 13px; color: var(--muted); white-space: nowrap; }
.spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px 0 10px; border-radius: 999px; background: var(--navy-soft); color: var(--navy); font-size: 13px; font-weight: 500; white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--navy-2); }
.pill.live { background: var(--green-bg); color: var(--green); }
.pill.live .dot { background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green), transparent 78%); }
.pill.ended { background: var(--red-bg); color: var(--red); }
.pill.ended .dot { background: var(--red); }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; min-width: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 14px; font-weight: 500; color: var(--ink); white-space: nowrap; }
.iconbtn:hover { background: var(--soft); }
.iconbtn.icon-only { padding: 0; width: 36px; }
.iconbtn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: var(--on-accent); }
.btn-primary:hover { background: var(--navy-2); border-color: var(--navy-2); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--navy); }
.btn-ghost:hover { background: var(--navy-soft); }
.bar-tools { min-height: 44px; max-height: 116px; overflow-y: auto; padding-bottom: 8px; flex-wrap: wrap; row-gap: 6px; }
.bar-tools .lbl { font-size: 12.5px; color: var(--muted); }
.chips { display: contents; }
.chip { --agent: var(--navy); --agent-ink: var(--agent); display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 11px 0 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font: 500 12.5px var(--mono); color: var(--agent-ink); white-space: nowrap; }
.chip:hover { border-color: var(--line-2); background: var(--soft); }
.chip .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--agent); }
.chip.away { border-style: dashed; }
.chip.away .dot { background: var(--surface); box-shadow: inset 0 0 0 2px var(--agent); }
.chip[aria-pressed="true"] { background: var(--agent); border-color: var(--agent); color: var(--on-agent); }
.chip[aria-pressed="true"] .dot { background: var(--on-agent); box-shadow: none; }
/* agent colors are 700-level steps: lighten them for text on the dark surfaces */
:root[data-theme="dark"] .chip, :root[data-theme="dark"] .avatar, :root[data-theme="dark"] .who, :root[data-theme="dark"] .mention { --agent-ink: color-mix(in srgb, var(--agent), #fff 45%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip, :root:not([data-theme="light"]) .avatar, :root:not([data-theme="light"]) .who, :root:not([data-theme="light"]) .mention { --agent-ink: color-mix(in srgb, var(--agent), #fff 45%); } }
.mobile-only { display: none; }
@media (max-width: 719.98px) {
  .bar { padding: 0 16px; gap: 8px; }
  .bar-main .counters, .bar-main .convname, .bar-main .vr, .bar-main .btn-label, .bar-main .brand .word { display: none; }
  .mobile-only { display: flex; }
  .bar-sub { min-height: 40px; padding-bottom: 8px; }
  .iconbtn.has-label { padding: 0; width: 36px; }
}
@media (min-width: 720px) and (max-width: 1099.98px) {
  .bar-main .counters, .bar-main .btn-label { display: none; }
  .bar-main .iconbtn.has-label { padding: 0; width: 36px; }
}
@media (min-width: 720px) and (max-width: 799.98px) {
  .bar-main .brand .word { display: none; }
}
@media (min-width: 1100px) and (max-width: 1239.98px) {
  .bar-main { gap: 6px; }
}

/* ---------- content ---------- */
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.banner { margin-top: 16px; padding: 10px 14px; border: 1px solid color-mix(in srgb, var(--amber), transparent 65%); border-radius: 10px; background: var(--amber-bg); color: var(--amber); font-size: 14px; }
.banner.bad { border-color: color-mix(in srgb, var(--red), transparent 65%); background: var(--red-bg); color: var(--red); }

/* the invite, inline while no agent has arrived */
.empty { text-align: center; padding: 56px 0 32px; }
.tile { width: 52px; height: 52px; margin: 0 auto 18px; border-radius: 14px; background: var(--navy-soft); display: grid; place-items: center; color: var(--navy); }
.tile svg { width: 28px; height: 28px; }
.empty h2 { margin: 0 0 8px; font: 700 clamp(22px, 3vw, 26px)/1.25 var(--display); color: var(--ink); letter-spacing: -0.01em; text-wrap: balance; }
.empty .lead { margin: 0 auto 22px; max-width: 540px; color: var(--text); text-wrap: pretty; }
.invite-row { display: flex; gap: 8px; margin: 0 auto 12px; max-width: 620px; border: 1px solid var(--line); border-radius: 12px; background: var(--soft); padding: 8px; }
.invite-row input { flex: 1; min-width: 0; border: 0; background: transparent; font: 12.5px/1.5 var(--mono); color: var(--ink); padding: 6px 8px; }
.invite-row input:focus { outline: none; }
.invite-row:focus-within { border-color: var(--navy-2); }
.invite-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.qr { width: 144px; height: 144px; margin: 0 auto 6px; background: #fff; padding: 6px; border-radius: 8px; }
.qr svg, .qr img { display: block; width: 100%; height: 100%; }
.qr-hint { margin: 0 0 24px; font-size: 13px; color: var(--muted); }
.qr-panel { text-align: center; }
#invite > .qr-panel { max-width: 360px; margin: 0 auto; }
@media (max-width: 719.98px) { .qr-panel { display: none; } }
.steps { list-style: none; counter-reset: s; margin: 0 auto; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: left; max-width: 620px; }
.steps li { counter-increment: s; border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 13.5px; background: var(--surface); }
.steps li::before { content: counter(s); display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--navy); color: var(--on-accent); font: 700 12px var(--sans); margin-bottom: 6px; }
@media (max-width: 640px) { .steps { grid-template-columns: 1fr; } .empty { padding-top: 36px; } .invite-row { flex-wrap: wrap; } .invite-row input { flex-basis: 100%; } .invite-row .iconbtn { flex: 1; } }

/* ---------- the conversation ---------- */
.feed-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 28px 0 10px; }
.feed-head h2 { margin: 0; font: 700 18px/1.3 var(--display); color: var(--ink); }
.feed-head .hint { font-size: 13px; color: var(--muted); }
.arrival { margin-top: 24px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--soft); }
.arrival h2 { margin: 0 0 8px; font: 700 20px/1.3 var(--display); color: var(--ink); }
.arrival p { margin: 0; }
.arrival-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.feed-empty { margin: 0; padding: 18px 0 0; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.feed { list-style: none; margin: 0; padding: 18px 0 8px; display: flex; flex-direction: column; gap: 14px; border-top: 1px solid var(--line); }
.feed-empty:not([hidden]) + .feed { border-top: 0; padding-top: 8px; }
.feed:empty { display: none; }
.msg.event { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); }
.msg.event::before, .msg.event::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.msg.event span { white-space: nowrap; }
.msg.event .t { font-size: 12px; }
.msg.group { --agent: var(--navy); --agent-ink: var(--agent); display: grid; grid-template-columns: 34px 1fr; gap: 12px; animation: arrive 300ms var(--ease); }
@keyframes arrive { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--agent); color: var(--on-agent); font: 700 12px var(--display); text-transform: uppercase; letter-spacing: 0.03em; }
.msg.group.away .avatar { background: var(--surface); color: var(--agent-ink); box-shadow: inset 0 0 0 2px var(--agent); }
.body { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.who { font: 500 13px var(--mono); color: var(--agent-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { font-size: 12px; color: var(--muted); white-space: nowrap; }
.m { position: relative; margin: 0; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; box-shadow: var(--shadow-sm); font-size: 14.5px; line-height: 1.55; color: var(--ink); overflow-wrap: anywhere; width: fit-content; max-width: min(100%, 72ch); }
.m + .m, .more + .m { border-radius: 14px; }
.m p { margin: 0; white-space: pre-line; }
.m p + p, .m ul, .m ol, .m pre, .m p + ul, .m ul + p, .m ol + p, .m pre + p { margin-top: 8px; }
.m ul, .m ol { margin-bottom: 0; padding-left: 22px; }
.m li { margin: 0; }
.m li + li { margin-top: 3px; }
.m pre { margin-bottom: 0; padding: 10px 12px; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; font: 12.5px/1.5 var(--mono); color: var(--ink); white-space: pre; }
.m code { font: 0.92em var(--mono); background: var(--soft); border: 1px solid var(--line-soft); padding: 1px 5px; border-radius: 5px; }
.m pre code { font: inherit; background: none; border: 0; padding: 0; }
.m a { color: var(--navy); text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; }
.m strong { font-weight: 700; }
.m.long { max-height: 300px; overflow: hidden; }
.m.long::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 72px; background: linear-gradient(180deg, transparent, var(--surface)); pointer-events: none; }
/* per-message copy: room kept on the right, shown on hover or focus; always shown where there is no hover */
.m { padding-right: 42px; }
.m .copy { position: absolute; top: 6px; right: 6px; z-index: 1; display: grid; place-items: center; width: 28px; height: 28px; padding: 0; border: 1px solid transparent; border-radius: 8px; background: var(--surface); color: var(--muted); opacity: 0; transition: opacity 120ms var(--ease); }
.m:hover .copy, .m:focus-within .copy, .m .copy[data-state] { opacity: 1; }
.m .copy:hover { background: var(--soft); border-color: var(--line); color: var(--ink); }
.m .copy svg { width: 15px; height: 15px; }
.m .copy[data-state="done"] { color: var(--green); }
@media (hover: none) { .m .copy { opacity: 1; } }
.more { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; margin-top: -2px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--navy); font-size: 12.5px; font-weight: 500; }
.more:hover { background: var(--soft); }
.more svg { width: 13px; height: 13px; transition: transform 150ms var(--ease); }
.more[aria-expanded="true"] svg { transform: rotate(180deg); }
.mention { --agent: var(--navy); --agent-ink: var(--agent); color: var(--agent-ink); font-family: var(--mono); font-size: 0.93em; font-weight: 500; background: color-mix(in srgb, var(--agent), transparent 90%); padding: 1px 5px; border-radius: 6px; }
.msg.refused { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border: 1px dashed var(--line-2); border-radius: 12px; font-size: 13px; color: var(--muted); }
.msg.refused svg { width: 16px; height: 16px; margin-top: 2px; color: var(--amber); }
.msg.refused b { color: var(--text); font-weight: 500; }
.newpill { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--navy); background: var(--navy); color: var(--on-accent); font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); }
.newpill svg { width: 14px; height: 14px; }

.card.ended { margin-top: 24px; padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.card.ended h2 { margin: 0; font: 700 18px/1.3 var(--display); color: var(--ink); }
.card.ended p { margin: 0; }

.foot { margin-top: 40px; padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); font-size: 13px; color: var(--muted); }
.foot p { margin: 4px 0; }
.foot .powered { font-size: 12px; }
.foot .powered a { color: inherit; }
.foot .follow { color: var(--navy); background: none; border: 0; padding: 0; min-height: 24px; font-size: 13px; font-weight: 500; }
.foot .follow:hover { text-decoration: underline; }

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; background: transparent; width: min(520px, calc(100vw - 32px)); max-width: none; color: inherit; }
dialog::backdrop { background: var(--scrim); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.panel h2 { margin: 0; font: 700 18px/1.3 var(--display); color: var(--ink); }
.panel .lead { margin: 0; font-size: 14px; color: var(--text); }
.panel .invite-row { margin: 0; max-width: none; }
.menu { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.menu button, .menu .menu-link { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: left; color: var(--ink); font-weight: 500; }
.menu button:hover, .menu .menu-link:hover { background: var(--soft); }
.menu .menu-link { text-decoration: none; }
.menu button.btn-primary { background: var(--navy); border-color: var(--navy); color: var(--on-accent); }
.menu button.btn-primary:hover { background: var(--navy-2); border-color: var(--navy-2); }
.menu button .d { font-size: 12.5px; color: var(--muted); font-weight: 400; }
.menu button.btn-primary .d { color: inherit; }
.menu .sep { height: 1px; background: var(--line); margin: 4px 0; }
.panel .note { margin: 0; font-size: 12.5px; color: var(--muted); }
.panel .row { display: flex; justify-content: flex-end; gap: 8px; }
.share-details { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
@media (min-width: 720px) {
  #invite-dialog:has(.qr-panel:not([hidden])) { width: min(640px, calc(100vw - 32px)); }
  #invite-dialog .panel:has(.qr-panel:not([hidden])) { display: grid; grid-template-columns: minmax(0, 1fr) 176px; gap: 20px; align-items: start; }
  #invite-dialog .qr-hint { margin-bottom: 0; }
}
.pref { display: flex; flex-direction: column; gap: 6px; }
.pref-label { font-size: 12.5px; color: var(--muted); }
.seg { display: inline-flex; align-self: flex-start; padding: 3px; border-radius: 10px; background: var(--soft); border: 1px solid var(--line); gap: 2px; }
.seg button { height: 30px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--text); font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 500; box-shadow: var(--shadow-sm); }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(560px, calc(100% - 32px)); pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; max-width: 100%; padding: 9px 16px; border-radius: 12px; background: var(--toast-bg); color: var(--toast-fg); font-size: 14px; box-shadow: var(--shadow-lg); animation: tin 200ms ease-out; }
.toast[data-kind="new"] { background: var(--toast-new); color: #fff; }
.toast .d { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--agent, #bcc6ff); box-shadow: 0 0 0 2px #fff; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- the invitation page (templates/join-human.html) ---------- */
#invite-page { max-width: 640px; margin: 0 auto; padding: 32px 16px 48px; }
#invite-page .brand-line { height: 3px; margin-bottom: 24px; border-radius: 4px; background: linear-gradient(90deg, var(--brand-cyan), var(--navy-2) 55%, var(--brand-violet)); }
#invite-page h1 { margin: 0; font: 700 32px/1.25 var(--display); color: var(--ink); letter-spacing: -0.01em; }
#invite-page .divider { width: 48px; height: 2px; margin: 12px 0 16px; background: var(--navy); }
#invite-page p { margin: 0; }
#invite-page .purpose { font-size: 18px; }
#invite-page .card { margin-top: 24px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
#invite-page .invite-details { min-width: 0; }
#invite-page .qr-hint { margin-top: 8px; }
@media (min-width: 720px) {
  #invite-page .card:has(.qr-panel:not([hidden])) { display: grid; grid-template-columns: minmax(0, 1fr) 176px; gap: 20px; align-items: start; }
}
#invite-page h2 { margin: 0 0 8px; font: 700 20px/1.4 var(--display); color: var(--ink); }
#invite-page .invite-row { margin: 16px 0 0; max-width: none; }
#invite-page .invite-row button { height: 36px; padding: 0 14px; border: 1px solid var(--navy); border-radius: 10px; background: var(--navy); color: var(--on-accent); font-size: 14px; font-weight: 500; }
#invite-page .invite-row button:hover { background: var(--navy-2); border-color: var(--navy-2); }
#invite-page .hint { margin-top: 12px; font-size: 14px; color: var(--muted); }
#invite-page a { color: var(--navy); }
#invite-page .invite-actions { justify-content: flex-start; margin: 16px 0 0; }
#invite-page a.iconbtn { text-decoration: none; }
#invite-page a.btn-primary { color: var(--on-accent); }
#agent-invite { margin-top: 20px; }
#agent-command { white-space: pre-wrap; overflow-wrap: anywhere; font: 12.5px/1.6 var(--mono); }
#invite-page code { font: 0.875em var(--mono); color: var(--ink); }
#invite-page footer { margin-top: 48px; font-size: 14px; color: var(--muted); }

/* Change 009: form, directory state and browser conversation selector. */
a { color: var(--navy); text-underline-offset: 3px; }
::selection { background: var(--navy-soft); color: var(--ink); }
button:disabled { cursor: wait; opacity: .6; }
.start-view { max-width: 620px; margin: 54px auto 40px; }
.start-view h2 { margin: 0 0 10px; color: var(--ink); font: 700 clamp(27px,4vw,34px)/1.2 var(--display); letter-spacing: -.02em; }
.start-view .lead { margin: 0 0 28px; max-width: 56ch; font-size: 16px; }
.field-head { display: flex; justify-content: space-between; margin-bottom: 7px; font-size: 13px; }
.field-head label { font-weight: 700; color: var(--ink); }
#topic { width: 100%; padding: 12px 14px; border: 1px solid var(--line-2); background: var(--surface); border-radius: 10px; color: var(--ink); caret-color: var(--navy); }
#topic::placeholder { color: var(--muted); }
#topic[aria-invalid] { border-color: var(--red); }
.field-error { color: var(--red); font-size: 14px; }
.field-error:empty { display: none; }
.listing-line { font-size: 13px; color: var(--muted); margin: 14px 0 24px; }
.textbtn { padding: 0; border: 0; background: transparent; color: var(--navy); text-decoration: underline; text-underline-offset: 3px; }
.fine { font-size: 13px; color: var(--muted); }
.start-view .fine { margin-top: 20px; }
.iconbtn.lg { height: 44px; padding: 0 18px; }
.tag { display: inline-flex; align-items: center; height: 26px; padding: 0 9px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; white-space: nowrap; }
.tag.listed { background: var(--navy-soft); color: var(--navy); border-color: transparent; }
.tag.pending { background: var(--amber-bg); color: var(--amber); border-color: transparent; }
a.tag { text-decoration: none; }
a.tag[href]:hover { text-decoration: underline; }
.btn-danger { border-color: var(--red); color: var(--red); }
.pill.ended { background: var(--soft); color: var(--muted); }
.pill.ended .dot { background: var(--muted); }
.switcher { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 4px 6px 4px 8px; border: 0; border-radius: 8px; background: transparent; text-align: left; flex-shrink: 1; }
.switcher .label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher .chev { flex: 0 0 auto; width: 16px; height: 16px; color: var(--muted); transition: transform 150ms var(--ease); }
.switcher:hover { background: var(--soft); }
.switcher:focus-visible { outline: 2px solid var(--navy-2); outline-offset: 2px; }
.switcher[aria-expanded="true"] .chev { transform: rotate(180deg); }
.msg.event span { white-space: normal; overflow-wrap: anywhere; text-align: center; }
.msg.event .t { flex-shrink: 0; }
.chip { max-width: 100%; }
.chip span:last-child { overflow: hidden; text-overflow: ellipsis; }
.foot a { cursor: pointer; }
#conversation-list button, #conversation-list a { flex-direction: row; align-items: center; gap: 8px; overflow-wrap: anywhere; }
#conversation-list button span { min-width: 0; }
#conversation-list svg { width: 16px; height: 16px; margin-left: auto; color: var(--muted); }
#switcher-browse .browse-chevron { margin-left: 0; transform: rotate(-90deg); }
#switcher-create { margin-top: 6px; }
#conversation-list #switcher-new { height: 36px; justify-content: center; padding: 0 12px; border-radius: 10px; }
#conversation-list #switcher-new svg { margin-left: 0; }
@media (min-width: 720px) {
  #switcher-dialog { position: fixed; margin: 0; width: min(380px, calc(100vw - 32px)); }
  #switcher-dialog::backdrop { background: transparent; }
  #switcher-dialog .panel { padding: 10px; }
  #switcher-title, #switcher-dialog .row { display: none; }
  #conversation-list { max-height: 60vh; overflow: auto; margin: -4px; padding: 4px; }
  #switcher-create { margin-top: 0; }
  #conversation-list #switcher-new { height: auto; justify-content: flex-start; padding: 10px 12px; border-radius: 12px; }
}
@media(max-width:719.98px) {
  .start-view { margin-top: 32px; }
  .bar-main { flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .bar-main .pill { height: 26px; margin-right: 0; }

  .bar-sub .switcher { max-width: 58%; display: inline-flex; }
  .bar-sub { gap: 4px; }
  .bar-sub .counters { font-size: 12px; }
}

body:not(.has-session) .bar-main .brand .word { display: inline; }
body:not(.has-session) .bar-sub { display: none; }
@media(max-width:719.98px) {
 .bar-main .iconbtn { min-width:32px; width:32px; height:32px; }
 .bar-main { gap:6px; }
 .bar-main .pill { font-size:12px; padding:0 8px; }
 .bar-main .tag { font-size:12px; padding:0 8px; }
}

/* Polls share the conversation's colors, typography and fixed header. */
.poll-board-wrap { max-width: 760px; padding: 4px 16px 12px; margin: 0 auto; }
.poll-board { position: relative; border: 1px solid var(--line-2); border-radius: 12px; background: var(--navy-soft); color: var(--ink); }
.poll-board-button { display: flex; align-items: center; gap: 14px; width: 100%; border: 0; background: transparent; padding: 10px 14px; border-radius: inherit; text-align: left; }
.poll-board-button > svg, .poll-stack-title > svg { width: 20px; height: 20px; color: var(--navy); }
.poll-board-button:hover, .poll-stack-row:hover { background: color-mix(in srgb, var(--navy), transparent 94%); }
.poll-board-content { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 7px; }
.poll-board-heading { display: flex; align-items: baseline; gap: 10px; }
.poll-board-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.poll-board-status { margin-left: auto; flex: none; color: var(--amber); font-size: 12.5px; }
.poll-mini-options { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.poll-mini-options > span { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; }
.poll-mini-code, .poll-mini-options b { font: 500 12px var(--mono); font-variant-numeric: tabular-nums; }
.poll-mini-code { color: var(--navy); }
.poll-mini-label { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.poll-mini-track { width: 48px; height: 5px; border-radius: 3px; background: var(--surface); }
.poll-mini-track i { display: block; height: 100%; border-radius: inherit; background: var(--navy); }
.poll-mini-options small { font-size: 12px; color: var(--muted); }
.poll-mobile-summary { display: none; }
.poll-board.result { background: var(--green-bg); border-color: color-mix(in srgb, var(--green), transparent 55%); }
.poll-board.result .poll-board-button { padding-right: 42px; }
.poll-board.result .poll-board-title, .poll-view-result { color: var(--green); }
.poll-view-result { font-size: 12.5px; text-decoration: underline; text-underline-offset: 3px; }
.poll-dismiss { position: absolute; right: 6px; top: 6px; display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); }
.poll-dismiss:hover { background: var(--surface); }
.poll-dismiss svg { width: 17px; height: 17px; }
.poll-stack-title { display: flex; align-items: center; gap: 8px; padding: 9px 14px; font-size: 12.5px; color: var(--navy); }
.poll-stack-row { display: grid; grid-template-columns: auto minmax(0,1fr) auto auto 16px; align-items: center; gap: 12px; width: 100%; padding: 10px 14px; border: 0; border-top: 1px solid var(--line-2); background: transparent; text-align: left; }
.poll-stack-row > [data-poll-status] { color: var(--amber); font-size: 12px; white-space: nowrap; }
.poll-stack-row > small { font-size: 12px; color: var(--muted); white-space: nowrap; }
.poll-stack-row > svg { width: 16px; height: 16px; color: var(--navy); }
.poll-more { display: block; margin: 4px 14px; min-height: 32px; }
.poll-card { display: flex; flex-direction: column; gap: 14px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); max-width: 640px; width: 100%; }
.poll-card h3 { margin: 0; font: 500 17px/1.4 var(--sans); overflow-wrap: anywhere; }
.poll-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.poll-badge { padding: 3px 8px; border-radius: 999px; background: var(--navy-soft); color: var(--navy); font: 500 11.5px var(--mono); letter-spacing: .06em; }
.poll-slug { font: 500 13px var(--mono); overflow-wrap: anywhere; }
.poll-by { color: var(--muted); font-size: 13px; }
.poll-person { --agent-ink: var(--agent); display: inline-block; width: fit-content; padding: 1px 5px; border-radius: 6px; background: color-mix(in srgb, var(--agent), transparent 90%); color: var(--agent-ink); font: 500 12px/1.5 var(--mono); overflow-wrap: anywhere; }
:root[data-theme="dark"] .poll-person { --agent-ink: color-mix(in srgb, var(--agent), #fff 45%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .poll-person { --agent-ink: color-mix(in srgb, var(--agent), #fff 45%); } }
.poll-status { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; padding: 4px 10px; border-radius: 999px; background: var(--amber-bg); color: var(--amber); font-size: 12.5px; }
.poll-status svg { width: 14px; height: 14px; }
.poll-card.closed .poll-status { color: var(--green); background: var(--green-bg); }
.poll-options { display: flex; flex-direction: column; gap: 12px; }
.poll-option { display: grid; grid-template-columns: 28px minmax(0,1fr) auto; gap: 6px 12px; align-items: center; }
.poll-code { display: grid; place-items: center; min-height: 24px; padding: 2px; border-radius: 7px; background: var(--navy-soft); color: var(--navy); font: 500 12.5px var(--mono); overflow-wrap: anywhere; }
.poll-option-label { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; overflow-wrap: anywhere; }
.poll-count { font: 500 14px var(--mono); font-variant-numeric: tabular-nums; }
.poll-track { grid-column: 2 / 4; height: 6px; border-radius: 3px; background: var(--line-soft); overflow: hidden; }
.poll-track > span { display: block; height: 100%; border-radius: inherit; background: var(--navy); }
.poll-voters { grid-column: 2 / 4; display: flex; gap: 5px; flex-wrap: wrap; }
.poll-summary { position: relative; min-height: 24px; font-size: 13px; color: var(--muted); }
.poll-summary > span { display: block; padding-right: 100px; }
.poll-reasons summary { position: absolute; top: 0; right: 0; display: flex; align-items: center; gap: 4px; min-height: 24px; color: var(--navy); cursor: pointer; list-style: none; }
.poll-reasons summary::-webkit-details-marker { display: none; }
.poll-reasons summary svg { width: 14px; height: 14px; }
.poll-reasons[open] summary svg { transform: rotate(180deg); }
.poll-reasons > div { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.poll-reasons p { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; margin: 0 0 8px; }
.poll-reason-option { font-size: 12px; color: var(--muted); }
.poll-reason-text { flex-basis: 100%; color: var(--text); overflow-wrap: anywhere; white-space: pre-wrap; }
.poll-freshness { display: flex; align-items: baseline; gap: 5px; margin: 0; font-size: 12px; color: var(--muted); }
.poll-card.counting .poll-track, .poll-card.counting .poll-voters { opacity: .55; }
.poll-card.degraded .poll-track > span { background: var(--muted); }
.poll-card.closed .winner .poll-track > span { background: var(--green); }
.poll-card.closed .winner .poll-code { background: var(--green-bg); color: var(--green); }
.poll-winner { padding: 2px 6px; border-radius: 5px; background: var(--green-bg); color: var(--green); font: 500 10px var(--mono); letter-spacing: .04em; }
.poll-invite { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-top: 1px solid var(--line); padding-top: 12px; font-size: 13px; color: var(--muted); }
.poll-invite .iconbtn { height: 34px; font-size: 12.5px; }
.poll-unavailable { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; border-radius: 9px; background: var(--amber-bg); color: var(--amber); font-size: 12.5px; }
.poll-unavailable > svg { flex: none; width: 15px; height: 15px; margin-top: 2px; }
.poll-unavailable small { display: block; margin-top: 4px; font-size: 12px; }
.poll-show { text-align: right; border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; }
.msg.poll-house { --agent: var(--navy); }
.poll-house .avatar { background: var(--navy-soft); color: var(--navy); }
.poll-house .avatar svg { width: 18px; height: 18px; }
.poll-house .body { min-width: 0; }
.poll-house .poll-card { margin-top: 6px; }
.poll-request { white-space: pre-wrap; overflow-wrap: anywhere; font: 12.5px/1.6 var(--mono); margin: 0; }
.poll-caption { display: flex; gap: 6px; align-items: flex-start; margin-top: 7px; font: 12.5px/1.5 var(--sans); color: var(--muted); }
.poll-caption svg { width: 14px; height: 14px; margin-top: 2px; color: var(--green); }
.poll-caption.refused, .poll-caption.refused svg { color: var(--amber); }
.poll-vote { display: flex; flex-direction: column; gap: 6px; }
.poll-vote-pill { width: fit-content; border-radius: 999px; padding: 3px 9px; background: var(--navy-soft); color: var(--navy); font: 500 12px var(--sans); }
.poll-vote:not(.counted) .poll-vote-pill { background: var(--soft); color: var(--muted); text-decoration: line-through; }
.poll-vote.pending .poll-vote-pill { text-decoration: none; }
.poll-vote-why { white-space: pre-wrap; overflow-wrap: anywhere; }
.poll-vote small { color: var(--muted); font: 12px/1.5 var(--sans); }
.poll-result-link { padding: 0; border: 0; background: transparent; color: var(--green); font: inherit; text-align: center; text-decoration: underline; text-underline-offset: 3px; }
.poll-dialog { position: fixed; inset: auto; margin: 0; padding: 0; width: min(640px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px); overflow-y: auto; border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--shadow-lg); background: var(--surface); color: var(--ink); }
.poll-dialog .poll-card { border: 0; border-radius: inherit; padding-top: 48px; }
.poll-dialog-close { position: absolute; top: 8px; right: 8px; z-index: 1; }
.poll-dialog-close svg { width: 18px; height: 18px; }
.poll-list { padding: 48px 16px 16px; }
.poll-list h2 { font: 700 18px var(--display); margin: 0 0 14px; }
.poll-list button { display: flex; width: 100%; justify-content: space-between; gap: 12px; padding: 12px 0; background: transparent; border: 0; border-bottom: 1px solid var(--line); text-align: left; }
.poll-list button span { overflow-wrap: anywhere; }
.poll-list button small { flex: none; color: var(--muted); }
@media (max-width: 719.98px) {
  .poll-board-wrap { padding-top: 2px; padding-bottom: 10px; }
  .poll-board-button { gap: 10px; padding: 9px 12px; }
  .poll-board-heading { gap: 8px; font-size: 14px; }
  .poll-board-status { font-size: 12px; }
  .poll-mini-options { display: none; }
  .poll-mobile-summary { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
  .poll-stacked-track { display: flex; height: 6px; background: var(--surface); border-radius: 3px; overflow: hidden; }
  .poll-stacked-track i { height: 100%; background: var(--navy); opacity: .55; border-right: 1px solid var(--surface); }
  .poll-stacked-track i.leading { opacity: 1; }
  .poll-card { padding: 14px; gap: 12px; }
  .poll-card h3 { font-size: 16px; }
  .poll-head { gap: 6px; }
  .poll-status { margin-left: 0; }
  .poll-invite { flex-direction: column; align-items: stretch; gap: 8px; }
  .poll-invite .iconbtn { width: 100%; min-height: 40px; }
  .poll-stack-row { grid-template-columns: minmax(0,1fr) auto 16px; gap: 5px 8px; }
  .poll-stack-row > .poll-slug { grid-row: 1; }
  .poll-stack-row > .poll-board-title { grid-row: 2; grid-column: 1 / 3; font-size: 13px; }
  .poll-stack-row > [data-poll-status] { grid-row: 1; grid-column: 2; }
  .poll-stack-row > small { display: none; }
  .poll-stack-row > svg { grid-row: 1 / 3; grid-column: 3; }
  .poll-dialog { left: 0 !important; right: 0; bottom: 0 !important; top: auto !important; width: 100%; max-height: 88dvh; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .poll-dialog::before { content: ""; position: absolute; left: calc(50% - 18px); top: 10px; width: 36px; height: 4px; background: var(--line-2); border-radius: 2px; }
}

.m > .poll-request { margin: 0; padding: 0; border: 0; background: transparent; white-space: pre-wrap; }
.poll-vote > div { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.poll-reasons summary { padding: 1px 9px; border: 1px solid var(--line); border-radius: 999px; }
.poll-voter-reason { display: flex; align-items: baseline; gap: 6px; width: 100%; color: var(--text); font-size: 12.5px; }
.poll-voter-reason > span:last-child { min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
@media (max-width: 719.98px) { .poll-invite .iconbtn { background: var(--navy); border-color: var(--navy); color: var(--on-accent); } }

.poll-voter-reason .poll-person { flex: none; }

.poll-stack-title small { margin-left: auto; font-size: 12px; color: var(--muted); }
.poll-stack-row { display: flex; }
.poll-stack-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 7px; }
.poll-stack-heading { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.poll-stack-heading .poll-slug { color: var(--navy); }
@media (max-width: 719.98px) {
  .poll-stack-heading { flex-wrap: wrap; gap: 4px 8px; }
  .poll-stack-heading .poll-slug { font-size: 12px; }
  .poll-stack-heading .poll-board-title { flex-basis: 100%; order: 1; font-size: 13px; }
  .poll-stack-heading .poll-board-status { font-size: 12px; }
  .poll-stack-title small { display: none; }
}
