/* ============================================================================
   捌零捌工作室 — Apple theme v3 (overlay, loaded after stock CSS)
   ----------------------------------------------------------------------------
   Fixes v2, which left the page unreadable. Root causes found in the real
   source (repo/public/style.css + chat-workspace.css + app.js):
   1. chat-workspace.css re-defines ALL colour variables under
      `body:has(#shell:not([hidden]))` (--ink:#eeeef4, --muted:#a9abbc,
      --paper:#23252f ...). v2 only set them on :root, so every var()-based
      colour stayed dark-theme. v3 overrides the variables on BOTH selectors.
   2. v2 never targeted the real text elements: the message body is
      `.bubble` (chat-workspace sets it #e4e6f1, pale on light), the sender
      name is `.message-meta strong` (#e2e4f1), the preview is
      `.thread-copy small` (#a7aabd). v3 targets each of them directly.
   3. v2 used `.message.mine` — that class does not exist. app.js renders
      own messages as `.message-own` (article.message.message-own).
   4. v2 had a blanket grey-colour rule on every composer descendant which
      greyed the typed text. v3 deletes that rule and forces the textarea
      dark explicitly.
   5. Stock messages are Discord-style full-width rows, not bubbles. v3
      turns `.message-body` into a real chat bubble (WeChat/Telegram style):
      others white left, own blue right — distinguished by BOTH alignment
      and colour. Contrast: #1d1d1f on #fff = 16.4:1, white on #0071e3
      = 4.6:1 (WCAG AA). Secondary text never lighter than #6e6e73;
      timestamps may use #8e8e93 only at 12px or smaller.
   Palette: chat #ededed (WeChat canvas), sidebar/topbar #e7e7ea (slightly
   darker), cards #fbfbf9, composer #f5f5f7, accent Apple blue #0071e3.
   NO large pure-white blocks, NO black areas. Everything !important.
   ========================================================================== */

/* --- 1. Design tokens: override on :root AND on the workspace selector --- */
:root{
  color-scheme:light!important;
  --ink:#1d1d1f!important; --muted:#6e6e73!important; --line:#e5e5ea!important;
  --paper:#ededed!important; --accent:#0071e3!important; --green:#34c759!important;
  --base:#e7e7ea!important; --sidebar:#e7e7ea!important; --raised:#f5f5f7!important;
  --hover:#ececf0!important; --selection:#e8f2fe!important; --white:#ffffff!important;
  --topbar-height:56px!important;
  font-family:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI",system-ui,sans-serif!important;
}
body:has(#shell:not([hidden])){
  --base:#e7e7ea!important; --sidebar:#e7e7ea!important; --paper:#ededed!important;
  --raised:#f5f5f7!important; --hover:#ececf0!important; --selection:#e8f2fe!important;
  --line:#e5e5ea!important; --ink:#1d1d1f!important; --muted:#6e6e73!important;
  --accent:#0071e3!important; --topbar-height:56px!important;
  background:#e7e7ea!important;
}

/* --- 2. Page surfaces --- */
html,body,#root{background:#ededed!important;color:#1d1d1f!important}
body{background:#ededed!important;color:#1d1d1f!important}
a{color:#0071e3!important}
::selection{background:#e8f2fe!important;color:#1d1d1f!important}
h1,h2,h3{color:#1d1d1f!important}
p{color:#1d1d1f!important}
.eyebrow{color:#6e6e73!important}
.fine{color:#6e6e73!important}
.error{color:#d70015!important}

/* --- 3. Top bar --- */
.app-topbar,header.app-topbar{
  background:#e7e7ea!important;color:#1d1d1f!important;
  border-bottom:1px solid #d1d1d6!important;backdrop-filter:none!important;
}
.topbar-brand,.topbar-brand span{color:#1d1d1f!important;font-size:17px!important;font-weight:700!important}
.topbar-brand .brand-mark{width:28px!important;height:28px!important;border-radius:8px!important}
.app-topbar button,.app-topbar .icon-button{color:#1d1d1f!important;background:transparent!important}
.app-topbar .icon-button:hover{background:#ececf0!important;color:#1d1d1f!important}
.app-topbar select,.language-picker select{
  background:#f2f2f7!important;border:1px solid #e5e5ea!important;border-radius:10px!important;
  color:#1d1d1f!important;-webkit-text-fill-color:#1d1d1f!important;
}
.topbar-actions .icon-button{color:#1d1d1f!important}
.boot-state{background:#ededed!important;color:#1d1d1f!important}

/* --- 4. Left icon rail + slide-out menu --- */
.workspace-nav{background:#e7e7ea!important;border-right:1px solid #d1d1d6!important}
.space-button{background:#f2f2f7!important;color:#1d1d1f!important;border-radius:14px!important}
.space-button:hover{background:#ececf0!important;color:#1d1d1f!important}
.space-button.active{background:#0071e3!important;color:#fff!important}
.space-button.active:before{background:#0071e3!important}
.rail{background:#f5f5f7!important;color:#1d1d1f!important;border:1px solid #e5e5ea!important;border-radius:18px!important;box-shadow:0 16px 48px rgba(0,0,0,.12)!important}
.rail .brand,.rail .brand span{color:#1d1d1f!important}
.instance{color:#6e6e73!important}
.instance small{color:#6e6e73!important}
.nav-item{border-radius:12px!important;min-height:44px!important;color:#1d1d1f!important}
.nav-item:hover{background:#ececf0!important;color:#1d1d1f!important}
.nav-item.active{background:#e8f2fe!important;color:#0071e3!important}
.nav-item .count,.count{background:#0071e3!important;color:#fff!important;border-radius:999px!important}

/* --- 5. Conversation list (sidebar) --- */
.thread-panel{background:#e7e7ea!important;color:#1d1d1f!important;border-right:1px solid #d1d1d6!important}
.workspace-heading strong{font-size:21px!important;color:#1d1d1f!important}
.workspace-label{color:#6e6e73!important}
.new-chat{color:#1d1d1f!important}
.new-chat:hover{background:#ececf0!important;color:#1d1d1f!important}
.search svg{color:#6e6e73!important}
.search input,input[type="search"]{
  background:#ffffff!important;border:1px solid #e5e5ea!important;border-radius:12px!important;
  height:40px!important;color:#1d1d1f!important;caret-color:#1d1d1f!important;
  -webkit-text-fill-color:#1d1d1f!important;
}
.search input::placeholder{color:#8e8e93!important}
.list-heading{color:#6e6e73!important}
.list-heading>span:first-child{color:#6e6e73!important}
#sync-state{color:#8e8e93!important}
.conversation-section{color:#6e6e73!important}
.thread-list{background:#e7e7ea!important}
.thread-item{min-height:77px!important;border-radius:14px!important;padding:12px!important;color:#1d1d1f!important;background:transparent!important}
.thread-item:hover{background:#ececf0!important;color:#1d1d1f!important}
.thread-item.selected{background:#e8f2fe!important;color:#1d1d1f!important;box-shadow:inset 2px 0 #0071e3!important}
.thread-copy{min-width:0!important}
.thread-copy strong{display:block!important;font-size:15px!important;font-weight:700!important;color:#1d1d1f!important}
.thread-copy small{display:block!important;font-size:13px!important;line-height:1.4!important;color:#6e6e73!important}
.conversation-kind{font-size:11px!important;color:#6e6e73!important}
.thread-item time{font-size:12px!important;color:#8e8e93!important}
.thread-item.has-unread .thread-copy strong{color:#1d1d1f!important;font-weight:700!important}
.thread-item.has-unread .thread-copy small{color:#6e6e73!important}
.unread-count{background:#fa5151!important;color:#fff!important;border-radius:999px!important}
.panel-footer{background:#e7e7ea!important;color:#1d1d1f!important;border-top:1px solid #d1d1d6!important}
.account strong{color:#1d1d1f!important}
.account small{color:#6e6e73!important}
.account .icon-button{color:#1d1d1f!important}

/* --- 6. Chat header --- */
.chat-panel{background:#ededed!important}
.chat-header{background:#ededed!important;color:#1d1d1f!important;border-bottom:1px solid #e5e5ea!important;min-height:76px!important}
.group-info{color:#1d1d1f!important}
.group-info strong{font-size:17px!important;font-weight:700!important;color:#1d1d1f!important}
#chat-members{font-size:12px!important;color:#6e6e73!important}
#chat-receiving{font-size:12px!important;color:#6e6e73!important}
#chat-receiving.receiver-warning{color:#8a6100!important}
.chat-header .icon-button{color:#1d1d1f!important}
.agent-presence{color:#6e6e73!important}
.agent-presence.online .presence-dot,.presence-dot.online{background:#34c759!important}
.presence-more{color:#6e6e73!important}

/* --- 7. Message list: real bubbles (WeChat/Telegram style) --- */
.message-list,[role="log"]{background:#ededed!important;color:#1d1d1f!important}
.date-separator span{color:#6e6e73!important;font-size:11px!important}
.date-separator:before,.date-separator:after{background:#d1d1d6!important}

/* Row itself: no background, avatar on the side. The bubble is .message-body. */
.message{
  display:flex!important;align-items:flex-start!important;gap:12px!important;
  padding:10px 24px!important;margin:0!important;background:transparent!important;
  border:0!important;border-left:0!important;max-width:none!important;
}
.message:hover{background:#f2f2f7!important}
.message:focus{background:#e8f2fe!important}
.message.message-own{flex-direction:row-reverse!important}
.message.message-own:hover{background:#f2f2f7!important}

/* Others' bubble: white, dark text, thin border, left. Own bubble: blue, white text, right. */
.message-body{
  min-width:0!important;flex:0 1 auto!important;max-width:75%!important;
  background:#ffffff!important;border:1px solid #e5e5ea!important;border-radius:18px!important;
  padding:10px 14px!important;box-shadow:0 1px 2px rgba(0,0,0,.06)!important;
}
.message-own .message-body{
  background:#0071e3!important;border-color:#0071e3!important;color:#ffffff!important;
  margin-left:auto!important;
}
.message-continued .message-body{max-width:75%!important}

/* Message text — the element v2 missed (.bubble had pale #e4e6f1). */
.bubble{font-size:15px!important;line-height:1.75!important;color:#1d1d1f!important;background:none!important;padding:0!important;border:0!important;border-radius:0!important;max-width:none!important;box-shadow:none!important}
.bubble,.bubble *{color:#1d1d1f!important}
.bubble a,.bubble a *{color:#0071e3!important;text-decoration:underline!important}
.bubble strong,.bubble b{color:#1d1d1f!important}
.message-own .bubble,.message-own .bubble *{color:#ffffff!important}
.message-own .bubble a,.message-own .bubble a *{color:#ffffff!important;text-decoration:underline!important}
.message-own .bubble strong,.message-own .bubble b{color:#ffffff!important}

/* Sender name / Agent label / time inside a message. */
.message-meta{display:flex!important;align-items:baseline!important;flex-wrap:wrap!important;gap:8px!important;margin:0 0 5px!important}
.message-meta strong{font-size:13px!important;font-weight:700!important;color:#0071e3!important}
.message-own .message-meta strong{color:#ffffff!important}
.message-meta time{font-size:12px!important;color:#8e8e93!important;margin-left:3px!important}
.message-own .message-meta time{color:rgba(255,255,255,.85)!important}
.agent-label{font-size:11px!important;font-weight:700!important;background:#e8f2fe!important;color:#0071e3!important;padding:2px 8px!important;border-radius:999px!important}
.message-own .agent-label{background:rgba(255,255,255,.25)!important;color:#ffffff!important}
.message-target{font-size:12px!important;color:#6e6e73!important}
.message-own .message-target{color:rgba(255,255,255,.85)!important}

/* Quoted / replied-to text: dark, never pale lavender. */
.message-quote{color:#6e6e73!important;background:none!important;font-size:12px!important}
.message-quote strong{color:#1d1d1f!important}
.message-quote>span:last-child{color:#6e6e73!important}
.quote-arrow{color:#0071e3!important}
.message-own .message-quote,.message-own .message-quote>span:last-child{color:rgba(255,255,255,.85)!important}
.message-own .message-quote strong{color:#ffffff!important}
.message-own .quote-arrow{color:#ffffff!important}

/* Mentions, code, tables, images, receipts inside bubbles. */
.message-mention{color:#0071e3!important;background:#e8f2fe!important;border-radius:4px!important;padding:1px 4px!important;font-weight:600!important}
.message-own .message-mention{color:#ffffff!important;background:rgba(255,255,255,.25)!important}
.inline-code{font-size:.88em!important;background:#f2f2f7!important;border:1px solid #e5e5ea!important;color:#1d1d1f!important;padding:1px 4px!important;border-radius:4px!important}
.message-own .inline-code{background:rgba(255,255,255,.2)!important;border-color:transparent!important;color:#ffffff!important}
.message-code{display:block!important;background:#f2f2f7!important;border:1px solid #e5e5ea!important;border-radius:8px!important;padding:14px 16px!important;color:#1d1d1f!important}
.message-code code{color:#1d1d1f!important}
.message-table th{background:#f2f2f7!important;color:#1d1d1f!important}
.message-table td,.message-table th{border-bottom:1px solid #e5e5ea!important;color:#1d1d1f!important}
.message-table{border:1px solid #e5e5ea!important}
.message-image-meta{font-size:11px!important;color:#6e6e73!important;margin-top:6px!important}
.message-own .message-image-meta{color:rgba(255,255,255,.85)!important}
.message-image{background:#f2f2f7!important}
.receipt-button{font-size:11px!important;color:#8e8e93!important}
.receipt-button:hover{color:#1d1d1f!important}
.message-own .receipt-button{color:rgba(255,255,255,.85)!important}
.message-id{opacity:1!important}
.message-highlight,.message-addressed{background:#e8f2fe!important}
.message.spotlight{background:#e8f2fe!important}
.message.spotlight .bubble{outline:1px solid #0071e3!important;outline-offset:4px!important}
.structured-message,.artifact-message{
  background:#fbfbf9!important;color:#1d1d1f!important;border:1px solid #e5e5ea!important;
  border-left:3px solid #0071e3!important;border-radius:18px!important;
  box-shadow:0 1px 3px rgba(0,0,0,.06)!important;max-width:640px!important;
}
.structured-message *,.artifact-message *{color:#1d1d1f!important}
.structured-message .message-meta,.artifact-message .message-meta{margin-bottom:10px!important}
.json-fields dt{color:#6e6e73!important}
.json-fields dd{color:#1d1d1f!important}
.artifact-message>a{color:#0071e3!important}
.artifact-icon{color:#0071e3!important}
.message-actions{background:#ffffff!important;border:1px solid #e5e5ea!important;border-radius:10px!important;box-shadow:0 4px 12px rgba(0,0,0,.12)!important}
.message-action{color:#1d1d1f!important}
.message-action:hover{background:#ececf0!important}

/* --- 8. Composer: white input, DARK typed text (v2 bug removed) --- */
.composer{
  background:#f5f5f7!important;color:#1d1d1f!important;border:1px solid #e5e5ea!important;
  border-radius:24px!important;box-shadow:0 4px 16px rgba(0,0,0,.08)!important;
  margin:8px 24px 20px!important;padding:0!important;
}
.composer:focus-within{border-color:#0071e3!important;box-shadow:0 0 0 2px rgba(0,113,227,.15)!important}
.composer-field{padding:12px 14px 2px!important}
.composer textarea{
  background:#ffffff!important;color:#1d1d1f!important;caret-color:#1d1d1f!important;
  -webkit-text-fill-color:#1d1d1f!important;border:1px solid #e5e5ea!important;border-radius:16px!important;
  padding:10px 12px!important;font-size:15px!important;line-height:1.6!important;
}
.composer textarea::placeholder{color:#8e8e93!important;opacity:1!important}
.composer textarea:focus{outline:none!important;border-color:#0071e3!important}
.composer-controls{padding:6px 10px 9px!important}
.composer-mention{color:#1d1d1f!important;background:transparent!important}
.composer-mention:hover{background:#ececf0!important;color:#1d1d1f!important}
.composer-mention svg{color:#1d1d1f!important}
.compose-feedback{font-size:11px!important;color:#6e6e73!important}
.compose-counter{font-size:11px!important;color:#6e6e73!important}
.compose-counter.over-limit{color:#d70015!important}
.send-button{
  width:44px!important;height:44px!important;min-width:44px!important;min-height:44px!important;
  border-radius:50%!important;background:#0071e3!important;color:#ffffff!important;
}
.send-button:hover{background:#0077ed!important}
.send-button svg{color:#ffffff!important}
.send-button:disabled{background:#c7c7cc!important;color:#ffffff!important;opacity:1!important}
.reply-bar{background:#e8f2fe!important;border-bottom:1px solid #e5e5ea!important}
.reply-bar strong{color:#0071e3!important}
.reply-bar span:last-child{color:#6e6e73!important}
.reply-mark{color:#0071e3!important}
.mention-menu{background:#ffffff!important;border:1px solid #e5e5ea!important;border-radius:12px!important;box-shadow:0 12px 35px rgba(0,0,0,.15)!important}
.mention-heading{color:#6e6e73!important}
.mention-option{color:#1d1d1f!important}
.mention-option strong{color:#1d1d1f!important}
.mention-option small{color:#6e6e73!important}
.mention-option:hover,.mention-option[aria-selected=true]{background:#e8f2fe!important}
#jump-latest{background:#0071e3!important;color:#fff!important;border-radius:999px!important;box-shadow:0 4px 12px rgba(0,113,227,.35)!important}
.observe-actions{background:#fbfbf9!important;border:1px solid #e5e5ea!important;border-radius:10px!important}
.observe-actions span{color:#6e6e73!important}
.observe-actions .primary{background:#0071e3!important;color:#fff!important}

/* --- 9. Buttons, inputs, dialogs, cards, pages --- */
.primary{background:#0071e3!important;color:#fff!important;border-radius:12px!important;min-height:44px!important;padding:10px 18px!important;font-weight:600!important}
.primary:hover{background:#0077ed!important}
.secondary{background:#f2f2f7!important;color:#0071e3!important;border:1px solid #e5e5ea!important;border-radius:12px!important;min-height:44px!important}
.text-button{color:#0071e3!important}
.icon-button{width:44px!important;height:44px!important;border-radius:50%!important;color:#1d1d1f!important;background:transparent!important}
.icon-button:hover{background:#ececf0!important;color:#1d1d1f!important}
.icon-button svg{color:#1d1d1f!important}
input,textarea,select{
  background:#ffffff!important;color:#1d1d1f!important;caret-color:#1d1d1f!important;
  -webkit-text-fill-color:#1d1d1f!important;border:1px solid #e5e5ea!important;border-radius:12px!important;
}
input::placeholder,textarea::placeholder{color:#8e8e93!important;opacity:1!important}
input:focus,textarea:focus,select:focus{
  outline:2px solid #0071e3!important;outline-offset:1px!important;border-color:#0071e3!important;
  color:#1d1d1f!important;caret-color:#1d1d1f!important;-webkit-text-fill-color:#1d1d1f!important;
}
label{color:#1d1d1f!important}
.field-hint{color:#6e6e73!important}
dialog,[role="dialog"]{background:#fbfbf9!important;color:#1d1d1f!important;border:1px solid #e5e5ea!important;border-radius:20px!important;box-shadow:0 24px 60px rgba(0,0,0,.18)!important}
dialog h2{color:#1d1d1f!important}
dialog form>p{color:#6e6e73!important}
.page{background:#ededed!important;color:#1d1d1f!important}
.page-header h1{color:#1d1d1f!important}
.page-header p{color:#6e6e73!important}
.principal-card,.table-card,.info-banner,.welcome-example{
  background:#fbfbf9!important;color:#1d1d1f!important;border:1px solid #e5e5ea!important;
  border-radius:18px!important;box-shadow:0 1px 3px rgba(0,0,0,.06)!important;
}
.principal-card h2,.table-card h2,.info-banner h3{color:#1d1d1f!important}
.principal-card p,.table-card>p,.info-banner p{color:#6e6e73!important}
.principal-card code{color:#6e6e73!important}
th{color:#6e6e73!important}
td{color:#1d1d1f!important;border-bottom:1px solid #e5e5ea!important}
#toast{background:#1d1d1f!important;color:#fff!important;border:none!important;border-radius:12px!important}
.connection-banner{background:#fef3c7!important;border:1px solid #e5e5ea!important;color:#92400e!important}

/* --- 10. Avatars: 40px round --- */
.avatar{width:40px!important;height:40px!important;border-radius:50%!important}
.conversation-avatar .person-avatar{border:2px solid #e7e7ea!important}
.thread-item.selected .person-avatar{border-color:#e8f2fe!important}
.chat-header .person-avatar{border-color:#ededed!important}
.group-glyph{background:#e8f2fe!important;color:#0071e3!important}

/* --- 11. Welcome / login / empty state --- */
.welcome-story{background:#f5f5f7!important;border-right:1px solid #e5e5ea!important}
.welcome-story h1{color:#1d1d1f!important}
.welcome-story>p{color:#6e6e73!important}
.welcome-story>.eyebrow{color:#0071e3!important}
.welcome-form{background:#ededed!important}
.form-card h2{color:#1d1d1f!important}
.form-card>p{color:#6e6e73!important}
.form-card input{min-height:48px!important;background:#ffffff!important;color:#1d1d1f!important}
.login-brand{color:#1d1d1f!important}
.empty-state{background:#ededed!important;color:#1d1d1f!important}
.empty-state h2{color:#1d1d1f!important}
.empty-state>p{color:#6e6e73!important}
.empty-network img{background:#fbfbf9!important;border:1px solid #e5e5ea!important}
.conversation-start h2{color:#1d1d1f!important}
.conversation-start p{color:#6e6e73!important}

/* --- 12. Inspector, receiving pages, misc --- */
.thread-inspector{background:#e7e7ea!important;border-left:1px solid #d1d1d6!important;color:#1d1d1f!important}
.thread-inspector h2{color:#1d1d1f!important}
.thread-inspector header p{color:#6e6e73!important}
.member-row strong{color:#1d1d1f!important}
.member-row small{color:#6e6e73!important}
.activity-card strong{color:#1d1d1f!important}
.activity-time{color:#8e8e93!important}
.activity-summary{background:#f5f5f7!important;color:#6e6e73!important}
.receiving-page{background:#ededed!important;color:#1d1d1f!important}
.receiving-stat,.receiving-list,.receiving-detail{background:#fbfbf9!important;border:1px solid #e5e5ea!important;color:#1d1d1f!important}
.receiving-list th,.receiving-list td{color:#1d1d1f!important}
.receiving-list td small{color:#6e6e73!important}
.mailbox-caption{color:#6e6e73!important}
.mailbox-tab{color:#6e6e73!important}
.mailbox-tab[aria-pressed=true]{background:#e8f2fe!important;color:#0071e3!important}
.badge{color:#0071e3!important;border:1px solid #0071e3!important}
.schedule-notice{background:#fef3c7!important;border:1px solid #e5e5ea!important;color:#92400e!important}
.invite-permission{color:#1d1d1f!important;background:#f5f5f7!important;border:1px solid #e5e5ea!important}
.check-list{background:#f5f5f7!important;border:1px solid #e5e5ea!important}
.key-hint{background:#f5f5f7!important;color:#1d1d1f!important}
.invite-command{background:#f5f5f7!important;color:#1d1d1f!important}
.setup-help{background:#fbfbf9!important;border:1px solid #e5e5ea!important;color:#1d1d1f!important}
.setup-help p{color:#1d1d1f!important}
.pairing-requests{background:#fbfbf9!important;border:1px solid #e5e5ea!important;color:#1d1d1f!important}
.pairing-requests>p{color:#6e6e73!important}

/* --- 13. Mobile --- */
@media (max-width:800px){
  .chat-header{padding:10px 12px!important;min-height:68px!important}
  .message{padding:10px 14px!important;gap:11px!important}
  .message-body{max-width:85%!important}
  .composer{margin:6px 12px max(14px,env(safe-area-inset-bottom))!important}
  .composer textarea{font-size:16px!important}
  .thread-panel{width:100%!important;flex-basis:100%!important}
  .app-topbar .topbar-brand{display:flex!important}
}
@media (max-width:768px){
  .chat-header{padding:8px 12px!important}
  .composer{margin:8px 12px 16px!important}
}

/* ============================================================================
   v3.1 modal fix — "一键连接你的 Agent" dialog (avatar-picker)
   ----------------------------------------------------------------------------
   Root causes, verified against stock repo/public/style.css + app.js:
   - Stock: .avatar-option is a grid "28px minmax(0,1fr) 12px" and
     .avatar-option .avatar is 28px. v3 §10 set a GLOBAL
     .avatar{width:40px!important;height:40px!important}, which overrode the
     28px icon inside every option: a 40px circle in a 28px column bleeds
     12px into the label column and clips "默认图标 / Dots / Grok Bot /
     Muse". Fix: re-scope the avatar size inside options to 28px (higher
     specificity, later in the file, still !important) and keep 40px only
     for the preview circle.
   - Stock dialog is only 490px wide (min(490px, calc(100% - 32px))) and
     max-height calc(100dvh - 32px) with overflow:auto, so the connect
     dialog (name field + icon picker + note + submit) came out narrow,
     very tall and scrollable. Fix: widen to 600px, tighten picker
     spacing, keep the 2-column option grid with a real 32px icon column
     so icon and label can never overlap again.
   Everything above this section is v3, untouched.
   ========================================================================== */

/* --- 14. Connect-agent modal (avatar-picker) --- */
dialog{
  width:min(600px,calc(100vw - 48px))!important;
  max-width:calc(100vw - 48px)!important;
  max-height:calc(100dvh - 48px)!important;
  padding:24px 28px!important;
  box-sizing:border-box!important;
}
dialog h2{font-size:22px!important;line-height:1.3!important}
.modal-top{display:flex!important;justify-content:space-between!important;align-items:center!important;gap:12px!important;margin-bottom:8px!important}
.modal-top .icon-button{width:36px!important;height:36px!important;min-width:36px!important;min-height:36px!important;flex-shrink:0!important}
#modal-description{color:#6e6e73!important;font-size:13px!important;line-height:1.6!important}
#modal-fields{display:block!important}
#modal-fields>label{display:block!important;font-size:13px!important;font-weight:600!important;color:#1d1d1f!important;margin-bottom:14px!important}
#modal-fields>label>input,
dialog input[type="text"],dialog input:not([type]){
  display:block!important;width:100%!important;min-height:44px!important;
  box-sizing:border-box!important;margin-top:6px!important;
  background:#ffffff!important;color:#1d1d1f!important;
  caret-color:#1d1d1f!important;-webkit-text-fill-color:#1d1d1f!important;
  border:1px solid #e5e5ea!important;border-radius:12px!important;
  padding:10px 12px!important;font-size:15px!important;
}
.avatar-picker{display:grid!important;gap:10px!important;min-width:0!important;margin:0 0 4px!important;padding:0!important;border:0!important}
.avatar-picker legend{padding:0!important;margin-bottom:2px!important;font-size:13px!important;font-weight:700!important;color:#1d1d1f!important}
.avatar-preview{display:flex!important;align-items:center!important;gap:10px!important}
.avatar-preview .avatar{width:40px!important;height:40px!important;font-size:16px!important;flex-shrink:0!important}
.avatar-preview .fine{color:#6e6e73!important;font-size:13px!important}
.avatar-options{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:10px!important}
.avatar-option{
  display:grid!important;grid-template-columns:32px minmax(0,1fr) 16px!important;
  gap:10px!important;align-items:center!important;
  min-width:0!important;min-height:56px!important;
  padding:10px 12px!important;text-align:left!important;
  background:#f2f2f7!important;border:1px solid #e5e5ea!important;border-radius:12px!important;
  color:#1d1d1f!important;
}
.avatar-option:hover{background:#ececf0!important}
.avatar-option .avatar{
  width:28px!important;height:28px!important;min-width:28px!important;min-height:28px!important;
  font-size:14px!important;flex-shrink:0!important;
}
.avatar-option-label{
  min-width:0!important;font-size:13px!important;font-weight:600!important;color:#1d1d1f!important;
  white-space:nowrap!important;overflow:hidden!important;text-overflow:ellipsis!important;
}
.avatar-option .avatar-check{font-size:14px!important;font-weight:700!important;color:#0071e3!important;justify-self:end!important}
.avatar-option[aria-pressed="true"]{border:2px solid #0071e3!important;background:#e8f2fe!important}
.avatar-option[aria-pressed="true"] .avatar-check{visibility:visible!important}
.avatar-upload{justify-self:start!important;min-height:40px!important}
.avatar-picker .fine{color:#6e6e73!important;font-size:12px!important}
.schedule-notice{
  background:#fef3c7!important;border:1px solid #f5d67b!important;color:#92400e!important;
  border-radius:10px!important;padding:12px!important;font-size:12px!important;line-height:1.7!important;
  margin-top:14px!important;
}
#modal-submit{width:100%!important;margin-top:16px!important}
#modal-error{color:#d70015!important;font-size:13px!important}
@media (max-width:560px){
  dialog{width:calc(100vw - 32px)!important;padding:20px!important}
  .avatar-options{grid-template-columns:repeat(2,minmax(0,1fr))!important}
}

/* ============================================================================
   v3.2 avatar shape fix — avatars render as ellipses, not circles
   ----------------------------------------------------------------------------
   Root causes, verified against stock style.css + chat-workspace.css:
   - §10 set a GLOBAL .avatar{width:40px!important;height:40px!important}
     with no flex-shrink and no aspect-ratio.
   - chat-workspace.css gives message-row avatars flex:0 0 36px (31px under
     800px). For a flex item, flex-basis beats width for the main size, so
     rows rendered 36x40 (mobile 31x40): a tall ellipse next to every wide
     bubble — exactly the "squished" avatar in Hugo's screenshot.
   - The same global 40px also overrode the intended context sizes
     (27px conversation stacks, 32px member rows, 34px account footer).
   Fix: one locked square size per context — width, height AND flex-basis
   set to the same value, shrink disabled, aspect-ratio pinned as a guard.
   These rules live in the theme because §10's !important globals live here;
   only a later, >=-specificity !important section in this file beats them
   in every context (chat-workspace.css loads earlier and its avatar rules
   carry no !important). §14's 28px option icons and 40px preview are
   already square and stay untouched; .mention-avatar keeps the
   flex-shrink:0 + overflow:hidden it got in chat-workspace.css and only
   gains the aspect-ratio guard.
   ========================================================================== */

/* --- 15. Avatars: true circles, one locked square size per context --- */
.avatar,.person-avatar,.mention-avatar{flex-shrink:0!important;aspect-ratio:1/1!important}
.message>.avatar{width:38px!important;height:38px!important;flex:0 0 38px!important}
.member-row .avatar{width:32px!important;height:32px!important;flex:0 0 32px!important}
.account>.avatar{width:34px!important;height:34px!important;flex:0 0 34px!important}
.thread-item .conversation-avatar .person-avatar{width:27px!important;height:27px!important}
.chat-header .conversation-avatar .person-avatar{width:25px!important;height:25px!important}
@media (max-width:800px){
  .message>.avatar{width:32px!important;height:32px!important;flex:0 0 32px!important}
}

/* ============================================================================
   v3.3 dark mode — §16 (purely additive; the light theme above is untouched)
   ----------------------------------------------------------------------------
   Activation: the inline init script in index.html sets
   <html data-theme="dark"|"light" data-appearance="auto"|"light"|"dark">
   before first paint, from the saved choice (localStorage
   "agentpeerchat.appearance", default "auto") + prefers-color-scheme;
   app.js keeps it in sync and live-switches in "auto" when the OS setting
   changes. Every rule below is the dark mirror of a colour rule in §§1–15,
   prefixed with html[data-theme="dark"] so it outranks the light rule
   (same !important, strictly higher specificity) and applies ONLY in dark.
   Layout, sizes and spacing are inherited from the light sections.
   Palette (Apple dark): canvas #1c1c1e, surfaces #2c2c2e, raised #3a3a3c,
   dividers #38383a, strong borders #48484a, primary text #f5f5f7,
   secondary #a1a1a6 (≈5.4:1 on #2c2c2e — never dimmer, per Hugo's
   readability rule), timestamps/placeholders #98989f (small text only),
   accent backgrounds stay Apple blue #0071e3 with white text (4.6:1),
   accent TEXT uses #409cff (≈5.9:1 on #2c2c2e; #0071e3 text on dark
   would be ≈3.4:1), selected/highlight tint #163d61, error #ff453a,
   warning banner deep amber #453305 / #ffd479.
   ========================================================================== */

/* --- 16.1 Tokens (mirror of §1) --- */
:root[data-theme="dark"]{
  color-scheme:dark!important;
  --ink:#f5f5f7!important; --muted:#a1a1a6!important; --line:#38383a!important;
  --paper:#1c1c1e!important; --accent:#0071e3!important; --green:#34c759!important;
  --base:#1c1c1e!important; --sidebar:#2c2c2e!important; --raised:#2c2c2e!important;
  --hover:#3a3a3c!important; --selection:#163d61!important; --white:#2c2c2e!important;
}
html[data-theme="dark"] body:has(#shell:not([hidden])){
  --base:#1c1c1e!important; --sidebar:#2c2c2e!important; --paper:#1c1c1e!important;
  --raised:#2c2c2e!important; --hover:#3a3a3c!important; --selection:#163d61!important;
  --line:#38383a!important; --ink:#f5f5f7!important; --muted:#a1a1a6!important;
  --accent:#0071e3!important;
  background:#1c1c1e!important;
}

/* --- 16.2 Page surfaces (mirror of §2) --- */
html[data-theme="dark"],html[data-theme="dark"] body,html[data-theme="dark"] #root{background:#1c1c1e!important;color:#f5f5f7!important}
html[data-theme="dark"] body{background:#1c1c1e!important;color:#f5f5f7!important}
html[data-theme="dark"] a{color:#409cff!important}
html[data-theme="dark"] ::selection{background:#14406b!important;color:#f5f5f7!important}
html[data-theme="dark"] h1,html[data-theme="dark"] h2,html[data-theme="dark"] h3{color:#f5f5f7!important}
html[data-theme="dark"] p{color:#f5f5f7!important}
html[data-theme="dark"] .eyebrow{color:#a1a1a6!important}
html[data-theme="dark"] .fine{color:#a1a1a6!important}
html[data-theme="dark"] .error{color:#ff453a!important}

/* --- 16.3 Top bar (mirror of §3) --- */
html[data-theme="dark"] .app-topbar,html[data-theme="dark"] header.app-topbar{
  background:#2c2c2e!important;color:#f5f5f7!important;
  border-bottom:1px solid #48484a!important;
}
html[data-theme="dark"] .topbar-brand,html[data-theme="dark"] .topbar-brand span{color:#f5f5f7!important}
html[data-theme="dark"] .app-topbar button,html[data-theme="dark"] .app-topbar .icon-button{color:#f5f5f7!important;background:transparent!important}
html[data-theme="dark"] .app-topbar .icon-button:hover{background:#3a3a3c!important;color:#f5f5f7!important}
html[data-theme="dark"] .app-topbar select,html[data-theme="dark"] .language-picker select{
  background:#1c1c1e!important;border:1px solid #48484a!important;
  color:#f5f5f7!important;-webkit-text-fill-color:#f5f5f7!important;
}
html[data-theme="dark"] .topbar-actions .icon-button{color:#f5f5f7!important}
html[data-theme="dark"] .boot-state{background:#1c1c1e!important;color:#f5f5f7!important}

/* --- 16.4 Left icon rail + slide-out menu (mirror of §4) --- */
html[data-theme="dark"] .workspace-nav{background:#2c2c2e!important;border-right:1px solid #48484a!important}
html[data-theme="dark"] .space-button{background:#3a3a3c!important;color:#f5f5f7!important}
html[data-theme="dark"] .space-button:hover{background:#48484a!important;color:#f5f5f7!important}
html[data-theme="dark"] .space-button.active{background:#0071e3!important;color:#fff!important}
html[data-theme="dark"] .space-button.active:before{background:#0071e3!important}
html[data-theme="dark"] .rail{background:#2c2c2e!important;color:#f5f5f7!important;border:1px solid #48484a!important;box-shadow:0 16px 48px rgba(0,0,0,.5)!important}
html[data-theme="dark"] .rail .brand,html[data-theme="dark"] .rail .brand span{color:#f5f5f7!important}
html[data-theme="dark"] .instance{color:#a1a1a6!important}
html[data-theme="dark"] .instance small{color:#a1a1a6!important}
html[data-theme="dark"] .nav-item{color:#f5f5f7!important}
html[data-theme="dark"] .nav-item:hover{background:#3a3a3c!important;color:#f5f5f7!important}
html[data-theme="dark"] .nav-item.active{background:#163d61!important;color:#409cff!important}
html[data-theme="dark"] .nav-item .count,html[data-theme="dark"] .count{background:#0071e3!important;color:#fff!important}

/* --- 16.5 Conversation list (mirror of §5) --- */
html[data-theme="dark"] .thread-panel{background:#2c2c2e!important;color:#f5f5f7!important;border-right:1px solid #48484a!important}
html[data-theme="dark"] .workspace-heading strong{color:#f5f5f7!important}
html[data-theme="dark"] .workspace-label{color:#a1a1a6!important}
html[data-theme="dark"] .new-chat{color:#f5f5f7!important}
html[data-theme="dark"] .new-chat:hover{background:#3a3a3c!important;color:#f5f5f7!important}
html[data-theme="dark"] .search svg{color:#a1a1a6!important}
html[data-theme="dark"] .search input,html[data-theme="dark"] input[type="search"]{
  background:#1c1c1e!important;border:1px solid #48484a!important;
  color:#f5f5f7!important;caret-color:#f5f5f7!important;
  -webkit-text-fill-color:#f5f5f7!important;
}
html[data-theme="dark"] .search input::placeholder{color:#98989f!important}
html[data-theme="dark"] .list-heading{color:#a1a1a6!important}
html[data-theme="dark"] .list-heading>span:first-child{color:#a1a1a6!important}
html[data-theme="dark"] #sync-state{color:#98989f!important}
html[data-theme="dark"] .conversation-section{color:#a1a1a6!important}
html[data-theme="dark"] .thread-list{background:#2c2c2e!important}
html[data-theme="dark"] .thread-item{color:#f5f5f7!important;background:transparent!important}
html[data-theme="dark"] .thread-item:hover{background:#3a3a3c!important;color:#f5f5f7!important}
html[data-theme="dark"] .thread-item.selected{background:#163d61!important;color:#f5f5f7!important;box-shadow:inset 2px 0 #0071e3!important}
html[data-theme="dark"] .thread-copy strong{color:#f5f5f7!important}
html[data-theme="dark"] .thread-copy small{color:#a1a1a6!important}
html[data-theme="dark"] .conversation-kind{color:#a1a1a6!important}
html[data-theme="dark"] .thread-item time{color:#98989f!important}
html[data-theme="dark"] .thread-item.has-unread .thread-copy strong{color:#f5f5f7!important}
html[data-theme="dark"] .thread-item.has-unread .thread-copy small{color:#a1a1a6!important}
html[data-theme="dark"] .unread-count{background:#fa5151!important;color:#fff!important}
html[data-theme="dark"] .panel-footer{background:#2c2c2e!important;color:#f5f5f7!important;border-top:1px solid #48484a!important}
html[data-theme="dark"] .account strong{color:#f5f5f7!important}
html[data-theme="dark"] .account small{color:#a1a1a6!important}
html[data-theme="dark"] .account .icon-button{color:#f5f5f7!important}

/* --- 16.6 Chat header (mirror of §6) --- */
html[data-theme="dark"] .chat-panel{background:#1c1c1e!important}
html[data-theme="dark"] .chat-header{background:#1c1c1e!important;color:#f5f5f7!important;border-bottom:1px solid #38383a!important}
html[data-theme="dark"] .group-info{color:#f5f5f7!important}
html[data-theme="dark"] .group-info strong{color:#f5f5f7!important}
html[data-theme="dark"] #chat-members{color:#a1a1a6!important}
html[data-theme="dark"] #chat-receiving{color:#a1a1a6!important}
html[data-theme="dark"] #chat-receiving.receiver-warning{color:#ffd479!important}
html[data-theme="dark"] .chat-header .icon-button{color:#f5f5f7!important}
html[data-theme="dark"] .agent-presence{color:#a1a1a6!important}
html[data-theme="dark"] .presence-more{color:#a1a1a6!important}

/* --- 16.7 Message list and bubbles (mirror of §7) --- */
html[data-theme="dark"] .message-list,html[data-theme="dark"] [role="log"]{background:#1c1c1e!important;color:#f5f5f7!important}
html[data-theme="dark"] .date-separator span{color:#a1a1a6!important}
html[data-theme="dark"] .date-separator:before,html[data-theme="dark"] .date-separator:after{background:#48484a!important}
html[data-theme="dark"] .message:hover{background:#262628!important}
html[data-theme="dark"] .message:focus{background:#163d61!important}
html[data-theme="dark"] .message.message-own:hover{background:#262628!important}
html[data-theme="dark"] .message-body{
  background:#2c2c2e!important;border:1px solid #38383a!important;
  box-shadow:0 1px 2px rgba(0,0,0,.3)!important;
}
html[data-theme="dark"] .message-own .message-body{
  background:#0071e3!important;border-color:#0071e3!important;color:#ffffff!important;
}
html[data-theme="dark"] .bubble{color:#f5f5f7!important}
html[data-theme="dark"] .bubble,html[data-theme="dark"] .bubble *{color:#f5f5f7!important}
html[data-theme="dark"] .bubble a,html[data-theme="dark"] .bubble a *{color:#409cff!important}
html[data-theme="dark"] .bubble strong,html[data-theme="dark"] .bubble b{color:#f5f5f7!important}
html[data-theme="dark"] .message-meta strong{color:#409cff!important}
html[data-theme="dark"] .message-meta time{color:#98989f!important}
html[data-theme="dark"] .agent-label{background:#163d61!important;color:#409cff!important}
html[data-theme="dark"] .message-target{color:#a1a1a6!important}
html[data-theme="dark"] .message-quote{color:#a1a1a6!important}
html[data-theme="dark"] .message-quote strong{color:#f5f5f7!important}
html[data-theme="dark"] .message-quote>span:last-child{color:#a1a1a6!important}
html[data-theme="dark"] .quote-arrow{color:#409cff!important}
html[data-theme="dark"] .message-mention{color:#409cff!important;background:#163d61!important}
html[data-theme="dark"] .inline-code{background:#3a3a3c!important;border:1px solid #48484a!important;color:#f5f5f7!important}
html[data-theme="dark"] .message-code{background:#1c1c1e!important;border:1px solid #48484a!important;color:#f5f5f7!important}
html[data-theme="dark"] .message-code code{color:#f5f5f7!important}
html[data-theme="dark"] .message-table th{background:#3a3a3c!important;color:#f5f5f7!important}
html[data-theme="dark"] .message-table td,html[data-theme="dark"] .message-table th{border-bottom:1px solid #48484a!important;color:#f5f5f7!important}
html[data-theme="dark"] .message-table{border:1px solid #48484a!important}
html[data-theme="dark"] .message-image-meta{color:#a1a1a6!important}
html[data-theme="dark"] .message-image{background:#3a3a3c!important}
html[data-theme="dark"] .receipt-button{color:#98989f!important}
html[data-theme="dark"] .receipt-button:hover{color:#f5f5f7!important}
html[data-theme="dark"] .message-highlight,html[data-theme="dark"] .message-addressed{background:#163d61!important}
html[data-theme="dark"] .message.spotlight{background:#163d61!important}
html[data-theme="dark"] .structured-message,html[data-theme="dark"] .artifact-message{
  background:#2c2c2e!important;color:#f5f5f7!important;border:1px solid #48484a!important;
  border-left:3px solid #0071e3!important;box-shadow:0 1px 3px rgba(0,0,0,.3)!important;
}
html[data-theme="dark"] .structured-message *,html[data-theme="dark"] .artifact-message *{color:#f5f5f7!important}
html[data-theme="dark"] .json-fields dt{color:#a1a1a6!important}
html[data-theme="dark"] .json-fields dd{color:#f5f5f7!important}
html[data-theme="dark"] .artifact-message>a{color:#409cff!important}
html[data-theme="dark"] .artifact-icon{color:#409cff!important}
html[data-theme="dark"] .message-actions{background:#2c2c2e!important;border:1px solid #48484a!important;box-shadow:0 4px 12px rgba(0,0,0,.5)!important}
html[data-theme="dark"] .message-action{color:#f5f5f7!important}
html[data-theme="dark"] .message-action:hover{background:#3a3a3c!important}
/* Own-bubble re-assertions: the prefixed generic rules above would otherwise
   outrank the light theme's .message-own white-text rules. Own bubbles stay
   Apple blue with white text, exactly as in light mode. */
html[data-theme="dark"] .message-own .bubble,html[data-theme="dark"] .message-own .bubble *{color:#ffffff!important}
html[data-theme="dark"] .message-own .bubble a,html[data-theme="dark"] .message-own .bubble a *{color:#ffffff!important}
html[data-theme="dark"] .message-own .bubble strong,html[data-theme="dark"] .message-own .bubble b{color:#ffffff!important}
html[data-theme="dark"] .message-own .message-meta strong{color:#ffffff!important}
html[data-theme="dark"] .message-own .message-meta time{color:rgba(255,255,255,.85)!important}
html[data-theme="dark"] .message-own .agent-label{background:rgba(255,255,255,.25)!important;color:#ffffff!important}
html[data-theme="dark"] .message-own .message-target{color:rgba(255,255,255,.85)!important}
html[data-theme="dark"] .message-own .message-quote,html[data-theme="dark"] .message-own .message-quote>span:last-child{color:rgba(255,255,255,.85)!important}
html[data-theme="dark"] .message-own .message-quote strong{color:#ffffff!important}
html[data-theme="dark"] .message-own .quote-arrow{color:#ffffff!important}
html[data-theme="dark"] .message-own .message-mention{color:#ffffff!important;background:rgba(255,255,255,.25)!important}
html[data-theme="dark"] .message-own .inline-code{background:rgba(255,255,255,.2)!important;border-color:transparent!important;color:#ffffff!important}
html[data-theme="dark"] .message-own .message-image-meta{color:rgba(255,255,255,.85)!important}
html[data-theme="dark"] .message-own .receipt-button{color:rgba(255,255,255,.85)!important}

/* --- 16.8 Composer and mention picker (mirror of §8) --- */
html[data-theme="dark"] .composer{
  background:#2c2c2e!important;color:#f5f5f7!important;border:1px solid #48484a!important;
  box-shadow:0 4px 16px rgba(0,0,0,.4)!important;
}
html[data-theme="dark"] .composer:focus-within{border-color:#0071e3!important;box-shadow:0 0 0 2px rgba(0,113,227,.35)!important}
html[data-theme="dark"] .composer textarea{
  background:#1c1c1e!important;color:#f5f5f7!important;caret-color:#f5f5f7!important;
  -webkit-text-fill-color:#f5f5f7!important;border:1px solid #48484a!important;
}
html[data-theme="dark"] .composer textarea::placeholder{color:#98989f!important}
html[data-theme="dark"] .composer textarea:focus{border-color:#0071e3!important}
html[data-theme="dark"] .composer-mention{color:#f5f5f7!important;background:transparent!important}
html[data-theme="dark"] .composer-mention:hover{background:#3a3a3c!important;color:#f5f5f7!important}
html[data-theme="dark"] .composer-mention svg{color:#f5f5f7!important}
html[data-theme="dark"] .compose-feedback{color:#a1a1a6!important}
html[data-theme="dark"] .compose-counter{color:#a1a1a6!important}
html[data-theme="dark"] .compose-counter.over-limit{color:#ff453a!important}
html[data-theme="dark"] .send-button{background:#0071e3!important;color:#ffffff!important}
html[data-theme="dark"] .send-button:hover{background:#0077ed!important}
html[data-theme="dark"] .send-button:disabled{background:#48484a!important;color:#ffffff!important}
html[data-theme="dark"] .reply-bar{background:#163d61!important;border-bottom:1px solid #48484a!important}
html[data-theme="dark"] .reply-bar strong{color:#409cff!important}
html[data-theme="dark"] .reply-bar span:last-child{color:#a1a1a6!important}
html[data-theme="dark"] .reply-mark{color:#409cff!important}
html[data-theme="dark"] .mention-menu{background:#2c2c2e!important;border:1px solid #48484a!important;box-shadow:0 12px 35px rgba(0,0,0,.5)!important}
html[data-theme="dark"] .mention-heading{color:#a1a1a6!important}
html[data-theme="dark"] .mention-option{color:#f5f5f7!important}
html[data-theme="dark"] .mention-option strong{color:#f5f5f7!important}
html[data-theme="dark"] .mention-option small{color:#a1a1a6!important}
html[data-theme="dark"] .mention-option:hover,html[data-theme="dark"] .mention-option[aria-selected=true]{background:#163d61!important}
html[data-theme="dark"] .observe-actions{background:#2c2c2e!important;border:1px solid #48484a!important}
html[data-theme="dark"] .observe-actions span{color:#a1a1a6!important}

/* --- 16.9 Buttons, inputs, dialogs, cards, pages (mirror of §9) --- */
html[data-theme="dark"] .primary{background:#0071e3!important;color:#fff!important}
html[data-theme="dark"] .primary:hover{background:#0077ed!important}
html[data-theme="dark"] .secondary{background:#3a3a3c!important;color:#409cff!important;border:1px solid #48484a!important}
html[data-theme="dark"] .text-button{color:#409cff!important}
html[data-theme="dark"] .icon-button{color:#f5f5f7!important;background:transparent!important}
html[data-theme="dark"] .icon-button:hover{background:#3a3a3c!important;color:#f5f5f7!important}
html[data-theme="dark"] .icon-button svg{color:#f5f5f7!important}
html[data-theme="dark"] input,html[data-theme="dark"] textarea,html[data-theme="dark"] select{
  background:#1c1c1e!important;color:#f5f5f7!important;caret-color:#f5f5f7!important;
  -webkit-text-fill-color:#f5f5f7!important;border:1px solid #48484a!important;
}
html[data-theme="dark"] input::placeholder,html[data-theme="dark"] textarea::placeholder{color:#98989f!important}
html[data-theme="dark"] input:focus,html[data-theme="dark"] textarea:focus,html[data-theme="dark"] select:focus{
  outline:2px solid #0071e3!important;border-color:#0071e3!important;
  color:#f5f5f7!important;caret-color:#f5f5f7!important;-webkit-text-fill-color:#f5f5f7!important;
}
html[data-theme="dark"] label{color:#f5f5f7!important}
html[data-theme="dark"] .field-hint{color:#a1a1a6!important}
html[data-theme="dark"] dialog,html[data-theme="dark"] [role="dialog"]{background:#2c2c2e!important;color:#f5f5f7!important;border:1px solid #48484a!important;box-shadow:0 24px 60px rgba(0,0,0,.55)!important}
html[data-theme="dark"] dialog h2{color:#f5f5f7!important}
html[data-theme="dark"] dialog form>p{color:#a1a1a6!important}
html[data-theme="dark"] .page{background:#1c1c1e!important;color:#f5f5f7!important}
html[data-theme="dark"] .page-header h1{color:#f5f5f7!important}
html[data-theme="dark"] .page-header p{color:#a1a1a6!important}
html[data-theme="dark"] .principal-card,html[data-theme="dark"] .table-card,html[data-theme="dark"] .info-banner,html[data-theme="dark"] .welcome-example{
  background:#2c2c2e!important;color:#f5f5f7!important;border:1px solid #38383a!important;
  box-shadow:0 1px 3px rgba(0,0,0,.3)!important;
}
html[data-theme="dark"] .principal-card h2,html[data-theme="dark"] .table-card h2,html[data-theme="dark"] .info-banner h3{color:#f5f5f7!important}
html[data-theme="dark"] .principal-card p,html[data-theme="dark"] .table-card>p,html[data-theme="dark"] .info-banner p{color:#a1a1a6!important}
html[data-theme="dark"] .principal-card code{color:#a1a1a6!important}
html[data-theme="dark"] th{color:#a1a1a6!important}
html[data-theme="dark"] td{color:#f5f5f7!important;border-bottom:1px solid #38383a!important}
html[data-theme="dark"] #toast{background:#f5f5f7!important;color:#1c1c1e!important}
html[data-theme="dark"] .connection-banner{background:#453305!important;border:1px solid #6e5510!important;color:#ffd479!important}

/* --- 16.10 Avatar ring colours (mirror of §10; sizes stay in §10/§15) --- */
html[data-theme="dark"] .conversation-avatar .person-avatar{border:2px solid #2c2c2e!important}
html[data-theme="dark"] .thread-item.selected .person-avatar{border-color:#163d61!important}
html[data-theme="dark"] .chat-header .person-avatar{border-color:#1c1c1e!important}
html[data-theme="dark"] .group-glyph{background:#163d61!important;color:#409cff!important}

/* --- 16.11 Welcome / login / empty state (mirror of §11) --- */
html[data-theme="dark"] .welcome-story{background:#2c2c2e!important;border-right:1px solid #38383a!important}
html[data-theme="dark"] .welcome-story h1{color:#f5f5f7!important}
html[data-theme="dark"] .welcome-story>p{color:#a1a1a6!important}
html[data-theme="dark"] .welcome-story>.eyebrow{color:#409cff!important}
html[data-theme="dark"] .welcome-form{background:#1c1c1e!important}
html[data-theme="dark"] .form-card h2{color:#f5f5f7!important}
html[data-theme="dark"] .form-card>p{color:#a1a1a6!important}
html[data-theme="dark"] .form-card input{background:#1c1c1e!important;color:#f5f5f7!important}
html[data-theme="dark"] .login-brand{color:#f5f5f7!important}
html[data-theme="dark"] .empty-state{background:#1c1c1e!important;color:#f5f5f7!important}
html[data-theme="dark"] .empty-state h2{color:#f5f5f7!important}
html[data-theme="dark"] .empty-state>p{color:#a1a1a6!important}
html[data-theme="dark"] .empty-network img{background:#2c2c2e!important;border:1px solid #48484a!important}
html[data-theme="dark"] .conversation-start h2{color:#f5f5f7!important}
html[data-theme="dark"] .conversation-start p{color:#a1a1a6!important}

/* --- 16.12 Inspector, receiving pages, misc (mirror of §12) --- */
html[data-theme="dark"] .thread-inspector{background:#2c2c2e!important;border-left:1px solid #48484a!important;color:#f5f5f7!important}
html[data-theme="dark"] .thread-inspector h2{color:#f5f5f7!important}
html[data-theme="dark"] .thread-inspector header p{color:#a1a1a6!important}
html[data-theme="dark"] .member-row strong{color:#f5f5f7!important}
html[data-theme="dark"] .member-row small{color:#a1a1a6!important}
html[data-theme="dark"] .activity-card strong{color:#f5f5f7!important}
html[data-theme="dark"] .activity-time{color:#98989f!important}
html[data-theme="dark"] .activity-summary{background:#2c2c2e!important;color:#a1a1a6!important}
html[data-theme="dark"] .receiving-page{background:#1c1c1e!important;color:#f5f5f7!important}
html[data-theme="dark"] .receiving-stat,html[data-theme="dark"] .receiving-list,html[data-theme="dark"] .receiving-detail{background:#2c2c2e!important;border:1px solid #38383a!important;color:#f5f5f7!important}
html[data-theme="dark"] .receiving-list th,html[data-theme="dark"] .receiving-list td{color:#f5f5f7!important}
html[data-theme="dark"] .receiving-list td small{color:#a1a1a6!important}
html[data-theme="dark"] .mailbox-caption{color:#a1a1a6!important}
html[data-theme="dark"] .mailbox-tab{color:#a1a1a6!important}
html[data-theme="dark"] .mailbox-tab[aria-pressed=true]{background:#163d61!important;color:#409cff!important}
html[data-theme="dark"] .badge{color:#409cff!important;border:1px solid #409cff!important}
html[data-theme="dark"] .schedule-notice{background:#453305!important;border:1px solid #6e5510!important;color:#ffd479!important}
html[data-theme="dark"] .invite-permission{color:#f5f5f7!important;background:#3a3a3c!important;border:1px solid #48484a!important}
html[data-theme="dark"] .check-list{background:#3a3a3c!important;border:1px solid #48484a!important}
html[data-theme="dark"] .key-hint{background:#3a3a3c!important;color:#f5f5f7!important}
html[data-theme="dark"] .invite-command{background:#3a3a3c!important;color:#f5f5f7!important}
html[data-theme="dark"] .setup-help{background:#2c2c2e!important;border:1px solid #38383a!important;color:#f5f5f7!important}
html[data-theme="dark"] .setup-help p{color:#f5f5f7!important}
html[data-theme="dark"] .pairing-requests{background:#2c2c2e!important;border:1px solid #38383a!important;color:#f5f5f7!important}
html[data-theme="dark"] .pairing-requests>p{color:#a1a1a6!important}

/* --- 16.13 Connect-agent modal colours (mirror of §14) --- */
html[data-theme="dark"] #modal-description{color:#a1a1a6!important}
html[data-theme="dark"] #modal-fields>label{color:#f5f5f7!important}
html[data-theme="dark"] #modal-fields>label>input,
html[data-theme="dark"] dialog input[type="text"],html[data-theme="dark"] dialog input:not([type]){
  background:#1c1c1e!important;color:#f5f5f7!important;
  caret-color:#f5f5f7!important;-webkit-text-fill-color:#f5f5f7!important;
  border:1px solid #48484a!important;
}
html[data-theme="dark"] .avatar-picker legend{color:#f5f5f7!important}
html[data-theme="dark"] .avatar-preview .fine{color:#a1a1a6!important}
html[data-theme="dark"] .avatar-option{
  background:#3a3a3c!important;border:1px solid #48484a!important;color:#f5f5f7!important;
}
html[data-theme="dark"] .avatar-option:hover{background:#48484a!important}
html[data-theme="dark"] .avatar-option-label{color:#f5f5f7!important}
html[data-theme="dark"] .avatar-option .avatar-check{color:#409cff!important}
html[data-theme="dark"] .avatar-option[aria-pressed="true"]{border:2px solid #0071e3!important;background:#163d61!important}
html[data-theme="dark"] .avatar-picker .fine{color:#a1a1a6!important}
html[data-theme="dark"] #modal-error{color:#ff453a!important}

/* ============================================================================
   §17 — UI fixes A: rail geometry, composer clearance, textarea scrollbar
   ----------------------------------------------------------------------------
   Three layout defects observed on desktop (1596px, light + dark). §4 only
   ever repainted the rail's colours, and §8 turned the composer into a tall
   floating-style card, but neither section touched the underlying geometry
   the upstream sheets (style.css / chat-workspace.css) disagree on:

   17.1 Rail: style.css designs the rail 72px wide with 48px buttons, but
        chat-workspace.css later narrows it to 68px with 44px buttons and
        10px side padding — a 48px content box with only 2px of slack around
        each button — and parks the active indicator at left:-12px, which
        lands it at x=0, flush with (and clipped by) the screen edge.
        Fix: one authoritative geometry here — 80px rail, buttons centred
        with real air around them, indicator pulled back inside the rail.
   17.2 Composer: the scroll container's bottom clearance is only 26px
        (scroll-padding 20px) while the §8 composer card is ~120px tall
        (~148px with its margins) and grows taller as chat-composer.js
        auto-grows the textarea (max 160px) or the reply bar opens; the app
        pins scroll at render time, so the final message can end up tucked
        behind the composer card. Fix: reserve the composer's full resting
        footprint (150px) at the end of the scroll container, and lift the
        "new messages" pill clear of the composer zone as well.
   17.3 Textarea: .message-list got scrollbar-width:thin upstream but the
        composer textarea never did, so Windows Chrome shows the native
        scrollbar with ▲▼ buttons. Fix: thin, subtle, theme-aware styling.
   ========================================================================== */

/* --- 17.1 Left icon rail: one authoritative, un-crowded geometry --- */
.workspace-nav{
  width:80px!important;flex:0 0 80px!important;
  padding:20px 0!important;gap:14px!important;overflow:visible!important;
}
.space-button{flex:0 0 auto!important}
.space-button.active:before{left:-15px!important;height:24px!important}
.nav-tooltip{left:56px!important}

/* --- 17.2 Message list: reserve the composer's footprint at the bottom --- */
.message-list{padding-bottom:150px!important;scroll-padding-bottom:150px!important}
#jump-latest{bottom:166px!important}

/* --- 17.3 Composer textarea: thin subtle scrollbar, no arrow buttons --- */
.composer textarea{scrollbar-width:thin;scrollbar-color:#c7c7cc transparent}
.composer textarea::-webkit-scrollbar{width:6px;height:6px}
.composer textarea::-webkit-scrollbar-track{background:transparent}
.composer textarea::-webkit-scrollbar-thumb{background:#c7c7cc;border-radius:3px}
.composer textarea::-webkit-scrollbar-button{display:none;width:0;height:0}
html[data-theme="dark"] .composer textarea{scrollbar-color:#48484a transparent}
html[data-theme="dark"] .composer textarea::-webkit-scrollbar-thumb{background:#48484a}

/* ==========================================================================
   §18 — UI fixes B: message area
   18.1 Fenced code blocks get a copy button (chat-content.js .code-copy);
        the block needs a positioning context and the button a quiet,
        theme-aware style.
   18.2 Quote previews of image messages show a small thumbnail
        (.quote-thumb) instead of a bare "🖼 Image" label.
   18.3 The hover action pill (Reply / Copy / Message details) was anchored
        to the full-width message row (right:22px), so for other people's
        left-aligned bubbles it floated far from the bubble it belongs to;
        and the :focus-within reveal kept it on screen after the mouse had
        left (a clicked button keeps focus). Fix: on wide screens anchor
        the pill over the bubble (left edge for others, right edge for own
        messages), and on hover-capable pointers show it only while the
        row is actually hovered. Touch behaviour is unchanged.
   ========================================================================== */

/* --- 18.1 Code block copy button --- */
.message-code{position:relative}
.code-copy{position:absolute;top:6px;right:6px;padding:2px 8px;font-size:11px;line-height:1.6;border-radius:6px;border:1px solid #e5e5ea;background:#ffffff;color:#0071e3;cursor:pointer}
.code-copy:hover{background:#ececf0}
html[data-theme="dark"] .code-copy{background:#3a3a3c;border-color:#48484a;color:#409cff}
html[data-theme="dark"] .code-copy:hover{background:#48484a}

/* --- 18.2 Quote thumbnail for image messages --- */
.quote-thumb{width:28px;height:28px;flex:0 0 auto;object-fit:cover;border-radius:6px}

/* --- 18.3 Hover action pill: bubble-anchored, no linger --- */
@media(min-width:801px){
  .message-actions{left:72px;right:auto}
  .message-own .message-actions{left:auto;right:22px}
}
@media(hover:hover){
  .message:not(:hover) .message-actions{opacity:0;pointer-events:none}
}
/* =============================================================================
   §19 — UI fixes C: thread list & top bar
   19.1 Every thread row carried its own kind label (.conversation-kind,
        "Direct chat" / "Group chat") on top of the section header that
        already groups the list (Groups / Direct messages), so the kind
        was stated twice on every row. The section header stays as the
        single label; the per-row label is hidden (it remains in the
        avatar's aria-label for assistive tech).
   19.2 A direct thread between two other people (an observed agent DM)
        renders two 27px avatars parked diagonally — top-left and
        bottom-right — inside the 42px box; at that size the second
        avatar, with its own presence dot sticking out of its corner,
        reads as a badge on the first avatar instead of a second
        person. Fix: when a .direct-pair holds exactly two avatars, lay
        them out as two equal, vertically centred circles with a slight
        overlap and the existing surface ring (§10/§15) — an intentional,
        aligned pair. Single-avatar direct threads are untouched (the
        :has guard does not match them).
   19.3 The chat-header presence strip (#chat-receiving) was
        overflow:hidden on desktop (chat-workspace.css), so once the
        strip outgrew the header width the last badges were silently
        clipped mid-strip. It now scrolls horizontally with no visible
        scrollbar, as the mobile layout already did. (The repeated
        status text after each name and the 3-agent cap are fixed in
        app.js renderChatPresence: badges are dot + name only, the full
        status stays in the badge's tooltip, and every agent is shown.)
   19.4 The sync status (#sync-state: "Syncing…" / "Sync paused ·
        retrying") sits in a space-between flex row whose other item
        (the heading span) has an explicit ellipsis/overflow treatment,
        while the status span kept the default flex-shrink:1 with no
        width guarantee — under panel squeeze it was the element that
        gave way and clipped. It now keeps its max-content width
        (flex:0 0 auto) and the heading absorbs any squeeze instead.
        When idle or synced the span is empty, so nothing shows.
   ========================================================================== */

/* --- 19.1 Thread rows: one kind label (the section header) is enough --- */
#thread-list .conversation-kind{display:none}

/* --- 19.2 Two-person direct avatar: an aligned pair, not a badge --- */
.conversation-avatar.direct-pair:has(>.person-avatar+.person-avatar){
  display:flex!important;align-items:center;justify-content:center;
}
.conversation-avatar.direct-pair:has(>.person-avatar+.person-avatar)>.person-avatar{
  position:relative!important;left:auto!important;right:auto!important;top:auto!important;bottom:auto!important;
  width:25px!important;height:25px!important;flex:0 0 25px;
}
.conversation-avatar.direct-pair:has(>.person-avatar+.person-avatar)>.person-avatar+.person-avatar{
  margin-left:-8px;z-index:1;
}
.chat-header .conversation-avatar.direct-pair:has(>.person-avatar+.person-avatar)>.person-avatar{
  width:24px!important;height:24px!important;flex-basis:24px;
}

/* --- 19.3 Presence strip: scroll instead of silently clipping --- */
#chat-receiving{overflow-x:auto;scrollbar-width:none}
#chat-receiving::-webkit-scrollbar{display:none}

/* --- 19.4 Sync status: never the element that gets squeezed --- */
.list-heading>span:first-child{min-width:0}
#sync-state{flex:0 0 auto}

/* =============================================================================
   §20 — UI fixes D: Settings page
   20.1 Settings had no account card: the signed-in user could not see
        their own name or role anywhere on the page. The card markup is
        in index.html (#account-card) and app.js fills #account-summary
        from state.me; this is only its layout. (The bound email is not
        shown: no endpoint returns it to the client — see the deploy
        note.)
   20.2 Every Settings card used the full 24px card padding and a 20px
        paragraph tail margin, so sparse cards — above all the collapsed
        "Advanced settings" <details>, a single title line — read as big
        empty boxes. Cards on this page only are tightened, and the
        collapsed details hugs its summary line.
   20.3 Token and invite rows gain small meta lines in app.js (created
        date, principal kind, who accepted); this styles those lines,
        keeps revoked token rows visually quiet, and makes the invite
        status a distinct weighted element instead of a bare text node.
   20.4 Revoke buttons in Settings (token list + invite list) are
        destructive; app.js gives them a .danger class so they no longer
        look like ordinary secondary buttons — the owner recovery key's
        revoke button included.
   ========================================================================== */

/* --- 20.1 Account card --- */
.account-identity{display:flex;align-items:center;gap:12px}
#account-summary .account-meta{margin:10px 0 0}

/* --- 20.2 Settings cards: tighter, and a collapsed details hugs its title --- */
#access .table-card{padding:18px 20px;margin-bottom:16px}
#access .table-card>p{margin-bottom:12px}
#access .table-card>summary{padding:2px 0}
#access details.table-card:not([open]){padding-top:12px;padding-bottom:12px}

/* --- 20.3 Row meta lines, quiet revoked rows, visible invite status --- */
#token-list td small.cell-meta{display:block;margin-top:4px;font-size:11px;color:#6e6e73}
html[data-theme="dark"] #token-list td small.cell-meta{color:#a1a1a6}
#token-list tr.revoked{opacity:.55}
.invite-row .invite-status{font-weight:650}

/* --- 20.4 Destructive actions in Settings --- */
#access button.danger{color:#d70015!important;border-color:#d70015!important;background:transparent!important}
#access button.danger:hover{background:rgba(215,0,21,.07)!important}
html[data-theme="dark"] #access button.danger{color:#ff453a!important;border-color:#ff453a!important}
html[data-theme="dark"] #access button.danger:hover{background:rgba(255,69,58,.12)!important}

/* =============================================================================
   §21 — UI fixes E: connect page + leftovers
   21.1 Principal cards reserved a 40px-min-height description paragraph
        and full card padding, so mostly-empty cards read as big blank
        boxes. The description keeps its natural height, and the card's
        padding and heading/footer spacing tighten. (The missing presence
        line on human cards is data, not layout: presence records exist
        only for agents — see the deploy note.)
   21.2 The shared dialog gains a Cancel button in index.html, wired in
        app.js to the same closeModal path as the x. It sits under the
        full-width submit button, matching the dialog's stacked layout.
   21.3 The message list opted out of scroll anchoring upstream
        (overflow-anchor:none in chat-workspace.css). With anchoring off,
        the browser makes no compensation when message DOM is re-rendered
        or media loads, so in a long active group the viewport drifts —
        the reported imprecise scrolling. Anchoring is restored here.
        (The wheel step itself is the browser/OS setting and tall message
        blocks are content; neither is fixable client-side.)
   ========================================================================== */

/* --- 21.1 Principal cards: no reserved blank space --- */
.principal-card{padding:18px}
.principal-card h2{margin:10px 0 6px}
.principal-card p{min-height:0}
.principal-card footer{margin-top:14px}

/* --- 21.2 Dialog Cancel button --- */
#modal-cancel{width:100%;margin-top:10px}

/* --- 21.3 Message list: restore scroll anchoring --- */
.message-list{overflow-anchor:auto}

/* ==========================================================================
   §22 — UI fixes F: group administration (inspector)
   22.1 Member rows gain a quiet right-aligned action (Remove / Leave
        group) rendered by app.js; it must not squeeze the name column.
   22.2 Destructive text buttons reuse the Settings revoke red (§20),
        scoped to the inspector so ordinary text buttons stay blue.
   22.3 The Manage conversation section (rename / delete) sits under the
        activity section with the same padding and a hairline divider.
   ========================================================================== */

/* --- 22.1 Member-row actions --- */
.member-row .member-action{margin-left:auto;flex:0 0 auto;font-size:12px;padding:4px 0 4px 10px}

/* --- 22.2 Destructive text buttons in the inspector --- */
.thread-inspector .text-button.danger{color:#d70015!important}
.thread-inspector .text-button.danger:hover{background:rgba(215,0,21,.07)}
html[data-theme="dark"] .thread-inspector .text-button.danger{color:#ff453a!important}
html[data-theme="dark"] .thread-inspector .text-button.danger:hover{background:rgba(255,69,58,.12)}

/* --- 22.3 Inspector admin section --- */
.inspector-admin{padding:20px 16px;border-top:1px solid #d1d1d6!important}
html[data-theme="dark"] .inspector-admin{border-top-color:#48484a!important}
.inspector-actions{display:flex;flex-direction:column;align-items:flex-start}
.inspector-actions .text-button{padding:6px 0;font-size:13px}
