// This remove the margins set here: https://github.com/GeChiUI/gutenberg/blob/17e5c2d870d84fb6de48dcd5bc3c38cd0c0fb0d0/packages/block-library/src/editor.scss#L56
// It removes the margins around blocks when a BlockPreview is rendered in the block style selector
.block-editor-block-styles .block-editor-block-list__block {
	margin: 0;
}

/**
 * Notices & Block Selected/Hover Styles.
 */

/**
 * Cross-Block Selection
 */

// Note to developers refactoring this, please test navigation mode, and
// multi selection and hovering the block switcher to highlight the block.
.block-editor-block-list__layout {
	position: relative;

	// Select tool/navigation mode shows the default cursor until an additional click edits.
	&.is-navigate-mode {
		cursor: default;
	}

	// The primary indicator of selection in text is the native selection marker.
	// When selecting multiple blocks, we provide an additional selection indicator.
	&.is-navigate-mode .block-editor-block-list__block.is-selected,
	&.is-navigate-mode .block-editor-block-list__block.is-hovered,
	.block-editor-block-list__block.is-highlighted,
	.block-editor-block-list__block.is-multi-selected {

		&::after {
			// Show selection borders around every non-nested block's actual footprint.
			position: absolute;
			z-index: 1;
			pointer-events: none;
			content: "";
			top: $border-width;
			bottom: $border-width;
			left: $border-width;
			right: $border-width;

			// Everything else.
			box-shadow: 0 0 0 $border-width var(--gc-admin-theme-color);
			border-radius: $radius-block-ui - $border-width; // Border is outset, so subtract the width to achieve correct radius.

			// Windows High Contrast mode will show this outline.
			outline: 2px solid transparent;

			// Show a lighter color for dark themes.
			.is-dark-theme & {
				box-shadow: 0 0 0 $border-width $dark-theme-focus;
			}
		}

		// Provide exceptions for placeholders.
		.components-placeholder {
			::selection {
				background: transparent;
			}
		}
	}

	&.is-navigate-mode .block-editor-block-list__block.is-hovered:not(.is-selected)::after {
		box-shadow: 0 0 0 $border-width var(--gc-admin-theme-color);
	}

	.block-editor-block-list__block.is-highlighted::after {
		box-shadow: 0 0 0 $border-width var(--gc-admin-theme-color);
		outline: $border-width solid transparent;
	}

	.block-editor-block-list__block.is-multi-selected::after,
	&.is-navigate-mode .block-editor-block-list__block.is-selected::after,
	& .is-block-moving-mode.block-editor-block-list__block.has-child-selected {
		box-shadow: 0 0 0 var(--gc-admin-border-width-focus) var(--gc-admin-theme-color);
		outline: 2px solid transparent;
	}

	& .is-block-moving-mode.block-editor-block-list__block.is-selected {

		&::before {
			content: "";
			position: absolute;
			z-index: 0;
			pointer-events: none;
			transition:
				border-color 0.1s linear,
				border-style 0.1s linear,
				box-shadow 0.1s linear;
			right: 0;
			left: 0;
			top: -$default-block-margin * 0.5;
			border-radius: $radius-block-ui;
			border-top: 4px solid $gray-400;
		}

		&::after {
			content: none;
		}
	}

	& .is-block-moving-mode.can-insert-moving-block.block-editor-block-list__block.is-selected {
		&::before {
			border-color: var(--gc-admin-theme-color);
		}
	}
}


.is-block-moving-mode.block-editor-block-list__block-selection-button {
	// Should be invisible but not unfocusable.
	opacity: 0;
	font-size: 1px;
	height: 1px;
	padding: 0;
}

.block-editor-block-list__layout .block-editor-block-list__block {
	position: relative;

	// Break long strings of text without spaces so they don't overflow the block.
	overflow-wrap: break-word;

	.reusable-block-edit-panel * {
		z-index: z-index(".block-editor-block-list__block .reusable-block-edit-panel *");
	}

	/**
	 * Notices
	 */

	.components-placeholder .components-with-notices-ui {
		margin: -10px 0 12px 0;
	}

	.components-with-notices-ui {
		margin: 0 0 12px 0;
		width: 100%;

		.components-notice {
			margin-left: 0;
			margin-right: 0;

			.components-notice__content {
				font-size: $default-font-size;
			}
		}
	}


	/**
	 * Block Layout
	 */

	// Navigate mode & Focused wrapper.
	// We're using a pseudo element to overflow placeholder borders
	// and any border inside the block itself.
	&:not([contenteditable]):focus {
		outline: none;

		&::after {
			position: absolute;
			z-index: 1;
			pointer-events: none;
			content: "";
			top: $border-width;
			bottom: $border-width;
			left: $border-width;
			right: $border-width;

			// 2px outside.
			box-shadow: 0 0 0 var(--gc-admin-border-width-focus) var(--gc-admin-theme-color);
			border-radius: $radius-block-ui - $border-width; // Border is outset, so subtract the width to achieve correct radius.
			outline: 2px solid transparent; // This shows up in Windows High Contrast Mode.

			// Show a light color for dark themes.
			.is-dark-theme & {
				box-shadow: 0 0 0 var(--gc-admin-border-width-focus) $dark-theme-focus;
			}
		}
	}

	/**
	* Block styles and alignments
	*/
	&::after {
		content: "";
		pointer-events: none;
		position: absolute;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		border-radius: $radius-block-ui;
		box-shadow: 0 0 0 var(--gc-admin-border-width-focus) transparent;
	}

	// Warnings
	&.has-warning {
		min-height: $grid-unit-60;

		// When a block has a warning, you shouldn't be able to manipulate the contents.
		> * {
			pointer-events: none;
			user-select: none;
		}

		// Allow the warning action buttons to be manipulable.
		.block-editor-warning {
			pointer-events: all;
		}
	}

	// Scrim overlay.
	&.has-warning::after {
		content: "";
		position: absolute;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		border-radius: $radius-block-ui;
		background-color: rgba($white, 0.4);
	}

	// Avoid conflict with the multi-selection highlight color.
	&.has-warning.is-multi-selected::after {
		background-color: transparent;
	}

	// Reusable blocks clickthrough overlays.
	&.is-reusable > .block-editor-inner-blocks > .block-editor-block-list__layout.has-overlay {
		// Remove only the top click overlay.
		&::after {
			display: none;
		}

		// Restore it for subsequent.
		.block-editor-block-list__layout.has-overlay::after {
			display: block;
		}
	}

	// Reusable blocks parent borer.
	&.is-reusable.has-child-selected::after {
		box-shadow: 0 0 0 1px var(--gc-admin-theme-color);
	}

	// Clear floats.
	&[data-clear="true"] {
		float: none;
	}
}

.is-outline-mode .block-editor-block-list__block:not(.remove-outline) {
	&.is-hovered {
		cursor: default;

		&::after {
			top: $border-width;
			left: $border-width;
			right: $border-width;
			bottom: $border-width;
			box-shadow: 0 0 0 $border-width var(--gc-admin-theme-color);
			border-radius: $radius-block-ui - $border-width; // Border is outset, so subtract the width to achieve correct radius.
		}
	}

	&.is-selected {
		cursor: unset;

		&::after {
			box-shadow: 0 0 0 var(--gc-admin-border-width-focus) var(--gc-admin-theme-color); // Selected not focussed.
			top: $border-width;
			left: $border-width;
			right: $border-width;
			bottom: $border-width;
			border-radius: $radius-block-ui - $border-width; // Border is outset, so subtract the width to achieve correct radius.
		}

		&:focus {
			&::after {
				box-shadow: 0 0 0 var(--gc-admin-border-width-focus) var(--gc-admin-theme-color);
			}
		}
	}
}

// Spotlight mode. Fade out blocks unless they contain a selected block.
.is-focus-mode .block-editor-block-list__block:not(.has-child-selected) {
	opacity: 0.5;
	transition: opacity 0.1s linear;
	@include reduce-motion("transition");

	// Nested blocks should never be faded. If the parent block is already faded
	// out, it shouldn't be faded out more. If the parent block in not faded
	// out, it shouldn't be faded out either because the block as a whole,
	// including inner blocks, should be focused.
	.block-editor-block-list__block,
	&.is-selected,
	&.is-multi-selected {
		opacity: 1;
	}
}

// Active entity spotlight.
// Disable if focus mode is active.
.is-root-container:not(.is-focus-mode) .block-editor-block-list__block.has-active-entity {
	opacity: 0.5;
	transition: opacity 0.1s linear;
	@include reduce-motion("transition");

	&.is-active-entity,
	&.has-child-selected,
	&:not(.has-child-selected) .block-editor-block-list__block,
	&.is-active-entity .block-editor-block-list__block,
	.is-active-entity .block-editor-block-list__block {
		opacity: 1;
	}
}

.gc-block[data-align="left"] > *,
.gc-block[data-align="right"] > * {
	// Without z-index, won't be clickable as "above" adjacent content.
	z-index: z-index("{core/image aligned left or right} .gc-block");
}

.gc-site-blocks > [data-align="left"] {
	float: left;
	margin-right: 2em;
}

.gc-site-blocks > [data-align="right"] {
	float: right;
	margin-left: 2em;
}

.gc-site-blocks > [data-align="center"] {
	justify-content: center;
	margin-left: auto;
	margin-right: auto;
}

/**
 * In-Canvas Inserter
 */

.block-editor-block-list .block-editor-inserter {
	margin: $grid-unit-10;
	cursor: move; // Fallback for IE/Edge < 14
	cursor: grab;
}

@keyframes block-editor-inserter__toggle__fade-in-animation {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

// Hide the appender that sits at the end of block lists, when inside a nested block,
// unless the block itself, or a parent, is selected.
.gc-block .block-list-appender .block-editor-inserter__toggle {
	animation: block-editor-inserter__toggle__fade-in-animation 0.1s ease;
	animation-fill-mode: forwards;
	@include reduce-motion("animation");
}

.block-editor-block-list__block:not(.is-selected):not(.has-child-selected) .block-editor-default-block-appender {
	display: none;

	.block-editor-inserter__toggle {
		opacity: 0;
		transform: scale(0);
	}
}

.block-editor-block-list__block .block-editor-block-list__block-html-textarea {
	display: block;
	margin: 0;
	padding: $grid-unit-15;
	width: 100%;
	border: none;
	outline: none;
	border-radius: 2px;
	box-shadow: inset 0 0 0 $border-width $gray-900;
	resize: none;
	overflow: hidden;
	font-family: $editor-html-font;
	font-size: $text-editor-font-size;
	line-height: 1.5;
	transition: padding 0.2s linear;
	@include reduce-motion("transition");

	&:focus {
		box-shadow: inset 0 0 0 var(--gc-admin-border-width-focus) var(--gc-admin-theme-color);
	}
}


/**
 * Warnings.
 */

.block-editor-block-list__block .block-editor-warning {
	z-index: z-index(".block-editor-warning");
	position: relative;

	&.block-editor-block-list__block-crash-warning {
		// The block crash warning has no block preview underneath it.
		// The lack of a preview combined with the negative margin that
		// the warning normally has results in crashed blocks overlapping
		// any blocks that come after them. Resetting the margin to `auto`
		// solves this.
		margin-bottom: auto;
	}
}
