/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

.agent-sessions-viewer {

	flex: 1 1 auto;
	height: 100%;
	min-height: 0;

	.pane-body & .monaco-scrollable-element {
		padding: 0 6px;
	}

	.agent-sessions-workbench .pane-body & .monaco-scrollable-element {
		padding: 0 12px;
	}

	.agent-sessions-workbench .pane-body & .monaco-tree-sticky-container {
		left: 12px;
		width: calc(100% - 24px);
	}

	.monaco-list-row {
		border-radius: 6px;
	}

	/* Suppressed while selected so the selection highlight is not overpainted. */
	.monaco-list-row:not(.selected):not(.focused):not(:hover):has(.agent-session-icon.needs-input) {
		background-color: color-mix(in srgb, var(--vscode-list-warningForeground) 8%, transparent);
	}

	.monaco-list-row:not(.selected):not(.focused):not(:hover) .agent-session-chat-item.needs-input {
		background-color: color-mix(in srgb, var(--vscode-list-warningForeground) 8%, transparent);
	}

	.monaco-list-row .force-no-twistie {
		display: none !important;
	}

	.monaco-list-row .agent-session-chat-twistie {
		position: absolute;
		top: var(--vscode-spacing-size80);
		left: var(--vscode-spacing-size60);
		width: var(--vscode-spacing-size160);
		height: var(--vscode-spacing-size160);
		padding-right: 0;
		font-size: var(--vscode-codiconFontSize);
		opacity: 0;
		pointer-events: none;
		transform: none;
		z-index: 1;
	}

	.monaco-list-row:hover .agent-session-chat-twistie.collapsible {
		opacity: 1;
		pointer-events: auto;
	}

	.monaco-list-row:hover[aria-expanded] .agent-session-item .agent-session-icon {
		visibility: hidden;
	}

	.monaco-list-row.selected .agent-session-details-row {
		color: unset;

		.rendered-markdown {
			a {
				color: unset;
			}
		}
	}

	.monaco-list:focus .monaco-list-row.selected .agent-session-details-row {
		.agent-session-diff-container {
			.agent-session-diff-added,
			.agent-session-diff-removed {
				color: unset;
			}
		}
	}

.monaco-list:focus .monaco-list-row.selected .agent-session-icon > .codicon,
.monaco-list:focus .monaco-list-row.selected .agent-session-icon > .monaco-pixel-spinner {
	color: var(--vscode-list-activeSelectionForeground) !important;
}

	.monaco-list-row.selected .agent-session-item,
	.monaco-list-row.selected .agent-session-title {
		color: unset;
	}

	.monaco-list:not(:focus) .monaco-list-row.selected .agent-session-details-row {
		color: var(--vscode-descriptionForeground);
	}

	.monaco-list-row .agent-session-pinned-indicator {
		display: none;
		height: 16px;
		align-items: center;
		color: var(--vscode-descriptionForeground);
		font-size: var(--vscode-codiconFontSize-compact);
		pointer-events: none;
		margin-right: 3px;

		&.visible {
			display: flex;
		}
	}

	.monaco-list-row .agent-session-pending-voice-indicator {
		display: none;
		height: 16px;
		align-items: center;
		margin-left: 4px;
		color: var(--vscode-charts-blue);
		font-size: var(--vscode-codiconFontSize-compact);
		pointer-events: none;

		&.visible {
			display: flex;
		}
	}

	.monaco-list-row .agent-session-title-toolbar {
		/* for the absolute positioning of the toolbar below */
		position: relative;
		height: 16px;
		display: none;

		.monaco-toolbar {
			/* this is required because the overal height (including the padding needed for hover feedback) would push down the title otherwise */
			position: relative;
			right: 0;
			top: 0;
		}
	}

	/* On hover or keyboard focus: show toolbar, hide pinned indicator */
	.monaco-list-row:hover,
	.monaco-list-row.focused:not(.selected),
	.monaco-list-row.agent-session-chat-row.focused,
	.monaco-list-row.agent-session-chat-row:focus-within {

		.agent-session-pinned-indicator {
			display: none;
		}

		.agent-session-title-toolbar {
			display: block;
		}

		.agent-session-title {
			margin-right: 8px;
		}
	}

	.agent-session-item {
		display: flex;
		flex-direction: row;
		position: relative;
		padding: 8px 6px;

		&.archived {
			color: var(--vscode-descriptionForeground);
		}

		.agent-session-main-col,
		.agent-session-title-row,
		.agent-session-details-row {
			flex: 1;
			min-width: 0;
		}

		.agent-session-icon-col {
			display: flex;
			align-items: flex-start;
			line-height: 17px;

			.agent-session-icon {
				flex-shrink: 0;
				font-size: var(--vscode-codiconFontSize, 16px);
				height: 16px;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

		.agent-session-main-col {
			padding-left: 6px;
		}

		.agent-session-title-row,
		.agent-session-details-row {
			display: flex;
			align-items: center;
		}

		.agent-session-title-row {
			line-height: 17px;
			padding-bottom: 4px;
		}

		.agent-session-details-row {
			gap: 4px;
			font-size: 12px;
			line-height: 15px;
			max-height: 15px;
			color: var(--vscode-descriptionForeground);

			.agent-session-harness-icon {
				/* muted, details-row scale, so it never competes with the status icon */
				color: inherit;
				display: flex;
				align-items: center;
				align-self: center;
				flex-shrink: 0;
				font-size: var(--vscode-codiconFontSize-compact);
				line-height: 1;
			}

			.rendered-markdown {
				p {
					display: flex;
					align-items: center;
					margin: 0;

					> span.codicon {
						margin-right: 2px;
					}
				}

				a {
					color: var(--vscode-descriptionForeground);
				}
			}

			.agent-session-diff-container {
				font-variant-numeric: tabular-nums;
				overflow: hidden;
			}

			.agent-session-diff-container {
				display: flex;
				gap: 4px;

				&:not(.has-diff) {
					display: none;
				}

				.agent-session-diff-added {
					color: var(--vscode-chat-linesAddedForeground);
				}

				.agent-session-diff-removed {
					color: var(--vscode-chat-linesRemovedForeground);
				}
			}

			.agent-session-separator {
				display: none;

				&.has-separator {
					display: inline;

					&::before {
						content: '\00B7';
					}
				}
			}

			.agent-session-badge {

				p {
					overflow: hidden;
				}

				&:not(.has-badge) {
					display: none;
				}
			}
		}

		.agent-session-title,
		.agent-session-description {
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}

		.agent-session-title {
			/* push the title toolbar to the end */
			flex: 1;
		}

		.agent-session-description {
			/* size to content so following metadata stays inline after its separator */
			flex: 0 1 auto;
			min-width: 0;
		}

		.agent-session-description:empty {
			display: none;
		}

		.agent-session-description.has-separator::before {
			content: '\00B7';
			margin-right: 4px;
		}

		.agent-session-title {
			font-size: 13px;
		}

		.agent-session-status {
			display: flex;
			align-items: center;
			font-variant-numeric: tabular-nums;
			white-space: nowrap;

			&.has-separator::before {
				content: '\00B7';
				margin-right: 4px;
			}

			&.hidden {
				display: none;
			}

		}
	}

	.agent-session-item,
	.agent-session-chat-item {
		.agent-session-approval-row {
			display: none;
			align-items: flex-end;
			gap: var(--vscode-spacing-size80);
			margin-top: var(--vscode-spacing-size40);
			padding: var(--vscode-spacing-size40) var(--vscode-spacing-size80);
			box-sizing: border-box;
			border: var(--vscode-strokeThickness) solid var(--vscode-contrastBorder, var(--vscode-widget-border, transparent));
			border-radius: var(--vscode-cornerRadius-small);
			background-color: var(--vscode-editor-background);
			color: var(--vscode-editor-foreground);

			&.visible {
				display: flex;
			}

			.agent-session-approval-label {
				flex: 1;
				overflow: hidden;
				min-width: 0;

				& > .rendered-markdown,
				& > .rendered-markdown > .code,
				& > .rendered-markdown > .code > span {
					display: block;
					overflow: hidden;
				}

				.monaco-tokenized-source {
					display: block;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-size: var(--vscode-fontSize-label1);
				}
			}

			.agent-session-approval-button {
				flex-shrink: 0;

				.monaco-button {
					padding: var(--vscode-spacing-size20) var(--vscode-spacing-size100);
					font-size: var(--vscode-fontSize-label1);
					white-space: nowrap;
				}
			}
		}
	}

	.monaco-list-row[aria-expanded="true"].has-chat-children::after {
		content: '';
		position: absolute;
		top: var(--vscode-spacing-size280);
		bottom: 0;
		left: calc(var(--vscode-spacing-size60) + var(--vscode-spacing-size80));
		border-left: var(--vscode-strokeThickness) solid var(--vscode-tree-inactiveIndentGuidesStroke);
		pointer-events: none;
	}

	.agent-session-chat-item {
		display: flex;
		flex-direction: column;
		position: relative;
		box-sizing: border-box;
		min-width: 0;
		overflow: visible;
		padding: 0 var(--vscode-spacing-size60) 0 var(--vscode-spacing-size280);
		color: var(--vscode-foreground);
		font-size: var(--vscode-fontSize-body1);
		font-weight: var(--vscode-fontWeight-regular);

		&::before {
			content: '';
			position: absolute;
			top: 0;
			bottom: calc(-1 * var(--vscode-spacing-size20));
			left: calc(var(--vscode-spacing-size60) + var(--vscode-spacing-size80));
			border-left: var(--vscode-strokeThickness) solid var(--vscode-tree-inactiveIndentGuidesStroke);
		}

		&::after {
			content: '';
			position: absolute;
			top: calc(var(--vscode-spacing-size280) / 2);
			left: calc(var(--vscode-spacing-size60) + var(--vscode-spacing-size80));
			width: var(--vscode-spacing-size100);
			border-top: var(--vscode-strokeThickness) solid var(--vscode-tree-inactiveIndentGuidesStroke);
		}

		&.last-chat {
			&::before {
				bottom: calc(100% - var(--vscode-spacing-size280) / 2);
				width: var(--vscode-spacing-size100);
				border-bottom: var(--vscode-strokeThickness) solid var(--vscode-tree-inactiveIndentGuidesStroke);
				border-bottom-left-radius: var(--vscode-cornerRadius-small);
			}

			&::after {
				display: none;
			}
		}

		.agent-session-chat-title-row {
			display: flex;
			align-items: center;
			flex: 0 0 auto;
			height: var(--vscode-spacing-size280);
			gap: var(--vscode-spacing-size60);
			line-height: 17px;
		}

		.agent-session-chat-icon {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: var(--vscode-spacing-size160);
			height: var(--vscode-spacing-size160);
			font-size: var(--vscode-codiconFontSize-compact);

			> .monaco-pixel-spinner {
				width: var(--vscode-spacing-size120);
				height: var(--vscode-spacing-size120);
			}
		}

		.agent-session-chat-title {
			flex: 1;
			min-width: 0;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}

		.agent-session-title-toolbar {
			flex-shrink: 0;
		}

		&.needs-input .agent-session-chat-title {
			color: var(--vscode-strongForeground);
		}

		.agent-session-approval-row {
			margin-left: var(--vscode-spacing-size100);
		}
	}

	.monaco-list-row.selected .agent-session-chat-title {
		color: unset;
	}

	.monaco-list:focus .monaco-list-row.selected .agent-session-chat-icon > .codicon,
	.monaco-list:focus .monaco-list-row.selected .agent-session-chat-icon > .monaco-pixel-spinner {
		color: var(--vscode-list-activeSelectionForeground) !important;
	}

	.agent-session-show-more {
		display: flex;
		align-items: center;
		font-size: 12px;
		color: var(--vscode-foreground);
		/* align with session item text: 6px item padding + 16px icon + 6px main-col padding */
		padding: 0 6px 0 24px;
		cursor: pointer;
		text-decoration: none !important;
	}

	.agent-session-section {
		display: flex;
		align-items: center;
		font-size: var(--vscode-fontSize-label1);
		font-weight: var(--vscode-fontWeight-semiBold);
		color: var(--vscode-descriptionForeground);
		text-transform: uppercase;
		/* align with session item padding */
		padding: 0 6px;

		.agent-session-section-label {
			flex: 1;
			min-width: 0;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}

		.agent-session-section-count {
			opacity: 0.7;
			margin-right: 4px;
		}

		.agent-session-section-toolbar {
			/* for the absolute positioning of the toolbar below */
			position: relative;

			.monaco-toolbar {
				/* this is required because the overal height (including the padding needed for hover feedback) would push down the label otherwise */
				position: absolute;
				right: 0;
				top: 0;
				display: none;
			}
		}
	}

	.monaco-list-row:hover .agent-session-section .agent-session-section-count {
		display: none;
	}

	.monaco-list-row:hover .agent-session-section .agent-session-section-toolbar,
	.monaco-list-row.focused:not(.selected) .agent-session-section .agent-session-section-toolbar {
		width: 22px;

		.monaco-toolbar {
			display: block;
		}
	}

	.monaco-list:focus .monaco-list-row.focused.selected .agent-session-section-label,
	.monaco-list:focus .monaco-list-row.selected .agent-session-section-label {
		color: var(--vscode-list-activeSelectionForeground);
	}

	.monaco-list:not(:focus) .monaco-list-row.selected .agent-session-section-label {
		color: var(--vscode-list-inactiveSelectionForeground);
	}

	.agent-sessions-empty-filter-message {
		padding: 8px 12px;
		font-size: 12px;
		color: var(--vscode-descriptionForeground);

		.reset-filter-link {
			color: var(--vscode-textLink-foreground);
			cursor: pointer;
			text-decoration: none;

			&:hover {
				text-decoration: underline;
			}

			&:focus-visible {
				text-decoration: underline;
				outline: 1px solid var(--vscode-focusBorder);
				outline-offset: 1px;
			}
		}
	}
}
