:root {
  --bg: #faf7f0;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-soft: #6b6b6b;
  --border: #e8e0d0;
  --accent: #b8945e;
  --accent-light: #d4b384;
  --accent-soft: #f5ead0;
  --user-bg: #fff8ea;
  --user-border: #d4b384;
  --ai-bg: #f2ede2;
  --ai-text: #2a2a2a;
  --shadow: 0 2px 12px rgba(0,0,0,.06);
  --shadow-strong: 0 8px 32px rgba(0,0,0,.12);
}

[data-theme="dark"] {
  --bg: #0d0d12;
  --surface: #14141c;
  --text: #f0ebe4;
  --text-soft: #8a8578;
  --border: #2a2a35;
  --accent: #d4b384;
  --accent-light: #e8d4a8;
  --accent-soft: #1e1e28;
  --user-bg: #1e1e28;
  --user-border: #d4b384;
  --ai-bg: #1a1a22;
  --ai-text: #e8e3d8;
  --shadow: 0 2px 12px rgba(0,0,0,.3);
  --shadow-strong: 0 8px 32px rgba(0,0,0,.5);
}

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

html, body {
  height: 100vh;
  height: 100dvh;
  font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .4s ease, color .4s ease;
  overflow: hidden;
}

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ===== 侧边栏 ===== */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform .3s cubic-bezier(.4,0,.2,1), background .4s ease;
  z-index: 100;
}

.sidebar-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}

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

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  font-weight: 700;
  font-family: 'STSong', 'SimSun', serif;
}

.brand-name {
  font-family: 'STSong', 'SimSun', serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 2px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-soft);
  letter-spacing: 1px;
}

.new-chat-btn {
  width: 100%;
  padding: 11px 16px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all .2s ease;
}

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

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

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s ease;
  margin-bottom: 2px;
}

.session-item:hover {
  background: var(--accent-soft);
}

.session-item.active {
  background: var(--accent-soft);
  border-left: 2px solid var(--accent);
}

.session-label {
  flex: 1;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 8px;
}

.session-del {
  opacity: 0;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-soft);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s ease;
  flex-shrink: 0;
}

.session-item:hover .session-del {
  opacity: 1;
}

.session-del:hover {
  background: #c0392b;
  color: #fff;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}

.user-nick {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}

.theme-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all .2s ease;
}

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

/* ===== 主区域 ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.top-bar {
  height: 56px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  transition: background .4s ease;
}

.menu-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all .2s ease;
}

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

.top-title {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.welcome-ink {
  font-family: 'STSong', 'SimSun', serif;
  font-size: 48px;
  font-weight: 700;
  letter-spacing: 8px;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-sub {
  font-size: 15px;
  color: var(--text-soft);
  margin-bottom: 36px;
  letter-spacing: 1px;
}

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 500px;
  justify-content: center;
}

.chip {
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-soft);
  cursor: pointer;
  transition: all .2s ease;
  background: var(--surface);
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

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

.msg-row {
  display: flex;
  gap: 10px;
  max-width: 78%;
  animation: fadeUp .3s ease;
}

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

.msg-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-row.ai {
  align-self: flex-start;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg-avatar.ai {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
  font-family: 'STSong', serif;
}

.msg-avatar.user {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
}

.msg-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg-card {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
  position: relative;
}

.msg-card.user {
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  border-bottom-right-radius: 4px;
}

.msg-row.ai .msg-card {
  background: var(--ai-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg-card pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
  overflow-x: auto;
  margin: 6px 0;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

.msg-card code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}

.copy-btn {
  align-self: flex-end;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--text-soft);
  font-size: 11px;
  cursor: pointer;
  transition: all .2s ease;
  opacity: 0;
}

.msg-row.ai:hover .copy-btn,
.msg-card + .copy-btn:hover {
  opacity: 1;
}

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

.copy-btn.done {
  color: var(--accent);
  border-color: var(--accent);
}

/* ===== 输入区 ===== */
.input-area {
  padding: 12px 20px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

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

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

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

.send-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s ease;
  flex-shrink: 0;
}

.send-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
  transform: scale(1.05);
}

.send-btn:not(:disabled):active {
  transform: scale(.95);
}

/* ===== 加载动画 ===== */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }

@keyframes dot {
  0%, 80%, 100% { transform: scale(.6); opacity: .4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ===== 流式光标 ===== */
.streaming-cursor::after {
  content: '▊';
  display: inline-block;
  color: var(--accent);
  animation: blink 1s step-end infinite;
  margin-left: 1px;
  font-size: .9em;
}

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

/* ===== 消息淡入 ===== */
.msg-row {
  animation-fill-mode: both;
}

/* ===== 手机侧边栏遮罩 ===== */
.sidebar-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}

.sidebar-mask.show {
  opacity: 1;
  pointer-events: auto;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 260px;
    transform: translateX(-100%);
    z-index: 200;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .msg-row {
    max-width: 92%;
  }

  .welcome-ink {
    font-size: 36px;
  }

  .welcome-chips {
    flex-direction: column;
    width: 100%;
  }

  .top-bar {
    padding: 0 14px;
  }

  .messages {
    padding: 14px;
  }

  .input-area {
    padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  }
}