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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #57606a;
  --green: #3fb950;
  --green-dim: #1f4a2a;
  --yellow: #d29922;
  --yellow-dim: #3d2e0a;
  --red: #f85149;
  --red-dim: #3c1018;
  --blue: #58a6ff;
  --blue-dim: #1a3a5c;
  --accent: #79c0ff;
  --font: 'Space Grotesk', system-ui, sans-serif;
  --mono: 'Space Mono', monospace;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

.page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 0.75rem;
  gap: 0.75rem;
}

/* ── TOPBAR ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.topbar-icon { font-size: 1.4rem; }

.topbar-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.topbar-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: 0.25rem;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1.2rem;
}

.data-vintage {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-family: var(--mono);
}

.back-link {
  font-size: 0.8rem;
  color: var(--blue);
  text-decoration: none;
  opacity: 0.8;
  transition: opacity 0.15s;
}
.back-link:hover { opacity: 1; }

/* ── METRICS BAR ── */
.metrics-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.6rem;
  flex-shrink: 0;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: 10px 10px 0 0;
}
.metric-card.alert::before { background: var(--red); }
.metric-card.warn::before { background: var(--yellow); }
.metric-card.good::before { background: var(--green); }

.metric-val {
  font-family: var(--mono);
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 0.2rem;
}
.metric-card.alert .metric-val { color: var(--red); }
.metric-card.warn .metric-val { color: var(--yellow); }
.metric-card.good .metric-val { color: var(--green); }

.metric-unit {
  font-size: 0.9rem;
  font-weight: 400;
  margin-left: 0.15rem;
  opacity: 0.75;
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.15rem;
}

.metric-note {
  font-size: 0.65rem;
  color: var(--text-dim);
  line-height: 1.3;
}

/* ── MAIN GRID ── */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  flex: 1;
  min-height: 0;
}

/* ── PANELS ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
}

.panel-icon { font-size: 1rem; }

.panel-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

/* ── TABS ── */
.panel-tabs {
  display: flex;
  gap: 0.25rem;
}

.tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.tab:hover { border-color: var(--blue); color: var(--blue); }
.tab.active { background: var(--blue-dim); border-color: var(--blue); color: var(--accent); }

/* ── LEADERBOARD ── */
.panel-leaderboard {
  grid-row: span 1;
}

.leaderboard {
  overflow-y: auto;
  padding: 0.4rem;
  flex: 1;
  min-height: 0;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.5rem;
  border-radius: 7px;
  transition: background 0.12s;
}
.lb-row:hover { background: var(--surface2); }

.lb-rank {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  width: 1.2rem;
  text-align: center;
  flex-shrink: 0;
}

.lb-row:nth-child(1) .lb-rank { color: #ffd700; font-weight: 700; font-size: 0.85rem; }
.lb-row:nth-child(2) .lb-rank { color: #c0c0c0; font-weight: 700; }
.lb-row:nth-child(3) .lb-rank { color: #cd7f32; font-weight: 700; }

.lb-flag { font-size: 1.2rem; flex-shrink: 0; }

.lb-info { flex: 1; min-width: 0; }

.lb-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

.lb-note {
  font-size: 0.65rem;
  color: var(--text-dim);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-val {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

.lb-number {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--green);
}

.lb-trend {
  font-size: 0.8rem;
  font-weight: 700;
}
.trend-down { color: var(--green); }
.trend-up   { color: var(--red); }
.trend-flat { color: var(--text-muted); }

/* ── RIGHT COLUMN ── */
.right-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
}

/* ── MILESTONES ── */
.panel-milestones {
  flex: 1;
  min-height: 0;
}

.milestones-list {
  overflow-y: auto;
  padding: 0.4rem 0.6rem;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.milestone {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.4rem 0.5rem;
  border-radius: 7px;
  border-left: 3px solid transparent;
}
.milestone.good { border-color: var(--green); background: rgba(63,185,80,0.05); }
.milestone.warn { border-color: var(--yellow); background: rgba(210,153,34,0.05); }
.milestone.bad  { border-color: var(--red); background: rgba(248,81,73,0.05); }

.milestone-year {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-top: 0.05rem;
}

.milestone-text {
  font-size: 0.75rem;
  color: var(--text);
  line-height: 1.4;
}
.milestone-text strong { color: var(--accent); }

/* ── EMITTERS ── */
.panel-emitters { flex-shrink: 0; }

.emitters-grid {
  padding: 0.5rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.emitter-bar-wrap {
  display: grid;
  grid-template-columns: 6rem 1fr 3.5rem;
  align-items: center;
  gap: 0.5rem;
}

.emitter-label {
  font-size: 0.75rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.flag { font-size: 0.9rem; }

.bar-track {
  background: var(--surface2);
  border-radius: 3px;
  height: 0.5rem;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.bar-fill.worst { background: var(--red); }
.bar-fill.bad   { background: #e07b35; }
.bar-fill.warn  { background: var(--yellow); }
.bar-fill.ok    { background: #6bc46d; }
.bar-fill.good  { background: var(--green); }

.emitter-val {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: right;
}

/* ── SOURCES FOOTER ── */
.sources-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.2rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.9rem;
  flex-shrink: 0;
}

.sources-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 0.2rem;
}

.source-link {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: color 0.15s;
}
.source-link:hover { color: var(--blue); }

.source-tag {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
  font-size: 0.6rem;
  color: var(--text-dim);
  font-family: var(--mono);
}
.source-link:hover .source-tag { border-color: var(--blue); color: var(--accent); }

/* ── SCROLLBAR STYLING ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  .metrics-bar {
    grid-template-columns: repeat(3, 1fr);
  }
  .metrics-bar .metric-card:nth-child(4),
  .metrics-bar .metric-card:nth-child(5) {
    grid-column: span 1;
  }
  .main-grid {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  .right-col {
    min-height: 30rem;
  }
  html, body { overflow: auto; }
  .page { height: auto; }
}

@media (max-width: 600px) {
  .topbar-sub { display: none; }
  .metrics-bar { grid-template-columns: repeat(2, 1fr); }
  .metric-val { font-size: 1.2rem; }
}
