:root {
  --bg-0: #0b0a1f;
  --bg-1: #15123a;
  --bg-2: #1d1b4b;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.10);
  --text: #ecebff;
  --text-dim: #a9a6d6;
  --accent-1: #8b5cff;
  --accent-2: #3aa0ff;
  --user-bubble: linear-gradient(135deg, #7c5cff, #3aa0ff);
  --ai-bubble: rgba(255, 255, 255, 0.06);
  --radius: 18px;
  --sidebar-w: 270px;
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(124, 92, 255, 0.25), transparent 60%),
    radial-gradient(1000px 600px at 110% 10%, rgba(58, 160, 255, 0.20), transparent 55%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1) 55%, var(--bg-2));
  background-attachment: fixed;
  overflow: hidden;
}

.app {
  display: flex;
  height: 100dvh;
  width: 100%;
}

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: rgba(10, 8, 30, 0.55);
  backdrop-filter: blur(14px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 14px;
  transition: transform 0.28s ease;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.brand-avatar { width: 34px; height: 34px; border-radius: 50%; box-shadow: 0 4px 16px rgba(124, 92, 255, 0.5); }
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: 0.5px; }

.btn-new {
  border: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.25), rgba(58, 160, 255, 0.25));
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 12px;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.btn-new:hover { filter: brightness(1.12); transform: translateY(-1px); }
.btn-new:active { transform: translateY(0); }

.history { flex: 1 1 auto; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 2px; }
.history::-webkit-scrollbar { width: 6px; }
.history::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 6px; }
.hist-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: 12px; cursor: pointer;
  color: var(--text-dim); font-size: 14px; border: 1px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hist-item:hover { background: var(--panel); color: var(--text); }
.hist-item.active { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.hist-item .del { opacity: 0; color: #ff8a8a; font-size: 13px; margin-left: 8px; flex: 0 0 auto; }
.hist-item:hover .del { opacity: 0.8; }
.hist-empty { color: var(--text-dim); font-size: 13px; text-align: center; padding: 20px 6px; opacity: 0.6; }

.sidebar-foot { display: flex; flex-direction: column; gap: 10px; }
.btn-clear {
  border: 1px solid var(--border); background: transparent; color: #ff9a9a;
  font-size: 13px; padding: 9px; border-radius: 12px; cursor: pointer;
}
.btn-clear:hover { background: rgba(255, 120, 120, 0.12); }
.privacy-note { font-size: 11.5px; line-height: 1.6; color: var(--text-dim); opacity: 0.8; }

/* ---------- 主体 ---------- */
.main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; height: 100%; }
.topbar {
  display: none; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: rgba(10, 8, 30, 0.4); backdrop-filter: blur(10px);
}
.menu-btn {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  font-size: 18px; width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
}
.top-title { font-weight: 700; font-size: 16px; }

.chat {
  flex: 1 1 auto; overflow-y: auto; padding: 24px 16px 8px;
  display: flex; flex-direction: column; gap: 18px; scroll-behavior: smooth;
}
.chat::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 8px; }

/* 欢迎页 */
.welcome { margin: auto; text-align: center; max-width: 640px; padding: 10px; animation: fadeUp 0.5s ease; }
.welcome .avatar-big { width: 88px; height: 88px; border-radius: 50%; box-shadow: 0 10px 40px rgba(124, 92, 255, 0.55); margin-bottom: 18px; }
.welcome h1 { font-size: 26px; margin-bottom: 10px; background: linear-gradient(135deg, #b69bff, #79c0ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.welcome p { color: var(--text-dim); font-size: 16px; line-height: 1.7; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 22px; }
.chip {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 11px 16px; border-radius: 999px; font-size: 14px; cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.chip:hover { background: var(--panel-2); transform: translateY(-2px); }

/* 消息气泡 */
.msg { display: flex; gap: 12px; max-width: 860px; width: 100%; margin: 0 auto; animation: fadeUp 0.3s ease; }
.msg.user { flex-direction: row-reverse; }
.avatar-sm { width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 4px 14px rgba(124,92,255,0.4); }
.bubble {
  padding: 12px 16px; border-radius: var(--radius); line-height: 1.7; font-size: 15px;
  word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap;
}
.msg.user .bubble { background: var(--user-bubble); color: #fff; border-bottom-right-radius: 6px; }
.msg.ai .bubble { background: var(--ai-bubble); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg.ai .bubble.error { border-color: rgba(255,120,120,0.5); color: #ffb3b3; }
.msg.ai .bubble.config { border-color: rgba(255,200,80,0.5); color: #ffe0a0; }

/* AI 回复内的 Markdown 元素 */
.bubble h1, .bubble h2, .bubble h3 { margin: 10px 0 6px; line-height: 1.35; }
.bubble h1 { font-size: 20px; } .bubble h2 { font-size: 18px; } .bubble h3 { font-size: 16px; }
.bubble p { margin: 6px 0; }
.bubble ul { margin: 6px 0 6px 20px; }
.bubble li { margin: 3px 0; }
.bubble code { background: rgba(255,255,255,0.12); padding: 2px 6px; border-radius: 6px; font-size: 0.92em; font-family: ui-monospace, Menlo, Consolas, monospace; }
.bubble pre { background: rgba(0,0,0,0.35); border: 1px solid var(--border); padding: 12px; border-radius: 12px; overflow-x: auto; margin: 8px 0; }
.bubble pre code { background: none; padding: 0; }
.bubble blockquote { border-left: 3px solid var(--accent-1); padding-left: 12px; color: var(--text-dim); margin: 6px 0; }
.bubble a { color: #8fc1ff; }

/* 打字光标 */
.cursor::after { content: "▋"; margin-left: 1px; animation: blink 1s steps(2) infinite; color: var(--accent-2); }

/* 操作条 */
.actions { display: flex; gap: 8px; margin-top: 8px; }
.actions button {
  background: var(--panel); border: 1px solid var(--border); color: var(--text-dim);
  font-size: 12.5px; padding: 6px 12px; border-radius: 10px; cursor: pointer;
}
.actions button:hover { color: var(--text); background: var(--panel-2); }

/* ---------- 输入区 ---------- */
.composer { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: rgba(10, 8, 30, 0.4); backdrop-filter: blur(10px); }
.composer-box {
  max-width: 860px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 18px; padding: 8px 8px 8px 16px;
}
#input {
  flex: 1 1 auto; resize: none; border: none; outline: none; background: transparent;
  color: var(--text); font-size: 15px; line-height: 1.6; max-height: 160px; padding: 8px 0;
  font-family: inherit;
}
.send-btn, .stop-btn {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 12px; border: none; cursor: pointer;
  font-size: 18px; color: #fff; background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  display: flex; align-items: center; justify-content: center; transition: filter 0.15s ease, transform 0.15s ease;
}
.send-btn:hover, .stop-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.stop-btn { background: linear-gradient(135deg, #ff7a7a, #ff5470); }
.composer-hint { max-width: 860px; margin: 8px auto 0; font-size: 11.5px; color: var(--text-dim); opacity: 0.7; text-align: center; }

.hidden { display: none !important; }

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

@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* ---------- 响应式（手机） ---------- */
@media (max-width: 860px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
    transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  .app.sidebar-open .overlay { display: block; }
  .chat { padding: 16px 12px 8px; }
  .welcome h1 { font-size: 22px; }
  .bubble { font-size: 14.5px; }
}
