:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f3f4f6;
  --bg-tertiary: #e5e7eb;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --accent-primary: #3b82f6;
  --accent-hover: #2563eb;
  --border-color: #d1d5db;
  --node-color: #3b82f6;
  --node-text: #ffffff;
  --edge-color: #9ca3af;
  --pin-color: #f59e0b;
  --tag-bg: #e0e7ff;
  --tag-text: #3730a3;
  --chip-bg: #e5e7eb;
  --chip-text: #1f2937;
  --focus-ring: #38bdf8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --bg-tertiary: #374151;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --accent-primary: #60a5fa;
    --accent-hover: #3b82f6;
    --border-color: #4b5563;
    --node-color: #60a5fa;
    --edge-color: #6b7280;
    --pin-color: #fbbf24;
    --tag-bg: #312e81;
    --tag-text: #c7d2fe;
    --chip-bg: #374151;
    --chip-text: #e5e7eb;
    --focus-ring: #38bdf8;
  }
}

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

body {
  font-family:
    system-ui,
    -apple-system,
    sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  max-width: 100%;
}

.header {
  text-align: center;
  margin-bottom: 0.75rem;
}

.header h1 {
  font-size: 1.5rem;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.workspace {
  display: flex;
  flex: 1;
  gap: 1rem;
  min-height: 0;
  position: relative;
}

.editor-pane,
.graph-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.pane-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.75rem;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  gap: 0.5rem;
}

.graph-header {
  flex-wrap: wrap;
}

.title-input {
  flex: 1;
  padding: 0.45rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 600;
  min-width: 120px;
}

.title-input:focus,
.search-input:focus {
  outline: 2px solid var(--accent-primary);
  border-color: transparent;
}

.pane-actions,
.graph-controls {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  min-width: 180px;
}

.search-input {
  flex: 1;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.85rem;
}

.search-count {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.btn {
  padding: 0.35rem 0.7rem;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.82rem;
  transition: all 0.15s ease-in-out;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
}

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

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

.btn-danger {
  background: #ef4444;
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-small {
  padding: 0.3rem 0.55rem;
  font-size: 0.78rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-small:hover {
  background: var(--bg-tertiary);
}

.btn-cluster.active {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

#note-content {
  flex: 2;
  min-height: 180px;
  width: 100%;
  padding: 0.85rem;
  border: none;
  resize: none;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  outline: none;
}

/* Note Inspector: Backlinks, Outgoing links, Tags */
.note-inspector {
  padding: 0.6rem 0.75rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 180px;
  overflow-y: auto;
}

.inspector-section {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.inspector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.inspector-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 9999px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.badge-cluster {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.link-chips,
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--chip-bg);
  color: var(--chip-text);
  font-size: 0.75rem;
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  transform: translateY(-1px);
}

.chip-tag {
  background: var(--tag-bg);
  color: var(--tag-text);
  font-family: monospace;
  font-weight: 600;
  border: 1px solid transparent;
}

.chip-tag:hover {
  border-color: var(--accent-primary);
}

.empty-hint {
  font-size: 0.75rem;
  font-style: italic;
  color: var(--text-secondary);
}

/* Vault Notes List */
.note-list-container {
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  max-height: 160px;
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.75rem;
  background: var(--bg-tertiary);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

.vault-actions {
  display: flex;
  gap: 0.3rem;
}

.note-list {
  overflow-y: auto;
  max-height: 130px;
}

.note-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  transition: background 0.15s ease;
}

.note-item:hover,
.note-item.active {
  background: var(--bg-tertiary);
}

.note-item-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.note-item-badges {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

.canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
}

.canvas-wrapper:active {
  cursor: grabbing;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.graph-footer {
  padding: 0.35rem 0.75rem;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border-color);
  text-align: center;
}

.graph-hint {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Drag-and-drop overlay */
.drop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  border: 3px dashed var(--accent-primary);
  border-radius: 6px;
  pointer-events: none;
}

.drop-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  color: #ffffff;
  text-align: center;
}

.drop-message svg {
  color: var(--accent-primary);
}

.drop-message p {
  font-size: 1.1rem;
  font-weight: 700;
}

.drop-subtext {
  font-size: 0.8rem;
  color: #9ca3af;
}

@media (max-width: 860px) {
  .workspace {
    flex-direction: column;
  }

  .editor-pane,
  .graph-pane {
    min-height: 380px;
  }
}
