﻿/* Sport Dashboard - Light Theme Design System
   Based on Q.Tu Dashboard architecture spec */

:root {
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #cbd5e1;
  --accent: #f97316;
  --accent-hover: #ea580c;
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --red: #ef4444;
  --red-bg: #fef2f2;
  --blue: #3b82f6;
  --blue-bg: #eff6ff;
  --yellow: #ca8a04;
  --yellow-bg: #fefce8;
  --purple: #8b5cf6;
  --purple-bg: #faf5ff;
  --cyan: #0891b2;
  --cyan-bg: #ecfeff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --space-section: 28px;
  --space-group: 16px;
  --space-element: 12px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  width: min(100vw, 1200px);
  margin: 0 auto;
  padding: 12px 16px 40px;
}

/* Navigation */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  background: linear-gradient(180deg, var(--bg) 74%, rgba(248, 250, 252, 0));
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.brand strong {
  display: block;
  font-size: 20px;
  font-weight: 750;
  line-height: 1.2;
  color: var(--text);
}

.brand span {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 12px;
}

.nav-links {
  display: flex;
  gap: 4px;
}

.nav-link {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}

.nav-link:hover {
  background: var(--border);
  color: var(--text);
}

.nav-link.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* Status bar */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  color: var(--text-muted);
  font-size: 12px;
  padding: 0 2px 12px;
}

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.15);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Error display */
.error {
  display: none;
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius);
  background: var(--red-bg);
  color: var(--red);
  padding: 12px 16px;
  margin: 8px 0 12px;
  font-size: 13px;
  line-height: 1.6;
}

/* Loading */
.loading {
  display: grid;
  place-items: center;
  min-height: 200px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Section */
.section {
  margin-top: var(--space-section);
}

.section:first-child {
  margin-top: 0;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.section-note {
  color: var(--text-muted);
  font-size: 12px;
}

/* Status Cards */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.status-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}

.status-card:hover {
  box-shadow: var(--shadow-md);
}

.status-card .card-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.status-card .card-value {
  margin-top: 6px;
  font-size: 28px;
  font-weight: 750;
  line-height: 1.1;
}

.status-card .card-sub {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.status-card .card-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
}

.badge-good { background: var(--green-bg); color: var(--green); }
.badge-warn { background: var(--yellow-bg); color: var(--yellow); }
.badge-info { background: var(--blue-bg); color: var(--blue); }
.badge-bad  { background: var(--red-bg); color: var(--red); }

/* Card accent borders */
.card-accent-green  { border-left: 3px solid var(--green); }
.card-accent-blue   { border-left: 3px solid var(--blue); }
.card-accent-purple { border-left: 3px solid var(--purple); }
.card-accent-orange { border-left: 3px solid var(--accent); }
.card-accent-cyan   { border-left: 3px solid var(--cyan); }
.card-accent-red    { border-left: 3px solid var(--red); }

/* Chart panels */
.chart-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  padding: 16px;
  box-shadow: var(--shadow);
}

.chart-panel canvas {
  width: 100% !important;
  max-height: 280px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.chart-grid .chart-panel {
  margin-top: 0;
}

/* Legend */
.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

/* Tables & Lists */
.list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.row:last-child {
  border-bottom: 0;
}

.row:hover {
  background: var(--bg);
}

.row-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.row-meta {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 12px;
}

.row-score {
  text-align: right;
  font-size: 13px;
  color: var(--accent);
  white-space: nowrap;
  font-weight: 600;
}

/* Monthly table */
.month-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.month-table th {
  text-align: left;
  padding: 8px 12px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
}

.month-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.month-table tr:hover td {
  background: var(--bg);
}

.month-table .clickable {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}

/* Note cards */
.note {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  padding: 14px 16px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.7;
  box-shadow: var(--shadow);
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  justify-content: center;
  align-items: flex-start;
  padding: 40px 16px;
  overflow-y: auto;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  width: min(100%, 680px);
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.modal-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 18px;
}

.modal-body {
  padding: 20px;
  max-height: 70vh;
  overflow-y: auto;
}

.modal-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.modal-metric {
  text-align: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.modal-metric .val {
  font-size: 22px;
  font-weight: 700;
}

.modal-metric .lbl {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* View switching */
.view {
  display: none;
}

.view.active {
  display: block;
}

/* Button */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover {
  background: var(--bg);
  border-color: var(--border-light);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

/* Insight */
.insight-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--blue-bg), var(--purple-bg));
  padding: 16px;
  line-height: 1.7;
}

.insight-card .insight-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
}

/* Responsive */
@media (max-width: 768px) {
  .chart-grid {
    grid-template-columns: 1fr;
  }
  .status-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .modal-metrics {
    grid-template-columns: repeat(2, 1fr);
  }
  .month-table {
    font-size: 11px;
  }
  .month-table th, .month-table td {
    padding: 6px 8px;
  }
}

@media (max-width: 480px) {
  .status-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .nav-link {
    padding: 6px 10px;
    font-size: 12px;
  }
}

/* Enhanced Modal Layers */
.modal-layer {
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.modal-layer h4 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.modal-layer h4 .layer-icon {
  width: 20px; height: 20px;
  border-radius: 4px;
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  color: #fff;
}
/* Route Map */
.route-map {
  height: 260px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #e2e8f0;
}
/* HR Zone Stacked Bar */
.hr-zone-bar {
  display: flex; height: 28px;
  border-radius: 6px; overflow: hidden;
  margin-bottom: 8px;
}
.hr-zone-seg {
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: #fff; font-weight: 600;
}
.hr-zone-legend {
  display: flex; gap: 12px; flex-wrap: wrap;
  font-size: 11px; color: var(--text-muted);
}
.hr-zone-legend span {
  display: inline-flex; align-items: center; gap: 4px;
}
/* Running Dynamics Grid */
.dynamics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.dynamic-item {
  text-align: center; padding: 10px 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.dynamic-item .dv { font-size: 20px; font-weight: 700; color: var(--text); }
.dynamic-item .dl { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
/* Race Card */
.race-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(135deg, #fff7ed, #fefce8);
  padding: 16px; box-shadow: var(--shadow);
}
.race-card .race-name { font-size: 15px; font-weight: 700; }
.race-card .race-days { font-size: 32px; font-weight: 800; color: var(--accent); margin: 4px 0; }
.race-card .race-info { font-size: 12px; color: var(--text-muted); }
/* Recovery Index */
.recovery-bar {
  height: 8px; border-radius: 999px;
  background: var(--border); overflow: hidden;
  margin-top: 6px;
}
.recovery-fill {
  height: 100%; border-radius: inherit;
  transition: width 0.5s;
}
/* Monthly Collapsible */
.month-group { margin-bottom: 2px; }
.month-group-header {
  display: grid; grid-template-columns: 1fr auto;
  align-items: center; padding: 12px 16px;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  transition: background 0.15s;
}
.month-group-header:hover { background: var(--bg); }
.month-group-header .mgh-label { font-weight: 700; font-size: 14px; }
.month-group-header .mgh-value { color: var(--accent); font-weight: 600; font-size: 14px; }
.month-group-body { display: none; padding: 0; }
.month-group.open .month-group-body { display: block; }
.month-group.open .month-group-header { border-radius: var(--radius) var(--radius) 0 0; border-bottom: 0; }
/* 16-col mini table */
.month-detail-table {
  width: 100%; border-collapse: collapse;
  font-size: 11px; background: var(--card-bg);
  border: 1px solid var(--border); border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius); overflow: hidden;
}
.month-detail-table th {
  text-align: left; padding: 6px 8px;
  color: var(--text-muted); font-weight: 600; font-size: 10px;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.month-detail-table td {
  padding: 6px 8px; border-bottom: 1px solid var(--border);
}
.month-detail-table tr:last-child td { border-bottom: 0; }
.month-detail-table .clickable { color: var(--accent); font-weight: 600; cursor: pointer; }
/* Motivation */
.motivation {
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: var(--card-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 14px; font-style: italic;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
/* Pace/HR Activity Chart */
.modal-chart { height: 180px; margin-top: 10px; }
/* AI analysis card in modal */
.ai-analysis {
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--purple-bg), var(--blue-bg));
  border-radius: var(--radius-sm);
  font-size: 13px; line-height: 1.7;
  color: var(--text-secondary);
}
/* Responsive updates */
@media (max-width: 768px) {
  .dynamics-grid { grid-template-columns: repeat(2, 1fr); }
  .month-detail-table { font-size: 10px; }
  .month-detail-table th, .month-detail-table td { padding: 4px 6px; }
}


/* Language Toggle */
.lang-toggle {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border-light);
  background: var(--card-bg);
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.lang-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #fff;
  box-shadow: 0 1px 4px rgba(249, 115, 22, 0.15);
}
.lang-toggle:active {
  transform: scale(0.96);
}