/* ============================================================
   深信服智能知识助手 —— 界面样式
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
button { cursor: pointer; border: none; background: none; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-pill);
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

/* ============================================================
   骨架布局
   ============================================================ */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

/* 顶部品牌色细线：呼应 logo 蓝绿缎带 */
.app::before {
  content: '';
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--brand-gradient);
  z-index: 100;
}

/* ============================================================
   左侧导航栏
   ============================================================ */
.rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  padding-top: 3px;
  transition: margin-left .28s var(--ease);
}

.rail__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
}

.brandmark {
  height: 30px;
  width: auto;
  flex-shrink: 0;
  display: block;
}

/* 字标「SANGFOR 深信服科技」在源文件中是一组无 class 的 path，
   未声明 fill，因而继承 svg 根节点的填充色。这里挂上主题色，
   深色模式即可自动反白。地球缎带的各 path 都有 class 显式指定渐变填充，
   优先级高于继承，配色不受影响。 */
.brandmark { fill: var(--text); }

.rail__brandtext {
  min-width: 0;
  padding-left: 11px;
  border-left: 1px solid var(--border-strong);
}

.rail__title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .2px;
  color: var(--text);
  white-space: nowrap;
}

.rail__sub {
  font-size: 11.5px;
  color: var(--text-3);
  white-space: nowrap;
  margin-top: 1px;
}

.rail__new {
  margin: 0 14px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  border-radius: var(--r-md);
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-brand);
  transition: background .18s var(--ease), transform .18s var(--ease), box-shadow .18s var(--ease);
}
.rail__new:hover { background: var(--brand-hover); transform: translateY(-1px); }
.rail__new:active { background: var(--brand-active); transform: translateY(0); }

.rail__section {
  padding: 0 18px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text-3);
}

.rail__list {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 12px;
  min-height: 0;
}

.rail__empty {
  padding: 10px 8px;
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.6;
}

.sess {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--text-2);
  font-size: 13.5px;
  transition: background .15s var(--ease), color .15s var(--ease);
  position: relative;
}
.sess:hover { background: var(--surface-3); color: var(--text); }
.sess.is-active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 500; }
.sess.is-active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  width: 3px; height: 16px;
  border-radius: 0 3px 3px 0;
  background: var(--brand);
  transform: translateY(-50%);
}

.sess__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sess__del {
  flex-shrink: 0;
  width: 22px; height: 22px;
  display: grid;
  place-items: center;
  border-radius: var(--r-xs);
  color: var(--text-3);
  opacity: 0;
  transition: opacity .15s var(--ease), color .15s, background .15s;
}
.sess:hover .sess__del { opacity: 1; }
.sess__del:hover { background: var(--danger-soft); color: var(--danger); }

.rail__foot {
  border-top: 1px solid var(--border);
  padding: 12px 14px 14px;
}

.rail__scope {
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--text-3);
  margin-bottom: 10px;
}
.rail__scope b { color: var(--text-2); font-weight: 600; }

.rail__tools { display: flex; gap: 8px; }

.toolbtn {
  flex: 1;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  transition: border-color .15s var(--ease), color .15s, background .15s;
}
.toolbtn:hover { border-color: var(--brand); color: var(--brand); }

/* ============================================================
   主区域
   ============================================================ */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
  padding-top: 3px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
  flex-shrink: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
}

.topbar__toggle {
  display: none;
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  place-items: center;
}
.topbar__toggle:hover { background: var(--surface-2); }

.topbar__title { font-size: 14px; font-weight: 600; }

.topbar__badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-2);
}

.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 20%, transparent);
}
.dot.is-off { background: var(--text-3); box-shadow: none; }
.dot.is-err { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent); }

/* —— 滚动区 —— */
.scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

.thread {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 28px 24px 24px;
}

/* ============================================================
   空状态
   ============================================================ */
.hero {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 56px 24px 24px;
  animation: rise .5s var(--ease-out) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

.hero__mark {
  width: 52px; height: 52px;
  border-radius: 15px;
  background: var(--brand-gradient);
  display: grid;
  place-items: center;
  margin-bottom: 20px;
  box-shadow: var(--shadow-brand);
}
.hero__mark svg { width: 27px; height: 27px; color: #fff; }

.hero__title {
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -.4px;
  margin: 0 0 10px;
  line-height: 1.3;
}
.hero__accent {
  display: inline-block;
  width: 34px;
  height: 3px;
  border-radius: var(--r-pill);
  background: var(--brand-gradient);
  margin-bottom: 16px;
}

.hero__sub {
  font-size: 14.5px;
  color: var(--text-2);
  margin: 0 0 30px;
  max-width: 62ch;
  line-height: 1.7;
}

.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.card {
  text-align: left;
  padding: 15px 16px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color .18s var(--ease), transform .18s var(--ease), box-shadow .18s var(--ease);
  position: relative;
  overflow: hidden;
}
.card::after {
  content: '';
  position: absolute;
  inset: auto auto 0 0;
  width: 100%; height: 2px;
  background: var(--brand-gradient);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .3s var(--ease-out);
}
.card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
}
.card:hover::after { transform: scaleX(1); }

.card__head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.card__icon {
  width: 26px; height: 26px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  background: var(--brand-soft);
  color: var(--brand);
  flex-shrink: 0;
}
.card__icon svg { width: 14px; height: 14px; }
.card__title { font-size: 13px; font-weight: 600; color: var(--text); }
.card__text { font-size: 13px; color: var(--text-2); line-height: 1.6; }

/* ============================================================
   消息
   ============================================================ */
.msg { margin-bottom: 26px; animation: rise .35s var(--ease-out) both; }

/* 用户消息：右对齐卡片 */
.msg--user { display: flex; justify-content: flex-end; }
.msg--user .msg__body {
  max-width: 76%;
  padding: 11px 15px;
  border-radius: var(--r-lg) var(--r-lg) var(--r-xs) var(--r-lg);
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow-brand);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
}

/* 助手消息：文档流 */
.msg--bot { display: flex; gap: 13px; }

.avatar {
  width: 30px; height: 30px;
  flex-shrink: 0;
  border-radius: 9px;
  background: var(--brand-gradient);
  display: grid;
  place-items: center;
  margin-top: 2px;
}
.avatar svg { width: 16px; height: 16px; color: #fff; }

.msg--bot .msg__body { flex: 1; min-width: 0; padding-top: 2px; }

/* —— 思考步骤 —— */
.trace {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 10px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-2);
  margin-bottom: 10px;
}

.trace__spin {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid var(--brand-soft);
  border-top-color: var(--brand);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.caret {
  display: inline-block;
  width: 7px; height: 15px;
  vertical-align: -2px;
  margin-left: 2px;
  background: var(--brand);
  border-radius: 1px;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* —— 消息操作 —— */
.acts {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  opacity: 0;
  transition: opacity .18s var(--ease);
}
.msg:hover .acts, .acts:focus-within { opacity: 1; }

.act {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 27px;
  padding: 0 9px;
  border-radius: var(--r-sm);
  color: var(--text-3);
  font-size: 12px;
  transition: background .15s var(--ease), color .15s;
}
.act:hover { background: var(--surface-2); color: var(--text); }
.act svg { width: 13px; height: 13px; }

/* —— 参考来源 —— */
.cites {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
}

.cites > summary {
  list-style: none;
  cursor: pointer;
  padding: 9px 13px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 7px;
  user-select: none;
  transition: background .15s var(--ease);
}
.cites > summary::-webkit-details-marker { display: none; }
.cites > summary:hover { background: var(--surface-2); }
.cites > summary svg { width: 13px; height: 13px; color: var(--brand); }
.cites__chev { margin-left: auto; transition: transform .2s var(--ease); }
.cites[open] .cites__chev { transform: rotate(180deg); }

.cites__note {
  padding: 7px 13px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 11px;
  color: var(--text-3);
}

.cite {
  padding: 11px 13px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.cite__no {
  flex-shrink: 0;
  width: 19px; height: 19px;
  border-radius: var(--r-xs);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  display: grid;
  place-items: center;
  margin-top: 1px;
}

.cite__main { min-width: 0; flex: 1; }
.cite__name {
  font-size: 12.5px;
  color: var(--text);
  font-weight: 500;
  word-break: break-all;
}
.cite__snip {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.6;
}

.cite__score {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  font-size: 10.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.cite__bar {
  width: 40px; height: 3px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}
.cite__bar i { display: block; height: 100%; border-radius: inherit; background: var(--brand-gradient); }

/* —— 错误条 —— */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 14px;
  border-radius: var(--r-md);
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent);
  color: var(--danger);
  font-size: 13.5px;
  line-height: 1.6;
}
.alert svg { width: 15px; height: 15px; flex-shrink: 0; margin-top: 2px; }
.alert button {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ============================================================
   Markdown 正文
   ============================================================ */
.prose { font-size: 15px; line-height: 1.78; color: var(--text); word-break: break-word; }
.prose > *:first-child { margin-top: 0; }
.prose > *:last-child { margin-bottom: 0; }
.prose p { margin: 0 0 13px; }
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  margin: 22px 0 10px;
  font-weight: 650;
  line-height: 1.4;
  letter-spacing: -.2px;
}
.prose h1 { font-size: 21px; }
.prose h2 { font-size: 18.5px; }
.prose h3 { font-size: 16.5px; }
.prose h4, .prose h5, .prose h6 { font-size: 15px; }
.prose strong { font-weight: 650; color: var(--text); }
.prose em { font-style: italic; }
.prose del { color: var(--text-3); }
.prose a { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; }
.prose a:hover { color: var(--brand-hover); }
.prose ul, .prose ol { margin: 0 0 13px; padding-left: 1.5em; }
.prose li { margin: 4px 0; }
.prose li > ul, .prose li > ol { margin: 4px 0 2px; }
.prose ul { list-style: disc; }
.prose ul ul { list-style: circle; }
.prose ol { list-style: decimal; }
.prose ol::marker, .prose li::marker { color: var(--brand); }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.prose blockquote {
  margin: 0 0 13px;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--brand);
  background: var(--brand-gradient-soft);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  color: var(--text-2);
}
.prose blockquote p:last-child { margin-bottom: 0; }

.md-code-inline {
  font-family: var(--font-mono);
  font-size: .88em;
  padding: 2px 6px;
  border-radius: var(--r-xs);
  background: var(--surface-3);
  color: var(--brand-ink);
  word-break: break-word;
}

.md-codeblock {
  margin: 0 0 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--surface-2);
}
.md-codebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--surface-3);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-3);
  font-family: var(--font-mono);
}
.md-copy {
  font-family: var(--font-sans);
  font-size: 11.5px;
  color: var(--text-2);
  padding: 2px 7px;
  border-radius: var(--r-xs);
  transition: background .15s, color .15s;
}
.md-copy:hover { background: var(--surface); color: var(--brand); }
.md-codeblock pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.md-codeblock code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
}

.md-tablewrap {
  margin: 0 0 14px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.md-tablewrap table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.md-tablewrap th, .md-tablewrap td {
  padding: 9px 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.md-tablewrap th {
  background: var(--surface-2);
  font-weight: 600;
  white-space: nowrap;
  color: var(--text);
}
.md-tablewrap tbody tr:last-child td { border-bottom: none; }
.md-tablewrap tbody tr:hover { background: var(--surface-2); }

/* ============================================================
   输入区
   ============================================================ */
.composer {
  flex-shrink: 0;
  padding: 0 24px 18px;
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}

.composer__inner { max-width: var(--measure); margin: 0 auto; }

.composer__stop {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}
.stopbtn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-2);
  font-size: 13px;
  color: var(--text-2);
  transition: border-color .15s, color .15s;
}
.stopbtn:hover { border-color: var(--danger); color: var(--danger); }
.stopbtn svg { width: 12px; height: 12px; }

.box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 9px 9px 9px 16px;
  border-radius: var(--r-xl);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-2);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.box:focus-within {
  border-color: var(--brand);
  box-shadow: var(--shadow-2), 0 0 0 3px color-mix(in srgb, var(--brand) 15%, transparent);
}

.box textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 15px;
  line-height: 1.6;
  max-height: 200px;
  padding: 7px 0;
  min-height: 34px;
}
.box textarea::placeholder { color: var(--text-3); }

.send {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  transition: background .18s var(--ease), transform .18s var(--ease), opacity .18s;
}
.send:hover:not(:disabled) { background: var(--brand-hover); transform: scale(1.06); }
.send:disabled { background: var(--surface-3); color: var(--text-3); cursor: not-allowed; }
.send svg { width: 17px; height: 17px; }

.composer__hint {
  margin-top: 9px;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-3);
}
.composer__hint kbd {
  font-family: var(--font-sans);
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: var(--r-xs);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
}

/* ============================================================
   提示浮条
   ============================================================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translate(-50%, 12px);
  padding: 9px 18px;
  border-radius: var(--r-pill);
  background: var(--sf-navy);
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-3);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s var(--ease), transform .22s var(--ease);
  z-index: 200;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ============================================================
   响应式
   ============================================================ */
.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(9,18,32,.44);
  z-index: 40;
  opacity: 0;
  transition: opacity .28s var(--ease);
}

@media (max-width: 900px) {
  .rail {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 50;
    margin-left: calc(var(--rail-w) * -1);
    box-shadow: var(--shadow-3);
  }
  .app.is-open .rail { margin-left: 0; }
  .app.is-open .scrim { display: block; opacity: 1; }
  .topbar__toggle { display: grid; }
  .cards { grid-template-columns: 1fr; }
  .thread, .hero { padding-left: 16px; padding-right: 16px; }
  .composer { padding-left: 14px; padding-right: 14px; }
  .hero { padding-top: 34px; }
  .hero__title { font-size: 25px; }
  .msg--user .msg__body { max-width: 88%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
