:root {
  --bg: #0b0b0f;
  --sidebar: #15151b;
  --panel: #15151b;
  --panel-2: #1c1c24;
  --text: #e8e8ea;
  --muted: #8a8a93;
  --gold: #f5a623;
  --border: #26262e;
  --user-bubble: #f5a623;
  --sidebar-w: 260px;
}

/* 浅色主题覆盖 */
.theme-light {
  --bg: #f4f5f7;
  --sidebar: #ffffff;
  --panel: #ffffff;
  --panel-2: #f0f1f4;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --user-bubble: #f5a623;
}
.theme-light body { background: var(--bg); }
.theme-light .message.assistant code, .theme-light .message.assistant pre { background: #f0f0f3; color: #c00; }
.theme-light .insight-block code { background: #f0f0f3; color: #c00; }

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

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

/* ============ 登录 / 注册 ============ */
.auth-view {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 0%, #1a1a22, var(--bg));
}
.auth-card {
  width: 360px;
  max-width: 92vw;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
}
.auth-logo { font-size: 1.5rem; font-weight: 800; margin-bottom: 22px; }
.auth-logo span { font-size: 0.8rem; font-weight: 400; color: var(--muted); margin-left: 6px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.auth-tab {
  flex: 1; background: transparent; color: var(--muted); border: none;
  padding: 8px; cursor: pointer; font-size: 0.9rem; border-bottom: 2px solid transparent;
}
.auth-tab.active { color: var(--text); border-bottom-color: var(--gold); }
.auth-input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; font-size: 0.95rem;
}
.auth-input:focus { outline: none; border-color: var(--gold); }
.auth-submit {
  width: 100%; background: var(--gold); color: #1a1300; border: none; border-radius: 10px;
  padding: 12px; font-weight: 700; cursor: pointer; font-size: 0.95rem; margin-top: 4px;
}
.auth-submit:hover { filter: brightness(1.05); }
.auth-hint { color: var(--muted); font-size: 0.78rem; text-align: center; margin-top: 14px; }
.auth-error {
  background: #3a1a1a; color: #ff9a9a; border: 1px solid #5a2a2a;
  border-radius: 8px; padding: 10px 12px; font-size: 0.85rem; margin-bottom: 14px;
}

/* ============ 聊天布局 ============ */
.app-view { display: flex; height: 100vh; position: relative; }

/* ---- 左侧固定侧边栏 ---- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.sidebar-top { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; padding: 14px 12px 0; }
.sidebar-logo {
  font-weight: 800; font-size: 1.05rem; padding: 4px 8px 12px; color: var(--text);
  display: flex; align-items: center; gap: 6px;
}
.logo-mark { color: var(--gold); }
.newchat-btn {
  width: 100%; text-align: left; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 14px;
  cursor: pointer; font-size: 0.9rem; font-weight: 600; margin-bottom: 14px;
}
.newchat-btn:hover { border-color: var(--gold); color: var(--gold); }

.history-list { flex: 1 1 auto; overflow-y: auto; padding-bottom: 12px; }
.history-group-title {
  font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px;
  padding: 12px 10px 6px; font-weight: 600;
}
.history-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px;
  cursor: pointer; margin-bottom: 2px; border: 1px solid transparent;
}
.history-item:hover { background: var(--panel-2); border-color: var(--border); }
.history-info { flex: 1; min-width: 0; }
.history-item .hi-title {
  font-size: 0.85rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.history-item .hi-meta { font-size: 0.7rem; color: var(--muted); margin-top: 1px; }
.history-del {
  background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 0.85rem;
  padding: 4px 6px; border-radius: 6px; flex: 0 0 auto; opacity: 0; transition: opacity .15s;
}
.history-item:hover .history-del { opacity: 1; }
.history-del:hover { color: #ff6b6b; background: var(--panel); }

/* ---- 侧栏底部用户区 ---- */
.sidebar-bottom {
  flex: 0 0 auto; border-top: 1px solid var(--border); padding: 10px 12px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 4px 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--gold); color: #1a1300;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.9rem; flex: 0 0 auto;
}
.user-meta { min-width: 0; }
.user-email { font-size: 0.82rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-credits { font-size: 0.72rem; color: var(--gold); }
.side-btn {
  width: 100%; text-align: left; background: transparent; color: var(--muted);
  border: none; padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 0.85rem;
}
.side-btn:hover { background: var(--panel-2); color: var(--text); }

/* ---- 右侧主区 ---- */
.main-area { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; height: 100vh; }

.topbar {
  height: 52px; flex: 0 0 52px; display: flex; align-items: center;
  padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--bg);
}
.chat-title { font-weight: 600; font-size: 0.95rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn {
  display: none; background: transparent; border: none; color: var(--muted);
  font-size: 1.3rem; cursor: pointer; margin-right: 10px; line-height: 1;
}
.menu-btn:hover { color: var(--text); }

/* ---- 消息区（扁平，仿 DeepSeek 直接铺在背景上） ---- */
.message-container {
  flex: 1 1 auto; overflow-y: auto; padding: 28px 0 16px;
  display: flex; flex-direction: column; gap: 22px; scroll-behavior: smooth;
}
.message-container > * { width: 100%; }
.empty-state {
  margin: auto; text-align: center; color: var(--muted); max-width: 460px; padding: 40px 20px;
}
.empty-state .bolt { font-size: 2.2rem; display: block; margin-bottom: 14px; color: var(--gold); }

.msg-row { display: flex; flex-direction: column; padding: 0 24px; }
.msg-row.user-row { align-items: flex-start; }
.msg-row.assistant-row { align-items: flex-start; }

/* 居中内容容器，限制最大阅读宽度 */
.msg-body { max-width: 760px; width: 100%; margin: 0 auto; }
.msg-row.user-row .msg-body { display: flex; justify-content: flex-end; }

.message {
  width: 100%; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap;
}
/* 用户消息：右对齐，宽度随内容自适应 */
.message.user {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 16px; font-weight: 500;
  width: fit-content; max-width: 80%;
}
/* 助手消息：直接铺在背景上，无卡片边框 */
.message.assistant {
  background: transparent; border: none; padding: 0;
}
.message.assistant.streaming::after { content: "▋"; color: var(--gold); animation: blink 1s steps(2) infinite; margin-left: 2px; }
@keyframes blink { 0%,50% { opacity: 1; } 50.01%,100% { opacity: 0; } }
/* 生成中状态文案（首 token 到达前显示，跟随闪烁光标） */
.gen-status { color: var(--muted); font-size: 0.95rem; font-style: italic; }
.msg-meta { font-size: 0.7rem; color: var(--muted); margin-top: 4px; }

/* markdown 基本排版 */
.message.assistant h1, .message.assistant h2, .message.assistant h3 { margin: 0.7em 0 0.35em; line-height: 1.3; }
.message.assistant p { margin: 0.6em 0; }
.message.assistant ul, .message.assistant ol { margin: 0.5em 0 0.5em 1.3em; }
.message.assistant code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
.message.assistant pre { background: var(--panel-2); padding: 12px; border-radius: 8px; overflow-x: auto; border: 1px solid var(--border); }
.message.assistant a { color: var(--gold); }

/* 浮动回到底部按钮 */
.scroll-btn {
  position: absolute; left: calc(var(--sidebar-w) + (100% - var(--sidebar-w)) / 2);
  transform: translateX(-50%); bottom: 110px;
  width: 42px; height: 42px; border-radius: 50%; background: var(--panel-2);
  border: 1px solid var(--border); color: var(--text); font-size: 1.2rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 14px rgba(0,0,0,0.5); z-index: 30;
}
.scroll-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ---- 输入区：单条圆角输入条 ---- */
.composer {
  flex: 0 0 auto; padding: 14px 20px 18px; background: var(--bg);
}
.composer-inner {
  max-width: 760px; margin: 0 auto; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 18px; padding: 10px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.input-box {
  width: 100%; resize: none; background: transparent; color: var(--text);
  border: none; font-family: inherit; font-size: 0.98rem; line-height: 1.5; max-height: 180px;
}
.input-box:focus { outline: none; }
.composer-tools { display: flex; align-items: center; gap: 8px; }
.pill-select {
  background: var(--panel); color: var(--muted); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; font-size: 0.78rem; font-weight: 600; cursor: pointer;
}
.pill-select:focus { outline: none; border-color: var(--gold); }
.send-btn {
  margin-left: auto; background: var(--gold); color: #1a1300; border: none; border-radius: 50%;
  width: 38px; height: 38px; font-size: 1.1rem; font-weight: 700; cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.send-btn:hover:not(:disabled) { filter: brightness(1.05); }

/* ============ 消息操作栏 / 脚注 / 洞察 ============ */
.msg-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.mini-btn {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 7px; padding: 4px 10px; cursor: pointer; font-size: 0.72rem;
}
.mini-btn:hover { color: var(--gold); border-color: var(--gold); }
.msg-footer {
  font-size: 0.7rem; color: var(--muted); margin-top: 8px; padding: 0 2px;
  border-top: 1px dashed var(--border); padding-top: 6px;
}
.insight-block {
  margin-top: 12px; border-radius: 12px;
  background: rgba(245,166,35,0.07); border: 1px solid rgba(245,166,35,0.3);
  font-size: 0.9rem; overflow: hidden;
}
.insight-block.collapsed { padding: 0; }
.insight-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; cursor: pointer; user-select: none;
  color: var(--gold); font-weight: 700;
}
.insight-header:hover { background: rgba(245,166,35,0.12); }
.insight-toggle-icon { font-size: 0.8rem; width: 12px; text-align: center; }
.insight-title-text { flex: 1; }
.insight-content { padding: 0 16px 14px; }
.insight-block h1, .insight-block h2, .insight-block h3 { margin: 0.5em 0 0.3em; color: var(--gold); line-height: 1.3; }
.insight-block p { margin: 0.45em 0; }
.insight-block ul, .insight-block ol { margin: 0.4em 0 0.4em 1.2em; }
.insight-block code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }

/* ============ 设置面板（右侧浮层） ============ */
.settings-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 300px; max-width: 84vw;
  background: var(--panel); border-left: 1px solid var(--border); z-index: 40;
  display: flex; flex-direction: column;
}
.settings-body { padding: 16px; overflow-y: auto; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 0.88rem;
}
.settings-select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 0.82rem;
}
.settings-link { color: var(--gold); text-decoration: none; font-size: 0.85rem; }
.settings-link:hover { text-decoration: underline; }
.settings-link-btn {
  background: transparent; border: none; color: var(--gold); cursor: pointer;
  font-size: 0.85rem; padding: 0; font-family: inherit;
}
.settings-link-btn:hover { text-decoration: underline; }
.settings-ver { color: var(--muted); font-size: 0.82rem; }
.settings-note {
  margin-top: 16px; font-size: 0.76rem; color: var(--muted); line-height: 1.6;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px;
}

/* ============ 通用 ============ */
.ghost-btn {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 0.82rem;
}
.ghost-btn:hover { color: var(--text); border-color: var(--gold); }
.history-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 600;
}

/* ============ 移动端：侧栏改为可抽屉 ============ */
@media (max-width: 720px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    position: absolute; left: 0; top: 0; bottom: 0; width: 260px; z-index: 50;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .scroll-btn { left: 50%; }
  .msg-row { padding: 0 14px; }
  .composer { padding: 10px 12px 14px; }
  .pill-select { display: none; }
  .menu-btn { display: block; }
}

/* ============ 购买积分弹窗 ============ */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.modal-mask { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.modal-card {
  position: relative; width: min(440px, 92vw); max-height: 88vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 1.05rem; font-weight: 600; margin-bottom: 16px;
}
.buy-packages { display: flex; flex-direction: column; gap: 12px; }
.buy-card {
  text-align: left; cursor: pointer; font-family: inherit;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; transition: border-color .15s ease, transform .1s ease;
}
.buy-card:hover { border-color: var(--gold); transform: translateY(-1px); }
.buy-credits { font-size: 1.4rem; font-weight: 700; color: var(--text); }
.buy-credits span { font-size: 0.85rem; font-weight: 500; color: var(--muted); margin-left: 4px; }
.buy-label { font-size: 0.8rem; color: var(--muted); margin: 2px 0 8px; }
.buy-price { font-size: 1.05rem; font-weight: 600; color: var(--gold); }
.buy-note {
  margin-top: 16px; font-size: 0.74rem; color: var(--muted); line-height: 1.6;
  border-top: 1px solid var(--border); padding-top: 12px;
}
