*{box-sizing:border-box}
html,body{margin:0;height:100%}
body{font:15px/1.45 system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;color:#111827;background:#fff;--brand:#2563eb}
.w-root{display:flex;flex-direction:column;height:100%}
.w-head{display:flex;align-items:center;gap:10px;padding:14px 16px;background:var(--brand);color:#fff}
.w-avatar{width:38px;height:38px;border-radius:50%;background:rgba(255,255,255,.22);display:flex;align-items:center;justify-content:center;font-weight:700;font-size:14px;flex:none}
.w-title{display:flex;flex-direction:column;min-width:0;flex:1}
.w-title strong{font-size:15px}
.w-title small{opacity:.85;font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.w-close{background:transparent;border:0;color:#fff;font-size:26px;line-height:1;cursor:pointer;padding:4px 8px;border-radius:8px}
.w-close:hover,.w-close:focus-visible{background:rgba(255,255,255,.18);outline:none}
.w-log{flex:1;min-height:140px;overflow-y:auto;padding:16px;background:#f8fafc;display:flex;flex-direction:column;gap:8px}
.w-msg{display:flex}
.w-msg.me{justify-content:flex-end}
.w-bubble{max-width:82%;padding:9px 13px;border-radius:16px;white-space:pre-wrap;word-wrap:break-word;overflow-wrap:anywhere}
.w-msg.them .w-bubble{background:#fff;border:1px solid #e5e7eb;border-bottom-left-radius:4px}
.w-msg.me .w-bubble{background:var(--brand);color:#fff;border-bottom-right-radius:4px}
.w-msg.w-error .w-bubble{background:#fef2f2;border-color:#fecaca;color:#991b1b}
.w-typing .w-bubble{display:flex;gap:4px;align-items:center;min-height:36px}
.dot{width:7px;height:7px;border-radius:50%;background:#9ca3af;animation:b 1.2s infinite ease-in-out}
.dot:nth-child(2){animation-delay:.15s}.dot:nth-child(3){animation-delay:.3s}
@keyframes b{0%,80%,100%{transform:scale(.6);opacity:.5}40%{transform:scale(1);opacity:1}}
.w-form{display:flex;gap:8px;padding:10px 12px;border-top:1px solid #e5e7eb;background:#fff}
.w-form input{flex:1;border:1px solid #d1d5db;border-radius:22px;padding:10px 14px;font:inherit;min-width:0}
.w-form input:focus{outline:2px solid var(--brand);outline-offset:0;border-color:transparent}
.w-send{width:42px;height:42px;border-radius:50%;border:0;background:var(--brand);color:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;flex:none}
.w-send:disabled{opacity:.5;cursor:not-allowed}
.w-lead{max-height:55%;overflow-y:auto;flex:none;padding:12px;border-top:1px solid #e5e7eb;background:#fff;display:flex;flex-direction:column;gap:8px}
.w-lead[hidden]{display:none}
.w-lead-title{margin:0;font-weight:600}
.w-lead input,.w-lead textarea{border:1px solid #d1d5db;border-radius:10px;padding:9px 12px;font:inherit;width:100%}
.w-lead input:focus,.w-lead textarea:focus{outline:2px solid var(--brand);border-color:transparent}
.w-lead-actions{display:flex;justify-content:flex-end;gap:8px}
.w-btn{background:var(--brand);color:#fff;border:0;border-radius:10px;padding:9px 16px;font:600 14px system-ui,sans-serif;cursor:pointer}
.w-btn-ghost{background:transparent;border:1px solid #d1d5db;border-radius:10px;padding:9px 14px;font:14px system-ui,sans-serif;cursor:pointer}
.w-privacy{margin:0;font-size:11px;color:#6b7280}
.w-hp{position:absolute!important;left:-9999px!important;width:1px;height:1px;opacity:0}
.w-foot{font-size:11px;color:#9ca3af;text-align:center;padding:6px 8px 8px;background:#fff}
.w-link{background:none;border:0;color:var(--brand);font:inherit;cursor:pointer;padding:0;text-decoration:underline}
.w-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0)}

/* Dark theme (widget.theme = "dark"): deep surfaces, brand accent. Text colours meet WCAG AA on their backgrounds. */
body[data-theme=dark]{color:#eef0ff;background:#0b0d1a}
body[data-theme=dark] .w-head{background:linear-gradient(135deg,var(--brand),#2a1f6e)}
body[data-theme=dark] .w-log{background:#0b0d1a}
body[data-theme=dark] .w-msg.them .w-bubble{background:#171a2e;border-color:#2a2f4a;color:#eef0ff}
body[data-theme=dark] .w-msg.w-error .w-bubble{background:#3a1218;border-color:#7f1d1d;color:#fecaca}
body[data-theme=dark] .dot{background:#8b90b8}
body[data-theme=dark] .w-form,body[data-theme=dark] .w-lead,body[data-theme=dark] .w-foot{background:#10132a;border-color:#23284a}
body[data-theme=dark] .w-form input,body[data-theme=dark] .w-lead input,body[data-theme=dark] .w-lead textarea{background:#0b0d1a;border-color:#2f3558;color:#eef0ff}
body[data-theme=dark] .w-form input::placeholder,body[data-theme=dark] .w-lead input::placeholder,body[data-theme=dark] .w-lead textarea::placeholder{color:#8b90b8}
body[data-theme=dark] .w-btn-ghost{border-color:#2f3558;color:#eef0ff}
body[data-theme=dark] .w-privacy,body[data-theme=dark] .w-foot{color:#9a9fc4}
body[data-theme=dark] .w-link{color:#c4b8ff}
/* White text on brand fills: deepen the brand ~18% so it clears WCAG AA (4.5:1) even for light brand colours like
   #7c62ff (4.2:1 → ~5.6:1). Browsers without color-mix keep the plain brand colour. */
body[data-theme=dark] .w-msg.me .w-bubble,body[data-theme=dark] .w-btn,body[data-theme=dark] .w-send{background:var(--brand);background:color-mix(in srgb,var(--brand) 82%,#000)}

/* Topic buttons under the welcome message */
.w-quick{display:flex;flex-wrap:wrap;gap:6px;margin:2px 0 4px}
.w-chip{border:1px solid var(--brand);background:transparent;color:var(--brand);border-radius:999px;padding:7px 12px;font:600 13px/1.2 system-ui,sans-serif;cursor:pointer}
.w-chip:hover,.w-chip:focus-visible{background:var(--brand);color:#fff;outline:none}
body[data-theme=dark] .w-chip{border-color:color-mix(in srgb,var(--brand) 70%,#fff);color:#d9d2ff}
body[data-theme=dark] .w-chip:hover,body[data-theme=dark] .w-chip:focus-visible{background:color-mix(in srgb,var(--brand) 82%,#000);color:#fff}

/* Links in replies */
.w-reply-link{color:inherit;text-decoration:underline;text-underline-offset:2px;word-break:break-all}
.w-msg.them .w-reply-link{color:var(--brand)}
body[data-theme=dark] .w-msg.them .w-reply-link{color:#c4b8ff}
