/* Chat view. Shares the main page's tokens (--surface, --ink, --accent ...), so light and dark themes
   come from app-model.html. Every class is prefixed ch- because .msg, .thread, .compose, .sys and
   .files already mean something else on the page. */

.vh{position:absolute!important;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;margin:-1px;padding:0;border:0}

/* ---- view switching ---- */
main.chatmode{grid-template-columns:minmax(0,1fr)}
main.chatmode .list, main.chatmode .detail, main.chatmode #dash, main.chatmode #adm{display:none!important}
#chat{display:grid;grid-template-columns:320px minmax(0,1fr);min-width:0;min-height:360px;overflow:hidden;
  height:calc(100vh - var(--ch-top,100px) - var(--ch-bot,0px));height:calc(var(--ch-vh,100dvh) - var(--ch-top,100px) - var(--ch-bot,0px))}
#chat[hidden]{display:none}
#chat [hidden], .ch-pop [hidden], .ch-toasts [hidden], .ch-dlg [hidden], .ch-lb [hidden]{display:none!important}
.navbtn[hidden]{display:none}
.navbtn .count.ch-unread{background:var(--accent);color:var(--on-accent);font-weight:600}

/* ---- chat list pane ---- */
.ch-side{display:flex;flex-direction:column;min-width:0;min-height:0;border-right:1px solid var(--line);background:var(--surface)}
.ch-sidehead{padding:16px 16px 10px;display:flex;flex-direction:column;gap:10px;border-bottom:1px solid var(--line)}
.ch-sidehead .row{display:flex;align-items:center;gap:8px}
.ch-sidehead h2{font-family:var(--f-display);font-weight:600;font-size:24px;margin:0 auto 0 0;letter-spacing:.01em}
.ch-new{display:inline-flex;align-items:center;gap:6px;padding:7px 12px}
.ch-new svg{width:16px;height:16px}
.ch-filt{display:flex;gap:8px;align-items:center}
.ch-filt .search{flex:1;min-width:0}
.ch-filt .seg{flex:none}
.ch-filt .seg button{padding:5px 10px}
.ch-lists{flex:1;min-height:0;overflow-y:auto;overflow-x:hidden;padding:4px 8px 24px;overscroll-behavior:contain}
.ch-grp{font-size:11px;letter-spacing:.09em;text-transform:uppercase;color:var(--muted);font-weight:600;margin:12px 10px 4px}
.ch-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:1px}
.ch-row{display:grid;grid-template-columns:40px minmax(0,1fr) auto;gap:1px 10px;align-items:center;width:100%;padding:8px 10px;border:0;background:none;border-radius:10px;text-align:left;cursor:pointer;color:var(--fg)}
.ch-row:hover{background:var(--surface-2)}
.ch-row[aria-current="true"]{background:var(--surface-2);box-shadow:inset 3px 0 0 var(--accent)}
.ch-row > .ch-ava{grid-row:1/span 2}
.ch-rt{font-weight:500;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-rtime{font-size:11.5px;color:var(--muted);white-space:nowrap;justify-self:end}
.ch-rp{grid-column:2;font-size:12.5px;color:var(--muted);min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-rmeta{grid-column:3;display:flex;gap:4px;align-items:center;justify-content:flex-end;min-height:20px}
.ch-rmeta svg{width:14px;height:14px;color:var(--muted)}
.ch-row.unread .ch-rt{font-weight:700}
.ch-row.unread .ch-rp{color:var(--fg)}
.ch-row.unread .ch-rtime{color:var(--fg);font-weight:600}
.ch-badge{min-width:20px;height:20px;padding:0 6px;border-radius:10px;background:var(--accent);color:var(--on-accent);font:600 11.5px/20px var(--f-mono);text-align:center}
.ch-badge.quiet{background:var(--surface-2);color:var(--muted);border:1px solid var(--line);line-height:18px}
.ch-at{width:20px;height:20px;border-radius:10px;background:var(--info);color:var(--surface);font:700 12px/20px var(--f-body);text-align:center}

/* avatars with presence */
.ch-ava{position:relative;width:40px;height:40px;flex:none;display:block}
.ch-ava > .av{width:100%;height:100%;font-size:13.5px}
.ch-ava.s36{width:36px;height:36px}.ch-ava.s36 > .av{font-size:12.5px}
.ch-ava.s32{width:32px;height:32px}.ch-ava.s32 > .av{font-size:11.5px}
.ch-ava.grp > .av{position:absolute;width:64%;height:64%;font-size:10px;box-shadow:0 0 0 2px var(--surface)}
.ch-ava.grp > .av:first-child{left:0;top:0}
.ch-ava.grp > .av + .av{right:0;bottom:0}
.ch-ava.grp1{display:grid;place-items:center;border-radius:50%;background:var(--surface-2);color:var(--muted);border:1px solid var(--line)}
.ch-ava.grp1 svg{width:55%;height:55%}
.ch-pres{position:absolute;right:-1px;bottom:-1px;width:12px;height:12px;border-radius:50%;border:2px solid var(--surface);background:var(--surface);box-shadow:inset 0 0 0 1.5px var(--muted)}
.ch-pres[data-s="online"]{background:var(--ok);box-shadow:none}
.ch-pres[data-s="away"]{background:var(--accent);box-shadow:none}
.ch-row[aria-current="true"] .ch-pres,.ch-row:hover .ch-pres{border-color:var(--surface-2)}
.ch-presword{display:inline-flex;align-items:center;gap:6px}
.ch-presword i{width:8px;height:8px;border-radius:50%;background:transparent;box-shadow:inset 0 0 0 1.5px var(--muted)}
.ch-presword[data-s="online"] i{background:var(--ok);box-shadow:none}
.ch-presword[data-s="away"] i{background:var(--accent);box-shadow:none}

/* ---- conversation pane ---- */
.ch-conv{display:flex;flex-direction:column;min-width:0;min-height:0;position:relative;background:var(--bg)}
.ch-head{display:flex;align-items:center;gap:12px;padding:10px 16px;background:var(--surface);border-bottom:1px solid var(--line);min-height:64px;flex:none}
.ch-back{display:none!important}
.ch-title{min-width:0;flex:1;display:flex;flex-direction:column}
.ch-title h2{margin:0;font:600 20px/1.2 var(--f-display);letter-spacing:.01em;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-title h2:focus{outline:none}
.ch-title h2 button{border:0;background:none;padding:0;margin:0;font:inherit;color:inherit;cursor:pointer;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:left;border-radius:4px}
.ch-title h2 button:hover{text-decoration:underline;text-underline-offset:3px}
.ch-sub{font-size:12.5px;color:var(--muted);display:flex;gap:8px;align-items:center;min-width:0;white-space:nowrap;overflow:hidden}
.ch-hact{display:flex;gap:4px;flex:none}
.ch-ib{width:36px;height:36px;border-radius:8px;border:1px solid transparent;background:none;display:grid;place-items:center;color:var(--muted);cursor:pointer;flex:none;padding:0}
.ch-ib:hover{background:var(--surface-2);color:var(--fg)}
.ch-ib[aria-expanded="true"]{background:var(--surface-2);color:var(--fg);border-color:var(--line)}
.ch-ib[aria-pressed="true"]{background:var(--accent-soft);color:var(--accent-fg)}
.ch-ib svg{width:18px;height:18px}

.ch-streamwrap{flex:1;min-height:0;position:relative;display:flex;flex-direction:column}
.ch-stream{flex:1;min-height:0;overflow-y:auto;overflow-x:hidden;padding:12px 24px 10px;overscroll-behavior:contain}
.ch-stream:focus-visible{outline:2px solid var(--accent);outline-offset:-3px}
.ch-inner{max-width:940px;margin:0 auto;display:flex;flex-direction:column;padding-top:8px}

.ch-intro{display:flex;flex-direction:column;align-items:center;text-align:center;gap:6px;padding:20px 12px 8px;color:var(--muted)}
.ch-intro .ch-ava{width:64px;height:64px}
.ch-intro .ch-ava > .av{font-size:21px}
.ch-intro strong{font:600 20px/1.2 var(--f-display);color:var(--fg)}
.ch-intro p{margin:0;font-size:13px;max-width:420px}
.ch-more{align-self:center;margin:8px 0;font-size:12.5px;color:var(--muted)}

.ch-day{display:flex;align-items:center;gap:12px;margin:22px 0 4px;font:600 11.5px/1 var(--f-body);letter-spacing:.07em;text-transform:uppercase;color:var(--muted)}
.ch-day::before,.ch-day::after{content:"";flex:1;height:1px;background:var(--line)}
.ch-newdiv{display:flex;align-items:center;gap:10px;margin:18px 0 0;color:var(--accent-fg);font-size:12px;font-weight:600}
.ch-newdiv::before,.ch-newdiv::after{content:"";flex:1;height:2px;border-radius:1px;background:var(--accent)}
.ch-newdiv span{background:var(--accent-soft);padding:2px 10px;border-radius:999px}

.ch-sys{align-self:center;text-align:center;font-size:12.5px;color:var(--muted);margin:14px auto 2px;max-width:min(560px,92%);display:flex;flex-wrap:wrap;justify-content:center;gap:2px 8px;align-items:baseline;line-height:1.4}
.ch-sys time{font-size:11.5px}
.ch-sys b{font-weight:600;color:var(--fg)}

.ch-msg{position:relative;display:grid;grid-template-columns:32px minmax(0,1fr);column-gap:10px;padding:3px 8px;margin-top:12px;border-radius:12px}
.ch-msg.ch-cont{margin-top:2px}
.ch-msg.ch-mine{grid-template-columns:minmax(0,1fr)}
.ch-msg:focus{outline:none}
.ch-msg:focus-visible{outline:2px solid var(--accent);outline-offset:0}
.ch-mav{grid-column:1;align-self:start;margin-top:20px}
.ch-cont .ch-mav{visibility:hidden;margin-top:0;height:0}
.ch-col{grid-column:2;min-width:0;display:flex;flex-direction:column;align-items:flex-start}
.ch-mine .ch-col{grid-column:1;align-items:flex-end}
.ch-mh{display:flex;gap:8px;align-items:baseline;font-size:12px;color:var(--muted);margin:0 2px 3px;min-width:0;max-width:100%}
.ch-mh b{font-weight:600;font-size:13px;color:var(--fg);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-mh .ch-ed{font-style:italic}
.ch-bubble{background:var(--surface);border:1px solid var(--line);border-radius:4px 14px 14px 14px;padding:7px 12px 8px;max-width:min(680px,100%);min-width:0;overflow-wrap:anywhere;position:relative;box-shadow:0 1px 1px rgba(23,35,43,.04)}
.ch-cont .ch-bubble{border-radius:14px}
.ch-mine .ch-bubble{background:var(--info-soft);border-color:var(--info-soft);border-radius:14px 4px 14px 14px}
.ch-mine.ch-cont .ch-bubble{border-radius:14px}
.ch-bubble.bare{background:none;border:0;padding:0;box-shadow:none}
.ch-bubble.ch-delb{background:transparent;border:1px dashed var(--line)}
.ch-text{line-height:1.5;font-size:14px;margin:0}
.ch-text p{margin:0}
.ch-text.big{font-size:40px;line-height:1.15;padding:2px 0}
.ch-text a{color:var(--info);text-decoration:underline;text-underline-offset:2px;overflow-wrap:anywhere}
.ch-text code{font:12.5px/1.4 var(--f-mono);background:var(--surface-2);border:1px solid var(--line);border-radius:5px;padding:0 4px}
.ch-mine .ch-text code{background:var(--surface)}
.ch-code{margin:4px 0;padding:8px 10px;background:var(--surface-2);border:1px solid var(--line);border-radius:8px;overflow-x:auto;font:12.5px/1.5 var(--f-mono);white-space:pre;max-width:100%}
.ch-mine .ch-code{background:var(--surface)}
.ch-del{font-style:italic;color:var(--muted)}
.ch-mention{font-weight:600;color:var(--info)}
.ch-mention.me{background:var(--accent-soft);color:var(--accent-fg);border-radius:4px;padding:0 3px}
.ch-ed-inline{font-size:11.5px;color:var(--muted);margin-left:6px;font-style:italic}

.ch-quote{display:block;width:100%;text-align:left;border:0;border-left:3px solid var(--accent);background:var(--surface-2);border-radius:6px;padding:5px 10px;margin:2px 0 6px;cursor:pointer;font-size:12.5px;color:var(--fg);min-width:0}
.ch-mine .ch-quote{background:var(--surface)}
.ch-quote:hover{border-left-color:var(--accent-fg)}
.ch-quote b{display:block;font-weight:600;font-size:12px}
.ch-quote span{display:block;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-quote.off{cursor:default}

/* hover / focus action bar */
.ch-actions{position:absolute;top:-14px;right:10px;display:flex;gap:2px;padding:3px;background:var(--surface);border:1px solid var(--line);border-radius:10px;box-shadow:0 4px 14px rgba(10,24,30,.14);opacity:0;pointer-events:none;z-index:2}
.ch-msg:hover .ch-actions,.ch-msg:focus-within .ch-actions,.ch-actions.open{opacity:1;pointer-events:auto}
.ch-actions button{width:30px;height:30px;border:0;background:none;border-radius:7px;display:grid;place-items:center;color:var(--muted);cursor:pointer;padding:0}
.ch-actions button:hover,.ch-actions button[aria-expanded="true"]{background:var(--surface-2);color:var(--fg)}
.ch-actions svg{width:17px;height:17px}

/* files */
.ch-files{display:flex;flex-direction:column;gap:6px;margin-top:6px;width:100%;min-width:0}
.ch-bubble.bare .ch-files{margin-top:0}
.ch-imgs{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:4px;width:min(420px,100%)}
.ch-imgs.one{grid-template-columns:minmax(0,1fr);width:min(360px,100%)}
.ch-img{position:relative;border-radius:10px;overflow:hidden;background:var(--surface-2);min-width:0}
.ch-imgs:not(.one) .ch-img{aspect-ratio:1/1}
.ch-img > button{display:block;width:100%;height:100%;border:0;padding:0;background:none;cursor:zoom-in}
.ch-img img,.ch-img canvas{display:block;width:100%;height:100%;max-height:240px;object-fit:cover}
.ch-imgs.one .ch-img img,.ch-imgs.one .ch-img canvas{height:auto}
.ch-img.ch-hold img{visibility:hidden}
.ch-file{display:flex;align-items:center;gap:10px;padding:6px 6px 6px 6px;border:1px solid var(--line);border-radius:10px;background:var(--surface);min-width:0;width:min(340px,100%);text-align:left}
.ch-file .fmeta{min-width:0}
.ch-file .fname{font-size:13px}
.ch-gifbtn{position:absolute;left:6px;bottom:6px;background:rgba(8,16,20,.78);color:#fff;border:0;border-radius:6px;padding:3px 8px 3px 6px;font:600 11.5px/1.2 var(--f-mono);display:inline-flex;gap:5px;align-items:center;cursor:pointer;z-index:1}
.ch-gifbtn svg{width:12px;height:12px}
.ch-gifbtn:hover{background:rgba(8,16,20,.92)}

/* reactions + receipts */
.ch-reacts{display:flex;flex-wrap:wrap;gap:4px;margin-top:4px}
.ch-react{display:inline-flex;gap:5px;align-items:center;border:1px solid var(--line);background:var(--surface);border-radius:999px;padding:1px 9px 1px 7px;font-size:14px;line-height:22px;cursor:pointer;color:var(--fg)}
.ch-react b{font:600 12px var(--f-mono);color:var(--muted)}
.ch-react:hover{border-color:var(--muted)}
.ch-react[aria-pressed="true"]{background:var(--info-soft);border-color:var(--info)}
.ch-react[aria-pressed="true"] b{color:var(--info)}
.ch-receipt{font-size:11.5px;color:var(--muted);margin:3px 2px 0;display:flex;gap:4px;align-items:center}
.ch-receipt svg{width:14px;height:14px}
.ch-receipt.seen{color:var(--info)}
.ch-receipt .linkbtn{font-size:11.5px;min-height:24px;padding:0 4px;margin:-4px -4px -4px 0;border-radius:6px}
.ch-receipt .linkbtn:hover{background:var(--surface-2);text-decoration:none}
.ch-state{font-size:11.5px;color:var(--muted);margin:3px 2px 0;display:flex;gap:10px;align-items:center;flex-wrap:wrap}
.ch-state.bad{color:var(--warn)}
.ch-state .linkbtn{font-size:11.5px;font-weight:600;min-height:24px;padding:0 6px;border-radius:6px}
.ch-msg.failed .ch-bubble{border-color:var(--warn)}

.ch-flash > .ch-col > .ch-bubble{box-shadow:0 0 0 3px var(--accent)}
@media (prefers-reduced-motion:no-preference){
  .ch-flash > .ch-col > .ch-bubble{animation:chflash 2.2s ease-out forwards}
  @keyframes chflash{0%,40%{box-shadow:0 0 0 3px var(--accent)}100%{box-shadow:0 0 0 3px transparent}}
}

/* typing + jump to latest */
.ch-typing{height:22px;flex:none;padding:0 32px;font-size:12.5px;color:var(--muted);display:flex;align-items:center;gap:6px;max-width:1004px;margin:0 auto;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
.ch-dots{display:inline-flex;gap:3px}
.ch-dots i{width:5px;height:5px;border-radius:50%;background:var(--muted);opacity:.6}
@media (prefers-reduced-motion:no-preference){
  .ch-dots i{animation:chdot 1.2s infinite ease-in-out}
  .ch-dots i:nth-child(2){animation-delay:.15s}.ch-dots i:nth-child(3){animation-delay:.3s}
  @keyframes chdot{0%,60%,100%{transform:none;opacity:.5}30%{transform:translateY(-3px);opacity:1}}
}
.ch-jump{position:absolute;left:50%;bottom:12px;transform:translateX(-50%);background:var(--ink);color:var(--ink-fg);border:1px solid var(--line);border-radius:999px;padding:7px 14px 7px 11px;font-weight:600;font-size:13px;box-shadow:0 6px 18px rgba(10,24,30,.25);display:flex;gap:6px;align-items:center;cursor:pointer;z-index:3;white-space:nowrap}
.ch-jump svg{width:15px;height:15px}

/* composer */
.ch-compose{position:relative;padding:2px 24px 16px;flex:none}
.ch-box{max-width:940px;margin:0 auto;background:var(--surface);border:1px solid var(--line);border-radius:14px;box-shadow:0 1px 3px rgba(23,35,43,.06)}
.ch-box:focus-within{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent),0 0 0 4px var(--accent-soft)}
.ch-box.ch-editing{border-color:var(--info);box-shadow:0 0 0 1px var(--info)}
.ch-ctx{display:flex;align-items:center;gap:8px;padding:8px 8px 0 10px;font-size:12.5px;min-width:0}
.ch-ctxin{flex:1;min-width:0;background:var(--surface-2);border-left:3px solid var(--accent);border-radius:6px;padding:4px 10px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-ctxin b{font-weight:600}
.ch-editing .ch-ctxin{border-left-color:var(--info)}
.ch-ctx .ch-ib{width:28px;height:28px}
.ch-ctx .ch-ib svg{width:15px;height:15px}
.ch-pend{display:flex;flex-wrap:wrap;gap:6px;padding:8px 10px 0}
.ch-chip{display:flex;align-items:center;gap:8px;border:1px solid var(--line);background:var(--surface-2);border-radius:9px;padding:4px 4px 4px 4px;max-width:250px;min-width:0;font-size:12.5px;position:relative;overflow:hidden}
.ch-chip .th{width:34px;height:34px;border-radius:6px;object-fit:cover;flex:none;background:var(--surface)}
.ch-chip .ficon{width:34px;height:34px}
.ch-chip .ficon svg{width:16px;height:16px}
.ch-chip .meta{display:flex;flex-direction:column;min-width:0}
.ch-chip .meta b{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-chip .meta small{color:var(--muted);font-size:11.5px}
.ch-chip.bad{border-color:var(--warn)}
.ch-chip.bad small{color:var(--warn)}
.ch-chip .ch-ib{width:26px;height:26px}
.ch-chip .ch-ib svg{width:14px;height:14px}
.ch-prog{position:absolute;left:0;bottom:0;height:3px;background:var(--accent);width:0}
.ch-input{display:block;width:100%;border:0;background:transparent;resize:none;padding:11px 14px 4px;font:14px/1.45 var(--f-body);color:var(--fg);max-height:calc(8 * 1.45em + 15px);overflow-y:auto;min-height:40px}
.ch-input:focus,.ch-input:focus-visible{outline:none}
.ch-input::placeholder{color:var(--muted)}
.ch-help{margin:4px 12px 2px;padding:8px 10px;font-size:12.5px;color:var(--fg);background:var(--surface-2);border-radius:8px;display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:4px 18px}
.ch-help h3{grid-column:1/-1;margin:2px 0 0;font-size:11px;letter-spacing:.09em;text-transform:uppercase;color:var(--muted);font-weight:600}
.ch-help div{display:flex;gap:8px;justify-content:space-between}
.ch-help span{color:var(--muted)}
.ch-help kbd,.ch-help code{font:11.5px var(--f-mono);background:var(--surface);border:1px solid var(--line);border-radius:4px;padding:0 4px;color:var(--fg)}
.ch-tools{display:flex;align-items:center;gap:2px;padding:2px 6px 6px}
.ch-tool{width:34px;height:34px;border:0;background:none;border-radius:8px;color:var(--muted);display:grid;place-items:center;cursor:pointer;padding:0}
.ch-tool:hover,.ch-tool[aria-expanded="true"]{background:var(--surface-2);color:var(--fg)}
.ch-tool svg{width:19px;height:19px}
.ch-count{margin-left:auto;font:12px var(--f-mono);color:var(--muted);padding:0 8px}
.ch-count.bad{color:var(--warn);font-weight:600}
.ch-send{margin-left:auto;width:38px;height:34px;border-radius:9px;border:0;background:var(--accent);color:var(--on-accent);display:grid;place-items:center;cursor:pointer;padding:0}
.ch-count:not(:empty) + .ch-send{margin-left:0}
.ch-send svg{width:18px;height:18px}
.ch-send:hover:not(:disabled){filter:brightness(1.06)}
.ch-send:disabled{background:var(--surface-2);color:var(--muted);cursor:default}
.ch-ro{max-width:940px;margin:0 auto;padding:14px 16px;border:1px dashed var(--line);border-radius:14px;color:var(--muted);text-align:center;background:var(--surface);font-size:13px}

.ch-drop{position:absolute;inset:8px;border:2px dashed var(--accent);background:var(--accent-soft);color:var(--accent-fg);border-radius:16px;display:grid;place-items:center;align-content:center;gap:8px;font:600 20px var(--f-display);z-index:10;pointer-events:none;text-align:center;padding:16px}
.ch-drop svg{width:36px;height:36px;margin:0 auto}

/* mention list (inside the composer) */
.ch-mlist{position:absolute;bottom:calc(100% - 2px);left:36px;width:min(330px,calc(100% - 72px));max-height:280px;overflow:auto;background:var(--surface);border:1px solid var(--line);border-radius:12px;box-shadow:0 12px 32px rgba(10,24,30,.22);padding:6px;z-index:20}
.ch-mlist h3{margin:4px 8px 6px;font-size:11px;letter-spacing:.09em;text-transform:uppercase;color:var(--muted);font-weight:600}
.ch-opt{display:flex;gap:10px;align-items:center;padding:6px 8px;border-radius:8px;cursor:pointer;min-width:0}
.ch-opt .av{width:28px;height:28px;font-size:10.5px}
.ch-opt > span:not(.av):not(.ch-every){min-width:0;display:flex;flex-direction:column}
.ch-opt b{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-opt small{color:var(--muted);font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-opt[aria-selected="true"]{background:var(--surface-2);box-shadow:inset 3px 0 0 var(--accent)}
.ch-opt .ch-every{width:28px;height:28px;border-radius:50%;background:var(--info-soft);color:var(--info);display:grid;place-items:center;font-weight:700;flex:none}

/* popovers + menus */
.ch-pop{position:fixed;z-index:45;background:var(--surface);color:var(--fg);border:1px solid var(--line);border-radius:12px;box-shadow:0 12px 32px rgba(10,24,30,.24);padding:6px;max-width:calc(100vw - 16px)}
@media (prefers-reduced-motion:no-preference){
  .ch-pop{animation:chpop .12s ease-out}
  @keyframes chpop{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:none}}
}
.ch-menu{min-width:210px}
.ch-menu button{display:flex;width:100%;gap:10px;align-items:center;padding:8px 10px;border:0;background:none;border-radius:7px;text-align:left;cursor:pointer;font-weight:500;color:var(--fg)}
.ch-menu button:hover,.ch-menu button:focus{background:var(--surface-2);outline:none}
.ch-menu button:focus-visible{box-shadow:inset 0 0 0 2px var(--accent)}
.ch-menu button svg{width:17px;height:17px;color:var(--muted);flex:none}
.ch-menu button.danger,.ch-menu button.danger svg{color:var(--warn)}
.ch-menu button[aria-checked]::after{content:"";margin-left:auto;width:12px;height:7px;border-left:2px solid transparent;border-bottom:2px solid transparent;transform:rotate(-45deg) translateY(-2px)}
.ch-menu button[aria-checked="true"]::after{border-color:var(--ok)}
.ch-menu hr{border:0;border-top:1px solid var(--line);margin:5px 4px}
.ch-menu .ch-mnote{font-size:12px;color:var(--muted);padding:4px 10px 6px;margin:0;max-width:260px}
.ch-mreacts{display:flex;gap:2px;justify-content:space-between;padding:2px 2px 0}
.ch-mreacts button{width:36px;height:36px;font-size:20px;line-height:1;border:0;background:none;border-radius:9px;cursor:pointer;display:grid;place-items:center;padding:0;flex:none}
.ch-mreacts button:hover,.ch-mreacts button:focus-visible{background:var(--surface-2)}
.ch-mreacts button:focus{outline:none}
.ch-mreacts button:focus-visible{box-shadow:inset 0 0 0 2px var(--accent)}
.ch-mreacts button[aria-checked="true"]{background:var(--info-soft);box-shadow:inset 0 0 0 1.5px var(--info)}
.ch-menu:has(.ch-mreacts){min-width:min(320px,calc(100vw - 16px))}
.ch-scrim{position:fixed;inset:0;z-index:44;background:rgba(6,14,17,.42)}
.ch-pop.ch-sheet{left:8px;right:8px;top:auto;bottom:calc(8px + env(safe-area-inset-bottom,0px));max-width:none;border-radius:18px;padding:8px 8px 10px}
.ch-pop.ch-sheet::before{content:"";display:block;width:36px;height:4px;border-radius:2px;background:var(--line);margin:0 auto 8px}
.ch-sheet .ch-mreacts button{width:auto;flex:1;height:46px;font-size:24px}
.ch-sheet.ch-menu button[role="menuitem"]{padding:12px;font-size:15px}
.ch-held > .ch-col > .ch-bubble{box-shadow:0 0 0 2px var(--accent)}
@media (pointer:coarse){
  .ch-stream .ch-msg{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
  .ch-stream .ch-msg .ch-code{-webkit-user-select:text;user-select:text}
}
@media (prefers-reduced-motion:no-preference){
  .ch-pop.ch-sheet{animation:chsheet .18s cubic-bezier(.2,.8,.2,1)}
  @keyframes chsheet{from{transform:translateY(24px);opacity:0}to{transform:none;opacity:1}}
}
.ch-qr{display:flex;gap:2px;flex-wrap:wrap}
.ch-qr button{width:38px;height:38px;font-size:21px;line-height:1;border:0;background:none;border-radius:9px;cursor:pointer;display:grid;place-items:center;padding:0}
.ch-qr button:hover,.ch-qr button:focus{background:var(--surface-2);outline:none}
.ch-qr button:focus-visible{box-shadow:inset 0 0 0 2px var(--accent)}
.ch-qr button[aria-pressed="true"]{background:var(--info-soft);box-shadow:inset 0 0 0 1.5px var(--info)}
@media (prefers-reduced-motion:no-preference){.ch-qr button:hover{transform:scale(1.12)}.ch-qr button{transition:transform .1s}}

/* task and idea references (#T-1042) */
.ch-ref{display:inline-flex;align-items:center;gap:6px;max-width:100%;vertical-align:baseline;margin:1px 0;padding:1px 4px 1px 7px;border:1px solid var(--line);border-radius:7px;background:var(--surface-2);color:var(--fg);font:inherit;font-size:13px;line-height:1.5;cursor:pointer;text-align:left}
.ch-ref:hover{border-color:var(--info);background:var(--info-soft)}
.ch-ref:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
.ch-ref .mono{font-weight:600;color:var(--info);flex:none}
.ch-ref .t{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-ref .chip{flex:none;font-size:11px;padding:0 7px}
.ch-ref.none{cursor:default;color:var(--muted);padding-right:7px}
.ch-ref.none small{font-size:11.5px}
.ch-opt .ch-every.ref{background:var(--surface-2);color:var(--fg)}

/* skeletons */
.ch-sk{background:var(--surface-2);border-radius:7px;display:block}
.ch-skrow{display:grid;grid-template-columns:40px minmax(0,1fr);gap:8px 10px;padding:10px;align-items:center}
.ch-skrow .c{width:40px;height:40px;border-radius:50%;grid-row:span 2}
.ch-skrow .l1{height:12px;width:60%}.ch-skrow .l2{height:10px;width:85%}
.ch-skmsg{display:flex;gap:10px;margin-top:16px;align-items:flex-start}
.ch-skmsg .c{width:32px;height:32px;border-radius:50%;flex:none}
.ch-skmsg .b{height:46px;border-radius:4px 14px 14px 14px}
.ch-skmsg.mine{justify-content:flex-end}
.ch-skmsg.mine .b{border-radius:14px 4px 14px 14px}
@media (prefers-reduced-motion:no-preference){
  .ch-sk{background:linear-gradient(90deg,var(--surface-2) 0%,var(--line) 45%,var(--surface-2) 90%);background-size:240% 100%;animation:chsk 1.4s linear infinite}
  @keyframes chsk{from{background-position:120% 0}to{background-position:-120% 0}}
}

/* empty states */
.ch-empty{margin:auto;text-align:center;color:var(--muted);max-width:380px;padding:28px 20px;display:flex;flex-direction:column;align-items:center;gap:10px}
.ch-empty .ill{width:76px;height:76px;border-radius:22px;background:var(--accent-soft);color:var(--accent-fg);display:grid;place-items:center;margin-bottom:4px;position:relative}
.ch-empty .ill svg{width:38px;height:38px}
.ch-empty .ill::after{content:"";position:absolute;right:-8px;top:-8px;width:26px;height:26px;border-radius:9px;background:var(--info-soft);box-shadow:0 0 0 4px var(--bg)}
.ch-side .ch-empty .ill::after{box-shadow:0 0 0 4px var(--surface)}
.ch-empty strong{font:600 22px/1.15 var(--f-display);color:var(--fg)}
.ch-empty p{margin:0;font-size:13px;line-height:1.5}
.ch-empty .ch-lock{display:inline-flex;gap:6px;align-items:center;font-size:12px;margin-top:6px;padding:4px 10px;border-radius:999px;background:var(--surface);border:1px solid var(--line)}
.ch-empty .ch-lock svg{width:13px;height:13px;color:var(--ok)}
.ch-noresult{padding:20px 12px;text-align:center;color:var(--muted);font-size:13px}
.ch-noresult b{display:block;color:var(--fg);margin-bottom:2px}

/* incoming-message banners */
.ch-toasts{position:fixed;right:16px;top:64px;z-index:55;display:flex;flex-direction:column;gap:8px;width:min(360px,calc(100vw - 32px));pointer-events:none}
.ch-ban{display:flex;gap:4px;align-items:flex-start;background:var(--surface);border:1px solid var(--line);border-left:4px solid var(--accent);border-radius:12px;box-shadow:0 12px 32px rgba(10,24,30,.24);pointer-events:auto;overflow:hidden}
.ch-ban > button:first-child{flex:1;min-width:0;display:flex;gap:10px;align-items:flex-start;text-align:left;border:0;background:none;padding:10px 4px 10px 12px;cursor:pointer;color:var(--fg)}
.ch-ban .av{width:32px;height:32px;font-size:11.5px}
.ch-ban .tx{min-width:0;display:flex;flex-direction:column;gap:1px}
.ch-ban b{font-weight:600;font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-ban small{color:var(--muted);font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-ban p{margin:2px 0 0;font-size:13px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;overflow-wrap:anywhere}
.ch-ban .ch-ib{margin:6px 6px 0 0;width:28px;height:28px}
.ch-ban .ch-ib svg{width:14px;height:14px}
@media (prefers-reduced-motion:no-preference){
  .ch-ban{animation:chban .22s cubic-bezier(.2,.8,.2,1)}
  @keyframes chban{from{opacity:0;transform:translateX(16px)}to{opacity:1;transform:none}}
}

/* dialogs (inside the page's modal()) */
.ch-dlg{gap:12px}
.ch-dlg .sub{margin:-6px 0 0;color:var(--muted);font-size:13px}
.ch-tobox{display:flex;flex-wrap:wrap;gap:6px;align-items:center;padding:6px 8px;border:1px solid var(--line);border-radius:8px;background:var(--surface-2);min-width:0}
.ch-tobox:focus-within{border-color:var(--accent)}
.ch-tobox input{flex:1 1 140px;min-width:0;border:0!important;background:none!important;padding:4px 2px!important;outline:none}
.ch-tag{display:inline-flex;gap:5px;align-items:center;padding:2px 3px 2px 3px;border-radius:999px;background:var(--info-soft);color:var(--info);font-size:12.5px;font-weight:600;max-width:100%}
.ch-tag .av{width:20px;height:20px;font-size:8.5px}
.ch-tag > span:not(.av){overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-tag button{width:20px;height:20px;border-radius:50%;border:0;background:none;color:inherit;cursor:pointer;display:grid;place-items:center;padding:0}
.ch-tag button:hover{background:var(--surface)}
.ch-tag button svg{width:12px;height:12px}
.ch-picker{display:flex;flex-direction:column;gap:1px;max-height:min(300px,42vh);overflow:auto;border:1px solid var(--line);border-radius:10px;padding:4px}
.ch-prow{display:flex;gap:10px;align-items:center;padding:6px 8px;border-radius:8px;cursor:pointer;font-size:13px;min-width:0}
.ch-prow:hover{background:var(--surface-2)}
.ch-prow input{width:16px;height:16px;flex:none;accent-color:var(--ink);margin:0}
.ch-prow .av{width:30px;height:30px;font-size:11px}
.ch-prow > span:not(.av){min-width:0;display:flex;flex-direction:column}
.ch-prow b{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-prow small{color:var(--muted);font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-prow.dis{cursor:default;opacity:1}
.ch-prow.dis b{color:var(--muted)}
.ch-radio{border:0;margin:0;padding:0;display:flex;flex-direction:column;gap:8px;min-width:0}
.ch-radio legend{font-size:12.5px;font-weight:600;color:var(--muted);padding:0;margin-bottom:6px}
.ch-radio label{display:flex;gap:10px;align-items:flex-start;padding:10px 12px;border:1px solid var(--line);border-radius:10px;cursor:pointer;font-size:13.5px}
.ch-radio label input{margin:3px 0 0;accent-color:var(--ink)}
.ch-radio label small{display:block;color:var(--muted);font-size:12.5px}
.ch-radio label:has(input:checked){border-color:var(--accent);background:var(--accent-soft)}
.ch-radio label:has(input:checked) small{color:var(--accent-fg)}
.ch-mem{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;max-height:min(420px,50vh);overflow:auto}
.ch-mem li{display:flex;align-items:center;gap:10px;padding:8px 2px;min-width:0;flex-wrap:wrap}
.ch-mem li + li{border-top:1px solid var(--line)}
.ch-mem .who{flex:1;min-width:140px;display:flex;flex-direction:column}
.ch-mem .who b{font-weight:600}
.ch-mem .who small{color:var(--muted);font-size:12px}
.ch-mem .ch-ava{width:34px;height:34px}
.ch-mem .ch-ava > .av{font-size:12px}
.ch-mem .btns{display:flex;gap:6px;flex-wrap:wrap}
.ch-mem .btn{padding:4px 10px;font-size:12.5px}
.ch-ownr{font-size:11px;font-weight:600;padding:1px 7px;border-radius:20px;background:var(--accent-soft);color:var(--accent-fg);margin-left:6px;vertical-align:1px}
.ch-gone{font-size:11px;font-weight:600;padding:1px 7px;border-radius:20px;background:var(--surface-2);color:var(--muted);border:1px solid var(--line);margin-left:6px}

/* dark: ink-coloured checkboxes and radios disappear on dark dialogs */
@media (prefers-color-scheme: dark){:root:not([data-theme="light"]) :is(.ch-prow,.ch-radio label) input{accent-color:var(--accent)}}
:root[data-theme="dark"] :is(.ch-prow,.ch-radio label) input{accent-color:var(--accent)}

/* lightbox */
.modal.ch-lbm{background:rgba(4,9,11,.86)}
.sheet.ch-lb{width:min(1100px,100%);gap:10px;padding:14px}
.ch-lbhead{display:flex;align-items:center;gap:12px;min-width:0}
.ch-lbhead > div{flex:1;min-width:0}
.ch-lb h3{font-size:18px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-lbmeta{font-size:12.5px;color:var(--muted)}
.ch-lbimg{display:grid;place-items:center;min-height:240px;background:#0b1214;border-radius:10px;overflow:hidden}
.ch-lbimg img{display:block;max-width:100%;max-height:min(68vh,900px);object-fit:contain}
.ch-lbbar{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.ch-lbbar .n{font:12.5px var(--f-mono);color:var(--muted);margin:0 auto}
.ch-lbbar .btn:disabled{opacity:.5;cursor:default}

/* directory button */
.btn.ch-msgbtn{display:inline-flex;align-items:center}

/* landscape tablets / small laptops: give the conversation more room */
@media (min-width:901px) and (max-width:1180px){#chat{grid-template-columns:280px minmax(0,1fr)}}

/* ---- phones and small tablets ---- */
@media (max-width:900px), (max-height:500px){
  #chat{grid-template-columns:minmax(0,1fr)}
  #chat .ch-conv{display:none}
  #chat.ch-showconv .ch-side{display:none}
  #chat.ch-showconv .ch-conv{display:flex}
  .ch-back{display:grid!important}
  .ch-side{border-right:0}
  .ch-stream{padding:10px 12px 8px}
  .ch-compose{padding:2px 10px calc(10px + env(safe-area-inset-bottom,0px))}
  .ch-typing{padding:0 18px}
  .ch-msg{padding:3px 2px}
  .ch-bubble{max-width:100%}
  .ch-toasts{top:auto;bottom:calc(80px + env(safe-area-inset-bottom,0px));right:12px;left:12px;width:auto}
}
/* Phones (upright or sideways) with a conversation open: the conversation gets the whole screen, as in any
   messaging app. Its own header has the back arrow; the top bar and the section bar come back with the list. */
@media (max-width:680px), (max-height:500px){
  body.ch-conv-open nav.rail, body.ch-conv-open header.top, body.ch-conv-open aside.proto{display:none}
  body.ch-conv-open .shell{padding-bottom:0;grid-template-columns:minmax(0,1fr)}
  body.ch-conv-open{overscroll-behavior:none}
  #chat{min-height:0}
}
@media (max-width:680px){
  body.ch-active .cpbadge{display:none}
  .ch-head{padding:8px 8px 8px 6px;gap:8px;min-height:56px}
  .ch-head .ch-ava{display:none}
  .ch-title h2{font-size:18px}
  .ch-hact{gap:0}
  .ch-hact .ch-pinbtn{display:none}
  .ch-sidehead{padding:12px 12px 8px}
  .ch-lists{padding:2px 4px 16px}
  .ch-row{padding:9px 8px}
  .ch-imgs{width:100%}
  .ch-actions{right:4px}
  .ch-mlist{left:10px;width:calc(100% - 20px)}
  .ch-toasts{bottom:calc(16px + env(safe-area-inset-bottom,0px))}
  body:not(.ch-conv-open) .ch-toasts{bottom:calc(80px + env(safe-area-inset-bottom,0px))}
}
@media (prefers-reduced-motion:no-preference){
  .ch-row,.ch-ib,.ch-tool,.ch-react,.ch-send{transition:background-color .15s,border-color .15s,color .15s}
  .ch-actions{transition:opacity .12s}
  .ch-box{transition:border-color .15s,box-shadow .15s}
}

/* page-level odds and ends while chat is on screen */
body.ch-active .shell{min-height:0}
body.ch-active .toast{bottom:calc(112px + env(safe-area-inset-bottom,0px))}
.olk[hidden]{display:none}
.av.ch-gone-av svg{width:55%;height:55%;color:#fff}
