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

:root {
  --bg: #0a0a0a;
  --surface: #111;
  --surface2: #1a1a1a;
  --border: #252525;
  --border-strong: #333;
  --text: #e8e8e8;
  --text-muted: #666;
  --accent: #0db7ed;
  --accent-hover: #1dd4ff;
  --gold: #f5c518;
  --start: #00ff88;
  --end: #ff4444;
  --radius: 8px;
  --sidebar-w: 256px;
  --panel-size: 340px;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: Inter, system-ui, sans-serif; font-size: 13px; overflow: hidden; }

#app { display: flex; height: 100vh; }

/* ── Left sidebar ─────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border-strong);
  display: flex; flex-direction: column; overflow: hidden; z-index: 10;
}

#sidebar-header { padding: 16px 14px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
#sidebar-header h1 { font-size: 13px; font-weight: 600; color: var(--accent); }
#sidebar-header p { font-size: 11px; color: var(--text-muted); margin-top: 3px; line-height: 1.4; }

#search-wrap { padding: 10px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
#search {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 10px; color: var(--text);
  font-size: 12px; outline: none; transition: border-color .15s;
}
#search::placeholder { color: var(--text-muted); }
#search:focus { border-color: var(--accent); }

#controls { padding: 8px 14px; border-bottom: 1px solid var(--border); display: flex; gap: 5px; flex-wrap: wrap; flex-shrink: 0; }
.btn {
  padding: 5px 9px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); font-size: 11px; cursor: pointer;
  transition: all .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.active { background: var(--gold); border-color: var(--gold); color: #000; font-weight: 600; }
.btn.gold:hover { border-color: var(--gold); color: var(--gold); }

#stats { padding: 8px 14px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; flex-shrink: 0; }
.stat { text-align: center; flex: 1; }
.stat-num { font-size: 15px; font-weight: 700; color: var(--accent); line-height: 1; }
.stat-label { font-size: 9px; color: var(--text-muted); margin-top: 2px; text-transform: uppercase; letter-spacing: .5px; }

/* Learning path rail */
#lp-rail { border-bottom: 1px solid var(--border); flex-shrink: 0; max-height: 230px; display: flex; flex-direction: column; }
#lp-rail h3, #categories h3 { font-size: 9px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-muted); padding: 8px 14px 5px; flex-shrink: 0; }
#lp-steps { overflow-y: auto; padding: 0 8px 6px; }

.lp-step {
  display: flex; align-items: center; gap: 7px; padding: 4px 6px;
  border-radius: 5px; cursor: pointer; transition: background .12s;
  margin-bottom: 1px; border-left: 2px solid transparent;
}
.lp-step:hover { background: var(--surface2); }
.lp-step.active { background: var(--surface2); border-left-color: var(--gold); }
.lp-step.start { border-left-color: var(--start); }
.lp-step.end   { border-left-color: var(--end); }
.lp-step.start.active { background: #00ff8808; }
.lp-step.end.active   { background: #ff444408; }

.lp-num {
  width: 16px; height: 16px; border-radius: 50%; background: var(--gold);
  color: #000; font-size: 8px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.lp-step.start .lp-num { background: var(--start); }
.lp-step.end   .lp-num { background: var(--end); }
.lp-label { font-size: 11px; line-height: 1.2; }
.lp-step:hover .lp-label { color: var(--gold); }

/* Category filters */
#categories { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 8px; }
.cat-item { display: flex; align-items: center; gap: 7px; padding: 4px 14px; cursor: pointer; transition: background .12s; }
.cat-item:hover { background: var(--surface2); }
.cat-item.hidden { opacity: 0.3; }
.cat-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.cat-name { flex: 1; font-size: 11px; }
.cat-count { font-size: 10px; color: var(--text-muted); }

/* ── Content area (graph + handle + panel) ──────── */
#content-area {
  flex: 1; display: flex; flex-direction: row;
  overflow: hidden; min-width: 0;
}
#content-area.layout-bottom { flex-direction: column; }

/* ── Graph container ─────────────────────────────── */
#graph-container { flex: 1; position: relative; overflow: hidden; background: var(--bg); min-width: 0; min-height: 0; }
#graph-3d { width: 100%; height: 100%; }

/* Loading */
#loading {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: var(--bg); z-index: 200; gap: 12px;
}
#loading p { color: var(--text-muted); font-size: 12px; }
.spinner { width: 30px; height: 30px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Resize handle ───────────────────────────────── */
#resize-handle {
  display: none;
  flex-shrink: 0;
  width: 5px;
  background: var(--border-strong);
  cursor: col-resize;
  position: relative;
  transition: background .15s;
  z-index: 20;
}

#resize-handle:hover,
#resize-handle.dragging { background: var(--accent); }

/* Grip dots — vertical (right mode) */
#resize-handle::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 2px; height: 28px;
  background: repeating-linear-gradient(
    to bottom,
    var(--text-muted) 0px, var(--text-muted) 2px,
    transparent 2px, transparent 5px
  );
  border-radius: 2px;
  opacity: 0.6;
}

/* Horizontal mode (bottom layout) */
#content-area.layout-bottom #resize-handle {
  width: auto; height: 5px;
  cursor: row-resize;
}

#content-area.layout-bottom #resize-handle::after {
  width: 28px; height: 2px;
  background: repeating-linear-gradient(
    to right,
    var(--text-muted) 0px, var(--text-muted) 2px,
    transparent 2px, transparent 5px
  );
}

/* ── Doc panel ───────────────────────────────────── */
#doc-panel {
  display: none;
  flex-shrink: 0;
  width: var(--panel-size);
  background: var(--surface);
  border-left: 2px solid var(--border-strong);
  flex-direction: column;
  overflow: hidden;
}
#doc-panel.visible { display: flex; }

/* Bottom layout overrides */
#content-area.layout-bottom #doc-panel {
  width: 100%;
  height: var(--panel-size);
  border-left: none;
  border-top: 2px solid var(--border-strong);
}

/* Bottom layout: arrange content horizontally */
#content-area.layout-bottom #doc-panel > * { flex-shrink: 0; }
#content-area.layout-bottom #doc-panel {
  flex-direction: row;
  overflow: hidden;
}
#content-area.layout-bottom #doc-header {
  width: 260px; min-width: 260px; border-right: 1px solid var(--border); border-bottom: none;
  flex-direction: column; justify-content: flex-start;
}
#content-area.layout-bottom .doc-block {
  border-bottom: none; border-right: 1px solid var(--border);
  overflow-y: auto; min-width: 160px;
}
#content-area.layout-bottom #doc-excerpt-wrap { flex: 1; min-width: 200px; }
#content-area.layout-bottom #doc-related-wrap { min-width: 180px; max-width: 220px; }

/* Doc header */
#doc-header {
  padding: 14px 14px 12px;
  border-bottom: 2px solid var(--border-strong);
  flex-shrink: 0; position: relative;
  display: flex; flex-direction: column; gap: 4px;
}

#doc-close {
  position: absolute; top: 10px; right: 10px; background: none;
  border: 1px solid var(--border); cursor: pointer; color: var(--text-muted);
  font-size: 12px; padding: 2px 7px; border-radius: 4px; line-height: 1.4;
  transition: all .12s;
}
#doc-close:hover { color: var(--text); border-color: var(--text-muted); }

#doc-step-badge {
  display: none; font-size: 9px; font-weight: 700; padding: 2px 7px;
  border-radius: 4px; letter-spacing: .6px; text-transform: uppercase; width: fit-content;
}

#doc-title { font-size: 13px; font-weight: 600; line-height: 1.4; margin-right: 28px; }
#doc-cat { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.cat-dot-inline { display: inline-block; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

#doc-open {
  display: block; padding: 6px 10px; background: var(--accent); color: #000;
  border-radius: 5px; text-decoration: none; font-size: 11px; font-weight: 700;
  text-align: center; margin-top: 4px;
}
#doc-open:hover { background: var(--accent-hover); }

/* Doc blocks */
.doc-block { padding: 10px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.doc-block-label { font-size: 9px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-muted); margin-bottom: 7px; }

/* Headings pills */
#doc-headings { display: flex; flex-wrap: wrap; gap: 4px; }
.heading-pill {
  font-size: 10px; padding: 3px 7px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 4px; color: var(--text-muted);
}

/* Excerpt */
#doc-excerpt-wrap { flex: 1; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
#doc-excerpt { font-size: 12px; line-height: 1.7; color: var(--text-muted); word-break: break-word; }
#doc-excerpt code {
  font-family: "SF Mono", Consolas, monospace; font-size: 11px;
  background: var(--surface2); border: 1px solid var(--border);
  padding: 1px 4px; border-radius: 3px; color: var(--accent);
}
#doc-excerpt strong { color: var(--text); font-weight: 600; }

#doc-code-badge {
  display: none; font-size: 10px; padding: 2px 8px;
  background: #0db7ed12; border: 1px solid #0db7ed35;
  color: var(--accent); border-radius: 4px; width: fit-content;
}

/* Related */
#doc-related { display: flex; flex-direction: column; gap: 3px; }
.related-pill {
  display: flex; align-items: center; gap: 7px; padding: 5px 8px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 5px; cursor: pointer; text-align: left;
  font-size: 11px; color: var(--text); transition: all .12s; width: 100%;
}
.related-pill:hover { border-color: var(--accent); color: var(--accent); }

/* Scrollbars */
::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
