/**
 * "Carousel Placements" card (port of Logo Carousel Pro's).
 *
 * A three-column grid table (Used on · Type & Layouts · Last updated). Each
 * row's type line swaps for Edit / View on hover or keyboard focus, and a long
 * layout list folds its tail into a "+N" chip whose tooltip names the rest.
 */

$placements-columns: minmax(0, 1fr) minmax(0, 1.4fr) 120px;
$placements-gutter: 24px;
$placements-line: #f0f0f1;
$placements-muted: #646970;
$placements-faint: #8c8f94;
$placements-ink: #1d2327;
$placements-body: #3c434a;
$placements-action: #3858e9;
$placements-primary: #19949e;

.wpcpf-admin-dashboard-container {
	.wpcpf-placements {
		margin-top: 28px;
		background: #fff;
		border: 1px solid #e5e5e7;
		border-radius: 10px;
	}

	/* ---- Heading + tools ---- */

	.wpcpf-placements__head {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		justify-content: space-between;
		gap: 16px;
		padding: 20px $placements-gutter;
	}

	.wpcpf-placements__heading {
		margin: 0 0 3px;
		padding: 0;
		font-size: 17px;
		font-weight: 700;
		line-height: 1.45;
		color: $placements-ink;
	}

	.wpcpf-placements__intro {
		margin: 0;
		font-size: 13.5px;
		line-height: 1.45;
		color: $placements-muted;
	}

	.wpcpf-placements__tools {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: 10px;
	}

	.wpcpf-placements__filters {
		display: flex;
		align-items: center;
		gap: 4px;
		padding: 3px;
		background: #f0f0f1;
		border-radius: 7px;
	}

	.wpcpf-placements__filter {
		height: 28px;
		margin: 0;
		padding: 0 12px;
		border: 0;
		border-radius: 5px;
		background: transparent;
		box-shadow: none;
		color: $placements-muted;
		font-size: 12.5px;
		font-weight: 600;
		line-height: 28px;
		white-space: nowrap;
		cursor: pointer;
		transition:
			background-color 0.15s ease,
			color 0.15s ease,
			box-shadow 0.15s ease;

		&:hover {
			color: $placements-ink;
		}

		&:focus-visible {
			outline: 2px solid $placements-primary;
			outline-offset: 1px;
		}

		&.is-active {
			background: #fff;
			color: $placements-ink;
			box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
		}
	}

	/* Sync: an icon button beside search, its state in a tooltip above. */
	.wpcpf-placements__tip-wrap {
		position: relative;
		display: inline-flex;

		&:hover,
		&:focus-within {
			.wpcpf-placements__tip {
				opacity: 1;
				visibility: visible;
				transform: translate(-50%, 0) scale(1);
				transition:
					opacity 0.18s ease,
					transform 0.18s cubic-bezier(0.2, 0.8, 0.3, 1.2),
					visibility 0s;
			}
		}
	}

	.wpcpf-placements__sync {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 34px;
		height: 34px;
		margin: 0;
		padding: 0;
		background: #fff;
		border: 1px solid #dcdcde;
		border-radius: 6px;
		color: $placements-muted;
		cursor: pointer;
		transition:
			border-color 0.2s ease,
			color 0.2s ease,
			background-color 0.2s ease;

		svg {
			display: block;
		}

		&:hover,
		&:focus-visible {
			background: #f0f9fa;
			border-color: $placements-primary;
			color: $placements-primary;
		}

		&:focus-visible {
			outline: 2px solid $placements-primary;
			outline-offset: 1px;
		}

		&:disabled {
			cursor: default;
		}

		&.is-syncing {
			color: $placements-primary;

			svg {
				animation: wpcpf-placements-spin 0.8s linear infinite;
			}
		}
	}

	.wpcpf-placements__tip {
		position: absolute;
		bottom: calc(100% + 8px);
		left: 50%;
		z-index: 20;
		padding: 8px 12px;
		background: rgba(29, 35, 39, 0.88);
		border-radius: 7px;
		box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
		color: #fff;
		font-size: 12.5px;
		font-weight: 500;
		line-height: 1.45;
		text-align: center;
		white-space: nowrap;
		opacity: 0;
		visibility: hidden;
		transform: translate(-50%, 6px) scale(0.97);
		transition:
			opacity 0.16s ease,
			transform 0.16s ease,
			visibility 0s linear 0.16s;
		pointer-events: none;

		// Arrow pointing down at the button.
		&::after {
			content: '';
			position: absolute;
			top: 100%;
			left: 50%;
			margin-left: -5px;
			border: 5px solid transparent;
			border-top-color: rgba(29, 35, 39, 0.88);
		}
	}

	.wpcpf-placements__tip-sub {
		display: block;
		color: #c3c4c7;
		font-size: 11.5px;
	}

	.wpcpf-placements__search {
		display: flex;
		align-items: center;
		gap: 6px;
		height: 34px;
		margin: 0;
		padding: 0 10px;
		background: #fff;
		border: 1px solid #dcdcde;
		border-radius: 6px;
		cursor: text;
		transition: border-color 0.15s ease;

		&:focus-within {
			border-color: $placements-primary;
		}

		.dashicons {
			display: block;
			width: 16px;
			height: 16px;
			font-size: 16px;
			line-height: 16px;
			color: $placements-faint;
		}

		input[type='search'] {
			width: 140px;
			min-height: 0;
			height: 32px;
			margin: 0;
			padding: 0;
			border: 0;
			border-radius: 0;
			outline: none;
			background: transparent;
			box-shadow: none;
			font-size: 13px;
			line-height: 32px;
			color: $placements-ink;

			&:focus {
				border: 0;
				box-shadow: none;
				outline: none;
			}

			&::placeholder {
				color: $placements-faint;
			}

			&::-webkit-search-cancel-button {
				cursor: pointer;
			}
		}
	}

	/* ---- Table ---- */

	.wpcpf-placements__row {
		display: grid;
		grid-template-columns: $placements-columns;
		gap: 16px;
		align-items: center;
		padding: 14px $placements-gutter;
		border-bottom: 1px solid $placements-line;
		transition: background-color 0.15s ease;

		&:hover {
			background: #fafafa;
		}

		/* Edit / View take the type line's place while the row is pointed at
		   or holds focus. */
		&:hover,
		&:focus-within {
			.wpcpf-placements__meta.has-actions {
				opacity: 0;
			}

			.wpcpf-placements__actions {
				opacity: 1;
				transform: none;
				pointer-events: auto;
			}
		}
	}

	.wpcpf-placements__row--head {
		padding-top: 12px;
		padding-bottom: 12px;
		background: #f6f7f7;
		border-top: 1px solid $placements-line;
		color: $placements-muted;
		font-size: 12px;
		font-weight: 700;
		letter-spacing: 0.04em;
		line-height: 1.45;
		text-transform: uppercase;

		&:hover {
			background: #f6f7f7;
		}
	}

	.wpcpf-placements__cell {
		min-width: 0;
	}

	.wpcpf-placements__where {
		min-width: 0;
	}

	.wpcpf-placements__title-line {
		display: flex;
		align-items: center;
		gap: 8px;
		min-width: 0;
	}

	.wpcpf-placements__title {
		overflow: hidden;
		font-size: 14px;
		font-weight: 600;
		line-height: 1.45;
		color: $placements-ink;
		text-overflow: ellipsis;
		white-space: nowrap;
		transition: color 0.15s ease;
	}

	a.wpcpf-placements__title:hover,
	a.wpcpf-placements__title:focus {
		color: $placements-primary;
	}

	.wpcpf-placements__status {
		flex: 0 0 auto;
		padding: 1px 7px;
		border-radius: 10px;
		background: #fcf0d9;
		color: #996800;
		font-size: 11px;
		font-weight: 600;
		line-height: 1.45;
	}

	.wpcpf-placements__sub {
		position: relative;
		height: 20px;
		margin-top: 2px;
	}

	.wpcpf-placements__meta {
		position: absolute;
		inset: 0;
		overflow: hidden;
		font-size: 12.5px;
		line-height: 20px;
		color: $placements-faint;
		text-overflow: ellipsis;
		white-space: nowrap;
		transition: opacity 0.15s ease;
	}

	.wpcpf-placements__meta--unused {
		color: #a7aaad;
	}

	.wpcpf-placements__actions {
		position: absolute;
		inset: 0;
		display: flex;
		align-items: center;
		gap: 8px;
		font-size: 12.5px;
		line-height: 20px;
		opacity: 0;
		transform: translateY(3px);
		pointer-events: none;
		transition:
			opacity 0.15s ease,
			transform 0.15s ease;
	}

	.wpcpf-placements__action {
		display: inline-flex;
		align-items: center;
		gap: 3px;
		font-weight: 400;
		color: $placements-action;

		svg {
			display: block;
		}

		&:hover,
		&:focus {
			color: #2145e6;
			text-decoration: underline;
		}
	}

	.wpcpf-placements__sep {
		color: #dcdcde;
	}

	.wpcpf-placements__unused {
		font-size: 14px;
		font-weight: 600;
		line-height: 1.45;
		color: $placements-faint;
	}

	.wpcpf-placements__layouts {
		min-width: 0;
		font-size: 13.5px;
		line-height: 1.5;
		color: $placements-body;
	}

	.wpcpf-placements__type {
		font-weight: 600;
	}

	.wpcpf-placements__type--block {
		color: $placements-action;
	}

	.wpcpf-placements__type--shortcode {
		color: $placements-body;
	}

	.wpcpf-placements__type--template {
		color: $placements-primary;
	}

	.wpcpf-placements__more {
		display: inline-flex;
		align-items: center;
		height: 20px;
		margin: 0 0 0 4px;
		padding: 0 8px;
		border: 0;
		border-radius: 10px;
		background: #f0f0f1;
		color: #50575e;
		font-size: 12px;
		font-weight: 600;
		line-height: 20px;
		vertical-align: 1px;
		cursor: default;
		transition:
			background-color 0.2s ease,
			color 0.2s ease;

		&:hover,
		&:focus-visible {
			background: #e0f7f8;
			color: $placements-primary;
		}

		&:focus-visible {
			outline: 2px solid $placements-primary;
			outline-offset: 1px;
		}
	}

	.wpcpf-placements__date {
		font-size: 13px;
		color: $placements-muted;
	}

	.wpcpf-placements__no-match {
		padding: 40px $placements-gutter;
		border-bottom: 1px solid $placements-line;
		font-size: 13.5px;
		color: $placements-faint;
		text-align: center;
	}

	/* ---- Foot ---- */

	.wpcpf-placements__foot {
		display: flex;
		flex-direction: row-reverse;
		justify-content: space-between;
		align-items: center;
		gap: 8px;
		padding: 18px $placements-gutter;
		font-size: 13px;
		color: $placements-muted;
		text-align: center;
	}

	.wpcpf-placements__load-more {
		display: inline-flex;
		align-items: center;
		gap: 6px;
		height: 34px;
		margin: 0;
		padding: 0 18px;
		border: 1px solid #dcdcde;
		border-radius: 7px;
		background: #fff;
		color: $placements-ink;
		font-size: 13px;
		font-weight: 600;
		line-height: 1;
		cursor: pointer;
		transition:
			border-color 0.2s ease,
			color 0.2s ease,
			background-color 0.2s ease;

		.dashicons {
			display: block;
			width: 14px;
			height: 14px;
			font-size: 14px;
			line-height: 14px;
		}

		&:hover,
		&:focus-visible {
			border-color: $placements-primary;
			background: #f0f9fa;
			color: $placements-primary;
		}
	}

	.wpcpf-placements__more-wrap {
		margin-left: 4px;
		vertical-align: 1px;

		.wpcpf-placements__more {
			margin-left: 0;
		}
	}

	/* ---- Loading / error ---- */

	.wpcpf-placements__skeleton {
		display: flex;
		flex-direction: column;
		gap: 10px;
		padding: 16px $placements-gutter $placements-gutter;
		border-top: 1px solid $placements-line;
	}

	.wpcpf-placements__skeleton-row {
		height: 40px;
		border-radius: 6px;
		background: linear-gradient(90deg, #f3f4f6 25%, #e9ebee 37%, #f3f4f6 63%);
		background-size: 400% 100%;
		animation: wpcpf-placements-shimmer 1.2s ease infinite;
	}

	.wpcpf-placements__state {
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 12px;
		padding: 40px $placements-gutter;
		border-top: 1px solid $placements-line;
		color: #b32d2e;
		font-size: 13.5px;
		text-align: center;

		p {
			margin: 0;
		}
	}

	/* ---- Empty ---- */

	.wpcpf-placements__empty {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 56px $placements-gutter 60px;
		border-top: 1px solid $placements-line;
		text-align: center;
	}

	.wpcpf-placements__empty-art {
		display: block;
		margin-bottom: 22px;
	}

	.wpcpf-placements__empty-title {
		margin: 0 0 8px;
		padding: 0;
		font-size: 17px;
		font-weight: 700;
		line-height: 1.45;
		color: $placements-ink;
	}

	.wpcpf-placements__empty-text {
		max-width: 440px;
		margin: 0;
		font-size: 14px;
		line-height: 1.6;
		color: $placements-muted;
	}

	.wpcpf-placements__empty-link {
		display: inline-flex;
		align-items: center;
		gap: 6px;
		margin-top: 16px;
		padding-bottom: 3px;
		font-size: 14px;
		font-weight: 500;
		line-height: 1.45;
		color: #135c5d;
		transition: color 0.25s ease;

		.dashicons {
			display: block;
			width: 15px;
			height: 15px;
			font-size: 15px;
			line-height: 15px;
		}

		&:hover,
		&:focus {
			color: $placements-primary;
		}
	}

	@keyframes wpcpf-placements-spin {
		to {
			transform: rotate(360deg);
		}
	}

	@keyframes wpcpf-placements-shimmer {
		0% {
			background-position: 100% 50%;
		}

		100% {
			background-position: 0 50%;
		}
	}

	@media (prefers-reduced-motion: reduce) {
		.wpcpf-placements__skeleton-row {
			animation: none;
		}

		.wpcpf-placements__tip {
			transition: none;
		}

		.wpcpf-placements__actions,
		.wpcpf-placements__meta {
			transition: none;
		}
	}

	/* Phones: each row stacks its three cells, and the column heads go. */
	@media (max-width: 600px) {
		.wpcpf-placements__head {
			padding: 16px;
		}

		.wpcpf-placements__tools {
			width: 100%;
		}

		.wpcpf-placements__search {
			flex: 1;
			min-width: 0;
		}

		/* The button sits at the left edge here: open the tooltip rightward
		   from it instead of centring it off-screen. */
		.wpcpf-placements__tip {
			left: 0;
			transform: translate(0, 6px) scale(0.97);

			&::after {
				left: 17px;
			}
		}

		.wpcpf-placements__tip-wrap:hover .wpcpf-placements__tip,
		.wpcpf-placements__tip-wrap:focus-within .wpcpf-placements__tip {
			transform: translate(0, 0) scale(1);
		}

		/* The tab row scrolls instead of widening the card; containment keeps
		   its content width out of the card's intrinsic size. */
		.wpcpf-placements__filters {
			flex: 1 1 100%;
			min-width: 0;
			contain: inline-size;
			max-width: 100%;
			overflow-x: auto;
		}

		.wpcpf-placements__search input[type='search'] {
			flex: 1;
			width: auto;
		}

		.wpcpf-placements__row {
			grid-template-columns: minmax(0, 1fr);
			gap: 6px;
			padding: 14px 16px;
		}

		.wpcpf-placements__row--head {
			display: none;
		}

		/* No hover on touch: the type and Edit / View sit side by side. */
		.wpcpf-placements__sub {
			display: flex;
			flex-wrap: wrap;
			gap: 0 12px;
			height: auto;
		}

		.wpcpf-placements__meta,
		.wpcpf-placements__actions {
			position: static;
		}

		.wpcpf-placements__row:hover .wpcpf-placements__meta.has-actions,
		.wpcpf-placements__row:focus-within .wpcpf-placements__meta.has-actions {
			opacity: 1;
		}

		.wpcpf-placements__actions {
			opacity: 1;
			transform: none;
			pointer-events: auto;
		}
	}
}
