:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-sidebar: #f7f7f8;
  --bg-message-user: #f0f7ff;
  --bg-message-assistant: #ffffff;
  --border-color: #e5e5e5;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --text-muted: #999999;
  --accent-color: #2563eb;
  --accent-hover: #1d4ed8;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --code-bg: #1e1e1e;
}

[data-theme="dark"] {
  --bg-primary: #1a1a1a;
  --bg-secondary: #242424;
  --bg-sidebar: #1e1e1e;
  --bg-message-user: #1e3a5f;
  --bg-message-assistant: #2a2a2a;
  --border-color: #333333;
  --text-primary: #e8e8e8;
  --text-secondary: #b0b0b0;
  --text-muted: #888888;
  --accent-color: #3b82f6;
  --accent-hover: #60a5fa;
  --code-bg: #0d0d0d;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

.app {
  display: flex;
  height: 100vh;
}

/* ========== 侧边栏 ========== */
.sidebar {
  width: 280px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 16px;
  flex-shrink: 0;
  transition: width 0.25s ease, padding 0.25s ease, opacity 0.25s ease;
  overflow: hidden;
  opacity: 1;
}

.sidebar.collapsed {
  width: 0;
  padding: 0;
  border-right: none;
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  margin-bottom: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.logo-icon {
  font-size: 28px;
}

.logo-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.new-chat-btn {
  width: 100%;
  padding: 10px 14px;
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.2s;
}

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

.model-selector {
  margin-bottom: 20px;
}

.model-selector label,
.quick-prompts label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.model-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.model-check {
  cursor: pointer;
  display: block;
}

.model-check input {
  display: none;
}

.model-check-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  position: relative;
}

.model-check-box:hover {
  background: var(--bg-secondary);
}

.model-check input:checked + .model-check-box {
  border-color: var(--accent-color);
  background: rgba(37, 99, 235, 0.06);
}

.model-check .check-mark {
  margin-left: auto;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--border-color);
  color: transparent;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.model-check input:checked + .model-check-box .check-mark {
  background: var(--accent-color);
  color: white;
}

.model-icon {
  font-size: 20px;
}

.model-info {
  display: flex;
  flex-direction: column;
}

.model-name {
  font-size: 14px;
  font-weight: 600;
}

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

.quick-prompts {
  flex: 1;
  overflow-y: auto;
}

.quick-btn {
  display: block;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}

.quick-btn:hover {
  background: var(--bg-primary);
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.chat-history {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
}

.chat-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  margin-bottom: 8px;
  user-select: none;
}

.chat-history-header label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0;
  cursor: pointer;
}

.history-toggle-icon {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.chat-history.collapsed .history-toggle-icon {
  transform: rotate(-90deg);
}

.chat-history-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  transition: max-height 0.2s ease, opacity 0.2s ease;
  opacity: 1;
}

.chat-history.collapsed .chat-history-list {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  gap: 6px;
  border-left: 3px solid transparent;
}

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

.history-item.active {
  background: rgba(37, 99, 235, 0.08);
  border-left-color: var(--accent-color);
}

.history-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}

.history-title {
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.history-delete {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}

.history-item:hover .history-delete {
  opacity: 1;
}

.history-delete:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ========== 聊天区域 ========== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.current-model {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.current-model span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: var(--bg-secondary);
}

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

.messages-container.hidden {
  display: none !important;
}

/* 单栏模式 */
.messages-container.single-view {
  display: flex;
  flex-direction: column;
}

/* 多栏模式 */
.messages-container.multi-view {
  display: flex;
  flex-direction: row;
  padding: 0;
  gap: 0;
}

.multi-pane {
  flex: 1;
  display: none;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--border-color);
}

.multi-pane.visible {
  display: flex;
}

.multi-pane:last-child.visible {
  border-right: none;
}

.pane-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pane-badge {
  font-size: 13px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pane-badge.codex {
  background: rgba(37, 99, 235, 0.1);
  color: var(--accent-color);
}

.pane-badge.deepseek {
  background: rgba(139, 92, 246, 0.1);
  color: #8b5cf6;
}

[data-theme="dark"] .pane-badge.deepseek {
  color: #a78bfa;
}

.pane-badge.kimi {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
}

[data-theme="dark"] .pane-badge.kimi {
  color: #34d399;
}

.pane-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Welcome 消息 */
.welcome-message {
  text-align: center;
  max-width: 600px;
  margin: 40px auto;
}

.welcome-message.compact {
  margin: 20px auto;
}

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

.welcome-message.compact .welcome-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.welcome-message h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.welcome-message > p {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.welcome-message.compact > p {
  font-size: 14px;
  margin-bottom: 0;
}

.welcome-features {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.feature {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--text-secondary);
}

.feature-icon {
  font-size: 20px;
}

.welcome-hint {
  font-size: 13px !important;
  color: var(--text-muted) !important;
}

/* 消息气泡 */
.message {
  display: flex;
  gap: 12px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  animation: fadeIn 0.3s ease;
}

.multi-pane .message {
  max-width: 100%;
}

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

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: var(--accent-color);
  color: white;
  order: 2;
}

.message.assistant .message-avatar {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
}

.message-content {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}

.message.user .message-content {
  background: var(--bg-message-user);
  border: 1px solid rgba(37, 99, 235, 0.15);
}

.message.assistant .message-content {
  background: var(--bg-message-assistant);
  border: 1px solid var(--border-color);
}

/* Markdown 样式 */
.message-content p {
  margin-bottom: 10px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content pre {
  background: var(--code-bg);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  margin: 10px 0;
}

.message-content pre code {
  background: none;
  padding: 0;
  font-size: 12px;
  line-height: 1.6;
  font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
}

.message-content code {
  background: rgba(0,0,0,0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
}

[data-theme="dark"] .message-content code {
  background: rgba(255,255,255,0.08);
}

.message-content ul,
.message-content ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-content li {
  margin: 3px 0;
}

.message-content h1,
.message-content h2,
.message-content h3 {
  margin: 14px 0 8px;
  font-weight: 600;
}

.message-content h1 { font-size: 18px; }
.message-content h2 { font-size: 16px; }
.message-content h3 { font-size: 15px; }

.message-content blockquote {
  border-left: 3px solid var(--accent-color);
  padding-left: 12px;
  margin: 10px 0;
  color: var(--text-secondary);
}

.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
}

.message-content th,
.message-content td {
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  text-align: left;
}

.message-content th {
  background: var(--bg-secondary);
  font-weight: 600;
}

/* 代码块复制按钮 */
.code-block-wrapper {
  position: relative;
}

.code-block-wrapper .copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 3px 8px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  color: #ccc;
  font-size: 11px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}

.code-block-wrapper:hover .copy-btn {
  opacity: 1;
}

.code-block-wrapper .copy-btn:hover {
  background: rgba(255,255,255,0.2);
}

/* 思考中动画 */
.thinking {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 13px;
}

.thinking-dots span {
  display: inline-block;
  width: 5px;
  height: 5px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

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

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ========== 输入区 ========== */
.input-area {
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-primary);
  flex-shrink: 0;
}

.input-box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  max-width: 900px;
  margin: 0 auto;
  transition: border-color 0.2s;
}

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

.input-box textarea {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 15px;
  color: var(--text-primary);
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 200px;
  font-family: inherit;
}

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

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

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

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

.send-btn svg {
  width: 18px;
  height: 18px;
}

.input-footer {
  display: flex;
  justify-content: space-between;
  max-width: 900px;
  margin: 8px auto 0;
  font-size: 12px;
  color: var(--text-muted);
}

#status {
  font-weight: 500;
}

.status-thinking {
  color: var(--accent-color);
}

/* 滚动条 */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

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

::-webkit-scrollbar-thumb {
  background: #cccccc;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #aaaaaa;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: #444444;
}

/* 响应式 */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
  
  .welcome-features {
    grid-template-columns: 1fr;
  }
  
  .messages-container.multi-view {
    flex-direction: column;
  }
  
  .multi-pane {
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    max-height: 50vh;
  }
  
  .multi-pane:last-child.visible {
    border-bottom: none;
  }
}
