/* 丝路天山 · 新疆AI平台  —— 视觉：天山蓝 / 大漠金 / 草原绿 / 和田玫 */
:root {
  --bg: #0a1822;
  --bg-2: #0f2533;
  --panel: rgba(255, 255, 255, .045);
  --panel-2: rgba(255, 255, 255, .07);
  --line: rgba(243, 217, 164, .16);
  --text: #e9eff3;
  --muted: #93a8b8;
  --gold: #e0a33f;
  --gold-soft: #f3d9a4;
  --lake: #3a9cc4;
  --grass: #4a9a68;
  --rose: #cf6272;
  --sunset: #e2703a;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .28);
  --grad-gold: linear-gradient(135deg, #f3d9a4, #e0a33f 55%, #c9762a);
  --font: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Source Han Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
}

[data-theme="light"] {
  --bg: #f6f1e7;
  --bg-2: #fffdf8;
  --panel: rgba(28, 62, 84, .045);
  --panel-2: rgba(28, 62, 84, .07);
  --line: rgba(28, 62, 84, .14);
  --text: #1d3243;
  --muted: #6b8496;
  --shadow: 0 10px 26px rgba(30, 60, 80, .12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* 背景：中国地图点阵（由 mapbg.js 绘制） */
#mapBg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; display: block;
  background:
    radial-gradient(1100px 620px at 78% 42%, rgba(58, 156, 196, .10), transparent 62%),
    radial-gradient(900px 620px at 18% 88%, rgba(74, 154, 104, .07), transparent 64%);
}
[data-theme="light"] #mapBg {
  background:
    radial-gradient(1000px 600px at 78% 40%, rgba(58, 156, 196, .09), transparent 62%),
    radial-gradient(900px 560px at 16% 90%, rgba(224, 163, 63, .10), transparent 60%);
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: relative; z-index: 3;
  height: 62px; display: flex; align-items: center; gap: 18px;
  padding: 0 18px;
  background: linear-gradient(180deg, rgba(10, 24, 34, .92), rgba(10, 24, 34, .72));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
[data-theme="light"] .topbar { background: linear-gradient(180deg, rgba(255, 253, 248, .95), rgba(255, 253, 248, .8)); }

.brand { display: flex; align-items: center; gap: 10px; min-width: 208px; }
.brand-mark { width: 34px; height: 34px; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .35)); }
.brand-text h1 {
  margin: 0; font-size: 17px; letter-spacing: 2px; font-weight: 700;
  background: var(--grad-gold); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 1px; }

.tabs { display: flex; gap: 6px; margin-left: 6px; }
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  background: transparent; border: 1px solid transparent; color: var(--muted);
  font-size: 14px; font-family: var(--font); transition: .18s;
}
.tab:hover { background: var(--panel); color: var(--text); }
.tab.active {
  color: var(--text); border-color: rgba(224, 163, 63, .45);
  background: linear-gradient(180deg, rgba(224, 163, 63, .16), rgba(224, 163, 63, .06));
}
.tab .ico { font-size: 15px; }

.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 3px rgba(147, 168, 184, .16); }
.dot.ok { background: var(--grass); box-shadow: 0 0 0 3px rgba(74, 154, 104, .18); }
.dot.bad { background: var(--rose); box-shadow: 0 0 0 3px rgba(207, 98, 114, .18); }
.icon-btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  width: 34px; height: 34px; border-radius: 10px; cursor: pointer; font-size: 15px;
}
.icon-btn:hover { background: var(--panel-2); }

/* ---------------- 舞台 ---------------- */
.stage { position: relative; z-index: 2; height: calc(100% - 62px); }
.view { display: none; height: 100%; }
.view.active { display: flex; }

/* ---------------- 对话视图 ---------------- */
#view-chat { gap: 0; }
.side {
  width: 236px; flex: 0 0 236px; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 12px 12px 8px; background: rgba(0, 0, 0, .12);
}
[data-theme="light"] .side { background: rgba(28, 62, 84, .03); }
.side-head { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--muted); letter-spacing: 2px; margin-bottom: 8px; }
.mini-btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 4px 9px; font-size: 12px; cursor: pointer; font-family: var(--font);
}
.mini-btn:hover { background: var(--panel-2); border-color: rgba(224, 163, 63, .4); }
.mini-btn.ghost { background: transparent; }

.conv-list { flex: 1 1 auto; overflow: auto; display: flex; flex-direction: column; gap: 4px; min-height: 60px; }
.conv {
  padding: 8px 10px; border-radius: 10px; cursor: pointer; font-size: 13px;
  color: var(--muted); border: 1px solid transparent; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.conv:hover { background: var(--panel); color: var(--text); }
.conv.active { background: linear-gradient(90deg, rgba(224, 163, 63, .16), transparent); border-color: rgba(224, 163, 63, .3); color: var(--text); }
.side-sec-title { font-size: 11px; color: var(--muted); letter-spacing: 2px; margin: 12px 0 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 999px; padding: 5px 10px; font-size: 12px; cursor: pointer; transition: .15s; font-family: var(--font);
}
.chip:hover { color: var(--text); border-color: rgba(224, 163, 63, .45); transform: translateY(-1px); }
.chip.on { background: linear-gradient(135deg, rgba(224, 163, 63, .22), rgba(58, 156, 196, .16)); color: var(--text); border-color: rgba(224, 163, 63, .5); }
.side-foot { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.side-stat { font-size: 11px; color: var(--muted); }

.chat-col { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
.messages { flex: 1 1 auto; overflow-y: auto; padding: 22px 6% 12px; display: flex; flex-direction: column; gap: 18px; scroll-behavior: smooth; }
.msg { display: flex; gap: 12px; max-width: 100%; animation: rise .25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.me { flex-direction: row-reverse; }
.avatar {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 10px; display: grid; place-items: center;
  font-size: 15px; border: 1px solid var(--line); background: var(--panel);
}
.msg.ai .avatar { background: linear-gradient(135deg, rgba(224, 163, 63, .3), rgba(58, 156, 196, .25)); }
.bubble {
  max-width: min(760px, 78%); padding: 12px 15px; border-radius: 14px; line-height: 1.72; font-size: 14.5px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); word-break: break-word;
}
.msg.me .bubble { background: linear-gradient(135deg, rgba(58, 156, 196, .2), rgba(224, 163, 63, .12)); border-color: rgba(58, 156, 196, .3); }
.msg.err .bubble { border-color: rgba(207, 98, 114, .5); color: #ffd9de; }

/* markdown 渲染 */
.bubble h1, .bubble h2, .bubble h3 { margin: .6em 0 .35em; line-height: 1.4; font-size: 15.5px; }
.bubble h1 { font-size: 18px; color: var(--gold-soft); }
.bubble h2 { color: var(--gold-soft); }
.bubble p { margin: .5em 0; }
.bubble ul, .bubble ol { margin: .5em 0; padding-left: 1.4em; }
.bubble li { margin: .28em 0; }
.bubble code { background: rgba(128, 128, 128, .22); padding: 1px 5px; border-radius: 5px; font-size: 13px; font-family: ui-monospace, Consolas, monospace; }
.bubble pre { background: rgba(0, 0, 0, .38); padding: 12px; border-radius: 10px; overflow-x: auto; border: 1px solid var(--line); }
.bubble pre code { background: none; padding: 0; }
.bubble blockquote { margin: .6em 0; padding: 6px 12px; border-left: 3px solid var(--gold); color: var(--muted); background: rgba(224, 163, 63, .07); border-radius: 0 8px 8px 0; }
.bubble table { border-collapse: collapse; margin: .6em 0; font-size: 13.5px; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 6px 10px; }
.bubble th { background: rgba(224, 163, 63, .12); }
.bubble a { color: var(--lake); }
.bubble hr { border: none; border-top: 1px solid var(--line); margin: .8em 0; }
.cursor::after { content: "▌"; color: var(--gold); animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
.thinking { color: var(--muted); font-size: 13px; border-left: 2px solid var(--line); padding-left: 10px; margin-bottom: 8px; }

.refs-inline { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; font-size: 12px; color: var(--muted); }
.refs-inline b { color: var(--gold-soft); font-weight: 600; }

.offline-tip {
  margin-bottom: 10px; padding: 6px 10px; border-radius: 8px; font-size: 12px;
  background: rgba(224, 145, 63, .12); border: 1px solid rgba(224, 145, 63, .35);
  color: var(--gold-soft);
}
.offline-tip a { color: var(--gold-soft); text-decoration: underline; }

.composer { padding: 10px 6% 16px; }
.composer-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.kb-toggle { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 12.5px; color: var(--muted); user-select: none; }
.kb-toggle input { display: none; }
.kb-toggle .track { width: 34px; height: 18px; border-radius: 999px; background: rgba(128, 128, 128, .3); position: relative; transition: .2s; border: 1px solid var(--line); }
.kb-toggle .knob { position: absolute; top: 1.5px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #cfd8de; transition: .2s; }
.kb-toggle input:checked + .track { background: linear-gradient(90deg, var(--gold), var(--sunset)); }
.kb-toggle input:checked + .track .knob { left: 17px; background: #fff; }
.kb-label { color: var(--muted); }
.kb-toggle input:checked ~ .kb-label { color: var(--gold-soft); }
.hint { font-size: 12px; color: var(--muted); }

.composer-input { display: flex; align-items: flex-end; gap: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; transition: .18s; }
.composer-input:focus-within { border-color: rgba(224, 163, 63, .5); box-shadow: 0 0 0 3px rgba(224, 163, 63, .1); }
#input {
  flex: 1 1 auto; background: transparent; border: none; outline: none; resize: none; color: var(--text);
  font-family: var(--font); font-size: 14.5px; line-height: 1.6; max-height: 168px; padding: 4px 2px;
}
.send-btn, .stop-btn {
  border: none; cursor: pointer; width: 38px; height: 38px; border-radius: 11px; font-size: 15px; color: #23180a;
  background: var(--grad-gold); box-shadow: 0 4px 14px rgba(224, 163, 63, .3);
}
.stop-btn { background: linear-gradient(135deg, #cf6272, #a33f4d); color: #fff; }
.send-btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

.refs { width: 0; overflow: hidden; border-left: 1px solid var(--line); background: rgba(0, 0, 0, .12); transition: width .22s; }
[data-theme="light"] .refs { background: rgba(28, 62, 84, .03); }
.refs.open { width: 292px; padding: 12px; }
.refs-head { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); letter-spacing: 1px; margin-bottom: 8px; }
.refs-body { height: calc(100% - 30px); overflow: auto; }
.ref-card { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 11px; margin-bottom: 8px; font-size: 12.5px; line-height: 1.6; }
.ref-title { color: var(--gold-soft); font-weight: 600; margin-bottom: 4px; }
.ref-text { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.ref-url { margin-bottom: 4px; font-size: 11.5px; word-break: break-all; }
.ref-url a { color: var(--lake); }

/* ---------------- 画境 ---------------- */
.img-layout, .kb-layout, .set-wrap { width: 100%; height: 100%; overflow: auto; }
.img-layout { display: flex; gap: 16px; padding: 18px 4%; flex-wrap: wrap; }
.img-panel { flex: 1 1 420px; min-width: 320px; }
.gallery-col { flex: 1 1 380px; min-width: 300px; display: flex; flex-direction: column; }
.sec-title { margin: 0 0 4px; font-size: 20px; letter-spacing: 1px; color: var(--gold-soft); }
.sec-desc { margin: 0 0 14px; color: var(--muted); font-size: 13.5px; line-height: 1.7; }
.prompt-box {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); padding: 12px 14px; font-family: var(--font); font-size: 14.5px; line-height: 1.7; outline: none; resize: vertical;
}
.prompt-box:focus { border-color: rgba(224, 163, 63, .5); box-shadow: 0 0 0 3px rgba(224, 163, 63, .1); }
.field-label { font-size: 12px; color: var(--muted); letter-spacing: 1px; margin: 14px 0 8px; }
.chips.scenes .chip { max-width: 100%; }
.text-input, select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 9px 11px; font-family: var(--font); font-size: 13.5px; outline: none;
}
.text-input:focus, select:focus { border-color: rgba(224, 163, 63, .5); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.img-actions { display: flex; align-items: center; gap: 10px; margin: 18px 0 6px; flex-wrap: wrap; }
.primary-btn {
  border: none; cursor: pointer; padding: 10px 20px; border-radius: 11px; font-size: 14px; font-family: var(--font);
  color: #241a08; background: var(--grad-gold); box-shadow: 0 6px 18px rgba(224, 163, 63, .28); font-weight: 600;
}
.ghost-btn {
  cursor: pointer; padding: 9px 16px; border-radius: 11px; font-size: 13.5px; font-family: var(--font);
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
}
.ghost-btn:hover, .primary-btn:hover { filter: brightness(1.06); }

.gallery-head { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 10px; letter-spacing: 1px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 12px; align-content: start; }
.gcard { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); animation: rise .3s; }
.gcard img { width: 100%; display: block; aspect-ratio: 1/1; object-fit: cover; background: rgba(0, 0, 0, .25); }
.gcard .meta { padding: 7px 9px; font-size: 11.5px; color: var(--muted); line-height: 1.5; max-height: 46px; overflow: hidden; }
.gcard .acts { display: flex; gap: 6px; padding: 0 9px 9px; }
.gcard a { color: var(--lake); font-size: 11.5px; text-decoration: none; border: 1px solid var(--line); padding: 2px 8px; border-radius: 7px; }

/* ---------------- 知识库 ---------------- */
.kb-layout { display: flex; gap: 16px; padding: 18px 4%; align-items: flex-start; }
.kb-side { width: 260px; flex: 0 0 260px; position: sticky; top: 0; }
.kb-main { flex: 1 1 auto; min-width: 0; }
.kb-reader { width: 380px; flex: 0 0 380px; border-left: 1px solid var(--line); padding-left: 14px; max-height: 100%; overflow: auto; }
.kb-stats { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 12.5px; color: var(--muted); line-height: 1.9; }
.kb-stats b { color: var(--gold-soft); font-size: 15px; }
.kb-search { display: flex; gap: 8px; }
.cat-list { display: flex; flex-direction: column; gap: 4px; }
.cat {
  display: flex; justify-content: space-between; padding: 7px 10px; border-radius: 9px; cursor: pointer;
  font-size: 13px; color: var(--muted); border: 1px solid transparent;
}
.cat:hover { background: var(--panel); color: var(--text); }
.cat.on { background: linear-gradient(90deg, rgba(224, 163, 63, .16), transparent); border-color: rgba(224, 163, 63, .3); color: var(--text); }
.cat span:last-child { opacity: .7; }

.doc-list, .kb-results { display: grid; gap: 10px; }
.doc-card {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 12px 14px; cursor: pointer; transition: .16s;
}
.doc-card:hover { border-color: rgba(224, 163, 63, .45); transform: translateY(-1px); }
.doc-title { font-size: 15px; color: var(--gold-soft); font-weight: 600; margin-bottom: 3px; }
.doc-desc { font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.doc-tags { font-size: 11.5px; color: var(--muted); margin-top: 6px; opacity: .85; }
.res-card { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 11px 13px; }
.res-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.res-head b { color: var(--gold-soft); }
.res-text { font-size: 13.5px; line-height: 1.75; }
.res-text em { background: rgba(224, 163, 63, .28); font-style: normal; border-radius: 3px; }
.reader-body { font-size: 13.5px; line-height: 1.85; color: var(--text); }
.reader-body h1 { font-size: 17px; color: var(--gold-soft); }
.reader-body h2 { font-size: 15px; color: var(--gold-soft); border-left: 3px solid var(--gold); padding-left: 9px; }
.reader-body h3 { font-size: 14px; }
.reader-body code { background: rgba(128, 128, 128, .2); padding: 1px 4px; border-radius: 4px; }

/* ---------------- 设置 ---------------- */
.set-wrap { padding: 20px 6%; max-width: 940px; margin: 0 auto; }
.set-card { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.set-card h3 { margin: 0 0 12px; font-size: 15px; color: var(--gold-soft); letter-spacing: 1px; }
.set-card label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.set-card label .text-input, .set-card label textarea, .set-card label input { margin-top: 5px; }
.quick-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; }
.probe-box { margin-top: 10px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 10px; background: rgba(255, 255, 255, 0.02); }
.probe-box .hint b { color: var(--gold-soft); }
.probe-box .quick-row { margin-top: 8px; }
.set-actions { display: flex; align-items: center; gap: 10px; margin-bottom: 30px; flex-wrap: wrap; }

/* ---------------- 通用 ---------------- */
.muted { color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translate(-50%, 20px); z-index: 99;
  background: rgba(12, 26, 36, .96); border: 1px solid var(--line); color: var(--text);
  padding: 11px 18px; border-radius: 12px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: .25s;
  box-shadow: var(--shadow); max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(147, 168, 184, .3); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(224, 163, 63, .45); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  .side, .refs { display: none; }
  .side.open, .refs.open { display: block; position: fixed; z-index: 20; top: 62px; bottom: 0; background: var(--bg); border: none; }
  .tabs .lab { display: none; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .messages { padding: 16px 4% 8px; }
  .composer { padding: 8px 4% 12px; }
  .bubble { max-width: 88%; }
  .brand-text .brand-sub { display: none; }
  .kb-layout { flex-direction: column; }
  .kb-side { width: 100%; flex: none; position: static; }
  .kb-reader { width: 100%; flex: none; }
}
