:root {
  --bg: #F6F6F3;
  --panel: #FFFFFF;
  --line: #E6E4DD;
  --line-strong: #D3D1C7;
  --ink: #1D1D1B;
  --ink-2: #4A4A46;
  --muted: #78776F;
  --accent: #0F6E56;
  --accent-soft: #E1F5EE;
  --accent-line: #9FE1CB;
  --warn: #854F0B;
  --warn-soft: #FAEEDA;
  --danger: #A32D2D;
  --danger-soft: #FCEBEB;
  --blue: #185FA5;
  --blue-soft: #E6F1FB;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Helvetica Neue", var(--font-sans), sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
code, pre, .mono { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 12px; }

.layout { display: flex; min-height: 100vh; }
.side {
  width: 216px; flex: 0 0 216px; background: var(--panel);
  border-right: 1px solid var(--line); padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 4px 8px 18px; }
.brand .dot { width: 22px; height: 22px; border-radius: 7px; background: var(--accent); position: relative; }
.brand .dot::after { content: ""; position: absolute; inset: 6px; border-radius: 3px; background: var(--accent-soft); }
.brand b { font-size: 14px; font-weight: 500; letter-spacing: .2px; }
.brand small { display: block; color: var(--muted); font-size: 11px; line-height: 1.2; font-weight: 400; }
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 8px;
  color: var(--ink-2); cursor: pointer; font-size: 13px; user-select: none;
}
.nav-item:hover { background: #F4F4F0; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-item .ico { width: 15px; height: 15px; opacity: .7; }
.nav-spacer { flex: 1; }
.side-foot { font-size: 11px; color: var(--muted); padding: 8px; border-top: 1px solid var(--line); }

.main { flex: 1; padding: 28px 34px 60px; max-width: 1180px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
h1 { font-size: 19px; font-weight: 500; margin: 0 0 4px; letter-spacing: -.2px; }
h2 { font-size: 14px; font-weight: 500; margin: 26px 0 10px; }
h3 { font-size: 13px; font-weight: 500; margin: 0 0 6px; }
.sub { color: var(--muted); font-size: 12.5px; margin: 0; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card + .card { margin-top: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.grid { display: grid; gap: 12px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 1fr 1fr; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 11.5px; }
.stat .v { font-size: 22px; font-weight: 500; letter-spacing: -.5px; margin-top: 2px; }
.stat .v small { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong);
  background: #fff; color: var(--ink); padding: 6px 12px; border-radius: 7px; cursor: pointer;
  font-size: 12.5px; font-family: inherit; transition: .12s; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #0B5A46; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.danger { color: var(--danger); border-color: #EFD3D3; }
.btn.sm { padding: 3px 8px; font-size: 11.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 7px; padding: 7px 9px;
  font-size: 13px; font-family: inherit; color: var(--ink); background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 62px; line-height: 1.6; }

.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 20px;
  font-size: 11px; line-height: 1.7; white-space: nowrap;
}
.tag.ok { background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--danger-soft); color: var(--danger); }
.tag.info { background: var(--blue-soft); color: var(--blue); }
.tag.gray { background: #F1EFE8; color: #5F5E5A; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.tbl th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 11.5px;
  padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.tbl td { padding: 8px 10px; border-bottom: 1px solid #F2F0EA; vertical-align: top; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tr.clickable { cursor: pointer; }
table.tbl tr.clickable:hover td { background: #FAFAF7; }
.scroll { overflow: auto; }
.scroll-y { max-height: 520px; overflow: auto; }

.progress { height: 5px; background: #EFEDE6; border-radius: 4px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .4s; }

.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: "SF Mono", ui-monospace, Menlo, monospace; }
.pre {
  background: #FBFAF7; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 11.5px; white-space: pre-wrap;
  word-break: break-word; line-height: 1.6; overflow-x: auto;
}
.md { font-size: 13px; line-height: 1.75; }
.md h1 { font-size: 16px; margin: 0 0 6px; }
.md h2 { font-size: 13px; margin: 18px 0 6px; color: var(--accent); }
.md ul { margin: 4px 0; padding-left: 18px; }
.md li { margin: 2px 0; }
.md code { background: #F1EFE8; padding: 1px 5px; border-radius: 4px; }
.md blockquote { margin: 10px 0 0; padding: 6px 10px; border-left: 2px solid var(--accent-line); color: var(--muted); font-size: 12px; }

.split { display: grid; grid-template-columns: 330px 1fr; gap: 14px; align-items: start; }
.list-item { padding: 9px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.list-item:hover { background: #FAFAF7; }
.list-item.active { background: var(--accent-soft); border-color: var(--accent-line); }
.list-item .t { font-size: 12.5px; font-weight: 500; display: flex; justify-content: space-between; gap: 8px; }
.list-item .d { font-size: 11.5px; color: var(--muted); line-height: 1.5; margin-top: 2px; }

.banner { border: 1px solid var(--accent-line); background: var(--accent-soft); border-radius: 9px; padding: 10px 13px; font-size: 12.5px; }
.banner.warn { border-color: #EFD9A8; background: var(--warn-soft); }
.banner.bad { border-color: #F0C9C9; background: var(--danger-soft); }

.empty { text-align: center; color: var(--muted); padding: 34px 10px; font-size: 12.5px; }
.toast-wrap { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 99; }
.toast {
  background: #1D1D1B; color: #fff; padding: 9px 14px; border-radius: 8px; font-size: 12.5px;
  box-shadow: 0 6px 24px rgba(0,0,0,.14); animation: slide .2s ease;
}
.toast.err { background: #A32D2D; }
@keyframes slide { from { transform: translateY(6px); opacity: 0; } }

.modal-mask {
  position: fixed; inset: 0; background: rgba(20,20,18,.28); display: flex; align-items: center;
  justify-content: center; z-index: 60; padding: 20px;
}
.modal { background: #fff; border-radius: 12px; width: 520px; max-width: 100%; padding: 20px; max-height: 86vh; overflow: auto; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { width: 340px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 26px; }
.steps { display: flex; flex-direction: column; gap: 6px; }
.step { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; background: #FCFCFA; }
.step .h { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.sqltable { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 11.5px; }
.sqltable td, .sqltable th { white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.conf { display: inline-flex; align-items: center; gap: 5px; }
.conf i { display: block; width: 46px; height: 4px; border-radius: 3px; background: #EAE8E1; overflow: hidden; }
.conf i b { display: block; height: 100%; background: var(--accent); }
@media (max-width: 900px) {
  .side { width: 60px; flex-basis: 60px; padding: 16px 8px; }
  .brand small, .nav-item span, .side-foot { display: none; }
  .split, .grid-4, .grid-2 { grid-template-columns: 1fr; }
  .main { padding: 20px 16px 50px; }
}

/* ---------------- chat harness（问数台） ---------------- */

body.chatmode .main { padding: 0; max-width: none; height: 100vh; overflow: hidden; }
.chat { display: flex; flex-direction: column; height: 100vh; background: #FCFCFA; }
.chat-top {
  flex: 0 0 54px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; border-bottom: 1px solid var(--line); background: #fff;
}
.chat-top select { width: auto; min-width: 180px; padding: 4px 8px; font-size: 12.5px; border-color: var(--line); }
.chat-dot { width: 9px; height: 9px; border-radius: 3px; background: var(--accent); }
.chat-body { flex: 1; overflow-y: auto; padding: 26px 22px 12px; }
.chat-body > * { max-width: 780px; margin-left: auto; margin-right: auto; }

.chat-empty {
  min-height: 54vh; padding: 0 10px; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.chat-empty .hello { font-size: 21px; font-weight: 500; letter-spacing: -.2px; }
.chat-empty .sub { margin: 8px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 7px 13px;
  font-size: 12.5px; color: var(--ink-2); cursor: pointer; font-family: inherit; transition: .12s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.msg { display: flex; gap: 10px; margin-bottom: 24px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: #EEF2EF; color: var(--ink); padding: 9px 14px; border-radius: 14px 14px 4px 14px;
  max-width: 78%; white-space: pre-wrap; font-size: 13.5px; line-height: 1.7;
}
.msg.ai { align-items: flex-start; }
.ava {
  flex: 0 0 26px; width: 26px; height: 26px; border-radius: 8px; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; margin-top: 2px;
}
.ai-body { flex: 1; min-width: 0; }

.toolbox { border-left: 2px solid #E6E4DD; padding: 2px 0 2px 12px; margin-bottom: 12px; }
.toolbox-head {
  display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted);
  min-height: 20px; user-select: none;
}
.toolbox-head.done { cursor: pointer; color: var(--ink-2); }
.toolbox-head.done:hover { color: var(--accent); }
.tlabel { font-variant-numeric: tabular-nums; }
.okmark { color: var(--accent); font-size: 12px; }
.failmark { color: var(--danger); font-size: 12px; }
.steps { margin-top: 8px; }
.hidden { display: none !important; }

.step { border: 1px solid transparent; border-radius: 7px; margin: 2px 0; }
.srow {
  display: flex; align-items: center; gap: 7px; padding: 3px 6px; border-radius: 6px;
  font-size: 12px; cursor: pointer; color: var(--ink-2);
}
.srow:hover { background: #F4F4F0; }
.ssum {
  font-size: 11.5px; color: var(--muted); line-height: 1.55; padding: 0 6px 4px 18px;
  word-break: break-word;
}
.ssum:empty { display: none; }
.sdot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent-line); flex: 0 0 5px; }
.step.pending .sdot { background: var(--warn); }
.step.failed .sdot { background: var(--danger); }
.sname { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 11.5px; color: var(--ink); }
.sarg {
  color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; flex: 1; min-width: 0;
}
.sms { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.sbody { padding: 6px 6px 8px; }
.pre.sm { font-size: 11px; padding: 7px 9px; background: #FAFAF7; max-height: 180px; overflow: auto; }
.pre.sm.out { margin-top: 6px; color: var(--ink-2); }

.stream { font-size: 14.5px; line-height: 1.8; word-break: break-word; }
.stream .md p:first-child { margin-top: 0; }
.cursor {
  display: inline-block; width: 7px; height: 15px; background: var(--accent);
  vertical-align: -2px; margin-left: 2px; border-radius: 1px;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.spin {
  width: 11px; height: 11px; border: 1.5px solid #D9D7CE; border-top-color: var(--accent);
  border-radius: 50%; animation: rot .8s linear infinite; display: inline-block; flex: 0 0 11px;
}
@keyframes rot { to { transform: rotate(360deg); } }

.resultblock {
  margin-top: 14px; border: 1px solid var(--line); border-radius: 9px; background: #fff; overflow: hidden;
}
.rb-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 12px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--ink-2);
  background: #FCFCFA;
}
.resultblock .scroll { max-height: 320px; }
.resultblock .pre { border: 0; border-radius: 0; margin: 0; }

.chat-foot { flex: 0 0 auto; padding: 6px 22px 16px; background: linear-gradient(#FCFCFA00, #FCFCFA 26%); }
.composer {
  max-width: 780px; margin: 0 auto; display: flex; align-items: flex-end; gap: 6px;
  background: #fff; border: 1px solid var(--line-strong); border-radius: 14px;
  padding: 6px 6px 6px 12px; box-shadow: 0 2px 12px rgba(29,29,27,.05);
}
.composer:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 2px var(--accent-soft); }
.composer textarea {
  border: 0; padding: 5px 0; resize: none; max-height: 168px; font-size: 13.5px; line-height: 1.65;
  background: transparent; flex: 1; outline: none; box-shadow: none;
}
.composer textarea:focus { border: 0; box-shadow: none; }
.send {
  flex: 0 0 28px; width: 28px; height: 28px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 15px; line-height: 1; transition: .12s;
}
.send:hover:not(:disabled) { background: #0B5A46; }
.send:disabled { background: #CFCDC5; cursor: not-allowed; }
.send.stop { background: #3A3A36; font-size: 10px; }
.foot-hint { max-width: 780px; margin: 8px auto 0; text-align: center; font-size: 11px; color: var(--tertiary, #9B998F); }
@media (max-width: 900px) {
  .chat-body { padding: 18px 14px 8px; }
  .chat-foot { padding: 6px 14px 12px; }
  .chat-top { padding: 0 14px; }
}
