/* 「问 AI」模块样式 — 纯本地，对话不经服务器 */

/* 按钮强调 */
.ia-btn.ia-askai {
  border-color: #c4b5fd;
  color: #6d28d9;
  background: #f5f3ff;
}
.ia-btn.ia-askai:hover {
  background: #ede9fe;
  color: #5b21b6;
}
.ia-btn.ia-askai.active {
  background: #6d28d9;
  color: #fff;
  border-color: #6d28d9;
}

/* 遮罩 — 透明不遮挡主界面，仅作为浮动层的定位容器 */
.askai-overlay {
  position: fixed;
  inset: 0;
  background: transparent;
  z-index: 10000;
  display: none;
  pointer-events: none; /* 让点击穿透到主界面，只有弹窗本身接收事件 */
  align-items: flex-start;
  justify-content: center;
  padding: 60px 16px 16px;
}
.askai-overlay.open { display: flex; }

/* 主卡片 — 可拖动浮动面板 */
.askai-card {
  pointer-events: auto; /* 重新启用卡片本身的事件 */
  background: var(--glass-bg-strong, #fff);
  border: 1px solid var(--glass-border-outer, #e5e7eb);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
  width: 100%;
  max-width: 760px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* 拖动定位：用 transform 移动，避免破坏 flex 居中 */
}

/* 头部 — 拖动手柄 */
.askai-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border, #e5e7eb);
  background: #f5f3ff;
  cursor: move; /* 拖动提示 */
  user-select: none;
}
.askai-card.dragging { opacity: 0.92; }
.askai-drag-handle {
  cursor: move;
  color: #a78bfa;
  font-weight: 700;
  letter-spacing: -2px;
  font-size: 14px;
  line-height: 1;
  user-select: none;
}
.askai-head-title {
  cursor: move;
}
.askai-head-title {
  cursor: move;
  font-size: 15px;
  font-weight: 700;
  color: #5b21b6;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.askai-head-title small {
  font-weight: 400;
  color: var(--fg-muted, #6b7280);
  font-size: 12px;
  margin-left: 6px;
}
.askai-head-btn {
  font-family: var(--font-ui, inherit);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  color: var(--fg-muted, #6b7280);
  border: 1px solid var(--border, #e5e7eb);
  transition: all 0.15s;
  white-space: nowrap;
}
.askai-head-btn:hover { background: #f3f3f0; color: var(--fg, #1a1a1a); }
.askai-head-btn.active { background: #6d28d9; color: #fff; border-color: #6d28d9; }
.askai-head-close {
  font-size: 22px;
  line-height: 1;
  padding: 2px 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--fg-muted, #6b7280);
}
.askai-head-close:hover { color: var(--fg, #1a1a1a); }

/* 本地隐私提示条 */
.askai-privacy {
  padding: 8px 16px;
  background: #fffbeb;
  border-bottom: 1px solid #fcd34d;
  color: #92400e;
  font-size: 12px;
  line-height: 1.5;
}

/* 设置面板 */
.askai-settings {
  display: none;
  padding: 16px;
  border-bottom: 1px solid var(--border, #e5e7eb);
  background: var(--glass-bg, #fafaf8);
  overflow-y: auto;
}
.askai-settings.open { display: block; }
.askai-settings h4 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--fg, #1a1a1a);
}
.askai-field { margin-bottom: 12px; }
.askai-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-muted, #6b7280);
  margin-bottom: 4px;
}
.askai-field input,
.askai-field select {
  width: 100%;
  font-family: var(--font-ui, inherit);
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 6px;
  background: #fff;
  color: var(--fg, #1a1a1a);
  box-sizing: border-box;
}
.askai-field input:focus,
.askai-field select:focus {
  outline: none;
  border-color: #6d28d9;
  box-shadow: 0 0 0 2px rgba(109, 40, 217, 0.15);
}
.askai-field .askai-hint {
  font-size: 11px;
  color: var(--fg-muted, #6b7280);
  margin-top: 3px;
}
.askai-provider-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  background: #ede9fe;
  padding: 3px;
  border-radius: 8px;
}
.askai-provider-tab {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  padding: 6px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  color: #6d28d9;
  transition: all 0.15s;
}
.askai-provider-tab.active {
  background: #fff;
  color: #5b21b6;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.askai-ctx-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--fg, #1a1a1a);
  margin: 10px 0;
  cursor: pointer;
}
.askai-settings-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.askai-save-btn {
  font-size: 13px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  background: #6d28d9;
  color: #fff;
  border: none;
}
.askai-save-btn:hover { background: #5b21b6; }
.askai-clear-btn {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  color: var(--fg-muted, #6b7280);
  border: 1px solid var(--border, #e5e7eb);
}

/* 对话区 */
.askai-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 280px;
}
.askai-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.65;
  word-wrap: break-word;
  white-space: normal;
}
.askai-msg pre {
  background: rgba(0,0,0,0.06);
  padding: 8px 10px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 12px;
  margin: 6px 0;
}
.askai-msg code {
  font-family: var(--font-mono, monospace);
  font-size: 12px;
}
.askai-msg.user {
  align-self: flex-end;
  background: #6d28d9;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.askai-msg.assistant {
  align-self: flex-start;
  background: #f3f3f0;
  color: var(--fg, #1a1a1a);
  border-bottom-left-radius: 4px;
}
.askai-msg.system {
  align-self: center;
  background: transparent;
  color: var(--fg-muted, #6b7280);
  font-size: 12px;
  font-style: italic;
  text-align: center;
  padding: 4px 0;
}
.askai-msg.context-status {
  align-self: center;
  background: #ecfeff;
  border: 1px solid #99f6e4;
  color: #0f766e;
  font-size: 11px;
  border-radius: 6px;
  padding: 4px 10px;
}
.askai-msg-error {
  align-self: center;
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #b91c1c;
  font-size: 12px;
  border-radius: 6px;
  padding: 6px 12px;
  max-width: 100%;
}
.askai-typing {
  align-self: flex-start;
  color: var(--fg-muted, #6b7280);
  font-size: 13px;
  padding: 10px 14px;
}
/* 流式输出中：左侧脉冲边 + 内联占位 */
.askai-msg.assistant.askai-streaming {
  border-left: 3px solid #6d28d9;
  animation: askai-stream-pulse 1.5s ease-in-out infinite;
}
.askai-typing-inline {
  color: var(--fg-muted, #6b7280);
  font-style: italic;
  animation: askai-blink 1.4s infinite both;
}
@keyframes askai-stream-pulse {
  0%, 100% { box-shadow: -3px 0 0 #6d28d9; }
  50% { box-shadow: -3px 0 6px rgba(109, 40, 217, 0.5); }
}
.askai-typing span {
  display: inline-block;
  animation: askai-blink 1.4s infinite both;
}
.askai-typing span:nth-child(2) { animation-delay: 0.2s; }
.askai-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes askai-blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}
.askai-empty {
  align-self: center;
  color: var(--fg-muted, #6b7280);
  font-size: 13px;
  text-align: center;
  padding: 40px 20px;
  line-height: 1.8;
}

/* 输入区 */
.askai-foot {
  border-top: 1px solid var(--border, #e5e7eb);
  padding: 12px 16px;
  background: var(--glass-bg, #fafaf8);
}
.askai-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.askai-input {
  flex: 1;
  font-family: var(--font-ui, inherit);
  font-size: 13px;
  padding: 8px 12px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  background: #fff;
  color: var(--fg, #1a1a1a);
  box-sizing: border-box;
  line-height: 1.5;
}
.askai-input:focus {
  outline: none;
  border-color: #6d28d9;
  box-shadow: 0 0 0 2px rgba(109, 40, 217, 0.15);
}
.askai-input:disabled { background: #f3f3f0; cursor: not-allowed; }
.askai-send {
  font-size: 13px;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  background: #6d28d9;
  color: #fff;
  border: none;
  white-space: nowrap;
}
.askai-send:hover:not(:disabled) { background: #5b21b6; }
.askai-send:disabled { background: #c4b5fd; cursor: not-allowed; }
.askai-foot-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  font-size: 11px;
  color: var(--fg-muted, #6b7280);
}
.askai-foot-meta button {
  font-size: 11px;
  background: none;
  border: none;
  color: var(--fg-muted, #6b7280);
  cursor: pointer;
  text-decoration: underline;
}
.askai-foot-meta button:hover { color: var(--fg, #1a1a1a); }

@media (max-width: 640px) {
  .askai-card { max-height: 90vh; border-radius: 8px; }
  .askai-overlay { padding: 8px; align-items: flex-start; }
  .askai-msg { max-width: 95%; }
}

/* ── 深色模式覆盖（显式 [data-theme=dark] 或 跟随系统）── */
:root[data-theme="dark"] .askai-card,
:root[data-theme="dark"] .askai-msg.assistant,
:root[data-theme="dark"] .askai-settings { background: #1c1e24; }
:root[data-theme="dark"] .askai-head { background: #2a1f45; border-color: #3a2f55; }
:root[data-theme="dark"] .askai-head-title { color: #c4b5fd; }
:root[data-theme="dark"] .askai-head-btn,
:root[data-theme="dark"] .askai-input,
:root[data-theme="dark"] .askai-field input,
:root[data-theme="dark"] .askai-field select,
:root[data-theme="dark"] .askai-field textarea {
  background: #232530; color: var(--fg, #e7e7ea); border-color: #2c2e36;
}
:root[data-theme="dark"] .askai-head-btn:hover { background: #2c2e36; }
:root[data-theme="dark"] .askai-endpoint,
:root[data-theme="dark"] .askai-drag-handle { color: #a78bfa; background: #2a1f45; }
:root[data-theme="dark"] .askai-tool,
:root[data-theme="dark"] .askai-faq details { background: #1c1e24; }
:root[data-theme="dark"] .askai-msg.user { background: #3a1d1b; color: #fde7e4; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .askai-card,
  :root:not([data-theme="light"]) .askai-msg.assistant,
  :root:not([data-theme="light"]) .askai-settings { background: #1c1e24; }
  :root:not([data-theme="light"]) .askai-head { background: #2a1f45; border-color: #3a2f55; }
  :root:not([data-theme="light"]) .askai-head-title { color: #c4b5fd; }
  :root:not([data-theme="light"]) .askai-head-btn,
  :root:not([data-theme="light"]) .askai-input,
  :root:not([data-theme="light"]) .askai-field input,
  :root:not([data-theme="light"]) .askai-field select,
  :root:not([data-theme="light"]) .askai-field textarea {
    background: #232530; color: var(--fg, #e7e7ea); border-color: #2c2e36;
  }
  :root:not([data-theme="light"]) .askai-head-btn:hover { background: #2c2e36; }
  :root:not([data-theme="light"]) .askai-endpoint,
  :root:not([data-theme="light"]) .askai-drag-handle { color: #a78bfa; background: #2a1f45; }
  :root:not([data-theme="light"]) .askai-tool,
  :root:not([data-theme="light"]) .askai-faq details { background: #1c1e24; }
  :root:not([data-theme="light"]) .askai-msg.user { background: #3a1d1b; color: #fde7e4; }
}
