:root {
  /* 雾霾紫冷调配色 */
  --chat-bg: rgba(22, 22, 32, 0.82);
  --chat-bg-solid: #161620;
  --chat-border: rgba(140, 130, 180, 0.18);
  --chat-purple: #8B7FC8;
  --chat-purple-deep: #6B5FA0;
  --chat-purple-light: #A79BD8;
  --chat-purple-glow: rgba(139, 127, 200, 0.25);
  --chat-text: rgba(240, 238, 248, 0.92);
  --chat-text-muted: rgba(200, 196, 220, 0.5);
  --chat-ease: cubic-bezier(0.23, 1, 0.32, 1);
}

#chat-panel {
  position: fixed;
  left: 100px;
  top: 24px;
  z-index: 480;
  width: 440px;
  max-width: calc(100vw - 130px);
  height: 640px;
  max-height: calc(100vh - 48px);
  min-width: 320px;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  --chat-font-size: 14px;
  background: var(--chat-bg);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid var(--chat-border);
  border-radius: 18px;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.5), 0 0 60px var(--chat-purple-glow);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.95) translateY(6px);
  transform-origin: top left;
  transition: opacity 0.24s var(--chat-ease), transform 0.24s var(--chat-ease), visibility 0s linear 0.24s;
}

#chat-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  z-index: 2;
  background: linear-gradient(90deg, transparent, var(--chat-purple-light) 30%, var(--chat-purple) 70%, transparent);
  opacity: 0.7;
  pointer-events: none;
}

#chat-panel.open {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.24s var(--chat-ease), transform 0.24s var(--chat-ease);
}

/* 拖拽调整大小手柄 */
.chat-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  z-index: 10;
  opacity: 0.5;
  transition: opacity 160ms;
}
.chat-resize-handle::before {
  content: '';
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--chat-purple-light);
  border-bottom: 2px solid var(--chat-purple-light);
  border-radius: 0 0 2px 0;
  opacity: 0.6;
}
.chat-resize-handle:hover {
  opacity: 1;
}
#chat-panel.resizing {
  transition: none;
  user-select: none;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  background: rgba(255, 255, 255, 0.025);
  border-bottom: 1px solid var(--chat-border);
  cursor: move;
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--chat-text);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
}

.chat-title::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-purple);
  box-shadow: 0 0 10px var(--chat-purple-glow);
}

.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 10px;
  padding-left: 10px;
  border-left: 1px solid var(--chat-border);
  color: var(--chat-text-muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  font-weight: 500;
}

.chat-status::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--chat-purple);
  box-shadow: 0 0 6px var(--chat-purple-glow);
  animation: chatPulse 2.4s var(--chat-ease) infinite;
}

@keyframes chatPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* 标题栏操作区 */
.chat-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  margin-right: 14px;
}
.chat-new-btn {
  width: 26px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--chat-text-muted);
  font-size: 14px;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 160ms var(--chat-ease), color 160ms var(--chat-ease), transform 200ms var(--chat-ease);
}
.chat-new-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--chat-text);
  transform: rotate(180deg);
}

/* 字体大小调节按钮 */
.chat-font-size {
  display: flex;
  align-items: center;
  gap: 2px;
}
.chat-font-btn {
  width: 26px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--chat-text-muted);
  font-size: 11px;
  font-weight: 500;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 160ms var(--chat-ease), color 160ms var(--chat-ease);
}
.chat-font-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--chat-text);
}
.chat-font-btn.active {
  background: rgba(139, 127, 200, 0.2);
  color: var(--chat-purple-light);
}

.chat-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--chat-text-muted);
  font-size: 18px;
  font-weight: 300;
  line-height: 1;
  transition: background-color 200ms var(--chat-ease), color 200ms var(--chat-ease), transform 160ms var(--chat-ease);
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--chat-text);
}

.chat-close:active {
  transform: scale(0.92);
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(140, 130, 180, 0.2) transparent;
}

.chat-body::-webkit-scrollbar {
  width: 5px;
}

.chat-body::-webkit-scrollbar-thumb {
  background: rgba(140, 130, 180, 0.2);
  border-radius: 999px;
}

.chat-msg {
  position: relative;
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  display: block;
  margin-bottom: 12px;
  animation: msgIn 0.28s var(--chat-ease) both;
}

.chat-msg-content {
  font-size: var(--chat-font-size, 14px);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-time {
  position: absolute;
  bottom: -2px;
  transform: translateY(100%);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--chat-text-muted);
  white-space: nowrap;
  pointer-events: none;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.chat-msg.ai {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--chat-border);
  color: var(--chat-text);
  border-top-left-radius: 4px;
  margin-right: auto;
  margin-bottom: 24px;
}

.chat-msg.ai .chat-time {
  left: 6px;
}

/* 消息操作按钮（复制/重新生成）—— 放在气泡右下方，不与文字和时间戳重合 */
.chat-msg-actions {
  position: absolute;
  bottom: -22px;
  right: 0;
  left: auto;
  top: auto;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 160ms var(--chat-ease);
  z-index: 2;
}
.chat-msg.ai:hover .chat-msg-actions {
  opacity: 1;
}
.chat-msg-action {
  padding: 3px 10px;
  background: rgba(30, 28, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--chat-border);
  border-radius: 6px;
  color: var(--chat-text-muted);
  font-size: 10px;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.chat-msg-action:hover {
  background: rgba(139, 127, 200, 0.2);
  border-color: var(--chat-purple);
  color: var(--chat-purple-light);
}
.chat-msg-action:active {
  transform: scale(0.94);
}

.chat-msg.user {
  background: linear-gradient(135deg, var(--chat-purple) 0%, var(--chat-purple-deep) 100%);
  color: #FFFFFF;
  border-top-right-radius: 4px;
  box-shadow: 0 4px 14px rgba(107, 95, 160, 0.3);
  margin-left: auto;
}

.chat-msg.user .chat-time {
  right: 6px;
  color: rgba(255, 255, 255, 0.55);
}

.chat-msg.error {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.2);
  color: #FCA5A5;
}

.chat-msg.error .chat-time {
  color: rgba(252, 165, 165, 0.5);
}

.chat-dots {
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
  max-width: 64px;
  animation: none;
}

/* 等待加载状态的三点动画 */
.chat-msg.loading .chat-msg-content {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 2px 0;
}
.chat-msg.loading .chat-msg-content span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-purple-light);
  box-shadow: 0 0 6px var(--chat-purple-glow);
  animation: loadingDot 1.2s var(--chat-ease) infinite;
}
.chat-msg.loading .chat-msg-content span:nth-child(2) { animation-delay: 0.2s; }
.chat-msg.loading .chat-msg-content span:nth-child(3) { animation-delay: 0.4s; }
@keyframes loadingDot {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.chat-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--chat-purple-light);
  box-shadow: 0 0 6px var(--chat-purple-glow);
  animation: chatDot 1.2s var(--chat-ease) infinite;
}

.chat-dots span:nth-child(2) { animation-delay: 0.18s; }
.chat-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes chatDot {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.chat-foot {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--chat-border);
  background: rgba(255, 255, 255, 0.015);
}

.chat-input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  color: var(--chat-text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 200ms var(--chat-ease), box-shadow 200ms var(--chat-ease);
}

.chat-input::placeholder {
  color: var(--chat-text-muted);
}

.chat-input:focus {
  border-color: var(--chat-purple);
  box-shadow: 0 0 0 3px var(--chat-purple-glow);
}

.chat-send {
  padding: 10px 18px;
  background: linear-gradient(135deg, var(--chat-purple) 0%, var(--chat-purple-deep) 100%);
  color: #FFFFFF;
  border: 0;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(107, 95, 160, 0.3);
  transition: transform 160ms var(--chat-ease), opacity 200ms var(--chat-ease), filter 200ms var(--chat-ease);
}

.chat-send:not(:disabled):hover {
  filter: brightness(1.1);
}

.chat-send:active {
  transform: scale(0.96);
}

.chat-send:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  #chat-panel {
    transform: none;
    transition: opacity 0.2s ease;
  }
  .chat-msg { animation: none; }
  .chat-dots span, .chat-status::before { animation: none; opacity: 0.55; }
}

/* ========== v2.0 Agent 新增样式 ========== */

.chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 0;
  border-top: 1px solid rgba(140, 130, 180, 0.08);
}
.chat-quick-btn {
  padding: 5px 10px;
  background: rgba(139, 127, 200, 0.08);
  border: 1px solid rgba(139, 127, 200, 0.2);
  border-radius: 999px;
  color: rgba(220, 214, 240, 0.9);
  font-size: 11px;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 160ms var(--chat-ease), border-color 160ms var(--chat-ease), transform 120ms var(--chat-ease);
}
.chat-quick-btn:hover {
  background: rgba(139, 127, 200, 0.18);
  border-color: rgba(139, 127, 200, 0.45);
}
.chat-quick-btn:active { transform: scale(0.96); }

.chat-tool-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 4px 0;
  background: rgba(139, 127, 200, 0.06);
  border: 1px solid rgba(139, 127, 200, 0.15);
  border-radius: 10px;
  font-size: 12px;
  color: rgba(200, 192, 228, 0.85);
  animation: toolIn 0.25s var(--chat-ease) both;
}
.chat-tool-status.done {
  background: rgba(34, 197, 94, 0.06);
  border-color: rgba(34, 197, 94, 0.18);
  color: rgba(134, 239, 172, 0.85);
}
.chat-tool-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-purple);
  box-shadow: 0 0 6px var(--chat-purple-glow);
  animation: chatDot 1.2s var(--chat-ease) infinite;
}
.chat-tool-status.done .chat-tool-dot {
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.7);
  animation: none;
}
@keyframes toolIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.chat-card { margin: 6px 0; animation: toolIn 0.3s var(--chat-ease) both; }

.chat-card-projects { display: flex; flex-direction: column; gap: 8px; }
.chat-project-card {
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  transition: border-color 160ms var(--chat-ease), background 160ms var(--chat-ease);
}
.chat-project-card:hover {
  border-color: rgba(139, 127, 200, 0.35);
  background: rgba(139, 127, 200, 0.05);
}
.chat-project-title { font-size: 13px; font-weight: 600; color: var(--chat-text); margin-bottom: 3px; }
.chat-project-short { font-size: 11px; color: var(--chat-text-muted); line-height: 1.5; margin-bottom: 7px; }
.chat-project-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.chat-project-open {
  width: 100%;
  padding: 6px;
  background: linear-gradient(135deg, rgba(139, 127, 200, 0.15), rgba(107, 95, 160, 0.15));
  border: 1px solid rgba(139, 127, 200, 0.3);
  border-radius: 8px;
  color: var(--chat-purple-light);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 160ms var(--chat-ease), transform 120ms var(--chat-ease);
}
.chat-project-open:hover { background: linear-gradient(135deg, rgba(139, 127, 200, 0.3), rgba(107, 95, 160, 0.3)); }
.chat-project-open:active { transform: scale(0.98); }

.chat-card-skills { display: flex; flex-direction: column; gap: 10px; }
.chat-skill-section { padding: 8px 10px; background: rgba(255, 255, 255, 0.025); border-radius: 10px; }
.chat-skill-label { font-size: 11px; font-weight: 600; color: rgba(200, 192, 228, 0.9); letter-spacing: 0.06em; margin-bottom: 6px; }
.chat-skill-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.chat-tag {
  display: inline-block;
  padding: 3px 8px;
  background: rgba(139, 127, 200, 0.1);
  border: 1px solid rgba(139, 127, 200, 0.2);
  border-radius: 6px;
  font-size: 10px;
  color: rgba(220, 214, 240, 0.85);
  line-height: 1.4;
}

/* 技能标签云（紧凑版） */
.chat-card-skills-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
}
.chat-skill-tag {
  display: inline-block;
  padding: 4px 10px;
  background: rgba(139, 127, 200, 0.08);
  border: 1px solid rgba(139, 127, 200, 0.18);
  border-radius: 999px;
  font-size: 11px;
  color: rgba(220, 214, 240, 0.9);
  line-height: 1.4;
  transition: background 160ms, border-color 160ms;
}
.chat-skill-tag:hover {
  background: rgba(139, 127, 200, 0.18);
  border-color: rgba(139, 127, 200, 0.4);
}

.chat-card-contact {
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--chat-border);
  border-radius: 12px;
}
.chat-contact-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid rgba(140, 130, 180, 0.08);
  font-size: 12px;
}
.chat-contact-row:last-child { border-bottom: none; }
.chat-contact-label { color: var(--chat-text-muted); flex-shrink: 0; }
.chat-contact-value { color: rgba(220, 214, 240, 0.95); text-align: right; word-break: break-all; margin-left: 12px; }
a.chat-contact-value { text-decoration: none; color: var(--chat-purple-light); }
a.chat-contact-value:hover { text-decoration: underline; }

.chat-msg.system {
  background: transparent;
  border: none;
  max-width: 100%;
  text-align: center;
  padding: 4px 0;
  margin-bottom: 8px;
}
.chat-msg.system .chat-msg-content { font-size: 11px; color: var(--chat-text-muted); letter-spacing: 0.02em; }
.chat-msg.system .chat-time { display: none; }

.chat-send.stop {
  background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
  box-shadow: 0 4px 14px rgba(185, 28, 28, 0.3);
}

@media (prefers-reduced-motion: reduce) {
  .chat-tool-status, .chat-card { animation: none; }
  .chat-tool-dot { animation: none; opacity: 0.7; }
}

@media (max-width: 768px) {
  #chat-panel {
    left: 12px;
    right: 12px;
    top: 74px;
    width: auto;
    max-width: none;
    height: min(60vh, 520px);
    transform-origin: top center;
  }
  .chat-quick-btn { font-size: 10px; padding: 4px 8px; }
  .chat-resize-handle { display: none; }
}
