:root {
  --bg: #0f1420;
  --bg-soft: #161d2e;
  --panel: #1b2436;
  --panel-2: #212c42;
  --border: #2c3852;
  --text: #e6ebf5;
  --muted: #93a0b8;
  --accent: #5cc8ff;
  --accent-2: #b388ff;
  --good: #4ade80;
  --warn: #fbbf24;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1a2742 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 20, 32, 0.7);
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 16px; }
.logo {
  font-size: 38px;
  color: var(--accent);
  filter: drop-shadow(0 0 10px rgba(92, 200, 255, 0.5));
}
.topbar h1 { font-size: 1.15rem; margin: 0; letter-spacing: 0.2px; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; }
.source {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 999px;
  white-space: nowrap;
}
.source:hover { background: var(--panel); }

/* ---------- Nav ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 6px;
  padding: 10px 28px;
  background: rgba(15, 20, 32, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.86rem;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 9px;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.nav a:hover { color: var(--text); background: var(--panel); }
.nav a.active { color: #06121f; background: var(--accent); }

/* ---------- Layout ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 28px; }
section { margin-bottom: 56px; scroll-margin-top: 70px; }
section.hidden { display: none; }
h2 { font-size: 1.5rem; margin: 0 0 4px; }
.section-desc { color: var(--muted); margin: 0 0 22px; max-width: 760px; }
.panel-title { margin: 0 0 10px; font-size: 1rem; color: var(--text); }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 18px;
}
.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

/* ---------- KPI cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.card {
  background: linear-gradient(160deg, var(--panel-2), var(--bg-soft));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card .value { font-size: 2rem; font-weight: 700; color: var(--accent); }
.card .label { color: var(--muted); font-size: 0.82rem; margin-top: 4px; }

/* ---------- Controls ---------- */
.controls { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 12px; }
.controls label { color: var(--muted); font-size: 0.85rem; }
.controls select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  margin-left: 6px;
  font-size: 0.85rem;
}

/* ---------- Cluster profile table ---------- */
table.profiles { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.profiles th, table.profiles td {
  padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border);
}
table.profiles th:first-child, table.profiles td:first-child { text-align: left; }
table.profiles thead th { color: var(--muted); font-weight: 600; }
.swatch { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 7px; vertical-align: middle; }

/* ---------- Misc ---------- */
.note { color: var(--muted); font-size: 0.8rem; margin-top: 10px; }
.note code, code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; color: var(--accent-2); font-size: 0.85em; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; font-size: 1rem; }
.footer { border-top: 1px solid var(--border); padding: 22px 28px; color: var(--muted); font-size: 0.8rem; text-align: center; }

/* D3 circadian */
#chart-circadian svg text { fill: var(--muted); font-size: 11px; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
  font-size: 0.8rem; color: var(--text); box-shadow: var(--shadow); opacity: 0;
  transition: opacity 0.1s;
}
