/* ============================================================
   Citation Network Visualization Tool - Style Sheet
   鉄と鋼 引用ネットワーク
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  min-width: 1200px;
  font-family: "Segoe UI", "Helvetica Neue", Arial, "Noto Sans JP", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #e0e0e0;
  background: #1a1a2e;
  overflow: hidden;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: #16213e;
}
::-webkit-scrollbar-thumb {
  background: #4a4e69;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #6c7089;
}

/* --- Layout Grid --- */
#app-container {
  display: grid;
  grid-template-rows: auto 1fr 180px;
  grid-template-columns: 340px 1fr 0;
  grid-template-areas:
    "header   header   header"
    "sidebar  graph    right"
    "timeline timeline timeline";
  height: 100vh;
  width: 100%;
  transition: grid-template-columns 0.25s ease;
}

#app-container.detail-open {
  grid-template-columns: 340px 1fr 380px;
}

/* --- Header --- */
#header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  background: #16213e;
  border-bottom: 1px solid #2a2d4a;
  z-index: 100;
}

#header .title-group {
  display: flex;
  align-items: baseline;
  gap: 14px;
}

#header .title-group h1 {
  font-size: 18px;
  font-weight: 700;
  color: #f0f0f0;
  letter-spacing: 0.5px;
}

#header .title-group .subtitle {
  font-size: 12px;
  color: #8888aa;
}

#header .stats-bar {
  display: flex;
  gap: 20px;
  font-size: 12px;
  color: #9999bb;
}

#header .stats-bar .stat-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

#header .stats-bar .stat-value {
  font-weight: 600;
  color: #c0c0e0;
  font-size: 14px;
}

#header .stats-bar-global {
  font-size: 11px;
  color: #777799;
  opacity: 0.7;
  margin-top: 2px;
}

.reset-view-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  background: transparent;
  border: 1px solid #444466;
  border-radius: 4px;
  color: #9999bb;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.reset-view-btn:hover {
  background: #2a2d4a;
  color: #e0e0f0;
  border-color: #5b6abf;
}

/* --- Sidebar --- */
#sidebar {
  grid-area: sidebar;
  width: 340px;
  background: #16213e;
  border-right: 1px solid #2a2d4a;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  z-index: 50;
}

.sidebar-section {
  padding: 12px 16px;
  border-bottom: 1px solid #2a2d4a;
}

.sidebar-section:last-child {
  border-bottom: none;
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #7777aa;
  margin-bottom: 8px;
}

/* Collapsible sidebar sections */
[data-collapsible] > .sidebar-section-title {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
[data-collapsible] > .sidebar-section-title::after {
  content: '\25B2'; /* ▲ */
  font-size: 8px;
  transition: transform 0.2s ease;
  color: #5555aa;
}
[data-collapsible].collapsed > .sidebar-section-title {
  margin-bottom: 0;
}
[data-collapsible].collapsed > .sidebar-section-title::after {
  transform: rotate(180deg);
}
[data-collapsible].collapsed > *:not(.sidebar-section-title) {
  display: none;
}

/* Sidebar subsections (grouped controls inside a collapsible section) */
.sidebar-subsection {
  margin-bottom: 10px;
}
.sidebar-subsection:last-child {
  margin-bottom: 0;
}
.sidebar-sub-label {
  font-size: 10px;
  font-weight: 600;
  color: #6666aa;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Display Mode Selector */
.mode-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.mode-btn {
  padding: 7px 10px;
  font-size: 12px;
  color: #b0b0cc;
  background: #1e2545;
  border: 1px solid #2a2d4a;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  white-space: nowrap;
}

.mode-btn:hover {
  background: #252a50;
  border-color: #4a4e80;
}

.mode-btn.active {
  background: #2a3a6e;
  border-color: #5b6abf;
  color: #e0e0ff;
}

/* Size Basis Selector */
.size-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.size-btn {
  padding: 4px 10px;
  font-size: 11px;
  color: #a0a0c0;
  background: #1e2545;
  border: 1px solid #2a2d4a;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.size-btn:hover {
  background: #252a50;
}

.size-btn.active {
  background: #2a3a6e;
  border-color: #5b6abf;
  color: #d0d0ff;
}

/* Edge Filter Selector */
.edge-filter-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.edge-filter-btn {
  padding: 4px 10px;
  font-size: 11px;
  color: #a0a0c0;
  background: #1e2545;
  border: 1px solid #2a2d4a;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.edge-filter-btn:hover {
  background: #252a50;
}

.edge-filter-btn.active {
  background: #2a3a6e;
  border-color: #5b6abf;
  color: #d0d0ff;
}

.edge-filter-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.legend-line {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 1px;
  vertical-align: middle;
  margin-right: 6px;
}

/* Edge Type Badges (detail panel) */
.edge-type-badge {
  display: inline-block;
  padding: 0 5px;
  font-size: 9px;
  font-weight: 700;
  border-radius: 6px;
  letter-spacing: 0.3px;
  margin-left: 6px;
  vertical-align: middle;
}

.edge-type-badge.badge-extends {
  background: #ef444433;
  color: #ef4444;
  border: 1px solid #ef444455;
}

.edge-type-badge.badge-applies {
  background: #f59e0b33;
  color: #f59e0b;
  border: 1px solid #f59e0b55;
}

.edge-type-badge.badge-informed {
  background: #64748b33;
  color: #94a3b8;
  border: 1px solid #64748b55;
}

/* Chain Coherence (detail panel) */
.coherence-badge {
  display: inline-block;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 10px;
  letter-spacing: 0.3px;
}

.coherence-badge.coherence-ok {
  background: #22c55e33;
  color: #22c55e;
  border: 1px solid #22c55e55;
}

.coherence-badge.coherence-warn {
  background: #f59e0b33;
  color: #f59e0b;
  border: 1px solid #f59e0b55;
}

.coherence-badge.coherence-low {
  background: #ef444433;
  color: #ef4444;
  border: 1px solid #ef444455;
}

.coherence-detail {
  font-size: 11px;
  color: #8888aa;
  margin-left: 6px;
}

.coherence-warning {
  font-size: 11px;
  color: #f97316;
  margin-top: 4px;
}

/* Year Filter */
.year-filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.year-filter-label {
  font-size: 12px;
  color: #a0a0c0;
  flex-shrink: 0;
}
.year-filter-slider {
  flex: 1;
  min-width: 0;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #2a2d4a;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.year-filter-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #5b6abf;
  border: 2px solid #7b8adf;
  cursor: pointer;
  transition: background 0.15s;
}
.year-filter-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #5b6abf;
  border: 2px solid #7b8adf;
  cursor: pointer;
  transition: background 0.15s;
}
.year-filter-slider::-webkit-slider-thumb:hover {
  background: #7b8adf;
}
.year-filter-slider::-moz-range-thumb:hover {
  background: #7b8adf;
}
.year-filter-value {
  font-size: 12px;
  color: #e0e0e0;
  min-width: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.year-filter-value.inactive {
  color: #5a5a7a;
}
.year-filter-clear {
  background: transparent;
  border: 1px solid #2a2d4a;
  color: #8888aa;
  font-size: 14px;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.year-filter-clear:hover {
  background: #3a2020;
  border-color: #ef4444;
  color: #ef4444;
}

/* Visual Tuning */
.visual-tuning-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.visual-tuning-label {
  font-size: 11px;
  color: #a0a0c0;
  flex-shrink: 0;
  width: 72px;
}
.visual-tuning-row input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #2a2d4a;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.visual-tuning-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #5b6abf;
  border: 2px solid #7b8adf;
  cursor: pointer;
}
.visual-tuning-value {
  font-size: 11px;
  color: #d0d0e0;
  width: 24px;
  text-align: right;
  flex-shrink: 0;
}

/* Search */
#search-box {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  color: #e0e0e0;
  background: #1e2545;
  border: 1px solid #2a2d4a;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s;
}

#search-box::placeholder {
  color: #5a5a7a;
}

#search-box:focus {
  border-color: #5b6abf;
}

.search-results-count {
  font-size: 11px;
  color: #7777aa;
  margin-top: 4px;
}

/* Keyword Filter (Tag Cloud / Tree) */
.keyword-cloud {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 280px;
  overflow-y: auto;
}

/* Keyword toolbar */
.kw-toolbar {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-bottom: 4px;
  flex-shrink: 0;
}
.kw-search-input {
  flex: 1;
  padding: 3px 8px;
  font-size: 11px;
  color: #e0e0e0;
  background: #1e2545;
  border: 1px solid #2a2d4a;
  border-radius: 6px;
  outline: none;
  min-width: 0;
}
.kw-search-input:focus {
  border-color: #5b6abf;
}
.kw-search-input::placeholder {
  color: #5a5a7a;
}

/* Tree structure */
.kw-tree {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.kw-tree-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  font-size: 11px;
  font-weight: 600;
  color: #c0c0e0;
  cursor: pointer;
  border-radius: 4px;
  user-select: none;
}
.kw-tree-header:hover {
  background: #252a50;
}
.kw-tree-header.expanded {
  color: #e0e0f0;
}
.kw-tree-arrow {
  font-size: 9px;
  width: 10px;
  color: #8888aa;
}
.kw-tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kw-tree-badge {
  font-size: 9px;
  color: #8888aa;
  background: #1e2545;
  padding: 1px 5px;
  border-radius: 8px;
}
.kw-tree-children {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 2px 0 4px 8px;
}
.kw-tree-sub-header {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  font-size: 11px;
  color: #b0b0d0;
  cursor: pointer;
  border-radius: 4px;
  user-select: none;
}
.kw-tree-sub-header:hover {
  background: #252a50;
}
.kw-tree-sub-header.expanded {
  color: #d0d0f0;
}
.kw-tree-sub-header.selected {
  color: #fff;
  background: #3a3d6a;
}
.kw-tree-sub-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.kw-tree-sub-label:hover {
  text-decoration: underline;
}
.kw-tree-leaves {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 3px 4px 6px 20px;
}
.kw-tree-more-btn {
  font-size: 10px;
  color: #8888cc;
  background: none;
  border: 1px dashed #3a3d5a;
  border-radius: 10px;
  padding: 2px 8px;
  cursor: pointer;
}
.kw-tree-more-btn:hover {
  color: #aaaaee;
  border-color: #5555aa;
}

.keyword-tag {
  padding: 3px 9px;
  font-size: 11px;
  color: #a0a0c0;
  background: #1e2545;
  border: 1px solid #2a2d4a;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.keyword-tag:hover {
  background: #252a50;
  border-color: #4a4e80;
}

.keyword-tag.selected {
  background: #2d4a3e;
  border-color: #22c55e;
  color: #a0f0c0;
}

.keyword-clear-btn {
  padding: 3px 9px;
  font-size: 11px;
  color: #ef4444;
  background: transparent;
  border: 1px solid #ef444444;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.keyword-clear-btn:hover {
  background: #3a1a1a;
}

/* Generic (high-count) keyword tags */
.keyword-tag-generic {
  opacity: 0.5;
  border-style: dashed;
}
.keyword-tag-generic:hover {
  opacity: 0.8;
}

/* Show-all toggle for hidden generic keywords */
.keyword-show-all-btn {
  padding: 3px 9px;
  font-size: 10px;
  color: #8888aa;
  background: transparent;
  border: 1px solid #2a2d4a;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  text-align: center;
  margin-top: 4px;
}
.keyword-show-all-btn:hover {
  color: #c0c0e0;
  border-color: #4a4e80;
}

/* Set Default button */
.keyword-default-btn {
  padding: 3px 9px;
  font-size: 10px;
  color: #f59e0b;
  background: transparent;
  border: 1px solid #f59e0b44;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.keyword-default-btn:hover {
  background: #3a2e1a;
  border-color: #f59e0b;
}
.keyword-default-btn.saved {
  color: #22c55e;
  border-color: #22c55e44;
}

/* Keyword Picker (first visit) */
.keyword-picker-header {
  font-size: 12px;
  font-weight: 600;
  color: #c0c0e0;
  margin-bottom: 6px;
  width: 100%;
}
.keyword-picker-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 7px 12px;
  margin-bottom: 3px;
  background: #1e2545;
  border: 1px solid #2a2d4a;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
  color: inherit;
  font-family: inherit;
}
.keyword-picker-card:hover {
  background: #252a50;
  border-color: #22c55e;
}
.keyword-picker-name {
  font-size: 12px;
  color: #e0e0f0;
  font-weight: 500;
}
.keyword-picker-meta {
  font-size: 10px;
  color: #8888aa;
  white-space: nowrap;
  margin-left: 8px;
}
.keyword-picker-skip {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 4px;
  font-size: 10px;
  color: #6b7f96;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: center;
}
.keyword-picker-skip:hover {
  color: #c0c0e0;
  text-decoration: underline;
}

/* Curated Keyword Groups */
.kw-groups {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kw-group-category {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.kw-group-category-header {
  font-size: 10px;
  font-weight: 600;
  color: #8888aa;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 2px 0;
}
.kw-group-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.kw-group-chip {
  padding: 4px 10px;
  font-size: 11px;
  font-family: inherit;
  color: #b0b0d0;
  background: #1e2545;
  border: 1px solid #2a2d4a;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  white-space: nowrap;
}
.kw-group-chip:hover {
  background: #252a50;
  border-color: #4a4e80;
  color: #d0d0f0;
}
.kw-group-chip.selected {
  background: #1a3a2e;
  border-color: #22c55e;
  color: #a0f0c0;
  font-weight: 500;
}
.kw-group-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
}
.kw-group-selected-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 10px;
  color: #a0f0c0;
  background: #1a3a2e;
  border: 1px solid #22c55e66;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.kw-group-selected-pill:hover {
  background: #2a1a1a;
  border-color: #ef4444;
  color: #f0a0a0;
}

/* Sampling indicator (when node budget limits results) */
.sampling-indicator {
  color: #f59e0b;
}

/* Author Index */
.author-index {
  max-height: 240px;
  overflow-y: auto;
}

.author-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  font-size: 12px;
  color: #b0b0cc;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}

.author-item.author-dim {
  opacity: 0.5;
}
.author-item.author-dim:hover {
  opacity: 0.8;
}

.author-item:hover {
  background: #252a50;
}

.author-item .author-count {
  font-size: 10px;
  color: #6666aa;
  background: #1e2545;
  padding: 1px 6px;
  border-radius: 8px;
  flex-shrink: 0;
}

.author-show-more {
  display: block;
  width: 100%;
  padding: 4px 8px;
  background: transparent;
  border: none;
  color: #5b6abf;
  font-size: 11px;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s;
}
.author-show-more:hover {
  color: #8899ff;
}

.search-author-item {
  border-left: 3px solid #5b6abf;
}

/* --- Right Panel (Paper Detail) --- */
#right-panel {
  grid-area: right;
  background: #16213e;
  border-left: 1px solid #2a2d4a;
  overflow: hidden;
  width: 0;
  opacity: 0;
  transition: width 0.25s ease, opacity 0.2s ease;
  z-index: 50;
}

#app-container.detail-open #right-panel {
  width: 380px;
  opacity: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* --- Detail Panel --- */
#detail-panel {
  padding: 0;
}

#detail-panel .detail-header {
  padding: 12px 16px;
  background: #1a2040;
  border-bottom: 1px solid #2a2d4a;
}

#detail-panel .detail-close-btn {
  float: right;
  background: transparent;
  border: none;
  color: #8888aa;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s;
}

#detail-panel .detail-close-btn:hover {
  background: #2a2d4a;
  color: #e0e0e0;
}

#detail-panel .detail-title-en {
  font-size: 14px;
  font-weight: 700;
  color: #f0f0f0;
  margin-bottom: 4px;
  line-height: 1.4;
}

#detail-panel .detail-title-ja {
  font-size: 12px;
  color: #9999bb;
  line-height: 1.4;
}

/* --- Detail Panel Tabs --- */
.detail-tabs {
  display: flex;
  border-bottom: 1px solid #2a2d4a;
  background: #161a30;
  padding: 0 8px;
  gap: 2px;
}

.detail-tab {
  flex: 1;
  padding: 7px 0;
  border: none;
  background: transparent;
  color: #7777aa;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.detail-tab:hover {
  color: #b0b0dd;
}

.detail-tab.active {
  color: #e0e0ff;
  border-bottom-color: #5b6abf;
}

.detail-tab-content {
  display: none;
}

.detail-tab-content.active {
  display: block;
}

#detail-panel .detail-body {
  padding: 12px 16px;
}

.detail-field {
  margin-bottom: 12px;
}

.detail-field-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #6666aa;
  margin-bottom: 3px;
}

.detail-field-value {
  font-size: 12px;
  color: #c0c0e0;
  line-height: 1.5;
}

/* Journal + IF Tier Badge */
.journal-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tier-badge {
  display: inline-block;
  padding: 1px 8px;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  letter-spacing: 0.5px;
}

.tier-badge.tier-s-plus {
  background: #fb718533;
  color: #fb7185;
  border: 1px solid #fb718555;
}

.tier-badge.tier-s {
  background: #f59e0b33;
  color: #f59e0b;
  border: 1px solid #f59e0b55;
}

.tier-badge.tier-a {
  background: #22d3ee33;
  color: #22d3ee;
  border: 1px solid #22d3ee55;
}

.tier-badge.tier-b {
  background: #818cf833;
  color: #818cf8;
  border: 1px solid #818cf855;
}

.tier-badge.tier-c {
  background: #6b7f9633;
  color: #6b7f96;
  border: 1px solid #6b7f9655;
}

/* Citation Counts */
.citation-counts {
  display: flex;
  gap: 16px;
}

.citation-stat {
  text-align: center;
}

.citation-stat .stat-number {
  font-size: 20px;
  font-weight: 700;
  color: #e0e0ff;
}

.citation-stat .stat-label {
  font-size: 10px;
  color: #7777aa;
}

/* Keywords in detail */
.detail-keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.detail-keyword {
  padding: 2px 8px;
  font-size: 11px;
  color: #a0c0e0;
  background: #1e2f45;
  border-radius: 10px;
}

/* Reference Lists (cites / cited-by) */
.ref-list {
  list-style: none;
}

.ref-list li {
  padding: 5px 8px;
  font-size: 12px;
  color: #a0a0cc;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  border-left: 2px solid transparent;
  margin-bottom: 2px;
}

.ref-list li:hover {
  background: #252a50;
  border-left-color: #5b6abf;
  color: #d0d0ff;
}

/* OA Link */
.oa-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  color: #22c55e;
  background: #1a3a2a;
  border: 1px solid #22c55e44;
  border-radius: 6px;
  text-decoration: none;
  transition: all 0.2s;
}

.oa-link:hover {
  background: #224a34;
  border-color: #22c55e88;
}

/* --- Main Graph Area --- */
#graph-area {
  grid-area: graph;
  position: relative;
  background: #1a1a2e;
  overflow: hidden;
}

#network-container {
  width: 100%;
  height: 100%;
}

/* Legend Overlay (bottom-right) */
#graph-legend {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: #16213eee;
  border: 1px solid #2a2d4a;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 11px;
  z-index: 20;
  max-width: 220px;
}

#graph-legend .legend-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #7777aa;
  margin-bottom: 6px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
  color: #a0a0c0;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-size-row {
  gap: 4px;
}

/* Loading / Error Overlays */
#graph-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 30;
}

#graph-loading .spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #2a2d4a;
  border-top-color: #5b6abf;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#graph-loading .loading-text {
  font-size: 13px;
  color: #8888aa;
}

#graph-error {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 30;
  display: none;
}

#graph-error .error-icon {
  font-size: 32px;
  color: #ef4444;
  margin-bottom: 8px;
}

#graph-error .error-message {
  font-size: 13px;
  color: #cc8888;
  margin-bottom: 12px;
  max-width: 360px;
}

#graph-error .retry-btn {
  padding: 6px 18px;
  font-size: 12px;
  color: #e0e0e0;
  background: #2a3a6e;
  border: 1px solid #5b6abf;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

#graph-error .retry-btn:hover {
  background: #3a4a8e;
}

/* Bubble chart canvas overlay */
#bubble-chart-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  display: none;
}

/* --- Timeline Panel --- */
#timeline-panel {
  grid-area: timeline;
  height: 180px;
  background: #16213e;
  border-top: 1px solid #2a2d4a;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 24px;
  min-height: 24px;
  padding: 0 12px;
  background: #16213e;
  border-bottom: 1px solid #2a2d4a;
}

.timeline-header-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #7777aa;
}

.timeline-mode-btns { display: flex; gap: 4px; }

.tl-mode-btn {
  padding: 2px 8px;
  font-size: 11px;
  color: #a0a0c0;
  background: #1e2545;
  border: 1px solid #2a2d4a;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
}
.tl-mode-btn:hover { background: #252a50; }
.tl-mode-btn.active {
  background: #2a3a6e;
  border-color: #5b6abf;
  color: #d0d0ff;
}

#timeline-canvas {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: block;
}

#timeline-tooltip {
  position: absolute;
  display: none;
  background: #1a1a2eee;
  border: 1px solid #4a4e80;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11px;
  color: #d0d0e0;
  pointer-events: none;
  z-index: 40;
  max-width: 280px;
  white-space: nowrap;
}

#timeline-panel.collapsed { height: 24px !important; }
#timeline-panel.collapsed #timeline-canvas,
#timeline-panel.collapsed #timeline-tooltip { display: none; }
#app-container.timeline-hidden { grid-template-rows: auto 1fr 24px; }

/* --- Utility Classes --- */
.hidden {
  display: none !important;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Transitions --- */
.fade-in {
  animation: fadeIn 0.25s ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- No Data State --- */
.no-data-message {
  text-align: center;
  padding: 20px;
  color: #6666aa;
  font-size: 12px;
}

/* --- Paper Type Indicators --- */
.paper-type-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

.paper-type-dot.landmark { background: #ef4444; }
.paper-type-dot.review   { background: #22c55e; }
.paper-type-dot.paper    { background: #3b82f6; }
.paper-type-dot.method   { background: #f59e0b; }

/* --- Toast Notifications --- */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  min-width: 300px;
  max-width: 500px;
  padding: 12px 16px;
  background: #2a2d4a;
  border-left: 4px solid;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast.success {
  border-left-color: #22c55e;
}

.toast.error {
  border-left-color: #ef4444;
}

.toast.warning {
  border-left-color: #f59e0b;
}

.toast.info {
  border-left-color: #3b82f6;
}

.toast-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.toast.success .toast-icon::before {
  content: "✓";
  color: #22c55e;
}

.toast.error .toast-icon::before {
  content: "✕";
  color: #ef4444;
}

.toast.warning .toast-icon::before {
  content: "⚠";
  color: #f59e0b;
}

.toast.info .toast-icon::before {
  content: "ℹ";
  color: #3b82f6;
}

.toast-message {
  flex: 1;
  color: #e0e0e0;
  font-size: 13px;
  line-height: 1.4;
}

.toast-close {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.toast-close:hover {
  color: #fff;
}

/* --- Favorite Button (detail panel header) --- */
.detail-header-actions {
  float: right;
  margin-right: 28px;
}

.favorite-btn {
  background: transparent;
  border: none;
  font-size: 22px;
  color: #64748b;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.2s, transform 0.15s;
}

.favorite-btn:hover {
  color: #f59e0b;
  transform: scale(1.15);
}

.favorite-btn.favorited {
  color: #f59e0b;
}

/* --- Read Status Buttons (detail panel header) --- */
.detail-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.read-status-btns {
  display: flex;
  gap: 4px;
}

.read-status-btn {
  padding: 3px 10px;
  font-size: 11px;
  color: #a0a0c0;
  background: #1e2545;
  border: 1px solid #2a2d4a;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.read-status-btn:hover {
  background: #252a50;
}

.read-status-btn.active[data-status="unread"] {
  background: #2a2d4a;
  border-color: #64748b;
  color: #a0a0c0;
}

.read-status-btn.active[data-status="reading"] {
  background: #1e3a5f;
  border-color: #3b82f6;
  color: #93c5fd;
}

.read-status-btn.active[data-status="read"] {
  background: #1a3a2a;
  border-color: #22c55e;
  color: #86efac;
}

/* --- Importance Stars --- */
.importance-stars {
  display: flex;
  gap: 1px;
}

.importance-star {
  font-size: 14px;
  color: #3a3d5a;
  cursor: pointer;
  transition: color 0.15s;
  user-select: none;
}

.importance-star:hover,
.importance-star.active {
  color: #f59e0b;
}

/* --- Recommendation Score Badges --- */
.rec-score-badge {
  display: inline-block;
  padding: 0 5px;
  font-size: 9px;
  font-weight: 700;
  border-radius: 6px;
  letter-spacing: 0.3px;
  margin-left: 6px;
  vertical-align: middle;
}

.rec-score-badge.rec-high {
  background: #22c55e33;
  color: #22c55e;
  border: 1px solid #22c55e55;
}

.rec-score-badge.rec-mid {
  background: #f59e0b33;
  color: #f59e0b;
  border: 1px solid #f59e0b55;
}

.rec-score-badge.rec-low {
  background: #64748b33;
  color: #94a3b8;
  border: 1px solid #64748b55;
}

/* --- Favorites List (sidebar) --- */
.favorites-list {
  max-height: 180px;
  overflow-y: auto;
}

.favorite-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.favorite-item:hover {
  background: #252a50;
}

.favorite-title {
  font-size: 12px;
  color: #c0c0e0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.favorite-meta {
  font-size: 10px;
  color: #6666aa;
  width: 100%;
}

.favorite-remove-btn {
  position: absolute;
  right: 4px;
  top: 4px;
  background: transparent;
  border: none;
  color: #555580;
  font-size: 11px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.favorite-item:hover .favorite-remove-btn {
  opacity: 1;
}

.favorite-remove-btn:hover {
  color: #ef4444;
}

/* --- Reading List (sidebar) --- */
.reading-list-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.reading-list-tab {
  padding: 3px 10px;
  font-size: 11px;
  color: #a0a0c0;
  background: #1e2545;
  border: 1px solid #2a2d4a;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.reading-list-tab:hover {
  background: #252a50;
}

.reading-list-tab.active {
  background: #2a3a6e;
  border-color: #5b6abf;
  color: #d0d0ff;
}

.reading-list {
  max-height: 200px;
  overflow-y: auto;
}

.reading-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}

.reading-list-item:hover {
  background: #252a50;
}

.reading-list-title {
  font-size: 12px;
  color: #c0c0e0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 8px;
}

.reading-list-badges {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.rl-status-badge {
  display: inline-block;
  padding: 1px 6px;
  font-size: 9px;
  font-weight: 700;
  border-radius: 8px;
  letter-spacing: 0.3px;
}

.rl-status-badge.rl-status-reading {
  background: #3b82f633;
  color: #93c5fd;
  border: 1px solid #3b82f655;
}

.rl-status-badge.rl-status-read {
  background: #22c55e33;
  color: #86efac;
  border: 1px solid #22c55e55;
}

.rl-status-badge.rl-status-unread {
  background: #64748b33;
  color: #94a3b8;
  border: 1px solid #64748b55;
}

.rl-importance {
  font-size: 10px;
  color: #f59e0b;
  letter-spacing: -1px;
}

/* --- Section count badge --- */
.section-count {
  font-size: 10px;
  color: #8888aa;
  font-weight: 400;
}

/* --- Responsive Design --- */
@media (max-width: 1199px) {
  body::before {
    content: "This tool requires a minimum viewport width of 1200px. Please use a desktop browser for the best experience.";
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1a1a2e;
    color: #8888aa;
    font-size: 16px;
    z-index: 9999;
    padding: 40px;
    text-align: center;
  }
}

@media (max-width: 768px) {
  #toast-container {
    left: 10px;
    right: 10px;
    top: 10px;
  }

  .toast {
    min-width: auto;
    max-width: 100%;
  }
}

/* --- Ego Graph: Context Menu --- */
.ego-context-menu {
  position: fixed;
  z-index: 200;
  background: #1a2040;
  border: 1px solid #4a4e80;
  border-radius: 8px;
  padding: 10px 14px;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.ego-context-menu.hidden { display: none; }

.ego-context-title {
  font-size: 11px;
  font-weight: 700;
  color: #a0a0c0;
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
}

.ego-context-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.ego-context-hop-label {
  font-size: 11px;
  color: #8888aa;
  min-width: 50px;
}

.ego-context-slider,
.ego-hop-slider {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  background: #2a2d4a;
  border-radius: 2px;
  outline: none;
}

.ego-context-slider::-webkit-slider-thumb,
.ego-hop-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #5b6abf;
  cursor: pointer;
  border: 2px solid #1a2040;
}

.ego-context-btn {
  display: block;
  width: 100%;
  padding: 6px 10px;
  font-size: 11px;
  color: #d0d0ff;
  background: #2a3a6e;
  border: 1px solid #5b6abf;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
  margin-bottom: 4px;
  text-align: center;
}
.ego-context-btn:hover { background: #3a4a8e; }
.ego-context-btn:last-child { margin-bottom: 0; }

.ego-context-clear {
  color: #ef4444;
  background: #2a1a1a;
  border-color: #ef444488;
}
.ego-context-clear:hover { background: #3a2020; }

/* --- Ego Graph: Detail Panel Controls --- */
.ego-control-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.ego-hop-label {
  font-size: 11px;
  color: #a0a0c0;
  min-width: 50px;
}

/* Ego button row (detail panel) */
.ego-btn-row {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}

.ego-btn-row .ego-context-btn {
  flex: 1;
  margin-bottom: 0;
}

.ego-db-btn {
  background: #1e3a5f !important;
  border-color: #3b82f6 !important;
  color: #93c5fd !important;
}
.ego-db-btn:hover { background: #254a7f !important; }

.ego-extract-btn { width: 100%; }

/* Author ego button (Author Index sidebar) */
.author-ego-btn {
  background: transparent;
  border: 1px solid #2a2d4a;
  color: #8888aa;
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1;
  margin-left: 4px;
  flex-shrink: 0;
}
.author-ego-btn:hover {
  background: #2a3a6e;
  border-color: #5b6abf;
  color: #d0d0ff;
}

/* Ego button in search modal results */
.search-ego-btn {
  background: transparent;
  border: 1px solid #2a2d4a;
  color: #8888aa;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1;
  flex-shrink: 0;
  align-self: center;
}
.search-ego-btn:hover {
  background: #1e3a5f;
  border-color: #3b82f6;
  color: #93c5fd;
}

/* Ego controls group in search modal (hop select + position select + button) */
.search-ego-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}
.search-ego-select {
  background: #1a1d2e;
  border: 1px solid #2a2d4a;
  color: #b0b0cc;
  font-size: 11px;
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
  outline: none;
  max-width: 60px;
}
.search-ego-select:hover,
.search-ego-select:focus {
  border-color: #3b82f6;
  color: #d0d0ff;
}

/* Author name link (detail panel + search modal) */
.author-link {
  color: #93c5fd;
  cursor: pointer;
  transition: color 0.15s;
}
.author-link:hover {
  color: #bfdbfe;
  text-decoration: underline;
}

.ego-clear-btn {
  width: 100%;
  color: #ef4444 !important;
  border-color: #ef444488 !important;
  background: #2a1a1a !important;
}
.ego-clear-btn:hover { background: #3a2020 !important; }

/* --- Ego Graph: Filter Active Badge --- */
.ego-filter-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: #2a3a6eee;
  border: 1px solid #5b6abf;
  border-radius: 20px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 20;
  font-size: 12px;
  color: #d0d0ff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.ego-filter-badge.hidden { display: none; }

.ego-badge-clear {
  background: transparent;
  border: none;
  color: #a0a0c0;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
}
.ego-badge-clear:hover { color: #ef4444; }

/* ============================================================
   Search More Badge & Modal
   ============================================================ */
.search-more-badge {
  display: inline-block;
  background: #3b82f6;
  color: #fff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  cursor: pointer;
  margin-left: 4px;
  transition: background 0.2s;
}
.search-more-badge:hover { background: #2563eb; }
.search-more-badge.hidden { display: none; }

/* --- Modal Overlay --- */
.search-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}
.search-modal.hidden { display: none; }

.search-modal-content {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  width: 640px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.search-modal-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid #334155;
}
.search-modal-title {
  font-size: 15px;
  font-weight: 600;
  color: #e2e8f0;
}
.search-modal-query {
  font-size: 11px;
  color: #94a3b8;
  flex: 1;
}
.search-modal-close {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.search-modal-close:hover { color: #ef4444; }

.search-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 18px;
}

.search-modal-section {
  margin-bottom: 16px;
}
.search-section-title {
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #1e293b;
}

.search-result-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.search-result-empty {
  font-size: 12px;
  color: #64748b;
  padding: 8px 0;
}

.search-result-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  transition: background 0.15s;
}
.search-result-item:hover { background: #334155; }

.search-result-cb {
  margin-top: 4px;
  accent-color: #3b82f6;
}

.search-result-info { flex: 1; min-width: 0; }

.search-result-title {
  font-size: 13px;
  color: #e2e8f0;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-result-meta {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 2px;
}

.search-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid #334155;
}
.search-modal-selected {
  font-size: 12px;
  color: #94a3b8;
}
.search-modal-footer .mode-btn {
  font-size: 12px;
  padding: 6px 14px;
}
.search-modal-footer .mode-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --- Keyboard Shortcuts Help --- */
.keyboard-help-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.keyboard-help-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
.keyboard-help-content {
  background: #1a1e35;
  border: 1px solid #2a2d4a;
  border-radius: 12px;
  padding: 24px 32px;
  max-width: 360px;
  width: 90%;
}
.keyboard-help-title {
  font-size: 16px;
  font-weight: 700;
  color: #e0e0ff;
  margin-bottom: 16px;
  text-align: center;
}
.keyboard-help-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  align-items: center;
}
.keyboard-help-grid kbd {
  display: inline-block;
  background: #252a50;
  border: 1px solid #3a3d5a;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 12px;
  font-family: monospace;
  color: #c0c0e0;
  min-width: 28px;
  text-align: center;
}
.keyboard-help-grid span {
  font-size: 13px;
  color: #a0a0cc;
}
.keyboard-help-dismiss {
  margin-top: 16px;
  text-align: center;
  font-size: 11px;
  color: #6666aa;
}

/* ============================================================
   Knowledge Base UI
   ============================================================ */

#kb-container {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 16px 24px;
  background: #1a1a2e;
}

/* Tabs */
.kb-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid #333366;
  padding-bottom: 8px;
}
.kb-tab-btn {
  padding: 6px 16px;
  background: transparent;
  border: 1px solid #444466;
  border-radius: 4px 4px 0 0;
  color: #a0a0cc;
  cursor: pointer;
  font-size: 13px;
}
.kb-tab-btn.active {
  background: #16213e;
  color: #e0e0ff;
  border-bottom-color: transparent;
}
.kb-tab-btn:hover { color: #ffffff; }

/* Filter bar */
.kb-filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.kb-filter-bar select {
  padding: 4px 8px;
  background: #16213e;
  border: 1px solid #333366;
  color: #e0e0e0;
  border-radius: 4px;
  font-size: 12px;
  max-width: 180px;
}
.kb-count-badge {
  font-size: 12px;
  color: #8888bb;
  margin-left: auto;
}

/* Facts table */
.kb-table-wrapper {
  max-height: 50vh;
  overflow-y: auto;
  border: 1px solid #333366;
  border-radius: 4px;
}
.kb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.kb-table thead {
  position: sticky;
  top: 0;
  background: #16213e;
  z-index: 1;
}
.kb-table th {
  padding: 6px 8px;
  text-align: left;
  color: #8888bb;
  font-weight: 600;
  border-bottom: 1px solid #333366;
  white-space: nowrap;
}
.kb-sortable { cursor: pointer; }
.kb-sortable:hover { color: #ccccff; }
.kb-table td {
  padding: 4px 8px;
  border-bottom: 1px solid #222244;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.kb-fact-row { cursor: pointer; }
.kb-fact-row:hover { background: #1e2a4a; }
.kb-col-id { font-family: monospace; font-size: 11px; color: #8888cc; }
.kb-col-dir { text-align: center; }

/* Type badges */
.kb-type-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}
.kb-type-mechanism-chain { background: #1a3a1a; color: #66cc66; }
.kb-type-quantitative { background: #1a2a3a; color: #66aacc; }
.kb-type-decision-rule { background: #3a2a1a; color: #ccaa66; }
.kb-type-empirical-formula { background: #2a1a3a; color: #aa88cc; }
.kb-type-comparison { background: #1a3a3a; color: #66ccaa; }
.kb-type-qualitative { background: #2a2a2a; color: #aaaaaa; }
.kb-type-threshold { background: #3a1a1a; color: #cc8888; }

/* Confidence */
.kb-conf-high { color: #66cc66; }
.kb-conf-medium { color: #cccc66; }
.kb-conf-low { color: #cc8866; }

/* Direction icons */
.dir-up { color: #66cc66; }
.dir-down { color: #cc6666; }
.dir-opt { color: #66aacc; }
.dir-other { color: #666688; }

/* Fact detail panel */
.kb-detail-panel {
  margin-top: 12px;
  padding: 12px 16px;
  background: #16213e;
  border: 1px solid #333366;
  border-radius: 4px;
  max-height: 40vh;
  overflow-y: auto;
}
.kb-detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.kb-detail-header h3 { font-size: 14px; color: #e0e0ff; }
.kb-detail-section { margin-bottom: 8px; font-size: 12px; line-height: 1.6; }
.kb-detail-section strong { color: #8888bb; }
.kb-detail-section p { margin-top: 4px; color: #d0d0e0; }
.kb-detail-section code { background: #0a0a1e; padding: 2px 6px; border-radius: 3px; font-size: 11px; }
.kb-detail-section ul { list-style: none; padding-left: 8px; }
.kb-related-link { color: #6688cc; cursor: pointer; }
.kb-related-link:hover { color: #aaccff; text-decoration: underline; }

/* ---- CausalModel panel ---- */
.kb-cm-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  height: calc(100vh - 180px);
}
.kb-cm-list {
  overflow-y: auto;
  border: 1px solid #333366;
  border-radius: 4px;
  padding: 8px;
}
.kb-cm-card {
  padding: 8px 12px;
  border: 1px solid #333366;
  border-radius: 4px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.kb-cm-card:hover { border-color: #6666aa; }
.kb-cm-card.selected { border-color: #8888cc; background: #1e2a4a; }
.kb-cm-card-header { display: flex; justify-content: space-between; align-items: center; }
.kb-cm-id { font-family: monospace; font-size: 11px; color: #8888cc; }
.kb-cm-title { font-size: 12px; color: #d0d0e0; margin: 4px 0; line-height: 1.4; }
.kb-cm-meta { display: flex; gap: 8px; font-size: 10px; color: #8888aa; }
.kb-cm-contra { color: #cc8866; }

/* CM status badges */
.kb-cm-status {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
}
.kb-cm-status-proposed { background: #2a2a1a; color: #cccc66; }
.kb-cm-status-supported { background: #1a3a1a; color: #66cc66; }
.kb-cm-status-contested { background: #3a1a1a; color: #cc6666; }
.kb-cm-status-refined { background: #1a2a3a; color: #66aacc; }

/* Hypothesis / Contradiction status badges */
.kb-status-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
}
.kb-status-proposed { background: #1a2a3a; color: #2563eb; }
.kb-status-searching { background: #2a2a1a; color: #d97706; }
.kb-status-confirmed { background: #1a3a1a; color: #16a34a; }
.kb-status-refuted { background: #3a1a1a; color: #dc2626; }
.kb-status-stale { background: #2a2a2a; color: #6b7280; }
.kb-status-needs-review { background: #2a2a1a; color: #d97706; }
.kb-status-resolved { background: #1a3a1a; color: #66cc66; }
.kb-status-acknowledged { background: #1a3a1a; color: #66cc66; }

/* Contradiction row styles */
.kb-contra-unresolved { border-left: 3px solid #d97706; }
.kb-contra-resolved { border-left: 3px solid #16a34a; opacity: 0.75; }

/* CM detail panel */
.kb-cm-detail-panel {
  overflow-y: auto;
  border: 1px solid #333366;
  border-radius: 4px;
  padding: 16px;
}
.kb-cm-detail-header { margin-bottom: 12px; }
.kb-cm-detail-header h3 { font-size: 14px; color: #e0e0ff; }
.kb-cm-scope { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.kb-scope-badge {
  padding: 2px 8px;
  background: #1a2a3a;
  border: 1px solid #334466;
  border-radius: 3px;
  font-size: 11px;
  color: #88aacc;
}

/* CM step diagram */
.kb-cm-steps { margin: 16px 0; }
.kb-cm-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 12px;
  background: #16213e;
  border: 1px solid #333366;
  border-radius: 4px;
}
.kb-step-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #334466;
  color: #e0e0ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}
.kb-step-desc { font-size: 12px; color: #d0d0e0; line-height: 1.5; }
.kb-step-arrow { text-align: center; color: #6666aa; font-size: 18px; padding: 2px 0; }

/* CM edges */
.kb-cm-edges { margin-top: 12px; }
.kb-cm-edges h4 { font-size: 12px; color: #8888bb; margin-bottom: 4px; }
.kb-cm-edges ul { list-style: none; padding-left: 8px; }
.kb-cm-edges li { font-size: 12px; padding: 2px 0; }
.kb-cm-contra-section h4 { color: #cc8866; }
.kb-edge-strength { font-size: 10px; color: #888888; }

/* ---- Stats dashboard ---- */
.kb-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.kb-stat-card {
  padding: 16px;
  background: #16213e;
  border: 1px solid #333366;
  border-radius: 6px;
}
.kb-stat-title { font-size: 11px; color: #8888bb; text-transform: uppercase; letter-spacing: 0.5px; }
.kb-stat-value { font-size: 28px; font-weight: 700; color: #e0e0ff; margin: 4px 0; }
.kb-stat-detail { font-size: 11px; color: #8888aa; }
.kb-stat-sub { font-size: 11px; color: #6666aa; }

/* Bar chart in stats */
.kb-bar-container {
  width: 100%;
  height: 8px;
  background: #0a0a1e;
  border-radius: 4px;
  overflow: hidden;
  margin: 4px 0;
}
.kb-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}
.kb-bar-blue { background: linear-gradient(90deg, #3366cc, #6699ff); }
.kb-bar-green { background: linear-gradient(90deg, #339966, #66cc99); }

/* Type distribution bar */
.kb-type-bar {
  display: flex;
  height: 16px;
  border-radius: 3px;
  overflow: hidden;
  margin: 4px 0;
}
.kb-type-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  color: #ffffff88;
  overflow: hidden;
}
.kb-type-seg:nth-child(1) { background: #1a6a1a; }
.kb-type-seg:nth-child(2) { background: #1a4a6a; }
.kb-type-seg:nth-child(3) { background: #6a4a1a; }
.kb-type-seg:nth-child(4) { background: #4a1a6a; }
.kb-type-seg:nth-child(5) { background: #1a6a4a; }
.kb-type-seg:nth-child(6) { background: #4a4a4a; }
