:root {
  --border: #d8dde3;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7684;
  --accent: #2f7fe0;
  --accent-dark: #1f5fae;
  --danger: #d0342c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", "Helvetica Neue", Arial, "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

/* ---------- top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

#brand { font-weight: 600; font-size: 15px; white-space: nowrap; }

#query-bar { display: flex; gap: 8px; flex: 1; }

select, button {
  font: inherit;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

select:focus, button:focus { outline: 2px solid #bcd6f5; }

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button:hover { border-color: var(--accent); }

/* ---------- layout ---------- */
#layout {
  display: grid;
  grid-template-columns: 340px 1fr 480px;
  grid-template-rows: minmax(380px, 58vh) minmax(220px, 1fr);
  gap: 8px;
  padding: 8px;
  height: calc(100vh - 50px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#panel-association { grid-row: 1 / 3; }
#panel-center { grid-column: 2; grid-row: 1; position: relative; }
#panel-journals { grid-column: 3; grid-row: 1 / 3; }
#panel-info { grid-column: 2; grid-row: 2; }

.panel-title {
  padding: 8px 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}

/* ---------- association panel ---------- */
#assoc-metrics { display: flex; gap: 6px; padding: 8px 12px 0; }
.metric-btn { font-size: 12px; padding: 3px 8px; }
.metric-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

#dumbbell-container { flex: 1; overflow-y: auto; padding: 4px 6px; }
#dumbbell-container svg { display: block; }

#assoc-legend {
  display: flex;
  gap: 14px;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.dot { border-radius: 50%; display: inline-block; }
.dot.big { width: 12px; height: 12px; background: #888; }
.dot.small { width: 8px; height: 8px; background: #3366cc; }

.db-row-label { cursor: pointer; }
.db-row-label.excluded { text-decoration: line-through; opacity: 0.45; }

/* ---------- center panel ---------- */
.tab-row {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  padding: 4px 8px 0;
}

.tab {
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 5px 5px 0 0;
  background: #eef1f4;
  padding: 5px 14px;
}
.tab.active { background: #fff; font-weight: 600; }
.tab-action { margin-left: auto; border-radius: 5px 5px 0 0; background: #eef1f4; }

.center-view { flex: 1; min-height: 0; position: relative; }
#network-container svg, #analysis-container svg { display: block; }

#direction-legend {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 10px;
  font-size: 12px;
  max-width: 240px;
}
#direction-legend .legend-item { margin: 2px 0; }
#direction-legend .swatch {
  width: 12px; height: 12px; border-radius: 3px; display: inline-block; margin-right: 6px;
}

.hull { stroke-linejoin: round; }
.net-link { stroke: #a9a9a9; stroke-width: 1.4px; cursor: pointer; }
.net-link.strong { stroke: var(--danger); stroke-width: 3.5px; }
.net-link.dimmed { opacity: 0.15; }
.net-node { cursor: pointer; stroke: #696969; stroke-width: 1.5px; }
.net-node.selected { stroke: var(--danger); stroke-width: 3.5px; }
.net-node.dimmed { opacity: 0.25; }
.net-label { font-size: 11px; pointer-events: none; fill: #333; }
.net-label.dimmed { opacity: 0.25; }

/* ---------- sankey panel ---------- */
#sankey-container { flex: 1; overflow-y: auto; padding: 4px; }
#sankey-container svg { display: block; }
.sankey-link { cursor: pointer; }
.sankey-link.dimmed { stroke: #dce8f3; stroke-opacity: 0.9; }
.sankey-node-label { font-size: 11px; cursor: pointer; }
.sankey-header { font-size: 12px; font-weight: 600; }

/* ---------- info panel ---------- */
.info-view { flex: 1; overflow: auto; min-height: 0; }

table.papers {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
table.papers th, table.papers td {
  border-bottom: 1px solid var(--border);
  padding: 5px 8px;
  text-align: left;
  vertical-align: top;
}
table.papers th { position: sticky; top: 0; background: #fafbfc; z-index: 1; }
table.papers tr:hover td { background: #f2f7fd; }

.author-chip {
  display: inline-block;
  padding: 0 6px;
  margin: 1px 2px;
  border-radius: 8px;
  color: #fff;
  font-size: 11.5px;
  white-space: nowrap;
}

#info-author, #info-journal { padding: 10px 14px; }
/* one row, horizontally scrollable, so no widget is ever clipped vertically */
.info-grid { display: flex; flex-wrap: nowrap; gap: 12px; align-items: stretch; overflow-x: auto; }
.info-block { border: 1px solid var(--border); border-radius: 6px; padding: 8px; flex-shrink: 0; }
.info-block h4 { margin: 0 0 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.info-meta { line-height: 1.8; }
.info-meta b { font-size: 16px; }
.placeholder { color: var(--muted); padding: 14px; }

/* ---------- fullscreen modal ---------- */
#fullscreen-modal {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 50;
  display: flex;
  flex-direction: column;
}
#fullscreen-modal[hidden] { display: none; }
#fs-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
#fs-body { flex: 1; display: flex; gap: 8px; padding: 8px; min-height: 0; }
.fs-side {
  width: 300px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-y: auto;
  flex-shrink: 0;
}
#fs-network {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-width: 0;
}
#fs-papers-list, #fs-strong-list { padding: 8px 12px; font-size: 12.5px; }
.fs-paper { border-bottom: 1px solid var(--border); padding: 6px 0; }
.fs-paper .meta { color: var(--muted); font-size: 11.5px; }
.strong-link-item { padding: 5px 0; border-bottom: 1px solid var(--border); }
.strong-link-item button { float: right; font-size: 11px; padding: 1px 6px; }

/* ---------- context menu / tooltip ---------- */
#context-menu {
  position: fixed;
  z-index: 100;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 5px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
  min-width: 190px;
}
#context-menu li { padding: 7px 16px; cursor: pointer; }
#context-menu li:hover { background: var(--accent); color: #fff; }

#tooltip {
  position: fixed;
  z-index: 90;
  background: rgba(30, 36, 44, 0.92);
  color: #fff;
  padding: 6px 9px;
  border-radius: 4px;
  font-size: 12px;
  pointer-events: none;
  max-width: 320px;
}

/* ---------- responsive fallback ---------- */
@media (max-width: 1200px) {
  #layout {
    grid-template-columns: 300px 1fr;
    grid-template-rows: minmax(340px, 50vh) minmax(300px, auto) minmax(220px, auto);
    height: auto;
  }
  #panel-association { grid-row: 1 / 3; }
  #panel-journals { grid-column: 2; grid-row: 2; }
  #panel-info { grid-column: 1 / 3; grid-row: 3; }
}
