/* Nexus Board v0.0.1: compact board layout (from Eric's v0.2 prototype), AI Connect tokens. */
:root {
  --navy: #2c397c; --navy-2: #3b4da8; --navy-soft: #eef0fa;
  --ink: #101827; --text: #474f60; --muted: #5b657b; --faint: #9aa1ae;
  --line: #e6e8ee; --line-2: #cdd2de; --soft: #f5f6fa; --bg: #fff;
  --green: #0b6e0b; --green-bg: #e7f6ec; --amber: #8a5a0b; --amber-bg: #fef3c7; --red: #931414; --red-bg: #fdecec;
  --cyan: #1fb6d9; --cyan-bg: #e3f7fc; --purple: #6d32a4;
  /* Cards #57 and #32: roles the dark theme remaps. Light values are the ones already in use. */
  --surface: #fff; --on-accent: #fff; --line-soft: #f0f1f5; --appbar-bg: rgba(255, 255, 255, 0.96);
  --cyan-ink: #0b5e73; --amber-ink: #6b4608; --brand-cyan: #02d7ee; --brand-violet: #8c49c9;
  --toast-bg: #101827; --toast-fg: #fff; --toast-error: #7f1d1d; --toast-new: #2c397c;
  --scrim: rgba(16, 24, 39, 0.35); --scrim-strong: rgba(16, 24, 39, 0.55); --shadow-sm: 0 1px 2px rgba(16, 24, 39, 0.14);
  --shadow-xl: 0 24px 60px rgba(16, 24, 39, 0.28), 0 4px 12px rgba(16, 24, 39, 0.1);
  --on-agent: #fff; --grid-dot: #d9deea;
  color-scheme: light;
  --radius: 16px; --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);
  --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);
  --page-gutter: 24px;
}

/* Card #57: the dark theme. The head script sets data-theme from the saved choice or the system;
   the roles are composed for a dark room, not inverted: surfaces rise in steps, accents get lighter,
   and text on an accent turns dark. Agent colours stay the same hues (they are identities) and only
   their text is lifted (--agent-ink). */
:root[data-theme="dark"] {
  --navy: #a4b1ff; --navy-2: #bcc6ff; --navy-soft: #232b4d;
  --ink: #eef1f8; --text: #c9cfdb; --muted: #a1a9ba; --faint: #78819a;
  --line: #2a3247; --line-2: #3a4560; --soft: #1d2435; --bg: #0f1422;
  --green: #6fd98a; --green-bg: #13301e; --amber: #f2bf5e; --amber-bg: #33280f; --red: #ff8f8f; --red-bg: #3b181a;
  --cyan: #5ad6ef; --cyan-bg: #0f2e37; --purple: #c9a3ff;
  --surface: #171d2c; --on-accent: #10152a; --line-soft: #222a3b; --appbar-bg: rgba(15, 20, 34, 0.92);
  --cyan-ink: #86e3f6; --amber-ink: #f6cd80;
  --toast-bg: #262e42; --toast-fg: #eef1f8; --toast-error: #6a1f1f;
  --scrim: rgba(0, 0, 0, 0.55); --scrim-strong: rgba(0, 0, 0, 0.7); --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);
  --shadow-xl: 0 24px 60px rgba(0, 0, 0, 0.65), 0 4px 12px rgba(0, 0, 0, 0.4);
  --grid-dot: #262e42;
  color-scheme: dark;
}
:root[data-theme="dark"] .chip, :root[data-theme="dark"] .card { --agent-ink: color-mix(in srgb, var(--agent), #fff 45%); }
:root[data-theme="dark"] .card { border-top-color: var(--agent-ink); }
:root[data-theme="dark"] .chip .dot { background: var(--agent-ink); }
:root[data-theme="dark"] .chip.away .dot { background: var(--surface); box-shadow: inset 0 0 0 2px var(--agent-ink); }
:root[data-theme="dark"] .chip[aria-pressed="true"] .dot { background: var(--on-agent); }
:root[data-theme="dark"] .toast { border: 1px solid var(--line-2); }
/* Kilo on PR #15: without color-mix() the agent hues are too dark to read on the dark surface, so the
   text falls back to the readable text colour and only the decorative marks (card top, dot) keep the hue. */
@supports not (color: color-mix(in srgb, red, white)) {
  :root[data-theme="dark"] .chip, :root[data-theme="dark"] .card { --agent-ink: var(--text); }
  :root[data-theme="dark"] .card { border-top-color: var(--agent); }
  :root[data-theme="dark"] .chip .dot { background: var(--agent); }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
body.board-page { background-image: radial-gradient(var(--grid-dot) 1px, transparent 1.4px); background-size: 22px 22px; background-position: 11px 11px; }
button, input, select { font: inherit; color: inherit; }
svg { flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--navy-2); outline-offset: 2px; }
[hidden] { display: none !important; }

/* header: compact and fixed */
.appbar { position: sticky; top: 0; 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 var(--page-gutter); display: flex; align-items: center; gap: 10px; }
.bar-main { height: 54px; }
.board-heading, .header-actions, .agent-row, .card-tools { display: contents; }
.bar-main .conn { order: 1; }
.bar-main .hgroup { order: 2; }
.bar-tools { position: relative; min-height: 44px; padding-bottom: 8px; flex-wrap: nowrap; row-gap: 6px; }
.bar-tools.search-open .agent-row, .bar-tools.search-open .card-tools { visibility: hidden; }
.clear-filter-icon { display: none; }
.brand { text-decoration: none; display: flex; align-items: center; gap: 8px; font: 800 18px/1 var(--display); color: var(--ink); white-space: nowrap; letter-spacing: -0.01em; }
.brand-mark { width: 26px; height: 26px; display: block; flex: none; }
.divider { width: 1px; height: 22px; background: var(--line); flex: none; }
.switcher { display: flex; align-items: center; gap: 6px; min-width: 0; max-width: 340px; height: 36px; padding: 0 8px 0 10px; border: 1px solid transparent; border-radius: 10px; background: none; cursor: pointer; font-weight: 500; color: var(--ink); }
.switcher:hover, .switcher[aria-expanded="true"] { background: var(--soft); border-color: var(--line); }
.switcher .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher .chev, .iconbtn .chev { color: var(--muted); transition: transform 0.15s var(--ease); }
.switcher[aria-expanded="true"] .chev, .iconbtn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.iconbtn.has-menu { padding-right: 8px; gap: 4px; }
.iconbtn.btn-primary .chev { color: currentColor; }
/* card #58: the header in groups (status, view, actions); a group keeps its buttons together */
.hgroup { display: flex; align-items: center; gap: 6px; flex: none; }
.hgroup-view::before, .hgroup-actions::before { content: ""; width: 1px; height: 22px; margin: 0 4px 0 2px; background: var(--line); }
.conn .txt-short { display: none; }
.pop .sub.url { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 11.5px; }
/* card #58: between phone and wide desktop the brand word and the counts give way first, so the board
   name and the action labels keep their room */
@media (max-width: 1100px) {
  .brand .word, .bar-main .stats { display: none; }
  .divider { display: none; }
}
.stats { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }
.conn { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px; font-size: 12.5px; font-weight: 500; background: var(--soft); color: var(--muted); white-space: nowrap; }
.conn .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.conn[data-state="live"] { background: var(--green-bg); color: var(--green); }
.conn[data-state="live"] .dot { animation: pulse 2.2s infinite; }
.conn[data-state="waiting"] { background: var(--navy-soft); color: var(--navy); }
.conn[data-state="reconnecting"] { background: var(--amber-bg); color: var(--amber); }
.conn[data-state="error"], .conn[data-state="ended"] { background: var(--red-bg); color: var(--red); }
.conn[data-state="closed"] { background: var(--soft); color: var(--muted); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(11, 110, 11, 0.45); } 70% { box-shadow: 0 0 0 6px rgba(11, 110, 11, 0); } 100% { box-shadow: 0 0 0 0 rgba(11, 110, 11, 0); } }
.iconbtn { position: relative; 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); cursor: pointer; font-size: 14px; font-weight: 500; color: var(--ink); white-space: nowrap; }
.iconbtn:hover { background: var(--soft); }
.iconbtn[aria-expanded="true"] { background: var(--soft); border-color: var(--line-2); }
.btn-primary, .iconbtn.btn-primary { background: var(--navy); border-color: var(--navy); color: var(--on-accent); }
.btn-primary:hover, .iconbtn.btn-primary:hover { background: var(--navy-2); }
.iconbtn.emphasis { background: var(--navy-soft); border-color: var(--navy-2); color: var(--navy); }
.badge { position: absolute; top: -6px; right: -6px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: var(--purple); color: var(--on-accent); font-size: 11px; font-weight: 700; line-height: 15px; text-align: center; border: 2px solid var(--surface); }
.badge.warn { background: var(--amber); }
#btn-sound .snd-off { display: none; }
#btn-sound.muted { color: var(--muted); }
#btn-sound.muted .snd-on { display: none; }
#btn-sound.muted .snd-off { display: inline; }

/* agents: presence dots, click to filter */
.agents { display: flex; align-items: center; gap: 6px; flex: 0 1 auto; min-width: 0; overflow: hidden; padding: 2px; }
.agents .chip { max-width: 100%; flex-shrink: 0; }
.lbl-small { font-size: 12px; color: var(--muted); white-space: nowrap; }
.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); cursor: pointer; white-space: nowrap; }
.chip:hover { border-color: var(--line-2); background: var(--soft); }
.chip .dot { flex: none; position: relative; width: 10px; height: 10px; border-radius: 50%; background: var(--agent); }
.chip.active .dot::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 2px solid var(--agent); opacity: 0.35; }
.chip.away { border-style: dashed; }
.chip.away .dot { background: var(--surface); box-shadow: inset 0 0 0 2px var(--agent); }
.chip .n { color: var(--muted); font-family: var(--sans); font-size: 12px; }
/* card #21: names longer than the room are cut with an ellipsis; the full id stays in the title */
.chip > span:nth-child(2) { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; }
.chip[aria-pressed="true"] > span:nth-child(2) { min-width: 6ch; }
.chip.more-agents { flex: none; font-family: var(--sans); color: var(--text); padding: 0 11px; }
.chip.more-agents[aria-expanded="true"] { background: var(--soft); border-color: var(--line-2); }
.pop-agents .agents-list { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 4px 8px 8px; }
.pop-agents .agents-list .chip { max-width: 100%; }
.pop-agents .agents-list .chip > span:nth-child(2) { max-width: 36ch; }
.chip[aria-pressed="true"] { background: var(--agent); border-color: var(--agent); color: var(--on-agent); }
.chip[aria-pressed="true"] .n { color: var(--on-agent); }
.chip[aria-pressed="true"] .dot { background: var(--on-agent); }
.chip .admin-badge { padding: 1px 6px; border-radius: 999px; background: var(--soft); color: var(--navy); font: 600 10.5px var(--sans); letter-spacing: 0.02em; text-transform: uppercase; }
.chip[aria-pressed="true"] .admin-badge { background: var(--on-agent); color: var(--agent); }
.about .about-admin { margin: 6px 0 0; font-size: 12.5px; color: var(--ink); }
.chip.new { animation: chip-in 700ms var(--ease); }
@keyframes chip-in { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.linkbtn { border: 0; background: none; padding: 4px 6px; border-radius: 6px; color: var(--navy-2); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.linkbtn:hover { text-decoration: underline; }

/* sort */
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--soft); border: 1px solid var(--line); }
.seg button { border: 0; background: none; height: 28px; padding: 0 11px; border-radius: 7px; font-size: 13px; color: var(--text); cursor: pointer; white-space: nowrap; }
.seg button:hover { color: var(--ink); }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 500; box-shadow: var(--shadow-sm); }
.sort-select { display: none; height: 32px; border: 1px solid var(--line); border-radius: 9px; padding: 0 8px; background: var(--surface); font-size: 13px; color: var(--ink); }
.hintbar { max-width: 1240px; margin: 0 auto; padding: 0 var(--page-gutter) 8px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.hintbar kbd { font: 500 11px var(--mono); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: var(--surface); color: var(--ink); }

.banner { max-width: 1240px; margin: 0 auto 8px; padding: 8px 24px; font-size: 13.5px; color: var(--amber); background: var(--amber-bg); border-radius: 10px; }
.banner.bad { color: var(--red); background: var(--red-bg); }

/* cards */
main { max-width: 1240px; margin: 0 auto; padding: 20px var(--page-gutter) 120px; }
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: stretch; }
@media (max-width: 1000px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid { grid-template-columns: minmax(0, 1fr); } } /* card #7: a 64-character agent id never widens the column */
.card { --agent: var(--navy); --agent-ink: var(--agent); position: relative; display: flex; flex-direction: column; transition: opacity 0.15s ease, transform 0.15s ease; background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--agent); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 20px 12px; scroll-margin-top: calc(var(--header-h, 124px) + 16px); cursor: pointer; }
.card:focus { outline: none; }
.card:focus-visible { outline: 2px solid var(--navy-2); outline-offset: 3px; }
.card:hover { border-bottom-color: var(--line-2); border-left-color: var(--line-2); border-right-color: var(--line-2); }
.card.open { outline: 2px solid var(--navy-2); outline-offset: 3px; }
#cards.layer-open .card:not(.open), #cards.layer-open .invite-tile { opacity: 0.5; }
.card-top { display: flex; align-items: center; gap: 8px; font: 12px/1 var(--mono); color: var(--muted); min-height: 24px; }
.top-seal { font: 600 10.5px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.06em; padding: 3px 7px; border-radius: 999px; background: var(--green-bg); color: var(--green); }
.card-top .author { min-width: 0; margin-left: auto; color: var(--agent-ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grip { display: inline-flex; opacity: 0.45; align-items: center; justify-content: center; width: 26px; height: 24px; margin-left: -4px; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--muted); cursor: grab; touch-action: none; }
.manual .grip, .card:hover .grip, .grip:focus-visible { opacity: 1; }
.invite-tile { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; justify-content: center; order: 99999; padding: 16px 20px; border: 1.5px dashed var(--navy-2); border-radius: var(--radius); background: var(--navy-soft); transition: opacity 0.15s ease; }
.invite-tile .it-title { margin: 0; font-weight: 700; color: var(--navy); }
.invite-tile .it-text { margin: 0 0 4px; font-size: 13px; color: var(--muted); }
.grip:hover { background: var(--soft); border-color: var(--line); }
.grip[aria-pressed="true"] { background: var(--navy); color: var(--on-accent); }
.card-title { margin: 6px 0; font: 700 17px/1.3 var(--display); color: var(--ink); letter-spacing: -0.005em; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.card-body { margin: 0 0 12px; font-size: 14.5px; line-height: 1.6; overflow-wrap: anywhere; white-space: pre-wrap; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden; }
.card-meta { display: flex; align-items: center; gap: 10px; margin-top: auto; }
.score { display: inline-grid; place-items: center; min-width: 34px; height: 26px; padding: 0 8px; border-radius: 7px; font: 700 12.5px var(--mono); background: var(--soft); color: var(--ink); }
.score.pos { background: var(--green-bg); color: var(--green); }
.score.neg { background: var(--red-bg); color: var(--red); }
.votes { font: 12.5px var(--mono); color: var(--muted); }
.cmt-btn { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--muted); font-size: 13px; cursor: pointer; }
/* Card #16: listen button, shown only with an ElevenLabs key saved in Preferences. */
.voice-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; flex: none; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--muted); cursor: pointer; }
.card-meta .voice-btn { margin-left: auto; }
.card-meta .voice-btn + .cmt-btn { margin-left: 6px; }
.voice-btn:hover { border-color: var(--line-2); color: var(--ink); }
.voice-btn[data-state="playing"], .voice-btn[data-state="loading"] { color: var(--navy); border-color: var(--navy); }
.voice-btn[data-state="loading"] { cursor: progress; }
.voice-btn .voice-spin { animation: voice-spin .9s linear infinite; }
@keyframes voice-spin { to { transform: rotate(360deg); } }
.voice-btn:focus-visible { outline: 2px solid var(--navy-2); outline-offset: 2px; }
.cm-meta .voice-btn { width: 26px; height: 26px; align-self: center; }
/* On a phone the touch area reaches 44px without changing the look; it grows up, down and to the left only,
   so it never covers the comments button beside it nor widens the comment list. */
@media (max-width: 760px) {
  .voice-btn { position: relative; }
  .voice-btn::before { content: ""; position: absolute; inset: -7px 0 -7px -14px; }
  .cm-meta .voice-btn::before { inset: -9px 0 -9px -18px; }
}
.cmt-btn:hover { border-color: var(--line-2); color: var(--ink); }
.cmt-btn.has { color: var(--navy); font-weight: 500; }
.cmt-btn[aria-expanded="true"] { background: var(--navy); border-color: var(--navy); color: var(--on-accent); }
.card-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; font: 12px var(--mono); color: var(--muted); }
.new-badge { font: 700 10.5px var(--sans); text-transform: uppercase; letter-spacing: 0.06em; padding: 2px 7px; border-radius: 999px; background: var(--cyan-bg); color: var(--cyan-ink); }
.detail { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font: 500 12px var(--sans); color: var(--muted); }
.card:hover .detail { color: var(--navy); }
.card.flash { animation: flash 1.8s; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--cyan), var(--shadow); } 100% { box-shadow: var(--shadow); } }
.card.dragging, .card.grabbed { box-shadow: var(--shadow-lg); outline: 2px dashed var(--navy-2); outline-offset: 3px; }
.card.dragging { opacity: 0.55; transform: scale(0.98); }
@media (prefers-reduced-motion: reduce) { .card { transition: none; } .card.dragging { transform: none; } }
.is-dragging, .is-dragging * { cursor: grabbing !important; user-select: none; }

/* states: waiting for the first agent, filter empty, ended */
.state { max-width: 620px; margin: 32px auto; text-align: center; }
.state-icon { width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 14px; display: grid; place-items: center; background: var(--navy-soft); color: var(--navy); }
.state-icon.muted { background: var(--soft); color: var(--muted); }
.state h2 { margin: 0 0 8px; font: 700 22px/1.3 var(--display); color: var(--ink); }
.state p { margin: 0 auto 16px; max-width: 540px; }
.state .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.invite-row { display: flex; gap: 8px; margin: 0 auto 12px; 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; }
.qr { margin: 8px auto 16px; width: fit-content; }
.qr svg { display: block; width: 150px; height: 150px; }
.steps { list-style: none; counter-reset: s; margin: 0 auto 12px; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: left; }
.steps li { counter-increment: s; border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 13.5px; }
.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; }
.hint { font-size: 13.5px; color: var(--muted); }
.foot { margin-top: 48px; font-size: 13px; color: var(--muted); }
.foot p { margin: 4px 0; }
.foot .powered { font-size: 12px; }
.foot .powered a { color: inherit; }

/* popovers */
.pop { position: fixed; z-index: 60; width: 340px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 6px; max-height: calc(100vh - var(--header-h, 104px) - 16px); overflow: auto; }
#pop-boards { width: 380px; }
#pop-bell { width: 380px; }
.pop h3 { margin: 8px 10px 6px; font: 600 11.5px var(--sans); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.pop h3 .attention { margin-left: 6px; text-transform: none; letter-spacing: 0; color: var(--amber); font-weight: 500; }
.pop hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }
.mi { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 7px 10px; border: 0; border-radius: 9px; background: none; text-align: left; cursor: pointer; font-size: 14px; color: var(--ink); }
.mi:hover, .mi:focus-visible { background: var(--soft); outline: none; }
.mi:focus-visible { box-shadow: inset 0 0 0 2px var(--navy-2); }
.mi .sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.mi .grow { flex: 1; min-width: 0; }
.mi[aria-current="true"] { background: var(--navy-soft); }
.mi-row { display: flex; align-items: center; gap: 2px; }
.mi-row .mi { flex: 1; min-width: 0; }
.mi-rm { flex: none; width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer; }
.mi-rm:hover, .mi-rm:focus-visible { background: var(--soft); color: var(--ink); }
.mi.danger { color: var(--red); }
.mi.danger .sub { color: var(--muted); }
.about { margin: 4px 6px 8px; padding: 12px; border-radius: 10px; background: var(--soft); font-size: 13px; }
.about strong { display: block; font: 700 15px var(--display); color: var(--ink); margin-bottom: 4px; }
.about .about-desc { margin: 0 0 6px; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.meta-form { display: flex; flex-direction: column; gap: 8px; margin: 4px 6px 8px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.meta-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 500; color: var(--ink); }
.meta-form .opt { font-weight: 400; color: var(--muted); }
.meta-form input, .meta-form textarea { width: 100%; border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 9px; font: 14px var(--sans); color: var(--ink); background: var(--surface); resize: vertical; }
.meta-form .meta-hint { margin: 0; font-size: 12px; color: var(--muted); }
.meta-form .meta-row { display: flex; gap: 8px; }
.tag { display: inline-block; font: 600 10.5px var(--sans); text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 7px; border-radius: 999px; margin-left: 6px; vertical-align: 1px; }
.tag.ok { background: var(--green-bg); color: var(--green); }
.tag.exp { background: var(--soft); color: var(--muted); border: 1px solid var(--line); }
.pop .note { margin: 4px 10px 8px; font-size: 12px; color: var(--muted); }
.pop-empty { padding: 14px 12px; text-align: center; color: var(--muted); font-size: 13.5px; margin: 0; }
.activity { list-style: none; margin: 0; padding: 0 4px 4px; display: flex; flex-direction: column; gap: 4px; }
.msg { font-size: 13px; padding: 6px 8px; border-radius: 8px; overflow-wrap: anywhere; }
.msg .at { display: block; font: 11.5px var(--mono); color: var(--muted); }
.msg.event { color: var(--text); }
.msg.unanswered { background: var(--red-bg); color: var(--red); }
.msg.unread { box-shadow: inset 3px 0 0 var(--purple); }

/* card #11: the details are a drawer on the right (a sheet on the phone) with one scroll: the whole
   description, then the comments. The header stays put outside the scroll, so nothing hides behind it. */
.cmt { --drawer-w: clamp(360px, 40vw, 480px); position: fixed; z-index: 50; top: var(--header-h, 104px); right: 0; bottom: 0; width: var(--drawer-w); display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-xl); }
body.cmt-drawer main { margin-right: clamp(360px, 40vw, 480px); }
body.cmt-drawer .grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.cmt-head { flex: none; display: flex; gap: 4px; align-items: flex-start; padding: 14px 10px 10px 16px; border-bottom: 1px solid var(--line); position: relative; }
.cmt-headtext { flex: 1; min-width: 0; }
.cmt-kicker { font: 12px var(--mono); color: var(--muted); }
.cmt-head h2 { margin: 2px 0 0; font: 700 15px/1.3 var(--display); color: var(--ink); overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.cmt-head .iconbtn { flex: none; border-color: transparent; }
.cmt-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; overflow-anchor: none; }
.cmt-body:focus-visible { outline: 2px solid var(--navy-2); outline-offset: -2px; }
.cmt-desc { margin: 0; padding: 12px 16px 14px; border-bottom: 1px solid var(--line); font-size: 14px; line-height: 1.55; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.cmt-section { margin: 0; padding: 12px 16px 4px; font: 500 12px var(--mono); color: var(--muted); }
.cmt-list { list-style: none; margin: 0; padding: 0 0 12px; }
.cmt-list > li { display: flex; gap: 10px; padding: 10px 16px; }
.cmt-list > li + li { border-top: 1px solid var(--line-soft); }
.cmt-list > li.fresh { animation: fresh 2.4s; }
@keyframes fresh { 0%, 50% { background: var(--cyan-bg); } 100% { background: transparent; } }
.av { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font: 700 11px var(--sans); color: var(--on-agent); flex: none; }
.cm-meta { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: var(--muted); }
/* card #7: a 64-character agent id is cut with an ellipsis; time and position stay in view */
.cm-meta b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 12.5px var(--mono); color: var(--ink); }
.cm-meta > :not(b) { flex: none; white-space: nowrap; }
.cm-meta .ord { margin-left: auto; font-family: var(--mono); }
.cm-text { margin: 2px 0 0; font-size: 14px; color: var(--text); overflow-wrap: anywhere; white-space: pre-wrap; }
.cmt-empty { padding: 28px 20px; text-align: center; color: var(--muted); font-size: 14px; }
.cmt-jump, .cmt-to-comments { position: absolute; left: 50%; bottom: max(16px, var(--toasts-clear, 0px)); transform: translateX(-50%); height: 30px; padding: 0 12px; border-radius: 999px; border: 0; background: var(--navy); color: var(--on-accent); font-size: 12.5px; font-weight: 500; box-shadow: var(--shadow); cursor: pointer; white-space: nowrap; }
.cmt-to-comments::after { content: " \2193"; content: " \2193" / ""; } /* decoration: screen readers skip the arrow */
.backdrop { position: fixed; inset: 0; z-index: 49; background: var(--scrim); }
.cmt.sheet { top: auto; left: 0; width: auto; height: 90vh; height: 90dvh; border-left: 0; border-radius: 18px 18px 0 0; }

/* toasts */
.toasts { position: fixed; left: 50%; bottom: 20px; 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 { pointer-events: auto; display: flex; align-items: center; gap: 12px; max-width: 100%; padding: 8px 8px 8px 16px; border-radius: 12px; background: var(--toast-bg); color: var(--toast-fg); font-size: 14px; box-shadow: var(--shadow-lg); animation: tin 0.2s ease-out; }
.toast[data-kind="new"] { background: var(--toast-new); }
.toast[data-kind="error"] { background: var(--toast-error); }
.toast .msg-t { flex: 1; min-width: 0; }
.toast .t-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--agent, var(--toast-fg)); box-shadow: 0 0 0 2px var(--toast-fg); flex: none; }
.toast .t-act { height: 30px; padding: 0 12px; border: 0; border-radius: 8px; background: var(--toast-fg); color: var(--toast-bg); font-weight: 500; font-size: 13px; cursor: pointer; white-space: nowrap; }
.toast .t-x { width: 30px; height: 30px; border: 0; border-radius: 8px; background: none; color: var(--toast-fg); cursor: pointer; display: grid; place-items: center; }
.toast .t-x:hover { background: rgba(255, 255, 255, 0.12); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* QR dialog */
.lightbox { border: 0; padding: 0; background: transparent; }
.lightbox::backdrop { background: var(--scrim-strong); }
.lightbox-card { background: var(--surface); border-radius: 16px; padding: 20px 24px; text-align: center; box-shadow: var(--shadow-lg); }
.lightbox-card h2 { margin: 0 0 8px; font: 700 18px var(--display); color: var(--ink); }
.lightbox-card .qr svg { width: 220px; height: 220px; }

/* a light touch of confetti, once per board, on the first agent */
.confetti { position: fixed; top: 0; left: 0; width: 8px; height: 12px; border-radius: 2px; z-index: 80; pointer-events: none; animation: fall 1.4s var(--ease) forwards; }
@keyframes fall { to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; } }

@media (max-width: 760px) {
  :root { --page-gutter: 16px; }
  main { padding: 14px var(--page-gutter) 120px; }
  .steps { grid-template-columns: 1fr; }
  .pop { left: 8px !important; right: 8px; width: auto !important; }
  .toasts { bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } .confetti { display: none; } }

/* Find and share cards: keep controls and notices within the existing board hierarchy. */
/* card #21: the search opens over the tools row and closes back to an icon; the filter stays */
.card-search { position: absolute; z-index: 5; left: 24px; right: 24px; top: 0; height: 36px; display: flex; align-items: center; gap: 7px; min-width: 0; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow-sm); color: var(--muted); }
.card-search:focus-within { outline: 2px solid var(--navy-2); outline-offset: 2px; }
.card-search input { min-width: 0; width: 100%; border: 0; background: transparent; color: var(--ink); outline: none; font-size: 14px; }
.card-search input::placeholder { color: var(--muted); opacity: 1; }
.card-search input::-webkit-search-cancel-button { display: none; }
.card-search button { display: flex; align-items: center; justify-content: center; min-width: 32px; min-height: 34px; padding: 0; background: transparent; border: 0; border-radius: 4px; cursor: pointer; }
.card-search button:hover { background: var(--soft); }
.card-search .close-search { min-width: auto; padding: 0 8px; font-size: 13px; color: var(--text); }
#btn-search { flex: none; }
#btn-search.on { border-color: var(--navy-2); color: var(--navy); }
#btn-search .search-dot { display: none; position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--navy-2); }
#btn-search.on .search-dot { display: block; }
.search-pill { display: inline-flex; align-items: center; min-width: 0; max-width: 220px; height: 30px; border: 1px solid var(--line); border-radius: 999px; background: var(--navy-soft); color: var(--navy); font-size: 12.5px; }
.search-pill button { border: 0; background: none; color: inherit; cursor: pointer; height: 100%; }
.search-pill-q { min-width: 0; padding: 0 4px 0 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-pill-x { display: inline-flex; align-items: center; padding: 0 9px 0 5px; border-radius: 0 999px 999px 0; }
.search-pill-x:hover { background: var(--soft); }
.search-summary { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.navigation-notice, .temporary-card-note, .cmt-notice { padding: 10px 12px; background: var(--navy-soft); color: var(--navy); border-radius: 8px; font-size: 13px; }
.temporary-card-note { margin: 8px 0 0; }
.cmt-notice { margin: 10px 16px 0; }
.grip:disabled { opacity: 0.35; cursor: default; }
.activity-link { color: inherit; text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
.activity-link:hover { color: var(--navy); text-decoration-color: currentColor; }
.cmt-list li:focus { outline: 2px solid var(--navy-2); outline-offset: -2px; background: var(--navy-soft); }

/* Context panel uses the same surface and focus hierarchy as card details. */
.context-panel { position:fixed; z-index:60; top:calc(var(--header-h,64px) + 12px); right:1.5rem; bottom:1.5rem; width:min(34rem,calc(100vw - 3rem)); overflow:auto; background:var(--surface,#fff); color:var(--ink,#111827); border:1px solid var(--line,#dfe3ed); border-radius:1.25rem; padding:1.5rem; box-shadow:0 18px 60px #0003; }
.context-panel[hidden] { display:none; }
.context-panel header { display:flex; align-items:center; justify-content:space-between; gap:1rem; }
.context-panel h2 { margin:0; }
.context-item { border-top:1px solid var(--line,#dfe3ed); padding:1rem 0; overflow-wrap:anywhere; }
.context-item h3 { margin:0 0 .5rem; font-size:1rem; }
.context-item .context-actions { display:flex; flex-wrap:wrap; gap:.75rem; margin-top:.75rem; }
.context-panel form { border-top:1px solid var(--line,#dfe3ed); padding-top:1rem; display:grid; gap:.75rem; }
.context-panel form[hidden] { display:none; }
.context-panel textarea { width:100%; box-sizing:border-box; resize:vertical; }
.context-panel button, .context-panel input, .context-panel textarea { font:inherit; }
.context-panel button { cursor:pointer; }
html[data-theme="dark"] .context-panel { background:#182034; color:#edf0f7; border-color:#3a4358; }
@media(max-width:600px) { .context-panel { inset:.5rem; width:auto; padding:1rem; } }

.context-toolbar {display:flex;align-items:center;justify-content:flex-end;gap:10px;max-width:1240px;margin:0 auto;padding:0 var(--page-gutter) 8px;}
#btn-context {flex:none;}
.context-toolbar .bar-tools {flex:1;min-width:0;padding:0;}
.context-actions button, #context-form button, #context-recovery button {border:1px solid var(--line,#dfe2eb);border-radius:10px;padding:8px 12px;font:inherit;background:var(--surface,#fff);color:inherit;cursor:pointer;}
html[data-theme="dark"] .context-actions button, html[data-theme="dark"] #context-form button, html[data-theme="dark"] #context-recovery button {background:#202535;}

.context-panel textarea {border:1px solid var(--line-2);border-radius:10px;background:var(--surface);color:var(--ink);padding:10px;}
.context-actions a {color:var(--navy);align-self:center;}
.context-panel input[type="file"] {max-width:100%;color:var(--text);}
.context-panel input[type="file"]::file-selector-button {font:inherit;border:1px solid var(--line-2);border-radius:8px;background:var(--soft);color:var(--ink);padding:8px;margin-right:8px;}
@media(max-width:760px) { .context-actions button, .context-actions a, #context-close {min-height:44px;} }

/* Compact controls keep the selected author readable without a tall landscape header.
   Context stays outside #tools so an empty board can still open it. */
@media (max-width: 1150px) {
  .brand .word, .divider, .bar-main .stats, .appbar .lbl, .conn .txt { display: none; }
  .bar-main .brand { width: 44px; height: 44px; }
  .hgroup { gap: 4px; }
  .hgroup-view::before, .hgroup-actions::before { display: none; }
  .conn { padding: 0 9px; }
  .conn .txt-short { display: inline; }
  .appbar .iconbtn, .appbar #btn-preferences { padding: 0; width: 44px; min-width: 44px; height: 44px; }
  .seg { display: none; }
  .sort-select { display: inline-block; min-width: 0; height: 44px; }
  .bar-tools .lbl-small, .bar-tools > .spacer { display: none; }
  .search-pill { max-width: none; height: 46px; justify-content: space-between; }
  .search-pill-x { min-width: 44px; justify-content: center; }
  .appbar .chip { min-height: 44px; }
  #agents-here .chip > span:nth-child(2) { max-width: 14ch; }
  #clear-filter { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 44px; min-height: 44px; }
  .clear-filter-icon { display: block; }
  .clear-filter-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .card-search { position: static; width: 100%; height: 44px; min-height: 44px; }
  .card-search input { font-size: 16px; }
  .card-search button { min-width: 44px; min-height: 44px; }
  .bar-tools.search-open .agent-row, .bar-tools.search-open .card-tools { visibility: visible; }
}
/* Two rows on narrow desktops/tablets and phones in landscape; a query adds one row. */
@media (min-width: 761px) and (max-width: 1150px) {
  .bar-main { gap: 8px; }
  .bar-main > .spacer { display: none; }
  .switcher { flex: 1; max-width: none; height: 44px; }
  .context-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) max-content minmax(140px, 180px) max-content; gap: 8px; }
  .context-toolbar .bar-tools, .card-tools { display: contents; }
  .agent-row { display: flex; align-items: center; gap: 8px; min-width: 0; grid-column: 1; grid-row: 1; }
  #btn-search { grid-column: 2; grid-row: 1; }
  .sort-select { grid-column: 3; grid-row: 1; }
  #btn-context { grid-column: 4; grid-row: 1; }
  .search-pill, .card-search { grid-column: 1 / -1; grid-row: 2; }
}
@media (min-width: 761px) and (max-height: 500px) {
  /* A filter notice and title can exceed the available panel height in landscape. */
  .cmt:not(.sheet) { overflow: auto; }
}
/* Phone portrait: actions, board identity, agents, then card tools. */
@media (max-width: 760px) {
  .bar-main { height: auto; flex-wrap: wrap; padding: 8px var(--page-gutter); gap: 8px; row-gap: 6px; }
  .bar-main > .spacer { display: none; }
  .bar-main .brand { margin-right: auto; }
  .header-actions { display: flex; flex: none; gap: 8px; }
  .board-heading { display: grid; grid-template-columns: minmax(0, 1fr) max-content; align-items: center; gap: 8px; order: 1; flex: 1 0 100%; min-width: 0; }
  .switcher { height: 44px; width: 100%; max-width: none; }
  .context-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) max-content; gap: 8px; }
  .context-toolbar .bar-tools { display: contents; }
  .agent-row { display: flex; align-items: center; gap: 8px; min-width: 0; grid-column: 1 / -1; grid-row: 1; }
  .card-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; grid-column: 1; grid-row: 2; }
  #btn-context { grid-column: 2; grid-row: 1; }
  #tools:not([hidden]) ~ #btn-context { grid-row: 2; align-self: end; }
  .search-pill { flex: 1 0 100%; }
  .sort-select { flex: 1; }
  .card-search { grid-column: 1 / -1; grid-row: 3; }
}
@media (max-width: 380px) {
  :root { --page-gutter: 12px; }
  .bar-main { column-gap: 4px; }
  .header-actions { gap: 4px; }
  .appbar .badge { right: 2px; }
  .agent-row { display: grid; grid-template-columns: minmax(0, max-content) max-content minmax(0, 1fr); }
  .agent-row .agents { grid-column: 1; grid-row: 1; }
  .agent-row .more-agents { grid-column: 2; grid-row: 1; }
  #clear-filter { grid-column: 1 / -1; grid-row: 2; justify-self: end; }
  #tools.author-filtered .agents { grid-column: 1 / -1; }
  #tools.author-filtered .more-agents { grid-column: 1; grid-row: 2; justify-self: start; }
}
@media (max-width: 340px) {
  :root { --page-gutter: 8px; }
  /* Six 44px targets fit at 280px; spacing grows to 4px as room becomes available. */
  .bar-main { column-gap: clamp(0px, calc(20vw - 56px), 4px); }
  .header-actions, .hgroup { gap: clamp(0px, calc(20vw - 56px), 4px); }
}

/* Card content: the same safe subset in descriptions and discussions. */
.markdown-content { white-space: normal; }
.markdown-content p { margin: 0 0 .75em; white-space: pre-wrap; }
.markdown-content ul, .markdown-content ol { margin: 0 0 .75em; padding-left: 1.5em; }
.markdown-content li { white-space: pre-wrap; }
.markdown-content > :last-child { margin-bottom: 0; }
.markdown-content code { font: .9em var(--mono, monospace); background: var(--soft); border-radius: 3px; padding: .1em .25em; overflow-wrap: anywhere; }
.markdown-content a, .cm-text a { color: var(--navy-2); text-decoration: underline; overflow-wrap: anywhere; }

/* Tag labels inherit the board palette; grouped views keep one card identity. */
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.tag-chip, .tag-filter { border: 1px solid var(--line-2); background: var(--surface); color: var(--text); border-radius: 999px; padding: 5px 10px; font: 500 12px var(--mono); cursor: pointer; overflow-wrap: anywhere; }
.tag-chip:hover, .tag-chip[aria-pressed="true"], .tag-filter { color: var(--navy); border-color: var(--navy-2); background: var(--navy-soft); }
.tag-filter { max-width: 100%; }
.tag-groups { display: block; }
.tag-group { margin-bottom: 28px; }
.tag-group-head { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line-2); margin-bottom: 14px; padding-bottom: 6px; }
.tag-group-name { border: 0; background: none; color: var(--ink); font: 600 14px var(--sans); padding: 6px 0; overflow-wrap: anywhere; }
button.tag-group-name { cursor: pointer; }
button.tag-group-name:hover { text-decoration: underline; text-underline-offset: 3px; }
.tag-group-toggle { margin-left: auto; display: inline-flex; align-items: center; justify-content: center; flex: none; width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--text); cursor: pointer; }
.tag-group-toggle:hover { background: var(--soft); }
.tag-groups .grip { visibility: hidden; }
#cmt-tags { padding: 14px 16px 0; }
@media (max-width: 760px) {
  .tag-chip, .tag-filter { min-height: 44px; }
  .tag-group-toggle { width: 44px; height: 44px; }
}
