@@ -382,7 +382,22 @@ fun LogViewerScreen(
382382 logEntry = logEntry,
383383 isExpanded = expandedLogKey == key,
384384 onClick = {
385− expandedLogKey = if (expandedLogKey == key) null else key
385+ if (expandedLogKey == key) {
386+ // Collapsing: if the top of the entry is scrolled
387+ // above the viewport, jump to it so the user sees
388+ // the collapsed card instead of a random position.
389+ val itemInfo = listState.layoutInfo.visibleItemsInfo
390+ .firstOrNull { it.index == index }
391+ val needsScroll = itemInfo == null || itemInfo.offset < 0
392+ expandedLogKey = null
393+ if (needsScroll) {
394+ scope.launch {
395+ listState.animateScrollToItem(index)
396+ }
397+ }
398+ } else {
399+ expandedLogKey = key
400+ }
386401 },
387402 clipboardManager = clipboard,
388403 onCopied = {