

:root {
  --bg: #0e1116;
  --panel-bg: rgba(20, 24, 32, 0.92);
  --panel-border: #2a3140;
  --text: #e6e9ef;
  --text-dim: #9aa3b2;
  --accent: #4ea1ff;
  --accent-dim: rgba(78, 161, 255, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  overflow: hidden;
}

/* ── Tab panes ────────────────────────────────────────────────────────── */
.view {
  position: absolute;
  inset: 0;
  display: none;
}
.view.active { display: block; }

#sigma-container {
  position: absolute;
  inset: 0;
}
/* ── Quick jump search results ────────────────────────────────────────── */
#search-results {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  background: #161a22;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
}
#search-results li {
  padding: 6px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--panel-border);
  font-size: 12px;
  line-height: 1.3;
}
#search-results li:last-child { border-bottom: none; }
#search-results li:hover { background: #1f2530; }
#search-results .meta {
  color: var(--text-dim);
  font-size: 11px;
  margin-top: 2px;
}
/* ── Controls hide/show ──────────────────────────────────────────────── */
#controls-toggle.icon-btn {
  position: sticky;
  top: 0;
  float: right;
  margin: -6px -6px 8px 8px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #161a22;
  color: var(--text);
  border: 1px solid var(--panel-border);
  cursor: pointer;
  font-size: 16px;
  line-height: 28px;
  text-align: center;
  padding-bottom: 1px;
}

#controls-toggle.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#controls.collapsed {
  width: 44px;
  padding: 10px;
  overflow: hidden;
}
#controls.collapsed *:not(#controls-toggle) {
  display: none !important;
}
#controls.collapsed #controls-toggle {
  display: block !important;
  float: none;
  margin: 0;
}
/* ── Cluster centroid labels ─────────────────────────────────────────── */
#cluster-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.cluster-label {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 3px 8px;
  border-radius: 12px;
  background: rgba(14, 17, 22, 0.65);
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.2px;
  white-space: nowrap;
  pointer-events: auto;
  cursor: help;
  user-select: none;
  border: 1px solid transparent;
  transition: background 120ms, border-color 120ms;
}
.cluster-label:hover {
  background: rgba(14, 17, 22, 0.92);
  border-color: var(--accent-dim);
}
.cluster-label .swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

/* ── Panels (controls + detail + table) ───────────────────────────────── */
.panel {
  position: absolute;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 14px 16px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

#controls {
  top: 16px;
  left: 16px;
  width: 340px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

#controls h1 {
  margin: 0 0 2px;
  font-size: 16px;
  font-weight: 600;
}
.subtitle {
  margin: 0;
  color: var(--text-dim);
  font-size: 11px;
}

/* header line in controls */
#controls .topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
#controls .titleblock {
  min-width: 0;
}
#controls .titleblock h1,
#controls .titleblock .subtitle {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* tabs */
#controls .tabs {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
#controls .tab {
  background: #161a22;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
#controls .tab.active {
  border-color: var(--accent);
  color: var(--accent);
}

.selected-count {
  margin: 10px 0 10px;
  color: var(--text);
  font-weight: 600;
}

/* primary filter button */
#apply-filters.primary {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: var(--accent);
  color: #0e1116;
  font-weight: 700;
  cursor: pointer;
}
#apply-filters.primary:hover { filter: brightness(1.05); }

/* Global filter inputs */
#controls input[type="search"] {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: #161a22;
  color: var(--text);
  font-size: 13px;
  outline: none;
  margin-top: 6px;
}
#controls input[type="search"]:focus { border-color: var(--accent); }

.control-row {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.control-row label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.control-row select {
  padding: 5px 8px;
  background: #161a22;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  font-size: 12px;
}
.control-row input[type="range"] {
  width: 100%;
}

.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}
.checkbox-row label {
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

details.legend-wrap, details.about {
  margin-top: 12px;
  border-top: 1px solid var(--panel-border);
  padding-top: 8px;
}
details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 0;
}
details[open] summary {
  color: var(--text);
}
details.about p {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
  margin: 6px 0;
}

#legend {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}
#legend li {
  display: flex;
  align-items: center;
  padding: 3px 4px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
}
#legend li:hover { background: #1f2530; }
#legend li.muted { opacity: 0.35; }
#legend .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 8px;
  flex-shrink: 0;
}

/* ── Detail panel ────────────────────────────────────────────────────── */
#detail {
  top: 16px;
  right: 16px;
  width: 360px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}
#detail-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}
#detail-close:hover { color: var(--text); }
#detail h2 {
  margin: 0 0 6px;
  font-size: 14px;
  line-height: 1.3;
  padding-right: 22px;
}
#detail .meta {
  color: var(--text-dim);
  font-size: 11px;
  margin-bottom: 8px;
}
#detail .cluster-tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 8px;
}
#detail .abstract {
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
  margin-top: 8px;
  white-space: pre-wrap;
}
#detail .actions {
  display: flex;
  gap: 6px;
  margin: 10px 0 4px;
  flex-wrap: wrap;
}
#detail .actions button,
#detail .actions a {
  background: #1f2530;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  padding: 5px 10px;
  font-size: 11px;
  cursor: pointer;
  text-decoration: none;
}
#detail .actions button:hover,
#detail .actions a:hover { border-color: var(--accent); color: var(--accent); }
#detail h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin: 14px 0 4px;
}
#detail ul.top-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
#detail ul.top-list li {
  padding: 4px 0;
  font-size: 12px;
  border-bottom: 1px solid var(--panel-border);
  line-height: 1.4;
}
#detail ul.top-list li:last-child { border-bottom: none; }
#detail ul.top-list .sub {
  color: var(--text-dim);
  font-size: 11px;
}

/* ── Hover tooltip ───────────────────────────────────────────────────── */
#tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(14, 17, 22, 0.95);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px 10px;
  max-width: 320px;
  font-size: 12px;
  line-height: 1.4;
  z-index: 1000;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
#tooltip strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
  font-weight: 600;
}
#tooltip .tt-meta {
  color: var(--text-dim);
  font-size: 11px;
}

/* ── Table view ───────────────────────────────────────────────────────── */
#table-wrap {
  top: 16px;
  left: 16px;
  right: 16px;
  bottom: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.table-filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.table-filter-row select,
.table-filter-row input,
.table-filter-row button {
  background: #161a22;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
}
.table-filter-row input {
  flex: 1;
  min-width: 160px;
}
.table-filter-row button {
  cursor: pointer;
}
.table-filter-row button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#papers-table {
  flex: 1;
  min-height: 0;
}

/* ── Loading overlay ─────────────────────────────────────────────────── */
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text-dim);
  font-size: 14px;
  z-index: 2000;
  transition: opacity 400ms;
}
#loading.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ── Legend buttons ──────────────────────────────────────────────────── */
.legend-btn-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.legend-btn-row button {
  flex: 1;
  padding: 6px 10px;
  background: #161a22;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  transition: border-color 120ms, color 120ms;
}

.legend-btn-row button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

