:root {
  --bg: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #242424;
  --text: #e8e8e8;
  --text-secondary: #888;
  --accent: #7c5cfc;
  --accent-light: #9d85fd;
  --user-bubble: #7c5cfc;
  --ai-bubble: #1e1e1e;
  --border: rgba(255,255,255,0.08);
  --radius: 14px;
  --font: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --sidebar-width: 280px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ===== 登录页 ===== */
.auth-wrapper {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; padding: 20px; background: var(--bg);
}
.auth-card {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 16px; padding: 40px; width: 100%; max-width: 380px;
}
.auth-card h2 { text-align: center; margin-bottom: 6px; font-size: 1.4rem; }
.auth-card .sub { text-align: center; color: var(--text-secondary); font-size: 0.85rem; margin-bottom: 24px; }
.auth-card .switch { text-align: center; margin-top: 16px; font-size: 0.85rem; color: var(--text-secondary); }
.auth-card .switch a { color: var(--accent-light); cursor: pointer; text-decoration: none; }

/* ===== 表单 ===== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 4px; }
.form-group input, .form-group textarea, .form-group select {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-tertiary);
  color: var(--text); font-size: 0.9rem; font-family: var(--font); outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group textarea:focus { border-color: var(--accent); }
.form-group textarea { resize: vertical; min-height: 60px; }

.btn {
  display: inline-block; padding: 10px 20px; border-radius: 10px; border: none;
  background: var(--accent); color: #fff; font-size: 0.9rem; cursor: pointer;
  transition: all 0.2s; font-family: var(--font);
}
.btn:hover { background: var(--accent-light); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-tertiary); color: var(--text); }
.btn-danger { background: #ef4444; }
.btn-danger:hover { background: #dc2626; }

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

/* ===== 侧边栏（对话列表） ===== */
.sidebar {
  width: var(--sidebar-width); min-width: var(--sidebar-width);
  background: var(--bg-secondary); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; transition: margin-left 0.3s;
}
.sidebar.collapsed { margin-left: calc(var(--sidebar-width) * -1); }
.sidebar-header {
  padding: 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-header h3 { font-size: 0.95rem; }
.conv-list { flex: 1; overflow-y: auto; padding: 8px; }
.conv-item {
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  margin-bottom: 4px; transition: background 0.2s;
  display: flex; align-items: center; justify-content: space-between;
}
.conv-item:hover { background: var(--bg-tertiary); }
.conv-item.active { background: var(--accent); color: #fff; }
.conv-item .title { font-size: 0.88rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .del { opacity: 0; font-size: 0.8rem; cursor: pointer; padding: 2px 6px; border-radius: 4px; transition: all 0.2s; }
.conv-item:hover .del { opacity: 1; }
.conv-item .del:hover { background: rgba(239,68,68,0.3); }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }

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

/* 顶部栏 */
.topbar {
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-secondary); min-height: 52px;
}
.topbar-btn {
  width: 36px; height: 36px; border-radius: 8px; border: none;
  background: transparent; color: var(--text-secondary); font-size: 1.1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.topbar-btn:hover { background: var(--bg-tertiary); color: var(--text); }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title .title { font-size: 0.95rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title .model { font-size: 0.75rem; color: var(--text-secondary); }

/* 消息列表 */
.messages {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 16px;
}
.msg { display: flex; gap: 10px; max-width: 85%; position: relative; }
.msg:hover .speak-btn-inline { opacity: 1 !important; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700;
}
.msg.user .avatar { background: var(--accent); }
.msg.ai .avatar { background: var(--bg-tertiary); border: 1px solid var(--border); }
.msg .bubble {
  padding: 10px 14px; border-radius: var(--radius); font-size: 0.9rem;
  line-height: 1.7; white-space: pre-wrap; word-break: break-word;
}
.msg.user .bubble { background: var(--user-bubble); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai .bubble { background: var(--ai-bubble); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.ai .bubble.error { border-color: #ef4444; color: #f87171; }
.msg .bubble code { background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 4px; font-size: 0.85em; }
.msg .bubble pre { background: rgba(0,0,0,0.3); padding: 10px; border-radius: 8px; overflow-x: auto; margin: 8px 0; }
.msg .bubble pre code { background: none; padding: 0; }

/* 输入区 */
.input-area {
  padding: 12px 16px 16px; border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}
.input-row { display: flex; gap: 8px; align-items: flex-end; }
.input-row textarea {
  flex: 1; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg-tertiary);
  color: var(--text); font-size: 0.9rem; font-family: var(--font);
  resize: none; outline: none; max-height: 150px; min-height: 42px;
  transition: border-color 0.2s;
}
.input-row textarea:focus { border-color: var(--accent); }
.send-btn {
  width: 42px; height: 42px; border-radius: 12px; border: none;
  background: var(--accent); color: #fff; font-size: 1.1rem;
  cursor: pointer; transition: all 0.2s; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:hover { background: var(--accent-light); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.stop-btn { background: #ef4444; }
.stop-btn:hover { background: #dc2626; }

/* ===== 设置面板（从上滑出） ===== */
.settings-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 300;
  opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.settings-overlay.open { opacity: 1; pointer-events: auto; }
.settings-panel {
  position: fixed; top: 0; left: 0; right: 0; z-index: 301;
  background: var(--bg-secondary); border-bottom: 1px solid var(--border);
  transform: translateY(-100%); transition: transform 0.35s cubic-bezier(0.4,0,0.2,1);
  max-height: 80vh; overflow-y: auto; padding: 20px;
}
.settings-panel.open { transform: translateY(0); }
.settings-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.settings-tab {
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--text-secondary); font-size: 0.85rem;
  cursor: pointer; transition: all 0.2s;
}
.settings-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.settings-content { display: none; }
.settings-content.active { display: block; }
.settings-close {
  position: absolute; top: 16px; right: 16px; width: 32px; height: 32px;
  border-radius: 8px; border: none; background: var(--bg-tertiary);
  color: var(--text-secondary); font-size: 1rem; cursor: pointer;
}

/* 供应商卡片 */
.provider-card {
  padding: 14px; border-radius: 10px; border: 1px solid var(--border);
  margin-bottom: 10px; display: flex; align-items: center; gap: 12px;
}
.provider-card .info { flex: 1; }
.provider-card .info .name { font-size: 0.9rem; font-weight: 600; }
.provider-card .info .url { font-size: 0.75rem; color: var(--text-secondary); }
.provider-card .actions { display: flex; gap: 6px; }
.active-badge { padding: 2px 8px; border-radius: 4px; font-size: 0.7rem; background: rgba(34,197,94,0.2); color: #4ade80; }

/* 空状态 */
.empty-state { text-align: center; padding: 40px; color: var(--text-secondary); }
.empty-state .icon { font-size: 2.5rem; margin-bottom: 10px; }

/* ===== Toggle Switch ===== */
#aiThemeToggle:checked + span { background: var(--accent); }
#aiThemeToggle:checked ~ #aiThemeDot { left: 22px; }

/* ===== Toast ===== */
.toast {
  position: fixed; top: 16px; right: 16px; padding: 10px 18px;
  border-radius: 10px; background: var(--bg-tertiary); border: 1px solid var(--border);
  color: var(--text); font-size: 0.85rem; z-index: 500;
  animation: slideDown 0.3s ease;
}
.toast.error { border-color: #ef4444; color: #f87171; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ===== 欢迎页 ===== */
.welcome {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-secondary);
}
.welcome .logo { font-size: 3.5rem; margin-bottom: 16px; }
.welcome h2 { font-size: 1.3rem; color: var(--text); margin-bottom: 6px; }
.welcome p { font-size: 0.88rem; }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 200; margin-left: calc(var(--sidebar-width) * -1); }
  .sidebar.open { margin-left: 0; }
  .sidebar.collapsed { margin-left: calc(var(--sidebar-width) * -1); }
  .sidebar-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 199;
    opacity: 0; pointer-events: none; transition: opacity 0.3s;
  }
  .sidebar-overlay.open { opacity: 1; pointer-events: auto; }
  .settings-panel { max-height: 90vh; }
}
