/* === AI 分身 · ChatGPT 风格 === */

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

:root {
  --bg: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-sidebar: #f9f9f9;
  --bg-hover: #ececec;
  --bg-user: #f4f4f5;
  --text: #2d2d2d;
  --text-muted: #8e8ea0;
  --text-on-active: #2d2d2d;
  --border: #e5e5e5;
  --accent: #10a37f;
  --accent-hover: #0e8c6b;
  --error: #d9534f;
  --active-bg: #ececec;
  --shadow: 0 0 10px rgba(0,0,0,0.05);
  --radius: 8px;
  --welcome-bg: #f0f4ff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121;
    --bg-secondary: #2a2a2a;
    --bg-sidebar: #171717;
    --bg-hover: #2a2a2a;
    --bg-user: #2a2a2a;
    --text: #ececec;
    --text-muted: #9a9a9e;
    --border: #3a3a3a;
    --accent: #10a37f;
    --accent-hover: #13b989;
    --active-bg: #2f2f2f;
    --shadow: 0 0 10px rgba(0,0,0,0.2);
    --welcome-bg: #1a1a2e;
  }
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

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

/* ===== 侧边栏 ===== */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.2s ease;
  z-index: 100;
}
.sidebar-header {
  padding: 12px;
}
.new-chat-btn {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
}
.new-chat-btn:hover {
  background: var(--bg-hover);
}
.convo-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}
.convo-list::-webkit-scrollbar { width: 4px; }
.convo-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.convo-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  margin: 2px 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  gap: 8px;
}
.convo-item:hover {
  background: var(--bg-hover);
}
.convo-item.active {
  background: var(--active-bg);
}
.convo-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text);
}
.convo-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all 0.15s;
  line-height: 1;
}
.convo-item:hover .convo-delete {
  opacity: 1;
}
.convo-delete:hover {
  background: var(--bg-hover);
  color: var(--error);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.sidebar-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-name {
  font-size: 13px;
  font-weight: 600;
}
.sidebar-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 99;
}

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

/* ===== 顶栏 ===== */
.header {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  gap: 12px;
}
.menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.menu-btn:hover {
  background: var(--bg-hover);
}
.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-name {
  font-size: 16px;
  font-weight: 600;
}
.header-spacer {
  flex: 1;
}

/* ===== 聊天区域 ===== */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}
.chat::-webkit-scrollbar { width: 6px; }
.chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* 欢迎页 */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px 24px;
  text-align: center;
}
.welcome-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin-bottom: 20px;
  box-shadow: 0 4px 12px rgba(16, 163, 127, 0.2);
}
.welcome h1 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
}
.welcome p {
  color: var(--text-muted);
  font-size: 14px;
  max-width: 400px;
  margin-bottom: 24px;
}
.welcome-questions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 500px;
}
.welcome-q-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  transition: all 0.15s;
}
.welcome-q-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

/* 消息容器 */
.message {
  display: flex;
  padding: 16px 24px;
  gap: 12px;
  line-height: 1.6;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.message.user {
  background: var(--bg);
}
.message.assistant {
  background: var(--bg-secondary);
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.msg-avatar.user-avatar {
  background: var(--bg-hover);
  color: var(--text);
}
.msg-avatar.ai-avatar {
  background: var(--accent);
  color: white;
}

.msg-body {
  flex: 1;
  min-width: 0;
}
.msg-content {
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg-content p { margin-bottom: 8px; }
.msg-content p:last-child { margin-bottom: 0; }

/* Markdown 内容样式 */
.msg-content code {
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
}
.msg-content pre {
  background: var(--bg-hover);
  padding: 12px 16px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 8px 0;
}
.msg-content pre code {
  background: none;
  padding: 0;
}
.msg-content ul, .msg-content ol {
  padding-left: 20px;
  margin: 8px 0;
}
.msg-content li { margin-bottom: 4px; }

/* 光标闪烁 */
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 16px;
  background: var(--text);
  margin-left: 2px;
  animation: blink 0.8s infinite;
  vertical-align: text-bottom;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* 错误消息 */
.msg-error {
  color: var(--error);
  font-size: 13px;
  padding: 8px 12px;
  background: rgba(217, 83, 79, 0.08);
  border-radius: var(--radius);
  margin-top: 4px;
}

/* ===== 输入栏 ===== */
.input-bar {
  border-top: 1px solid var(--border);
  padding: 12px 24px 16px;
  background: var(--bg);
}
.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  transition: border-color 0.15s;
}
.input-wrap:focus-within {
  border-color: var(--accent);
}
#input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 120px;
  font-family: inherit;
}
#input::placeholder {
  color: var(--text-muted);
}
.send-btn {
  background: var(--accent);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.send-btn:hover {
  background: var(--accent-hover);
}
.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.footer-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.open {
    display: block;
  }
  .menu-btn {
    display: block;
  }
  .message {
    padding: 12px 16px;
  }
  .input-bar {
    padding: 8px 12px 12px;
  }
}
