/* ===== 主题变量（浅色为默认） ===== */
:root {
  --bg:            #f5f6f8;
  --surface:       #ffffff;
  --surface-2:     #f0f1f4;
  --border:        #e3e5ea;
  --text:          #1c1f26;
  --text-muted:    #6b7280;
  --text-faint:    #9aa1ad;
  --accent:        #2f6bff;
  --accent-weak:   #eef3ff;
  --user-bubble:   #2f6bff;
  --user-text:     #ffffff;
  --ai-bubble:     #ffffff;
  --shadow:        0 1px 2px rgba(16,24,40,.05), 0 4px 16px rgba(16,24,40,.06);
  --radius:        14px;
  --topbar-h:      58px;
}

/* ===== 深色模式 ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #15171c;
    --surface:     #1e2127;
    --surface-2:   #262a32;
    --border:      #31363f;
    --text:        #e8eaed;
    --text-muted:  #a8b0bd;
    --text-faint:  #7b838f;
    --accent:      #6f97ff;
    --accent-weak: #1f2740;
    --user-bubble: #3b6fe0;
    --user-text:   #ffffff;
    --ai-bubble:   #1e2127;
    --shadow:      0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}
/* 手动切换覆盖 */
html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] {
  color-scheme: dark;
  --bg:#15171c; --surface:#1e2127; --surface-2:#262a32; --border:#31363f;
  --text:#e8eaed; --text-muted:#a8b0bd; --text-faint:#7b838f;
  --accent:#6f97ff; --accent-weak:#1f2740; --user-bubble:#3b6fe0;
  --ai-bubble:#1e2127;
  --shadow:0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== 顶栏 ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-name { font-weight: 650; font-size: 16px; }
.brand-sub {
  font-size: 12.5px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.theme-toggle {
  flex: none; width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-muted); cursor: pointer; font-size: 14px; line-height: 1;
}
.theme-toggle:hover { color: var(--text); }
html[data-theme="light"] .icon-moon,
html:not([data-theme]) .icon-moon { display: none; }
html[data-theme="dark"] .icon-sun { display: none; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) .icon-sun { display: none; }
  html:not([data-theme]) .icon-moon { display: inline; }
}

/* ===== 布局 ===== */
.layout {
  display: grid;
  grid-template-columns: 328px minmax(0, 1fr);
  gap: 18px;
  max-width: 1180px;
  margin: 18px auto;
  padding: 0 18px;
  align-items: start;
}

/* ===== 资料卡 ===== */
.profile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  position: sticky;
  top: calc(var(--topbar-h) + 18px);
  max-height: calc(100vh - var(--topbar-h) - 36px);
  overflow-y: auto;
}
.profile-toggle { display: none; }
.profile-head { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
.avatar {
  flex: none; width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #7aa2ff);
  color: #fff; font-size: 21px; font-weight: 650;
  display: grid; place-items: center;
}
.p-name { margin: 0; font-size: 18px; font-weight: 650; }
.p-tag { margin: 2px 0 0; font-size: 12.5px; color: var(--text-muted); }
.p-block { margin-top: 16px; }
.p-block h2 {
  margin: 0 0 7px; font-size: 12px; font-weight: 650;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-faint);
}
.p-list { margin: 0; padding: 0; list-style: none; font-size: 13.5px; }
.p-list li { padding: 2.5px 0; color: var(--text); }
.p-list li.muted { color: var(--text-muted); font-size: 13px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags span {
  font-size: 12px; padding: 3px 9px; border-radius: 20px;
  background: var(--accent-weak); color: var(--accent); font-weight: 500;
}

/* ===== 聊天区 ===== */
.chat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  height: calc(100vh - var(--topbar-h) - 36px);
  min-height: 460px;
  overflow: hidden;
}
.chat-scroll {
  flex: 1; overflow-y: auto;
  padding: 22px 22px 8px;
  scroll-behavior: smooth;
}

.msg { display: flex; margin-bottom: 16px; gap: 10px; }
.msg .who {
  flex: none; width: 30px; height: 30px; border-radius: 8px;
  font-size: 12.5px; font-weight: 650; display: grid; place-items: center;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .who { background: var(--surface-2); color: var(--text-muted); }
.msg.ai .who { background: var(--accent-weak); color: var(--accent); }
.bubble {
  max-width: min(78%, 680px);
  padding: 10px 14px; border-radius: 13px;
  font-size: 14.5px; overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--user-bubble); color: var(--user-text);
  border-bottom-right-radius: 4px;
}
.msg.ai .bubble {
  background: var(--ai-bubble); color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* AI 气泡里的 markdown */
.bubble p { margin: 0 0 9px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0 9px; padding-left: 22px; }
.bubble li { margin: 2px 0; }
.bubble code {
  background: var(--surface-2); padding: 1.5px 5px; border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}
.bubble pre {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 11px 13px; border-radius: 9px; overflow-x: auto; margin: 8px 0;
}
.bubble pre code { background: none; padding: 0; font-size: 12.8px; line-height: 1.55; }
.bubble strong { font-weight: 650; }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.bubble a { word-break: break-all; }

/* 光标 */
.cursor::after {
  content: "▋"; margin-left: 1px; color: var(--accent);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* 错误 / 提示气泡 */
.note {
  font-size: 12.8px; color: var(--text-muted);
  background: var(--surface-2); border: 1px dashed var(--border);
  padding: 7px 11px; border-radius: 9px; margin-top: 8px;
}

/* 打字中 */
.typing { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint);
  animation: bounce 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity:.45 } 30% { transform: translateY(-4px); opacity:1 } }

/* ===== 底部输入 ===== */
.chat-foot { padding: 10px 18px 14px; border-top: 1px solid var(--border); background: var(--surface); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 10px; }
.chip {
  font-size: 12.5px; padding: 5px 11px; border-radius: 18px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-muted); cursor: pointer; transition: .15s;
}
.chip:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-weak); }

.composer { display: flex; gap: 9px; align-items: flex-end; }
#input {
  flex: 1; resize: none; max-height: 132px;
  padding: 10px 12px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font: inherit; font-size: 14.5px; line-height: 1.5;
  outline: none; transition: border-color .15s;
}
#input:focus { border-color: var(--accent); }
#send {
  flex: none; padding: 10px 20px; border: none; border-radius: 11px;
  background: var(--accent); color: #fff; font: inherit; font-weight: 600;
  cursor: pointer; transition: .15s;
}
#send:hover:not(:disabled) { filter: brightness(1.08); }
#send:disabled { opacity: .45; cursor: not-allowed; }
.disclaimer { margin: 9px 0 0; font-size: 11.5px; color: var(--text-faint); text-align: center; }

/* ===== 页脚 ===== */
.sitefoot {
  text-align: center; padding: 14px 18px 26px;
  font-size: 12px; color: var(--text-faint);
}
.sitefoot .dot { margin: 0 6px; }

/* ===== 移动端 ===== */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; gap: 12px; padding: 0 12px; margin: 12px auto; }
  .profile {
    position: static; max-height: none; padding: 0; overflow: hidden;
  }
  .profile-toggle {
    display: flex; width: 100%; align-items: center; justify-content: space-between;
    padding: 13px 16px; background: none; border: none; cursor: pointer;
    font: inherit; font-weight: 600; color: var(--text);
  }
  .profile-toggle .chev { transition: transform .2s; color: var(--text-faint); }
  .profile.open .profile-toggle .chev { transform: rotate(180deg); }
  .profile-body { display: none; padding: 0 16px 16px; }
  .profile.open .profile-body { display: block; }

  .chat { height: calc(100dvh - 190px); min-height: 400px; }
  .chat-scroll { padding: 16px 14px 6px; }
  .bubble { max-width: 86%; font-size: 14px; }
  .chat-foot { padding: 9px 12px 12px; }
  .brand-sub { display: none; }
}
