// Products › Attributes with Smart Swatches (admin/attributes bundle; PLAN Phase 8, appendix D §2).
// WooCommerce's own markup takes the design: the scripts add `.ssw-admin.ssw-attrs` to its `.wrap`
// (nothing changes without JavaScript) and classes for the shared WP-screen skin (components/wp).
@use "tokens" as *;
@use "components";
@use "admin/pro";

/* stylelint-disable selector-class-pattern, selector-id-pattern -- WooCommerce's ids and classes */

.ssw-attrs {
	position: relative;
	font-size: 13px;
	color: $ink-2;

	h1 {
		font-size: 23px;
		font-weight: 400;
		color: $ink;
	}

	// The native controls the design's controls stand in for (kept for the form post).
	.ssw-native {
		position: absolute !important;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip-path: inset(50%);
		opacity: 0;
		pointer-events: none;
	}

	.ssw-hidden {
		display: none !important;
	}

	.ssw-wpi {
		max-width: none;
	}
}

// Title row: the page title and "Smart Swatches Settings" on the right.
.ssw-attrs__header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	column-gap: 16px;

	h1 {
		margin-right: auto;
	}

	// WordPress moves admin notices to just after the page title: give them their own line.
	> :not(h1, .ssw-attrs__settings) {
		order: 3;
		flex-basis: 100%;
	}
}

.ssw-attrs__settings {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-size: 13px;
	font-weight: 500;
	color: $blue;
	text-decoration: none;

	// The design keeps this link blue on hover (only the underline grows).
	&:hover,
	&:focus {
		color: $blue;
	}

	@include focus-visible;
}

// The design's link hover (`.sslink`): an underline under the label that grows from the centre.
.ssw-link-label {
	position: relative;

	&::after {
		content: "";
		position: absolute;
		left: 0;
		right: 0;
		bottom: -2px;
		height: 1.5px;
		background: currentcolor;
		transform: scaleX(0);
		transform-origin: center;
		transition: transform 200ms $ease;
	}

	a:hover > &::after,
	a:focus-visible > &::after {
		transform: scaleX(1);
	}
}

.ssw-attrs__logo {
	display: inline-flex;
	color: #e2574c;
}

.ssw-attrs__back {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	margin: 6px 0 10px;
	font-size: 13px;
	color: $blue;
	text-decoration: none;

	&::before {
		content: "";
		width: 6px;
		height: 6px;
		border-left: 1.5px solid currentcolor;
		border-bottom: 1.5px solid currentcolor;
		transform: rotate(45deg);
		margin: 0 3px 0 2px;
	}
}

/* List screen ------------------------------------------------------------------------------------ */

.ssw-attrs.is-list {

	// The design's title row: 8px above, 16px to the columns (WordPress pads the h1 and WooCommerce
	// adds a <br class="clear">).
	.ssw-attrs__header {
		margin: 8px 0 16px;

		h1 {
			margin: 0;
			padding: 0;
			line-height: 1.3;
		}
	}

	> br.clear {
		display: none;
	}

	#col-container {
		display: flex;
		flex-wrap: wrap;
		align-items: flex-start;
		gap: 24px;
		margin-top: 0;
	}

	#col-left {
		order: -1;
		flex: 35 1 0;
		min-width: 260px;
		width: auto;
		float: none;
	}

	#col-right {
		flex: 65 1 0;
		min-width: 300px;
		width: auto;
		float: none;
	}

	// `#col-left .col-wrap` / `#col-right .col-wrap` in WordPress pad the columns apart.
	#col-left .col-wrap,
	#col-right .col-wrap {
		padding: 0;
	}

	.form-wrap {

		h2 {
			font-size: 14px;
			font-weight: 600;
			color: $ink;
			margin: 0 0 6px;
			padding: 0;
		}

		> p {
			font-size: 13px;
			color: $muted;
			margin: 0 0 16px;
		}

		.form-field {
			margin: 0 0 16px;
			padding: 0;
		}

		label {
			display: block;
			font-size: 14px;
			font-weight: 500;
			color: $text;
			margin: 0 0 8px;
			padding: 0;
		}

		.description {
			font-size: 13px;
			color: $muted;
			margin: 4px 0 0;
		}

		// Enable Archives? (checkbox inline with its label)
		label[for="attribute_public"] {
			display: flex;
			align-items: center;
			gap: 8px;
			font-weight: 400;
			color: $ink;
			margin: 0;
			cursor: pointer;

			input {
				margin: 0;
			}
		}

		// The rule above the Smart Swatches panel.
		.form-field:has(#attribute_orderby) {
			margin-bottom: 0;
			padding-bottom: 20px;
			border-bottom: 1px solid #dcdcde;
		}
	}

	.ssw-attr-panel {
		margin-top: 16px;
	}

	p.submit {
		margin: 16px 0 0;
		padding: 0;

		.button-primary {
			height: 40px;
			min-height: 40px;
			padding: 0 14px;
			border-radius: 4px;
			font-size: 14px;
			font-weight: 600;
			line-height: normal;
		}
	}
}

// Import / Export, level with "Add new attribute".
.ssw-attrs__toolbar {
	display: flex;
	justify-content: flex-end;
	gap: 10px;
	flex-wrap: wrap;
	margin: 0 0 12px;
	min-height: 34px;
}

// The attributes table (the prototype's card table).
.ssw-attrs table.attributes-table {
	background: #fff;
	border: 1px solid $line-card;
	border-radius: 6px;
	border-collapse: separate;
	border-spacing: 0;
	box-shadow: none;
	overflow: hidden;
	font-size: 14px;

	// The design sizes the columns by their content (WooCommerce fixes them at 15% / 32%).
	td,
	th,
	.attribute-terms {
		width: auto;
	}

	thead th {
		padding: 12px 14px;
		font-size: 14px;
		font-weight: 400;
		color: $ink;
		border-bottom: 1px solid $line-card;
		line-height: 1.5;
	}

	tbody td {
		position: relative;
		padding: 12px 14px;
		vertical-align: top;
		font-size: 14px;
		line-height: 1.5;
		color: $text;
		border-bottom: 1px solid $line-list;
		background: #fff;
	}

	tbody tr:last-child td {
		border-bottom: 0;
	}

	tbody tr.alternate td {
		background: $surface-2;
	}

	tbody td:first-child strong a {
		font-weight: 600;
	}

	tbody td:nth-child(2) {
		color: $muted;
		font-variant-numeric: tabular-nums;
	}

	tbody td:nth-child(3),
	tbody td:nth-child(4) {
		color: $text-2;
	}

	.row-actions {
		position: static;
		left: auto;
		margin-top: 4px;
		padding: 0;
		font-size: 13px;
		color: #c6c7cb;
		visibility: hidden;
	}

	tr:hover .row-actions,
	tr:focus-within .row-actions {
		visibility: visible;
	}

	.row-actions a {
		color: $blue;
	}

	.row-actions .delete a {
		color: $danger-2;
	}

	.attribute-terms {
		color: $text;
	}

	.configure-terms {
		display: inline-block;
		margin-top: 3px;
	}
}

// Inline Delete confirmation, anchored under the name cell (the popover sits at `100% - 4px`).
.ssw-attrs__confirm {
	position: absolute;
	top: 100%;
	left: 0;
	z-index: 20;

	.ssw-confpop {
		top: -4px;
	}
}

/* Smart Swatches panel (add form) ----------------------------------------------------------------- */

.ssw-attr-panel {
	background: #f4f4f5;
	border: 1px solid #e4e4e6;
	border-radius: 8px;
}

.ssw-attr-panel__head {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 13px 16px;
	border-bottom: 1px solid #e7e7e9;
	background: #efeff0;
	border-radius: 8px 8px 0 0;
}

.ssw-attr-panel__brand {
	font-size: 14px;
	font-weight: 600;
	color: #e2574c;

	img {
		display: block;
		height: 26px;
		width: auto;
	}
}

.ssw-attr-panel__link {
	margin-left: auto;
	font-size: 13px;
	font-weight: 500;
	color: $blue;
	text-decoration: none;

	&:hover,
	&:focus {
		color: $blue-2;
	}

	@include focus-visible;
}

.ssw-attrs.is-list .ssw-attr-panel__body {
	display: flex;
	flex-direction: column;
	gap: 24px;
	padding: 16px;

	.form-field {
		margin: 0;
	}

	.ssw-attr-field__label,
	label {
		display: block;
		font-size: 14px;
		font-weight: 500;
		color: $text;
		margin: 0 0 8px;
	}
}

// Shape and Shape Size side by side.
.ssw-attr-pair {
	display: flex;
	gap: 32px;
	align-items: flex-start;

	> .form-field:first-child {
		flex: 1 1 auto;
	}

	> .form-field:last-child {
		flex: 0 0 152px;
	}

	&:not(:has(> .form-field:not(.ssw-hidden))) {
		display: none;
	}
}

/* Edit screen ----------------------------------------------------------------------------------- */

.ssw-attrs.is-edit {
	max-width: 900px;

	h1 {
		margin: 0 0 14px;
	}

	.form-table {
		margin: 0;

		tr {
			display: flex;
			gap: 24px;
			align-items: flex-start;
			padding: 16px 0;
			border-top: 1px solid #e2e2e4;
		}

		tr:first-child {
			border-top: 0;
		}

		th {
			flex: 0 0 230px;
			width: 230px;
			padding: 9px 0 0;
			font-size: 14px;
			font-weight: 600;
			color: $ink;

			label,
			.ssw-attr-field__label {
				font-size: 14px;
				font-weight: 600;
				color: $ink;
			}
		}

		td {
			flex: 1;
			min-width: 0;
			padding: 0;
		}

		.description {
			font-size: 13px;
			color: $muted;
			margin: 4px 0 0;
		}

		input[type="checkbox"] {
			width: 18px;
			height: 18px;
			margin: 6px 0 0;
		}
	}

	p.submit {
		margin: 0;
		padding: 20px 0 0;

		.button-primary {
			height: 40px;
			min-height: 40px;
			padding: 0 18px;
			border-radius: 4px;
			font-size: 14px;
			font-weight: 600;
		}
	}
}

/* Import modal ----------------------------------------------------------------------------------- */

.ssw-import__intro {
	margin: 0 0 16px;
	font-size: 13px;
	color: $text-2;
}

.ssw-import__map {
	display: flex;
	flex-direction: column;
	gap: 13px;
}

.ssw-import__map-row {
	display: flex;
	align-items: center;
	gap: 12px;

	label {
		flex: 0 0 150px;
		font-size: 13px;
		font-weight: 500;
		color: $text;
	}
}

.ssw-import__req {
	color: $danger;
}

.ssw-admin .ssw-import__select {
	flex: 1;
	width: 100%;
	max-width: none;
	height: 40px;
	min-height: 40px;
	padding: 0 32px 0 12px;
	border: 0;
	border-radius: 4px;
	box-shadow: inset 0 0 0 1px $line-ring;
	background-color: #fff;
	font-size: 14px;
	color: $ink;
}

.ssw-import__groups {
	display: flex;
	flex-direction: column;
	gap: 8px;
	max-height: 340px;
	overflow-y: auto;
}

.ssw-import__group {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px 14px;
	border: 1px solid $line-card;
	border-radius: 8px;
	background: #f8f9fa;

	&.is-single {
		padding: 14px 16px;

		.ssw-import__tile {
			width: 42px;
			height: 42px;
			border-radius: 9px;
		}

		.ssw-import__name {
			font-size: 15px;
		}
	}
}

.ssw-import__tile {
	display: inline-flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border-radius: 8px;
	background: $tint;
	color: $blue;
}

.ssw-import__name {
	display: block;
	font-size: 14px;
	font-weight: 600;
	color: $ink;
}

.ssw-import__meta {
	display: block;
	font-size: 12.5px;
	color: $muted;
}

.ssw-import__error {
	margin: 14px 0 0;
	padding: 11px 14px;
	border: 1px solid #f5c2c2;
	border-radius: 6px;
	background: #fdecec;
	font-size: 13px;
	color: $danger-2;
}

.ssw-import__done {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 14px;
	padding: 24px 20px;
	text-align: center;

	p {
		margin: 0;
		font-size: 13px;
		color: $muted;
	}
}

.ssw-import__done-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	border-radius: 14px;
	background: #f0f9f2;
	color: #1a7f37;
}

.ssw-import__done-title {
	font-size: 16px;
	font-weight: 600;
	color: $ink;
}

// WooCommerce's `.woocommerce table.form-table` and WordPress's `.form-field input` rules outrank the
// shared skin on these two forms: restate it with an id.
#wpbody .ssw-attrs {

	.form-table th {
		padding: 9px 0 0;
	}

	.form-table input.ssw-wpi,
	.form-wrap input.ssw-wpi {
		width: 100%;
		height: 40px;
		padding: 0 10px 0 12px;
		margin: 0;
	}

	.ssw-spin__value input {
		width: 100%;
		height: auto;
		padding: 0;
		margin: 0;
		border: 0;
		box-shadow: none;
	}
}

// Label icons: the info tip and the demo-video buttons.
.ssw-attrs {

	.ssw-attr-field__label,
	.ssw-attr-panel__body label {
		display: inline-flex !important;
		align-items: center;
		gap: 6px;
	}

	.ssw-label-icon {
		display: inline-flex;
	}
}

.ssw-vtip {
	position: relative;
	display: inline-flex;
}

.ssw-vtip__btn {
	display: inline-flex;
	padding: 0;
	border: 0;
	background: none;
	color: $muted-2;
	cursor: pointer;

	&:hover {
		color: $ink;
	}

	@include focus-visible;
}

.ssw-vtip__pop {
	position: absolute;
	left: 50%;
	bottom: calc(100% + 8px);
	z-index: 30;
	transform: translateX(-50%);
	padding: 4px;
	border-radius: 8px;
	background: #fff;
	box-shadow: $shadow-pop;
	line-height: 0;

	video {
		display: block;
		width: 240px;
		height: auto;
		border-radius: 6px;
	}
}
