/* ==========================================================================
   1. AI UI COMPONENTS (Extracted from tool-ui.css)
   ========================================================================== */




.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--glass-border);
}



.chat-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 6px;
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
}



.composer {
  display: flex;
  gap: 12px;
  align-items: stretch;
}



.composer textarea {
  flex: 1;
  height: 90px;
  resize: none;
  border-radius: 20px;
  padding: 12px;
  font-size: 16px;
  line-height: 1.45;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
}



.composer .right {
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: space-between;
  width: 80px;
}



.composer .right button {
  margin-top: 0;
  padding: 5px 5px;
  border-radius: 40px;
  font-size: 15px;
  flex: 1;
  background: var(--primary-color);
  border: none;
  color: var(--bg-base);
  cursor: pointer;
  transition: all 0.3s;
  font-weight: 700;
}



.composer .right button:hover {
  transform: scale(1.05);
  box-shadow: var(--mystic-shadow);
}



.composer .right button:active {
  transform: scale(1.0);
}



.composer .right button.secondary {
  background: var(--glass-bg);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
}



.composer .right button.secondary:hover {
  background: var(--glass-bg-hover);
  transform: scale(1.04);
}



.composer .right button.danger {
  background: var(--glass-bg);
  color: var(--quaternary-color);
  border: 1px solid var(--glass-border);
}



.composer .right button.danger:hover {
  background: var(--glass-bg-hover);
  transform: scale(1.04);
}



/* 动态省略号动画 */
.typing-indicator {
  display: inline-block;
}



.typing-indicator span {
  opacity: 0;
  animation: typing 1.4s infinite;
  animation-fill-mode: both;
}



.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}



.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}



/* 标准笔记/文本区域样式 (standard-notes-area)
   用于排盘工具的笔记记录，支持磨砂玻璃质感与呼吸发光焦点
*/
.standard-notes-area {
  width: 100%;
  height: 260px;
  padding: 14px;
  border-radius: 12px;
  border: 1.5px solid var(--primary-color);
  background: var(--glass-bg);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: all 0.3s var(--ease-liquid);
  box-sizing: border-box;
  font-family: inherit;
}



.standard-notes-area:focus {
  border-color: var(--primary-color);
  background: var(--glass-bg-hover);
  box-shadow: 0 0 0 4px var(--mystic-glow);
  transform: translateY(-1px);
}



.standard-notes-area::placeholder {
  color: var(--text-muted);
  opacity: 0.5;
}



.notes-section-title {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}



/* AI 思考组件公共样式 */
.thinking-box {
  background: rgba(124, 58, 237, 0.04);
  border-left: 3px solid var(--secondary-color, #7c3aed);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13.5px;
  color: var(--text-secondary);
  border: 1px solid rgba(124, 58, 237, 0.1);
  border-left-width: 3px;
}



.thinking-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-weight: 500;
  user-select: none;
}



.thinking-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--secondary-color, #7c3aed);
  font-weight: bold;
}



.thinking-dot {
  width: 8px;
  height: 8px;
  background-color: var(--secondary-color, #7c3aed);
  border-radius: 50%;
  animation: pulse-dot 1.5s infinite ease-in-out;
}



.thinking-toggle-btn {
  font-size: 11px;
  opacity: 0.7;
  transition: transform 0.2s;
}



.thinking-content {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(124, 58, 237, 0.15);
  max-height: 180px;
  overflow-y: auto;
  font-family: var(--font-mono, monospace);
  white-space: pre-wrap;
  opacity: 0.85;
  color: var(--text-muted, #64748b);
  font-size: 13px;
  line-height: 1.6;
}



/* =========================================
   AI 追问对话窗口样式
   ========================================= */
.ai-chat-section {
  margin-top: 24px;
  border-top: 1px dashed var(--glass-border);
  padding-top: 24px;
  animation: fadeIn 0.4s ease-out;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}



.ai-chat-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}



.ai-chat-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary-color);
  display: flex;
  align-items: center;
  gap: 8px;
}



.ai-chat-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}



.ai-chat-history {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 4px;
}



/* 滚动条美化 */
.ai-chat-history::-webkit-scrollbar {
  width: 6px;
}


.ai-chat-history::-webkit-scrollbar-track {
  background: transparent;
}


.ai-chat-history::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 3px;
}



.ai-chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.6;
  font-size: 0.95rem;
  animation: fadeIn 0.3s ease-out;
}



.ai-chat-msg.user {
  align-self: flex-end;
  background: rgba(var(--primary-color-rgb), 0.15);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
  border: 1px solid rgba(var(--primary-color-rgb), 0.2);
}



.ai-chat-msg.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--glass-border);
}



.ai-chat-msg .markdown-body p:last-child {
  margin-bottom: 0;
}



.ai-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: rgba(var(--primary-color-rgb), 0.05);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  padding: 10px 14px;
  transition: border-color 0.3s, box-shadow 0.3s;
}



.ai-chat-input-area:focus-within {
  border-color: var(--primary-color);
  box-shadow: 0 0 10px rgba(var(--primary-color-rgb), 0.15);
}



.ai-chat-input {
  flex: 1;
  background: transparent;
  border: none;
  resize: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  line-height: 1.5;
  max-height: 120px;
  font-family: inherit;
  padding: 0;
}



.ai-chat-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.7;
}



.ai-chat-send-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-color);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: all 0.3s;
  padding: 0;
  flex-shrink: 0;
}



.ai-chat-send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  background: var(--secondary-color);
}



.ai-chat-send-btn:active:not(:disabled) {
  transform: scale(0.95);
}



.ai-chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--text-secondary);
}



.ai-chat-msg.thinking {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed var(--glass-border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  padding: 10px 14px;
}



.ai-chat-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(var(--primary-color-rgb), 0.2);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}



/* 夜间模式微调 */
.night-theme .ai-chat-msg.assistant {
  background: rgba(0, 0, 0, 0.2);
}


.night-theme .ai-chat-input-area {
  background: rgba(0, 0, 0, 0.15);
}

/* ==========================================================================
   2. AI CHAT WINDOW & MARKDOWN TYPOGRAPHY (Extracted from theme-ui.css)
   ========================================================================== */

/* 真实玻璃效果聊天界面 */
.chat-shell {
  position: relative;
  width: min(1100px, calc(100vw - 40px));
  height: min(760px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%);
  backdrop-filter: blur(25px) saturate(180%);
  -webkit-backdrop-filter: blur(25px) saturate(180%);
  will-change: transform, backdrop-filter;
  transform: translateZ(0);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: var(--shadow-medium), inset 0 1px 1px rgba(255, 255, 255, 0.6), inset 0 -1px 1px rgba(255, 255, 255, 0.2);
}

.chat-shell::before {
  display: none;
}

.chat-shell::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--noise-texture);
  opacity: 0.03;
  border-radius: 20px;
  pointer-events: none;
  mix-blend-mode: overlay;
}

.msg {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
  padding: 12px 12px;
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: var(--edge-blur);
  -webkit-backdrop-filter: var(--edge-blur);
}

/* 已通过 box-shadow 替代高光伪元素 */

.msg .meta {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.msg .who {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.msg .time {
  font-size: 11px;
  color: var(--text-muted);
}

.msg .content {
  word-break: break-word;
  line-height: 1.6;
  color: var(--text-secondary);
  font-size: 14px;
}

.msg .content p {
  margin: 0.5em 0;
}

.msg .content p:first-child {
  margin-top: 0;
}

.msg .content p:last-child {
  margin-bottom: 0;
}

.msg .content code {
  background: var(--glass-bg);
  padding: 2px 6px;
  border-radius: 40px;
  font-family: ui-monospace, 'Cascadia Code', 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.9em;
  color: var(--text-primary);
}

.msg .content pre {
  background: #0d1117;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 16px;
  overflow-x: auto;
  margin: 0.8em 0;
}

.msg .content pre code {
  background: transparent;
  color: #e6edf3;
  padding: 0;
  border-radius: 0;
  font-size: 0.85em;
  line-height: 1.5;
  display: block;
}

.msg .content h1,
.msg .content h2,
.msg .content h3,
.msg .content h4 {
  margin: 0.8em 0 0.4em 0;
  color: var(--text-primary);
  font-weight: 600;
}

.msg .content h1 {
  font-size: 1.5em;
}

.msg .content h2 {
  font-size: 1.3em;
}

.msg .content h3 {
  font-size: 1.15em;
}

.msg .content h4 {
  font-size: 1.05em;
}

.msg .content ul,
.msg .content ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

.msg .content li {
  margin: 0.3em 0;
}

.msg .content blockquote {
  border-left: 3px solid var(--primary-color);
  padding-left: 12px;
  margin: 0.8em 0;
  color: var(--text-secondary);
  font-style: italic;
}

.msg .content table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.8em 0;
}

.msg .content table th,
.msg .content table td {
  border: 1px solid var(--glass-border);
  padding: 8px 12px;
  text-align: left;
}

.msg .content table th {
  background: var(--glass-bg-hover);
  font-weight: 600;
}

.msg .content a {
  color: var(--primary-color);
  text-decoration: none;
}

.msg .content a:hover {
  text-decoration: underline;
}

.msg.user .content {
  white-space: pre-wrap;
}

.msg.user .who {
  color: var(--accent-color);
}

.msg.ai .who {
  color: var(--secondary-color);
}

.msg.system .who {
  color: var(--quaternary-color);
}

@keyframes typing {
  0%, 60%, 100% { opacity: 0; }
  30% { opacity: 1; }
}

@media (max-width: 768px) {
  body {
    padding-top: 70px;
  }

  .chat-shell {
    width: calc(100vw - 32px);
    height: calc(100vh - 80px);
    /* 为导航栏预留空间 */
    margin-top: 64px;
  }
}

@media (max-width: 480px) {
  .chat-shell {
    width: calc(100vw - 24px);
    height: calc(100vh - 80px);
    /* 为导航栏预留空间 */
    margin-top: 60px;
  }
}

/* =========================================
   AI 深度解析 Markdown 排版样式
   ========================================= */
#ai-result {
  margin-top: 24px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  font-size: 15px;
  line-height: 1.8;
  color: var(--text-primary);
  display: none;
  text-align: left;
  border: 1px solid var(--glass-border);
  animation: fadeIn 0.5s ease-out;
}

#ai-result h3, 
#ai-result h4 {
  color: var(--primary-color);
  margin-top: 1.5em;
  margin-bottom: 0.8em;
  font-weight: 600;
}

#ai-result h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.3em;
  border-bottom: 1px dashed rgba(var(--primary-rgb), 0.3);
  padding-bottom: 8px;
}

#ai-result p {
  margin-bottom: 1em;
  line-height: 1.8;
  color: var(--text-primary);
}

#ai-result strong {
  color: var(--primary-color);
  font-weight: 600;
  background: rgba(var(--primary-rgb), 0.08);
  padding: 0 4px;
  border-radius: 4px;
}

#ai-result ul, 
#ai-result ol {
  padding-left: 24px;
  margin-bottom: 1.2em;
}

#ai-result li {
  margin-bottom: 8px;
  line-height: 1.6;
  color: var(--text-primary);
}

#ai-result li::marker {
  color: var(--secondary-color);
}

#ai-result blockquote {
  border-left: 4px solid var(--primary-color);
  margin: 1em 0;
  padding: 0.5em 1em;
  background: rgba(var(--primary-rgb), 0.05);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(0.8); opacity: 0.5; }
  50% { transform: scale(1.2); opacity: 1; box-shadow: 0 0 8px var(--secondary-color, #7c3aed); }
}

.send-icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

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