:root {
  /* Colors - Dark Theme */
  --bg-base: #0b0f19;
  --bg-panel: #151c2e;
  --bg-panel-hover: #1e293b;
  --border-color: #2a364f;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  
  /* Accents */
  --c-cyan: #38bdf8;
  --c-purple: #c084fc;
  --c-rose: #fb7185;
  --c-emerald: #34d399;
  --c-amber: #fbbf24;
  --c-blue: #3b82f6;

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Fraunces', Georgia, serif;

  /* Layout */
  --sidebar-w: 280px;
  --header-h: 80px;
  --border-radius: 12px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  background-color: var(--bg-base);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.5;
  overflow: hidden; /* App-like feel */
  -webkit-font-smoothing: antialiased;
}

/* Ambient Background Blobs for Glassmorphism feel */
.bg-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  z-index: -1;
  opacity: 0.15;
}
.bg-blob--1 {
  width: 400px;
  height: 400px;
  background: var(--c-cyan);
  top: -100px;
  left: 20%;
}
.bg-blob--2 {
  width: 300px;
  height: 300px;
  background: var(--c-purple);
  bottom: 10%;
  right: 10%;
}
.bg-blob--3 {
  width: 250px;
  height: 250px;
  background: var(--c-rose);
  top: 30%;
  left: -50px;
}

/* App Shell Grid */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  margin-top: var(--nav-h, 60px);
  height: calc(100vh - var(--nav-h, 60px));
}

/* ================== SIDEBAR ================== */
.sidebar {
  background-color: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  gap: 2rem;
  overflow-y: auto;
  z-index: 10;
}
.sidebar::-webkit-scrollbar {
  width: 6px;
}
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.sidebar__brand-icon {
  width: 32px;
  height: 32px;
  color: var(--c-cyan);
}
.sidebar__brand-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.1;
}
.sidebar__brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Active Count Card */
.stat-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1.25rem;
  text-align: center;
}
.stat-card__label {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.stat-card__value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1;
  margin-bottom: 0.25rem;
}
.stat-card__sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.stat-card__bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}
.stat-card__bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--c-cyan), var(--c-purple));
  width: 0%;
  transition: width 1s ease-out;
}

/* Filter Groups */
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.filter-group__header {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.filter-group__icon {
  width: 16px;
  height: 16px;
}
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.pill {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.375rem 0.75rem;
  border-radius: 99px;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.pill:hover {
  background: rgba(255, 255, 255, 0.1);
}
.pill--active {
  background: var(--c-blue);
  border-color: var(--c-blue);
  color: #fff;
}

/* Legend Section */
.legend-section {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
  padding: 1rem;
}
.legend-section__title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 0.75rem;
}
.legend-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.legend-item {
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}
.legend-item__color {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.sidebar__footer {
  margin-top: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* ================== MAIN CONTENT ================== */
.main-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 1.5rem 2rem;
  gap: 1.5rem;
  overflow-y: auto;
}

/* Page Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}
.page-header__title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.page-header__subtitle {
  color: var(--text-muted);
  font-size: 0.9375rem;
}
.page-header__research-q {
  color: var(--c-cyan);
  font-size: 0.875rem;
  font-style: italic;
  margin-top: 0.25rem;
}
.page-header__controls {
  display: flex;
  gap: 1.5rem;
}
.align-control {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}
.align-control__label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
}

/* Segmented Control */
.seg-control {
  display: flex;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
}
.seg-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.seg-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}
.seg-btn--active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

/* Stage Labels Bar */
.stage-labels {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
}
.stage-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.stage-label__num {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: var(--font-display);
  font-weight: 700;
}
.stage-label__name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Chart Card */
.chart-card {
  flex: 1;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

.chart-loader {
  position: absolute;
  inset: 0;
  background: rgba(21, 28, 46, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 20;
  gap: 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  transition: opacity 0.3s;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--c-cyan);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

.chart-wrapper {
  flex: 1;
  width: 100%;
  height: 100%;
  padding: 1rem;
}
.chart-wrapper svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Bottom Mini-Stats */
.mini-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}
.mini-stat {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.mini-stat__icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mini-stat__icon svg {
  width: 20px;
  height: 20px;
}
.ms-cyan { background: rgba(56, 189, 248, 0.1); color: var(--c-cyan); }
.ms-rose { background: rgba(251, 113, 133, 0.1); color: var(--c-rose); }
.ms-emerald { background: rgba(52, 211, 153, 0.1); color: var(--c-emerald); }
.ms-amber { background: rgba(251, 191, 36, 0.1); color: var(--c-amber); }

.mini-stat__label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
  margin-bottom: 0.125rem;
}
.mini-stat__value {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
}

/* ================== D3 SVG STYLES ================== */
.node-rect {
  cursor: pointer;
  transition: opacity 0.2s;
}
.node-rect:hover {
  filter: brightness(1.2);
}
.node-label {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  fill: var(--text-main);
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
.link-path {
  cursor: pointer;
  transition: stroke-opacity 0.2s, stroke-width 0.2s;
}
.link-path:hover {
  stroke-opacity: 0.85 !important;
}

/* Hover effects */
.chart-wrapper.dimming .node-rect {
  opacity: 0.2;
}
.chart-wrapper.dimming .node-rect.highlight {
  opacity: 1;
}
.chart-wrapper.dimming .link-path {
  stroke-opacity: 0.05 !important;
}
.chart-wrapper.dimming .link-path.highlight {
  stroke-opacity: 0.75 !important;
}

/* ================== TOOLTIP ================== */
.tooltip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s, transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  will-change: transform;
}
.tooltip.show {
  opacity: 1;
}
.tooltip__inner {
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  color: var(--text-main);
  min-width: 200px;
}
.tooltip-header {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9375rem;
  margin-bottom: 0.375rem;
  padding-bottom: 0.375rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.tooltip-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}
.tooltip-label {
  color: var(--text-muted);
}
.tooltip-value {
  font-weight: 600;
}
