:root {
  /* Indigo Deep / Dark Mode Palette */
  --bg-color: #0C0C1E;
  --bg-sidebar: #14142B;
  --surface: rgba(30, 30, 60, 0.6);
  --surface-hover: rgba(50, 50, 90, 0.8);
  --border-color: rgba(99, 102, 241, 0.2);
  --border-highlight: rgba(99, 102, 241, 0.5);
  
  --primary: #6366F1;
  --primary-hover: #4F46E5;
  --secondary: #818CF8;
  --accent: #22D3EE;
  --danger: #EF4444;
  
  --text-main: #F8FAFC;
  --text-muted: #94A3B8;
  --text-link: #818CF8;
  --text-wikilink: #22D3EE;
  
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
  
  --transition: all 0.2s ease;
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-sans);
  overflow: hidden; /* Prevent body scroll, use inner scrolling */
}

/* Utilities */
.hidden { display: none !important; }
.w-full { width: 100%; }
.mt-md { margin-top: 1rem; }
.text-secondary { color: var(--text-muted); }

/* Glassmorphism */
.glass-panel {
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
}

/* Typography */
h1, h2, h3, h4 { color: var(--text-main); font-weight: 600; }

/* Buttons */
button {
  font-family: var(--font-sans);
  cursor: pointer;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-weight: 500;
  font-size: 0.875rem;
}

.btn-primary {
  background: var(--primary);
  color: white;
  padding: 0.6rem 1rem;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.5);
  transform: translateY(-1px);
}

.btn-outline {
  border: 1px solid var(--border-highlight);
  color: var(--text-main);
  padding: 0.6rem 1rem;
}
.btn-outline:hover {
  background: rgba(99, 102, 241, 0.1);
  border-color: var(--primary);
}

.btn-sm { padding: 0.4rem 0.6rem; }

.btn-icon {
  padding: 0.5rem;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}
.btn-icon:hover {
  color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}
.btn-icon.danger:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* Layout */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar-header { padding: 1.5rem 1.5rem 1rem; }

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.pulse-icon { animation: pulse 2s infinite alternate; }
@keyframes pulse { 0% { filter: drop-shadow(0 0 2px var(--primary)); } 100% { filter: drop-shadow(0 0 8px var(--primary)); } }

.sidebar-actions {
  padding: 0 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.search-box {
  margin: 0 1.5rem 1rem;
  position: relative;
  display: flex;
  align-items: center;
}
.search-box svg {
  position: absolute;
  left: 0.75rem;
  color: var(--text-muted);
}
.search-box input {
  width: 100%;
  padding: 0.5rem 1rem 0.5rem 2.25rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  outline: none;
  transition: var(--transition);
}
.search-box input:focus {
  border-color: var(--primary);
  box-shadow: var(--shadow-glow);
}

.sidebar-section {
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(255,255,255,0.05);
}
.sidebar-section.scrollable {
  flex: 1;
  overflow-y: auto;
}
.sidebar-section.scrollable::-webkit-scrollbar { width: 4px; }
.sidebar-section.scrollable::-webkit-scrollbar-thumb { background: var(--border-highlight); border-radius: 4px; }

.section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.nav-list { list-style: none; display: flex; flex-direction: column; gap: 0.25rem; }
.nav-item {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  transition: var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text-main); }
.nav-item.active {
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary);
  font-weight: 500;
  border-left: 3px solid var(--primary);
}

/* Tag Cloud */
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.tag {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  background: rgba(34, 211, 238, 0.1);
  color: var(--accent);
  border-radius: 999px;
  cursor: pointer;
  transition: var(--transition);
}
.tag:hover, .tag.active {
  background: var(--accent);
  color: #000;
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
}

/* Main Workspace */
.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1rem;
}

.editor-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.workspace-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border-color);
  z-index: 5;
  border-radius: 0;
}

.page-title-input {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  background: transparent;
  border: none;
  outline: none;
  width: 50%;
  font-family: var(--font-sans);
}
.page-title-input::placeholder { color: rgba(255,255,255,0.2); }

.workspace-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.toggle-group {
  display: flex;
  background: rgba(0,0,0,0.3);
  border-radius: var(--radius-sm);
  padding: 0.2rem;
  border: 1px solid var(--border-color);
}
.toggle-btn {
  padding: 0.4rem 1rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.8rem;
}
.toggle-btn.active {
  background: var(--primary);
  color: white;
}

/* Split View */
.split-view {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.pane {
  flex: 1;
  height: 100%;
  overflow-y: auto;
  transition: flex 0.3s;
}

/* Editor */
.edit-pane { padding: 0; }
.edit-pane textarea {
  width: 100%;
  height: 100%;
  background: transparent;
  color: var(--text-main);
  border: none;
  padding: 2rem;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.6;
  resize: none;
  outline: none;
}
.edit-pane textarea::-webkit-scrollbar { width: 8px; }
.edit-pane textarea::-webkit-scrollbar-thumb { background: var(--border-highlight); border-radius: 4px; }

/* Preview / Markdown Body */
.preview-pane {
  padding: 2rem;
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--border-color);
  box-shadow: none;
}
.preview-pane::-webkit-scrollbar { width: 8px; }
.preview-pane::-webkit-scrollbar-thumb { background: var(--border-highlight); border-radius: 4px; }

.markdown-body {
  max-width: 800px;
  margin: 0 auto;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin-top: 1.5em; margin-bottom: 0.5em; color: var(--text-main); }
.markdown-body p { margin-bottom: 1em; color: rgba(255,255,255,0.85); line-height: 1.7; }
.markdown-body a { color: var(--text-link); text-decoration: none; border-bottom: 1px solid transparent; transition: var(--transition); }
.markdown-body a:hover { border-bottom-color: var(--text-link); }

/* WikiLinks style */
.markdown-body a.internal-link {
  color: var(--text-wikilink);
  background: rgba(34, 211, 238, 0.1);
  padding: 0 4px;
  border-radius: 4px;
}
.markdown-body a.internal-link.missing {
  color: var(--text-muted);
  text-decoration: line-through;
  opacity: 0.7;
}

.markdown-body ul, .markdown-body ol { margin-bottom: 1em; padding-left: 2em; color: rgba(255,255,255,0.85); }
.markdown-body li { margin-bottom: 0.25em; }
.markdown-body blockquote { border-left: 3px solid var(--primary); margin: 0 0 1em 0; padding-left: 1em; color: var(--text-muted); }
.markdown-body code { font-family: var(--font-mono); background: rgba(0,0,0,0.3); padding: 0.2em 0.4em; border-radius: 4px; font-size: 0.85em; }
.markdown-body pre { background: rgba(0,0,0,0.5); padding: 1em; border-radius: 8px; overflow-x: auto; border: 1px solid var(--border-color); margin-bottom: 1em; }
.markdown-body pre code { background: none; padding: 0; }
.markdown-body img { max-width: 100%; border-radius: 8px; }

/* Context Panel (Backlinks) */
.context-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 40vh;
  border-radius: 0;
  border-top: 1px solid var(--border-color);
  border-left: none; border-right: none; border-bottom: none;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s;
  z-index: 10;
}
.context-panel.collapsed { transform: translateY(calc(100% - 45px)); }

.context-header {
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.context-header h3 { font-size: 0.9rem; color: var(--secondary); }
.collapse-icon { transition: transform 0.3s; }
.collapsed .collapse-icon { transform: rotate(180deg); }

.backlink-list {
  padding: 0 1.5rem 1.5rem;
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.backlink-list::-webkit-scrollbar { width: 4px; }
.backlink-list::-webkit-scrollbar-thumb { background: var(--border-highlight); border-radius: 4px; }

.backlink-item {
  background: rgba(0,0,0,0.2);
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
}
.backlink-item:hover { border-color: var(--border-color); background: rgba(255,255,255,0.05); }
.backlink-title { font-weight: 500; font-size: 0.85rem; color: var(--primary); margin-bottom: 0.25rem; }
.backlink-context { font-size: 0.8rem; color: var(--text-muted); font-family: var(--font-mono); }

/* Graph Overlay */
.graph-overlay {
  position: fixed;
  inset: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}
.graph-overlay.hidden { display: none !important; }

.overlay-title { padding: 1.5rem; border-bottom: 1px solid var(--border-color); }
.close-overlay {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  font-size: 2rem;
  color: var(--text-muted);
}
.close-overlay:hover { color: white; }

.network-container {
  flex: 1;
  background: rgba(0,0,0,0.5);
}

/* Tooltips */
.tooltip { position: relative; }
.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-5px);
  background: var(--text-main);
  color: #000;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-size: 0.7rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.tooltip:hover::after { opacity: 1; transform: translateX(-50%) translateY(-10px); }

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-main);
  color: #000;
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  z-index: 2000;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s;
}
.toast.hidden { transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none; }

/* Responsive */
@media (max-width: 768px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--border-color); max-height: 40vh; }
  .hidden-mobile { display: none; }
  .page-title-input { width: 100%; }
}
