:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1c2330;
  --muted: #6b7280;
  --border: #e3e8f0;
  --primary: #2f6bff;
  --primary-ink: #ffffff;
  --accent: #eef3ff;
  --shadow: 0 10px 30px rgba(20, 30, 60, 0.08);
  --radius: 16px;
}

[data-theme="dark"] {
  --bg: #0e1118;
  --card: #171b24;
  --text: #e7ebf3;
  --muted: #93a0b5;
  --border: #262d3a;
  --primary: #4f86ff;
  --primary-ink: #ffffff;
  --accent: #1b2740;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s ease, color 0.3s ease;
  line-height: 1.5;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  max-width: 980px;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #7aa2ff);
  color: #fff; font-weight: 800; font-size: 22px;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 18px; margin: 0; }
.sub { margin: 0; font-size: 12px; color: var(--muted); }

.icon-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 40px; height: 40px;
  font-size: 18px; cursor: pointer;
  transition: transform 0.2s ease;
}
.icon-btn:hover { transform: scale(1.08) rotate(-12deg); }

main { max-width: 980px; margin: 0 auto; padding: 8px 28px 40px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 6px; font-size: 16px; }
.card h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); }
.hint { margin: 0 0 14px; font-size: 13px; color: var(--muted); }

.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.row label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 6px; }
.grow { flex: 1; }

input, select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--accent); }
label.grow input, label.grow select { width: 100%; }
.row label:not(.grow) input { width: 120px; }

.btn {
  background: var(--accent);
  color: var(--primary);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn.small { padding: 6px 14px; font-size: 13px; }
.btn.danger { background: transparent; color: #dc2626; border-color: #f0c2c2; }
.btn.danger:hover { background: #dc2626; color: #fff; }

.name-input { width: 130px; padding: 6px 10px; font-size: 13px; margin-right: 6px; }

.status { font-size: 13px; color: var(--muted); }
.status.ok { color: #16a34a; }
.status.err { color: #dc2626; }

.table-wrap { overflow-x: auto; margin: 12px 0; border-radius: 10px; border: 1px solid var(--border); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; white-space: nowrap; }
th { background: var(--accent); font-weight: 600; }

.write-box { border-top: 1px dashed var(--border); margin-top: 16px; padding-top: 4px; }

.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 12px 20px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 50;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast.hidden { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(-10px); }
.toast.ok { background: #16a34a; }
.toast.err { background: #dc2626; }

.hidden { display: none !important; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }

/* 下载进度条 */
.progress { margin-top: 14px; }
.progress-track {
  width: 100%; height: 10px; border-radius: 999px;
  background: var(--accent); overflow: hidden;
  border: 1px solid var(--border);
}
.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary), #7aa2ff);
  border-radius: 999px;
  transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.progress-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 8px; gap: 12px;
}
.progress-status {
  font-size: 13px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.progress-pct {
  font-size: 13px; font-weight: 600; color: var(--primary);
  font-variant-numeric: tabular-nums; flex-shrink: 0;
}

/* ==================== 顶部导航 / 数据分析页 ==================== */
.topnav {
  display: flex; gap: 6px; max-width: 980px; margin: 0 auto; padding: 0 28px;
}
.topnav a {
  padding: 10px 18px; font-size: 14px; font-weight: 600; color: var(--muted);
  text-decoration: none; border-radius: 12px 12px 0 0; cursor: pointer;
  border: 1px solid transparent; border-bottom: none;
  transition: color 0.15s ease, background 0.15s ease;
}
.topnav a:hover { color: var(--text); }
.topnav a.active { color: var(--primary); background: var(--card); border-color: var(--border); }

.analysis-layout { display: flex; gap: 18px; align-items: flex-start; }
.analysis-side { width: 220px; flex-shrink: 0; display: flex; flex-direction: column; gap: 14px; }
.analysis-side select { width: 100%; }
.analysis-main { flex: 1; min-width: 0; }

.side-block {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.side-title { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.side-hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.side-nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.side-nav li {
  padding: 10px 12px; border-radius: 10px; font-size: 14px; cursor: pointer;
  color: var(--text); transition: background 0.15s ease;
}
.side-nav li:hover { background: var(--accent); }
.side-nav li.active { background: var(--primary); color: var(--primary-ink); font-weight: 600; }

.panel {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 6px; font-size: 16px; }

.dim-tabs, .gran-tabs { display: flex; gap: 8px; margin: 6px 0 16px; }
.dim-tab, .gran-tab {
  padding: 8px 16px; border: 1px solid var(--border); background: var(--bg);
  color: var(--muted); border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: all 0.15s ease;
}
.dim-tab.active, .gran-tab.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

.metric-pick { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.metric-pick label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.metric-pick select { min-width: 160px; }

.chart-box { position: relative; height: 340px; margin: 10px 0 18px; }

.ai-box { border-top: 1px dashed var(--border); margin-top: 8px; padding-top: 14px; }
.ai-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.ai-head h3 { margin: 0; font-size: 14px; }
.ai-result { white-space: pre-wrap; line-height: 1.6; font-size: 14px; margin-top: 10px; min-height: 40px; }
.ai-result.muted { color: var(--muted); }

@media (max-width: 760px) {
  .analysis-layout { flex-direction: column; }
  .analysis-side { width: 100%; }
}
