.lab-chat-fab{position:fixed;right:16px;bottom:22px;max-width:min(320px,calc(100vw - 32px));z-index:9000;display:inline-flex;align-items:center;gap:10px;background:#026AF2;color:#fff;border:0;border-radius:999px;padding:14px 20px;font-family:'Plus Jakarta Sans',system-ui,sans-serif;font-size:14px;font-weight:700;cursor:pointer;box-shadow:0 8px 28px rgba(2,106,242,.35);transition:transform .2s,box-shadow .2s,opacity .3s;overflow:hidden;white-space:nowrap}
.lab-chat-fab:hover{transform:translateY(-2px);box-shadow:0 12px 32px rgba(2,106,242,.45)}
.lab-chat-fab svg{flex:0 0 auto}
.lab-chat-fab span{overflow:hidden;text-overflow:ellipsis;min-width:0}
.lab-chat-panel{position:fixed;right:16px;bottom:88px;z-index:9000;width:380px;max-width:calc(100vw - 32px);height:520px;max-height:calc(100vh - 120px);display:none;flex-direction:column;background:#fff;border:1px solid var(--line);border-radius:20px;box-shadow:0 20px 60px rgba(10,25,45,.25);overflow:hidden;font-family:var(--sans)}
.lab-chat-panel.open{display:flex}
.lab-chat-head{background:var(--blue);color:#fff;padding:16px 18px;display:flex;align-items:center;justify-content:space-between;flex:0 0 auto;min-width:0}
.lab-chat-head>div{min-width:0;overflow:hidden}
.lab-chat-head b{font-size:15.5px;font-weight:800}
.lab-chat-head span{display:block;font-size:12px;opacity:.85;font-weight:500}
.lab-chat-close{background:transparent;border:0;color:#fff;font-size:20px;cursor:pointer;line-height:1;padding:4px}
.lab-chat-msgs{flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:10px;background:var(--paper)}
.lab-chat-msg{max-width:85%;padding:10px 14px;border-radius:14px;font-size:14px;line-height:1.55}
.lab-chat-msg.bot{background:#fff;border:1px solid var(--line);color:var(--ink);align-self:flex-start;border-bottom-left-radius:4px}
.lab-chat-msg.user{background:var(--blue);color:#fff;align-self:flex-end;border-bottom-right-radius:4px}
.lab-chat-msg.typing{color:var(--muted)}
.lab-chat-form{display:flex;gap:8px;padding:12px;border-top:1px solid var(--line);background:#fff}
.lab-chat-form input{flex:1;border:1px solid var(--line-2);border-radius:999px;padding:11px 16px;font:inherit;font-size:14px;outline:none}
.lab-chat-form input:focus{border-color:var(--blue)}
.lab-chat-form button{background:var(--blue);color:#fff;border:0;border-radius:999px;width:42px;height:42px;font-size:18px;cursor:pointer;flex:0 0 auto}
.lab-chat-form button:hover{background:var(--blue-dark)}
body.dark .lab-chat-panel{background:#16202e;border-color:#2e3d52}
body.dark .lab-chat-head{background:#026AF2}
body.dark .lab-chat-msgs{background:#0f1722}
body.dark .lab-chat-msg.bot{background:#1e2a3c;border-color:#2e3d52;color:#f0f4f8}
body.dark .lab-chat-msg.user{background:#026AF2;color:#fff}
body.dark .lab-chat-form{background:#16202e;border-color:#2e3d52}
body.dark .lab-chat-form input{background:#0f1722;border-color:#2e3d52;color:#f0f4f8}
body.dark .lab-chat-form input::placeholder{color:#8a96a8}
@media(max-width:480px){.lab-chat-fab span{display:none}.lab-chat-fab{padding:14px}}

/* Conversation is structured content, not one unformatted text blob. */
.lab-chat-panel{height:min(580px,calc(100dvh - 112px));min-height:0;isolation:isolate}
.lab-chat-msg{overflow-wrap:anywhere;white-space:normal;min-width:0}
.lab-chat-msg.bot{width:fit-content;max-width:94%;padding:14px 16px}
.lab-chat-msg.bot p{margin:0 0 10px;line-height:1.55}
.lab-chat-msg.bot p:last-child{margin-bottom:0}
.lab-chat-msg.bot ul,.lab-chat-msg.bot ol{padding-left:20px;margin:6px 0 12px;display:grid;gap:6px}
.lab-chat-msg.bot li{padding-left:2px}
.lab-chat-msg.bot strong{font-weight:800}
.lab-chat-msg.bot .lab-chat-section{display:block;margin:12px 0 7px;font-size:14px}
.lab-chat-msg.bot .lab-chat-section:first-child{margin-top:0}
.lab-chat-msg.bot a{color:var(--blue);text-decoration:underline;text-underline-offset:3px}
.lab-chat-msg.bot code{padding:2px 5px;background:var(--paper);border-radius:4px;white-space:normal;overflow-wrap:anywhere}
.lab-chat-prompts{display:flex;flex-wrap:wrap;gap:7px;align-self:flex-start;max-width:100%}
.lab-chat-prompts button{background:#fff;color:#154b9f;border:1px solid #aacaff;border-radius:999px;padding:7px 10px;font:600 12px/1.4 var(--sans);cursor:pointer}
.lab-chat-prompts button:hover{background:#ecf4ff}
.lab-chat-sr-only{position:absolute!important;width:1px!important;height:1px!important;padding:0!important;margin:-1px!important;overflow:hidden!important;clip:rect(0 0 0 0)!important;white-space:nowrap!important;border:0!important}
.lab-chat-msg.typing{display:flex;align-items:center;min-height:42px}
.lab-chat-dots{display:inline-flex;gap:5px;align-items:center;min-height:14px}
.lab-chat-dots i{width:7px;height:7px;border-radius:50%;background:#7c95b8;animation:lab-chat-pulse 1.1s ease-in-out infinite}
.lab-chat-dots i:nth-child(2){animation-delay:.15s}.lab-chat-dots i:nth-child(3){animation-delay:.3s}
@keyframes lab-chat-pulse{0%,65%,100%{opacity:.3;transform:translateY(0)}35%{opacity:1;transform:translateY(-4px)}}
.lab-chat-form input:disabled{opacity:.7;cursor:progress}
.lab-chat-form button:disabled{opacity:.5;cursor:progress}
body.dark .lab-chat-panel{background:var(--white);border-color:var(--line);color:var(--ink)}
body.dark .lab-chat-msgs{background:var(--paper)}
body.dark .lab-chat-msg.bot{background:var(--white);border-color:var(--line);color:var(--ink)}
body.dark .lab-chat-msg.user{background:#2f72d4;color:#fff}
body.dark .lab-chat-form{background:var(--white);border-color:var(--line)}
body.dark .lab-chat-form input{background:#0c1422;border-color:var(--line-2);color:var(--ink)}
body.dark .lab-chat-msg.bot code{background:#26364b}
body.dark .lab-chat-msg.bot a{color:var(--blue)}
body.dark .lab-chat-prompts button{background:#20334a;border-color:#3f688d;color:#e6f2ff}
body.dark .lab-chat-prompts button:hover{background:#294464}
@media(max-width:480px){
 .lab-chat-fab{width:48px;height:48px;min-height:48px;padding:0;justify-content:center;bottom:max(16px,env(safe-area-inset-bottom));right:16px}
 .lab-chat-fab svg{width:21px;height:21px}
 .lab-chat-panel{right:8px;left:8px;max-width:none;width:auto;bottom:72px;height:min(620px,calc(100dvh - 92px));max-height:calc(100dvh - 92px)}
 .lab-chat-msg.bot{max-width:95%}
}
@media(prefers-reduced-motion:reduce){.lab-chat-dots i{animation:none;opacity:.65}.lab-chat-fab,.lab-chat-panel{transition:none}}

/* Keep the assistant available without hiding the next/previous lesson links.
   Collapse to the icon on tablet/mobile; keep its accessible button label. */
@media (max-width:900px) and (min-width:481px){
 .lab-chat-fab{width:52px;height:52px;padding:0;justify-content:center}
 .lab-chat-fab span{display:none}
}
@media (min-width:901px){
 body:has(.lab-chat-fab) .bottombar{padding-right:340px}
 body:has(.lab-chat-fab) .provider-strip{padding-right:340px}
}
@media (max-width:900px){
 body:has(.lab-chat-fab) .bottombar{padding-bottom:84px}
}
