:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --line: #d7dbe0;
  --ink: #1f2328;
  --muted: #6b7280;
  --accent: #1f6feb;
  --accent-dark: #1a5fd0;
  --accent-soft: #e8f0fe;
  --ok: #16a34a;
  --warn: #b45309;
  --danger: #dc2626;
  --head-bg: #f5f6f8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- 顶栏 ---------- */
.topbar {
  height: 52px;
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: #20304a;
  color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.brand { font-size: 15px; font-weight: 700; letter-spacing: .5px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.dataset-info { font-size: 12px; color: #cbd5e1; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f0f3f7; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-sm { padding: 3px 9px; font-size: 12px; }

/* ---------- 布局 ---------- */
.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  flex: 0 0 320px;
  width: 320px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* ---------- 标签页 ---------- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--head-bg);
}
.tab {
  flex: 1;
  padding: 9px 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--ink); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
  background: #fff;
}
.main-tabs .tab { flex: none; min-width: 120px; }

.tab-panel {
  flex: 1;
  overflow: auto;
  padding: 12px;
  min-height: 0;
}

/* ---------- 输入 ---------- */
.input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
}
.input:focus { outline: none; border-color: var(--accent); }
.input-sm { width: 70px; display: inline-block; }
select.input { width: 100%; }

/* ---------- 变量列表 ---------- */
.var-list { display: flex; flex-direction: column; gap: 8px; }
.var-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
}
.var-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.var-name { font-weight: 700; }
.var-label { color: var(--muted); font-size: 12px; }
.badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  color: #fff;
}
.badge.num { background: #2563eb; }
.badge.cat { background: #7c3aed; }
.var-meta { color: var(--muted); font-size: 11.5px; margin: 3px 0; }
.vl { font-size: 11px; color: #065f46; background: #ecfdf5; border-radius: 4px; padding: 3px 6px; margin: 3px 0; }
.measure-row { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.measure-label { color: var(--muted); font-size: 12px; }
.measure-select { flex: 1; padding: 3px 6px; border: 1px solid var(--line); border-radius: 5px; font-size: 12px; }

/* ---------- 清洗建议 ---------- */
.cleaning-panel { display: flex; flex-direction: column; gap: 8px; }
.clean-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
}
.clean-warn { border-color: #f59e0b; background: #fffbeb; }
.clean-title { font-weight: 700; font-size: 13px; margin-bottom: 5px; }
.clean-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  border-top: 1px solid #eef0f3;
}
.clean-row:first-of-type { border-top: none; }
.clean-row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 数据表 ---------- */
.hint { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.data-table-wrap { overflow: auto; }
.data-table { border-collapse: collapse; font-size: 12px; }
.data-table th, .data-table td {
  border: 1px solid var(--line);
  padding: 3px 8px;
  min-width: 70px;
  white-space: nowrap;
}
.data-table th { background: var(--head-bg); position: sticky; top: 0; }
.data-table td.idx { background: var(--head-bg); color: var(--muted); text-align: right; }
.data-table td[contenteditable] { cursor: text; }
.data-table td[contenteditable]:hover { background: #fef9c3; }
.data-table td[contenteditable]:focus { background: #fef9c3; outline: 1px solid var(--accent); }

/* ---------- 转换面板 ---------- */
.tf-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 12px;
  background: #fff;
}
.tf-section h4 { margin: 0 0 8px; font-size: 13px; }
.tf-section .input, .tf-section select.input { margin-bottom: 6px; }
.tf-row { display: flex; align-items: center; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.tf-note { color: var(--muted); font-size: 11.5px; margin: 3px 0; }
.tf-suggest-box { border: 1px dashed var(--accent); border-radius: 6px; padding: 8px; background: var(--accent-soft); }
.tf-suggest-box textarea { min-height: 36px; font-size: 12px; }
.scale-json {
  min-height: 220px;
  font-family: Consolas, "Courier New", monospace;
  white-space: pre;
}
.check-group { display: flex; flex-direction: column; gap: 2px; max-height: 160px; overflow: auto; }
.check { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; cursor: pointer; }

.mv-row { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.mv-val { flex: 1; font-size: 12.5px; }
.mv-cnt { color: var(--muted); font-size: 11.5px; width: 46px; text-align: right; }
.mv-map { flex: 1.2; }

.dim-row { border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-bottom: 8px; background: #fafbfc; }
.dim-name { margin-bottom: 4px; }
.dim-item-row { display: flex; align-items: center; gap: 14px; }
.rev-tag { color: var(--warn); font-size: 11.5px; }

/* ---------- 分析菜单与参数 ---------- */
.analyze-layout { display: flex; gap: 0; height: 100%; }
.menu-col {
  flex: 0 0 260px;
  border-right: 1px solid var(--line);
  overflow: auto;
  padding-right: 12px;
}
.menu-cat {
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
  margin: 10px 0 4px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 3px;
}
.menu-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 4px;
  border-radius: 6px;
  cursor: pointer;
}
.menu-item:hover { background: var(--accent-soft); }
.menu-item input { margin-top: 3px; }
.mi-body { display: flex; flex-direction: column; }
.mi-name { font-weight: 600; font-size: 13px; }
.mi-desc { color: var(--muted); font-size: 11.5px; }

.param-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-left: 12px;
  overflow: auto;
}
.param-panel { flex: 1; overflow: auto; }
.param-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 12px;
  background: #fff;
}
.pf-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.pf-title { font-weight: 700; font-size: 13.5px; }
.pf-field { margin-bottom: 10px; }
.pf-label { font-weight: 600; font-size: 12.5px; margin-bottom: 3px; }
.req { color: var(--danger); }
.pf-help { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.pf-note { color: var(--muted); font-size: 12px; }
.pf-select { width: auto; min-width: 220px; }
.pf-ms-group { max-height: 200px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 6px; }

.fm-editor { border: 1px dashed var(--line); border-radius: 6px; padding: 8px; }
.fm-factor { border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-bottom: 8px; background: #fafbfc; }
.fm-name { margin-bottom: 6px; max-width: 260px; }
.fm-items { max-height: 150px; overflow: auto; }

.empty { color: var(--muted); text-align: center; padding: 24px 0; }
.upload-empty,
.start-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 150px;
  padding: 18px;
  text-align: center;
}
.start-panel {
  min-height: 110px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.upload-main {
  min-width: 150px;
  min-height: 36px;
  font-weight: 700;
}
.hidden-advanced { display: none; }

.run-bar { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.run-status { color: var(--muted); font-size: 12.5px; }

/* ---------- 登录 ---------- */
.auth-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(238, 241, 245, .92);
  z-index: 900;
}
.auth-box {
  width: min(360px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 20px;
  box-shadow: 0 12px 36px rgba(31, 35, 40, .16);
}
.auth-box h2 { margin: 0 0 8px; font-size: 18px; }
.auth-box .input { margin-top: 8px; }
.auth-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- 引导建议 ---------- */
.guide-panel { max-width: 980px; }
.guide-hero {
  border-bottom: 1px solid var(--line);
  background: #fff;
  padding: 14px 16px;
  margin: -12px -12px 12px;
}
.guide-title { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.guide-hero p {
  max-width: 860px;
  color: var(--muted);
  line-height: 1.65;
  margin: 0 0 10px;
}
.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 12px;
}
.guide-section {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.guide-section h3 { margin: 0 0 8px; font-size: 14px; }
.guide-item {
  border-top: 1px solid #eef0f3;
  padding: 8px 0;
}
.guide-item:first-of-type { border-top: none; padding-top: 0; }
.guide-item-title { font-weight: 700; margin-bottom: 4px; }
.guide-item p { color: var(--muted); line-height: 1.55; margin: 0 0 5px; }
.guide-item code {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 11.5px;
}
.guide-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.guide-tags span {
  padding: 2px 7px;
  border-radius: 10px;
  background: #ecfdf5;
  color: #047857;
  font-size: 11.5px;
}
.guide-required {
  border-left: 3px solid #f59e0b;
  background: #fffbeb;
  color: #92400e;
  padding: 6px 8px;
  margin: 6px 0;
  line-height: 1.55;
  font-size: 12px;
}
.guide-question {
  border-top: 1px solid #eef0f3;
  padding: 8px 0;
  line-height: 1.55;
}
.guide-question:first-of-type { border-top: none; padding-top: 0; }
@media (max-width: 900px) {
  .guide-grid { grid-template-columns: 1fr; }
}

/* ---------- 日志 ---------- */
.log-frame { width: 100%; height: 100%; border: none; background: #fff; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: #1f2328;
  color: #fff;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 70%;
  z-index: 999;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warn); }
