* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #fafafa;
  --card: #fff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-light: #718096;
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --sidebar-w: 260px;
}

body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--card); border-right: 1px solid var(--border); padding: 1rem; position: fixed; height: 100vh; overflow-y: auto; }
.main { margin-left: var(--sidebar-w); flex: 1; padding: 2rem; max-width: 900px; }
.main:has(.graph-wrapper) { max-width: none; }

/* Sidebar */
.sidebar h1 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.sidebar h1 a { color: var(--text); text-decoration: none; }
.sidebar .subtitle { font-size: 0.75rem; color: var(--text-light); margin-bottom: 1.5rem; }
.nav-section { margin-bottom: 1rem; }
.nav-section h3 { font-size: 0.8rem; text-transform: uppercase; color: var(--text-light); margin-bottom: 0.3rem; letter-spacing: 0.05em; }
.nav-link { display: block; padding: 0.3rem 0.5rem; color: var(--text); text-decoration: none; border-radius: 4px; font-size: 0.9rem; }
.nav-link:hover, .nav-link.active { background: var(--primary-light); color: var(--primary); }
.nav-count { font-size: 0.75rem; color: var(--text-light); }

/* Search */
.search-box { width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; margin-bottom: 1rem; }
.search-box:focus { outline: none; border-color: var(--primary); }

/* Cards */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin-bottom: 1rem; }
.card:hover { border-color: var(--primary); }
.card h3 a { color: var(--text); text-decoration: none; }
.card h3 a:hover { color: var(--primary); }

/* Badges */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.7rem; font-weight: 600; }
.badge-complete { background: #d1fae5; color: var(--success); }
.badge-draft { background: #fef3c7; color: var(--warning); }
.badge-pending-verification { background: #fee2e2; color: var(--danger); }
.badge-needs-review { background: #e0e7ff; color: #4338ca; }
.badge-category { background: var(--primary-light); color: var(--primary); }

.tags { margin-top: 0.3rem; }
.tag { display: inline-block; background: #f1f5f9; color: var(--text-light); padding: 0.1rem 0.4rem; border-radius: 4px; font-size: 0.7rem; margin-right: 0.3rem; }

/* Content */
.content h1 { font-size: 1.8rem; margin-bottom: 1rem; }
.content h2 { font-size: 1.4rem; margin: 1.5rem 0 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
.content h3 { font-size: 1.1rem; margin: 1rem 0 0.5rem; }
.content p { margin-bottom: 0.8rem; }
.content ul, .content ol { margin-bottom: 0.8rem; padding-left: 1.5rem; }
.content table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; font-size: 0.9rem; }
.content th, .content td { border: 1px solid var(--border); padding: 0.5rem; text-align: left; }
.content th { background: #f8fafc; font-weight: 600; }
.content code { background: #f1f5f9; padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.85em; }
.content pre { background: #1e293b; color: #e2e8f0; padding: 1rem; border-radius: 6px; overflow-x: auto; margin-bottom: 1rem; }
.content pre code { background: none; color: inherit; }
.content blockquote { border-left: 3px solid var(--primary); padding: 0.5rem 1rem; margin-bottom: 1rem; background: #f8fafc; }

/* Wikilinks */
.wikilink { color: var(--primary); text-decoration: none; border-bottom: 1px dashed var(--primary); }
.wikilink:hover { border-bottom-style: solid; }
.wikilink-broken { color: var(--danger); border-bottom: 1px dashed var(--danger); cursor: help; }

/* Callouts */
.callout { border-radius: 6px; padding: 1rem; margin-bottom: 1rem; border-left: 4px solid; }
.callout-title { font-weight: 600; margin-bottom: 0.3rem; }
.callout-tip { background: #f0fdf4; border-color: var(--success); }
.callout-warning { background: #fffbeb; border-color: var(--warning); }
.callout-info { background: #eff6ff; border-color: var(--primary); }
.callout-note { background: #f8fafc; border-color: #64748b; }

/* Meta bar */
.meta-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.meta-bar .updated { font-size: 0.8rem; color: var(--text-light); margin-left: auto; }

/* Edit */
.editor { width: 100%; min-height: 400px; font-family: "Cascadia Code", "Fira Code", monospace; font-size: 0.9rem; padding: 1rem; border: 1px solid var(--border); border-radius: 6px; resize: vertical; line-height: 1.6; }
.btn { padding: 0.5rem 1rem; border-radius: 6px; border: none; cursor: pointer; font-size: 0.9rem; font-weight: 500; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #f1f5f9; color: var(--text); }
.btn-secondary:hover { background: #e2e8f0; }
.toolbar { display: flex; gap: 0.5rem; margin-bottom: 1rem; }

/* Dashboard stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; text-align: center; }
.stat-number { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.8rem; color: var(--text-light); }

/* Page header with action button */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.page-header h1 { margin: 0; }

/* Forms */
.form-section { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1.5rem; margin-bottom: 1rem; }
.form-section h2 { font-size: 1.1rem; margin: 0 0 1rem; padding: 0; border: none; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.8rem; }
.form-grid label { display: flex; flex-direction: column; font-size: 0.8rem; font-weight: 600; color: var(--text-light); gap: 0.3rem; }
.form-grid input, .form-grid select { padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; color: var(--text); background: #fff; }
.form-grid input:focus, .form-grid select:focus { outline: none; border-color: var(--primary); }

/* Danger button */
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }

/* Graph */
.graph-toolbar { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.graph-search { padding: 0.4rem 0.75rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.85rem; width: 180px; }
.graph-search:focus { outline: none; border-color: var(--primary); }
.graph-filters { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.graph-chip { padding: 0.2rem 0.6rem; border-radius: 999px; border: 2px solid var(--chip-color, #94a3b8); background: transparent; color: var(--text); font-size: 0.75rem; cursor: pointer; transition: all 0.15s; }
.graph-chip.active { background: var(--chip-color, #94a3b8); color: #fff; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

.graph-wrapper { display: flex; gap: 0; height: calc(100vh - 8rem); }
.graph-container { position: relative; flex: 1; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px 0 0 8px; overflow: hidden; }
.graph-container svg { width: 100%; height: 100%; }
.graph-container .link { stroke: #cbd5e1; stroke-opacity: 0.6; transition: opacity 0.2s, stroke-width 0.2s; }
.graph-container .node { cursor: pointer; stroke: #fff; stroke-width: 1.5px; transition: opacity 0.2s; }
.graph-container .node:hover { stroke-width: 3px; }
.graph-container .node-label { font-size: 11px; fill: var(--text); pointer-events: none; text-anchor: middle; dominant-baseline: central; transition: opacity 0.2s; }
.graph-tooltip { position: absolute; background: var(--card); border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.75rem; font-size: 0.8rem; pointer-events: none; box-shadow: 0 2px 8px rgba(0,0,0,0.1); z-index: 10; white-space: nowrap; }
.graph-tooltip .tt-title { font-weight: 600; }
.graph-tooltip .tt-cat { font-size: 0.7rem; color: var(--text-light); }
.graph-legend { position: absolute; top: 0.75rem; right: 0.75rem; background: rgba(255,255,255,0.92); border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.75rem; font-size: 0.75rem; }
.graph-legend-item { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.2rem; }
.graph-legend-dot { width: 10px; height: 10px; border-radius: 50%; }

/* Graph side panel */
.graph-panel { width: 280px; background: var(--card); border: 1px solid var(--border); border-left: none; border-radius: 0 8px 8px 0; padding: 1rem; overflow-y: auto; position: relative; animation: panelSlide 0.2s ease; }
@keyframes panelSlide { from { width: 0; opacity: 0; padding: 0; } to { width: 280px; opacity: 1; } }
.graph-panel-close { position: absolute; top: 0.5rem; right: 0.5rem; background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-light); line-height: 1; }
.graph-panel-close:hover { color: var(--text); }
.graph-panel h3 { font-size: 1.1rem; margin: 0 0 0.5rem; padding-right: 1.5rem; }
.graph-panel h4 { font-size: 0.85rem; color: var(--text-light); margin: 0.75rem 0 0.4rem; }
.panel-meta { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; }
.panel-link-count { font-size: 0.75rem; color: var(--text-light); }
.panel-view-btn { display: inline-block; margin-bottom: 0.5rem; text-decoration: none; text-align: center; }
.panel-links { list-style: none; padding: 0; margin: 0; }
.panel-link-item { display: flex; align-items: center; gap: 0.4rem; padding: 0.4rem 0.5rem; border-radius: 5px; cursor: pointer; font-size: 0.85rem; }
.panel-link-item:hover { background: var(--primary-light); }
.panel-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.panel-link-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-link-cat { font-size: 0.7rem; color: var(--text-light); flex-shrink: 0; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
