/* ============================================================
   DyNetVis — canvas-first design tokens
   ============================================================ */
:root {
  --bg:           #fafaf8;
  --text:         #1a1a1a;
  --muted:        #737370;
  --muted-2:      #a8a8a3;
  --border:       #e5e5e0;
  --border-soft:  #f0efe9;
  --hover:        #f5f4ee;
  --accent:       #e85a3a;
  --accent-soft:  rgba(232,90,58,0.16);
  --accent-shadow:0 2px 8px rgba(232,90,58,0.25);

  --glass-bg:     rgba(255,255,255,0.86);
  --glass-blur:   blur(14px);
  --glass-border: rgba(229,229,224,0.95);
  --glass-shadow: 0 4px 20px rgba(26,26,26,0.05), 0 1px 2px rgba(26,26,26,0.04);

  --viz-bg:       #fafaf8;
  --node-stroke:  #1a1a1a;
  --edge:         #737370;

  --r-panel: 12px;
  --r-btn:    7px;
  --r-input:  6px;
  --r-chip:   4px;

  --font-ui:   'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}

[data-theme="dark"] {
  --bg:           #15171b;
  --text:         #ececec;
  --muted:        #9aa0a8;
  --muted-2:      #6c727a;
  --border:       #2a2e36;
  --border-soft:  #1f2229;
  --hover:        #1f242c;
  --accent:       #e85a3a;
  --accent-soft:  rgba(232,90,58,0.20);

  --glass-bg:     rgba(29,32,38,0.85);
  --glass-border: rgba(54,58,68,0.9);
  --glass-shadow: 0 4px 20px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.2);

  --viz-bg:       #14161a;
  --node-stroke:  #ececec;
  --edge:         #aaa;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%; width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  overflow: hidden;
}

#root { position: relative; height: 100vh; width: 100vw; }

/* ============================================================
   Canvas (full bleed)
   ============================================================ */
#viz {
  position: absolute; inset: 0;
  background: var(--viz-bg);
  overflow: hidden;
}
#viz svg, #viz canvas { display: block; }

#viz svg .nl-node      { stroke: var(--node-stroke); stroke-width: 1; }
#viz svg .nl-link      { stroke: var(--edge); }
#viz svg .msv-axis text, #viz svg .msv-label { fill: var(--text); }
#viz svg .msv-cursor   { stroke: var(--accent); }
#viz svg .nl-node.selected { stroke: var(--accent); stroke-width: 2.5; }
#viz svg .nl-node.dimmed   { opacity: 0.18; }
#viz svg .nl-link.selected { stroke: var(--accent); stroke-opacity: 0.95 !important; }
#viz svg .nl-link.dimmed   { stroke-opacity: 0.05 !important; }

/* ============================================================
   Chrome — floating panels
   ============================================================ */
#chrome { position: absolute; inset: 0; pointer-events: none; }
#chrome > * { pointer-events: auto; }

.glass {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-panel);
  box-shadow: var(--glass-shadow);
}

.cluster {
  position: absolute;
  display: flex; align-items: center; gap: 2px;
  padding: 5px;
}
.cluster.vertical { flex-direction: column; padding: 4px; }

.divider  { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.v-divider{ height: 1px; width: 22px; background: var(--border); margin: 4px 0; }

/* ---------- top bar (single row glass strip) ---------- */
.topbar {
  position: absolute; top: 14px; left: 14px; right: 14px;
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 8px; padding: 0 6px 0 4px; }
.brand-text { font-weight: 600; letter-spacing: -0.01em; font-size: 14px; white-space: nowrap; }
.brand-text .accent { color: var(--accent); }
.brand-mark { width: 22px; height: 22px; color: var(--text); }

.v-sep  { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

.seg { display: flex; align-items: center; gap: 2px; }

/* Toggles only meaningful in the MSV view (TAM, CNO edge filter). */
.msv-only { display: none; }
[data-view="msv"] .msv-only { display: flex; }

.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  font-size: 11px; color: var(--muted);
  font-family: var(--font-mono);
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: #2aa876; }
.status-dot.busy { background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

/* ---------- buttons ---------- */
.tool-btn {
  min-width: 34px; height: 32px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
  border: none; border-radius: var(--r-btn);
  cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-family: inherit;
  transition: background .12s, color .12s;
}
.tool-btn:hover { background: var(--hover); color: var(--text); }
.tool-btn.active { background: var(--text); color: var(--bg); }
.tool-btn.active:hover { background: var(--text); color: var(--bg); }
.tool-btn .icon { font-size: 13px; line-height: 1; }
.tool-btn .label { font-size: 12px; font-weight: 500; }
.tool-btn .meta  { color: var(--muted-2); font-size: 11px; }
.tool-btn .chev  { color: var(--muted-2); font-size: 9px; }

.icon-btn {
  width: 30px; height: 30px;
  border: none; background: transparent;
  color: var(--muted); cursor: pointer;
  border-radius: var(--r-btn); font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.kbd {
  font-family: var(--font-mono);
  font-size: 10px; padding: 2px 6px;
  background: var(--hover); border: 1px solid var(--border);
  border-radius: var(--r-chip); color: var(--muted);
}

/* ---------- right drawer (compact legend) ---------- */
.drawer {
  position: absolute;
  top: 76px; right: 14px; bottom: 116px;
  width: 200px;
  padding: 8px 10px;
  display: flex; flex-direction: column;
  z-index: 15;
  overflow: hidden;
  transition: width .12s ease, padding .12s ease;
}
.drawer.collapsed { width: 26px; padding: 8px 4px; }
.drawer.collapsed .drawer-body { display: none; }
.drawer.collapsed #drawer-title { display: none; }
.drawer.collapsed .drawer-head { justify-content: center; padding-bottom: 0; border-bottom: 0; }
.drawer.collapsed #drawer-reset { display: none; }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  font-size: 10px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted-2);
  padding-bottom: 6px; border-bottom: 1px solid var(--border-soft);
}
.drawer-head .link {
  font-size: 11px; color: var(--muted); text-transform: none; letter-spacing: 0;
  cursor: pointer; padding: 2px 4px; border-radius: 4px;
}
.drawer-head .link:hover { color: var(--text); background: var(--hover); }
.drawer-body { overflow-y: auto; flex: 1; padding-top: 6px; }

.drawer-palette {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 4px;
}
.drawer-palette .meta {
  font-size: 10px; color: var(--muted-2);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.drawer.collapsed .drawer-palette { display: none; }

.legend-row {
  display: flex; align-items: center; gap: 6px;
  padding: 2px 4px;
  border-radius: 3px;
  cursor: pointer; font-size: 11px;
  line-height: 1.4;
}
.legend-row:hover { background: var(--hover); }
.legend-row .label { flex: 1; }
.legend-row .count { color: var(--muted-2); font-family: var(--font-mono); font-size: 10px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; cursor: pointer; }

.legend-tam {
  margin-top: 12px; padding-top: 10px;
  border-top: 1px solid var(--border-soft);
  font-size: 11px;
}
.legend-tam-title {
  font-size: 10px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted-2);
  margin-bottom: 6px;
}
.legend-tam-bar {
  height: 12px;
  border-radius: 3px;
  /* Inferno gradient over the full range 0 → 1 (matches d3.interpolateInferno). */
  background: linear-gradient(to right,
    #000004 0%, #1b0c41 12%, #4a0c6b 24%, #781c6d 36%,
    #a52c60 48%, #cf4446 60%, #ed6925 72%, #fb9b06 84%,
    #f7d13d 92%, #fcfea4 100%);
  border: 1px solid var(--border);
}
.legend-tam-labels {
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--text);
  margin-top: 4px;
}
.legend-tam-labels .muted { color: var(--muted-2); }
.legend-tam-note {
  margin-top: 6px; font-size: 10px; color: var(--muted);
  line-height: 1.4;
}

/* ---------- bottom time bar ---------- */
.timebar {
  position: absolute; bottom: 14px; left: 14px; right: 14px;
  padding: 12px 18px 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center; gap: 16px;
  z-index: 25;
}
.play-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent); color: #fff;
  border: none; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--accent-shadow);
}

.scrub-area { position: relative; height: 50px; display: flex; flex-direction: column; justify-content: center; }
.scrub-track {
  position: relative; height: 36px;
  background: var(--hover); border-radius: var(--r-input);
  border: 1px solid var(--border);
  overflow: hidden; cursor: pointer;
}
.scrub-density {
  position: absolute; inset: 0;
  opacity: 0.55;
}
.scrub-window {
  position: absolute; top: 1px; bottom: 1px;
  background: var(--accent-soft);
  border-left: 1.5px solid var(--accent);
  border-right: 1.5px solid var(--accent);
  border-radius: 3px;
  pointer-events: none;
}
.scrub-playhead {
  position: absolute; top: -4px; bottom: -4px;
  width: 3px; background: var(--text);
  border-radius: 2px;
  box-shadow: 0 0 0 3px rgba(26,26,26,0.08);
  transform: translateX(-50%);
  z-index: 4;
}
.scrub-labels {
  display: flex; justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px; color: var(--muted-2);
  margin-top: 4px;
}

.time-readout {
  font-family: var(--font-mono);
  font-size: 12px; color: var(--text);
  display: flex; flex-direction: column; align-items: flex-end; gap: 3px;
  min-width: 130px;
}
.time-readout .now { font-size: 14px; font-weight: 600; }
.time-readout .sub { color: var(--muted-2); font-size: 10px; }

.timebar-stack {
  display: flex; flex-direction: column; gap: 3px; font-size: 11px; align-items: flex-end;
}

/* ---------- popovers ---------- */
.popover-scrim { position: absolute; inset: 0; z-index: 90; }
.popover {
  position: absolute; min-width: 200px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(26,26,26,0.18);
  padding: 6px;
  z-index: 91;
  display: flex; flex-direction: column;
  max-height: 60vh; overflow: auto;
}
.popover-section {
  font-size: 10px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted-2);
  padding: 8px 10px 4px;
}
.popover-item {
  padding: 8px 10px;
  display: flex; align-items: center; gap: 10px;
  border-radius: 6px;
  cursor: pointer; font-size: 13px;
  color: var(--text);
}
.popover-item:hover { background: var(--hover); }
.popover-item.active { background: var(--hover); font-weight: 600; }
.popover-item .meta { margin-left: auto; color: var(--muted-2); font-family: var(--font-mono); font-size: 11px; }
.popover-item .chip { width: 14px; height: 14px; border-radius: 3px; }
.popover-divider { height: 1px; background: var(--border-soft); margin: 4px 0; }

.popover-row {
  padding: 6px 10px;
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--text);
}
.popover-row label { color: var(--muted); min-width: 60px; }
.popover-row input[type=range] { flex: 1; }

/* ---------- inspector ---------- */
.inspector {
  position: absolute; width: 240px;
  padding: 14px 16px;
  z-index: 18;
}
.insp-head {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 10px; border-bottom: 1px solid var(--border-soft);
}
.insp-title { font-size: 13px; font-weight: 600; }
.insp-sub   { font-size: 11px; color: var(--muted); }
.insp-row {
  display: flex; justify-content: space-between;
  font-size: 11px; padding: 4px 0;
}
.insp-key { color: var(--muted); }
.insp-val { font-family: var(--font-mono); color: var(--text); }

/* ---------- stats modal ---------- */
.stats-scrim {
  position: absolute; inset: 0;
  background: rgba(26,26,26,0.35);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.stats-modal {
  width: min(1100px, 100%);
  max-height: 90vh;
  display: flex; flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
}
.stats-head {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--glass-bg);
}
.stats-title { font-weight: 600; font-size: 14px; }
.stats-sub   { font-size: 11px; color: var(--muted); font-family: var(--font-mono); }
.stats-tabs  { display: flex; gap: 2px; flex: 1; justify-content: center; }
.stats-tab {
  background: transparent; border: 1px solid transparent;
  padding: 6px 12px; border-radius: 6px; cursor: pointer;
  color: var(--muted); font-family: inherit; font-size: 12px;
}
.stats-tab:hover { color: var(--text); background: var(--hover); }
.stats-tab.active { color: var(--text); border-color: var(--border); background: var(--hover); }

.stats-status { padding: 4px 18px; font-size: 11px; color: var(--muted); }
.stats-body { padding: 16px 18px; overflow-y: auto; flex: 1; background: var(--bg); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  align-items: start;
}
.stats-card {
  background: var(--glass-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.stats-card h4 {
  margin: 0 0 8px; font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted-2);
}
.stats-card table { width: 100%; border-collapse: collapse; font-size: 12px; }
.stats-card td.k, .stats-card td.cls { color: var(--muted); }
.stats-card td.v   { text-align: right; font-family: var(--font-mono); color: var(--text); }
.stats-card td.rk  { color: var(--muted-2); font-family: var(--font-mono); width: 24px; }
.stats-card thead th {
  text-align: left; font-size: 10px; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted-2); padding: 4px 6px; border-bottom: 1px solid var(--border-soft);
}
.stats-card tbody td { padding: 3px 6px; border-bottom: 1px solid var(--border-soft); }
.stats-card tbody tr:last-child td { border-bottom: none; }
.stats-topk { grid-column: span 1; }
.stats-chart { display: flex; flex-direction: column; align-items: stretch; }
.stats-svg { width: 100%; height: auto; }
.stats-svg text { fill: var(--muted); }
.stats-svg .domain, .stats-svg line { stroke: var(--border); }
.stats-empty { color: var(--muted); font-size: 12px; padding: 12px; }

/* references tab */
.stats-refs {
  display: flex; flex-direction: column; gap: 18px;
  max-width: 920px;
}
.refs-section h3 {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted-2);
  padding-bottom: 6px; border-bottom: 1px solid var(--border-soft);
  margin-bottom: 8px;
}
.ref-item {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
}
.ref-item:last-child { border-bottom: none; }
.ref-line { font-size: 12px; line-height: 1.6; color: var(--text); }
.ref-authors { color: var(--text); }
.ref-title { font-weight: 500; }
.ref-venue { font-style: italic; color: var(--muted); }
.ref-year  { color: var(--muted); font-family: var(--font-mono); }
.ref-doi   { color: var(--accent); text-decoration: none; font-family: var(--font-mono); font-size: 11px; margin-left: 4px; }
.ref-doi:hover { text-decoration: underline; }
.ref-tags  { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.ref-tag {
  font-size: 10px; color: var(--muted);
  background: var(--hover); border: 1px solid var(--border);
  border-radius: 3px; padding: 1px 6px;
}

/* ---------- scrollbars ---------- */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: #d8d8d3; border-radius: 4px; }
*::-webkit-scrollbar-track { background: transparent; }
[data-theme="dark"] *::-webkit-scrollbar-thumb { background: #353a44; }
