.chat-stage { grid-area: chat; position: relative; min-width: 0; scroll-margin-top: 22px; }
.chat-stage-label { display: flex; justify-content: center; align-items: center; gap: 8px; width: fit-content; max-width: 100%; margin: 0 auto 14px; padding: 6px 14px; border: 1px solid color-mix(in srgb, var(--brand) 25%, var(--line)); border-radius: 50px; background: var(--brand-soft); color: var(--brand-700); font-size: .8rem; font-weight: 600; }
.chat-stage-label .icon { width: 18px; height: 18px; }
.web-chat-shell { padding: 6px; border: 1px solid var(--brand-accent); background: linear-gradient(145deg, var(--brand-accent), var(--brand-soft) 65%); border-radius: 25px; box-shadow: 0 24px 60px -24px #7047eb66, 0 0 0 6px color-mix(in srgb, var(--brand) 5%, transparent); }
.web-chat-card { background: var(--surface); border: 1px solid color-mix(in srgb, var(--brand) 20%, var(--line)); border-radius: 19px; overflow: hidden; min-width: 0; min-height: 515px; display: flex; flex-direction: column; }
.web-chat-card-head { padding: 24px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; background: linear-gradient(115deg, #4d269d, #7047eb); color: #fff; }
.chat-heading { display: flex; align-items: center; gap: 11px; min-width: 0; }
.chat-heading-icon { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid #ffffff40; border-radius: 14px; background: #ffffff1a; color: #fff; flex-shrink: 0; }
.chat-heading > div { display: flex; flex-direction: column; }
.chat-heading h2 { font-weight: 600; font-size: 1.4rem; line-height: 1.5; }
.chat-heading > div > span { color: #f0eaff; font-size: .76rem; }
.web-chat-connection { display: flex; align-items: center; gap: 6px; font-size: .62rem; white-space: nowrap; color: #f0eaff; }
.web-chat-connection::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.web-chat-connection.connected { color: #a5f3d2; }
.web-chat-setup { padding: 25px 29px 19px; display: flex; flex-direction: column; gap: 17px; flex: 1; }
.setup-intro h3 { font-size: 1.22rem; font-weight: 500; margin-bottom: 7px; }
.setup-intro p { font-size: .74rem; color: var(--ink-soft); }
.form-field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.form-field label { font-size: .77rem; font-weight: 500; }
.form-field input, .form-field select, .web-chat-report-dialog select { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 9px; padding: 11px 13px; background: var(--bg); color: var(--ink); font-size: .85rem; min-height: 44px; }
.form-field input::placeholder, .web-chat-compose input::placeholder { color: var(--ink-soft); opacity: 1; }
.form-field input:focus, .form-field select:focus { border-color: var(--brand-accent); }
.field-hint { font-size: .64rem; color: var(--ink-soft); line-height: 1.6; }
.web-chat-profile-fields { display: grid; grid-template-columns: .7fr 1.3fr; gap: 12px; }
.web-chat-check { display: flex; align-items: flex-start; gap: 9px; font-size: .69rem; line-height: 1.8; color: var(--ink-soft); cursor: pointer; }
.web-chat-check input { accent-color: #7047eb; width: 16px; height: 16px; flex-shrink: 0; margin: 3px 0 0; cursor: pointer; }
.web-chat-check a { text-decoration: underline; text-underline-offset: 2px; color: var(--brand-700); }
.web-chat-setup > .btn { width: 100%; font-size: 1rem; min-height: 52px; }
.setup-footnote { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: .63rem; color: var(--ink-soft); margin-top: -6px; }
.setup-footnote .icon { width: 13px; height: 13px; }
.web-chat-error { color: var(--danger); font-size: .8rem; }
.chat-stage-note { display: flex; justify-content: center; align-items: center; gap: 7px; margin-top: 15px; font-size: .68rem; color: var(--ink-soft); }
.web-chat-waiting, .web-chat-error-state, .web-chat-gate { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 22px; padding: 38px 26px; flex: 1; min-height: 426px; }
.web-chat-waiting h2, .web-chat-error-state h2 { font-size: 1.35rem; font-weight: 500; }
.web-chat-waiting p, .web-chat-error-state p, .web-chat-gate p { font-size: .86rem; color: var(--ink-soft); }
.web-chat-spinner { width: 56px; height: 56px; border: 3px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; animation: chat-spin 1s linear infinite; }
@keyframes chat-spin { to { transform: rotate(360deg); } }
.state-icon { display: grid; place-items: center; width: 56px; height: 56px; border: 1px solid var(--line); border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-size: 1.6rem; }
.web-chat-room { display: flex; flex-direction: column; flex: 1; min-height: 445px; }
.web-chat-peer { display: flex; align-items: center; gap: 10px; padding: 12px 17px; border-bottom: 1px solid var(--line); }
.web-chat-avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-700); font-weight: 500; flex-shrink: 0; }
.web-chat-peer > div:nth-child(2) { display: flex; flex-direction: column; min-width: 0; }
.web-chat-peer strong { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.web-chat-peer span { font-size: .65rem; color: var(--ink-soft); }
.web-chat-report { border: 0; background: transparent; color: var(--danger); font-size: .68rem; padding: 8px 0 8px 7px; margin-inline-start: auto; flex-shrink: 0; }
.web-chat-messages { padding: 18px 16px; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px; flex: 1; height: 275px; min-height: 240px; max-height: 340px; background: var(--bg); }
.web-chat-messages:focus-visible { outline-offset: -3px; }
.web-chat-message { font-size: .85rem; max-width: 84%; padding: 9px 13px; border-radius: 13px; overflow-wrap: anywhere; white-space: pre-wrap; unicode-bidi: plaintext; }
.web-chat-message.mine { align-self: flex-start; background: #7047eb; color: #fff; border-end-start-radius: 3px; }
.web-chat-message.theirs { align-self: flex-end; background: var(--surface); border: 1px solid var(--line); border-end-end-radius: 3px; }
.web-chat-message.system { align-self: center; max-width: 100%; padding: 5px 8px; font-size: .68rem; text-align: center; color: var(--ink-soft); }
.web-chat-typing { background: var(--bg); padding: 4px 17px; font-size: .7rem; color: var(--ink-soft); }
.web-chat-compose { display: flex; align-items: center; gap: 10px; padding: 12px; border-top: 1px solid var(--line); }
.web-chat-compose input { width: 100%; min-width: 0; flex: 1; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: .88rem; }
.web-chat-compose button { display: grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 11px; background: #7047eb; color: white; flex-shrink: 0; }
.web-chat-send-status { color: var(--ink-soft); font-size: .74rem; padding: 0 15px 9px; }
.web-chat-actions { display: flex; gap: 8px; padding: 0 12px 12px; }
.web-chat-actions .btn { flex: 1; min-height: 40px; padding: 8px 10px; font-size: .75rem; }
.web-chat-actions .btn-quiet { flex: none; }
.web-chat-gate { gap: 17px; }
.web-chat-gate > img { border-radius: 16px; }
.web-chat-gate .eyebrow { margin: 0; font-size: .74rem; }
.web-chat-gate h2 { font-size: 1.8rem; font-weight: 500; }
.web-chat-gate .stores { justify-content: center; gap: 8px; }
.web-chat-gate .store { padding: 9px 12px; gap: 8px; }
.web-chat-gate .store strong { font-size: .82rem; }
.web-chat-gate p.field-hint { font-size: .64rem; }
.web-chat-report-dialog { width: min(480px, calc(100% - 32px)); border: 1px solid var(--line); border-radius: 20px; padding: 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.web-chat-report-dialog::backdrop { background: #100c2066; backdrop-filter: blur(5px); }
.web-chat-report-dialog form { display: grid; gap: 16px; padding: 29px; }
.web-chat-report-dialog h2 { font-size: 1.5rem; }
.web-chat-report-dialog p { font-size: .87rem; color: var(--ink-soft); }
.web-chat-report-dialog p.web-chat-error { color: var(--danger); }
.web-chat-report-dialog label { font-size: .8rem; }
.web-chat-report-dialog form > div { display: flex; gap: 10px; }
.web-chat-report-dialog .btn { flex: 1; padding-inline: 10px; font-size: .85rem; }
@media (max-width: 1000px) {
  .web-chat-setup { padding: 23px 21px 18px; }
  .web-chat-card-head { padding: 18px; }
  .web-chat-connection { font-size: .58rem; }
}
@media (max-width: 850px) {
  .chat-stage { max-width: 540px; width: 100%; margin-inline: auto; }
}
@media (max-width: 680px) {
  .chat-stage { max-width: 460px; width: 100%; margin-inline: auto; }
  .web-chat-setup { padding: 24px; }
  .web-chat-card-head { padding: 18px 22px; }
  .chat-heading h2 { font-size: 1.25rem; }
  .form-field input, .form-field select, .web-chat-compose input, .web-chat-report-dialog select { font-size: 16px; }
  .web-chat-check { font-size: .73rem; }
  .field-hint, .setup-footnote { font-size: .68rem; }
  .web-chat-connection { font-size: .62rem; }
  .web-chat-messages { max-height: 44dvh; }
  .web-chat-room { min-height: 435px; }
}
@media (max-width: 370px) {
  .web-chat-setup { padding-inline: 17px; }
  .web-chat-card-head { padding-inline: 15px; }
  .chat-heading-icon { width: 32px; height: 32px; }
  .web-chat-report-dialog form > div { flex-direction: column-reverse; }
}
@media (prefers-reduced-motion: reduce) {
  .web-chat-spinner { animation: none; border-color: var(--brand); border-style: dashed; }
}
