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

:root {
    --bg-dark: #0d1117;
    --bg-panel: #161b22;
    --bg-node: #21262d;
    --border-color: #30363d;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --success: #3fb950;
    --danger: #f85149;
    --warning: #d29922;
    --purple: #a371f7;
    --pink: #db61a2;
    --cyan: #39c5cf;
    --orange: #db6d28;
}

body {
    font-family: 'JetBrains Mono', monospace;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    user-select: none;
}

#app {
    display: grid;
    grid-template-columns: 280px 1fr 320px;
    grid-template-rows: auto 1fr;
    height: 100vh;
}

/* Header */
#header {
    grid-column: 1 / -1;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 20px;
}

#header h1 {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent);
}

#header .controls {
    display: flex;
    gap: 10px;
    margin-left: auto;
}

.btn {
    background: var(--bg-node);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

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

.btn.primary {
    background: var(--accent);
    color: var(--bg-dark);
    border-color: var(--accent);
}

.btn.primary:hover {
    background: var(--accent-hover);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.project-select {
    background: var(--bg-node);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    min-width: 150px;
}

.project-select:hover {
    border-color: var(--accent);
}

.project-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* File Tree Panel */
#fileTree {
    background: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    padding: 12px;
    overflow-y: auto;
}

#fileTree h3 {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    margin-bottom: 2px;
}

.file-item:hover {
    background: var(--bg-node);
}

.file-item.active {
    background: rgba(88, 166, 255, 0.15);
    color: var(--accent);
}

.file-item .icon {
    font-size: 14px;
}

.file-item.html .icon { color: var(--orange); }
.file-item.css .icon { color: var(--purple); }
.file-item.js .icon { color: var(--warning); }
.file-item.external .icon { color: var(--text-secondary); }

.file-item .status {
    margin-left: auto;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
    background: var(--bg-dark);
}

.file-item .status.parsed { color: var(--success); }
.file-item .status.pending { color: var(--text-secondary); }
.file-item .status.error { color: var(--danger); }

/* Canvas Area */
#canvasArea {
    position: relative;
    background:
        linear-gradient(rgba(48, 54, 61, 0.3) 1px, transparent 1px),
        linear-gradient(90deg, rgba(48, 54, 61, 0.3) 1px, transparent 1px);
    background-size: 25px 25px;
    overflow: hidden;
    cursor: grab;
}

#canvasArea:active {
    cursor: grabbing;
}

#svgLayer, #svgLayerTop {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
}

#svgLayer { z-index: 5; }
#svgLayerTop { z-index: 15; }

#nodeLayer {
    position: absolute;
    left: 0;
    top: 0;
    width: 10000px;
    height: 10000px;
    z-index: 10;
}

/* Nodes */
.node {
    position: absolute;
    background: var(--bg-node);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 6px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: move;
    min-width: 120px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.node:hover {
    border-color: var(--accent);
}

.node.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.3);
}

.node.dragging {
    opacity: 0.8;
    z-index: 100;
}

.node.html { border-color: var(--orange); }
.node.css { border-color: var(--purple); }
.node.js { border-color: var(--warning); }
.node.function { border-color: var(--cyan); }
.node.external { border-color: var(--text-secondary); border-style: dashed; }

.node-icon {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
}

.node.html .node-icon { background: rgba(219, 109, 40, 0.2); }
.node.css .node-icon { background: rgba(163, 113, 247, 0.2); }
.node.js .node-icon { background: rgba(210, 153, 34, 0.2); }
.node.function .node-icon { background: rgba(57, 197, 207, 0.2); }
.node.external .node-icon { background: rgba(139, 148, 158, 0.2); }

.node-label {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

/* Container nodes */
.node.is-container {
    flex-direction: column;
    align-items: stretch;
    padding: 4px;
    min-width: 140px;
}

.node.is-container .node-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 4px;
}

.node.is-container .node-contents {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    min-height: 30px;
    /* No max-height - show all functions */
}

.node.contained {
    position: relative !important;
    left: auto !important;
    top: auto !important;
    min-width: auto;
    padding: 3px 6px;
    font-size: 10px;
    cursor: pointer;
    transition: background 0.15s;
}

.node.contained:hover {
    background: rgba(255, 255, 255, 0.1);
}

.node.contained.selected {
    background: rgba(88, 166, 255, 0.2);
    border-color: var(--accent);
}

.node.contained .node-icon {
    width: 18px;
    height: 18px;
    font-size: 10px;
}

.node.contained .node-label {
    font-size: 10px;
    max-width: 100px;
}

/* SVG Lines */
.hierarchy-line {
    fill: none;
    stroke: var(--border-color);
    stroke-width: 2;
}

.call-line {
    fill: none;
    stroke: var(--success);
    stroke-width: 2;
    opacity: 0.8;
}

.call-line.incoming {
    stroke: var(--pink);
}

.call-arrow {
    fill: var(--success);
    opacity: 0.8;
}

.call-arrow.incoming {
    fill: var(--pink);
}

/* Info Panel */
#infoPanel {
    background: var(--bg-panel);
    border-left: 1px solid var(--border-color);
    padding: 16px;
    overflow-y: auto;
}

#infoPanel h3 {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.info-section {
    margin-bottom: 20px;
}

.info-section h4 {
    font-size: 12px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.info-item {
    font-size: 11px;
    color: var(--text-secondary);
    padding: 4px 0;
    border-bottom: 1px solid var(--border-color);
}

.info-item:last-child {
    border-bottom: none;
}

.info-item .label {
    color: var(--text-secondary);
}

.info-item .value {
    color: var(--text-primary);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stat-box {
    background: var(--bg-node);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    text-align: center;
}

.stat-box .number {
    font-size: 24px;
    font-weight: 600;
    color: var(--accent);
}

.stat-box .label {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Log area */
#logArea {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 10px;
}

.log-entry {
    padding: 2px 0;
    color: var(--text-secondary);
}

.log-entry.info { color: var(--accent); }
.log-entry.success { color: var(--success); }
.log-entry.warning { color: var(--warning); }
.log-entry.error { color: var(--danger); }

/* Loading overlay */
#loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(13, 17, 23, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    flex-direction: column;
    gap: 20px;
}

#loading.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#loading p {
    color: var(--text-secondary);
    font-size: 14px;
}