@use "../tokens" as *;

// Settings app page (appendix B §4.3). The app is full-bleed inside the WordPress admin content
// area, like the prototype: no #wpcontent gutter, canvas background.
body.ssw-settings-page {
	background: $canvas;

	#wpcontent {
		padding-left: 0;
	}

	#wpbody-content {
		padding-bottom: 0;
	}

	// Notices printed by other plugins sit above the app with the usual admin gutter.
	#wpbody-content > .notice,
	#wpbody-content > .error,
	#wpbody-content > .updated {
		margin: 12px 20px;
	}
}

.ssw-settings {
	padding: 0 0 60px;
	min-height: calc(100vh - 32px);
	// Closed popovers and tooltips near the right edge still take layout room: never let them widen
	// the page on phones. `clip`, unlike `hidden`, keeps the sticky Save button and preview working.
	overflow-x: clip;
}

$gutter: max(20px, calc((100% - 1260px) / 2));

.ssw-settings__columns {
	position: relative;
	display: flex;
	gap: 20px;
	padding: 20px $gutter;
	align-items: flex-start;
	flex-wrap: wrap;

	// Pro Features tab: the options and live preview stay mounted (draft, size observer) but out of sight.
	&[hidden] {
		display: none;
	}
}

.ssw-settings__options {
	flex: 46 1 0;
	// Narrower than this the rows cramp: the preview gives way first (tablets), then the columns
	// stack (.is-compact, set by the app below 740px of room).
	min-width: 380px;
}

// Settings tab: no preview, the options take the row (prototype `optColMax: none`).
.ssw-settings__columns.is-wide .ssw-settings__options {
	flex-basis: 100%;
	min-width: 0;
}

.ssw-settings__heading {
	font-size: 17px;
	font-weight: 600;
	line-height: 1.5;
	color: $ink;
	margin: 0 0 22px;
	padding: 0;
}

.ssw-settings__preview {
	flex: 54 1 0;
	min-width: 300px;
	align-self: stretch;
	display: flex;
	flex-direction: column;
	z-index: 2;
}

// Settings tab: only the Save button remains, floating top right.
.ssw-settings__preview.is-floating {
	flex: 0 0 auto;
	min-width: 0;
	position: absolute;
	top: 20px;
	right: $gutter;
}

// The Save button stays in view while the options scroll, right under the admin bar (32px) and top
// bar (60px), with the live preview stuck below it (.ssw-preview). The canvas band covers the gap
// above and below the button, so the preview slides under it rather than showing through if the
// page ends before the preview can stay whole. In the floating Settings-tab box it has no room to
// move and stays put.
.ssw-settings__save {
	position: sticky;
	top: 92px;
	z-index: 1;
	display: flex;
	justify-content: flex-end;
	margin-top: -20px;
	padding: 20px 0 12px;
	background: $canvas;
}

// Below 782px the top bar scrolls away (_shell.scss) and the admin bar is 46px tall: the Save
// button and the preview stick under the admin bar alone.
@media screen and (max-width: 782px) {

	.ssw-settings__save {
		top: 46px;
	}

	.ssw-preview {
		top: 114px;
		max-height: calc(100vh - 194px);
	}
}

// One column (the app sets .is-compact when the columns get less than 740px) --------------------
// Options first, the preview after them, whole. Save moves to a bar fixed at the bottom of the
// screen, beside a button that jumps between the options and the preview.
$actionbar: 57px;

.ssw-settings__columns.is-compact {

	> .ssw-settings__options,
	> .ssw-settings__preview:not(.is-floating) {
		flex-basis: 100%;
		min-width: 0;
	}

	> .ssw-settings__preview {
		// Clear of the admin bar when the jump button scrolls here.
		scroll-margin-top: 62px;
	}

	.ssw-settings__save {
		position: fixed;
		top: auto;
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 30;
		align-items: center;
		gap: 12px;
		margin: 0;
		padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
		border-top: 1px solid $line-card;
		background: #fff;
		box-shadow: 0 -4px 12px -4px rgba(16, 17, 20, 0.12);
	}

	.ssw-preview {
		position: static;
		max-height: none;
	}
}

.ssw-settings__jump {
	margin-right: auto;
}

// Room under the page for the action bar, so it never covers the last options or the footer.
body.ssw-has-actionbar {

	#wpbody-content {
		padding-bottom: calc(65px + #{$actionbar});
	}

	#wpfooter {
		bottom: $actionbar;
	}
}

// Phones: tighter gutters and cards leave the controls more room.
@media screen and (max-width: 600px) {

	.ssw-settings__columns {
		padding: 16px;
		gap: 16px;
	}

	.ssw-settings__columns.is-compact > .ssw-settings__preview {
		scroll-margin-top: 16px;
	}

	.ssw-settings .ssw-card {
		padding: 16px;
	}
}

// Tabs whose content arrives in a later phase.
.ssw-pending {
	font-size: 14px;
	color: $muted;
	margin: 0;
}

// Save errors (WordPress notice markup inside the app).
.ssw-settings .ssw-settings__notice {
	margin: 0 0 16px;
}

// Two fields side by side (Swatch Box Size, Tooltip Color).
.ssw-field-pair {
	display: flex;
	gap: 10px;
	flex-wrap: wrap;

	&.is-wide {
		gap: 14px;
	}
}

.ssw-field-pair__item {
	min-width: 0;
}

// Swatch Border: equal columns, the last one the Style dropdown.
.ssw-border-grid {
	display: grid;
	grid-auto-flow: column;
	grid-auto-columns: minmax(0, 1fr);
	gap: 8px;
}

// Get Started (appendix B §4.4): between the navbar and the columns; closes by collapsing.
.ssw-getstarted {
	display: grid;
	grid-template-rows: 1fr;
	padding: 20px $gutter 0;
	opacity: 1;
	transition: grid-template-rows 360ms cubic-bezier(0.2, 0, 0, 1), opacity 240ms, padding 360ms;

	&.is-closing {
		grid-template-rows: 0fr;
		padding-top: 0;
		opacity: 0;
	}
}

.ssw-getstarted__inner {
	min-height: 0;
	overflow: hidden;
}

// Legacy behaviour notes (upgraded stores only; PLAN §6.4).
.ssw-legacy {
	display: flex;
	gap: 8px;
	align-items: flex-start;
	margin: 0 0 6px;
	padding: 10px 12px;
	border-radius: $radius-menu;
	background: #fcf9e8;
	box-shadow: inset 0 0 0 1px #f0e1a8;
	color: $warning;

	svg {
		margin-top: 2px;
	}

	p {
		margin: 0;
		font-size: 13px;
		line-height: 1.5;
		color: $text;
	}
}

.ssw-admin .ssw-legacy__action {
	color: $blue;
	font-weight: 500;
	text-decoration: underline;
	text-underline-offset: 2px;

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

	@include focus-visible;
}

// "Switch to the new card settings" (PLAN §7.4; not in the prototype).
.ssw-convert {
	font-size: 13px;
	line-height: 1.5;
	color: $text;

	p {
		margin: 0 0 14px;
	}

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

.ssw-convert__loading {
	color: $faint-2;
}

.ssw-convert__list {
	display: grid;
	grid-template-columns: 120px minmax(0, 1fr);
	gap: 10px 16px;
	margin: 0 0 14px;
	padding: 14px 16px;
	border-radius: $radius-menu;
	background: #f6f7f7;

	dt {
		font-weight: 600;
		color: $ink;
	}

	dd {
		margin: 0;
	}
}

.ssw-convert__names {
	margin-top: 4px !important;
	color: #50575e;
}

.ssw-convert__more {
	color: $faint-2;
}

.ssw-convert__notes li {
	position: relative;
	margin: 0 0 4px;
	padding-left: 14px;

	&::before {
		content: "•";
		position: absolute;
		left: 2px;
		color: $faint-2;
	}
}

.ssw-convert__error {
	margin: 12px 0 0 !important;
	color: $danger;
}

// Settings tab (appendix B §8): sub-tab nav beside the content card.
.ssw-adv {
	display: grid;
	grid-template-columns: minmax(150px, 200px) minmax(0, 1fr);
	gap: 20px;
	align-items: start;
}

.ssw-adv__content {
	min-width: 0;
}

@media screen and (max-width: 782px) {

	.ssw-adv {
		grid-template-columns: minmax(0, 1fr);
	}
}

.ssw-settings-row.is-center {
	align-items: center;
}

.ssw-settings-row__with-info {
	display: flex;
	align-items: center;
	gap: 6px;
}

// Custom CSS.
.ssw-css {
	padding-top: 10px;
}

.ssw-admin .ssw-css__input {
	// Inline like the prototype's textarea: the line box leaves the same gap below it.
	display: inline-block;
	vertical-align: baseline;
	width: 100%;
	min-height: 120px;
	font-family: ui-monospace, Menlo, Consolas, monospace;
	font-size: 13px;
}

.ssw-filters__title {
	margin-top: 12px;
	font-size: 12.5px;
	font-weight: 600;
	color: $muted-2;
}

.ssw-filters__row {
	display: flex;
	gap: 10px;
	align-items: baseline;
	padding: 8px 0;
	border-top: 1px solid $line-list;

	// WordPress's common.css pads, tints and spaces <code>.
	code {
		margin: 0;
		padding: 0;
		background: none;
		font-family: ui-monospace, Menlo, Consolas, monospace;
		font-size: 12px;
		color: $blue;
		white-space: nowrap;
	}

	span {
		font-size: 12.5px;
		color: $muted-2;
	}
}

// License, "not activated": key and Activate on one row (design of 2026-10-16).
.ssw-license {
	min-height: 400px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 28px 16px 32px;
}

.ssw-license__box {
	width: 100%;
	max-width: 460px;
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
}

.ssw-license__title {
	margin: 0;
	font-size: 22px;
	font-weight: 600;
	color: $ink;
	letter-spacing: -0.01em;
	line-height: 1.3;
}

.ssw-license__sub {
	margin: 10px 0 0;
	font-size: 14px;
	color: $muted;
	line-height: 1.6;
	text-wrap: pretty;

	// Underlined (the prototype is colour-only): a link inside text needs more than colour (WCAG 1.4.1).
	a {
		color: $blue;
		text-decoration: underline;
		text-underline-offset: 2px;

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

.ssw-license__form {
	margin-top: 24px;
	width: 100%;
	display: flex;
	align-items: stretch;
	gap: 10px;
}

.ssw-license__field {
	position: relative;
	display: flex;
	align-items: center;
	flex: 1;
	min-width: 0;

	svg {
		position: absolute;
		left: 12px;
		pointer-events: none;
	}
}

.ssw-admin .ssw-license__input {
	width: 100%;
	height: 40px;
	border: 0;
	border-radius: $radius-control;
	box-shadow: inset 0 0 0 1px $line-ring;
	background: #fff;
	padding: 0 12px 0 38px;
	font-size: 14px;
	letter-spacing: 0.04em;
	color: $text;
	outline: none;
	transition: box-shadow 140ms ease;

	&:hover {
		box-shadow: inset 0 0 0 1px $faint;
	}

	&:focus {
		box-shadow: inset 0 0 0 1px $text;
	}

	&.is-error {
		box-shadow: inset 0 0 0 1px $danger;
	}

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

.ssw-admin .ssw-license__activate {
	flex: 0 0 auto;
	min-width: 118px;
	height: 40px;
	padding: 0 20px;
	border-radius: $radius-control;
	background: $blue;
	color: #fff;
	font-size: 14px;
	font-weight: 500;
	line-height: normal;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	transition: background 140ms ease, opacity 140ms ease;

	&:hover {
		background: $blue-2;
	}

	&.is-empty {
		opacity: 0.6;
		cursor: default;
	}

	@include focus-visible;
}

.ssw-license__box > .ssw-collapse {
	width: 100%;
	transition: grid-template-rows 200ms ease, opacity 200ms ease;
}

.ssw-license__error {
	margin: 0;
	padding-top: 8px;
	text-align: left;
	font-size: 13px;
	color: $danger;
}

.ssw-license__note {
	margin: 10px 0 0;
	font-size: 13px;
	color: $muted;
}

.ssw-admin .ssw-license__activate.is-busy {
	opacity: 0.85;
	cursor: progress;
}

.ssw-license__spinner {
	width: 14px;
	height: 14px;
	border: 2px solid rgba(255, 255, 255, 0.35);
	border-top-color: #fff;
	border-radius: 50%;
	animation: ssw-lic-spin 700ms linear infinite;
}

@keyframes ssw-lic-spin {

	to {
		transform: rotate(360deg);
	}
}

// Active state (appendix B §8.4 State B).
.ssw-license__active {
	width: 100%;
	max-width: 460px;
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
}

.ssw-license__tick {
	width: 52px;
	height: 52px;
	display: flex;
	align-items: center;
	justify-content: center;

	&.is-new {
		animation: ssw-lic-pop 480ms $ease both;

		circle {
			stroke-dashoffset: 57;
			animation: ssw-lic-draw 560ms $ease 200ms forwards;
		}

		path {
			stroke-dashoffset: 12;
			animation: ssw-lic-draw 360ms $ease 680ms forwards;
		}
	}

	@media (prefers-reduced-motion: reduce) {

		&.is-new,
		&.is-new circle,
		&.is-new path {
			animation: none;
			stroke-dashoffset: 0;
		}
	}
}

@keyframes ssw-lic-pop {

	from {
		opacity: 0;
		transform: scale(0.6);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

@keyframes ssw-lic-draw {

	to {
		stroke-dashoffset: 0;
	}
}

.ssw-license__done-title {
	margin-top: 16px;
	font-size: 22px;
	font-weight: 600;
	color: $ink;
	letter-spacing: -0.01em;
	line-height: 1.3;
}

.ssw-license__done-sub {
	margin-top: 6px;
	font-size: 14px;
	color: $muted;
	line-height: 1.6;
}

.ssw-license__table {
	margin-top: 24px;
	width: 100%;
	display: flex;
	flex-direction: column;
	border-radius: 6px;
	box-shadow: inset 0 0 0 1px $line-card;
}

.ssw-license__row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 16px;
	padding: 13px 16px;

	& + & {
		box-shadow: inset 0 1px 0 $line-list;
	}
}

.ssw-license__label {
	font-size: 14px;
	color: $muted-2;
}

.ssw-license__value {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 2px;
	min-width: 0;
	text-align: right;
	font-size: 14px;
	font-weight: 600;
	color: $ink;

	.is-mono {
		font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
		font-size: 13.5px;
		font-weight: 400;
		letter-spacing: 0.02em;
	}
}

.ssw-license__value-sub {
	font-size: 13px;
	font-weight: 400;
	color: $muted-2;
}

.ssw-license__foot {
	margin-top: 16px;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 6px 10px;
	font-size: 13px;

	> span[aria-hidden] {
		color: $line-ring-strong;
	}

	a {
		color: $blue;
		text-decoration: none;

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

.ssw-license__checked {
	color: $muted-2;
}

.ssw-license__error.is-inline {
	padding-top: 12px;
	text-align: center;
}

.ssw-license__active > .ssw-collapse {
	width: 100%;
}

// Keeps the button's focus ring and ring shadow inside the collapsing row.
.ssw-license__deactivate-wrap {
	padding: 0 2px 2px;
}

.ssw-admin .ssw-license__deactivate {
	margin-top: 20px;
	height: 40px;
	padding: 0 20px;
	border-radius: $radius-control;
	background: #fff;
	box-shadow: inset 0 0 0 1px $line-ring;
	color: $text-2;
	font-size: 14px;
	font-weight: 500;
	transition: box-shadow 140ms ease, color 140ms ease;

	&:hover {
		box-shadow: inset 0 0 0 1px $danger;
		color: $danger-2;
	}

	@include focus-visible;
}

// Inline confirmation that replaces the Deactivate button.
.ssw-license__ask {
	margin-top: 20px;
	padding: 16px;
	border-radius: 6px;
	background: $danger-tint;
	box-shadow: inset 0 0 0 1px #f5c6ca;
	text-align: left;
	transform: translateY(-6px);
	transition: transform 280ms $ease-std;

	.is-open > div > & {
		transform: none;
	}

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

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

.ssw-license__ask-text {
	margin: 4px 0 0;
	font-size: 13px;
	line-height: 1.55;
	color: #50575e;
	text-wrap: pretty;
}

.ssw-license__ask-actions {
	margin-top: 14px;
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

.ssw-admin .ssw-license__ask-cancel,
.ssw-admin .ssw-license__ask-confirm {
	height: 36px;
	padding: 0 14px;
	border-radius: $radius-control;
	font-size: 14px;
	font-weight: 500;
	line-height: normal;

	@include focus-visible;
}

.ssw-admin .ssw-license__ask-cancel {
	background: #fff;
	box-shadow: inset 0 0 0 1px $line-ring;
	color: $text;
	transition: box-shadow 140ms ease;

	&:hover {
		box-shadow: inset 0 0 0 1px $faint;
	}
}

.ssw-admin .ssw-license__ask-confirm {
	background: $danger;
	color: #fff;
	transition: background 140ms ease;

	&:hover {
		background: $danger-2;
	}

	&[aria-busy="true"] {
		cursor: progress;
		opacity: 0.85;
	}
}
