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

:root {
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1a202c;
  --color-text-secondary: #718096;
  --color-primary: #5B8FF9;
  --color-primary-hover: #4a7de0;
  --color-danger: #E8684A;
  --color-success: #61DDAA;
  --color-warning: #F6BD16;
  --color-tech: #5B8FF9;
  --color-solution: #F6BD16;
  --color-paper: #61DDAA;
  --color-model: #F6903D;
  --color-org: #9270CA;
  --color-person: #E8684A;
  --sidebar-width: 200px;
  --right-panel-width: 320px;
  --top-bar-height: 56px;
  --bottom-bar-height: 48px;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --transition: 0.2s ease;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg);
  overflow: hidden;
}

/* ===== Top Bar ===== */
.top-bar {
  height: var(--top-bar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  z-index: 100;
  position: relative;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.app-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-primary);
  white-space: nowrap;
}

.mode-tabs {
  display: flex;
  gap: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.mode-tab {
  padding: 6px 14px;
  border: none;
  background: var(--color-surface);
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text-secondary);
  transition: var(--transition);
  white-space: nowrap;
}

.mode-tab.active {
  background: var(--color-primary);
  color: #fff;
}

.mode-tab:hover:not(.active) {
  background: #f1f5f9;
}

.top-bar-center {
  flex: 1;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.search-input {
  flex: 1;
  max-width: 400px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}

.search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(91,143,249,0.15);
}

.type-filter {
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--color-surface);
  outline: none;
  cursor: pointer;
}

.top-bar-right {
  flex-shrink: 0;
}

.node-count {
  font-size: 13px;
  color: var(--color-text-secondary);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background: #f1f5f9;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.btn-secondary:hover {
  background: #eef2ff;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.btn-close:hover {
  color: var(--color-text);
}

/* ===== Main Content ===== */
.main-content {
  height: calc(100vh - var(--top-bar-height) - var(--bottom-bar-height));
  display: flex;
  flex: 1;
}

.mode-panel {
  display: none;
  width: 100%;
  height: 100%;
}

.mode-panel.active {
  display: flex;
}

/* ===== Graph Browser Layout ===== */
#graphMode {
  display: none;
  flex-direction: row;
}

#graphMode.active {
  display: flex;
}

/* ===== Left Sidebar ===== */
.sidebar-left {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  padding: 12px;
  transition: var(--transition);
}

.sidebar-left.collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border-right: none;
}

.sidebar-section {
  margin-bottom: 16px;
}

.sidebar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.legend-list {
  list-style: none;
  font-size: 12px;
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.legend-item {
  cursor: pointer;
  border-radius: 4px;
  padding: 3px 6px !important;
  margin: 1px 0;
  transition: var(--transition);
  user-select: none;
}

.legend-item:hover {
  background: #f1f5f9;
}

.legend-item.active {
  background: #eef2ff;
  box-shadow: inset 0 0 0 1px var(--color-primary);
}

.legend-item .check-mark {
  margin-left: auto;
  font-size: 10px;
  color: var(--color-primary);
  opacity: 0;
}

.legend-item.active .check-mark {
  opacity: 1;
}

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

.legend-line {
  display: inline-block;
  width: 18px;
  height: 2px;
  border-top: 2px solid;
  flex-shrink: 0;
}

.legend-notes {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.legend-notes p {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

.line-sample {
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 2px solid #999;
  flex-shrink: 0;
}

.line-sample.dashed {
  border-top-style: dashed;
}

.line-sample.solid {
  border-top-style: solid;
}

/* ===== Canvas Container ===== */
.canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #fafbfc;
  background-image: radial-gradient(circle, #e2e8f0 1px, transparent 1px);
  background-size: 20px 20px;
}

.canvas-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.canvas-placeholder.hidden {
  display: none;
}

.placeholder-content {
  text-align: center;
  color: #cbd5e1;
}

.placeholder-content svg {
  margin-bottom: 12px;
  opacity: 0.5;
}

.placeholder-content p {
  font-size: 15px;
}

/* ===== Right Detail Panel ===== */
.sidebar-right {
  width: var(--right-panel-width);
  min-width: var(--right-panel-width);
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  overflow-y: auto;
  transition: var(--transition);
}

.sidebar-right.collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-left: none;
}

.panel-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-secondary);
  font-size: 14px;
}

.panel-content {
  padding: 16px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.node-type-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.5px;
}

.node-type-badge.Technology { background: var(--color-tech); }
.node-type-badge.Solution { background: var(--color-solution); }
.node-type-badge.Paper { background: var(--color-paper); }
.node-type-badge.Model { background: var(--color-model); }
.node-type-badge.Organization { background: var(--color-org); }
.node-type-badge.Person { background: var(--color-person); }
.node-type-badge.Resource { background: #73C0DE; }
.node-type-badge.Capability { background: #B07BE6; }

.node-label {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  word-break: break-word;
}

.detail-section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
}

.detail-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.detail-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

/* ===== Properties Table ===== */
.properties-table {
  font-size: 13px;
}

.property-row {
  display: flex;
  padding: 4px 0;
  gap: 8px;
}

.property-key {
  color: var(--color-text-secondary);
  min-width: 70px;
  flex-shrink: 0;
}

.property-value {
  color: var(--color-text);
  word-break: break-word;
}

.property-value.url {
  color: var(--color-primary);
  cursor: pointer;
}

/* ===== Verified Toggle ===== */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 14px;
}

.toggle-switch {
  width: 40px;
  height: 22px;
  appearance: none;
  background: #cbd5e1;
  border-radius: 11px;
  position: relative;
  cursor: pointer;
  transition: var(--transition);
  outline: none;
}

.toggle-switch::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  left: 2px;
  transition: var(--transition);
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.toggle-switch:checked {
  background: var(--color-primary);
}

.toggle-switch:checked::before {
  left: 20px;
}

/* ===== Relation List ===== */
.relation-list {
  list-style: none;
  font-size: 13px;
}

.relation-list li {
  padding: 6px 0;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

.relation-list li:hover {
  color: var(--color-primary);
}

.relation-list li:last-child {
  border-bottom: none;
}

.relation-type-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  background: #f1f5f9;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

/* ===== Bottom Bar ===== */
.bottom-bar {
  height: var(--bottom-bar-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 13px;
  z-index: 100;
  position: relative;
}

.depth-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.depth-control label {
  white-space: nowrap;
  color: var(--color-text-secondary);
}

.depth-control strong {
  color: var(--color-text);
  font-size: 15px;
}

#depthSlider {
  width: 120px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.bottom-actions {
  display: flex;
  gap: 8px;
}

/* ===== Collection Mode ===== */
#collectMode {
  display: none;
  align-items: center;
  justify-content: center;
}

#collectMode.active {
  display: flex;
  align-items: flex-start;
  overflow-y: auto;
  padding: 24px 0;
}

.collect-container {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: visible;
}

.collect-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
}

.collect-tab {
  flex: 1;
  padding: 12px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  transition: var(--transition);
  border-bottom: 2px solid transparent;
}

.collect-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.collect-tab:hover:not(.active) {
  color: var(--color-text);
}

.collect-panel {
  display: none;
  padding: 24px;
}

.collect-panel.active {
  display: block;
}

.collect-panel h2 {
  font-size: 18px;
  margin-bottom: 8px;
}

.collect-desc {
  color: var(--color-text-secondary);
  margin-bottom: 16px;
  font-size: 14px;
  line-height: 1.6;
}

.collect-form {
  display: flex;
  gap: 8px;
}

.collect-input {
  flex: 1;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}

.collect-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(91,143,249,0.15);
}

/* ===== Collect Result ===== */
.collect-result {
  margin-top: 16px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

.collect-result.loading {
  background: #fefce8;
  border-color: var(--color-warning);
}

.collect-result.success {
  background: #f0fdf4;
  border-color: var(--color-success);
}

.collect-result.error {
  background: #fef2f2;
  border-color: var(--color-danger);
}

.collect-result .result-title {
  font-weight: 600;
  margin-bottom: 8px;
}

.collect-result .result-list {
  list-style: disc;
  padding-left: 20px;
  font-size: 13px;
}

.collect-result .result-list li {
  margin-bottom: 4px;
}

.collect-result .result-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

/* ===== arXiv Paper List ===== */
.arxiv-paper-list {
  list-style: none;
  max-height: 500px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.arxiv-paper-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: var(--transition);
}
.arxiv-paper-item:hover {
  background: #f8fafc;
}
.arxiv-paper-item.selected {
  background: #eef2ff;
}
.arxiv-paper-item:last-child {
  border-bottom: none;
}
.arxiv-paper-checkbox {
  flex-shrink: 0;
  margin-top: 2px;
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
  cursor: pointer;
}
.arxiv-paper-info {
  flex: 1;
  min-width: 0;
}
.arxiv-paper-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 4px;
  line-height: 1.4;
}
.arxiv-paper-meta {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}
.arxiv-paper-meta a {
  color: var(--color-primary);
  margin-left: 8px;
}
.arxiv-paper-authors {
  font-size: 12px;
  color: var(--color-text-secondary);
}
.arxiv-paper-abstract {
  font-size: 12px;
  color: #a0aec0;
  margin-top: 4px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.arxiv-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}
.arxiv-select-all {
  font-size: 13px;
  color: var(--color-text-secondary);
  cursor: pointer;
  user-select: none;
}
.arxiv-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

/* arXiv inline section (inside tech collection result) */
.arxiv-inline-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}
.arxiv-inline-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  color: #fff;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.25s ease;
  max-width: 360px;
  word-break: break-word;
}

.toast.info { background: var(--color-primary); }
.toast.success { background: #38a169; }
.toast.error { background: var(--color-danger); }
.toast.warning { background: #d69e2e; }

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

/* ===== Create Node Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  padding: 16px;
}

.modal {
  width: 100%;
  max-width: 440px;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

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

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-form {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 13px;
  color: var(--color-text-secondary);
  font-weight: 500;
}

.form-label em {
  color: var(--color-danger);
  font-style: normal;
}

.form-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
  background: var(--color-surface);
  color: var(--color-text);
  resize: vertical;
}

.form-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(91, 143, 249, 0.15);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .sidebar-left {
    width: 160px;
    min-width: 160px;
  }

  .sidebar-right {
    width: 280px;
    min-width: 280px;
  }

  .top-bar-center {
    flex: 1;
  }

  .search-input {
    max-width: 250px;
  }
}

@media (max-width: 768px) {
  .sidebar-left {
    display: none;
  }

  .sidebar-left.collapsed {
    display: none;
  }

  .sidebar-right {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    box-shadow: var(--shadow-lg);
  }

  .sidebar-right.collapsed {
    display: none;
  }

  .top-bar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px;
    gap: 8px;
  }

  .top-bar-center {
    order: 3;
    flex-basis: 100%;
  }

  .search-input {
    max-width: none;
  }

  .app-title {
    font-size: 16px;
  }
}
