@use '../../shared/styles/utils';
@use './theme';
@use './scrollbars';

:root {
	--gitlens-gutter-width: 20px;
	--gitlens-scrollbar-gutter-width: 10px;
	--gitlens-tree-foreground: var(--vscode-sideBar-foreground, var(--vscode-foreground));
}

@include utils.dark-theme() {
	--color-background--level-05: var(--color-background--lighten-05);
	--color-background--level-075: var(--color-background--lighten-075);
	--color-background--level-10: var(--color-background--lighten-10);
	--color-background--level-15: var(--color-background--lighten-15);
	--color-background--level-30: var(--color-background--lighten-30);
}

@include utils.light-theme() {
	--color-background--level-05: var(--color-background--darken-05);
	--color-background--level-075: var(--color-background--darken-075);
	--color-background--level-10: var(--color-background--darken-10);
	--color-background--level-15: var(--color-background--darken-15);
	--color-background--level-30: var(--color-background--darken-30);
}

// generic resets
html {
	font-size: 62.5%;
	// box-sizing: border-box;
	font-family: var(--font-family);
}

*,
*:before,
*:after {
	box-sizing: border-box;
}

body {
	font-family: var(--font-family);
	font-size: var(--font-size);
	color: var(--color-foreground);
	padding: 0;
}

@include scrollbars.scrollableBase();

a {
	text-decoration: none;
	&:hover {
		text-decoration: underline;
	}
}

ul {
	list-style: none;
	margin: 0;
	padding: 0;
}

.bulleted {
	list-style: disc;
	padding-left: 1.2em;
	> li + li {
		margin-top: 0.25em;
	}
}

.button--busy {
	&[aria-busy='true'] {
		opacity: 0.5;
	}

	&:not([aria-busy='true']) {
		code-icon {
			display: none;
		}
	}
}

.button-container {
	margin: 1rem auto 0;
	text-align: left;
	max-width: 30rem;
	transition: max-width 0.2s ease-out;
}

@media (min-width: 640px) {
	.button-container {
		max-width: 100%;
	}
}

.button-group {
	display: inline-flex;
	gap: 0.1rem;

	&--single {
		width: 100%;
		max-width: 30rem;
	}

	> *:not(:first-child),
	> *:not(:first-child) gl-button {
		border-top-left-radius: 0;
		border-bottom-left-radius: 0;
	}

	> *:not(:last-child),
	> *:not(:last-child) gl-button {
		border-top-right-radius: 0;
		border-bottom-right-radius: 0;
	}
}

.section {
	padding: 0 var(--gitlens-scrollbar-gutter-width) 1.5rem var(--gitlens-gutter-width);

	> :first-child {
		margin-top: 0;
	}
	> :last-child {
		margin-bottom: 0;
	}
}

.section--message {
	padding: 0 var(--gitlens-scrollbar-gutter-width) 1rem var(--gitlens-scrollbar-gutter-width);
}

.section--empty {
	> :last-child {
		margin-top: 0.5rem;
	}
}

.section--skeleton {
	padding: {
		top: 1px;
		bottom: 1px;
	}
}

.message-block {
	font-size: 1.3rem;
	border: 1px solid var(--vscode-input-border);
	background: var(--vscode-input-background);
	padding: 0.5rem;
	border-radius: 0.2rem 0.2rem 0 0;

	&__text {
		margin: 0;

		overflow-y: auto;
		overflow-x: hidden;
		max-height: 9rem;

		> * {
			white-space: break-spaces;
		}

		strong {
			font-weight: 600;
			font-size: 1.4rem;
		}
	}
}
.message-block-row,
.message-block-group {
	display: flex;
	flex-direction: row;
	gap: 0.6rem;
}

.message-block-row {
	justify-content: space-between;
}

.message-block-row--actions {
	font-size: 1.3rem;
	color: var(--color-foreground--65);
	background: var(--color-background--level-075);
	padding: 0.2rem;

	&:last-child {
		border-radius: 0 0 0.2rem 0.2rem;
	}

	&:first-of-type:last-child {
		border-radius: 0.2rem;
	}

	gl-action-chip::part(icon),
	gl-autolink-chip::part(icon),
	gl-commit-date,
	.reachability-summary code-icon {
		--code-icon-size: 1.3rem;
	}

	gl-commit-date {
		margin-inline-end: 0.2rem;
	}

	gl-action-chip.error {
		background-color: var(--color-alert-errorBackground);
	}

	gl-action-chip.warning {
		background-color: var(--color-alert-warningHoverBackground);
	}
}

// Reachability styles
.reachability-summary {
	display: flex;
	flex-wrap: wrap;
	gap: 0.6rem;
	align-items: center;
	overflow: hidden;
}

.reachability-range-chip-wrapper {
	display: inline-block;
	max-width: 100%;

	@media (max-width: 768px) {
		flex: 1 1 100%;
	}
}

.reachability-range-chip {
	color: var(--color-foreground);
	opacity: 0.8;
	border-radius: 0.3rem;
	padding: 0.1rem 0.25rem;
	--chip-text-transform: none;
	display: inline-flex !important;
	min-width: 0;
	max-width: 100%;
	width: auto;
	transition:
		opacity 0.3s ease-in-out,
		color 0.3s ease-in-out;

	&:hover,
	&:focus {
		color: var(--color-foreground);
		opacity: 1;
	}

	&--range {
		cursor: pointer;
	}

	&--local-branch {
		background-color: color-mix(
			in srgb,
			var(--vscode-gitlens-graphScrollMarkerLocalBranchesColor) 75%,
			transparent
		);
	}

	&--remote-branch {
		background-color: color-mix(
			in srgb,
			var(--vscode-gitlens-graphScrollMarkerRemoteBranchesColor) 55%,
			transparent
		);
	}

	&--tag {
		background-color: var(--vscode-gitlens-graphScrollMarkerTagsColor);
	}

	&--current &__label {
		font-weight: 600;
	}

	&__label {
		flex: 1 1 auto;
		min-width: 0;
		max-width: 100%;
		width: 100%;
		padding-left: 0.25rem;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		font-size: 0.95em;
		display: flex;
		align-items: center;
		gap: 0.4rem;
	}

	&__ellipsis {
		opacity: 0.8;
		padding: 0 0.4rem;
	}

	&__count {
		padding-left: 0.4rem;
		font-weight: 600;
		font-size: 0.85em;
	}
}

.reachability-popover {
	min-width: 200px;
	max-width: 400px;

	&__header {
		padding-bottom: 0.6rem;
		font-weight: 500;
	}

	&__list {
		display: flex;
		flex-direction: column;
		gap: 0.2rem;
		max-height: 300px;
		overflow-y: auto;
	}
}

.reachability-list-item {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.3rem 0.4rem;
	font-size: 0.95em;
	line-height: 1.4;

	&--current {
		font-weight: 600;
	}

	&__icon {
		flex-shrink: 0;
		opacity: 0.8;
		font-size: 1.1em;
	}

	&__label {
		flex: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
}

.mq-hide-sm,
gl-autolink-chip::part(label) {
	@media (max-width: 300px) {
		display: none !important;
	}
}

.commit-detail-panel {
	max-height: 100vh;
	overflow: auto;
	scrollbar-gutter: stable;
	color: var(--vscode-sideBar-foreground);
	background-color: var(--vscode-sideBar-background);

	[aria-hidden='true'] {
		display: none;
	}
}

.ai-content {
	font-size: 1.3rem;
	border: 0.1rem solid var(--vscode-input-border, transparent);
	background: var(--vscode-input-background);
	margin-top: 1rem;
	padding: 0.5rem;
	border-radius: 2px;

	&.has-error {
		border-left-color: var(--color-alert-errorBorder);
		border-left-width: 0.3rem;
		padding-left: 0.8rem;
	}

	&:empty {
		display: none;
	}

	&__summary {
		display: block;
		margin: 0;
		overflow-y: auto;
		overflow-x: hidden;
		max-height: 20rem;
	}
}
