#graph {
	width: 100%;
	height: 600px;
	border-radius: 12px;
	overflow: hidden;
	background-image: radial-gradient(
		circle,
		var(--text-muted) 0.5px,
		transparent 0.5px
	);
	background-size: 16px 16px;
}

/* Loading */
#loading {
	display: flex;
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	align-items: center;
	gap: 12px;
	color: var(--text-muted);
	font-size: 14px;
	z-index: 10;
}

#loading .spinner {
	width: 20px;
	height: 20px;
	border: 2px solid var(--border);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

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

/* Stats badge */
#stats {
	position: fixed;
	top: 12px;
	left: 12px;
	font-size: 12px;
	color: var(--text-muted);
	z-index: 10;
	padding: 6px 12px;
	background: var(--bg-secondary);
	border: 1px solid var(--border);
	border-radius: 10px;
	box-shadow:
		0 4px 6px -1px rgba(0, 0, 0, 0.1),
		0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

/* Popup */
#popup {
	display: none;
	position: fixed;
	background: var(--bg-secondary);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 14px;
	box-shadow:
		0 10px 15px -3px rgba(0, 0, 0, 0.1),
		0 4px 6px -4px rgba(0, 0, 0, 0.1);
	z-index: 100;
	min-width: 220px;
	max-width: 360px;
	max-height: 300px;
	overflow-y: auto;
}

#popup-type {
	display: inline-block;
	font-size: 10px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	padding: 2px 8px;
	border-radius: 6px;
	margin-bottom: 8px;
}

#popup-type.document {
	background: rgba(59, 115, 184, 0.15);
	color: #3b73b8;
}
#popup-type.memory {
	background: rgba(59, 115, 184, 0.15);
	color: #3b73b8;
}
#popup-type.forgotten {
	background: rgba(239, 68, 68, 0.15);
	color: #ef4444;
}
#popup-type.latest {
	background: rgba(16, 185, 129, 0.15);
	color: #10b981;
}

#popup-title {
	font-weight: 600;
	font-size: 13px;
	margin-bottom: 6px;
	color: var(--text);
	word-wrap: break-word;
	line-height: 1.4;
}

#popup-content {
	font-size: 12px;
	color: var(--text-muted);
	margin-bottom: 6px;
	word-wrap: break-word;
	line-height: 1.5;
}

#popup-meta {
	font-size: 11px;
	color: var(--text-muted);
	opacity: 0.7;
}

/* Controls - vertical stack, bottom left, above legend */
#controls {
	position: fixed;
	bottom: 72px;
	left: 16px;
	display: flex;
	flex-direction: column;
	gap: 4px;
	z-index: 15;
}

#controls > button {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	background: var(--bg-secondary);
	border: 1px solid var(--border);
	border-radius: 9999px;
	color: var(--text-muted);
	font-size: 12px;
	cursor: pointer;
	padding: 8px 12px;
	white-space: nowrap;
	box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
	transition: opacity 0.15s;
	min-width: 0;
}

#controls > button:hover {
	opacity: 0.85;
}

#controls > button kbd {
	font-family: inherit;
	font-size: 10px;
	font-weight: 500;
	background: var(--border);
	padding: 2px 6px;
	border-radius: 4px;
	color: var(--text-muted);
}

#zoom-row {
	display: flex;
	align-items: center;
	gap: 2px;
	background: var(--bg-secondary);
	border: 1px solid var(--border);
	border-radius: 9999px;
	padding: 6px 10px;
	box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

#zoom-row button {
	width: 20px;
	height: 20px;
	padding: 0;
	border: 1px solid var(--border);
	border-radius: 4px;
	background: var(--bg-secondary);
	color: var(--text-muted);
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: none;
	transition: opacity 0.15s;
}

#zoom-row button:hover {
	opacity: 0.85;
}

#zoom-display {
	font-size: 12px;
	color: var(--text-muted);
	min-width: 36px;
	text-align: center;
	user-select: none;
	padding: 0 4px;
}

/* Legend - bottom left, single expandable card, 214px wide */
#legend {
	position: fixed;
	bottom: 16px;
	left: 16px;
	width: 214px;
	background: var(--bg-secondary);
	border: 1px solid var(--border);
	border-radius: 12px;
	z-index: 20;
	font-size: 12px;
	color: var(--text-muted);
	box-shadow:
		0 4px 6px -1px rgba(0, 0, 0, 0.1),
		0 2px 4px -2px rgba(0, 0, 0, 0.1);
	overflow: hidden;
}

#legend-toggle {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 12px;
	cursor: pointer;
	user-select: none;
	font-weight: 600;
	font-size: 12px;
	color: var(--text);
}

.legend-chevron {
	transition: transform 0.2s;
	transform: rotate(90deg);
}

#legend.collapsed .legend-chevron {
	transform: rotate(0deg);
}

#legend-body {
	padding: 0 12px 12px;
	overflow: hidden;
	max-height: 400px;
	transition:
		max-height 0.25s ease,
		padding 0.25s ease,
		opacity 0.2s;
	opacity: 1;
}

#legend.collapsed #legend-body {
	max-height: 0;
	padding: 0 12px;
	opacity: 0;
}

.legend-group {
	padding: 4px 0;
}

.legend-divider {
	height: 1px;
	background: var(--border);
	margin: 2px 0;
}

.legend-row {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 3px 0;
	font-size: 12px;
}

.legend-count {
	margin-left: auto;
	font-size: 11px;
	opacity: 0.7;
}

.legend-line {
	width: 18px;
	height: 0;
	border-top: 1.5px solid;
	flex-shrink: 0;
}

.legend-line.dashed {
	border-top-style: dashed;
}
