:root {
  --bg: #f9f9f9;
  --text: #222;
  --primary: #4A90E2;
  --secondary: #f0f0f0;
  --hover: #e0e0e0;
  --accent: #7ED321;
  --panel-bg: #ffffff;
  --panel-border: #eeeeee;
  --shadow: 0 2px 8px rgba(0, 0, 0, .04);
  --shadow-strong: 0 4px 14px rgba(0, 0, 0, .08);
  --toggle-bg: #f5f7fb;
  --toggle-border: #e6e8ef;
  --toggle-active-bg: #4A90E2;
  --toggle-active-text: #fff;
  --toggle-shadow: 0 2px 6px rgba(0, 0, 0, .06);
  --focus: 0 0 0 3px rgba(74, 144, 226, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.content-container { max-width: 1200px; margin: 0 auto; padding-left: 40px; padding-right: 20px; }

header {
  background: #fff;
  border-bottom: 1px solid #eee;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .05);
  position: sticky; top: 0; z-index: 100;
}

.header-content { display: flex; align-items: center; justify-content: space-between; padding: 16px 0; }
.site-name { font-size: 20px; font-weight: 700; }

.nav-menu { list-style: none; display: flex; gap: 20px; margin: 0; padding: 0; }
.nav-menu a { text-decoration: none; color: #000; font-weight: 500; }
.nav-menu a:hover, .nav-menu a.active { color: #d90c1a; }

.intro-flex { display: flex; align-items: flex-start; gap: 32px; max-width: 1200px; margin: 40px auto 20px auto; padding: 0 20px; }
.intro-image { width: 200px; height: auto; border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,.1); margin-top: .5em; flex-shrink: 0; }
.intro-text-block { flex: 1; padding-left: 20px; max-width: 800px; }
h1.left-aligned { font-size: 26px; margin: 0 0 20px 0; }
#description { font-size: 15px; line-height: 1.5; color: #000; }
#description p { margin: 10px 0 14px 0; }

.viz-wrap { max-width: 1200px; margin: 20px auto; padding: 0 20px 20px; }
.panel { background: var(--panel-bg); border: 1px solid var(--panel-border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); transition: box-shadow .2s ease; }
.panel:hover { box-shadow: var(--shadow-strong); }
.panel h2 { font-size: 18px; margin: 0 0 10px 0; line-height: 1.3; }
.panel-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }

.controls { display: flex; gap: 10px; margin-bottom: 15px; flex-wrap: wrap; }
.control-btn { padding: 8px 12px; border: 1px solid var(--panel-border); background: var(--secondary); border-radius: 6px; cursor: pointer; font-size: 14px; transition: all .2s ease; font-family: inherit; }
.control-btn:hover { background: var(--hover); transform: translateY(-1px); }
.control-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.control-btn[data-g="female"].active { background: #f5438a; border-color: #f5438a; color: #222; }
.control-btn[data-g="male"].active   { background: #40c0ea; border-color: #40c0ea; color: #222; }
.control-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.chart-and-table {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 16px;
  align-items: stretch;
  min-height: 360px;
}
@media (max-width: 1100px) {
  .chart-and-table { grid-template-columns: 1fr; }
}

#viz { width: 100%; height: min(84vh, 1200px); display: block; border-radius: 10px; }

.side-panel {
  background: #fff;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 280px;
}
.side-header {
  display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--panel-border);
}
.side-title { font-weight: 700; font-size: 15px; }
.side-count-badge {
  background: #eff3fb; border: 1px solid #dee5f4; padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: 12px;
}
.side-sub {
  padding: 10px 14px 0 14px; color: #6b7280; font-size: 13px;
}
.side-table-wrap { padding: 8px 12px 12px 12px; overflow: auto; max-height: 60vh; }
.side-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; }
.side-table thead th {
  position: sticky; top: 0; background: #fafbff; border-bottom: 1px solid var(--panel-border); text-align: left; padding: 6px 6px; font-weight: 700;
}
.side-table tbody td { padding: 5px 6px; border-bottom: 1px dashed #eef1f5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-table tbody tr:hover { background: #f7fafc; }
.row-highlight { outline: 2px solid #d1e3ff; outline-offset: -2px; }

.legend-container { margin-top: 18px; margin-bottom: 20px; padding: 15px; background: #fafafa; border-radius: 8px; border: 1px solid var(--panel-border); }
.mb-legend { display: flex; gap: 10px; align-items: center; padding: 8px 0; color: #6c7591; }
.mb-legend .lg::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 6px; border-radius: 50%; border: 1px solid #223047; }
.mb-legend .gender-f::before { background: #f5438a; }
.mb-legend .gender-m::before { background: #40c0ea; }
.mb-legend .gender-u::before { background: #9aa6bf; }
.mb-legend .gender-o::before { background: #f5c06d; }

.tooltip {
  position: absolute;
  background: rgba(0,0,0,.92);
  color: #fff;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s ease;
  z-index: 1000;
  max-width: 420px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.tooltip strong { color: #fff; display: block; margin-bottom: 4px; }
.tooltip .tt-row { white-space: nowrap; }
.tooltip .tt-row strong { display: inline; margin: 0; }
.tooltip.show { opacity: 1; }

#btn-clear-multi {
  margin-left: 60px;
  position: relative;
}
#btn-clear-multi::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: var(--panel-border);
}

.cluster-label {
  fill: #223047;
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  pointer-events: none;
}
.cluster-label.button {
  pointer-events: all;
  cursor: pointer;
  user-select: none;
}
.cluster-label.button:hover {
  fill: #4A90E2;
}
.cluster-label.active {
  fill: #4A90E2;
  font-weight: 700;
}

.node-circle { stroke: #223047; stroke-width: 1.1px; opacity: .95; vector-effect: non-scaling-stroke; }
.node-circle.female { fill: #f5438a; }
.node-circle.male   { fill: #40c0ea; }
.node-circle.unknown{ fill: #9aa6bf; }
.node-circle.highlight { fill: #fff !important; stroke-width: 1.6px; opacity: 1; }

.connector-line {
  stroke: #CDD3DE;
  stroke-width: 0.8px;
  vector-effect: non-scaling-stroke;
  pointer-events: stroke;
  shape-rendering: geometricPrecision;
  opacity: .9;
  transition: stroke-width .12s ease, opacity .12s ease, stroke .12s ease;
}
.connector-line:hover { stroke-width: 2px; opacity: 1; stroke: #808A9A; }
.connector-line--emph { stroke-width: 2.2px; stroke: #fa2003; opacity: 1; }
.connector-line--dim  { opacity: .25; }

.center-node {
  fill: #ffffff;
  stroke: #223047;
  stroke-width: 1.2px;
  r: 4;
  pointer-events: auto;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.08));
  transition: transform .2s ease, opacity .2s ease, stroke-width .12s ease;
}
.center-node:hover { stroke-width: 1.6px; }

footer { margin-top: auto; padding: 20px 0; text-align: center; color: #666; font-size: 14px; }

@media (max-width: 700px) {
  .panel-top { flex-direction: column; align-items: flex-start; gap: 6px; }
  #description { font-size: 14px; }
  .intro-flex { flex-direction: column; margin: 40px auto 10px auto; }
  .intro-image { width: 150px; margin: 0 auto; }
  .intro-text-block { padding-left: 0; }
  .viz-wrap { margin: 10px auto 20px auto; }
  .controls { justify-content: center; }
  .control-btn { font-size: 13px; padding: 6px 10px; }
}

.side-panel { border-radius: 10px; }
.side-header { padding: 10px 12px; }
.side-title  { font-size: 14px; }
.side-count-badge { font-size: 11px; padding: 1px 8px; }
.side-sub { font-size: 12px; padding: 8px 12px 0 12px; }
.side-table-wrap { padding: 6px 10px 10px 10px; }

.side-table thead th:nth-child(3),
.side-table tbody td:nth-child(3) {
  display: none;
}
