/* ============================================================
   行者骑行数据大屏 — 紧凑版 (1920×1080)
   ============================================================ */

:root {
  --bg-primary: #0b0f16;
  --bg-card: #141b2b;
  --bg-card-hover: #1a2340;
  --border: #1e2a45;
  --text-primary: #e2e8f0;
  --text-secondary: #7e8ea0;
  --green: #22c55e;
  --blue: #3b82f6;
  --orange: #f59e0b;
  --purple: #8b5cf6;
  --cyan: #06b6d4;
  --gradient-1: linear-gradient(135deg, #22c55e 0%, #06b6d4 100%);
  --gradient-2: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  --gradient-3: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
  --gradient-4: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --gutter-x: 28px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "PingFang SC", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

/* ── 顶部 ── */
.top-bar { height: 2px; background: var(--gradient-1); width: 100%; }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px max(var(--gutter-x), env(safe-area-inset-left)) 4px max(var(--gutter-x), env(safe-area-inset-right));
  width: 100%;
  max-width: 1920px;
}

.header-left { display: flex; align-items: center; gap: 10px; }
.header-icon { font-size: 24px; line-height: 1; }

.header h1 {
  font-size: 18px;
  font-weight: 700;
  background: var(--gradient-1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-right { display: flex; align-items: center; gap: 14px; }
.update-time { font-size: 11px; color: var(--text-secondary); }

/* ── 年份选择器 ── */
.year-tabs {
  padding: 2px max(var(--gutter-x), env(safe-area-inset-left)) 6px max(var(--gutter-x), env(safe-area-inset-right));
  display: flex;
  gap: 6px;
  width: 100%;
  max-width: 1920px;
}

.year-tab {
  padding: 3px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.year-tab:hover, .year-tab:active { border-color: var(--green); color: var(--text-primary); }

.year-tab.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-weight: 600;
}

/* ── 主体 ── */
.container {
  padding: 6px max(var(--gutter-x), env(safe-area-inset-left)) 10px max(var(--gutter-x), env(safe-area-inset-right));
  height: calc(100vh - 68px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 1920px;
}

/* ── KPI 卡片行 (8 张一行) ── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  flex-shrink: 0;
  margin-bottom: 4px;
}

.kpi-card {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 10px 6px 8px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  min-height: 86px;
  transition: all 0.25s ease;
  cursor: default;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.kpi-card:hover, .kpi-card:active {
  border-color: var(--accent, var(--green));
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
  background: var(--bg-card-hover);
}

/* 顶部彩色横条 */
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent, var(--gradient-1));
}

/* 图标 + 数字行 */
.kpi-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 2px;
}

.kpi-icon-wrap {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  background: var(--accent-bg, rgba(34,197,94,0.12));
  color: var(--accent, #22c55e);
  flex-shrink: 0;
  transition: all 0.25s;
}

.kpi-card:hover .kpi-icon-wrap,
.kpi-card:active .kpi-icon-wrap {
  transform: scale(1.12);
  background: var(--accent, #22c55e);
  color: #fff;
}

.kpi-main {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.kpi-unit {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 1px;
}

/* 下方标签 + 副标题合并在一行 */
.kpi-info {
  font-size: 10px;
  color: var(--text-secondary);
  letter-spacing: 0.2px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.3;
}

.kpi-info .accent {
  color: var(--accent, #22c55e);
  font-weight: 600;
}

/* ── 图表网格 ── */
.charts-main {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr 1fr;  /* 累计里程占 2 倍 */
  gap: 6px;
  flex: 1;
  min-height: 0;
}

.charts-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  flex: 1.2;
  min-height: 0;
}

.chart-card {
  background: var(--bg-card);
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.chart-wide {
  /* 已经由 grid 的 2fr 控制宽度 */
}

.chart-title {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  user-select: none;
}

.chart-body {
  flex: 1;
  min-height: 0;
  width: 100%;
}

/* ── 最近活动列表 ── */
.recent-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.recent-scroll::-webkit-scrollbar { width: 3px; }
.recent-scroll::-webkit-scrollbar-track { background: transparent; }
.recent-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.recent-item {
  display: grid;
  grid-template-columns: 68px 1fr auto;
  gap: 6px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(30, 42, 69, 0.4);
  align-items: center;
  font-size: 12px;
}

.recent-item:last-child { border-bottom: none; }

.recent-date { font-size: 11px; color: var(--text-secondary); white-space: nowrap; }
.recent-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.recent-stats { font-size: 11px; color: var(--green); white-space: nowrap; display: flex; gap: 8px; }

/* ── Loading / Error ── */
.loading, .error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 16px;
}

.loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
.error-text { color: var(--text-secondary); font-size: 14px; }

/* ============================================================
   响应式 — 平板 (≤1023)
   ============================================================ */
@media (max-width: 1023px) {
  :root { --gutter-x: 20px; }

  body { overflow-y: auto; overflow-x: hidden; height: auto; }
  .container { height: auto; min-height: calc(100vh - 68px); }

  .kpi-row { grid-template-columns: repeat(4, 1fr); }
  .kpi-card { min-height: 80px; }
  .kpi-main { font-size: 18px; }

  .charts-main { grid-template-columns: 1fr 1fr; }
  .charts-main .chart-wide { grid-column: span 2; }
  .charts-bottom { grid-template-columns: 1fr 1fr; }
  .charts-bottom .chart-card:last-child { grid-column: span 2; }

  .chart-card { min-height: 220px; }
}

/* ============================================================
   响应式 — 手机 (≤768)
   ============================================================ */
@media (max-width: 768px) {
  :root { --gutter-x: 12px; }

  body { overflow-y: auto; overflow-x: hidden; height: auto; min-height: 100vh; }
  .container { height: auto; min-height: auto; gap: 8px; }

  .header h1 { font-size: 15px; }
  .header-icon { font-size: 20px; }
  .update-time { font-size: 10px; }

  .year-tabs {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .year-tabs::-webkit-scrollbar { display: none; }
  .year-tab { flex-shrink: 0; min-height: 36px; padding: 7px 14px; font-size: 13px; }

  .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 4px; }
  .kpi-card { min-height: 78px; padding: 8px 4px 6px; }
  .kpi-icon-wrap { width: 22px; height: 22px; font-size: 10px; }
  .kpi-top { gap: 4px; }
  .kpi-main { font-size: 17px; }
  .kpi-unit { font-size: 9px; }
  .kpi-info { font-size: 9px; }

  .charts-main, .charts-bottom { grid-template-columns: 1fr; gap: 8px; }
  .charts-main .chart-wide { grid-column: auto; }

  .chart-card { padding: 10px 12px; min-height: 240px; }
  .chart-card:has(#chartHeatmap) { min-height: 230px; }
  .chart-card:has(#chartRouteMap) { min-height: 220px; }
  .chart-title { font-size: 13px; margin-bottom: 6px; }

  .loading, .error { font-size: 13px; }
}