/* ── 基础变量 ──────────────────────────────── */
:root {
  --bg-primary: #0f0f0f;
  --bg-sidebar: #1a1a1a;
  --bg-chat: #0f0f0f;
  --bg-input: #1e1e1e;
  --bg-hover: #252525;
  --bg-active: #2a2a2a;
  --bg-user-msg: #1e3a5f;
  --bg-ai-msg: #1a1a1a;
  --bg-modal: #1e1e1e;
  --bg-overlay: rgba(0,0,0,0.6);
  --text-primary: #e8e8e8;
  --text-secondary: #888;
  --text-muted: #555;
  --accent: #5b8def;
  --accent-hover: #4a7de0;
  --accent-light: rgba(91,141,239,0.15);
  --border: #2a2a2a;
  --border-light: #333;
  --danger: #e74c3c;
  --success: #2ecc71;
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 280px;
  --header-h: 56px;
  --input-h: 80px;
  --transition: 0.2s ease;
}

/* ── 重置 ──────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
input, textarea, select, button { font-family: inherit; font-size: inherit; }

/* ── 应用布局 ──────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}
.hidden { display: none !important; }

/* ── 侧边栏 ────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition);
  z-index: 10;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 3px;
  background: linear-gradient(135deg, #5b8def, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.sidebar-actions {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.btn-settings {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-settings:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}
.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-track { background: transparent; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* 对话项 */
.conv-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 2px;
  position: relative;
  gap: 10px;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--bg-active); }
.conv-item .conv-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #5b8def, #7c5bef);
}
.conv-item .conv-info {
  flex: 1;
  min-width: 0;
}
.conv-item .conv-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}
.conv-item .conv-model {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item .pin-badge {
  flex-shrink: 0;
  font-size: 10px;
  color: var(--accent);
}
.conv-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 12px 12px 4px;
}
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.sidebar-footer .hint { font-size: 11px; color: var(--text-muted); }

/* ── 主区域 ────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.empty-icon { font-size: 64px; }
.empty-state h2 {
  font-size: 24px;
  font-weight: 600;
  background: linear-gradient(135deg, #5b8def, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.empty-state p { color: var(--text-secondary); text-align: center; line-height: 1.8; }

/* ── 对话容器 ──────────────────────────────── */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-header {
  display: flex;
  align-items: center;
  height: var(--header-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}
.chat-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-title .model-badge {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 8px;
}
.chat-actions {
  display: flex;
  gap: 4px;
}

/* ── 消息区 ────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.msg-row {
  display: flex;
  gap: 12px;
  padding: 12px 24px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  animation: msgIn 0.25s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  font-weight: 600;
  color: #fff;
}
.msg-row.user .msg-avatar { background: #2563eb; }
.msg-row.assistant .msg-avatar { background: linear-gradient(135deg, #7c3aed, #5b8def); }

.msg-bubble {
  max-width: 75%;
  padding: 10px 16px;
  border-radius: var(--radius);
  line-height: 1.7;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-row.user .msg-bubble {
  background: var(--bg-user-msg);
  border-bottom-right-radius: 4px;
}
.msg-row.assistant .msg-bubble {
  background: var(--bg-ai-msg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-bubble code {
  background: rgba(255,255,255,0.08);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 13px;
}
.msg-bubble pre {
  background: #111;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg-bubble pre code {
  background: none;
  padding: 0;
}

/* 流式光标 */
.streaming-cursor::after {
  content: '▊';
  animation: blink 0.8s infinite;
  color: var(--accent);
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── 输入区 ────────────────────────────────── */
.input-area {
  padding: 12px 24px 20px;
  flex-shrink: 0;
}
.input-wrapper {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 12px;
  transition: border-color var(--transition);
}
.input-wrapper:focus-within { border-color: var(--accent); }
.input-wrapper textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  resize: none;
  max-height: 150px;
  line-height: 1.5;
  padding: 4px 0;
}
.input-wrapper textarea::placeholder { color: var(--text-muted); }
.btn-send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-hover); transform: scale(1.05); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── 按钮 ──────────────────────────────────── */
.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-icon.active { color: var(--accent); }
.btn {
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-weight: 500;
  transition: all var(--transition);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

/* ── 弹窗 ──────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-overlay);
}
.modal-content {
  position: relative;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 480px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  animation: modalIn 0.2s ease;
}
.modal-sm { width: 380px; }
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { font-size: 22px !important; }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

/* ── 表单 ──────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition);
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus { border-color: var(--accent); }
.form-group textarea { resize: vertical; }
.form-group select { cursor: pointer; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; display: block; }

/* ── 移动端适配 ────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex !important; }
  .msg-bubble { max-width: 88%; }
  .msg-row { padding: 10px 14px; }
  .input-area { padding: 10px 12px 16px; }
}
@media (min-width: 769px) {
  .sidebar-toggle { display: none !important; }
}
