/* 全站右侧悬浮 AI 问答 */
.ai-float-trigger {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 46px;
  padding: 14px 8px;
  border: none;
  border-radius: 14px 0 0 14px;
  cursor: pointer;
  background: linear-gradient(180deg, #ff8a00, #ff5e8a);
  color: #fff;
  box-shadow: -4px 4px 20px rgba(255, 94, 138, .35);
  transition: width .2s ease, padding .2s ease;
}
.ai-float-trigger:hover { width: 52px; }
.ai-float-trigger.hidden { display: none; }
.ai-float-icon { font-size: 22px; line-height: 1; }
.ai-float-text {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
}

.ai-float-panel {
  position: fixed;
  top: 56px;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  z-index: 130;
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: -8px 0 32px rgba(15, 23, 42, .12);
  border-left: 1px solid #eef2f7;
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.4, 0, .2, 1);
}
.ai-float-panel.open { transform: translateX(0); }

.ai-float-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid #eef2f7;
  background: linear-gradient(180deg, #fffdf7, #fff);
}
.ai-float-head-title { font-size: 15px; font-weight: 800; margin: 0; }
.ai-float-head-actions { display: flex; gap: 6px; align-items: center; }
.ai-float-head-btn {
  padding: 5px 10px; border-radius: 8px; border: none; cursor: pointer; font-size: 12px; font-weight: 600;
}
.ai-float-btn-new { background: #fff8ec; color: #ff8a00; }
.ai-float-btn-expand {
  background: #f0f9ff; color: #0284c7; width: 32px; height: 32px; padding: 0;
  border-radius: 8px; font-size: 16px; line-height: 1;
}
.ai-float-btn-login { background: linear-gradient(135deg, #ff8a00, #ff5e8a); color: #fff; }
.ai-float-btn-close { background: #f1f5f9; color: #64748b; width: 32px; height: 32px; padding: 0; border-radius: 8px; font-size: 18px; line-height: 1; }

.ai-float-login-err { font-size: 13px; color: #dc2626; min-height: 20px; margin: 8px 0 0; padding: 6px 10px; text-align: center; line-height: 1.4; background: #fef2f2; border-radius: 8px; }
.ai-float-login-err:empty { display: none; padding: 0; margin: 0; min-height: 0; background: none; }

.ai-float-gate {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  background: linear-gradient(180deg, #fffdf7 0%, #fff 100%);
}
.ai-float-gate-inner {
  width: 100%;
  max-width: 320px;
  text-align: center;
}
.ai-float-gate-icon { font-size: 36px; margin-bottom: 12px; }
.ai-float-gate-inner h3 { margin: 0 0 10px; font-size: 1.05rem; color: #1f2937; }
.ai-float-gate-inner > p { margin: 0 0 20px; font-size: 13px; line-height: 1.6; color: #64748b; }
.ai-float-gate-label {
  display: block; text-align: left; font-size: 13px; font-weight: 600; color: #334155; margin-bottom: 12px;
}
.ai-float-gate-label input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid #e2e8f0;
  border-radius: 10px; font-size: 15px; box-sizing: border-box;
}
.ai-float-login-form { margin: 0; }
.ai-float-gate-submit {
  width: 100%; margin-top: 4px; padding: 12px; border: none; border-radius: 12px; cursor: pointer;
  background: linear-gradient(135deg, #ff8a00, #ff5e8a); color: #fff; font-weight: 700; font-size: 15px;
}
.ai-float-gate-submit:disabled { opacity: .55; cursor: not-allowed; }

.ai-float-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.ai-float-btn-logout { background: #f1f5f9; color: #64748b; }

.ai-float-login-bar {
  padding: 10px 14px;
  border-bottom: 1px solid #eef2f7;
  background: #fff8ec;
  display: flex;
  gap: 8px;
  align-items: center;
}
.ai-float-login-bar input {
  flex: 1; padding: 8px 10px; border: 1px solid #fde68a; border-radius: 8px; font-size: 14px;
}
.ai-float-login-bar button {
  padding: 8px 12px; border: none; border-radius: 8px; background: #ff8a00; color: #fff;
  font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.ai-float-login-err { font-size: 12px; color: #ef4444; padding: 0 14px 8px; }

.ai-float-quota { font-size: 11px; color: #94a3b8; padding: 0 14px 6px; }

.ai-float-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(180deg, #fffdf7 0%, #fff 100%);
}
.ai-float-welcome { text-align: center; color: #64748b; padding: 24px 12px; margin: auto; }
.ai-float-welcome h3 { color: #1f2937; font-size: 1rem; margin: 0 0 8px; }
.ai-float-welcome p { font-size: 13px; line-height: 1.55; margin: 0; }
.ai-float-suggestions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 12px; }
.ai-float-suggestions button {
  padding: 6px 12px; border-radius: 999px; border: 1px solid #fde68a; background: #fff;
  color: #ff8a00; font-size: 12px; cursor: pointer;
}

.ai-float-msg { max-width: 92%; display: flex; flex-direction: column; gap: 6px; }
.ai-float-msg.user { align-self: flex-end; align-items: flex-end; }
.ai-float-msg.assistant { align-self: flex-start; }
.ai-float-bubble {
  padding: 10px 14px; border-radius: 12px; font-size: 13px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
.ai-float-msg.user .ai-float-bubble {
  background: linear-gradient(135deg, #ff8a00, #ff5e8a); color: #fff; border-bottom-right-radius: 4px;
}
.ai-float-msg.assistant .ai-float-bubble {
  background: #fff; border: 1px solid #eef2f7; border-bottom-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(15,23,42,.04);
}
.ai-float-citations { display: flex; flex-direction: column; gap: 5px; max-width: 100%; }
.ai-float-cite {
  display: block; padding: 8px 10px; border-radius: 8px; background: #f8fafc; border: 1px solid #e2e8f0;
  text-decoration: none; color: inherit; font-size: 11px;
}
.ai-float-cite:hover { border-color: #ff8a00; }
.ai-float-cite-num {
  display: inline-block; min-width: 16px; height: 16px; line-height: 16px; text-align: center;
  background: #ff8a00; color: #fff; border-radius: 3px; font-size: 10px; font-weight: 700; margin-right: 4px;
}
.ai-float-cite-title { font-weight: 700; color: #1e293b; }
.ai-float-cite-meta { color: #94a3b8; margin-top: 2px; }

.ai-float-typing { min-height: 18px; font-size: 12px; color: #94a3b8; padding: 0 14px; }

.ai-float-input-wrap {
  flex-shrink: 0;
  padding: 12px 14px;
  border-top: 1px solid #eef2f7;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: #fff;
}
.ai-float-input-wrap textarea {
  flex: 1; min-height: 40px; max-height: 100px; padding: 8px 12px; border: 1px solid #e2e8f0;
  border-radius: 10px; resize: none; font-size: 13px; font-family: inherit; line-height: 1.45;
}
.ai-float-send {
  padding: 10px 16px; border: none; border-radius: 10px; cursor: pointer; font-weight: 700; font-size: 13px;
  background: linear-gradient(135deg, #ff8a00, #ff5e8a); color: #fff;
}
.ai-float-send:disabled { opacity: .45; cursor: not-allowed; }

/* 全屏阅读 */
.ai-float-backdrop {
  position: fixed; inset: 0; z-index: 125;
  background: rgba(15, 23, 42, .52);
  backdrop-filter: blur(4px);
  opacity: 0; visibility: hidden;
  transition: opacity .25s ease, visibility .25s ease;
}
.ai-float-backdrop.show { opacity: 1; visibility: visible; }
body.ai-float-fs-lock { overflow: hidden; }

.ai-float-panel.ai-float-mode-fullscreen {
  top: 50%; left: 50%; right: auto; bottom: auto;
  transform: translate(-50%, -50%);
  width: min(960px, 96vw);
  height: min(92vh, 880px);
  max-height: 92vh;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .22);
  z-index: 140;
}
.ai-float-panel.ai-float-mode-fullscreen.open {
  transform: translate(-50%, -50%);
}
.ai-float-panel.ai-float-mode-fullscreen .ai-float-head {
  padding: 14px 18px;
  border-radius: 16px 16px 0 0;
}
.ai-float-panel.ai-float-mode-fullscreen .ai-float-messages {
  padding: 18px 20px;
}
.ai-float-panel.ai-float-mode-fullscreen .ai-float-msg { max-width: 88%; }
.ai-float-panel.ai-float-mode-fullscreen .ai-float-bubble {
  font-size: 14px;
  padding: 14px 16px;
}
.ai-float-panel.ai-float-mode-fullscreen .ai-float-input-wrap {
  padding: 14px 18px 18px;
  border-radius: 0 0 16px 16px;
}
.ai-float-panel.ai-float-mode-fullscreen .ai-float-input-wrap textarea {
  min-height: 48px; max-height: 140px; font-size: 14px;
}

/* Markdown 排版 */
.ai-float-bubble.ai-md-body { white-space: normal; }
.ai-md-body .ai-md-p {
  margin: 0 0 10px; line-height: 1.72; color: #334155;
}
.ai-md-body .ai-md-p:last-child { margin-bottom: 0; }
.ai-md-body .ai-md-h2,
.ai-md-body .ai-md-h3,
.ai-md-body .ai-md-h4 {
  margin: 14px 0 8px; font-weight: 800; color: #0f172a; line-height: 1.35;
}
.ai-md-body .ai-md-h2 { font-size: 1.05rem; padding-bottom: 6px; border-bottom: 2px solid #ffedd5; }
.ai-md-body .ai-md-h3 { font-size: .98rem; color: #c2410c; }
.ai-md-body .ai-md-h4 { font-size: .92rem; color: #475569; }
.ai-md-body .ai-md-h2:first-child,
.ai-md-body .ai-md-h3:first-child { margin-top: 0; }
.ai-md-body .ai-md-ul,
.ai-md-body .ai-md-ol {
  margin: 6px 0 12px; padding-left: 1.35em; line-height: 1.68; color: #334155;
}
.ai-md-body .ai-md-ul li,
.ai-md-body .ai-md-ol li { margin-bottom: 6px; }
.ai-md-body .ai-md-ul li::marker { color: #ff8a00; }
.ai-md-body .ai-md-ol li::marker { color: #ff8a00; font-weight: 700; }
.ai-md-body strong { color: #0f172a; font-weight: 700; }
.ai-md-body .ai-md-code-inline {
  padding: 2px 6px; border-radius: 4px; background: #f1f5f9;
  font-family: ui-monospace, Consolas, monospace; font-size: .88em; color: #be185d;
}
.ai-md-body .ai-md-ref {
  display: inline-block; margin: 0 1px; padding: 0 4px;
  border-radius: 4px; background: #fff7ed; color: #ea580c;
  font-size: .78em; font-weight: 700; vertical-align: super; line-height: 1.2;
}
.ai-md-body .ai-md-hr {
  border: none; border-top: 1px dashed #e2e8f0; margin: 12px 0;
}

.ai-float-msg.assistant .ai-float-citations {
  margin-top: 4px; padding-top: 8px; border-top: 1px solid #f1f5f9;
}
.ai-float-cite {
  display: block; padding: 10px 12px; border-radius: 10px;
  background: linear-gradient(180deg, #fff, #f8fafc);
  border: 1px solid #e2e8f0; transition: border-color .15s, box-shadow .15s;
}
.ai-float-cite:hover {
  border-color: #fdba74; box-shadow: 0 2px 8px rgba(255, 138, 0, .12);
}

@media (max-width: 480px) {
  .ai-float-panel { top: 0; width: 100vw; }
  .ai-float-panel.ai-float-mode-fullscreen {
    top: 0; left: 0; transform: none;
    width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0;
  }
  .ai-float-panel.ai-float-mode-fullscreen.open { transform: none; }
  .ai-float-trigger { top: auto; bottom: 80px; transform: none; border-radius: 14px 0 0 14px; }
}

/* 登录弹窗（ai-auth-modal 复用） */
.ai-auth-modal { position: fixed; inset: 0; z-index: 200; display: none; align-items: center; justify-content: center; padding: 16px; }
.ai-auth-modal.show { display: flex; }
.ai-auth-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); }
.ai-auth-panel {
  position: relative; width: min(400px, 100%); background: #fff; border-radius: 16px;
  padding: 28px 24px 24px; box-shadow: 0 20px 50px rgba(15, 23, 42, .18);
}
.ai-auth-close { position: absolute; right: 12px; top: 10px; border: none; background: none; font-size: 24px; cursor: pointer; color: #94a3b8; }
.ai-auth-panel h2 { margin: 0 0 8px; font-size: 1.25rem; }
.ai-auth-sub { margin: 0 0 20px; color: #64748b; font-size: 13px; line-height: 1.5; }
.ai-auth-label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: #334155; }
.ai-auth-label input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid #e2e8f0;
  border-radius: 10px; font-size: 15px; box-sizing: border-box;
}
.ai-auth-err { min-height: 20px; margin: 0 0 8px; color: #ef4444; font-size: 13px; }
.ai-auth-submit {
  width: 100%; padding: 12px; border: none; border-radius: 12px; cursor: pointer;
  background: linear-gradient(135deg, #ff8a00, #ff5e8a); color: #fff; font-weight: 700; font-size: 15px;
}
