:root {
  --bg: #f4f2ec;
  --panel: #fbfaf7;
  --card: #ffffff;
  --ink: #1d1d1b;
  --ink-2: #45433d;
  --muted: #7c786e;
  --line: #e4e0d6;
  --line-2: #d6d1c4;
  --accent: #1f6f5c;
  --accent-deep: #17574a;
  --accent-soft: #e4efe9;
  --warn: #9a5b12;
  --warn-soft: #fbf1df;
  --danger: #b3372c;
  --prompt-bg: #1b2420;
  --prompt-ink: #e8efe9;
  --radius: 14px;
  --font: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.75 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: not-allowed; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

#app { display: grid; grid-template-columns: 264px minmax(0, 1fr); height: 100dvh; }

/* ── 侧栏 ── */
#side { display: flex; flex-direction: column; min-height: 0; padding: 20px 14px 14px; background: var(--panel); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px 18px; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 700; font-size: 17px; flex: none; }
.brand strong { display: block; font-size: 15px; line-height: 1.3; letter-spacing: .01em; }
.brand small { color: var(--muted); font-size: 12px; }
.new-btn { display: flex; align-items: center; justify-content: center; gap: 6px; height: 40px; border-radius: 10px; background: var(--ink); color: #fff; font-weight: 600; transition: background .15s; }
.new-btn:hover { background: #000; }
.side-label { margin: 22px 8px 6px; font-size: 12px; color: var(--muted); letter-spacing: .08em; }
#history { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.h-item { position: relative; display: block; width: 100%; text-align: left; padding: 9px 30px 9px 10px; border-radius: 9px; transition: background .12s; }
.h-item:hover { background: #efece4; }
.h-item.active { background: var(--accent-soft); }
.h-title { display: block; font-size: 13.5px; line-height: 1.45; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-time { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.h-del { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 24px; height: 24px; border-radius: 6px; color: var(--muted); display: none; place-items: center; }
.h-del svg { width: 14px; height: 14px; }
.h-item:hover .h-del, .h-item:focus-within .h-del { display: grid; }
.h-del:hover { background: #e0dbcf; color: var(--danger); }
.h-empty { padding: 10px; font-size: 13px; color: var(--muted); }
.side-foot { margin: 10px 8px 0; font-size: 11.5px; color: #a29e93; }
#scrim { display: none; }

/* ── 主区 ── */
main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top { display: none; }
#scroll { flex: 1; min-height: 0; overflow-y: auto; scroll-behavior: smooth; }
#thread { max-width: 876px; margin: 0 auto; padding: 34px 28px 20px; }

.hero { padding: 13vh 0 0; text-align: center; }
.hero h1 { margin: 0 0 10px; font-size: 30px; line-height: 1.3; font-weight: 700; letter-spacing: -.01em; }
.hero p { margin: 0 auto; max-width: 36em; text-wrap: balance; color: var(--muted); font-size: 15px; }
.hero-out { display: flex; justify-content: center; gap: 10px; margin-top: 30px; flex-wrap: wrap; }
.hero-out span { display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border: 1px solid var(--line); border-radius: 99px; background: var(--panel); font-size: 13px; color: var(--ink-2); }
.hero-out i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.hero-out span:nth-child(2) i { background: var(--prompt-bg); }

/* 用户输入 */
.q { margin: 0 0 18px; display: flex; flex-direction: column; align-items: flex-end; }
.q-box { max-width: 88%; padding: 11px 16px; border-radius: 16px 16px 4px 16px; background: #e9e5db; }
.q-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.7; }
.q-text.clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 6; overflow: hidden; }
.q-more { margin-top: 4px; font-size: 12.5px; color: var(--accent-deep); font-weight: 600; }
.q-files { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 8px; max-width: 88%; }
.q-files:first-child { margin-top: 0; }

/* 附件小片 */
.chip { position: relative; display: flex; align-items: center; gap: 9px; height: 52px; max-width: 230px; padding: 5px 12px 5px 5px; border: 1px solid var(--line-2); border-radius: 11px; background: var(--card); }
.chip-thumb { width: 40px; height: 40px; border-radius: 7px; object-fit: cover; background: #eee; flex: none; }
.chip-ico { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 7px; font: 700 10.5px/1 var(--mono); letter-spacing: .02em; color: #fff; flex: none; }
.chip-ico.pdf { background: #c2473b; }
.chip-ico.word { background: #2f5fa8; }
.chip-ico.text { background: #6c6a62; }
.chip-ico.image { background: #6b8f7f; }
.chip-meta { min-width: 0; }
.chip-name { display: block; font-size: 12.5px; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-sub { display: block; font-size: 11px; line-height: 1.4; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.err { border-color: #e2b4ae; background: #fdf3f1; }
.chip.err .chip-sub { color: var(--danger); }
.chip-x { position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; }
.chip-x svg { width: 11px; height: 11px; stroke-width: 2.6; }
.chip-bar { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--accent); border-radius: 0 0 0 11px; transition: width .2s; }
.chip.busy .chip-thumb, .chip.busy .chip-ico { opacity: .55; }

/* 答疑结果 */
.a { margin: 0 0 34px; }
.status { display: inline-flex; align-items: center; gap: 9px; padding: 4px 0 10px; color: var(--muted); font-size: 13.5px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite both; }
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 80%, 100% { opacity: .22; } 40% { opacity: 1; } }

.judge { margin-bottom: 12px; padding: 11px 15px 12px; border-left: 3px solid var(--line-2); background: #efece4; border-radius: 0 10px 10px 0; }
.judge-tag { font-size: 11.5px; letter-spacing: .06em; color: var(--muted); }
.judge-body { margin: 1px 0 0; font-size: 13.5px; line-height: 1.7; color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.refs { margin-top: 6px; font-size: 11.5px; color: #99958a; line-height: 1.6; }
.notice { margin-bottom: 12px; padding: 8px 13px; border-radius: 9px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }

.card { border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 12px 0 18px; }
.card-title { display: flex; align-items: baseline; gap: 9px; font-size: 13px; font-weight: 700; letter-spacing: .04em; }
.card-title small { font-weight: 400; font-size: 11.5px; letter-spacing: 0; opacity: .6; }
.card-body { padding: 6px 18px 17px; white-space: pre-wrap; overflow-wrap: anywhere; outline: none; min-height: 1.75em; }
.copy-btn { display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 10px; border-radius: 8px; font-size: 12.5px; font-weight: 600; transition: background .12s; }
.copy-btn svg { width: 14px; height: 14px; }

.card.reply { background: var(--card); border: 1px solid var(--line); }
.card.reply .card-title { color: var(--accent-deep); }
.card.reply .copy-btn { color: var(--accent-deep); }
.card.reply .copy-btn:hover { background: var(--accent-soft); }
.card.reply .card-body { font-size: 15px; }

.card.prompt { background: var(--prompt-bg); color: var(--prompt-ink); }
.card.prompt .card-title { color: #8fd0b7; }
.card.prompt .copy-btn { color: #cfe6dc; }
.card.prompt .copy-btn:hover { background: rgba(255, 255, 255, .1); }
.card.prompt .card-body { font-size: 14.5px; line-height: 1.8; }
.card.prompt ::selection { background: rgba(143, 208, 183, .35); }

.caret::after { content: ""; display: inline-block; width: 2px; height: 1.05em; margin-left: 2px; vertical-align: -.16em; background: currentColor; animation: caret 1s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }

.a-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.all-btn { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 16px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; font-size: 14px; transition: background .15s; }
.all-btn:hover { background: var(--accent-deep); }
.tune { height: 32px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 99px; font-size: 12.5px; color: var(--ink-2); background: var(--panel); transition: border-color .12s, color .12s; }
.tune:hover { border-color: var(--accent); color: var(--accent-deep); }
.a-foot .gap { flex: 1; }
.a-err { margin-bottom: 12px; padding: 10px 14px; border-radius: 10px; background: #fdf1ef; color: var(--danger); font-size: 13.5px; display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.a-err button { font-weight: 600; text-decoration: underline; text-underline-offset: 3px; color: inherit; white-space: nowrap; }

/* ── 输入区 ── */
#composerWrap { padding: 0 28px 20px; }
#composer { max-width: 820px; margin: 0 auto; padding: 12px 12px 10px 16px; background: var(--card); border: 1px solid var(--line-2); border-radius: 18px; box-shadow: 0 10px 34px -18px rgba(40, 36, 24, .3); transition: border-color .15s, box-shadow .15s; }
#composer:focus-within { border-color: var(--accent); box-shadow: 0 10px 34px -16px rgba(31, 111, 92, .36); }
#pending { display: flex; flex-wrap: wrap; gap: 10px; }
#pending:not(:empty) { padding: 6px 0 12px; }
#input { display: block; width: 100%; max-height: 38vh; min-height: 28px; padding: 2px 0; border: 0; outline: 0; resize: none; background: transparent; line-height: 1.7; }
#input::placeholder { color: #a9a59a; }
.composer-bar { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.ghost-btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px 0 8px; margin-left: -8px; border-radius: 9px; font-size: 13px; color: var(--ink-2); }
.ghost-btn:hover { background: #f0ede5; }
.hint { flex: 1; text-align: right; font-size: 12px; color: #a9a59a; }
.send-btn { height: 38px; min-width: 96px; padding: 0 18px; border-radius: 11px; background: var(--accent); color: #fff; font-weight: 600; font-size: 14px; transition: background .15s, opacity .15s; }
.send-btn:hover:not(:disabled) { background: var(--accent-deep); }
.send-btn:disabled { opacity: .38; }
.send-btn.stop { background: var(--ink); }
#banner { max-width: 820px; margin: 0 auto 10px; padding: 9px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 13.5px; text-align: center; }

/* ── 浮层 ── */
#drop { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(31, 111, 92, .12); backdrop-filter: blur(3px); }
#drop div { padding: 26px 44px; border: 2px dashed var(--accent); border-radius: 20px; background: rgba(255, 255, 255, .93); color: var(--accent-deep); font-size: 17px; font-weight: 600; pointer-events: none; }
#toast { position: fixed; left: 50%; bottom: 120px; z-index: 40; transform: translate(-50%, 10px); padding: 8px 18px; border-radius: 99px; background: var(--ink); color: #fff; font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; max-width: 86vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#gate { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: var(--bg); }
#gateForm { width: min(340px, 88vw); display: flex; flex-direction: column; align-items: center; text-align: center; }
#gateForm h1 { margin: 16px 0 2px; font-size: 21px; }
#gateForm p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
#gateForm input { width: 100%; height: 44px; padding: 0 14px; margin-bottom: 12px; border: 1px solid var(--line-2); border-radius: 11px; background: var(--card); outline: 0; text-align: center; }
#gateForm input:focus { border-color: var(--accent); }
#gateForm .send-btn { width: 100%; height: 44px; }
.gate-err { min-height: 22px; margin-top: 10px; color: var(--danger); font-size: 13px; }

/* 滚动条 */
#scroll::-webkit-scrollbar, #history::-webkit-scrollbar, #input::-webkit-scrollbar { width: 9px; }
#scroll::-webkit-scrollbar-thumb, #history::-webkit-scrollbar-thumb, #input::-webkit-scrollbar-thumb { background: #d4cfc2; border-radius: 9px; border: 2px solid transparent; background-clip: padding-box; }

/* ── 窄屏 ── */
@media (max-width: 860px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  #side { position: fixed; z-index: 21; inset: 0 auto 0 0; width: min(290px, 84vw); transform: translateX(-102%); transition: transform .22s ease; box-shadow: 0 0 50px rgba(0, 0, 0, .18); }
  body.side-open #side { transform: none; }
  body.side-open #scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .28); }
  .top { display: flex; align-items: center; gap: 6px; height: 52px; padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
  #topTitle { flex: 1; text-align: center; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px; }
  #thread { padding: 20px 14px 12px; }
  #composerWrap { padding: 0 10px calc(10px + env(safe-area-inset-bottom)); }
  .hero { padding-top: 7vh; }
  .hero h1 { font-size: 24px; }
  .hint { visibility: hidden; }
  .q-box, .q-files { max-width: 100%; }
  .h-del { display: grid; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
