/* ========== Chat 滑出面板样式 ========== */
/* 浅色精致：左右分列（user 右 / assistant 左）+ 圆形头像 + 阴影 */

.chat-panel {
  position: fixed;
  top: calc(var(--floating-offset) + var(--topbar-height) + 12px);
  right: var(--floating-offset);
  bottom: var(--floating-offset);
  width: var(--chat-panel-width);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  z-index: 300;
  transform: translateX(calc(100% + var(--floating-offset) + 12px));
  transition: transform var(--duration-normal) var(--ease-smooth);
  overflow: hidden;
}

.chat-panel.visible {
  transform: translateX(0);
}

/* ---- 遮罩 ---- */

.chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.20);
  z-index: 250;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-normal) var(--ease-smooth);
}

.chat-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ---- 头部 ---- */

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.chat-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--font-lg);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.005em;
}

.chat-panel-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
}

.chat-panel-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: 
    color var(--duration-normal) var(--ease-smooth),
    background var(--duration-normal) var(--ease-smooth);
}

.chat-panel-close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ---- 年报上传区（助手独立 session） ---- */

#chat-upload-area {
  flex-shrink: 0;
  padding: var(--space-md) var(--space-xl);
  border-bottom: 1px solid var(--border-subtle);
}

/* 未上传态：虚线上传按钮 */
.chat-upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border: 1.5px dashed var(--border-default);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-tertiary);
  font-size: var(--font-sm);
  cursor: pointer;
  transition:
    border-color var(--duration-normal) var(--ease-smooth),
    color var(--duration-normal) var(--ease-smooth),
    background var(--duration-normal) var(--ease-smooth);
}

.chat-upload-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: rgba(255, 230, 0, 0.06);
}

/* 已上传态：文件名 + 更换 + 删除 */
.chat-upload-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.chat-upload-file-icon {
  flex-shrink: 0;
  color: var(--brand);
}

.chat-upload-name {
  flex: 1;
  min-width: 0;
  font-size: var(--font-sm);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-upload-action {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-size: var(--font-sm);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: color var(--duration-normal) var(--ease-smooth);
}

.chat-upload-action:hover {
  color: var(--text-primary);
}

.chat-upload-del {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
}

.chat-upload-del:hover {
  color: #d33;
}

/* 上传中态 */
.chat-upload-loading {
  text-align: center;
  padding: 10px;
  font-size: var(--font-sm);
  color: var(--text-tertiary);
}

/* ---- 消息区 ---- */

.chat-panel-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xl) var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

.chat-panel-messages::-webkit-scrollbar {
  width: 4px;
}
.chat-panel-messages::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 2px;
}

.chat-welcome {
  text-align: center;
  padding: var(--space-3xl) var(--space-md);
  color: var(--text-tertiary);
}

.chat-welcome p {
  font-size: var(--font-md);
  line-height: 1.7;
}

/* ---- 消息：左右分列 ---- */

.chat-msg {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: fadeInUp var(--duration-normal) var(--ease-smooth) both;
}

/* AI 消息：左对齐（头像在左） */
.chat-msg.assistant {
  flex-direction: row;
  align-items: flex-start;
}

/* 用户消息：右对齐（头像在右） */
.chat-msg.user {
  flex-direction: row-reverse;
  align-items: flex-start;
}

/* ---- 圆形头像 + 阴影 ---- */

.chat-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-sm);
  font-weight: 600;
  background: var(--bg-subtle);
  color: var(--text-primary);
  box-shadow: 0 2px 6px rgba(120, 100, 60, 0.10), 0 1px 2px rgba(120, 100, 60, 0.06);
  transition: transform var(--duration-normal) var(--ease-smooth);
}

/* 助手头像两个字偏宽，缩小字号 */
.chat-msg.assistant .chat-avatar {
  font-size: 11px;
}

.chat-msg:hover .chat-avatar {
  transform: scale(1.05);
}

/* AI 头像：黄色装饰 */
.chat-msg.assistant .chat-avatar {
  background: var(--brand);
  color: var(--text-primary);
  border: 2px solid var(--bg-card);
  box-shadow: 
    0 2px 8px rgba(255, 230, 0, 0.25),
    0 0 0 1px rgba(255, 230, 0, 0.3);
}

/* 用户头像：米色调 */
.chat-msg.user .chat-avatar {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  box-shadow: 
    0 2px 6px rgba(120, 100, 60, 0.10),
    0 1px 2px rgba(120, 100, 60, 0.06);
}

/* ---- 消息气泡 ---- */

.chat-bubble {
  flex: 1;
  min-width: 0;
  font-size: var(--font-md);
  line-height: 1.7;
  color: var(--text-primary);
  overflow-wrap: break-word;
  padding: 10px 14px;
  background: var(--bg-subtle);
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  max-width: 80%;
}

.chat-msg.assistant .chat-bubble {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;  /* 头像方向小尖角 */
}

.chat-msg.user .chat-bubble {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-default);
  border-bottom-right-radius: 4px;
  box-shadow: 0 1px 2px rgba(120, 100, 60, 0.04);
}

/* ---- 气泡包裹层 + 时间戳 ---- */

.chat-bubble-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-bubble-wrap .chat-bubble {
  flex: none;
}

.chat-timestamp {
  font-size: 10px;
  color: var(--text-muted, #aaa);
  padding: 0 4px;
}

.chat-msg.assistant .chat-timestamp {
  align-self: flex-start;
}

.chat-msg.user .chat-timestamp {
  align-self: flex-end;
}

/* Markdown 渲染 */
.chat-bubble p {
  margin-bottom: var(--space-sm);
}
.chat-bubble p:last-child {
  margin-bottom: 0;
}
.chat-bubble code {
  font-family: var(--font-mono);
  font-size: var(--font-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}
.chat-bubble pre {
  background: var(--bg-card);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin-bottom: var(--space-sm);
  border: 1px solid var(--border-subtle);
}
.chat-bubble pre code {
  background: none;
  padding: 0;
}
.chat-bubble ul, .chat-bubble ol {
  padding-left: var(--space-lg);
  margin-bottom: var(--space-sm);
}

/* ---- 工具调用 ---- */

.chat-tool-call,
.chat-tool-result {
  margin: var(--space-md) 0;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: var(--font-sm);
}

.chat-tool-name {
  color: var(--brand);
  font-family: var(--font-mono);
  font-weight: 500;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-tool-name::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--brand);
}

.chat-tool-args {
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---- 打字指示器 ---- */

.chat-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
  animation: typingDot 1.4s var(--ease-smooth) infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

/* ---- 阶段状态条 ---- */

.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  margin: 2px 0 6px;
  font-size: 12px;
  color: var(--text-muted, #888);
  background: var(--bg-subtle, #f5f5f5);
  border-radius: 6px;
}

.chat-status.active::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand, #4f8cff);
  animation: statusPulse 1.2s ease-in-out infinite;
}

@keyframes statusPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ---- 查询信息（searching 补充） ---- */

.chat-search-info {
  font-size: 11px;
  color: var(--text-muted, #888);
  padding: 3px 10px;
  margin: 2px 0;
  line-height: 1.5;
}

/* ---- 输入区 ---- */

.chat-panel-input {
  padding: var(--space-md) var(--space-xl) var(--space-lg);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  background: var(--bg-page);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-sm) var(--space-md);
  transition: 
    border-color var(--duration-normal) var(--ease-smooth),
    box-shadow var(--duration-normal) var(--ease-smooth);
}

.chat-input-wrapper:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(255, 230, 0, 0.25);
}

#chat-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--font-md);
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 120px;
  padding: 4px 0;
}

#chat-input::placeholder {
  color: var(--text-tertiary);
}

.chat-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  border-radius: var(--radius-md);
  flex-shrink: 0;
  transition: 
    color var(--duration-normal) var(--ease-smooth),
    background var(--duration-normal) var(--ease-smooth);
}

.chat-send:hover {
  color: var(--text-primary);
  background: var(--brand);
}
