/* ========== 全局样式 ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-user: #059669;
  --bg-assistant: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #10b981;
  --accent-hover: #059669;
  --border: #334155;
  --sidebar-width: 280px;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* ========== 布局 ========== */
.app {
  display: flex;
  height: 100vh;
}

/* 侧边栏 */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  z-index: 100;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
  background: linear-gradient(135deg, #10b981, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  animation: pulse 2s infinite;
}

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

.new-chat-btn {
  margin: 12px;
  padding: 10px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s;
}

.new-chat-btn:hover {
  background: var(--accent-hover);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conversation-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  font-size: 14px;
  color: var(--text-secondary);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.conversation-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.conversation-item.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.conv-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.conv-del {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}

.conversation-item:hover .conv-del {
  display: flex;
}

.conv-del:hover {
  background: rgba(255,80,80,0.2);
  color: #ef4444;
}

/* 侧边栏底部 - 改造成两行按钮组 */
.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-footer .row {
  display: flex;
  gap: 6px;
}

.sidebar-footer .row .footer-btn {
  flex: 1;
  padding: 6px 0;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: none;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  white-space: nowrap;
}

.sidebar-footer .row .footer-btn:hover {
  background: var(--accent);
  color: white;
}

.sidebar-footer .row .footer-btn.danger:hover {
  background: #dc2626;
  color: white;
}

/* 主聊天区 */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
}

.menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

.chat-header-title {
  font-size: 15px;
  font-weight: 500;
}

.chat-header-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* 消息区域 */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 80%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.message.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.6;
  font-size: 14px;
  word-wrap: break-word;
}

.message.user .message-bubble {
  background: var(--bg-user);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--bg-assistant);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

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

/* Markdown 样式 */
.message-bubble p { margin-bottom: 8px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble code {
  background: rgba(0,0,0,0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}
.message-bubble pre {
  background: #0d1117 !important;
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.message-bubble pre code {
  background: none;
  padding: 0;
}
.message-bubble ul, .message-bubble ol {
  margin-left: 20px;
  margin-bottom: 8px;
}

/* 打字光标 */
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 16px;
  background: var(--accent);
  margin-left: 2px;
  animation: blink 1s infinite;
  vertical-align: middle;
}

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

/* 思考指示器 */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.thinking-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: thinking-bounce 1.4s ease-in-out infinite;
}

.thinking-dot:nth-child(1) { animation-delay: 0s; }
.thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.thinking-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: 4px;
}

/* 输入区域 */
.input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.input-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 800px;
  margin: 0 auto;
}

.input-box {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  resize: none;
  outline: none;
  font-family: inherit;
  line-height: 1.5;
  max-height: 120px;
  transition: border-color 0.2s;
}

.input-box:focus {
  border-color: var(--accent);
}

.send-btn {
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:disabled {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* v6.0: 协作模式按钮 */
.orchestrate-btn {
  padding: 6px 12px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.orchestrate-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.orchestrate-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* v6.0: 协作进度提示 */
.progress-banner {
  padding: 8px 12px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 8px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 遮罩（移动端侧边栏） */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
}

.overlay.show { display: block; }

/* ========== 模态框通用 ========== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.show { display: flex; }

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 700px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-content.wide {
  max-width: 900px;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* 设置弹窗内部 */
.setting-section {
  margin-bottom: 24px;
}
.setting-section h3 {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 500;
}
.model-card {
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.model-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.model-status.ready { background: #10b981; }
.model-status.unavailable { background: #64748b; }

.model-info {
  flex: 1;
}
.model-name {
  font-size: 14px;
  font-weight: 500;
}
.model-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.system-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.info-card {
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: 8px;
}
.info-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.info-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

/* ========== 技能库 & 沙盒文件 样式 ========== */
.skill-card {
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  margin-bottom: 10px;
  border-left: 3px solid var(--accent);
}
.skill-card .skill-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
}
.skill-card .skill-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.skill-card .skill-tools {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.sandbox-file {
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background 0.2s;
}
.sandbox-file:hover {
  background: var(--border);
}
.sandbox-file .file-name {
  font-size: 14px;
  font-family: monospace;
}
.sandbox-file .file-size {
  font-size: 12px;
  color: var(--text-muted);
}
.sandbox-file .file-action {
  font-size: 12px;
  color: var(--accent);
}

.file-content-box {
  background: #0d1117;
  border-radius: 8px;
  padding: 12px;
  font-family: monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 300px;
  overflow-y: auto;
  margin-top: 8px;
}

/* 欢迎页面 */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}

.welcome-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.welcome h2 {
  font-size: 24px;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #10b981, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome p {
  color: var(--text-muted);
  font-size: 14px;
  max-width: 400px;
  line-height: 1.6;
}

.welcome-tips {
  margin-top: 32px;
  display: grid;
  gap: 12px;
  max-width: 500px;
  width: 100%;
}

.tip-card {
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}

.tip-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.tip-card strong {
  display: block;
  font-size: 14px;
  margin-bottom: 4px;
}

.tip-card span {
  font-size: 12px;
  color: var(--text-muted);
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .menu-btn {
    display: block;
  }
  
  .message {
    max-width: 90%;
  }
  
  .input-area {
    padding: 12px;
  }
  
  .messages {
    padding: 12px;
  }

  .modal-content {
    max-width: 100%;
    max-height: 90vh;
    margin: 10px;
  }
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
