:root {
  --paper: #f7f3ea;
  --paper-soft: #fbf8f1;
  --sidebar: #efe9db;
  --sidebar-hover: #e6ddc9;
  --ink: #2b2620;
  --ink-soft: #6f675c;
  --ink-faint: #a39a8b;
  --line: #e0d7c4;
  --clay: #c06b45;
  --clay-dark: #a8552f;
  --clay-soft: #f3e2d8;
  --bubble-user: #efe7d6;
  --green: #4c8a4f;
  --red: #b3402e;
  --serif: Georgia, "Times New Roman", "Songti SC", "Noto Serif CJK SC", serif;
  --sans: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
button { font-family: var(--sans); cursor: pointer; }
input, textarea { font-family: var(--sans); }
[hidden] { display: none !important; }

/* ---------- 登录 / 改密码 ---------- */
.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 36px 32px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(60, 45, 20, 0.08);
}
.auth-logo { font-size: 34px; color: var(--clay); }
.auth-card h1 { font-family: var(--serif); font-size: 24px; margin: 8px 0 4px; font-weight: 600; }
.auth-sub { color: var(--ink-soft); font-size: 14px; margin: 0 0 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card input {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
  background: #fff;
  outline: none;
}
.auth-card input:focus { border-color: var(--clay); box-shadow: 0 0 0 3px var(--clay-soft); }
.btn-primary {
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: var(--clay);
  color: #fff;
  font-size: 15px;
}
.btn-primary:hover { background: var(--clay-dark); }
.auth-error { color: var(--red); font-size: 13px; margin: 12px 0 0; }

/* ---------- 主布局 ---------- */
#app-view { display: flex; height: 100dvh; }
#sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.side-head { display: flex; gap: 8px; padding: 14px 14px 8px; }
.btn-new {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-soft);
  font-size: 14px;
  text-align: left;
}
.btn-new:hover { background: #fff; }
.icon-btn {
  border: none;
  background: transparent;
  font-size: 17px;
  color: var(--ink-soft);
  padding: 6px 10px;
  border-radius: 8px;
}
.icon-btn:hover { background: var(--sidebar-hover); }
#side-close { display: none; }
#conv-list { flex: 1; overflow-y: auto; padding: 4px 10px; }
.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
}
.conv-item:hover { background: var(--sidebar-hover); }
.conv-item.active { background: var(--sidebar-hover); font-weight: 600; }
.conv-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.conv-del {
  border: none;
  background: transparent;
  color: var(--ink-faint);
  font-size: 15px;
  padding: 0 4px;
  border-radius: 6px;
  display: none;
}
.conv-item:hover .conv-del { display: block; }
.conv-del:hover { color: var(--red); }
.conv-empty { color: var(--ink-faint); font-size: 13px; padding: 12px 10px; }
.side-foot { border-top: 1px solid var(--line); padding: 12px 14px; }
#model-status { font-size: 12.5px; color: var(--ink-soft); line-height: 1.9; margin-bottom: 8px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.on { background: var(--green); }
.dot.off { background: #c0b8a6; }
.btn-ghost {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--ink-soft);
}
.btn-ghost:hover { background: var(--paper-soft); }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  color: var(--ink-soft);
}
#menu-btn { display: none; }
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0 8px;
}
.msg-row { display: flex; padding: 10px 0; }
.msg-row.user { background: transparent; }
.msg-row.assistant { background: transparent; }
.msg {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 24px;
}
.msg-role { font-size: 12.5px; color: var(--ink-faint); margin-bottom: 4px; }
.msg.user .msg-body {
  background: var(--bubble-user);
  border-radius: 16px;
  padding: 12px 16px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-body { word-break: break-word; }
.msg-body p { margin: 0 0 10px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body h1, .msg-body h2, .msg-body h3 { font-family: var(--serif); margin: 16px 0 8px; }
.msg-body h1 { font-size: 21px; } .msg-body h2 { font-size: 18px; } .msg-body h3 { font-size: 16px; }
.msg-body ul, .msg-body ol { margin: 0 0 10px; padding-left: 22px; }
.msg-body li { margin-bottom: 3px; }
.msg-body a { color: var(--clay-dark); }
.msg-body blockquote {
  margin: 0 0 10px;
  padding-left: 12px;
  border-left: 3px solid var(--line);
  color: var(--ink-soft);
}
.msg-body code {
  font-family: var(--mono);
  font-size: 13px;
  background: #ece5d3;
  padding: 1px 5px;
  border-radius: 5px;
}
.msg-body pre {
  background: #2e2a24;
  color: #f0ead9;
  border-radius: 12px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 10px;
  position: relative;
}
.msg-body pre code { background: transparent; color: inherit; padding: 0; font-size: 13px; }
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.08);
  color: #e8e0cd;
  border-radius: 8px;
  font-size: 12px;
  padding: 3px 9px;
}
.copy-btn:hover { background: rgba(255,255,255,0.18); }
.msg-body table { border-collapse: collapse; margin: 0 0 10px; font-size: 14px; }
.msg-body th, .msg-body td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.msg-body th { background: var(--bubble-user); }
.msg-status { font-size: 12.5px; color: var(--ink-faint); margin-top: 6px; }
.msg-status .cursor { display: inline-block; width: 8px; height: 14px; background: var(--clay); vertical-align: -2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* 问候页 */
.greeting { text-align: center; padding: 8px 24px 4px; margin: auto 0; }
.greeting h2 { font-family: var(--serif); font-size: 30px; font-weight: 600; margin: 0 0 6px; }
.greeting p { color: var(--ink-soft); margin: 0 0 22px; }
.model-cards { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.model-card {
  border: 1px solid var(--line);
  background: var(--paper-soft);
  border-radius: 14px;
  padding: 14px 18px;
  min-width: 150px;
  text-align: left;
}
.model-card:hover { border-color: var(--clay); }
.model-card.active { border-color: var(--clay); box-shadow: 0 0 0 3px var(--clay-soft); }
.model-card b { display: block; font-size: 14.5px; }
.model-card span { font-size: 12.5px; color: var(--ink-soft); }
.model-card .speed { display: block; font-size: 12px; color: var(--ink-faint); margin-top: 2px; }

/* 输入框 */
#composer { padding: 10px 24px calc(14px + env(safe-area-inset-bottom)); }
.model-pills { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.pill {
  border: 1px solid var(--line);
  background: var(--paper-soft);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 13px;
  color: var(--ink-soft);
}
.pill.active { background: var(--clay); border-color: var(--clay); color: #fff; }
.composer-box {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 10px 10px 10px 18px;
  box-shadow: 0 4px 18px rgba(60, 45, 20, 0.07);
}
.composer-box:focus-within { border-color: var(--clay); }
#input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 15px;
  line-height: 1.55;
  max-height: 180px;
  background: transparent;
  padding: 4px 0;
}
.btn-send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--clay);
  color: #fff;
  font-size: 19px;
  line-height: 1;
}
.btn-send:hover { background: var(--clay-dark); }
.btn-send:disabled { background: #cfc6b2; cursor: default; }
.composer-hint { text-align: center; font-size: 12px; color: var(--ink-faint); margin: 8px 0 0; }

/* 手机 */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.2);
  }
  #sidebar.open { transform: translateX(0); }
  #side-close { display: block; }
  #menu-btn { display: block; }
  #side-scrim {
    position: fixed;
    inset: 0;
    background: rgba(40, 30, 15, 0.35);
    z-index: 20;
  }
  .greeting h2 { font-size: 24px; }
  .msg { padding: 0 16px; }
  #composer { padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); }
}
