:root {
  --font-size: 14px;
  --bg: #f4f6f9;
  --panel-bg: #ffffff;
  --border: #d8dee8;
  --text: #2d3748;
  --muted: #718096;
  --accent: #2b6cb0;
  --accent-dark: #1f4e79;
  --run-green: #2f855a;
  --stop-red: #c53030;
  --sys-text: #6b7280;
  --err-text: #c53030;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  font-size: var(--font-size);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* ---------- 工具栏 ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: linear-gradient(#fdfefe, #eef2f7);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 15px; color: var(--accent-dark); }
.brand-sub { font-size: 11px; color: var(--muted); }
.tb-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tb-right { margin-left: auto; }
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.tb-label { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.tb-label select {
  font-size: 12px; padding: 3px 4px; border: 1px solid var(--border);
  border-radius: 4px; background: #fff; color: var(--text);
}
button {
  font-size: 13px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
button:hover:not(:disabled) { background: #edf2f7; border-color: #b8c2d0; }
button:disabled { opacity: .45; cursor: not-allowed; }
.btn-run { color: #fff; background: var(--run-green); border-color: var(--run-green); font-weight: 600; }
.btn-run:hover:not(:disabled) { background: #276749; }
.btn-stop { color: #fff; background: var(--stop-red); border-color: var(--stop-red); font-weight: 600; }
.btn-stop:hover:not(:disabled) { background: #9b2c2c; }
.status { font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); }
.status.loading { color: #975a16; background: #fefcbf; border-color: #f6e05e; }
.status.ready { color: #22543d; background: #c6f6d5; border-color: #9ae6b4; }
.status.error { color: #822727; background: #fed7d7; border-color: #fc8181; }

/* ---------- 主区 ---------- */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  border-bottom: 1px solid var(--border);
}
.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel-bg);
}
.pane-title {
  padding: 5px 12px;
  font-size: 12px;
  color: var(--muted);
  background: #eef2f7;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.pane-title::-webkit-scrollbar { display: none; }
.mini-btn {
  font-size: 11px; padding: 1px 8px; margin-left: auto;
  border-radius: 4px;
}
#editorHost { flex: 1; min-height: 0; overflow: hidden; }
.CodeMirror {
  height: 100% !important;
  font-family: Consolas, "Courier New", monospace;
  font-size: var(--font-size);
  line-height: 1.5;
}
.CodeMirror-gutters { border-right: 1px solid var(--border); background: #fafbfd; }
.CodeMirror-activeline-background { background: #f0f6ff; }

/* ---------- 变量面板 ---------- */
.vars-pane {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--panel-bg);
}
.vars-scroll { flex: 1; overflow: auto; }
#varTable { width: 100%; border-collapse: collapse; font-size: 12px; }
#varTable th, #varTable td {
  text-align: left; padding: 4px 8px;
  border-bottom: 1px solid #edf0f5;
  word-break: break-all;
  max-width: 170px;
}
#varTable th {
  position: sticky; top: 0;
  background: #f7f9fc; color: var(--muted); font-weight: 600;
  border-bottom: 1px solid var(--border);
}
#varTable td.v-name { color: var(--accent-dark); font-weight: 600; font-family: Consolas, monospace; }
#varTable td.v-type { color: #805ad5; font-family: Consolas, monospace; white-space: nowrap; }
#varTable td.v-val { font-family: Consolas, monospace; color: #2d3748; }
.empty-hint {
  padding: 22px 14px; font-size: 12px; color: #a0aec0;
  text-align: center; line-height: 1.8;
}

/* ---------- Shell ---------- */
.shell-pane {
  height: 220px;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
}
.shell-out {
  flex: 1;
  overflow: auto;
  padding: 6px 12px;
  font-family: Consolas, "Courier New", monospace;
  font-size: var(--font-size);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}
.shell-line { min-height: 1.2em; }
.shell-line.sys { color: var(--sys-text); font-size: 12px; }
.shell-line.err { color: var(--err-text); }
.shell-line.echo { color: #1a365d; }
.shell-form {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 12px 8px;
}
.shell-prompt { font-family: Consolas, monospace; color: var(--run-green); font-weight: 700; }
#shellInput {
  flex: 1;
  font-family: Consolas, monospace;
  font-size: var(--font-size);
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
}
#shellInput:focus { border-color: var(--accent); }
#shellInput:disabled { background: #f1f5f9; }

/* ---------- 状态栏 ---------- */
.statusbar {
  display: flex; gap: 18px; align-items: center;
  padding: 3px 14px;
  font-size: 11px;
  color: var(--muted);
  background: #eef2f7;
  border-top: 1px solid var(--border);
}
.statusbar-right { margin-left: auto; }

/* ---------- 移动端 ---------- */
@media (max-width: 760px) {
  .workspace { flex-direction: column; }
  .vars-pane { width: auto; height: 160px; border-left: none; border-top: 1px solid var(--border); }
  .shell-pane { height: 180px; }
  .brand-sub { display: none; }
}

/* ---------- AI 助手抽屉 ---------- */
.btn-ai { color: var(--accent-dark); border-color: #a3c2e8; background: #eaf2fc; font-weight: 600; }
.btn-ai:hover { background: #d9e8fa; border-color: var(--accent); }
.ai-panel {
  position: fixed;
  top: 0; right: 0;
  width: 360px; max-width: 92vw;
  height: 100%;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  box-shadow: -6px 0 24px rgba(0,0,0,.08);
  display: flex;
  flex-direction: column;
  z-index: 100;
}
.ai-panel[hidden] { display: none; }
.ai-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(#fdfefe, #eef2f7);
  border-bottom: 1px solid var(--border);
}
.ai-title { font-weight: 700; color: var(--accent-dark); margin-right: auto; }
.ai-chat {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-msg { display: flex; }
.ai-msg.user { justify-content: flex-end; }
.ai-bubble {
  max-width: 88%;
  padding: 8px 11px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-msg.ai .ai-bubble { background: #f1f5fb; border: 1px solid #e2e8f0; }
.ai-msg.user .ai-bubble { background: #dceafd; border: 1px solid #c3dbf7; }
.ai-bubble.err { background: #fff5f5; border-color: #fed7d7; color: var(--err-text); }
.ai-code {
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.ai-code pre {
  margin: 0;
  padding: 8px 10px;
  background: #f8fafc;
  font-family: Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  max-height: 200px;
  overflow: auto;
  white-space: pre;
}
.ai-code-actions {
  display: flex; gap: 6px;
  padding: 6px 8px;
  background: #eef2f7;
  border-top: 1px solid var(--border);
}
.ai-code-actions button { font-size: 12px; padding: 3px 10px; border-radius: 4px; }
.ai-typing { color: var(--muted); font-size: 12px; }
.ai-form { border-top: 1px solid var(--border); padding: 8px 12px 12px; }
.ai-ctx { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.ai-input-row { display: flex; gap: 8px; margin-top: 6px; }
#aiInput {
  flex: 1;
  resize: none;
  font-family: inherit;
  font-size: 13px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}
#aiInput:focus { border-color: var(--accent); }
#btnAiSend { align-self: flex-end; font-weight: 600; }
.ai-loading { display: inline-block; animation: aiPulse 1.2s ease-in-out infinite; }
@keyframes aiPulse { 0%,100% { opacity: .35 } 50% { opacity: 1 } }
