:root {
  --bg: #070c09;
  --bg-deep: #040806;
  --panel: rgba(12, 22, 17, 0.82);
  --panel-hover: rgba(16, 30, 23, 0.9);
  --panel-card: rgba(11, 20, 16, 0.7);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --line-glow: rgba(184, 255, 90, 0.25);
  --ink: #f0f6f2;
  --ink-subtle: #b6c5bc;
  --muted: #6f8076;
  
  /* Domain Accent Colors */
  --acid: #b8ff5a;
  --acid-glow: rgba(184, 255, 90, 0.15);
  --emerald: #34d399;
  --cyan: #38bdf8;
  --cyan-glow: rgba(56, 189, 248, 0.15);
  --amber: #fbbf24;
  --amber-glow: rgba(251, 191, 36, 0.15);
  --rose: #f43f5e;
  --rose-glow: rgba(244, 63, 94, 0.15);
  --purple: #c084fc;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  line-height: 1.5;
}

/* Ambient Background Grid & Radial Lighting */
.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: 
    radial-gradient(circle at 15% 15%, rgba(184, 255, 90, 0.06), transparent 35%),
    radial-gradient(circle at 85% 20%, rgba(56, 189, 248, 0.06), transparent 35%),
    radial-gradient(circle at 50% 80%, rgba(244, 63, 94, 0.04), transparent 45%),
    linear-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px);
  background-size: auto, auto, auto, 48px 48px, 48px 48px;
}

main {
  max-width: 1380px;
  margin: 0 auto;
  padding: 24px 32px 64px;
  position: relative;
  z-index: 1;
}

/* Header & Top Bar */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: 'DM Mono', monospace;
  font-weight: 500;
  letter-spacing: 0.16em;
  font-size: 14px;
}

.brand .mark {
  width: 12px;
  height: 12px;
  background: var(--acid);
  transform: rotate(45deg);
  box-shadow: 0 0 12px var(--acid);
  position: relative;
}

.brand .mark::after {
  content: '';
  position: absolute;
  inset: 2px;
  background: var(--bg);
}

.brand small {
  color: var(--muted);
  font-size: 11px;
  border-left: 1px solid var(--line);
  padding-left: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

/* Status Pill */
.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.12em;
  padding: 6px 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  color: var(--muted);
}

.status-pill.live {
  color: var(--acid);
  border-color: rgba(184, 255, 90, 0.25);
  background: var(--acid-glow);
}

.status-pill i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}

.sync-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(184, 255, 90, 0.1);
  color: var(--acid);
  border: 1px solid rgba(184, 255, 90, 0.3);
  padding: 7px 16px;
  border-radius: 6px;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sync-btn:hover:not(:disabled) {
  background: var(--acid);
  color: var(--bg-deep);
  box-shadow: 0 0 16px rgba(184, 255, 90, 0.35);
}

.sync-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sync-btn svg {
  width: 13px;
  height: 13px;
  transition: transform 0.5s ease;
}

.sync-btn.loading svg {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  100% { transform: rotate(360deg); }
}

.user-tag {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--muted);
}

.logout-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 6px;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
}

.logout-btn:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

/* Nav Tabs */
.nav-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 28px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.nav-tab {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 10px 18px;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.12em;
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  position: relative;
  transition: all 0.2s;
}

.nav-tab:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.02);
}

.nav-tab.active {
  color: var(--acid);
  font-weight: 600;
  background: rgba(184, 255, 90, 0.05);
}

.nav-tab.active::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--acid);
  box-shadow: 0 0 10px var(--acid);
}

/* Hero Cards Grid */
.hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.card {
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  position: relative;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--line);
}

.card.readiness::before { background: linear-gradient(90deg, transparent, var(--acid), transparent); }
.card.sleep::before { background: linear-gradient(90deg, transparent, var(--cyan), transparent); }
.card.activity::before { background: linear-gradient(90deg, transparent, var(--amber), transparent); }
.card.vitals::before { background: linear-gradient(90deg, transparent, var(--rose), transparent); }
.card.weight::before { background: linear-gradient(90deg, transparent, var(--purple), transparent); }

.card:hover {
  border-color: var(--line-strong);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.domain-tag {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card.readiness .domain-tag { color: var(--acid); }
.card.sleep .domain-tag { color: var(--cyan); }
.card.activity .domain-tag { color: var(--amber); }
.card.vitals .domain-tag { color: var(--rose); }
.card.weight .domain-tag { color: var(--purple); }

.score-badge {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 10px;
  letter-spacing: 0.08em;
  font-weight: 500;
}

.badge-optimal { background: rgba(52, 211, 153, 0.18); color: #34d399; border: 1px solid rgba(52, 211, 153, 0.3); }
.badge-good { background: rgba(184, 255, 90, 0.18); color: #b8ff5a; border: 1px solid rgba(184, 255, 90, 0.3); }
.badge-fair { background: rgba(251, 191, 36, 0.18); color: #fbbf24; border: 1px solid rgba(251, 191, 36, 0.3); }
.badge-attention { background: rgba(244, 63, 94, 0.18); color: #f43f5e; border: 1px solid rgba(244, 63, 94, 0.3); }

.card-value {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}

.big-number {
  font-family: 'DM Mono', monospace;
  font-size: 56px;
  font-weight: 300;
  line-height: 1;
  letter-spacing: -0.05em;
  color: var(--ink);
}

.unit {
  font-family: 'DM Mono', monospace;
  font-size: 14px;
  color: var(--muted);
}

/* Sparklines */
.sparkline-wrapper {
  margin: 12px 0 16px;
  position: relative;
  height: 48px;
}

.sparkline-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.sparkline-curve {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.card.readiness .sparkline-curve { stroke: var(--acid); filter: drop-shadow(0 0 4px var(--acid)); }
.card.sleep .sparkline-curve { stroke: var(--cyan); filter: drop-shadow(0 0 4px var(--cyan)); }
.card.activity .sparkline-curve { stroke: var(--amber); filter: drop-shadow(0 0 4px var(--amber)); }
.card.vitals .sparkline-curve { stroke: var(--rose); filter: drop-shadow(0 0 4px var(--rose)); }
.card.weight .sparkline-curve { stroke: var(--purple); filter: drop-shadow(0 0 4px var(--purple)); }

.sparkline-fill {
  opacity: 0.15;
}

.card.readiness .sparkline-fill { fill: var(--acid); }
.card.sleep .sparkline-fill { fill: var(--cyan); }
.card.activity .sparkline-fill { fill: var(--amber); }
.card.vitals .sparkline-fill { fill: var(--rose); }
.card.weight .sparkline-fill { fill: var(--purple); }

.card-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.sub-metric {
  font-family: 'DM Mono', monospace;
}

.sub-metric span {
  display: block;
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.1em;
  margin-bottom: 2px;
}

.sub-metric strong {
  font-size: 13px;
  color: var(--ink-subtle);
  font-weight: 500;
}

/* Grid Layouts for Deep-Dive Sections */
.dashboard-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 28px;
}

.dashboard-row.full {
  grid-template-columns: 1fr;
}

.dashboard-row.three-col {
  grid-template-columns: 1.2fr 1fr 0.8fr;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-title h3 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-title span {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--muted);
}

/* Contributor Score Meters */
.contributors-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 24px;
}

.contributor-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.contributor-header {
  display: flex;
  justify-content: space-between;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
}

.contributor-name {
  color: var(--ink-subtle);
}

.contributor-score {
  font-weight: 600;
  color: var(--ink);
}

.progress-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.progress-fill.optimal { background: #34d399; box-shadow: 0 0 8px rgba(52, 211, 153, 0.4); }
.progress-fill.good { background: #b8ff5a; box-shadow: 0 0 8px rgba(184, 255, 90, 0.4); }
.progress-fill.fair { background: #fbbf24; box-shadow: 0 0 8px rgba(251, 191, 36, 0.4); }
.progress-fill.attention { background: #f43f5e; box-shadow: 0 0 8px rgba(244, 63, 94, 0.4); }

/* Sleep Stage Visualizer */
.sleep-stages-bar {
  display: flex;
  height: 28px;
  border-radius: 6px;
  overflow: hidden;
  margin: 16px 0;
  border: 1px solid var(--line);
}

.stage-block {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  color: var(--bg-deep);
  position: relative;
}

.stage-deep { background: #6366f1; color: #fff; }
.stage-rem { background: #38bdf8; }
.stage-light { background: #34d399; }
.stage-awake { background: #475569; color: #cbd5e1; }

.sleep-legend {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 12px;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--muted);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
  margin-right: 6px;
}

/* Activity Circles / Rings */
.activity-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 14px;
}

.stat-tile {
  background: var(--panel-card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}

.stat-tile span {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
}

.stat-tile strong {
  font-family: 'DM Mono', monospace;
  font-size: 20px;
  font-weight: 500;
  color: var(--ink);
}

/* Heart Rate Continuous Pulse Timeline */
.hr-chart-wrapper {
  height: 160px;
  width: 100%;
  margin-top: 12px;
}

/* Trend Matrix Table */
.trend-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
}

.trend-table th {
  text-align: left;
  padding: 10px 14px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.1em;
}

.trend-table td {
  padding: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.trend-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.delta-pill {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.delta-pill.positive {
  background: rgba(52, 211, 153, 0.15);
  color: #34d399;
}

.delta-pill.negative {
  background: rgba(244, 63, 94, 0.15);
  color: #f43f5e;
}

/* Daily AI Report Card */
.report-card {
  background: linear-gradient(145deg, rgba(14, 28, 21, 0.9), rgba(9, 17, 13, 0.95));
  border: 1px solid rgba(184, 255, 90, 0.2);
  border-radius: 12px;
  padding: 28px;
  margin-bottom: 32px;
  position: relative;
  overflow: hidden;
}

.report-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  bottom: 0;
  background: var(--acid);
  box-shadow: 0 0 16px var(--acid);
}

.report-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.report-header h2 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.report-status-badge {
  background: rgba(184, 255, 90, 0.12);
  color: var(--acid);
  border: 1px solid rgba(184, 255, 90, 0.3);
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 6px 14px;
  border-radius: 20px;
}

.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-top: 20px;
}

.report-col h4 {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 12px;
}

.report-col ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.report-col li {
  font-size: 13px;
  color: var(--ink-subtle);
  position: relative;
  padding-left: 20px;
  line-height: 1.6;
}

.report-col li::before {
  content: '▸';
  position: absolute;
  left: 0;
  color: var(--acid);
  font-family: 'DM Mono', monospace;
}

/* Toast Notification */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--panel);
  border: 1px solid var(--acid);
  color: var(--ink);
  padding: 12px 20px;
  border-radius: 8px;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  pointer-events: none;
  z-index: 1000;
}

#toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Responsive Rules */
@media (max-width: 1100px) {
  .hero-grid {
    grid-template-columns: 1fr 1fr;
  }
  .dashboard-row {
    grid-template-columns: 1fr;
  }
  .report-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 650px) {
  main {
    padding: 16px 16px 40px;
  }
  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
  }
  .hero-grid {
    grid-template-columns: 1fr;
  }
  .contributors-grid {
    grid-template-columns: 1fr;
  }
  .activity-stats {
    grid-template-columns: 1fr;
  }
}

/* Weight Form & BMI Gauge */
.weight-form {
  display: grid;
  grid-template-columns: 1.2fr 90px 1.2fr auto;
  gap: 12px;
  align-items: end;
  background: var(--panel-card);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  margin-bottom: 20px;
}

.weight-form label {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.1em;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.weight-form input, .weight-form select {
  background: #070c09;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 6px;
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  outline: none;
}

.weight-form input:focus, .weight-form select:focus {
  border-color: var(--purple);
}

.weight-submit-btn {
  background: var(--purple);
  color: #0d0614;
  border: none;
  padding: 11px 18px;
  border-radius: 6px;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all 0.2s;
}

.weight-submit-btn:hover {
  box-shadow: 0 0 16px rgba(192, 132, 252, 0.4);
  transform: translateY(-1px);
}

.bmi-bar {
  display: flex;
  height: 14px;
  border-radius: 7px;
  overflow: hidden;
  margin: 14px 0 8px;
  position: relative;
  border: 1px solid var(--line);
}

.bmi-segment { height: 100%; }
.bmi-under { background: #38bdf8; width: 25%; }
.bmi-normal { background: #34d399; width: 35%; }
.bmi-over { background: #fbbf24; width: 25%; }
.bmi-obese { background: #f43f5e; width: 15%; }

.bmi-marker {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 4px;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 0 8px #fff;
  transform: translateX(-50%);
}

.weight-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
}

.weight-table th {
  text-align: left;
  padding: 8px 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 9px;
  letter-spacing: 0.1em;
}

.weight-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.delete-weight-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  transition: all 0.2s;
}

.delete-weight-btn:hover {
  color: var(--rose);
  background: rgba(244, 63, 94, 0.1);
}

@media (max-width: 650px) {
  .weight-form {
    grid-template-columns: 1fr;
  }
}
