/* ─── Variables ───────────────────────────────────────────── */
:root {
  --module-bar-w: 64px;
  --side-panel-w: 268px;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #3b82f6;
  --sidebar-hover: #1e293b;
  --panel-bg: #ffffff;
  --panel-border: #e2e8f0;
  --panel-text: #475569;
  --panel-text-strong: #1e293b;
  --content-bg: #f8fafc;
  --note-bg: #ffffff;
  --accent: #3b82f6;
  --accent-light: #eff6ff;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
  --transition: 200ms ease;
  --st-bg: #0f172a;
}

/* ─── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--content-bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

button { background: none; border: none; cursor: pointer; }
a { color: var(--accent); }
svg { display: block; }

/* ─── App Layout ──────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--module-bar-w) var(--side-panel-w) 1fr;
  grid-template-rows: 100vh;
  height: 100vh;
  transition: grid-template-columns var(--transition);
}

.app.panel-hidden {
  grid-template-columns: var(--module-bar-w) 0 1fr;
}

/* ─── Module Bar ──────────────────────────────────────────── */
.module-bar {
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  z-index: 10;
  border-right: 1px solid rgba(255,255,255,.05);
}

.site-logo {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sidebar-active);
  margin-bottom: 16px;
  flex-shrink: 0;
}

.site-logo svg { width: 22px; height: 22px; }

.module-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 0 8px;
}

.module-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  padding: 10px 4px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  transition: color var(--transition), background var(--transition);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .3px;
}

.module-btn svg { width: 18px; height: 18px; }

.module-btn:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}

.module-btn.active {
  background: rgba(59, 130, 246, .15);
  color: var(--sidebar-active);
}

/* ─── Side Panel ──────────────────────────────────────────── */
.side-panel {
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition), opacity var(--transition);
}

.side-panel.hidden {
  width: 0;
  opacity: 0;
  pointer-events: none;
}

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

.panel-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.icon-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: color var(--transition), background var(--transition);
}

.icon-btn:hover { background: var(--panel-border); color: var(--text); }
.icon-btn svg { width: 14px; height: 14px; }

/* ─── Note Tree ───────────────────────────────────────────── */
.note-tree {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
}

.note-tree::-webkit-scrollbar { width: 4px; }
.note-tree::-webkit-scrollbar-thumb { background: var(--panel-border); border-radius: 2px; }

.tree-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 20px 16px;
  color: var(--text-muted);
  font-size: 13px;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--panel-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

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

.tree-empty, .tree-error {
  padding: 20px 16px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

.tree-error { color: #ef4444; }

/* Category row */
.tree-category-header {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding-right: 8px;
  cursor: pointer;
  border-radius: 0;
  transition: background var(--transition);
  user-select: none;
}

.tree-category-header:hover { background: #f1f5f9; }

.tree-arrow {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tree-arrow svg { width: 10px; height: 10px; }
.tree-arrow.open { transform: rotate(90deg); }

.tree-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tree-icon svg { width: 13px; height: 13px; }

.folder-icon { color: #f59e0b; }
.file-icon { color: var(--text-muted); }

.tree-category-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--panel-text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Children wrapper */
.tree-children {
  overflow: hidden;
  max-height: 0;
  transition: max-height 250ms ease;
}

.tree-children.open { max-height: 9999px; }

/* Note item */
.tree-note {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding-right: 8px;
  cursor: pointer;
  border-radius: 0;
  transition: background var(--transition);
  user-select: none;
}

.tree-note:hover { background: #f1f5f9; }

.tree-note.active {
  background: var(--accent-light);
}

.tree-note.active .file-icon { color: var(--accent); }
.tree-note.active .tree-note-label { color: var(--accent); font-weight: 500; }

.tree-note-label {
  font-size: 13px;
  color: var(--panel-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: capitalize;
}

/* ─── Main Content ────────────────────────────────────────── */
.main-content {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--content-bg);
}

.view {
  display: none;
  flex: 1;
  overflow: hidden;
}

.view.active { display: flex; flex-direction: column; }

/* ─── Welcome State ───────────────────────────────────────── */
.welcome-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-muted);
  padding: 40px;
}

.welcome-icon {
  width: 64px;
  height: 64px;
  color: #cbd5e1;
}

.welcome-icon svg { width: 100%; height: 100%; }

.welcome-state h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.welcome-state p {
  font-size: 14px;
  color: var(--text-muted);
}

/* ─── Note Content ────────────────────────────────────────── */
.note-content {
  flex: 1;
  overflow-y: auto;
  padding: 40px max(40px, calc((100% - 720px) / 2));
  background: var(--content-bg);
}

.note-content::-webkit-scrollbar { width: 5px; }
.note-content::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.note-header {
  margin-bottom: 32px;
}

.note-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.breadcrumb-item {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 2px 8px;
  border-radius: 20px;
}

.breadcrumb-sep {
  font-size: 11px;
  color: #cbd5e1;
}

.note-title {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  text-transform: capitalize;
}

/* ─── Markdown Body ───────────────────────────────────────── */
.markdown-body {
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-weight: 650;
  line-height: 1.3;
  margin: 1.8em 0 .6em;
  color: var(--text);
}

.markdown-body h1 { font-size: 28px; }
.markdown-body h2 {
  font-size: 20px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--panel-border);
}
.markdown-body h3 { font-size: 17px; }
.markdown-body h4 { font-size: 15px; color: var(--text-muted); }

.markdown-body p { margin: .9em 0; }

.markdown-body a { color: var(--accent); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }

.markdown-body ul, .markdown-body ol {
  padding-left: 1.4em;
  margin: .8em 0;
}

.markdown-body li { margin: .3em 0; }

.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.2em 0;
  padding: 10px 16px;
  background: var(--accent-light);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted);
}

.markdown-body code {
  font-family: 'JetBrains Mono', monospace;
  font-size: .85em;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: #be185d;
}

.markdown-body pre {
  margin: 1.2em 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--panel-border);
}

.markdown-body pre code {
  padding: 16px 20px;
  font-size: .875em;
  display: block;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2em 0;
  font-size: 14px;
}

.markdown-body th, .markdown-body td {
  border: 1px solid var(--panel-border);
  padding: 8px 12px;
  text-align: left;
}

.markdown-body th {
  background: #f8fafc;
  font-weight: 600;
}

.markdown-body tr:hover td { background: #fafafa; }

.markdown-body img {
  max-width: 100%;
  border-radius: var(--radius);
  margin: 1em 0;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--panel-border);
  margin: 2em 0;
}

.note-load-error {
  padding: 20px;
  color: #ef4444;
  font-size: 14px;
  background: #fef2f2;
  border-radius: var(--radius);
  border: 1px solid #fecaca;
}

/* ─── Skill Tree View ─────────────────────────────────────── */
#skill-tree-view {
  /* Fixed position bypasses the broken flex/grid height chain */
  position: fixed !important;
  inset: 0;
  left: var(--module-bar-w);
  background: #ffffff;
  display: none;
  flex-direction: column;
  align-items: center;
  overflow: auto;
  z-index: 5;
  padding: 40px 20px 60px;
}

#skill-tree-view.active {
  display: flex;
}

#skill-tree-container {
  width: 100%;
  max-width: 900px;
}

/* Legend */
.st-legend {
  position: absolute;
  top: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.st-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
}

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


/* ─── Note TOC ────────────────────────────────────────────── */
.note-toc {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.toc-back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 1px solid var(--panel-border);
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
  text-align: left;
}

.toc-back-btn:hover { background: #f1f5f9; color: var(--text); }
.toc-back-btn svg { width: 13px; height: 13px; }

#toc-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 0;
}

#toc-nav::-webkit-scrollbar { width: 4px; }
#toc-nav::-webkit-scrollbar-thumb { background: var(--panel-border); border-radius: 2px; }

.toc-item {
  display: block;
  font-size: 12.5px;
  color: var(--panel-text);
  text-decoration: none;
  padding: 4px 14px;
  line-height: 1.5;
  border-left: 2px solid transparent;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-item:hover {
  color: var(--accent);
  background: var(--accent-light);
  border-left-color: var(--accent);
  text-decoration: none;
}

.toc-item.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

.toc-h1 { padding-left: 14px; font-weight: 600; color: var(--panel-text-strong); }
.toc-h2 { padding-left: 22px; }
.toc-h3 { padding-left: 30px; font-size: 12px; color: var(--text-muted); }
.toc-h4 { padding-left: 38px; font-size: 11.5px; color: var(--text-muted); }

.toc-empty {
  padding: 16px 14px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ─── Utilities ───────────────────────────────────────────── */
.hidden { display: none !important; }
