/* ============================================
   学途 · 悬浮 AI 助手 — 安静皮肤

   改造前是「温暖木质」：多层渐变、发光阴影、玻璃拟态、脉冲光环，
   而且有大量颜色是【裸写的十六进制】（不是变量），所以换令牌时
   它们不会跟着变 —— 助手气泡和快捷提示按钮一直是旧的暖木色。

   现在：
   · 颜色一律走令牌，不再出现裸十六进制（功能性色除外，已加注释）
   · 去掉发光阴影和脉冲光环（纪律③：阴影只有两级且都很轻）
   · 去掉玻璃拟态（backdrop-filter）
   · 保留全部功能性动画：打字指示、流式点、录音脉冲、停止脉冲
   ============================================ */

/* ---- 悬浮球 ---- */
.chat-fab {
  position: fixed; bottom: 28px; right: 28px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--brand);
  box-shadow: var(--sh);
  border: none; cursor: pointer; z-index: 150;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: var(--on-brand);
  transition: background 0.2s, transform 0.2s;
}
.chat-fab:hover { background: var(--brand-hover); transform: scale(1.06); }
.chat-fab:active { transform: scale(0.96); }
.chat-fab.hidden { transform: scale(0); opacity: 0; pointer-events: none; }

/* ---- 聊天窗口 ---- */
.chat-window {
  position: fixed; bottom: 96px; right: 28px;
  width: 400px; height: 560px;
  min-width: 300px; min-height: 320px;
  max-width: 800px; max-height: 900px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--sh);
  z-index: 150; display: flex; flex-direction: column; overflow: hidden;
  transform-origin: bottom right;
  transition: transform 0.3s cubic-bezier(0.16,1,0.3,1), opacity 0.25s ease;
}
.chat-window.collapsed { transform: scale(0); opacity: 0; pointer-events: none; }

/* ---- 历史会话面板 ---- */
.chat-history-panel {
  position: absolute; top: 0; left: 0; bottom: 0; width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 10; display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.16,1,0.3,1);
  border-radius: var(--r) 0 0 var(--r);
}
.chat-history-panel.active { transform: translateX(0); }

.history-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s3) var(--s4);
  font-size: var(--t-sm); font-weight: 600;
  color: var(--ink); border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.history-list { flex: 1; overflow-y: auto; padding: var(--s2); }
.history-list::-webkit-scrollbar { width: 3px; }
.history-list::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 2px; }
.history-empty { text-align: center; color: var(--faint); font-size: var(--t-xs); padding: var(--s8) var(--s4); }

.history-item {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s3); border-radius: var(--r-sm);
  cursor: pointer; transition: background 0.15s; margin-bottom: 2px;
}
.history-item:hover { background: var(--sunk); }
.history-item.active { background: var(--brand-tint); }
.history-item.active .history-item-title { color: var(--brand-deep); font-weight: 600; }
.history-item-main { flex: 1; min-width: 0; }
.history-item-title { font-size: var(--t-xs); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item-meta { font-size: 11px; color: var(--faint); margin-top: 2px; }
.history-item-del {
  width: 26px; height: 26px; border-radius: 6px; border: none;
  background: transparent; color: var(--faint); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; transition: background 0.15s, color 0.15s; flex-shrink: 0;
}
.history-item-del:hover { background: var(--red-soft); color: var(--red); }

/* ---- 头部 ---- */
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s3) var(--s4);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  color: var(--ink); flex-shrink: 0; position: relative; z-index: 5;
}
.chat-header-left { display: flex; align-items: center; gap: var(--s2); }
.chat-header-icon {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  background: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--on-brand);
}
.chat-header-title { font-size: var(--t-sm); font-weight: 600; }
.chat-header-sub { font-size: 11px; color: var(--faint); }
.chat-header-actions { display: flex; gap: var(--s1); }
.chat-header-btn {
  width: 30px; height: 30px; border-radius: var(--r-sm); border: none;
  background: transparent; color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; transition: background 0.15s, color 0.15s;
}
.chat-header-btn:hover { background: var(--sunk); color: var(--brand); }

/* ---- 消息区 ---- */
.chat-messages {
  flex: 1; overflow-y: auto; padding: var(--s4);
  display: flex; flex-direction: column; gap: var(--s3);
  background: var(--canvas); position: relative; z-index: 1;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 2px; }

.chat-msg { display: flex; gap: var(--s2); max-width: 85%; animation: msgSlide 0.25s ease-out; }
@keyframes msgSlide { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
.chat-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg.assistant { align-self: flex-start; }

.chat-msg-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
}
.chat-msg.user .chat-msg-avatar { background: var(--brand); color: var(--on-brand); }
.chat-msg.assistant .chat-msg-avatar { background: var(--brand-tint); color: var(--brand-deep); }

.chat-msg-bubble {
  padding: var(--s2) var(--s3); border-radius: var(--r-sm);
  font-size: var(--t-xs); line-height: 1.7;
  word-break: break-word; white-space: pre-wrap;
}
.chat-msg.user .chat-msg-bubble {
  background: var(--brand);
  color: var(--on-brand);
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant .chat-msg-bubble {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

/* ---- 打字指示（功能性动画，保留）---- */
.chat-typing { display: flex; gap: 4px; padding: var(--s2) var(--s3); align-items: center; }
.chat-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--faint); animation: typingBounce 1.4s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%,60%,100% { opacity:0.25; transform:translateY(0); }
  30% { opacity:1; transform:translateY(-4px); }
}

/* ---- 输入区 ---- */
.chat-input-area {
  padding: var(--s3) var(--s4); border-top: 1px solid var(--line);
  display: flex; gap: var(--s2); background: var(--surface);
  position: relative; z-index: 1;
}
.chat-input {
  flex: 1; border: 1px solid var(--line-2);
  border-radius: var(--r-pill); padding: var(--s2) var(--s4);
  font-size: var(--t-xs); font-family: inherit; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--sunk); color: var(--ink); resize: none;
}
.chat-input:focus {
  background: var(--surface);
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}
.chat-input::placeholder { color: var(--faint); }

.chat-send-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; background: var(--brand);
  color: var(--on-brand); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; transition: background 0.2s; flex-shrink: 0;
}
.chat-send-btn:hover { background: var(--brand-hover); }
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-mic {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line-2); background: var(--surface);
  color: var(--faint); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; transition: color 0.2s, border-color 0.2s; flex-shrink: 0;
}
.btn-mic:hover { color: var(--brand); border-color: var(--brand); }
/* 录音态用功能性红（非语义令牌，与品牌色无关），保留脉冲提示 */
.btn-mic.recording { color: #fff; background: var(--red); border-color: var(--red); animation: micPulse 1.2s infinite; }
.btn-mic:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-mic.recording:disabled { animation: none; opacity: 0.7; }
@keyframes micPulse {
  0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--red) 45%, transparent); }
  50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--red) 0%, transparent); }
}

.chat-stop-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; background: var(--red);
  color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; transition: background 0.2s; flex-shrink: 0;
  animation: stopPulse 1.2s ease-in-out infinite;
}
.chat-stop-btn:hover { background: color-mix(in srgb, var(--red) 85%, #000); }
@keyframes stopPulse {
  0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--red) 35%, transparent); }
  50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--red) 0%, transparent); }
}
.chat-stop-btn.hidden, .chat-send-btn.hidden { display: none; }

/* ---- 快捷提问（chip 风格）---- */
.chat-quick-prompts { display: flex; gap: var(--s2); padding: 0 var(--s4) var(--s2); flex-wrap: wrap; }
.chat-quick-prompt {
  font-size: 11px; padding: 4px 10px; border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--sunk);
  color: var(--muted); cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.chat-quick-prompt:hover { border-color: var(--brand-2); color: var(--brand-deep); background: var(--surface); }

/* ---- 气泡内 Markdown ---- */
.chat-msg-bubble p { margin: 0 0 6px; }
.chat-msg-bubble p:last-child { margin-bottom: 0; }
.chat-msg-bubble h3 { font-size: var(--t-sm); font-weight: 700; margin: 10px 0 6px; color: var(--brand-deep); }
.chat-msg-bubble h4 { font-size: var(--t-xs); font-weight: 650; margin: 8px 0 4px; color: var(--ink); }
.chat-msg-bubble strong { color: var(--brand-deep); font-weight: 650; }
/* 用户气泡是品牌实心底，里面的强调色必须改用 on-brand，否则看不见 */
.chat-msg.user .chat-msg-bubble h3,
.chat-msg.user .chat-msg-bubble h4,
.chat-msg.user .chat-msg-bubble strong { color: var(--on-brand); }
.chat-msg-bubble code {
  background: var(--sunk); color: var(--brand-deep);
  padding: 2px 6px; border-radius: 4px; font-size: 0.92em;
  font-family: 'Consolas', 'Monaco', monospace;
}
.chat-msg-bubble pre {
  background: var(--sunk); color: var(--ink);
  padding: var(--s3) var(--s4); border-radius: var(--r-sm); overflow-x: auto;
  margin: 8px 0; font-size: 0.9em; line-height: 1.5;
  border: 1px solid var(--line);
}
.chat-msg-bubble pre code { background: none; color: inherit; padding: 0; font-size: inherit; }
.chat-msg-bubble ul, .chat-msg-bubble ol { margin: 6px 0; padding-left: 18px; }
.chat-msg-bubble li { margin: 2px 0; }
.chat-msg-bubble hr { border: none; border-top: 1px solid var(--line); margin: 10px 0; }
.chat-msg-bubble table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  margin: 8px 0; font-size: 0.95em;
  border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden;
}
.chat-msg-bubble thead { background: var(--sunk); color: var(--muted); }
.chat-msg-bubble th { padding: 6px 10px; text-align: left; font-weight: 600; }
.chat-msg-bubble td { padding: 6px 10px; border-top: 1px solid var(--line); }
.chat-msg.user .chat-msg-bubble thead { background: color-mix(in srgb, var(--on-brand) 18%, transparent); color: var(--on-brand); }
.chat-msg.user .chat-msg-bubble td { border-top-color: color-mix(in srgb, var(--on-brand) 22%, transparent); }

/* ---- 流式输出指示（功能性动画，保留）---- */
.streaming-dots { display: inline-flex; gap: 3px; align-items: center; margin-left: 2px; }
.streaming-dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--brand-2); animation: streamingBounce 1.2s ease-in-out infinite;
}
.streaming-dots span:nth-child(2) { animation-delay: 0.2s; }
.streaming-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes streamingBounce {
  0%,60%,100% { opacity:0.3; transform:translateY(0); }
  30% { opacity:1; transform:translateY(-5px); }
}

@media (max-width: 480px) {
  .chat-window { width: calc(100vw - 16px) !important; height: calc(100vh - 120px) !important; bottom: 86px; right: 8px; border-radius: var(--r) var(--r) 0 0; }
  .chat-history-panel { width: 220px; }
}
