/* Global floating trigger */
.xm-float-chat-trigger {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #2b7cee 0%, #0ea5e9 100%);
  color: #fff;
  box-shadow: 0 10px 24px rgba(43, 124, 238, 0.35);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1200;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  touch-action: none;
  user-select: none;
}

.xm-float-chat-trigger.is-dragging {
  cursor: grabbing;
  transform: none;
}

.xm-float-chat-trigger:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 16px 30px rgba(43, 124, 238, 0.42);
}

.xm-float-chat-trigger:active {
  transform: translateY(0);
}

.xm-float-chat-trigger-icon {
  font-size: 24px;
  line-height: 1;
}

.xm-float-chat-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 1190;
}

.xm-float-chat-mask.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.xm-float-chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 100vw);
  height: 100vh;
  background: #ffffff;
  border-left: 1px solid #e5e7eb;
  box-shadow: -10px 0 30px rgba(15, 23, 42, 0.18);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 1201;
  display: flex;
  flex-direction: column;
}

.xm-float-chat-panel.is-open {
  transform: translateX(0);
}

.xm-float-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px;
  border-bottom: 1px solid #e5e7eb;
  background: #f8fbff;
}

.xm-float-chat-title-wrap {
  min-width: 0;
}

.xm-float-chat-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
}

.xm-float-chat-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: #64748b;
}

.xm-float-chat-model {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  color: #1f2937;
  background: #fff;
  max-width: 145px;
}

.xm-float-chat-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: #eef2f7;
  color: #1f2937;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.xm-float-chat-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f9fbff 100%);
}

.xm-float-chat-row {
  display: flex;
  margin-bottom: 10px;
}

.xm-float-chat-row.user {
  justify-content: flex-end;
}

.xm-float-chat-row.assistant {
  justify-content: flex-start;
}

.xm-float-chat-bubble {
  max-width: 86%;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

/* 悬浮窗内 Markdown 样式隔离：避免被试题页、收藏页、社区页的全局 CSS 污染。 */
.xm-float-chat-bubble p {
  margin: 0 0 0.6em;
  line-height: 1.65;
}

.xm-float-chat-bubble p:last-child {
  margin-bottom: 0;
}

.xm-float-chat-bubble h1,
.xm-float-chat-bubble h2,
.xm-float-chat-bubble h3,
.xm-float-chat-bubble h4,
.xm-float-chat-bubble h5,
.xm-float-chat-bubble h6 {
  margin: 0.7em 0 0.45em;
  line-height: 1.25;
  font-weight: 700;
  color: #0f172a;
}

.xm-float-chat-bubble h1 { font-size: 1.12em; }
.xm-float-chat-bubble h2 { font-size: 1.06em; }
.xm-float-chat-bubble h3 { font-size: 1.0em; }
.xm-float-chat-bubble h4,
.xm-float-chat-bubble h5,
.xm-float-chat-bubble h6 { font-size: 0.96em; }

.xm-float-chat-bubble ul,
.xm-float-chat-bubble ol {
  margin: 0.45em 0 0.65em;
  padding-left: 1.2em;
}

.xm-float-chat-bubble li {
  margin: 0.18em 0;
  line-height: 1.6;
}

.xm-float-chat-bubble blockquote {
  margin: 0.55em 0;
  padding: 0.45em 0.75em;
  border-left: 3px solid #cbd5e1;
  background: #f8fafc;
  color: #475569;
  border-radius: 8px;
}

.xm-float-chat-bubble pre {
  margin: 0.55em 0;
  padding: 10px 12px;
  overflow: auto;
  border-radius: 10px;
  background: #0f172a;
  color: #e2e8f0;
  white-space: pre-wrap;
  word-break: break-word;
}

.xm-float-chat-bubble pre code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 0.92em;
}

.xm-float-chat-bubble code {
  padding: 0.12em 0.35em;
  border-radius: 6px;
  background: #f1f5f9;
  color: #c026d3;
  font-size: 0.92em;
  word-break: break-word;
}

.xm-float-chat-bubble hr {
  border: 0;
  height: 1px;
  margin: 0.7em 0;
  background: #e5e7eb;
  opacity: 0.45;
}

.xm-float-chat-bubble a {
  color: #2563eb;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.xm-float-chat-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6em 0;
  font-size: 0.94em;
}

.xm-float-chat-bubble th,
.xm-float-chat-bubble td {
  border: 1px solid #e2e8f0;
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.xm-float-chat-bubble th {
  background: #f8fafc;
  font-weight: 700;
}

.xm-float-chat-bubble mjx-container {
  margin: 0.15em 0 !important;
  overflow-x: auto;
  max-width: 100%;
}

.xm-float-chat-bubble mjx-container[display="true"] {
  display: block !important;
  margin: 0.5em 0 !important;
  text-align: center;
}

.xm-float-chat-bubble mjx-container[display="true"] > mjx-assistive-mml {
  display: block;
}

.xm-float-chat-bubble mjx-container mjx-math {
  font-size: 1em;
}

.xm-float-chat-bubble img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.xm-float-chat-row.user .xm-float-chat-bubble {
  background: #2b7cee;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.xm-float-chat-row.assistant .xm-float-chat-bubble {
  background: #fff;
  color: #0f172a;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

.xm-float-chat-thinking {
  font-size: 12px;
  color: #64748b;
  padding: 8px 10px;
  background: #f1f5f9;
  border-radius: 10px;
  border: 1px dashed #cbd5e1;
  margin-top: 6px;
}

.xm-float-chat-composer {
  border-top: 1px solid #e5e7eb;
  background: #fff;
  padding: 10px;
}

.xm-float-chat-input {
  width: 100%;
  min-height: 72px;
  max-height: 140px;
  resize: vertical;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  color: #0f172a;
  outline: none;
}

.xm-float-chat-input:focus {
  border-color: #2b7cee;
  box-shadow: 0 0 0 3px rgba(43, 124, 238, 0.12);
}

.xm-float-chat-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.xm-float-chat-status {
  font-size: 12px;
  color: #64748b;
}

.xm-float-chat-send {
  border: none;
  border-radius: 10px;
  background: #2b7cee;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
}

.xm-float-chat-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

@media (max-width: 768px) {
  .xm-float-chat-trigger {
    right: 14px;
    bottom: 14px;
    width: 54px;
    height: 54px;
  }

  .xm-float-chat-panel {
    width: 100vw;
  }
}
