/* =====================================================
   ai.css — AI 助手（BYOK）样式
   只新增样式，不改 css/style.css / plan.css / extra.css。
   仅复用 :root 既有变量；移动端 ≤640px 单列适配。
   ===================================================== */

/* ============ 悬浮按钮 + 迷你菜单（章节页） ============ */
.ai-fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.ai-fab-main {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #7c5cfc);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(79, 110, 247, .35);
  transition: transform .15s;
}
.ai-fab-main:hover { transform: scale(1.06); }
.ai-fab-item {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-2);
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity .15s, transform .15s;
  white-space: nowrap;
}
.ai-fab.open .ai-fab-item { opacity: 1; pointer-events: auto; transform: translateY(0); }
.ai-fab.open .ai-fab-item:hover { color: var(--primary); border-color: var(--primary); }

/* ============ 抽屉：多轮问答 ============ */
.ai-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 400px;
  max-width: 92vw;
  z-index: 950;
  background: var(--card);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 30px rgba(31, 36, 48, .12);
  display: flex;
  flex-direction: column;
}
.ai-drawer[hidden] { display: none; }
.ai-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-drawer-title { font-size: 15px; font-weight: 700; min-width: 0; }
.ai-drawer-title .ai-ctx {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}
.ai-drawer-acts { display: flex; gap: 6px; flex-shrink: 0; }
.ai-drawer-acts button {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-2);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.ai-drawer-acts button:hover { color: var(--primary); border-color: var(--primary); }
.ai-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-drawer-foot {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}
.ai-drawer-foot textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
}
.ai-drawer-foot textarea:focus { outline: none; border-color: var(--primary); background: var(--card); }

/* ============ 消息气泡 ============ */
.ai-msg {
  max-width: 92%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.75;
  word-break: break-word;
}
.ai-msg p { margin: 0 0 6px; }
.ai-msg p:last-child { margin-bottom: 0; }
.ai-msg ul, .ai-msg ol { margin: 4px 0 6px; padding-left: 20px; }
.ai-msg li { margin: 2px 0; }
.ai-msg h2, .ai-msg h3, .ai-msg h4 { font-size: 14.5px; margin: 10px 0 6px; }
.ai-msg table { border-collapse: collapse; margin: 8px 0; font-size: 12.5px; width: 100%; }
.ai-msg th, .ai-msg td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; }
.ai-msg th { background: var(--bg); }
.ai-msg code { background: var(--primary-light); color: var(--primary-dark); border-radius: 4px; padding: 1px 5px; font-size: 12.5px; }
.ai-msg pre { background: #1f2430; color: #e8ebf4; border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 8px 0; }
.ai-msg pre code { background: none; color: inherit; padding: 0; }
.ai-msg blockquote { border-left: 3px solid var(--primary); margin: 6px 0; padding: 2px 10px; color: var(--text-2); background: var(--primary-light); border-radius: 0 8px 8px 0; }
.ai-msg hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.ai-user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.ai-ai {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  max-width: 100%;
}
.ai-ai.thinking { opacity: .65; font-style: italic; }

/* ============ 弹窗：总结 / 评分 / 学情分析 / 笔记 ============ */
.ai-modal {
  position: fixed;
  inset: 0;
  z-index: 960;
  background: rgba(31, 36, 48, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.ai-modal[hidden] { display: none; }
.ai-modal-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 12px 48px rgba(31, 36, 48, .25);
  width: 720px;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ai-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-modal-head h3 { font-size: 16px; }
.ai-modal-head button {
  border: none;
  background: none;
  font-size: 15px;
  color: var(--text-3);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.ai-modal-head button:hover { color: var(--text); background: var(--bg); }
.ai-modal-body {
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-modal-foot {
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* ============ 设置面板（#/data） ============ */
.ai-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.ai-field { display: flex; flex-direction: column; gap: 5px; }
.ai-field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.ai-field input, .ai-field select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}
.ai-field input:focus, .ai-field select:focus { outline: none; border-color: var(--primary); background: var(--card); }
.ai-actions { align-items: center; }
.ai-enable { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.ai-enable input { accent-color: var(--primary); width: 15px; height: 15px; cursor: pointer; }
.ai-status { font-size: 12.5px; color: var(--text-2); }
.ai-status.ok { color: var(--green); }
.ai-status.err { color: var(--red); }
.ai-presets { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 12px 0 10px; }
.ai-presets-label { font-size: 12.5px; color: var(--text-3); }
.ai-warn { color: var(--orange); }
.ai-warn code, .dm-tip code { background: var(--primary-light); color: var(--primary-dark); border-radius: 4px; padding: 1px 5px; font-size: 12px; }

/* ============ AI 笔记列表（#/data） ============ */
.ai-notes-list { display: flex; flex-direction: column; gap: 8px; }
.ai-note-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--bg);
}
.ai-note-info { display: flex; flex-direction: column; min-width: 0; }
.ai-note-info b { font-size: 13.5px; }
.ai-note-info span { font-size: 12px; color: var(--text-3); }
.ai-note-acts { display: flex; gap: 6px; flex-shrink: 0; }

/* ============ 章节页 AI 评分入口 ============ */
.ai-grade-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.ai-grade-hint { font-size: 12px; color: var(--text-3); }

/* ============ 移动端适配 ============ */
@media (max-width: 640px) {
  .ai-drawer { width: 100%; max-width: 100%; }
  .ai-fab { right: 14px; bottom: 16px; }
  .ai-modal { padding: 12px 8px; }
  .ai-modal-card { max-height: 94%; }
  .ai-drawer-title .ai-ctx { max-width: 180px; }
  .ai-note-row { flex-direction: column; align-items: flex-start; }
}
