:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --border: #e3e8f0;
  --text: #1f2733;
  --text-dim: #67738a;
  --accent: #2f6fed;
  --accent-soft: #eaf1ff;
  --ok: #1a9e6c;
  --warn: #d90429;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 16px; font-weight: 700; }
.brand .sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 10px;
  margin-left: 8px;
}
.top-actions { display: flex; gap: 8px; align-items: center; }
.top-actions select {
  max-width: 260px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-family: var(--sans);
}

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 54px);
}
.panel { min-height: 0; overflow-y: auto; }
.side { display: flex; flex-direction: column; gap: 14px; }
.workspace { overflow: hidden; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.card h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- 上传 ---------- */
#dropZone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 22px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
#dropZone:hover, #dropZone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dz-icon { font-size: 30px; }
.dz-text strong { display: block; margin: 6px 0 4px; }
.dz-text small { color: var(--text-dim); }
.picked-file {
  margin-top: 10px;
  font-size: 13px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 8px;
  padding: 6px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.url-row { display: flex; gap: 8px; margin: 12px 0; }
.url-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.options { margin: 4px 0 12px; font-size: 13px; }
.options summary { cursor: pointer; color: var(--text-dim); }
.options label { display: block; margin-top: 8px; color: var(--text); }

button {
  font-family: var(--sans);
  font-size: 13px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button.primary {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
}
button.primary:hover { background: #255cd0; color: #fff; }
button.primary:disabled { background: #b9c4d8; border-color: #b9c4d8; cursor: not-allowed; }
button.ghost { background: transparent; }
button.danger:hover { border-color: var(--warn); color: var(--warn); }

/* ---------- 状态 ---------- */
.status-line { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.pending { background: #eef1f6; color: var(--text-dim); }
.badge.running { background: var(--accent-soft); color: var(--accent); }
.badge.done { background: #e2f7ee; color: var(--ok); }
.badge.failed { background: #fde8ea; color: var(--warn); }
.status-file { font-size: 13px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.progress-wrap {
  height: 8px;
  border-radius: 999px;
  background: #eef1f6;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.4s;
}
.status-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.status-error {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fde8ea;
  color: var(--warn);
  font-size: 13px;
  word-break: break-all;
}

.tips ul { margin: 0; padding-left: 18px; color: var(--text-dim); line-height: 1.9; }
.tips code { background: #eef1f6; border-radius: 4px; padding: 1px 5px; font-family: var(--mono); font-size: 12px; }

/* ---------- 工作区 ---------- */
.workspace {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
}
.tabs { display: flex; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--border); }
.tab {
  border: none;
  background: transparent;
  padding: 9px 16px;
  font-size: 14px;
  color: var(--text-dim);
  border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--accent); }
.tab.active { color: var(--accent); font-weight: 600; border-bottom-color: var(--accent); }

.tab-page { display: none; flex: 1; min-height: 0; flex-direction: column; }
.tab-page.active { display: flex; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.toolbar .spacer { flex: 1; }
.toolbar label { font-size: 13px; color: var(--text-dim); display: flex; align-items: center; gap: 4px; }

.split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.split.editor-only { grid-template-columns: minmax(0, 1fr); }
.split.editor-only .preview { display: none; }

.split textarea {
  border: none;
  border-right: 1px solid var(--border);
  resize: none;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  background: #fbfcfe;
  outline: none;
  min-width: 0;
}
.split textarea:read-only { background: #f6f7fa; }

.preview {
  overflow-y: auto;
  padding: 18px 22px 40px;
  min-width: 0;
}

/* ---------- Markdown 渲染 ---------- */
.markdown-body { line-height: 1.75; word-wrap: break-word; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5 { margin: 1.2em 0 0.6em; line-height: 1.4; }
.markdown-body h1 { font-size: 1.7em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.4em; border-bottom: 1px solid var(--border); padding-bottom: 0.25em; }
.markdown-body h3 { font-size: 1.2em; }
.markdown-body p { margin: 0.7em 0; }
.markdown-body a { color: var(--accent); }
.markdown-body img { max-width: 100%; border-radius: 6px; border: 1px solid var(--border); margin: 4px 0; }
.markdown-body code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: #eef1f6;
  border-radius: 4px;
  padding: 2px 5px;
}
.markdown-body pre {
  background: #f2f4f8;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote {
  margin: 0.8em 0;
  padding: 2px 14px;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
  color: var(--text-dim);
}
.markdown-body table { border-collapse: collapse; margin: 0.8em 0; display: block; overflow-x: auto; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 6px 12px; }
.markdown-body th { background: #f2f4f8; }
.markdown-body hr { border: none; border-top: 1px dashed var(--border); margin: 1.4em 0; }
.markdown-body ul, .markdown-body ol { padding-left: 1.6em; }
.math-error { color: var(--warn); font-family: var(--mono); font-size: 0.9em; }
.katex { font-size: 1.05em; }
.katex-display { margin: 0.6em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: #232c3b;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}
#toast.error { background: var(--warn); }
.hidden { display: none !important; }

/* ---------- 移动端 ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .workspace { min-height: 70vh; }
  .split { grid-template-columns: 1fr; grid-template-rows: minmax(160px, 40%) minmax(0, 1fr); }
  .split textarea { border-right: none; border-bottom: 1px solid var(--border); }
}
