/* ─── LifeOS Dashboard V4 — Dark Industrial ──────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  /* Backgrounds */
  --bg-base: #0d1117;
  --bg-surface: #161b22;
  --bg-elevated: #1c2128;
  --bg-inset: #0a0e14;

  /* Borders */
  --border-default: #30363d;
  --border-muted: #21262d;
  --border-subtle: #161b22;

  /* Text */
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --text-disabled: #30363d;

  /* Source Colors */
  --color-home: #f85149;
  --color-youtube: #7c3aed;
  --color-spotify: #1DB954;
  --color-food: #00CCBC;
  --color-whoop: #44D62C;
  --color-garmin: #FF6633;
  --color-insights: #F59E0B;
  --color-sleep: #7c3aed;
  --color-activity: #FF6633;

  /* Functional */
  --color-success: #3fb950;
  --color-warning: #d29922;
  --color-danger: #f85149;
  --color-info: #58a6ff;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;
  --space-4xl: 96px;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-pill: 100px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow-garmin: 0 0 20px rgba(255,102,51,0.15);
  --shadow-glow-whoop: 0 0 20px rgba(68,214,44,0.15);
  --shadow-glow-sleep: 0 0 20px rgba(124,58,237,0.15);

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 300ms;
}

/* ─── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; -webkit-font-smoothing: antialiased; }
body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── Loading Overlay ──────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-base);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: var(--space-lg);
  transition: opacity 0.5s var(--ease);
}
.loading-overlay.fade-out { opacity: 0; pointer-events: none; }
.loading-spinner {
  width: 48px; height: 48px;
  border: 3px solid var(--border-default);
  border-top-color: var(--color-garmin);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  font-size: 14px; color: var(--text-secondary);
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
}
.loading-progress {
  width: 200px; height: 2px;
  background: var(--border-default);
  border-radius: 1px;
  overflow: hidden;
}
.loading-progress-bar {
  height: 100%; width: 0%;
  background: var(--color-garmin);
  transition: width 0.3s var(--ease);
}

/* ─── Floating Nav (Desktop) ──────────────────────────── */
.floating-nav {
  position: fixed;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 0;
  cursor: pointer;
  position: relative;
}
.nav-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border-default);
  transition: all var(--duration) var(--ease);
  flex-shrink: 0;
}
.nav-item.active .nav-dot {
  width: 10px; height: 10px;
  box-shadow: 0 0 8px currentColor;
}
.nav-label {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  opacity: 0;
  transform: translateX(-4px);
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.nav-item:hover .nav-label,
.nav-item.active .nav-label {
  opacity: 1;
  transform: translateX(0);
}
.nav-item.active .nav-label { color: var(--text-secondary); }

/* ─── Mobile Nav ──────────────────────────────────────── */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  background: rgba(13,17,23,0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-default);
  padding: var(--space-sm) var(--space-md);
  overflow-x: auto;
  gap: var(--space-xs);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.mobile-nav::-webkit-scrollbar { display: none; }
.mobile-nav-pill {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-default);
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
  white-space: nowrap;
  letter-spacing: 0.03em;
  transition: all var(--duration) var(--ease);
}
.mobile-nav-pill.active {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

/* ─── Main Content ────────────────────────────────────── */
#dashboard { display: none; }
#dashboard.loaded { display: block; }
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-2xl) 120px;
}

/* ─── Section Base ────────────────────────────────────── */
.dash-section {
  padding: var(--space-4xl) 0;
  border-bottom: 1px solid var(--border-muted);
  min-height: 60vh;
}
.dash-section:last-child { border-bottom: none; }
.section-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-2xl);
}
.section-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.section-title {
  font-size: clamp(20px, 2.5vw, 28px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.section-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-left: auto;
  letter-spacing: 0.03em;
}

/* ─── Scroll Reveal Animations ────────────────────────── */
.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
}
.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}
.reveal-stagger > .reveal-child {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}
.reveal-stagger.visible > .reveal-child { opacity: 1; transform: translateY(0); }

/* ─── Grids ───────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-lg); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-lg); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-lg); }
.grid-6 { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--space-md); }

/* ─── Cards ───────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  transition: border-color var(--duration) var(--ease);
}
.card:hover { border-color: var(--text-muted); }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-md);
}
.card-title {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.card-value {
  font-size: clamp(28px, 3vw, 40px);
  font-weight: 800;
  font-family: var(--font-mono);
  line-height: 1;
  letter-spacing: -0.03em;
}
.card-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: var(--space-sm);
}

/* ─── SECTION 1: VITALS (Hero) ──────────────────────── */
#section-vitals { min-height: 100vh; padding-top: 80px; border-bottom: none; }
.vitals-title {
  text-align: center;
  margin-bottom: var(--space-3xl);
}
.vitals-title h1 {
  font-size: clamp(32px, 5vw, 56px);
  font-weight: 900;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
}
.vitals-title .vitals-sub {
  font-size: 14px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: var(--space-sm);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Fitness Age Gap */
.fitness-age-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(24px, 5vw, 64px);
  margin-bottom: var(--space-3xl);
  padding: var(--space-2xl) 0;
}
.age-number {
  font-family: var(--font-mono);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.05em;
}
.age-biological {
  font-size: clamp(48px, 8vw, 96px);
  color: var(--color-garmin);
  text-shadow: 0 0 40px rgba(255,102,51,0.3);
}
.age-chronological {
  font-size: clamp(36px, 6vw, 72px);
  color: var(--text-muted);
}
.age-label {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: var(--space-sm);
  text-align: center;
}
.age-gap-bar {
  flex: 0 0 auto;
  width: clamp(120px, 20vw, 240px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
}
.age-gap-track {
  width: 100%; height: 6px;
  background: var(--border-default);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.age-gap-fill {
  position: absolute;
  top: 0; left: 50%; height: 100%;
  border-radius: 3px;
  transition: width 1s var(--ease), transform 1s var(--ease);
}
.age-gap-label {
  font-size: 14px;
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.age-gap-label.younger { color: var(--color-success); }
.age-gap-label.older { color: var(--color-danger); }

.fitness-age-sparkline {
  width: 100%;
  max-width: 600px;
  margin: 0 auto var(--space-3xl);
  height: 60px;
}

/* Activity Rings */
.rings-row {
  display: flex;
  justify-content: center;
  gap: clamp(24px, 5vw, 64px);
  margin-bottom: var(--space-3xl);
  flex-wrap: wrap;
}
.ring-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
}
.ring-svg {
  width: clamp(80px, 10vw, 120px);
  height: clamp(80px, 10vw, 120px);
}
.ring-bg { fill: none; stroke: var(--border-default); }
.ring-fg { fill: none; stroke-linecap: round; transition: stroke-dasharray 1.5s var(--ease); }
.ring-center-text {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  fill: var(--text-primary);
  text-anchor: middle;
  dominant-baseline: central;
}
.ring-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Lifetime Stats */
.lifetime-stats {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-3xl);
}
.lifetime-stat {
  padding: var(--space-lg) var(--space-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  text-align: center;
  position: relative;
  overflow: hidden;
}
.lifetime-stat::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
}
.lifetime-stat .stat-number {
  font-family: var(--font-mono);
  font-size: clamp(20px, 2.5vw, 32px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  margin-bottom: var(--space-xs);
}
.lifetime-stat .stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Coverage Heatmap */
.coverage-heatmap {
  width: 100%;
  overflow-x: auto;
  padding-bottom: var(--space-md);
}
.coverage-heatmap svg { display: block; }
.coverage-heatmap .day-cell {
  rx: 2; ry: 2;
  stroke: var(--bg-base);
  stroke-width: 1;
  cursor: pointer;
  transition: opacity 0.15s;
}
.coverage-heatmap .day-cell:hover { opacity: 0.8; }
.coverage-heatmap .month-label {
  font-size: 10px;
  fill: var(--text-muted);
  font-family: var(--font-mono);
}
.coverage-heatmap .year-label {
  font-size: 11px;
  fill: var(--text-secondary);
  font-family: var(--font-mono);
  font-weight: 600;
}

/* ─── SECTION 2: BODY ────────────────────────────────── */
.vo2-hero { width: 100%; margin-bottom: var(--space-2xl); }
.chart-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}
.chart-container .chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-md);
}
.chart-container .chart-area {
  width: 100%;
  min-height: 280px;
}

/* ─── SECTION 3: SLEEP ───────────────────────────────── */
.sleep-stages-legend {
  display: flex; gap: var(--space-lg);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}
.sleep-stages-legend .legend-item {
  display: flex; align-items: center; gap: var(--space-sm);
  font-size: 12px; color: var(--text-secondary);
}
.sleep-stages-legend .legend-dot {
  width: 10px; height: 10px; border-radius: 2px;
}

/* ─── SECTION 4: ACTIVITY ────────────────────────────── */
.donut-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2xl);
  margin-bottom: var(--space-2xl);
  flex-wrap: wrap;
}
.donut-chart-container { width: 280px; height: 280px; position: relative; }
.donut-center-label {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
.donut-center-label .donut-number {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 800;
  color: var(--text-primary);
}
.donut-center-label .donut-text {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.donut-legend {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.donut-legend-item {
  display: flex; align-items: center; gap: var(--space-sm);
  font-size: 13px; color: var(--text-secondary);
}
.donut-legend-item .legend-bar {
  width: 12px; height: 12px; border-radius: 3px;
}
.donut-legend-item .legend-count {
  font-family: var(--font-mono);
  color: var(--text-primary);
  font-weight: 600;
  margin-left: auto;
  padding-left: var(--space-lg);
}

/* Record Board */
.record-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-2xl);
}
.record-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  position: relative;
  overflow: hidden;
}
.record-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(255,102,51,0.1), transparent 60%) border-box;
  mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
  -webkit-mask-composite: xor;
  pointer-events: none;
}
.record-card .record-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--color-garmin);
  margin-bottom: var(--space-xs);
}
.record-card .record-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}
.record-card .record-date {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ─── SECTION 5: HOME ────────────────────────────────── */
.home-kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-2xl);
}
.home-kpi {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-left: 3px solid var(--color-home);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
}
.home-kpi .kpi-val {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
}
.home-kpi .kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

/* ─── SECTION 6: MIND ────────────────────────────────── */
.mind-sub-nav {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-2xl);
}
.mind-pill {
  padding: 8px 20px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-default);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  letter-spacing: 0.03em;
}
.mind-pill:hover { color: var(--text-secondary); border-color: var(--text-muted); }
.mind-pill.active { color: var(--text-primary); border-color: var(--text-secondary); background: var(--bg-elevated); }
.mind-panel { display: none; }
.mind-panel.active { display: block; }

/* YouTube Heatmap */
.yt-heatmap-grid {
  display: grid;
  gap: 2px;
}
.yt-heatmap-cell {
  border-radius: 2px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.yt-heatmap-cell:hover { opacity: 0.7; }

/* ─── SECTION 7: FOOD ────────────────────────────────── */
/* uses .card and .chart-container */

/* ─── SECTION 8: INSIGHTS ────────────────────────────── */
.insight-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-left: 3px solid var(--color-insights);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
}
.insight-card .insight-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}
.insight-card .insight-body {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: var(--space-md);
}
.insight-card .insight-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: var(--space-md);
}
.confidence-bar {
  width: 80px; height: 4px;
  background: var(--border-default);
  border-radius: 2px;
  overflow: hidden;
}
.confidence-bar-fill {
  height: 100%;
  background: var(--color-insights);
  border-radius: 2px;
}

/* ─── Tooltip ─────────────────────────────────────────── */
.tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 200;
  background: rgba(28,33,40,0.97);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-primary);
  line-height: 1.5;
  max-width: 260px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 0.15s;
}
.tooltip.show { opacity: 1; }

/* ─── ApexCharts Dark Overrides ──────────────────────── */
.apexcharts-tooltip {
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border-default) !important;
  border-radius: var(--radius-sm) !important;
  color: var(--text-primary) !important;
  font-family: var(--font-mono) !important;
  font-size: 12px !important;
  box-shadow: var(--shadow-lg) !important;
}
.apexcharts-tooltip-title {
  background: var(--bg-surface) !important;
  border-bottom: 1px solid var(--border-default) !important;
  color: var(--text-secondary) !important;
  font-weight: 500 !important;
}
.apexcharts-xaxistooltip, .apexcharts-yaxistooltip {
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border-default) !important;
  color: var(--text-primary) !important;
}
.apexcharts-gridline { stroke: var(--border-muted) !important; }
.apexcharts-text { fill: var(--text-muted) !important; }
.apexcharts-legend-text { color: var(--text-secondary) !important; font-size: 12px !important; }

/* ─── Responsive ──────────────────────────────────────── */
@media (max-width: 1024px) {
  .main-content { padding: 0 var(--space-lg) 120px; }
  .lifetime-stats { grid-template-columns: repeat(3, 1fr); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .home-kpis { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .floating-nav { display: none; }
  .mobile-nav { display: flex; }
  .main-content { padding: 0 var(--space-md) 100px; }
  .dash-section { padding: var(--space-2xl) 0; }
  #section-vitals { padding-top: 40px; min-height: auto; }
  .fitness-age-hero { flex-direction: column; gap: var(--space-lg); }
  .age-gap-bar { width: 200px; }
  .lifetime-stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .home-kpis { grid-template-columns: 1fr 1fr; }
  .rings-row { gap: var(--space-lg); }
  .donut-hero { flex-direction: column; }
  .record-board { grid-template-columns: 1fr 1fr; }
  .section-subtitle { display: none; }
}

@media (max-width: 480px) {
  .lifetime-stats { grid-template-columns: 1fr 1fr; }
  .home-kpis { grid-template-columns: 1fr; }
  .record-board { grid-template-columns: 1fr; }
}
