/* 燎原驿 · 大众版。配色与“开始使用”页同一套（墨绿侧栏、白底、绿色点缀）。
   页面的 CSP 不允许内联样式，所以这里不依赖任何 style="" 属性。 */
:root {
  color-scheme: light;
  --canvas: #f4f6f5;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --ink: #17201c;
  --muted: #65716b;
  --faint: #8b9691;
  --line: #d8e0dc;
  --line-strong: #becbc4;
  --nav: #13201b;
  --nav-soft: #1d2e27;
  --nav-ink: #cbd9d2;
  --green: #087747;
  --green-deep: #075f3a;
  --green-soft: #e4f5eb;
  --green-line: #b9dfc9;
  --amber: #8a5900;
  --amber-soft: #fff2d5;
  --red: #b42318;
  --red-soft: #fee9e7;
  --code-bg: #101815;
  --code-ink: #e8f1ec;
  --shadow: 0 12px 30px rgba(21, 34, 28, .08);
  --radius: 10px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
html { min-width: 320px; background: var(--canvas); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--canvas); color: var(--ink); letter-spacing: 0; }
button, input, textarea { font: inherit; letter-spacing: 0; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: var(--green); }
:focus-visible { outline: 3px solid rgba(8, 119, 71, .32); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.brand-mark {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 8px;
  background: #1f5f43;
  color: #ffffff;
  font-size: 15px;
  font-weight: 900;
}
.brand-mark.big { width: 52px; height: 52px; border-radius: 12px; font-size: 22px; }
.brand-copy { min-width: 0; display: grid; gap: 2px; }
.brand-copy strong { font-size: 15px; line-height: 1.2; }
.brand-copy span { font-size: 12px; }

/* ---------- 按钮 ---------- */
.btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}
.btn:hover { border-color: #879990; background: #f6f8f7; }
.btn.primary { border-color: var(--green); background: var(--green); color: #ffffff; }
.btn.primary:hover { background: var(--green-deep); }
.btn.block { width: 100%; min-height: 44px; font-size: 15px; }
.btn.link { border: 0; background: none; color: var(--muted); min-height: 32px; font-weight: 700; }
.btn:disabled { cursor: not-allowed; opacity: .6; }
.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  font-size: 18px;
  line-height: 1;
}
.icon-btn:hover { background: #eef2f0; }

/* ---------- 打开中 ---------- */
.loading-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 15px;
}

/* ---------- 登录 / 注册 ---------- */
.auth-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  background:
    linear-gradient(180deg, var(--nav) 0, var(--nav) 180px, transparent 180px),
    var(--canvas);
}
.auth-card {
  width: min(420px, 100%);
  padding: 26px 24px 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 11px; }
.auth-brand .brand-copy span { color: var(--muted); }
.auth-title { margin: 20px 0 6px; font-size: 24px; line-height: 1.25; }
.auth-lede { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 16px; border-radius: 9px; background: #edf1ef; }
.auth-tab { min-height: 36px; border: 0; border-radius: 7px; background: none; color: var(--muted); font-size: 14px; font-weight: 800; }
.auth-tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(21, 34, 28, .12); }
.auth-form { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 800; color: var(--muted); }
.field input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 16px;
  font-weight: 400;
}
.field input:focus { border-color: var(--green); background: var(--surface); outline: none; box-shadow: 0 0 0 3px rgba(8, 119, 71, .14); }
.form-tip { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.form-msg { margin: 12px 0 0; padding: 10px 12px; border: 1px solid #efb8b2; border-radius: 8px; background: var(--red-soft); color: var(--red); font-size: 13px; line-height: 1.6; }
.form-msg[data-tone="ok"] { border-color: var(--green-line); background: var(--green-soft); color: var(--green); }
.auth-foot { margin: 18px 0 0; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; line-height: 1.7; }
.auth-foot a { font-weight: 800; }

/* ---------- 聊天主体 ---------- */
.chat-view {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  overflow: hidden;
}
.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 12px;
  background: var(--nav);
  color: #eaf2ee;
}
.side-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 4px; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; color: inherit; text-decoration: none; }
.brand .brand-copy span { color: #9fb3aa; }
.side-close { display: none; color: #eaf2ee; }
.side-close:hover { background: var(--nav-soft); }
.new-chat { width: 100%; border-color: rgba(255, 255, 255, .2); background: var(--nav-soft); color: #ffffff; }
.new-chat:hover { border-color: rgba(255, 255, 255, .34); background: #26392f; }
.conv-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: grid; align-content: start; gap: 2px; margin: 0 -4px; padding: 0 4px; scrollbar-width: thin; scrollbar-color: #33483e transparent; }
.conv-empty { margin: 8px 6px; color: #8fa49a; font-size: 12.5px; line-height: 1.6; }
.conv-item { position: relative; display: flex; align-items: center; border-radius: 7px; }
.conv-item:hover { background: var(--nav-soft); }
.conv-item[aria-current="true"] { background: #eef8f2; }
.conv-open {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  padding: 0 34px 0 10px;
  border: 0;
  background: none;
  color: var(--nav-ink);
  font-size: 13.5px;
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item[aria-current="true"] .conv-open { color: var(--green-deep); }
.conv-del {
  position: absolute;
  right: 4px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: #8fa49a;
  font-size: 16px;
  opacity: 0;
}
.conv-item:hover .conv-del,
.conv-item[aria-current="true"] .conv-del,
.conv-del:focus-visible { opacity: 1; }
.conv-del:hover { background: rgba(180, 35, 24, .14); color: #f3b2aa; }
.conv-item[aria-current="true"] .conv-del:hover { color: var(--red); }
.side-foot { display: grid; gap: 8px; padding: 12px 6px 2px; border-top: 1px solid rgba(255, 255, 255, .12); font-size: 12px; line-height: 1.6; }
.side-foot p { margin: 0; color: #8fa49a; }
.side-foot a { color: #cfe7da; font-weight: 800; text-decoration: none; }
.side-foot a:hover { color: #ffffff; }
.scrim { display: none; }

.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
.topbar {
  flex: 0 0 auto;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.menu-btn { display: none; }
.top-title { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 15px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; }
.chip {
  max-width: 260px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--green-line);
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-deep);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip:hover { border-color: #86c7a1; }
.chip[data-tone="warning"] { border-color: #ead09a; background: var(--amber-soft); color: var(--amber); }
.avatar { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--nav); color: #ffffff; font-size: 13px; font-weight: 800; }
.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  min-width: 220px;
  display: grid;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.menu-user { padding: 8px 10px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line); font-size: 13px; line-height: 1.5; }
.menu-user strong { display: block; font-size: 14px; overflow-wrap: anywhere; }
.menu-user span { color: var(--muted); font-size: 12px; }
.menu-item {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  text-decoration: none;
}
.menu-item:hover { background: #f1f4f2; }
.menu-item.danger { color: var(--red); }

.scroller { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 26px 18px 18px; scroll-behavior: auto; }

/* ---------- 空白页 ---------- */
.empty { width: min(760px, 100%); margin: 5vh auto 0; text-align: center; }
.empty h2 { margin: 16px 0 6px; font-size: 26px; line-height: 1.25; }
.empty > p { margin: 0 auto 24px; max-width: 460px; color: var(--muted); font-size: 15px; line-height: 1.7; }
.examples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; text-align: left; }
.example {
  display: grid;
  gap: 3px;
  min-height: 70px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  text-align: left;
}
.example:hover { border-color: #86c7a1; background: var(--green-soft); }
.example strong { font-size: 14px; }
.example span { color: var(--muted); font-size: 13px; }

/* ---------- 消息 ---------- */
.msg-list { width: min(760px, 100%); margin: 0 auto; padding: 0; list-style: none; display: grid; gap: 22px; }
.msg { min-width: 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  max-width: min(85%, 620px);
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  background: var(--green-soft);
  color: var(--ink);
  font-size: 15.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.assistant { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 12px; align-items: start; }
.msg.assistant > .brand-mark { width: 30px; height: 30px; border-radius: 7px; font-size: 13px; margin-top: 2px; }
.answer { min-width: 0; font-size: 15.5px; line-height: 1.78; overflow-wrap: anywhere; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p { margin: .55em 0; }
.answer h3, .answer h4, .answer h5, .answer h6 { margin: 1em 0 .4em; line-height: 1.4; }
.answer h3 { font-size: 18px; }
.answer h4 { font-size: 16.5px; }
.answer h5, .answer h6 { font-size: 16px; }
.answer ul, .answer ol { margin: .5em 0; padding-left: 1.5em; }
/* 消息列表本身是 <ol>，浏览器会把里面的列表当成“嵌套列表”画空心圆，这里写死 */
.answer ul { list-style-type: disc; }
.answer ul ul { list-style-type: circle; }
.answer ul ul ul { list-style-type: square; }
.answer ol { list-style-type: decimal; }
.answer li { margin: .25em 0; }
.answer li > ul, .answer li > ol { margin: .2em 0; }
.answer strong { font-weight: 800; }
.answer a { color: var(--green); text-decoration: underline; text-underline-offset: 2px; }
.answer hr { margin: 1.2em 0; border: 0; border-top: 1px solid var(--line); }
.answer blockquote { margin: .7em 0; padding: .2em 0 .2em 14px; border-left: 3px solid var(--green-line); color: #45514b; }
.answer code { padding: .12em .38em; border-radius: 5px; background: #eef2f0; font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: .88em; }
.code { margin: .8em 0; overflow: hidden; border-radius: 9px; background: var(--code-bg); }
.code-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 34px; padding: 0 8px 0 12px; background: #1b2621; color: #9fb3aa; font-size: 12px; }
.code-bar button { min-height: 26px; padding: 0 9px; border: 1px solid #33483e; border-radius: 6px; background: none; color: #cfe7da; font-size: 12px; font-weight: 700; }
.code-bar button:hover { background: #26392f; }
.code pre { margin: 0; padding: 12px 14px 14px; overflow-x: auto; color: var(--code-ink); font-size: 13px; line-height: 1.6; }
.code pre code { padding: 0; background: none; font-size: inherit; }
.table-wrap { margin: .8em 0; overflow-x: auto; border: 1px solid var(--line); border-radius: 9px; }
.answer table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 1.6; }
.answer th, .answer td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.answer th { background: var(--surface-soft); font-weight: 800; white-space: nowrap; }
.answer tr:last-child td { border-bottom: 0; }
.answer .al-center { text-align: center; }
.answer .al-right { text-align: right; }

.caret::after {
  content: "";
  display: inline-block;
  width: .5em;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: -.16em;
  border-radius: 2px;
  background: var(--green);
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.thinking { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; min-height: 30px; color: var(--muted); font-size: 14px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); opacity: .35; animation: pulse 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; transform: scale(.85); } 40% { opacity: 1; transform: scale(1); } }
.thinking-hint { color: var(--faint); font-size: 13px; }

.msg-note { margin-top: 6px; color: var(--faint); font-size: 12.5px; }
.msg-error { margin-top: 4px; padding: 10px 12px; border: 1px solid #efb8b2; border-radius: 9px; background: var(--red-soft); color: var(--red); font-size: 14px; line-height: 1.65; }
.msg-error .btn { min-height: 32px; margin-top: 8px; padding: 0 12px; border-color: #e4a39b; background: #ffffff; color: var(--red); font-size: 13px; }
.msg-actions { display: flex; gap: 4px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg.assistant:hover .msg-actions,
.msg.assistant:focus-within .msg-actions,
.msg.assistant.last .msg-actions { opacity: 1; }
.msg-actions button { min-height: 28px; padding: 0 9px; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--muted); font-size: 12.5px; font-weight: 700; }
.msg-actions button:hover { border-color: var(--line); background: var(--surface-soft); color: var(--ink); }

/* ---------- 输入框 ---------- */
.composer-wrap { flex: 0 0 auto; padding: 10px 18px calc(12px + env(safe-area-inset-bottom)); background: var(--surface); }
.notice { width: min(760px, 100%); margin: 0 auto 8px; padding: 10px 12px; border: 1px solid #ead09a; border-radius: 9px; background: var(--amber-soft); color: var(--amber); font-size: 13.5px; line-height: 1.6; }
.notice a { color: inherit; font-weight: 800; }
.composer {
  width: min(760px, 100%);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 6px 20px rgba(21, 34, 28, .06);
}
.composer:focus-within { border-color: #86c7a1; box-shadow: 0 0 0 3px rgba(8, 119, 71, .12), 0 6px 20px rgba(21, 34, 28, .06); }
.composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 200px;
  padding: 7px 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 16px;
  line-height: 1.55;
}
.composer textarea::placeholder { color: var(--faint); }
.send-btn, .stop-btn {
  flex: 0 0 auto;
  min-width: 64px;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 11px;
  font-size: 14.5px;
  font-weight: 800;
}
.send-btn { background: var(--green); color: #ffffff; }
.send-btn:hover { background: var(--green-deep); }
.send-btn:disabled { cursor: not-allowed; background: #cfd8d3; color: #ffffff; }
.stop-btn { background: var(--nav); color: #ffffff; }
.stop-btn:hover { background: #263830; }
.composer-note { width: min(760px, 100%); margin: 8px auto 0; color: var(--faint); font-size: 12px; text-align: center; }

/* ---------- 对话框 / 提示 ---------- */
.dialog { width: min(420px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgba(21, 34, 28, .25); }
.dialog::backdrop { background: rgba(10, 18, 14, .45); }
.dialog-body { display: grid; gap: 12px; padding: 22px; }
.dialog-body h2 { margin: 0; font-size: 19px; }
.dialog-body > p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.dialog-body .form-msg { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--nav);
  color: #ffffff;
  font-size: 14px;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}
.noscript { margin: 24px 16px; padding: 12px; border: 1px solid #ead09a; border-radius: 8px; background: var(--amber-soft); color: var(--amber); }

/* ---------- 平板 / 手机 ---------- */
@media (max-width: 900px) {
  .chat-view { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    width: min(300px, 84vw);
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    transform: translateX(-105%);
    transition: transform .2s ease;
  }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
  .side-close { display: inline-grid; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(10, 18, 14, .45); }
  .scrim[hidden] { display: none !important; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .conv-del { opacity: 1; }
  .msg-actions { opacity: 1; }
}
@media (max-width: 600px) {
  .scroller { padding: 18px 14px 12px; }
  .empty { margin-top: 2vh; }
  .empty h2 { font-size: 22px; }
  .empty > p { font-size: 14px; margin-bottom: 18px; }
  .examples { gap: 8px; }
  .example { min-height: 0; padding: 10px 12px; }
  .example span { display: none; }
  .chip { max-width: 44vw; padding: 0 10px; font-size: 12px; }
  .top-title { font-size: 14px; }
  .msg-list { gap: 18px; }
  .msg.assistant { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .msg.assistant > .brand-mark { display: none; }
  .msg.user .bubble { max-width: 88%; }
  .answer, .msg.user .bubble { font-size: 15.5px; }
  .composer-wrap { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .desktop-only { display: none; }
  .auth-card { padding: 22px 18px 18px; }
  .auth-title { font-size: 22px; }
}
@media (hover: none) {
  .msg-actions { opacity: 1; }
  .conv-del { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .caret::after, .dots i { animation: none; }
  .sidebar { transition: none; }
}
