// A preview is the layout rendered on a page, scaled down. Its schematic,
// drawn from the settings in the neutral tones core uses for pattern
// placeholders, shows while the page loads and when the layout has no items.
.vpf-library-preview {
	position: relative;
	box-sizing: border-box;
	width: 100%;
	aspect-ratio: 1;
	overflow: hidden;
	background: #f6f6f6;

	&.is-ready {
		background: #fff;
	}
}

.vpf-library-preview__schematic {
	position: absolute;
	inset: 0;
	box-sizing: border-box;
	padding: 10%;

	> div {
		height: 100%;
	}

	.is-ready > & {
		visibility: hidden;
		transition: visibility 0s 0.2s;
	}
}

.vpf-library-preview__frame {
	position: absolute;
	top: 0;
	left: 0;
	background: #fff;
	border: 0;
	opacity: 0;
	transform-origin: 0 0;
	pointer-events: none;
	transition: opacity 0.2s ease-out;

	.is-ready > & {
		opacity: 1;
	}

	@media (prefers-reduced-motion: reduce) {
		transition: none;
	}
}

.vpf-library-preview__tile {
	display: block;
	min-height: 0;
	background: #e2e2e2;
	border-radius: 2px;

	&:nth-child(3n + 2) {
		background: #d6d6d6;
	}

	&:nth-child(4n + 3) {
		background: #ebebeb;
	}
}

.vpf-library-preview__grid {
	display: grid;
	grid-auto-rows: 1fr;
	gap: 6%;
}

.vpf-library-preview__masonry {
	column-gap: 6%;

	.vpf-library-preview__tile {
		margin-bottom: 6%;
		break-inside: avoid;
	}
}

.vpf-library-preview__justified {
	display: flex;
	flex-wrap: wrap;
	gap: 6%;
	align-content: stretch;

	.vpf-library-preview__tile {
		height: 28%;
	}
}

.vpf-library-preview__tiles {
	display: grid;
	grid-template-rows: repeat(3, 1fr);
	grid-template-columns: repeat(4, 1fr);
	gap: 6%;

	.vpf-library-preview__tile:first-child {
		grid-row: span 2;
		grid-column: span 2;
	}

	.vpf-library-preview__tile:nth-child(4) {
		grid-column: span 2;
	}
}

.vpf-library-preview__carousel {
	display: flex;
	gap: 6%;
	align-items: stretch;
	margin-right: -30%;

	.vpf-library-preview__tile {
		flex: 0 0 45%;
	}
}

.vpf-library-title {
	display: inline-flex;
	flex-wrap: wrap;
	gap: 4px 8px;
	align-items: center;
	min-width: 0;
}

.vpf-library-title__link {
	min-width: 0;
	color: inherit;
	font-weight: 500;
	text-decoration: none;
	overflow-wrap: anywhere;

	&:hover,
	&:focus {
		color: var(--wp-admin-theme-color, #3858e9);
	}
}

.vpf-library-badge {
	padding: 0 6px;
	color: #2f2f2f;
	font-size: 11px;
	font-weight: 500;
	line-height: 20px;
	white-space: nowrap;
	background: #f0f0f0;
	border-radius: 2px;

	&.is-legacy {
		color: #6e5b00;
		background: #fcf9e8;
	}
}

.vpf-library-muted {
	color: #757575;
}

.vpf-library-code {
	padding: 2px 4px;
	font-size: 12px;
	white-space: nowrap;
	background: #f0f0f0;
	border-radius: 2px;
}

.vpf-library-add {
	width: auto;

	> .components-button:first-child {
		border-top-right-radius: 0;
		border-bottom-right-radius: 0;
	}

	.vpf-library-add__toggle {
		min-width: 32px;
		padding: 0 4px;
		border-top-left-radius: 0;
		border-bottom-left-radius: 0;
		box-shadow: inset 1px 0 0 rgb(255 255 255 / 30%);
	}
}

.vpf-library-empty {
	max-width: 480px;
	margin: 64px auto;
	text-align: center;
}

.vpf-library-usage {
	max-height: 200px;
	padding: 0;
	margin: 0;
	overflow: auto;
	list-style: none;

	li {
		display: flex;
		gap: 12px;
		justify-content: space-between;
		padding: 8px 0;
		margin: 0;
		border-bottom: 1px solid #f0f0f0;

		> :first-child {
			min-width: 0;
			overflow-wrap: anywhere;
		}

		> :last-child {
			flex: none;
		}
	}
}

.vpf-library-snackbars {
	position: fixed;
	bottom: 24px;
	left: 50%;
	z-index: 100000;
	width: max-content;
	max-width: calc(100vw - 32px);
	transform: translateX(-50%);
}

// The page header and content set the gutters, so DataViews adds none.
.vpf-library .dataviews-view-grid,
.vpf-library .dataviews-view-list,
.vpf-library .dataviews-footer,
.vpf-library .dataviews-filters__container {
	padding-right: 0;
	padding-left: 0;
}

.vpf-library .dataviews-view-table tr td:first-child,
.vpf-library .dataviews-view-table tr th:first-child {
	padding-left: 0;
}

.vpf-library .dataviews-view-table tr td:last-child,
.vpf-library .dataviews-view-table tr th:last-child {
	padding-right: 0;
}

.vpf-library-toolbar {
	display: flex;
	flex-wrap: wrap;
	gap: 8px 12px;
	align-items: center;
	margin-bottom: 16px;

	.dataviews-search {
		width: 280px;
		max-width: 100%;
	}
}

.vpf-library-toolbar__end {
	display: flex;
	gap: 4px;
	align-items: center;
	margin-left: auto;
}

.vpf-library-toolbar__bulk {
	flex: 1 1 200px;
	align-self: stretch;
	min-height: 40px;
}

// The grid's select-all bar, with the selection's bulk actions, sits over the
// toolbar's slot (see `useBulkSlot()`) instead of on a row of its own.
.vpf-library .dataviews-wrapper {
	position: relative;
}

.vpf-library .dataviews-view-grid__bulk-actions-header {
	position: absolute;
	top: var(--vpf-bulk-top, 0);
	left: var(--vpf-bulk-left, 0);
	z-index: 2;
	display: flex;
	align-items: center;
	width: var(--vpf-bulk-width, auto);
	height: 40px;
	padding: 0 0 0 12px;
	margin: 0;
	background: transparent;
	border-left: 1px solid #e0e0e0;

	@media (max-width: 600px) {
		padding-left: 0;
		border-left: 0;
	}

	> * {
		width: 100%;
		min-height: 0;
		padding: 0;
		background: transparent;
		border: 0;
	}
}

// A card's title keeps to one line and ends in an ellipsis.
.vpf-library .dataviews-view-grid .vpf-library-title {
	flex-wrap: nowrap;
	max-width: 100%;
}

.vpf-library .dataviews-view-grid .vpf-library-title__link {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

// WordPress's @wordpress/components fills every svg in a clickable `Item`, while the
// check of DataViews 22 is drawn with a stroke, so the filled path turns into
// a wedge. Not scoped to the page: the menu renders in a popover outside it.
// Drop once the two packages agree on the icon.
.components-item svg[stroke],
.components-item svg[stroke] path {
	fill: none;
}
