/* AI 风控助手面板：左右分栏（左=既有业务区，右=对话工作台），整页无全局滚动。
   宽度由 --ai-w 变量驱动（初始 35%，可拖拽），左区最小 40%、右区最小 25%。 */
:root { --ai-w: 35%; --ai-w-min: 25%; --ai-w-max: 60%; }
html, body { height: 100%; overflow: hidden; }
body {
  display: flex;
  flex-direction: column;
  padding-right: var(--ai-w);
}

/* 左侧业务区：顶部刊头（.sidebar）保持文档流可见，业务内容在 main 内独立滚动 */
.workspace {
  flex: 1 1 auto;
  min-height: 0;
  margin-right: 0 !important;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.workspace > header { flex: 0 0 auto; }
.workspace > main { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.workspace > footer { flex: 0 0 auto; }

/* 可拖拽分割条 */
#ai-chat-splitter {
  position: fixed;
  top: 0; bottom: 0;
  right: calc(var(--ai-w) - 2.5px);
  width: 5px;
  z-index: 70;
  cursor: col-resize;
  background: transparent;
  transition: background .15s;
  touch-action: none;
}
#ai-chat-splitter::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--line, #dfe5e4);
  opacity: .9;
  transition: background .15s, opacity .15s;
}
#ai-chat-splitter:hover::after,
#ai-chat-splitter:focus-visible::after { background: var(--accent, #167765); opacity: 1; }
body.ai-dragging #ai-chat-splitter::after { background: var(--accent, #167765); opacity: 1; box-shadow: 0 0 0 1px rgba(22,119,101,.35); }
body.ai-dragging { cursor: col-resize; user-select: none; -webkit-user-select: none; }
body.ai-dragging .workspace > main { pointer-events: none; }
body.ai-dragging #ai-chat-history { pointer-events: none; }

/* 右侧 AI 工作台：固定列，独立三段（头部 / 对话 / 输入） */
#ai-chat-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: var(--ai-w);
  min-width: 380px;
  display: flex;
  flex-direction: column;
  background: var(--ai-panel-bg, #fdfdfb);
  border-left: 1px solid var(--line, #e3e9e8);
  z-index: 60;
  font-family: inherit;
}
.ai-chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--line, #e3e9e8);
  background: var(--ai-panel-bg, #fdfdfb);
}
.ai-chat-avatar {
  width: 34px; height: 34px;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--accent, #167765);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.ai-chat-avatar svg { width: 20px; height: 20px; display: block; }
.ai-chat-title { display: grid; gap: 2px; min-width: 0; }
.ai-chat-title b { font-size: 14px; color: var(--ink, #20373d); letter-spacing: .3px; }
.ai-chat-title small { font-size: 10.5px; color: var(--muted, #75868b); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-chat-controls { flex:0 0 auto; display:grid; grid-template-columns:1fr 1fr; gap:8px 10px; padding:10px 16px; border-bottom:1px solid var(--line,#e3e9e8); }
.ai-chat-controls label { font-size:10.5px; color:var(--muted,#75868b); margin:0; min-width:0; }
.ai-chat-controls select { width:100%; font-family:inherit; font-size:11px; line-height:1.5; padding:7px 5px; margin-top:4px; color:var(--ink,#20373d); }
.ai-context-note { grid-column:1/-1; margin:0; font-size:11px; line-height:1.5; color:var(--muted,#75868b); }

.ai-chat-history {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
}
.ai-chat-history::-webkit-scrollbar { width: 8px; }
.ai-chat-history::-webkit-scrollbar-thumb { background: var(--line, #dfe5e4); border-radius: 4px; }

/* 欢迎块 */
.ai-chat-welcome { display: grid; gap: 10px; }
.ai-chat-welcome h3 { margin: 0; font-size: 17px; color: var(--ink, #20373d); }
.ai-chat-welcome p { margin: 0; font-size: 12px; line-height: 1.8; color: var(--ink, #20373d); }
.ai-chat-disclaimer { font-size: 10.5px; color: var(--muted, #75868b); border-left: 2px solid var(--orange, #a9682f); padding-left: 8px; }

/* 快捷问题标签 */
.ai-chat-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 4px; }
.ai-chip {
  font: inherit; font-size: 11.5px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line, #dfe5e4);
  background: transparent;
  color: var(--ink, #20373d);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.ai-chip:hover { border-color: var(--accent, #167765); background: rgba(22, 119, 101, .06); }

/* 消息 */
.ai-msg { display: flex; flex-direction: column; max-width: 94%; }
.ai-msg-user { align-self: flex-end; align-items: flex-end; }
.ai-msg-ai { align-self: flex-start; align-items: flex-start; }
.ai-bubble {
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.75;
  word-break: break-word;
}
.ai-msg-user .ai-bubble { background: var(--accent, #167765); color: #fff; border-bottom-right-radius: 4px; }
.ai-msg-ai .ai-bubble { background: #fff; color: var(--ink, #20373d); border: 1px solid var(--line, #e3e9e8); border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(32, 55, 61, .04); }
.ai-bubble p { margin: 0 0 7px; }
.ai-bubble p:last-child { margin-bottom: 0; }
.ai-bubble strong { font-weight: 600; }
.ai-bubble code { font-family: Consolas, monospace; font-size: 11.5px; background: rgba(32,55,61,.06); padding: 1px 5px; border-radius: 4px; }
.ai-msg-user .ai-bubble code { background: rgba(255,255,255,.22); }
.ai-bubble pre { background: rgba(32,55,61,.05); border: 1px solid var(--line, #e3e9e8); border-radius: 8px; padding: 9px 11px; overflow-x: auto; }
.ai-bubble pre code { background: none; padding: 0; }
.ai-bubble ul, .ai-bubble ol { margin: 2px 0 7px; padding-left: 18px; }
.ai-md-heading { margin: 8px 0 4px; font-size: 12.5px; font-weight: 600; }
.ai-msg-ai .ai-md-heading:first-child { margin-top:4px; }
.ai-result-meta { margin:0 0 9px; padding:0 0 8px; border-bottom:1px solid var(--line,#e3e9e8); font-size:10.5px; color:var(--muted,#75868b); line-height:1.7; }
.ai-model-notice { font-size:11.5px; padding:8px 10px; border-left:2px solid var(--orange,#a9682f); background:rgba(169,104,47,.05); }
.ai-progress small { display:block; color:var(--muted,#75868b); font-size:10.5px; }
.ai-progress-label { font-weight:600; }
.ai-retry { font:inherit; font-size:11px; padding:5px 10px; margin-top:7px; border:1px solid var(--line,#e3e9e8); background:white; border-radius:5px; }
.ai-call-details { font-size:10px; margin-top:6px; color:var(--muted,#75868b); }
.ai-call-details summary { font-size:10px; }
.ai-call-details p { margin:6px 0 0; line-height:1.7; }
.ai-formula { margin: 8px 0; padding: 8px 10px; background: rgba(32,55,61,.035); border-radius: 8px; overflow-x: auto; text-align: center; }

/* 报告视觉层：指标卡片 / 分位仪表 / 观点摘要 / 归因条形图（与导出报告同套语义） */
.ai-report-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 4px 0 10px; }
.ai-metric-card { position: relative; overflow: hidden; background: #fbfdfc; border: 1px solid var(--line, #e3e9e8); border-radius: 9px; padding: 9px 11px; }
.ai-metric-card::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2px; background: linear-gradient(90deg, var(--accent, #167765), #4aa08c); }
.ai-mc-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 10.5px; font-weight: 600; color: var(--muted, #75868b); letter-spacing: .02em; margin-bottom: 4px; }
.ai-mc-status { font-size: 9px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line, #e3e9e8); background: #eaf5f1; color: var(--accent, #167765); white-space: nowrap; }
.ai-mc-value { font-size: 22px; font-weight: 700; font-family: Consolas, monospace; font-variant-numeric: tabular-nums; color: var(--ink, #20373d); line-height: 1.2; white-space: nowrap; }
.ai-mc-sub { font-size: 10.5px; color: var(--muted, #75868b); margin-top: 3px; }
.ai-mc-unit { font-size: 9.5px; color: var(--muted, #9aa7a5); margin-top: 2px; }
.ai-gauge { position: relative; height: 4px; background: #e8eeec; border-radius: 999px; margin-top: 6px; }
.ai-gauge-fill { height: 100%; border-radius: 999px; }
.ai-gauge-mark { position: absolute; top: -2px; width: 2px; height: 8px; background: var(--ink, #20373d); border-radius: 1px; }
.ai-insight { border-left: 3px solid var(--accent, #167765); background: rgba(22, 119, 101, .05); border-radius: 0 9px 9px 0; padding: 9px 12px; margin: 0 0 10px; }
.ai-insight-head { font-size: 12px; font-weight: 600; color: var(--accent, #167765); letter-spacing: .04em; margin-bottom: 5px; }
.ai-insight p { margin: 4px 0; font-size: 12px; line-height: 1.75; }
.ai-attr-chart { margin: 2px 0 10px; }
.ai-attr-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.ai-attr-label { flex: none; width: 52px; font-size: 10.5px; color: var(--muted, #75868b); text-align: right; }
.ai-attr-track { flex: 1; height: 11px; background: #eef3f1; border-radius: 4px; overflow: hidden; }
.ai-attr-bar { height: 100%; border-radius: 4px 0 0 4px; }
.ai-attr-val { flex: none; width: 96px; font-size: 10.5px; font-family: Consolas, monospace; font-variant-numeric: tabular-nums; }

/* 打字指示 */
.ai-typing { display: inline-flex; gap: 5px; padding: 12px 14px; }
.ai-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted, #9aa7a5); animation: ai-blink 1.2s infinite ease-in-out; }
.ai-typing span:nth-child(2) { animation-delay: .18s; }
.ai-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes ai-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* 引用徽章与弹层 */
.ai-cite-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.ai-cite-badge {
  font: inherit; font-size: 10.5px;
  font-family: Consolas, monospace;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line, #dfe5e4);
  background: #fff;
  color: var(--accent, #167765);
  cursor: pointer;
}
.ai-cite-badge:hover { border-color: var(--accent, #167765); }
.ai-cite-popover {
  position: absolute;
  width: min(340px, calc(100% - 24px));
  background: #fff;
  border: 1px solid var(--line, #dfe5e4);
  border-radius: 10px;
  box-shadow: 0 8px 26px rgba(16, 45, 54, .16);
  padding: 12px 14px;
  z-index: 80;
}
.ai-cite-title { font-size: 12px; font-weight: 600; color: var(--ink, #20373d); }
.ai-cite-type { font-size: 10px; color: var(--muted, #75868b); margin: 2px 0 6px; }
.ai-cite-path { margin: 0 0 6px; padding-left: 16px; font-size: 11px; line-height: 1.7; color: var(--ink, #20373d); }
.ai-cite-excerpt { margin: 4px 0 8px; font-size: 10.5px; color: var(--muted, #75868b); line-height: 1.6; }
.ai-cite-close { font: inherit; font-size: 11px; padding: 4px 12px; border-radius: 7px; border: 1px solid var(--line, #dfe5e4); background: transparent; cursor: pointer; }
.ai-cite-actions, .ai-check-actions { display:flex; flex-wrap:wrap; align-items:center; gap:6px; }
.ai-evidence-open { font:inherit; font-size:10.5px; padding:3px 8px; border:1px solid var(--line,#dfe5e4); border-radius:6px; background:transparent; color:var(--accent,#167765); cursor:pointer; }
.ai-evidence-open:disabled, .ai-bound-retry:disabled { opacity:.5; cursor:default; }
.ai-evidence-notice { flex:1 0 100%; margin:3px 0 0; font-size:10.5px; line-height:1.6; color:var(--muted,#75868b); }
.ai-conversation-meta { display:grid; gap:3px; margin:0 0 9px; padding:7px 9px; border-left:2px solid var(--accent,#167765); background:rgba(22,119,101,.045); line-height:1.65; }
.ai-conversation-meta strong { font-size:11px; }
.ai-conversation-meta span { font-size:11px; }
.ai-conversation-meta small { color:var(--muted,#75868b); font-size:10px; }
.ai-investigation { box-sizing:border-box; width:100%; margin-top:8px; padding:9px 10px; border:1px solid var(--line,#dfe5e4); border-radius:9px; color:var(--ink,#20373d); background:var(--ai-panel-bg,#fdfdfb); }
.ai-investigation > summary { font-size:11.5px; font-weight:600; cursor:pointer; }
.ai-investigation-focus { margin:8px 0; font-size:11px; line-height:1.7; }
.ai-check { margin-top:8px; padding-top:8px; border-top:1px solid var(--line,#dfe5e4); }
.ai-check-title { display:flex; flex-wrap:wrap; align-items:baseline; gap:5px 8px; }
.ai-check-title strong { flex:1 1 150px; font-size:11.5px; }
.ai-check-status { font-size:9.5px; white-space:nowrap; padding:1px 5px; border-radius:4px; background:rgba(117,134,139,.1); }
.ai-check-status-verified { color:var(--accent,#167765); background:rgba(22,119,101,.08); }
.ai-check-status-review_required { color:var(--orange,#a9682f); background:rgba(169,104,47,.08); }
.ai-check p { margin:6px 0; font-size:11px; line-height:1.75; overflow-wrap:anywhere; }
.ai-check p b { font-weight:600; }
.ai-investigation-note { margin:9px 0 0; font-size:10px; line-height:1.7; color:var(--muted,#75868b); }

/* 输入区 */
.ai-chat-input-area { flex: 0 0 auto; border-top: 1px solid var(--line, #e3e9e8); padding: 12px 14px 10px; background: var(--ai-panel-bg, #fdfdfb); }
.ai-chat-thread { display:flex; flex-wrap:wrap; align-items:center; gap:5px 8px; margin:0 0 8px; }
#ai-chat-thread-label { flex:1 1 180px; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:10px; color:var(--muted,#75868b); }
.ai-chat-thread-actions { display:flex; gap:5px; }
.ai-chat-thread-actions button { font:inherit; font-size:10px; line-height:1.6; padding:2px 7px; border:1px solid var(--line,#dfe5e4); border-radius:5px; background:transparent; color:var(--accent,#167765); cursor:pointer; }
.ai-chat-thread-actions button:disabled { opacity:.45; cursor:default; }
#ai-chat-locate-note { flex:1 0 100%; font-size:9.5px; line-height:1.55; color:var(--muted,#75868b); }
#ai-chat-locate-note:empty { display:none; }
.ai-chat-input-row { display: flex; align-items: flex-end; gap: 9px; }
.ai-chat-input {
  flex: 1 1 auto;
  font: inherit; font-size: 12.5px; line-height: 1.6;
  padding: 9px 13px;
  min-height: 40px;
  max-height: 120px;
  resize: none;
  border-radius: 13px;
  border: 1px solid var(--line, #dfe5e4);
  background: #fff;
  color: var(--ink, #20373d);
  outline: none;
  transition: border-color .15s;
}
.ai-chat-input:focus { border-color: var(--accent, #167765); }
.ai-chat-send {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent, #167765);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, transform .1s;
}
.ai-chat-send:hover { opacity: .88; }
.ai-chat-send:active { transform: scale(.94); }
.ai-chat-send svg { width: 17px; height: 17px; display: block; }
.ai-chat-model-note { margin: 8px 2px 0; font-size: 10px; color: var(--muted, #75868b); line-height: 1.6; }
.ai-chat-telemetry {
  margin-top: 8px; padding: 8px 10px 7px; border: 1px solid var(--line, #dfe8e2);
  border-radius: 9px; background: #f5f8f6;
}
.ai-chat-telemetry-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.ai-chat-telemetry-head strong { color: var(--ink, #29453a); font-size: 10px; font-weight: 650; }
.ai-chat-telemetry-head span { color: var(--muted, #75868b); font-size: 9px; text-align: right; }
.ai-chat-telemetry-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 9px; }
.ai-chat-telemetry-grid>div { min-width: 0; }
.ai-chat-telemetry-grid span { display: block; color: var(--muted, #75868b); font-size: 8.5px; line-height: 1.4; }
.ai-chat-telemetry-grid strong { display: block; margin-top: 2px; color: var(--ink, #29453a); font-size: 10px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-chat-telemetry-note { margin: 6px 0 0; color: var(--muted, #75868b); font-size: 8.5px; line-height: 1.45; }
@media (max-width: 420px) { .ai-chat-telemetry-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* KaTeX 精简离线样式子集（无外部字体；覆盖本面板用到的结构） */
.katex { font-family: "Cambria Math", "Latin Modern Math", Georgia, "Times New Roman", serif; font-size: 1.02em; line-height: 1.35; white-space: nowrap; }
.katex .katex-mathml { position: absolute; clip: rect(1px, 1px, 1px, 1px); padding: 0; border: 0; height: 1px; width: 1px; overflow: hidden; }
.katex .katex-html { display: inline; }
.katex .base { display: inline; margin: 0 1.5px; }
.katex .mord, .katex .mbin, .katex .mrel, .katex .mopen, .katex .mclose { display: inline; }
.katex .mbin { margin: 0 3px; }
.katex .mrel { margin: 0 4px; }
.katex .mop { display: inline; margin: 0 2px; }
.katex .msupsub { display: inline; font-size: .72em; position: relative; top: -.55em; vertical-align: baseline; }
.katex .msubsup .vlist-t .vlist > span > .mord.mathnormal { font-size: 1em; }
.katex .vlist { display: inline; }
.katex .vlist > span { display: inline; }
.katex .vlist-r { display: inline; }
.katex .mfrac { display: inline-block; vertical-align: middle; text-align: center; margin: 0 2px; }
.katex .mfrac > span:first-child { display: block; padding: 0 3px; border-bottom: 1px solid currentColor; }
.katex .mfrac > span:last-child { display: block; padding: 0 3px; }
.katex .sqrt { display: inline; }
.katex .sqrt > .sqrt-sign { margin-right: 1px; }
.katex .delimsizing, .katex .delimsizinginner { font-size: 1.05em; }
.katex .mathnormal { font-style: italic; }
.katex .mathdefault { font-style: italic; }
.katex .textstyle { font-style: normal; }
.katex-display { display: block; margin: 6px 0; text-align: center; }
.katex-display > .katex { white-space: normal; }
.katex .katex-html[aria-hidden="true"] { position: static; clip: auto; height: auto; width: auto; overflow: visible; }

/* Narrow windows keep the assistant below the workspace. */
@media (max-width: 1150px) {
  #ai-chat-splitter { display:none; }
  #ai-chat-panel { position:static; width:100%; min-width:0; height:auto; max-height:none; border-left:0; border-top:1px solid var(--line,#e3e9e8); }
  #ai-chat-history { flex:0 0 auto; height:62vh; min-height:340px; max-height:620px; }
  body { padding-right: 0; display: block; }
  .workspace { height: auto; }
  html, body { overflow: auto; height: auto; }
}
@media(prefers-reduced-motion:reduce){.ai-typing span{animation:none}.ai-chat-send,.ai-chip{transition:none}}
