@media (max-width: 520px) {
  #xs-copilot-root {
    right: 10px;
    left: auto;
    bottom: 10px;
  }

  #xs-copilot-panel {
    max-width: calc(100vw - 20px);
    max-height: calc(100dvh - 72px);
  }
}

#xs-copilot-root {
  --xs-accent: #3d8bfd;
  --xs-accent2: #7c3aed;
  --xs-bg: #141c28;
  --xs-card: #1a2332;
  --xs-text: #e7ecf3;
  --xs-muted: #8b9cb3;
  --xs-border: rgba(255, 255, 255, 0.1);
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}

#xs-copilot-root.xs-positioned {
  right: auto;
  bottom: auto;
}

#xs-copilot-root.xs-dragging {
  z-index: 10000;
}

#xs-copilot-fab {
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  background: transparent;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s, box-shadow 0.2s;
}

#xs-copilot-fab .xs-fab-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  border-radius: 50%;
  display: block;
  pointer-events: none;
}

#xs-copilot-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

#xs-copilot-panel {
  display: none;
  flex-direction: column;
  position: relative;
  width: 380px;
  height: 520px;
  min-width: 300px;
  min-height: 320px;
  max-width: min(720px, calc(100vw - 24px));
  max-height: calc(100vh - 72px);
  margin-bottom: 12px;
  border-radius: 16px;
  border: 1px solid var(--xs-border);
  background: var(--xs-bg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

#xs-copilot-panel.xs-resizing {
  border-color: rgba(61, 139, 253, 0.45);
  box-shadow: 0 20px 50px rgba(61, 139, 253, 0.18);
}

.xs-copilot-resize-edges {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.xs-resize-handle {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
}

.xs-resize-t {
  top: 0;
  left: 8px;
  right: 40px;
  height: 8px;
  cursor: ns-resize;
}

.xs-resize-l {
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 8px;
  cursor: ew-resize;
}

.xs-resize-br {
  right: 0;
  bottom: 0;
  width: 22px;
  height: 22px;
  cursor: nwse-resize;
  border-bottom-right-radius: 16px;
  background: linear-gradient(
    135deg,
    transparent 0 42%,
    rgba(61, 139, 253, 0.35) 42% 48%,
    transparent 48% 58%,
    rgba(61, 139, 253, 0.55) 58% 64%,
    transparent 64%
  );
}

.xs-resize-br::after {
  content: "";
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 8px;
  height: 8px;
  border-right: 2px solid rgba(147, 197, 253, 0.85);
  border-bottom: 2px solid rgba(147, 197, 253, 0.85);
  border-bottom-right-radius: 2px;
}

#xs-copilot-root.open #xs-copilot-panel {
  display: flex;
}

#xs-copilot-root.open #xs-copilot-fab {
  width: 44px;
  height: 44px;
}

.xs-copilot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--xs-border);
  background: rgba(61, 139, 253, 0.08);
  cursor: move;
  touch-action: none;
  user-select: none;
}

#xs-copilot-root.xs-dragging .xs-copilot-head {
  cursor: grabbing;
}

#xs-copilot-root:not(.open) #xs-copilot-fab {
  cursor: grab;
  touch-action: none;
}

#xs-copilot-root.xs-dragging #xs-copilot-fab {
  cursor: grabbing;
}

.xs-copilot-head h3 {
  margin: 0;
  font-size: 14px;
  color: var(--xs-text);
}

.xs-copilot-head p {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--xs-muted);
}

.xs-copilot-close {
  border: none;
  background: rgba(255, 255, 255, 0.06);
  color: var(--xs-muted);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
}

.xs-copilot-context {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--xs-muted);
  border-bottom: 1px dashed var(--xs-border);
}

.xs-copilot-context strong {
  color: #93c5fd;
}

.xs-copilot-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.xs-copilot-msg {
  max-width: 92%;
  padding: 9px 11px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
}

.xs-copilot-msg.bot {
  align-self: flex-start;
  background: var(--xs-card);
  border: 1px solid var(--xs-border);
  color: var(--xs-text);
}

.xs-copilot-msg.user {
  align-self: flex-end;
  background: rgba(61, 139, 253, 0.22);
  border: 1px solid rgba(61, 139, 253, 0.35);
  color: #dbeafe;
}

.xs-copilot-msg .xs-pill {
  display: inline-block;
  margin: 0 4px 4px 0;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: rgba(61, 139, 253, 0.15);
  color: #93c5fd;
}

.xs-copilot-msg .xs-pill.good {
  background: rgba(61, 214, 140, 0.15);
  color: #86efac;
}

.xs-copilot-msg .xs-pill.risk {
  background: rgba(248, 113, 113, 0.12);
  color: #fca5a5;
}

.xs-copilot-msg .xs-title {
  font-weight: 700;
  color: #93c5fd;
  margin-bottom: 6px;
  font-size: 12px;
}

.xs-copilot-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 8px;
}

.xs-copilot-quick button {
  border: 1px solid var(--xs-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--xs-muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
}

.xs-copilot-quick button:hover {
  color: var(--xs-text);
  border-color: rgba(61, 139, 253, 0.4);
}

.xs-copilot-input {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--xs-border);
  align-items: center;
}

.xs-copilot-voice {
  border: 1px solid var(--xs-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--xs-text);
  border-radius: 10px;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  font-size: 18px;
}

.xs-copilot-voice.listening,
.xs-copilot-voice.holding {
  background: rgba(248, 113, 113, 0.2);
  border-color: rgba(248, 113, 113, 0.4);
  animation: xs-pulse 1s infinite;
}

.xs-copilot-voice.holding {
  transform: scale(1.06);
}

@keyframes xs-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.xs-copilot-input input {
  flex: 1;
  border: 1px solid var(--xs-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--xs-text);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
}

.xs-copilot-input button {
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  background: var(--xs-accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
  touch-action: manipulation;
}

.xs-voice-status {
  margin: 0 12px 6px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--xs-muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--xs-border);
  min-height: 20px;
}

.xs-voice-alt-row {
  padding: 0 12px 10px;
  display: flex;
  gap: 8px;
}

.xs-voice-file-btn {
  flex: 1;
  border: 1px dashed rgba(61, 139, 253, 0.45);
  background: rgba(61, 139, 253, 0.1);
  color: #93c5fd;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  cursor: pointer;
  touch-action: manipulation;
}

#xs-voice-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.xs-voice-status.listening {
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.08);
}

.xs-voice-status.ok {
  color: #86efac;
  border-color: rgba(61, 214, 140, 0.35);
  background: rgba(61, 214, 140, 0.08);
}

.xs-voice-status.error {
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.1);
}

.xs-copilot-muted {
  font-size: 11px;
  color: var(--xs-muted);
  margin-top: 6px;
}

.xs-glossary p {
  margin: 6px 0;
  font-size: 13px;
  line-height: 1.55;
}

.xs-gloss-formula,
.xs-gloss-usage,
.xs-gloss-ctx {
  font-size: 12px;
  color: var(--xs-muted);
}

.xs-gloss-ctx strong {
  color: #93c5fd;
}

.xs-rules ul {
  margin: 8px 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.55;
}

.xs-rules li {
  margin: 4px 0;
}

.xs-rules .xs-muted {
  font-size: 12px;
  color: var(--xs-muted);
}

.xs-open-account-form label {
  display: block;
  font-size: 12px;
  color: var(--xs-muted);
  margin: 8px 0 4px;
}
.xs-open-account-form .xs-req { color: #f87171; }
.xs-open-account-form input,
.xs-open-account-form select {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--xs-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--xs-text);
  font-size: 14px;
}
.xs-oa-submit {
  margin-top: 12px;
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #3d8bfd, #6366f1);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}
.xs-oa-submit:disabled { opacity: 0.6; cursor: not-allowed; }
.xs-title { font-weight: 600; margin-bottom: 6px; color: #93c5fd; }

.xs-ftick-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 8px 0;
}
.xs-ftick-table th,
.xs-ftick-table td {
  border-bottom: 1px solid var(--xs-border);
  padding: 4px 6px;
  text-align: right;
  white-space: nowrap;
}
.xs-ftick-table th:first-child,
.xs-ftick-table td:first-child {
  text-align: left;
}

@media (max-width: 480px) {
  #xs-copilot-root {
    right: 12px;
    bottom: 12px;
  }
}
