* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Microsoft YaHei', sans-serif;
  font-size: 14px;
  color: #1a1a1a;
  background: #f5f6f8;
}

.hidden { display: none !important; }

/* ── 登录 ─────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  width: 380px;
  background: #fff;
  border-radius: 12px;
  padding: 40px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

.login-box h1 {
  margin: 0 0 32px;
  font-size: 22px;
  text-align: center;
}

.login-box label {
  display: block;
  margin-bottom: 20px;
}

.login-box label span {
  display: block;
  margin-bottom: 8px;
  color: #666;
  font-size: 13px;
}

.login-box input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
}

.login-box input:focus {
  outline: none;
  border-color: #1a1a1a;
}

/* ── 顶栏 ─────────────────────────────── */
.topbar {
  height: 56px;
  background: #1a1a1a;
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 600;
  font-size: 16px;
  margin-right: 40px;
}

.tabs {
  display: flex;
  gap: 4px;
  flex: 1;
}

.tab {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.65);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.tab:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.tab.active { color: #fff; background: rgba(255, 255, 255, 0.15); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
}

.banner {
  background: #fff8e6;
  border-bottom: 1px solid #f5e6c0;
  color: #8a6d3b;
  padding: 12px 24px;
  font-size: 13px;
}

.content {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ── 面板 ─────────────────────────────── */
.panel-head {
  margin-bottom: 20px;
  display: flex;
  align-items: baseline;
  gap: 20px;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 20px;
}

.hint {
  color: #999;
  font-size: 13px;
  margin: 4px 0 0;
}

.card {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 20px;
}

.card h3 {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 600;
}

/* ── 按钮 ─────────────────────────────── */
.btn {
  height: 36px;
  padding: 0 18px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  color: #1a1a1a;
}

.btn:hover { border-color: #999; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: #1a1a1a;
  border-color: #1a1a1a;
  color: #fff;
  width: 100%;
}

.card .btn.primary, .form-row .btn.primary, .actions .btn.primary { width: auto; }

.btn.danger { color: #d4380d; border-color: #ffccc7; }
.btn.danger:hover { border-color: #d4380d; }

.btn.text { border: none; background: transparent; color: inherit; padding: 0 8px; }

.btn.small { height: 28px; padding: 0 12px; font-size: 13px; }

/* ── 表单 ─────────────────────────────── */
.form-row, .upload-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.form-row label, .upload-row label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: #666;
}

.form-row input, .upload-row input {
  height: 36px;
  padding: 0 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
}

input[type='file'] { padding: 6px; }

.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #666;
  cursor: pointer;
}

.filter-row { display: flex; gap: 8px; }

.chip {
  height: 30px;
  padding: 0 14px;
  border: 1px solid #ddd;
  border-radius: 15px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}

.chip.active { background: #1a1a1a; border-color: #1a1a1a; color: #fff; }

/* ── 表格 ─────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 10px 12px;
  color: #888;
  font-weight: 500;
  border-bottom: 1px solid #eee;
  white-space: nowrap;
}

td {
  padding: 12px;
  border-bottom: 1px solid #f5f5f5;
  vertical-align: middle;
}

tbody tr:hover { background: #fafafa; }

td.empty, .empty {
  text-align: center;
  color: #bbb;
  padding: 40px;
}

.missing { color: #d4380d; }

.code {
  background: #f5f5f5;
  padding: 3px 8px;
  border-radius: 4px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 13px;
}

.tag {
  display: inline-block;
  background: #f0f2f5;
  color: #555;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  margin-right: 4px;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 12px;
  background: #f0f0f0;
  color: #888;
}

.badge.on { background: #e8f5e9; color: #2e7d32; }
.badge.off { background: #fafafa; color: #999; }
.badge.warn { background: #fff8e6; color: #d48806; }

.msg-content {
  max-width: 480px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

/* ── 预览 ─────────────────────────────── */
.summary {
  display: flex;
  gap: 28px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.stat { color: #666; font-size: 13px; }
.stat b { color: #1a1a1a; font-size: 16px; margin: 0 4px; }

.warn-box {
  background: #fff8e6;
  border: 1px solid #f5e6c0;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.warn-title { color: #d48806; font-weight: 600; margin-bottom: 10px; }

.warn-box ul { margin: 0; padding-left: 20px; color: #8a6d3b; line-height: 1.9; }

.warn-box code {
  background: rgba(0, 0, 0, 0.05);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
}

.ok-box {
  background: #e8f5e9;
  color: #2e7d32;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
}

.actions {
  margin-top: 20px;
  display: flex;
  gap: 12px;
}

.kv {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #f5f5f5;
  max-width: 400px;
}

.kv span { color: #888; }

/* ── 助手对话 ─────────────────────────── */
.panel-head-right { margin-left: auto; }

/* 拖拽覆盖层需要定位锚点 */
.chat-shell {
  position: relative;
  margin-bottom: 12px;
}

.chat-area {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  height: 520px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.chat-drop {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  border: 2px dashed #1a1a1a;
  border-radius: 10px;
  pointer-events: none;
  z-index: 5;
}

.chat-shell.dropping .chat-drop { display: flex; }

.chat-drop-inner { font-size: 15px; color: #1a1a1a; font-weight: 500; }

.chat-empty { color: #999; line-height: 1.8; }

.chat-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.chat-example {
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 16px;
  padding: 7px 14px;
  font-size: 13px;
  color: #444;
  cursor: pointer;
}

.chat-example:hover { border-color: #1a1a1a; color: #1a1a1a; }

.chat-turn { margin-bottom: 18px; display: flex; flex-direction: column; }
.chat-turn.user { align-items: flex-end; }
.chat-turn.assistant { align-items: flex-start; }

.chat-msg {
  position: relative;
  padding: 12px 16px;
  border-radius: 10px;
  line-height: 1.7;
  max-width: 82%;
  word-break: break-word;
}

.chat-msg.user {
  background: #1a1a1a;
  color: #fff;
}

.chat-msg.assistant { background: #f5f6f8; }
.chat-msg.error { background: #fff1f0; color: #cf1322; }

/* 复制按钮：悬停才显形，避免干扰阅读 */
.chat-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  border: none;
  background: rgba(0, 0, 0, 0.06);
  color: #666;
  border-radius: 4px;
  font-size: 11px;
  padding: 2px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.chat-msg:hover .chat-copy { opacity: 1; }
.chat-msg.user .chat-copy { background: rgba(255, 255, 255, 0.18); color: #eee; }
.chat-copy:hover { background: rgba(0, 0, 0, 0.12); }

/* ── Markdown 正文 ─────────────────────── */
.chat-md > *:first-child { margin-top: 0; }
.chat-md > *:last-child { margin-bottom: 0; }

.chat-md p { margin: 0 0 10px; }
.chat-md h3, .chat-md h4, .chat-md h5, .chat-md h6 {
  margin: 14px 0 8px;
  font-weight: 600;
}
.chat-md h3 { font-size: 16px; }
.chat-md h4 { font-size: 15px; }
.chat-md h5, .chat-md h6 { font-size: 14px; }

.chat-md ul, .chat-md ol { margin: 0 0 10px; padding-left: 22px; }
.chat-md li { margin-bottom: 4px; }

.chat-md code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12.5px;
}

.chat-md pre {
  background: #1e1e1e;
  color: #e6e6e6;
  padding: 12px 14px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0 0 10px;
}

.chat-md pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.6;
}

.chat-md blockquote {
  margin: 0 0 10px;
  padding: 4px 0 4px 12px;
  border-left: 3px solid #ddd;
  color: #666;
}

.chat-md hr { border: none; border-top: 1px solid #e5e5e5; margin: 14px 0; }

.chat-md a { color: #0958d9; }

.md-table {
  border-collapse: collapse;
  margin: 0 0 10px;
  font-size: 13px;
  background: #fff;
  border-radius: 6px;
  overflow: hidden;
}

.md-table th, .md-table td {
  border: 1px solid #e8e8e8;
  padding: 7px 12px;
  text-align: left;
  white-space: nowrap;
}

.md-table th { background: #fafafa; color: #555; font-weight: 600; }
.md-table tbody tr:hover { background: #fafafa; }

.chat-msg.user .chat-md code { background: rgba(255, 255, 255, 0.2); }
.chat-msg.user .chat-md a { color: #9ec5ff; }

/* ── 输入中动画 ───────────────────────── */
.chat-typing { display: inline-flex; gap: 4px; align-items: center; padding: 2px 0; }

.chat-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #bbb;
  animation: typing 1.2s infinite ease-in-out;
}

.chat-typing i:nth-child(2) { animation-delay: 0.15s; }
.chat-typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ── 工具调用 ─────────────────────────── */
.tool-block {
  background: #f0f6ff;
  border: 1px solid #d6e6ff;
  border-radius: 8px;
  margin-bottom: 8px;
  max-width: 82%;
  font-size: 13px;
}

.tool-block summary {
  padding: 8px 14px;
  cursor: pointer;
  color: #0958d9;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  user-select: none;
}

.tool-block summary::-webkit-details-marker { display: none; }
.tool-block summary::marker { content: ''; }

.tool-summary-icon { font-size: 13px; display: inline-block; }
.tool-summary-icon.spin { animation: spin 1s linear infinite; }

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.tool-list {
  margin: 0;
  padding: 0 14px 10px 14px;
  list-style: none;
  border-top: 1px solid #d6e6ff;
  padding-top: 8px;
}

.tool-item {
  padding: 5px 0;
  color: #35507a;
}

.tool-item + .tool-item { border-top: 1px solid #e3edfb; }

.tool-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-item .tool-icon { width: 14px; display: inline-block; }
.tool-item.running .tool-icon { animation: spin 1s linear infinite; }
.tool-item.done .tool-icon { color: #2e7d32; }
.tool-item.failed .tool-icon { color: #cf1322; }
.tool-item.failed .tool-name { color: #cf1322; }

.tool-name { font-weight: 500; }

.tool-raw {
  color: #92a8c9;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 11px;
}

/* 参数与结果：缩进对齐到工具名下方 */
.tool-detail {
  display: flex;
  gap: 8px;
  margin: 4px 0 0 22px;
  font-size: 12px;
  line-height: 1.6;
}

.tool-detail-key {
  flex: none;
  color: #8ba3c4;
  min-width: 28px;
}

.tool-detail code {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid #dceafb;
  border-radius: 4px;
  padding: 2px 7px;
  color: #35507a;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 11.5px;
  word-break: break-word;
  /* 结果摘要后端已截到 200 字符，这里再兜底防止撑破布局 */
  max-height: 88px;
  overflow-y: auto;
}

.tool-detail.error .tool-detail-key { color: #cf1322; }

.tool-detail.error code {
  background: #fff1f0;
  border-color: #ffccc7;
  color: #cf1322;
}

/* 整块含失败项时用红色边框，折叠状态下也能看出问题 */
.tool-block.has-error {
  background: #fff5f5;
  border-color: #ffccc7;
}

.tool-block.has-error > summary { color: #cf1322; }
.tool-block.has-error .tool-list { border-top-color: #ffccc7; }
.tool-block.has-error .tool-item + .tool-item { border-top-color: #ffe0de; }

/* ── 文件气泡 ─────────────────────────── */
.chat-file {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  max-width: 320px;
}

.chat-file-icon {
  font-size: 18px;
  color: #1d7d4d;
}

.chat-file-meta { display: flex; flex-direction: column; overflow: hidden; }
.chat-file-meta b {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-file-meta em { font-style: normal; font-size: 12px; color: #999; margin-top: 2px; }

.chat-file.uploading { border-style: dashed; }
.chat-file.uploading .chat-file-meta em { color: #0958d9; }
.chat-file.failed { border-color: #ffccc7; background: #fff1f0; }
.chat-file.failed .chat-file-meta em { color: #cf1322; }

/* ── 输入区 ───────────────────────────── */
.chat-input {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input textarea {
  flex: 1;
  min-height: 40px;
  max-height: 140px;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
}

.chat-input textarea:focus { outline: none; border-color: #1a1a1a; }
.chat-input textarea:disabled { background: #fafafa; color: #999; }

.chat-input .btn { flex: none; }
.chat-input .btn.primary { width: auto; }

.btn.icon {
  width: 36px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  color: #666;
}

.btn.icon:hover { color: #1a1a1a; }

/* ── 统计 ─────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  text-align: center;
}

.stat-card.highlight { background: #fff8e6; }

.stat-value { font-size: 28px; font-weight: 600; }
.stat-label { margin-top: 6px; color: #999; font-size: 13px; }

.q-list { margin: 0; padding-left: 20px; line-height: 2.2; }
.q-time { color: #bbb; font-size: 12px; margin-right: 12px; }

.error { color: #d4380d; font-size: 13px; min-height: 18px; margin: 8px 0; }

/* ── 弹层 ─────────────────────────────── */
.mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

/* .hidden 是全局工具类（display:none），此处需覆盖 flex */
.mask.hidden { display: none; }

.dialog {
  width: 380px;
  max-width: calc(100vw - 32px);
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.16);
}

.dialog h3 {
  margin: 0 0 20px;
  font-size: 16px;
  font-weight: 600;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: #666;
  margin-bottom: 14px;
}

.field input {
  height: 36px;
  padding: 0 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
}

.field input:focus {
  outline: none;
  border-color: #1a1a1a;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.dialog-actions .btn { width: auto; }

/* ── 提示 ─────────────────────────────── */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1a1a1a;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  opacity: 0;
  transition: all 0.3s;
  z-index: 100;
  font-size: 14px;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #cf1322; }
