:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --line: #e3e8f0;
  --text: #1f2733;
  --dim: #8a94a6;
  --brand: #2f6bff;
  --brand-d: #1f4fd8;
  --green: #18a058;
  --amber: #c98a00;
  --red: #d03050;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 40, 90, .08), 0 4px 14px rgba(20, 40, 90, .06);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.6 "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.logo { font-size: 20px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ds-select { max-width: 240px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.badge { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-off { background: #eef1f6; color: #6a7486; }
.badge-on { background: #e5f6ec; color: #14804a; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 8px; padding: 7px 14px; transition: all .15s; white-space: nowrap;
}
.btn:hover { border-color: #c6d2e4; background: #f8faff; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-d); border-color: var(--brand-d); }
.btn-ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.filelabel { display: inline-block; }

/* ---------- 布局 ---------- */
.layout { flex: 1 1 auto; display: flex; min-height: 0; }
.sidebar {
  flex: 0 0 300px; min-width: 300px; background: #fbfcfe;
  border-right: 1px solid var(--line); overflow-y: auto; padding: 12px;
}
.workspace { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
/* ④ 对话输入框置底：结果区在上，输入/操作条固定在底部 */
.workspace .feed { order: 1; }
.workspace .ask-box { order: 2; border-bottom: none; border-top: 1px solid var(--line); border-radius: 0; }
.report-pane {
  flex: 0 0 340px; min-width: 300px; max-width: 42vw; background: #fff;
  border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0;
}

/* ---------- 左栏 ---------- */
.ds-empty { color: var(--dim); text-align: center; padding: 34px 8px; line-height: 2; }
.ds-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ds-chip {
  display: inline-flex; align-items: center; border: 1px solid #cfd9e8; background: #fff; color: #3a4556; border-radius: 999px;
  font-size: 12px; padding: 3px 11px; cursor: pointer; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.6;
  transition: border-color .15s, background .15s, color .15s;
}
.ds-chip:hover { border-color: var(--brand); color: var(--brand); }
.ds-chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.ds-chip .chip-x { margin-left: 4px; opacity: .75; }
.ds-chip .chip-x:hover { opacity: 1; }
.ds-chip > span:not(.chip-x) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pill.drillable { background: #e9f9f1; color: #12874d; border: 1px solid #bfe6d3; }
.text-card { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.9; }
.link-tag {
  font-size: 10.5px; padding: 0 6px; border-radius: 999px; background: #fdf3e7; color: #b07414;
  border: 1px solid #f1ddc0; flex: none;
}
#graphSvg line { stroke-width: 1.6; }
#graphSvg g text { pointer-events: none; }
.ds-info { margin-bottom: 14px; }
.ds-name { font-weight: 700; font-size: 15px; word-break: break-all; }
.ds-stats { color: var(--dim); font-size: 12.5px; margin-top: 4px; line-height: 1.8; }
.side-sec-title {
  font-size: 12.5px; font-weight: 700; color: #5a6472; margin: 10px 0 6px;
  text-transform: uppercase; letter-spacing: .4px;
}
.col-item {
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px;
  margin-bottom: 6px; cursor: default;
}
.col-item .col-name { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; word-break: break-all; }
.type-pill { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #eef4ff; color: #2f5fd0; flex: none; }
.type-pill.t-num { background: #eafaf1; color: #12874d; }
.type-pill.t-time { background: #fdf3e7; color: #b07414; }
.type-pill.t-empty { background: #f0f1f4; color: #99a0ab; }
.col-item .col-meta { color: var(--dim); font-size: 12px; margin-top: 2px; word-break: break-all; }
.col-type-sel {
  margin-top: 4px; font-size: 11.5px; padding: 1px 4px; border: 1px solid var(--line);
  border-radius: 6px; color: #5a6472; background: #fff; max-width: 118px; cursor: pointer;
}
.col-type-sel:hover { border-color: var(--brand); }

/* ---------- 中栏 ---------- */
.ask-box { padding: 12px 16px 8px; background: #fff; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
#question {
  width: 100%; border: 1px solid #cfd9e8; border-radius: 10px; padding: 10px 12px;
  resize: vertical; min-height: 60px; outline: none; transition: border .15s, box-shadow .15s;
}
#question:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47, 107, 255, .12); }
.ask-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.mini { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--dim); white-space: nowrap; }
#chartPick { padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
.chart-opts { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; padding: 2px 0; }
.opts-label { font-size: 12px; color: var(--dim); margin-right: 2px; }
.opts-group { display: inline-flex; gap: 4px; align-items: center; flex-wrap: wrap; }
button.seg {
  border: 1px solid #d5dde9; background: #fff; color: #4a5568; border-radius: 6px;
  font-size: 12px; padding: 1px 9px; line-height: 1.7;
}
button.seg:hover { border-color: var(--brand); color: var(--brand); }
button.seg.on { background: var(--brand); border-color: var(--brand); color: #fff; }
button.seg.dis { opacity: .45; cursor: not-allowed; }
.clarify-q { margin: 8px 0; }
.clarify-text { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.clarify-input { width: 100%; border: 1px solid #cfd9e8; border-radius: 8px; padding: 7px 10px; outline: none; }
.clarify-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47, 107, 255, .12); }
.spacer { flex: 1; }
.feed-note {
  font-size: 12px; color: #2f5fd0; background: #eef4ff; border: 1px dashed #b8c6e0;
  border-radius: 8px; padding: 6px 10px; margin-bottom: 8px;
}
.feed-group-head {
  display: flex; align-items: center; gap: 8px; margin: 8px 0 6px; padding: 4px 8px;
  background: #f2f5fa; border-left: 4px solid var(--brand); border-radius: 6px; font-weight: 700; font-size: 13px;
}
.feed-group-head .g-cnt { font-weight: 400; color: var(--dim); font-size: 12px; }
.feed-group-head .chip-btn { margin-left: auto; font-size: 11.5px; }
.feed { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px; }
.feed-empty { color: var(--dim); text-align: center; padding: 60px 20px; line-height: 2; }

/* ---------- 分析卡片 ---------- */
.card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  margin-bottom: 14px; overflow: hidden;
}
.card-head {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid #f0f2f6;
}
.card-title { font-weight: 700; font-size: 15px; flex: 1; min-width: 0; word-break: break-word; }
.card-mode { font-size: 11px; color: var(--dim); flex: none; margin-top: 3px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; background: #eef4ff; color: #3355b0; }
.pill.llm { background: #e5f6ec; color: #14804a; }
.pill.rule { background: #f0f1f4; color: #6a7486; }
.pill.err { background: #fdecef; color: #c0392b; }
.card-body { padding: 4px 14px 8px; }
.chart { width: 100%; height: 320px; }
.chart-tbl-tip { color: var(--dim); font-size: 12px; padding: 4px 0; }
.insight {
  background: #f7f9fd; border-left: 3px solid var(--brand); border-radius: 0 8px 8px 0;
  padding: 8px 12px; margin-top: 10px; color: #33405c; white-space: pre-wrap; font-size: 13px;
}
.insight .insight-tag { font-weight: 700; color: var(--brand); }
.err-box { padding: 16px; color: #b3392f; white-space: pre-wrap; }
.table-wrap { overflow: auto; max-height: 260px; border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; }
table.data { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.data th, table.data td { border-bottom: 1px solid #eef1f5; padding: 5px 10px; text-align: right; white-space: nowrap; }
table.data th { position: sticky; top: 0; background: #f6f8fc; text-align: right; font-weight: 600; }
table.data th:first-child, table.data td:first-child { text-align: left; }
.card-actions {
  display: flex; gap: 6px; padding: 8px 14px; border-top: 1px solid #f0f2f6; background: #fbfcfe;
  align-items: center; flex-wrap: wrap;
}
.chip-btn { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 2px 12px; font-size: 12.5px; }
.chip-btn:hover { border-color: var(--brand); color: var(--brand); }
.chip-btn.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip-btn.danger:hover { border-color: var(--red); color: var(--red); }
.card .col-meta-info { color: var(--dim); font-size: 12px; }

/* ---------- 右栏 ---------- */
.rp-head { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rp-title { font-weight: 700; font-size: 14px; margin-right: auto; }
.rp-note { color: var(--dim); font-size: 12px; padding: 8px 12px; border-bottom: 1px dashed var(--line); }
.rp-empty { color: var(--dim); text-align: center; padding: 26px 10px; }
.report-list { flex: 1 1 auto; overflow-y: auto; padding: 8px 10px; }
.rp-item {
  display: flex; align-items: center; gap: 6px; background: #f7f9fd; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; margin-bottom: 6px; font-size: 13px;
}
.rp-item .t { flex: 1; word-break: break-all; min-width: 0; }
.rp-item .ord { color: var(--dim); font-size: 12px; flex: none; }
.rp-foot { padding: 8px 12px; border-top: 1px solid var(--line); text-align: right; }
.report-summary { margin: 10px 12px; background: #f0f6ff; border-radius: 10px; padding: 10px 12px; font-size: 13px; white-space: pre-wrap; }
.report-summary .ov-tag { font-weight: 700; color: var(--brand); }
.report-summary .sec { margin-top: 6px; }
.hidden { display: none !important; }

/* ---------- 弹窗 / 忙碌 / toast ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal { background: #fff; border-radius: 14px; width: 480px; max-width: 96vw; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { padding: 14px 16px; font-weight: 700; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-x { margin-left: auto; border: none; background: none; font-size: 16px; color: var(--dim); }
.modal-body { padding: 14px 16px; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: #5a6472; margin-bottom: 4px; }
.field input, .field select { width: 100%; border: 1px solid #cfd9e8; border-radius: 8px; padding: 8px 10px; }
.hint { color: var(--dim); font-size: 12px; margin-top: 3px; }
.test-result { margin-left: 8px; font-size: 12.5px; color: var(--dim); }
.test-result.ok { color: var(--green); }
.test-result.err { color: var(--red); }

.modal-wide { width: 780px; max-width: 96vw; }
.modal-drill { width: min(1240px, 96vw); max-width: none; }
.drill-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 4px 0 6px; font-size: 12px; color: var(--dim); }
.drill-nav .crumb { background: #eef4ff; color: #2f5fd0; border-radius: 6px; padding: 2px 8px; font-size: 12px; }
.drill-link {
  display: inline-flex; align-items: center; gap: 6px; border: 1px dashed #b8c6e0; background: #fbfdff;
  border-radius: 8px; padding: 3px 9px; font-size: 12px; color: #2f5fd0; cursor: pointer;
}
.drill-link:hover { border-style: solid; border-color: var(--brand); background: #eef4ff; }
.drill-link .arr { color: var(--dim); }
table.data tbody tr.drill-row { cursor: pointer; }
table.data tbody tr.drill-row:hover { background: #f2f6ff; }
.drill-acts { display: inline-flex; gap: 5px; flex-wrap: wrap; margin-left: 6px; }
.drill-acts .drill-link { border-style: solid; padding: 1px 8px; font-size: 11.5px; }
.tbl-new-row {
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap; padding: 6px;
  border: 1px solid var(--line); border-radius: 8px; background: #fbfdff; margin-bottom: 6px; font-size: 12.5px;
}
.tbl-new-row input { width: 100px; border: 1px solid #cfd9e8; border-radius: 6px; padding: 4px 6px; font-size: 12px; }
#tblGrid td { white-space: nowrap; }
#tblGrid td input { border: 1px solid #b9c7e2; border-radius: 6px; padding: 3px 5px; font-size: 12px; width: 104px; }
#tblGrid td .chip-btn { margin-right: 4px; white-space: nowrap; }
.db-sec { margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px dashed var(--line); }
.db-sec:last-of-type { border-bottom: none; }
.db-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
.db-grid .field { margin-bottom: 8px; }
.check-row { display: flex; align-items: flex-end; padding-bottom: 9px; }
.check-row label { margin: 0; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check-row input { width: auto; }
.db-actions { display: flex; align-items: center; gap: 8px; }
.db-title { font-size: 13px; font-weight: 700; margin-bottom: 6px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.db-title .hint { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; }
.num-inp { width: 96px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; }
.db-search { width: 100%; border: 1px solid #cfd9e8; border-radius: 8px; padding: 7px 10px; margin-bottom: 6px; }
.db-tables { max-height: 210px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.db-row {
  width: 100%; text-align: left; background: #fff; border: none; border-bottom: 1px solid #f0f2f6;
  padding: 6px 10px; font-size: 13px; cursor: pointer; display: flex; gap: 8px; align-items: baseline;
}
.db-row:hover { background: #f2f6ff; }
.db-row .kind { font-size: 11px; color: var(--dim); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; flex: none; }
.db-row .schema { color: var(--dim); font-size: 11.5px; flex: none; }
.db-sql { width: 100%; border: 1px solid #cfd9e8; border-radius: 8px; padding: 8px 10px; resize: vertical; font: 12.5px/1.6 Consolas, 'Courier New', monospace; }

.statusbar {
  padding: 5px 16px; background: #fff; border-top: 1px solid var(--line);
  color: var(--dim); font-size: 12px; flex: 0 0 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.busy-mask {
  position: fixed; inset: 0; background: rgba(255,255,255,.55); z-index: 60;
  display: flex; align-items: center; justify-content: center;
}
.busy-box { background: #fff; border-radius: 12px; padding: 18px 26px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 12px; }
.spin { width: 22px; height: 22px; border: 3px solid #dbe3f0; border-top-color: var(--brand); border-radius: 50%; animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

#toastWrap { position: fixed; top: 14px; right: 14px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1f2733; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 380px; white-space: pre-wrap; animation: slide .2s ease;
}
.toast.err { background: #b3261e; }
.toast.ok { background: #1a7f45; }
@keyframes slide { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 1200px) {
  .sidebar { flex-basis: 240px; min-width: 240px; }
  .report-pane { flex-basis: 300px; min-width: 260px; max-width: 40vw; }
}
