/* AI 智能问答浮动窗口样式
   配色沿用 orchid-theme.css；按钮图片是站点线稿 logo（白色，透明底） */

/* ---------- 容器：位置由 JS 控制（可拖动 + 左右吸附） ---------- */
.ai-chat {
  position: fixed;
  left: 0;
  top: 0;
  width: 56px;
  height: 56px;
  /* 页头 .navbar 是 z-index:1000，这里必须更高，否则滚动到顶部时对话框会被页头盖住；
     导航下拉菜单是 1200，保持在他们下面 */
  z-index: 1100;
  font-family: inherit;
}

.ai-chat[hidden] {
  display: none;
}

.ai-chat.is-animating {
  transition: left 0.28s cubic-bezier(0.22, 0.7, 0.28, 1),
    top 0.28s cubic-bezier(0.22, 0.7, 0.28, 1);
}

/* ---------- 圆形悬浮按钮 ---------- */
.ai-chat-launcher {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  background: radial-gradient(circle at 30% 24%, #d2608f, #a02a58 58%, #7d1a40);
  box-shadow: 0 12px 28px rgba(91, 15, 50, 0.3);
  cursor: grab;
  touch-action: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.ai-chat:not(.is-dragging) .ai-chat-launcher:hover,
.ai-chat:not(.is-dragging) .ai-chat-launcher:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 16px 32px rgba(91, 15, 50, 0.34);
  outline: none;
}

.ai-chat.is-dragging .ai-chat-launcher {
  cursor: grabbing;
  transform: scale(1.05);
  box-shadow: 0 20px 38px rgba(91, 15, 50, 0.38);
}

.ai-chat-launcher-logo {
  width: 74%;
  height: 74%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* 右下角的小徽标：让"这是 AI 问答"一眼能看出来 */
.ai-chat-launcher-badge {
  position: absolute;
  right: -3px;
  bottom: -3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 23px;
  height: 23px;
  padding: 0 5px;
  border: 1.5px solid #ffffff;
  border-radius: 999px;
  background: linear-gradient(145deg, #ffffff, #ffe9f2);
  color: #8f2248;
  font-size: 0.6rem;
  font-weight: 900;
  letter-spacing: 0.02em;
  box-shadow: 0 3px 8px rgba(91, 15, 50, 0.28);
  pointer-events: none;
}

/* ---------- 对话框（位置和大小由 JS 计算，始终贴着按钮） ---------- */
.ai-chat-panel {
  position: fixed;
  display: flex;
  flex-direction: column;
  border: 1px solid #f0d9e3;
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 24px 60px rgba(91, 15, 50, 0.24);
  overflow: hidden;
}

.ai-chat-panel[hidden] {
  display: none;
}

.ai-chat-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #8f2248, #c4477f);
  color: #ffffff;
  overflow: hidden;
}

/* 标题栏右侧的 logo 水印 */
.ai-chat-header-mark {
  position: absolute;
  right: 46px;
  top: 50%;
  width: 76px;
  height: 76px;
  transform: translateY(-50%);
  opacity: 0.18;
  pointer-events: none;
}

.ai-chat-header-text {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ai-chat-header-text strong {
  font-size: 0.98rem;
  font-weight: 700;
}

.ai-chat-header-text small {
  font-size: 0.72rem;
  opacity: 0.85;
}

.ai-chat-close {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  cursor: pointer;
}

.ai-chat-close:hover,
.ai-chat-close:focus-visible {
  background: rgba(255, 255, 255, 0.28);
  outline: none;
}

.ai-chat-close svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* ---------- 对话区：用 logo 做底纹（居中） ---------- */
.ai-chat-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 14px;
  overflow-y: auto;
  background-color: #fffafd;
  background-image: url("ai-chat-watermark.png");
  background-repeat: no-repeat;
  background-position: center center;
  background-size: 240px 240px;
}

.ai-chat-bubble {
  position: relative;
  max-width: 84%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-chat-bubble--bot {
  align-self: flex-start;
  border: 1px solid #f0d9e3;
  border-top-left-radius: 4px;
  background: rgba(255, 255, 255, 0.94);
  color: #3c2630;
  box-shadow: 0 4px 12px rgba(122, 42, 76, 0.06);
  /* Bot replies are rendered as safe Markdown blocks; user/error bubbles
     keep the original pre-wrap behavior. */
  white-space: normal;
}

.ai-chat-bubble--bot p {
  margin: 0 0 0.55em;
}

.ai-chat-bubble--bot p:last-child {
  margin-bottom: 0;
}

.ai-chat-bubble--bot strong {
  font-weight: 700;
  color: #5c1b36;
}

.ai-chat-bubble--bot em {
  font-style: italic;
}

.ai-chat-bubble--bot code {
  padding: 0.08em 0.32em;
  border: 1px solid #efd7e2;
  border-radius: 4px;
  background: #fff7fa;
  color: #8f2248;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.86em;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.ai-chat-bubble--bot ul,
.ai-chat-bubble--bot ol {
  margin: 0.2em 0 0.6em;
  padding-left: 1.35em;
}

.ai-chat-bubble--bot ul {
  list-style: disc;
}

.ai-chat-bubble--bot ol {
  list-style: decimal;
}

.ai-chat-bubble--bot li {
  margin: 0.18em 0;
  padding-left: 0.1em;
}

.ai-chat-bubble--bot li::marker {
  color: #b24a78;
}

.ai-chat-bubble--user {
  align-self: flex-end;
  border-top-right-radius: 4px;
  background: linear-gradient(145deg, #c4477f, #8f2248);
  color: #ffffff;
}

.ai-chat-bubble--error {
  align-self: flex-start;
  border: 1px solid #f3c2cc;
  border-top-left-radius: 4px;
  background: #fff2f4;
  color: #a3182f;
}

/* ---------- 回答来源（RAG citations） ---------- */
.ai-chat-sources {
  margin-top: 9px;
  padding-top: 7px;
  border-top: 1px dashed #efd3df;
  color: #5c3a48;
  font-size: 0.76rem;
  line-height: 1.45;
  white-space: normal;
}

.ai-chat-sources summary {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #8f2248;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.ai-chat-sources summary::-webkit-details-marker {
  display: none;
}

.ai-chat-sources summary::before {
  content: "▸";
  display: inline-block;
  width: 0.8em;
  color: #c4477f;
  transition: transform 0.15s ease;
}

.ai-chat-sources[open] summary::before {
  transform: rotate(90deg);
}

.ai-chat-source-list {
  display: grid;
  gap: 6px;
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.ai-chat-source-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
}

.ai-chat-source-type {
  flex: 0 0 auto;
  margin-top: 1px;
  padding: 1px 6px;
  border: 1px solid #f0d0dd;
  border-radius: 999px;
  background: #fff6fa;
  color: #a02a58;
  font-size: 0.62rem;
  line-height: 1.4;
  text-transform: lowercase;
}

.ai-chat-source-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.ai-chat-source-link {
  color: #7d1a40;
  text-decoration: none;
  border-bottom: 1px solid rgba(196, 71, 127, 0.35);
  word-break: break-word;
}

.ai-chat-source-link:hover,
.ai-chat-source-link:focus-visible {
  color: #c4477f;
  border-bottom-color: #c4477f;
  outline: none;
}

.ai-chat-source-label {
  color: #8a7680;
  font-size: 0.68rem;
}

.ai-chat-source-note {
  display: block;
  margin-top: 6px;
  color: #9a7585;
  font-size: 0.66rem;
  line-height: 1.4;
}

@media (max-width: 576px) {
  .ai-chat-sources {
    font-size: 0.72rem;
  }

  .ai-chat-source-item {
    gap: 4px;
  }

  .ai-chat-bubble--bot ul,
  .ai-chat-bubble--bot ol {
    padding-left: 1.15em;
  }

  .ai-chat-bubble--bot code {
    overflow-wrap: anywhere;
  }
}

.ai-chat-typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid #f0d9e3;
  border-radius: 14px;
  border-top-left-radius: 4px;
  background: rgba(255, 255, 255, 0.94);
}

.ai-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #c4477f;
  opacity: 0.35;
  animation: ai-chat-blink 1.2s infinite ease-in-out;
}

.ai-chat-typing span:nth-child(2) {
  animation-delay: 0.18s;
}

.ai-chat-typing span:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes ai-chat-blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

/* ---------- 输入区 ---------- */
.ai-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid #f6e6ed;
  background: #ffffff;
}

.ai-chat-input {
  flex: 1 1 auto;
  max-height: 96px;
  min-height: 40px;
  padding: 10px 12px;
  border: 1px solid #dfc5d0;
  border-radius: 12px;
  background: #ffffff;
  color: #3c2630;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: none;
  outline: 0;
}

.ai-chat-input:focus {
  border-color: #c4477f;
  box-shadow: 0 0 0 3px rgba(196, 71, 127, 0.12);
}

/* 示例文字淡一点，不要和真正输入的内容混淆 */
.ai-chat-input::placeholder {
  color: #c6b3bc;
  opacity: 1;
}

.ai-chat-input::-webkit-input-placeholder {
  color: #c6b3bc;
  opacity: 1;
}

.ai-chat-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(145deg, #c4477f, #8f2248);
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.16s ease;
}

.ai-chat-send:hover:not(:disabled),
.ai-chat-send:focus-visible:not(:disabled) {
  filter: brightness(1.06);
  outline: none;
}

.ai-chat-send:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.ai-chat-send-spinner {
  display: none;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: ai-chat-spin 0.7s linear infinite;
}

.ai-chat.is-busy .ai-chat-send-text {
  display: none;
}

.ai-chat.is-busy .ai-chat-send-spinner {
  display: inline-block;
}

@keyframes ai-chat-spin {
  to {
    transform: rotate(360deg);
  }
}

/* 只显示字数统计，没有内容时整行隐藏 */
.ai-chat-hint {
  margin: 0;
  padding: 0 14px 10px;
  background: #ffffff;
  color: #8a7680;
  font-size: 0.72rem;
  line-height: 1.5;
}

.ai-chat-hint:empty {
  display: none;
}

/* ---------- 窄屏 ---------- */
@media (max-width: 576px) {
  .ai-chat-header-mark {
    right: 40px;
    width: 62px;
    height: 62px;
  }

  .ai-chat-body {
    background-size: 200px 200px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chat,
  .ai-chat-launcher,
  .ai-chat-typing span,
  .ai-chat-send-spinner {
    transition: none;
    animation: none;
  }
}
