/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-dark: #1a1a2e;
  --bg-darker: #16162a;
  --bg-light: #242442;
  --accent: #e94560;
  --accent-hover: #ff6b6b;
  --text: #eee;
  --text-dim: #888;
  --border: #333;
  --tier-0: #e74c3c;
  --tier-1: #e67e22;
  --tier-2: #f1c40f;
  --tier-3: #2ecc71;
  --tier-4: #3498db;
  --tier-5: #9b59b6;
  --link: #4ecdc4;
  --link-hover: #a8e6cf;
}

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--bg-darker);
  border-bottom: 1px solid var(--border);
  gap: 2rem;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.tabs {
  display: flex;
  gap: 0.5rem;
}

.tab {
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.tab:hover {
  background: var(--bg-light);
  color: var(--text);
}

.tab.active {
  background: var(--accent);
  color: white;
}

.stats {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* Main Layout */
.main {
  flex: 1;
  overflow: hidden;
}

.tab-content {
  display: none;
  height: 100%;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
}

#tab-files.active {
  flex-direction: row;
}

.modules-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 300px;
  background: var(--bg-darker);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-box {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.search-box input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-light);
  color: var(--text);
  font-size: 0.9rem;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.file-tree {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

/* Tree Items */
.tree-item {
  user-select: none;
}

.tree-folder, .tree-file {
  display: flex;
  align-items: center;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.85rem;
  gap: 0.5rem;
}

.tree-folder:hover, .tree-file:hover {
  background: var(--bg-light);
}

.tree-file.active {
  background: var(--accent);
  color: white;
}

.tree-folder::before {
  content: '📁';
}

.tree-folder.open::before {
  content: '📂';
}

.tree-file::before {
  content: '📄';
}

.tree-file[data-ext=".h"]::before {
  content: '📋';
}

.tree-children {
  display: none;
  margin-left: 1rem;
}

.tree-children.open {
  display: block;
}

/* Content Area */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.file-header {
  padding: 0.75rem 1rem;
  background: var(--bg-light);
  border-bottom: 1px solid var(--border);
}

.file-path {
  font-family: monospace;
  font-size: 0.9rem;
  color: var(--accent);
}

.file-info {
  padding: 0.5rem 1rem;
  background: var(--bg-darker);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  display: flex;
  gap: 1.5rem;
}

.file-info .badge {
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--bg-light);
}

.code-view {
  flex: 1;
  overflow: auto;
  padding: 1rem;
  margin: 0;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  background: var(--bg-dark);
}

.code-view code {
  display: block;
  white-space: pre;
}

/* Clickable References */
.ref-link {
  color: var(--link);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  padding: 0 2px;
  border-radius: 2px;
  transition: background 0.15s;
}

.ref-link:hover {
  color: var(--link-hover);
  text-decoration-style: solid;
  background: rgba(78, 205, 196, 0.2);
}

.ref-link.type {
  text-decoration: none;
  border-bottom: 1px dashed var(--link);
}

.ref-link.type:hover {
  border-bottom-style: solid;
}

/* Syntax Highlighting */
.comment { color: #6a9955; }
.keyword { color: #569cd6; }
.type { color: #4ec9b0; }
.string { color: #ce9178; }
.number { color: #b5cea8; }
.function { color: #dcdcaa; }
.class-name { color: #4ec9b0; }
.macro { color: #c586c0; }

/* Modules Tab */
.modules-sidebar {
  width: 250px;
}

.modules-sidebar h3 {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
}

.tier-legend {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.tier-item {
  padding: 0.35rem 0.5rem;
  margin-bottom: 0.25rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

.tier-0 { background: var(--tier-0); }
.tier-1 { background: var(--tier-1); }
.tier-2 { background: var(--tier-2); color: #333; }
.tier-3 { background: var(--tier-3); color: #333; }
.tier-4 { background: var(--tier-4); }
.tier-5 { background: var(--tier-5); }

.module-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.module-item {
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.25rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  border-left: 3px solid transparent;
}

.module-item:hover {
  background: var(--bg-light);
}

.module-item.active {
  background: var(--bg-light);
}

.module-item .count {
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* Module Graph */
.modules-content {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.module-graph {
  flex: 1;
  min-height: 400px;
  background: var(--bg-darker);
  position: relative;
}

#graph-svg {
  width: 100%;
  height: 100%;
}

/* Classes Sidebar (right panel) */
.classes-sidebar {
  width: 350px;
  background: var(--bg-darker);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.classes-sidebar.hidden {
  display: none;
}

.classes-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--bg-light);
  border-bottom: 1px solid var(--border);
}

.classes-header h3 {
  font-size: 1rem;
  color: var(--accent);
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.close-btn:hover {
  background: var(--bg-dark);
  color: var(--text);
}

.module-details {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.module-details h3 {
  margin-bottom: 1rem;
  color: var(--accent);
}

.class-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.5rem;
}

.class-item {
  padding: 0.5rem 0.75rem;
  background: var(--bg-light);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
}

.class-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.class-item:hover {
  background: var(--bg-light);
  border-left: 2px solid var(--accent);
}

.class-item.active {
  background: var(--accent);
  color: white;
}

.class-item.active .class-submodule {
  color: rgba(255,255,255,0.7);
}

.class-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.class-submodule {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-family: monospace;
}

.class-name {
  font-weight: 500;
}

/* Filter info for two-module view */
.filter-info {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.filter-badge {
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
}

.filter-badge.outgoing {
  background: rgba(46, 204, 113, 0.2);
  color: #2ecc71;
  border: 1px solid #2ecc71;
}

.filter-badge.incoming {
  background: rgba(52, 152, 219, 0.2);
  color: #3498db;
  border: 1px solid #3498db;
}

/* Directional class items */
.class-item.outgoing {
  border-left: 3px solid #2ecc71;
}

.class-item.incoming {
  border-left: 3px solid #3498db;
}

.class-item .count {
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* Bottom Connections Panel */
.connections-panel {
  height: 220px;
  background: var(--bg-darker);
  border-top: 2px solid var(--accent);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.connections-panel.hidden {
  display: none;
}

.connections-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--bg-light);
  border-bottom: 1px solid var(--border);
}

.connections-panel-header h3 {
  font-size: 0.95rem;
  color: var(--accent);
}

.connections-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-content: flex-start;
}

.connections-panel-content .connection-module {
  flex: 1;
  min-width: 250px;
  max-width: 350px;
}

/* Class Connections Panel (legacy, remove) */
.class-connections {
  display: none;
}

.connections-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.connections-header h4 {
  color: var(--accent);
  font-size: 0.95rem;
}

.goto-file-btn {
  padding: 0.3rem 0.6rem;
  background: var(--bg-light);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}

.goto-file-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.no-connections {
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.85rem;
}

.connections-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.connection-module {
  background: var(--bg-darker);
  border-radius: 6px;
  overflow: hidden;
}

.connection-module-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: var(--bg-light);
}

.module-badge {
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 500;
}

.connection-count {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.connection-calls {
  padding: 0.5rem;
}

.connection-call {
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  font-family: monospace;
  border-radius: 3px;
}

.connection-call:hover {
  background: var(--bg-light);
}

.call-target {
  color: var(--link);
  font-family: monospace;
}

.call-reason {
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-top: 0.2rem;
  padding-left: 0.5rem;
  border-left: 2px solid var(--border);
}

/* Graph pan cursor */
#graph-svg {
  cursor: grab;
}

#graph-svg:active {
  cursor: grabbing;
}

/* Graph Nodes */
.graph-node {
  cursor: pointer;
}

.graph-node rect {
  rx: 6;
  ry: 6;
  stroke: #fff;
  stroke-width: 1;
}

.graph-node text {
  fill: white;
  font-size: 12px;
  font-weight: 500;
}

.graph-edge {
  stroke: #555;
  stroke-width: 1;
  fill: none;
}

.graph-edge.highlighted {
  stroke: var(--accent);
  stroke-width: 3;
}

.graph-edge.edge-outgoing {
  stroke: #2ecc71;
  stroke-width: 3;
}

.graph-edge.edge-incoming {
  stroke: #e74c3c;
  stroke-width: 3;
}

.graph-node.highlighted rect {
  stroke: var(--accent);
  stroke-width: 3;
}

.graph-node.node-selected rect {
  stroke: #2ecc71;
  stroke-width: 4;
}

.graph-node.node-selected-secondary rect {
  stroke: #3498db;
  stroke-width: 4;
}

.graph-svg-dimmed .graph-node:not(.highlighted) {
  opacity: 0.4;
}

.graph-svg-dimmed .graph-node.highlighted {
  opacity: 1;
}

.graph-svg-dimmed .graph-edge:not(.highlighted) {
  opacity: 0.2;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-darker);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #444;
}
