* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --sidebar-width: 320px;
  --toolbar-height: 44px;
  --statusbar-height: 28px;
  --applies-color: #22c55e;
  --flagged-color: #f59e0b;
  --resolved-color: #94a3b8;
  --bg-color: #121420;
  --surface-color: #1a1f30;
  --text-color: #e8ecf7;
  --border-color: #2f3850;
  --canvas-color: #101522;
  --accent-color: #6f8fd6;
  --hover-color: #303a52;
}

body[data-theme="dark"] {
  --bg-color: #121420;
  --surface-color: #1a1f30;
  --text-color: #e8ecf7;
  --border-color: #2f3850;
  --canvas-color: #101522;
  --accent-color: #6f8fd6;
  --hover-color: #303a52;
}

body[data-theme="light"] {
  --bg-color: #f3f5fa;
  --surface-color: #ffffff;
  --text-color: #1f2937;
  --border-color: #d2d8e6;
  --canvas-color: #eef2fb;
  --accent-color: #4a6fa5;
  --hover-color: #e5eaf6;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* Toolbar */
#toolbar {
  height: var(--toolbar-height);
  background: var(--surface-color);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  z-index: 100;
  position: relative;
}

.fig-tab {
  background: var(--border-color) !important;
  padding: 4px 10px !important;
  font-size: 12px !important;
  border-radius: 6px !important;
  cursor: pointer;
}

.fig-tab.active {
  background: var(--accent-color) !important;
  border-color: var(--accent-color) !important;
}

#toolbar h1 {
  font-size: 14px;
  font-weight: 600;
  margin-right: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#toolbar button {
  background: var(--border-color);
  color: var(--text-color);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

#toolbar button:hover {
  background: var(--hover-color);
}

#toolbar button.active {
  background: var(--accent-color);
  border-color: var(--accent-color);
}

.toolbar-link {
  background: var(--border-color);
  color: var(--text-color);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  text-decoration: none;
  white-space: nowrap;
}

.toolbar-link:hover {
  background: var(--hover-color);
}

/* Main layout */
#main-container {
  display: flex;
  height: calc(100vh - var(--toolbar-height) - var(--statusbar-height));
  position: relative;
}

/* SVG container */
#svg-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--canvas-color);
  cursor: grab;
}

#svg-container.grabbing {
  cursor: grabbing;
}

#svg-container svg {
  display: block;
}

.load-error {
  max-width: 520px;
  margin: 40px auto;
  padding: 16px 18px;
  border: 1px solid #b85450;
  border-radius: 10px;
  background: rgba(184, 84, 80, 0.12);
  color: var(--text-color);
  line-height: 1.5;
}

.load-error h3 {
  font-size: 15px;
  margin-bottom: 8px;
}

/* Node state overlays */
.node-overlay {
  position: absolute;
  pointer-events: none;
  border-radius: 9px;
  transition: box-shadow 0.2s, opacity 0.2s;
}

/* SVG-based node highlights */
.node-highlight {
  pointer-events: none;
  transition: opacity 0.2s;
}

rect.node-rect {
  cursor: pointer;
}

rect.node-rect:hover {
  filter: brightness(1.1);
}

/* State indicators via outline rects */
.state-applies {
  stroke: var(--applies-color) !important;
  stroke-width: 4 !important;
}

.state-flagged {
  stroke: var(--flagged-color) !important;
  stroke-width: 4 !important;
}

.state-resolved {
  stroke: var(--resolved-color) !important;
  stroke-width: 4 !important;
  opacity: 0.5;
}

/* Dimming for connection highlighting */
.dimmed {
  opacity: 0.12 !important;
  transition: opacity 0.3s;
}

.highlighted-path {
  stroke-width: 3 !important;
  opacity: 1 !important;
  filter: brightness(1.25);
  transition: opacity 0.3s;
}

.highlighted-node rect {
  opacity: 1 !important;
}

/* Context menu */
#context-menu {
  display: none;
  position: fixed;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 4px;
  z-index: 1000;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

#context-menu.visible {
  display: block;
}

#context-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text-color);
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
  text-align: left;
}

#context-menu button:hover {
  background: var(--border-color);
}

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

#context-menu .separator {
  height: 1px;
  background: var(--border-color);
  margin: 4px 0;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  background: var(--surface-color);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: margin-right 0.3s;
  overflow: hidden;
  flex-shrink: 0;
}

#sidebar.collapsed {
  margin-right: calc(-1 * var(--sidebar-width));
}

#sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
}

#sidebar-header h2 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

#search-input {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-color);
  font-size: 12px;
  outline: none;
}

#search-input:focus {
  border-color: #5a8fd5;
}

/* Counters */
#counters {
  display: flex;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
  font-size: 11px;
}

.counter {
  display: flex;
  align-items: center;
  gap: 4px;
}

.counter .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* Filter tabs */
#filter-tabs {
  display: flex;
  padding: 6px 12px;
  gap: 4px;
  border-bottom: 1px solid var(--border-color);
}

#filter-tabs button {
  background: none;
  border: 1px solid transparent;
  color: #888;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
}

#filter-tabs button.active {
  background: var(--border-color);
  color: var(--text-color);
  border-color: #555;
}

/* Node list */
#node-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

#node-list::-webkit-scrollbar {
  width: 6px;
}

#node-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.node-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12px;
  border-left: 3px solid transparent;
  transition: background 0.15s;
}

.node-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.node-item.selected {
  background: rgba(74, 111, 165, 0.2);
  border-left-color: #5a8fd5;
}

.node-item .state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid #555;
}

.node-item .state-dot.applies { background: var(--applies-color); border-color: var(--applies-color); }
.node-item .state-dot.flagged { background: var(--flagged-color); border-color: var(--flagged-color); }
.node-item .state-dot.resolved { background: var(--resolved-color); border-color: var(--resolved-color); }

.node-item .fill-indicator {
  width: 4px;
  height: 20px;
  border-radius: 2px;
  flex-shrink: 0;
}

.node-item .label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Category headers in sidebar */
.category-header {
  padding: 8px 12px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
}

/* Status bar */
#statusbar {
  height: var(--statusbar-height);
  background: var(--surface-color);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 11px;
  color: #888;
  gap: 16px;
}

/* Legend */
#legend {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
  font-size: 11px;
}

#legend h3 {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
  margin-bottom: 6px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.legend-line {
  width: 24px;
  height: 2px;
  flex-shrink: 0;
}

.legend-line.dashed {
  border-top: 2px dashed;
  height: 0;
}

/* Tooltip */
#tooltip {
  display: none;
  position: fixed;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  z-index: 500;
  max-width: 280px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

#tooltip.visible {
  display: block;
}

#tooltip .tooltip-label {
  font-weight: 600;
  margin-bottom: 4px;
}

#tooltip .tooltip-state {
  font-size: 11px;
  color: #aaa;
}

/* Note editor in context menu */
#note-editor {
  padding: 8px 12px;
}

#note-editor textarea {
  width: 100%;
  height: 60px;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-color);
  font-size: 12px;
  padding: 6px;
  resize: vertical;
  outline: none;
  font-family: inherit;
}

/* File input hidden */
#import-input {
  display: none;
}

/* ── Research Panel (node detail, right drawer) ── */
#research-panel {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  width: 360px;
  max-height: 100%;
  background: var(--surface-color);
  border-left: 1px solid var(--border-color);
  z-index: 90;
  overflow-y: auto;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.25);
}

#research-panel.visible {
  display: block;
}

.rp-header {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

.rp-header h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  padding-right: 28px;
}

.rp-category {
  font-size: 11px;
  color: #888;
}

.rp-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-color);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.rp-close:hover {
  background: var(--hover-color);
}

.rp-body {
  padding: 8px 12px;
}

.rp-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
  margin-bottom: 8px;
}

.rp-empty {
  font-size: 12px;
  color: #888;
  padding: 16px 0;
  text-align: center;
}

.rp-assertion {
  padding: 8px;
  margin-bottom: 6px;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

.rp-assertion-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.rp-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.rp-evidence-link {
  font-size: 12px;
  color: var(--accent-color);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.rp-evidence-link:hover {
  text-decoration: underline;
}

.rp-no-url {
  font-size: 12px;
  color: #666;
  flex: 1;
}

.rp-strength-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--accent-color);
  color: #fff;
}

.rp-relation-note {
  font-size: 11px;
  color: #aaa;
  margin-bottom: 4px;
  line-height: 1.4;
}

.rp-assertion-actions {
  display: flex;
  gap: 6px;
}

.rp-status-select,
.rq-status-select {
  background: var(--surface-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 11px;
  padding: 2px 4px;
  cursor: pointer;
}

/* ── Research Queue Panel (full overlay) ── */
#research-queue {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface-color);
  z-index: 95;
  overflow-y: auto;
}

#research-queue.visible {
  display: flex;
  flex-direction: column;
}

.rq-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.rq-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.rq-close {
  background: none;
  border: none;
  color: var(--text-color);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.rq-close:hover {
  background: var(--hover-color);
}

.rq-progress {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.rq-progress-bar {
  height: 8px;
  background: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 4px;
}

.rq-progress-fill {
  height: 100%;
  background: var(--applies-color);
  border-radius: 4px;
  transition: width 0.3s;
}

.rq-progress-text {
  font-size: 11px;
  color: #888;
}

.rq-filters {
  display: flex;
  gap: 4px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.rq-filter {
  background: none;
  border: 1px solid transparent;
  color: #888;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.rq-filter.active {
  background: var(--border-color);
  color: var(--text-color);
  border-color: #555;
}

.rq-actions {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.rq-export-btn,
.rq-import-btn {
  background: var(--border-color);
  color: var(--text-color);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
}

.rq-export-btn:hover,
.rq-import-btn:hover {
  background: var(--hover-color);
}

.rq-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.rq-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 12px;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.15s;
}

.rq-row:hover {
  background: rgba(255, 255, 255, 0.05);
}

.rq-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.rq-node-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.rq-url {
  font-size: 11px;
  color: var(--accent-color);
  text-decoration: none;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rq-url:hover {
  text-decoration: underline;
}

.rq-no-url {
  font-size: 11px;
  color: #666;
}

/* Responsive */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 260px;
  }

  #research-panel {
    width: 100%;
    right: 0;
  }
}
