/**
 * 聊天页面样式
 * 使用 clawpanel CSS 变量
 */

/* 页面布局 - 双栏 */
.chat-page {
  display: flex;
  flex-direction: row;
  height: 100%;
  overflow: hidden;
  padding: 0 !important;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* 会话侧边栏 */
.chat-sidebar {
  width: 220px;
  border-right: 1px solid var(--border);
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.chat-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.chat-sidebar-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
}

.chat-sidebar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* 顶部栏 */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-status {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.chat-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

/* 状态指示点 */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted, #999);
  flex-shrink: 0;
}

.status-dot.online {
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

.status-dot.connecting {
  background: #f59e0b;
  animation: pulse-dot 1.2s ease-in-out infinite;
}

.status-dot.offline {
  background: #ef4444;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* 消息区域 */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

/* 消息通用 */
.msg {
  display: flex;
  max-width: 85%;
  animation: msg-in 0.2s ease-out;
}

.msg-user {
  align-self: flex-end;
}

.msg-ai {
  align-self: flex-start;
}

.msg-system {
  align-self: center;
  font-size: 12px;
  color: var(--text-muted, #999);
  padding: var(--space-xs) var(--space-sm);
  max-width: 100%;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 消息气泡 */
.msg-bubble {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg, 12px);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.msg-user .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-ai .msg-bubble {
  background: var(--bg-secondary, var(--bg-card));
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

/* AI 气泡内 Markdown 排版 */
.msg-ai .msg-bubble p {
  margin: 0 0 8px 0;
}

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

.msg-ai .msg-bubble h1,
.msg-ai .msg-bubble h2,
.msg-ai .msg-bubble h3 {
  margin: 12px 0 6px 0;
  font-weight: 600;
}

.msg-ai .msg-bubble h1 { font-size: 1.2em; }
.msg-ai .msg-bubble h2 { font-size: 1.1em; }
.msg-ai .msg-bubble h3 { font-size: 1em; }

.msg-ai .msg-bubble ul,
.msg-ai .msg-bubble ol {
  margin: 4px 0;
  padding-left: 20px;
}

.msg-ai .msg-bubble li {
  margin: 2px 0;
}

.msg-ai .msg-bubble a {
  color: var(--accent);
  text-decoration: none;
}

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

/* 代码块 */
.msg-ai .msg-bubble pre {
  background: var(--bg-primary, #1a1a2e);
  border-radius: var(--radius-md, 8px);
  padding: 0;
  margin: 8px 0;
  overflow: hidden;
  position: relative;
  font-size: 13px;
}

.msg-ai .msg-bubble pre code {
  display: block;
  padding: 12px 14px;
  overflow-x: auto;
  line-height: 1.5;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

.msg-ai .msg-bubble pre .code-lang {
  position: absolute;
  top: 6px;
  left: 12px;
  font-size: 11px;
  color: var(--text-muted, #888);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.msg-ai .msg-bubble pre .code-copy-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.msg-ai .msg-bubble pre:hover .code-copy-btn {
  opacity: 1;
}

.msg-ai .msg-bubble pre .code-copy-btn:hover {
  background: var(--bg-hover);
}

/* 代码高亮 */
.hl-keyword { color: #c678dd; }
.hl-string { color: #98c379; }
.hl-comment { color: #5c6370; font-style: italic; }
.hl-number { color: #d19a66; }
.hl-func { color: #61afef; }
.hl-type { color: #e5c07b; }

/* 行内代码 */
.msg-ai .msg-bubble > code {
  background: var(--bg-hover, rgba(255,255,255,0.08));
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* 流式光标 */
.stream-cursor::after {
  content: '▊';
  animation: blink-cursor 0.8s step-end infinite;
  color: var(--accent);
}

@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* 打字指示器 */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  align-self: flex-start;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted, #888);
  animation: typing-bounce 1.4s ease-in-out infinite;
}

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

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* 输入区域 */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-primary);
}

.chat-input-wrapper {
  flex: 1;
  min-width: 0;
}

.chat-input-wrapper textarea {
  width: 100%;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg-secondary, var(--bg-card));
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
  max-height: 150px;
  font-family: inherit;
}

.chat-input-wrapper textarea:focus {
  border-color: var(--accent);
}

.chat-input-wrapper textarea::placeholder {
  color: var(--text-muted, #888);
}

/* 发送按钮 */
.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md, 8px);
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, background 0.15s;
}

.chat-send-btn:hover:not(:disabled) {
  opacity: 0.85;
}

.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 回到底部按钮 */
.chat-scroll-btn {
  position: absolute;
  bottom: 80px;
  right: 24px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: opacity 0.15s;
  z-index: 10;
}

.chat-scroll-btn:hover {
  background: var(--bg-hover);
}

/* 断连横幅 */
.chat-disconnect-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  background: #f59e0b;
  color: #000;
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
}

/* 会话列表 */
.chat-session-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.chat-session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-md, 6px);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: background 0.12s;
}

.chat-session-item:hover {
  background: var(--bg-hover);
}

.chat-session-item.active {
  background: var(--bg-hover);
  color: var(--text-primary);
  font-weight: 500;
}

.chat-session-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.chat-session-del {
  background: none;
  border: none;
  color: var(--text-muted, #999);
  cursor: pointer;
  font-size: 16px;
  padding: 0 2px;
  opacity: 0;
  transition: opacity 0.12s;
  flex-shrink: 0;
}

.chat-session-item:hover .chat-session-del {
  opacity: 1;
}

.chat-session-del:hover {
  color: #ef4444;
}

.chat-session-empty {
  text-align: center;
  color: var(--text-muted, #999);
  font-size: 12px;
  padding: 20px 0;
}

/* 头部操作区 */
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-toggle-sidebar {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
}

.chat-toggle-sidebar:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* 快捷指令面板 */
.chat-cmd-panel {
  position: absolute;
  bottom: 70px;
  left: var(--space-md);
  right: var(--space-md);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  max-height: 280px;
  overflow-y: auto;
  padding: 6px;
  z-index: 20;
}

.cmd-group-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted, #888);
  padding: 6px 8px 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cmd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s;
}

.cmd-item:hover {
  background: var(--bg-hover);
}

.cmd-name {
  color: var(--accent);
  font-family: 'SF Mono', monospace;
  font-size: 12px;
  min-width: 100px;
}

.cmd-desc {
  color: var(--text-secondary);
}

/* 文件上传 */
.chat-attach-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.chat-attach-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.chat-attachments-preview {
  display: flex;
  gap: 8px;
  padding: 8px;
  flex-wrap: wrap;
}

.chat-attachment-item {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.chat-attachment-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-attachment-del {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-attachment-del:hover {
  background: rgba(255,0,0,0.8);
}
