/* ===== 浅色 / 多彩主题 · 跑步数据看板 ===== */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --border: #e6ebf2;
  --text: #1f2933;
  --text-muted: #52606d;
  --text-faint: #93a1b0;
  --accent: #2f80ed;
  --accent-2: #00a86b;
  --accent-3: #eb5757;
  --amber: #f2994a;
  --violet: #8b5cf6;
  --pink: #ec4899;
  --sky: #38bdf8;
  --grid: #eef1f5;
  --shadow: 0 2px 10px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1200px; margin: 0 auto; padding: 0 18px 80px; }

/* ---- 顶栏 ---- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0;
  background: rgba(245, 247, 251, .92);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}
.brand { font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 9px; }
.brand small { font-weight: 500; color: var(--text-faint); font-size: 11px; letter-spacing: .5px; }
.dot { width: 11px; height: 11px; border-radius: 50%; background: linear-gradient(135deg, var(--accent-2), var(--sky)); box-shadow: 0 0 0 4px rgba(0,168,107,.16); }
.spacer { flex: 1; }
.nav { display: flex; gap: 8px; flex-wrap: wrap; }
.nav button {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); padding: 9px 20px; border-radius: 999px;
  font-size: 14px; cursor: pointer; transition: .18s; white-space: nowrap; font-weight: 600;
}
.nav button:hover { border-color: var(--accent); color: var(--accent); }
.nav button.active { background: linear-gradient(135deg, var(--accent), #5aa9ff); border-color: transparent; color: #fff; box-shadow: 0 4px 12px rgba(47,128,237,.3); }

/* ---- 视图 ---- */
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- 卡片 ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 14px; font-size: 15px; color: var(--text); font-weight: 700; }
.card h3 .sub { font-size: 12px; color: var(--text-faint); font-weight: 500; }
.grid { display: grid; gap: 18px; }
.charts-grid { grid-template-columns: repeat(2, 1fr); }
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 300px; }
/* 占满整行的宽卡片（移动端在 media query 中重置为单列） */
.chart-wide { grid-column: 1 / -1; }

/* ---- 欢迎横幅 ---- */
.hero {
  background: linear-gradient(120deg, #2f80ed 0%, #00a86b 60%, #38bdf8 100%);
  border-radius: 20px; padding: 26px 28px; color: #fff; margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(47,128,237,.22); position: relative; overflow: hidden;
}
.hero::after { content: ""; position: absolute; right: -40px; top: -40px; width: 200px; height: 200px;
  background: rgba(255,255,255,.12); border-radius: 50%; }
.hero h1 { margin: 0; font-size: 24px; font-weight: 800; }
.hero p { margin: 8px 0 0; opacity: .92; font-size: 14px; }
.hero .hero-stats { display: flex; gap: 28px; margin-top: 16px; flex-wrap: wrap; }
.hero .hero-stats div { font-size: 13px; opacity: .9; }
.hero .hero-stats b { display: block; font-size: 22px; font-weight: 800; }

/* ---- KPI 卡片 ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi {
  border-radius: var(--radius); padding: 18px; color: #fff; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.kpi .label { font-size: 13px; opacity: .92; font-weight: 600; }
.kpi .value { font-size: 27px; font-weight: 800; margin-top: 8px; line-height: 1.1; }
.kpi .value small { font-size: 13px; font-weight: 600; opacity: .85; margin-left: 3px; }
.kpi .sub { font-size: 12px; opacity: .82; margin-top: 5px; }
.kpi.c1 { background: linear-gradient(135deg, #2f80ed, #56ccf2); }
.kpi.c2 { background: linear-gradient(135deg, #00a86b, #70e000); }
.kpi.c3 { background: linear-gradient(135deg, #eb5757, #f2994a); }
.kpi.c4 { background: linear-gradient(135deg, #8b5cf6, #d946ef); }
.kpi.c5 { background: linear-gradient(135deg, #f2994a, #f2c94c); }
.kpi.c6 { background: linear-gradient(135deg, #0ea5e9, #22d3ee); }
.kpi.c7 { background: linear-gradient(135deg, #ec4899, #f472b6); }
.kpi.c8 { background: linear-gradient(135deg, #334155, #64748b); }

/* ---- 个人纪录 ---- */
.records-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.record {
  background: var(--surface-2); border-radius: 12px; padding: 16px; text-align: center;
  border: 1px solid var(--border);
}
.record .rl { font-size: 13px; color: var(--text-muted); }
.record .rv { font-size: 26px; font-weight: 800; margin: 6px 0; color: var(--accent); }
.record .rmeta { font-size: 12px; color: var(--text-faint); }

/* ---- 坚持/连续 ---- */
.streak-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.streak { background: linear-gradient(135deg, #fff7ed, #fff1f2); border-radius: 12px; padding: 16px; border: 1px solid #fed7aa; }
.streak .sl { font-size: 13px; color: #c2410c; font-weight: 600; }
.streak .sv { font-size: 24px; font-weight: 800; margin-top: 6px; color: #9a3412; }

/* ---- 记录列表 ---- */
.list-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search {
  flex: 1; min-width: 180px; padding: 11px 14px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px; background: var(--surface); color: var(--text);
}
.search:focus { outline: none; border-color: var(--accent); }
select { padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 14px; }
.list-count { color: var(--text-faint); font-size: 13px; }
.list { display: grid; gap: 10px; }
.run-row {
  display: grid; grid-template-columns: 56px 1fr auto auto auto; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 16px; cursor: pointer; transition: .15s;
}
.run-row:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.run-date { text-align: center; }
.run-date .d { font-size: 22px; font-weight: 800; color: var(--accent); line-height: 1; }
.run-date .m { font-size: 11px; color: var(--text-faint); margin-top: 3px; }
.run-main .name { font-weight: 600; }
.run-extra { font-size: 11px; color: var(--text-faint); margin-top: 3px; }
.run-metric { text-align: right; }
.run-metric .v { font-size: 17px; font-weight: 800; }
.run-metric .l { font-size: 11px; color: var(--text-faint); }
.run-dist .v { color: var(--accent); }
.run-pace .v { color: var(--accent-3); }
.run-dur .v { color: var(--text-muted); }
.src-tag { font-size: 10px; background: var(--accent-2); color: #fff; padding: 1px 6px; border-radius: 6px; margin-left: 6px; vertical-align: 2px; }

/* ---- 详情 ---- */
.back-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 14px; }
.back-btn:hover { border-color: var(--accent); color: var(--accent); }
.detail-head h2 { margin: 0; font-size: 20px; }
.detail-head .when { color: var(--text-faint); font-size: 13px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 16px 0; }
.metric { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.metric .l { font-size: 12px; color: var(--text-faint); }
.metric .v { font-size: 18px; font-weight: 800; margin-top: 4px; }
.metric .v small { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.split-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.split-table th { text-align: left; color: var(--text-faint); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.split-table td { padding: 6px 8px; border-bottom: 1px solid var(--grid); }
.pace-bar { display: inline-block; height: 10px; border-radius: 5px; background: var(--accent-2); }
.lap-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.lap-table th, .lap-table td { padding: 7px 8px; border-bottom: 1px solid var(--grid); text-align: left; }
.lap-table th { color: var(--text-faint); font-weight: 600; }

/* ---- 地图 ---- */
.map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--border); }
#overview-map, #detail-map { height: 60vh; min-height: 380px; width: 100%; }
.map-controls { position: absolute; top: 12px; right: 12px; z-index: 10; display: flex; gap: 6px; }
.map-controls button, .upload-btn {
  border: 1px solid var(--border); background: rgba(255,255,255,.95); color: var(--text-muted);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; box-shadow: var(--shadow);
}
.map-controls button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.map-legend { position: absolute; bottom: 12px; left: 12px; z-index: 10;
  background: rgba(255,255,255,.94); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 11px; color: var(--text-muted); display: flex; gap: 8px; align-items: center; }
.map-legend i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.km-badge {
  width: 22px; height: 22px; border-radius: 50%; background: #fff; color: #00a86b;
  border: 2px solid #00a86b; font-size: 11px; font-weight: 800; line-height: 18px;
  text-align: center; box-shadow: 0 1px 4px rgba(0,0,0,.2); white-space: nowrap;
}

/* ---- 页脚 ---- */
.footer { margin-top: 30px; padding-top: 16px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-faint); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.footer a, .export-link { color: var(--accent); text-decoration: none; font-weight: 600; }

.loading { text-align: center; padding: 60px 0; color: var(--text-faint); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 40px; color: var(--text-faint); }

/* ---- 上传 ---- */
.upload-card { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 18px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; box-shadow: var(--shadow); }
.upload-card label.upload-btn { display: inline-flex; align-items: center; gap: 6px; }
.upload-card input[type=file] { display: none; }
.upload-hint { font-size: 12px; color: var(--text-faint); }
.upload-status { font-size: 13px; }
.upload-status.ok { color: var(--accent-2); }
.upload-status.err { color: var(--accent-3); }

/* ===== 移动端适配 ===== */
@media (max-width: 720px) {
  .app { padding: 0 12px 70px; }
  .topbar { flex-wrap: wrap; }
  .brand { width: 100%; }
  .spacer { display: none; }
  .nav { width: 100%; overflow-x: auto; padding-bottom: 4px; }
  .nav button { flex: 0 0 auto; padding: 8px 16px; }
  .charts-grid { grid-template-columns: 1fr; }
  /* 移动端取消所有跨列，确保每张卡片占满单行，避免横向溢出 */
  .charts-grid .chart-wide { grid-column: auto; }
  .chart-box { height: 220px; }
  #overview-map, #detail-map { height: 50vh; min-height: 320px; }
  .run-row { grid-template-columns: 48px 1fr auto; gap: 10px; padding: 10px 12px; }
  .run-dur, .run-pace { display: none; }
  .hero h1 { font-size: 20px; }
  .footer { font-size: 11px; }
}
@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== 详情页美化 ===== */
.detail-hero {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  background: linear-gradient(120deg, #2f80ed 0%, #00a86b 70%, #38bdf8 100%);
  color: #fff; border-radius: 18px; padding: 22px 24px; margin: 14px 0 18px;
  box-shadow: 0 8px 22px rgba(47,128,237,.22);
}
.detail-hero h2 { margin: 0; font-size: 22px; font-weight: 800; }
.detail-hero .when { opacity: .9; font-size: 13px; }
.detail-hero-badges { display: flex; gap: 12px; flex-wrap: wrap; }
.dbadge {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 78px; padding: 10px 12px; border-radius: 14px; color: #fff;
  box-shadow: 0 4px 10px rgba(0,0,0,.15); font-weight: 800; font-size: 17px; line-height: 1.1;
}
.dbadge small { font-size: 11px; font-weight: 600; opacity: .85; margin-top: 2px; }

/* 彩色指标卡 */
.metric-card {
  position: relative; border: none; color: #fff; overflow: hidden;
  box-shadow: 0 3px 10px rgba(15,23,42,.10);
  background: linear-gradient(135deg, #94a3b8, #64748b);
}
.metric-card .l { color: rgba(255,255,255,.9); font-weight: 600; }
.metric-card .v { color: #fff; }
.metric-card.mc-blue   { background: linear-gradient(135deg, #2f80ed, #56ccf2); }
.metric-card.mc-green  { background: linear-gradient(135deg, #00a86b, #70e000); }
.metric-card.mc-red    { background: linear-gradient(135deg, #eb5757, #f2994a); }
.metric-card.mc-sky    { background: linear-gradient(135deg, #0ea5e9, #22d3ee); }
.metric-card.mc-violet { background: linear-gradient(135deg, #8b5cf6, #d946ef); }
.metric-card.mc-amber  { background: linear-gradient(135deg, #f2994a, #f2c94c); }
.metric-card.mc-pink   { background: linear-gradient(135deg, #ec4899, #f472b6); }
.metric-card.mc-orange { background: linear-gradient(135deg, #f97316, #fbbf24); }
.metric-card.mc-gray   { background: linear-gradient(135deg, #64748b, #94a3b8); }

/* 卡片左侧彩色边 */
.card-accent { border-top: 3px solid var(--accent-2); }
.card-accent h3 { color: var(--accent); }

/* 详情地图说明 */
.map-cap { padding: 12px 16px 0; font-weight: 700; font-size: 14px; color: var(--text); }
.map-tip { padding: 6px 16px 12px; font-size: 12px; color: var(--text-faint); }
#detail-map { height: 60vh; min-height: 380px; width: 100%; }

@media (max-width: 720px) {
  .detail-hero { flex-direction: column; align-items: flex-start; }
  .detail-hero-badges { width: 100%; justify-content: space-between; }
  .dbadge { flex: 1; min-width: 0; }
}
