.layout{position:relative}
#chatRoot{pointer-events:none}
#chatFab{pointer-events:auto}
body:not(.chat-open) #chatPanel{visibility:hidden}
body:not(.chat-open) #chatPanel *{pointer-events:none}
body.chat-open #chatPanel, body.chat-open #chatPanel *{pointer-events:auto}

#chatFab{
  position:absolute;right:16px;bottom:16px;z-index:15;
  display:flex;align-items:center;gap:.45rem;
  background:var(--accent);color:var(--paper);
  border:0;border-radius:99px;padding:.55rem .95rem .55rem .75rem;
  font:600 .9rem Inter,system-ui,sans-serif;cursor:pointer;
  box-shadow:0 6px 18px #0003;
}
#chatFab:hover{filter:brightness(1.08)}
body.chat-open #chatFab{display:none}

#chatPanel{
  position:fixed;right:16px;bottom:16px;z-index:40;
  width:min(420px, calc(100vw - 24px));
  max-height:min(70vh, 640px);
  display:flex;flex-direction:column;
  background:var(--paper);color:var(--ink);
  border:1px solid var(--line);border-radius:16px;
  box-shadow:0 16px 40px #0003;
  transform:translateY(18px);opacity:0;pointer-events:none;
  transition:transform .22s ease,opacity .22s ease,visibility .22s;
}
body.chat-open #chatPanel{transform:none;opacity:1;pointer-events:auto}

.chatHead{display:flex;align-items:flex-start;gap:.6rem;padding:.85rem 1rem .7rem;border-bottom:1px solid var(--line)}
.chatHead h2{margin:0;font:600 1.02rem Literata,serif;color:var(--accent)}
.chatSub{margin:.2rem 0 0;font-size:.75rem;color:var(--muted);line-height:1.4}
.chatIcon{background:none;border:0;color:var(--ink);font-size:1.5rem;line-height:1;cursor:pointer;padding:.1rem .3rem}

.chatLog{flex:1;overflow:auto;padding:.8rem 1rem 1rem;display:flex;flex-direction:column;gap:.7rem}
.chatMsg{display:flex;max-width:100%}
.chatMsg.user{justify-content:flex-end}
.chatBubble{border:1px solid var(--line);background:var(--bg);border-radius:14px;padding:.7rem .85rem;max-width:100%}
.chatMsg.user .chatBubble{background:var(--hl);border-color:transparent}
.chatBubble p{margin:0 0 .55rem;font:400 .95rem/1.55 Inter,system-ui,sans-serif}
.chatBubble p:last-child{margin-bottom:0}
.chatBubble ul{margin:.2rem 0 .5rem 1.1rem;padding:0}
.chatBubble li{margin:.2rem 0;font-size:.95rem;line-height:1.5}
.chatBubble pre{white-space:pre-wrap;font-size:.85rem;background:var(--side);padding:.4rem .5rem;border-radius:8px}

.chatChips{display:flex;flex-wrap:wrap;gap:.4rem;margin-top:.7rem}
.chatChip,.chatCite,.chatRead,#chatSend{
  border:1px solid var(--line);background:var(--paper);color:var(--ink);
  border-radius:99px;padding:.3rem .7rem;font:500 .8rem Inter,system-ui,sans-serif;cursor:pointer
}
.chatChip:hover,.chatCite:hover{border-color:var(--accent);color:var(--accent)}
.chatCites{display:flex;flex-direction:column;align-items:flex-start;gap:.35rem;margin-top:.7rem}
.chatCite,a.chatJump{color:var(--accent);text-align:left}
a.chatJump{font-weight:600;text-decoration:underline;text-underline-offset:2px}
.chatActs{margin-top:.65rem}
.chatRead{padding:.25rem .65rem}
.chatMock{font-size:.75rem;color:var(--muted);margin-bottom:.45rem;font-style:italic}
.chatMsg.error .chatBubble{background:var(--hl);color:var(--ink)}

.chatDots{display:inline-flex;gap:.25rem;padding:.15rem 0}
.chatDots i{width:7px;height:7px;border-radius:50%;background:var(--accent);opacity:.4;animation:chatBounce 1s infinite}
.chatDots i:nth-child(2){animation-delay:.15s}
.chatDots i:nth-child(3){animation-delay:.3s}
@keyframes chatBounce{0%,80%,100%{transform:translateY(0);opacity:.35}40%{transform:translateY(-4px);opacity:1}}

.chatForm{display:flex;gap:.45rem;align-items:flex-end;padding:.65rem .75rem .75rem;border-top:1px solid var(--line)}
#chatInput{
  flex:1;resize:none;min-height:42px;max-height:140px;
  border:1px solid var(--line);border-radius:12px;background:var(--bg);color:var(--ink);
  font:400 1rem/1.4 Inter,system-ui,sans-serif;padding:.55rem .7rem
}
#chatInput:focus{outline:2px solid var(--accent);outline-offset:1px}
#chatSend{background:var(--accent);color:var(--paper);border-color:var(--accent);height:42px;padding:0 1rem;flex:0 0 auto}
#chatSend:disabled{opacity:.55;cursor:default}

.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0}

@media (max-width:800px){
  #chatFab{right:12px;bottom:12px}
  #chatPanel{
    right:0;left:0;bottom:0;width:100%;
    max-height:80vh;border-radius:16px 16px 0 0;
  }
}
