:root {
  --profile-accent: #dc3937;
  --profile-accent-hover: #bf2e2c;
  --profile-surface: #111218;
  --profile-raised: #1c1d25;
  --profile-border: #34353f;
  --profile-text: #f2f2f5;
  --profile-muted: #aaaab6;
}

.profile-chat-open {
  position: fixed;
  z-index: 398;
  right: 24px;
  bottom: 24px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 0 16px 0 10px;
  border: 1px solid var(--profile-accent);
  border-radius: 8px;
  background: var(--profile-accent);
  color: #fff;
  box-shadow: 0 12px 32px #08080c55;
  cursor: pointer;
  font: 700 14px/1 var(--font-body, sans-serif);
  white-space: nowrap;
  transition: transform 180ms ease, background 180ms ease;
}
.profile-chat-open:hover { background: var(--profile-accent-hover); transform: translateY(-2px); }
.profile-chat-open:active { transform: translateY(0); }
.profile-chat-open[aria-expanded="true"] { visibility: hidden; }
.profile-chat-open__mark {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border: 1px solid #ffffff99;
  border-radius: 4px;
  font: 700 11px/1 var(--font-mono, monospace);
}

.profile-chat {
  position: fixed;
  z-index: 400;
  inset: auto 24px 24px auto;
  right: 24px;
  bottom: 24px;
  width: min(400px, calc(100vw - 32px));
  height: min(550px, calc(100dvh - 32px));
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--profile-border);
  border-radius: 12px;
  background: var(--profile-surface);
  color: var(--profile-text);
  box-shadow: 0 20px 65px #06070cb3;
  font-family: var(--font-body, "Microsoft YaHei", sans-serif);
}
.profile-chat:not([open]) { display: none; }
.profile-chat::backdrop { background: transparent; }
.profile-chat__shell {
  display: grid;
  grid-template-rows: 68px minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
}
.profile-chat__header {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 16px;
  border-bottom: 1px solid #653035;
  background: #1b1820;
}
.profile-chat__avatar {
  display: block;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border: 2px solid #e86c67;
  border-radius: 50%;
  object-fit: cover;
}
.profile-chat__title { min-width: 0; flex: 1 1 auto; }
.profile-chat__title h2 {
  margin: 0;
  color: var(--profile-text);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}
.profile-chat__subtitle {
  margin: 2px 0 0;
  color: #d28c91;
  font: 600 10px/1.3 var(--font-mono, monospace);
  letter-spacing: .03em;
}
.profile-chat__close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #bdbdc8;
  cursor: pointer;
  font: 400 24px/1 Arial, sans-serif;
}
.profile-chat__close:hover { background: #ffffff12; color: #fff; }

.profile-chat__body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px;
  scrollbar-color: #4a4a55 transparent;
  scrollbar-width: thin;
}
.profile-chat__welcome,
.profile-chat__message--assistant {
  max-width: 88%;
  border: 1px solid var(--profile-border);
  border-radius: 4px 12px 12px 12px;
  background: var(--profile-raised);
}
.profile-chat__welcome {
  padding: 13px 15px;
  color: var(--profile-text);
  font-size: 13px;
  line-height: 1.65;
}
.profile-chat__messages { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.profile-chat__typing {
  display: flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--profile-border);
  border-radius: 4px 12px 12px 12px;
  background: var(--profile-raised);
}
.profile-chat__typing[hidden] { display: none; }
.profile-chat__typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #d19393;
  animation: profile-typing 1s ease-in-out infinite;
}
.profile-chat__typing i:nth-child(2) { animation-delay: 150ms; }
.profile-chat__typing i:nth-child(3) { animation-delay: 300ms; }
@keyframes profile-typing { 50% { opacity: .25; transform: translateY(-2px); } }
.profile-chat__message {
  width: fit-content;
  max-width: 88%;
  padding: 11px 14px;
  overflow-wrap: anywhere;
}
.profile-chat__message--user {
  align-self: flex-end;
  border-radius: 12px 4px 12px 12px;
  background: #a33136;
  color: #fff;
}
.profile-chat__message--assistant { align-self: flex-start; }
.profile-chat__speaker {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.profile-chat__message p:last-child {
  margin: 0;
  color: inherit;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.profile-chat__form {
  padding: 14px 16px 11px;
  border-top: 1px solid #2c2d35;
  background: #191a21;
}
.profile-chat__input-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.profile-chat__composer {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 48px;
  padding: 5px 6px 5px 14px;
  border: 1px solid #393a44;
  border-radius: 8px;
  background: #111218;
}
.profile-chat__composer:focus-within { border-color: #e27673; }
.profile-chat__input {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  height: 24px;
  max-height: 84px;
  padding: 1px 0;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--profile-text);
  font: 13px/1.55 var(--font-body, sans-serif);
}
.profile-chat__input::placeholder { color: #a4a4ae; opacity: 1; }
.profile-chat__input:disabled { opacity: .55; cursor: not-allowed; }
.profile-chat__submit {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 0;
  border-radius: 7px;
  background: var(--profile-accent);
  color: #fff;
  cursor: pointer;
}
.profile-chat__submit:hover { background: var(--profile-accent-hover); }
.profile-chat__submit:disabled { opacity: .5; cursor: not-allowed; }
.profile-chat__send-icon { display: block; font-size: 18px; line-height: 1; transform: rotate(-35deg); }
.profile-chat__status {
  display: block;
  min-height: 0;
  color: #d0a9ab;
  font-size: 11px;
  line-height: 1.4;
}
.profile-chat__status:not(:empty) { margin-top: 7px; }
.profile-chat__status[data-state="error"] { color: #ff9292; }
.profile-chat__note {
  margin: 10px 0 0;
  color: var(--profile-muted);
  font-size: 10px;
  line-height: 1.4;
  text-align: center;
}
.profile-chat-open:focus-visible,
.profile-chat button:focus-visible {
  outline: 2px solid #ffaaa7;
  outline-offset: 2px;
}

@media (max-width: 42rem) {
  .profile-chat-open {
    right: 16px;
    bottom: 16px;
    min-height: 46px;
    width: 46px;
    padding: 0;
    justify-content: center;
  }
  .profile-chat-open > span:last-child { display: none; }
  .profile-chat {
    right: 12px;
    bottom: 12px;
    width: min(360px, calc(100vw - 24px));
    height: min(560px, calc(100dvh - 24px));
  }
  .profile-chat__body { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .profile-chat-open { transition: none; }
  .profile-chat__typing i { animation: none; }
}
