/**
 * Customer-facing tracking.
 *
 * This plugin runs on other people's websites, so it names as few colours as it
 * can. Three ideas do most of the work:
 *
 *  1. The accent comes from the theme. Block themes publish their palette as
 *     --wp--preset--color--*, WooCommerce publishes --wc-primary, and the
 *     fallback at the end of the chain is currentColor — the theme's own text
 *     colour, which is never wrong, only quiet.
 *
 *  2. Surfaces and borders are mixed from currentColor rather than declared.
 *     A panel tinted from the text colour sits correctly on a white theme and
 *     on a dark one without either being detected.
 *
 *  3. Type is never set. No font-family, no base font-size — every size here is
 *     em, so the component is dressed by whatever it is dropped into.
 *
 * Everything is scoped under .ssg-track. The form controls are wrapped in
 * :where() so they carry no specificity at all and a theme's own button and
 * input styling wins outright.
 *
 * To override, set these on the container:
 *
 *   .ssg-track { --ssg-accent: #7b2d52; --ssg-max-width: 900px; }
 */

.ssg-track {
	/*
	 * The theme's accent, in the order themes actually define one. Each
	 * fallback is tried only if the one before it is undefined, so this lands
	 * on the first thing the active theme publishes.
	 */
	--ssg-accent:
		var(--wp--preset--color--primary,
		var(--wp--preset--color--accent,
		var(--wp--preset--color--theme-1,
		var(--wc-primary,
		currentColor))));

	/*
	 * Borders, tints and muted text, mixed from the current text colour.
	 *
	 * Each is declared twice on purpose: a neutral grey that works on light and
	 * dark alike for browsers without color-mix(), then the mixed value, which
	 * replaces it wherever it is supported.
	 */
	--ssg-line: rgba(128, 128, 128, 0.3);
	--ssg-line: color-mix(in srgb, currentColor 18%, transparent);

	--ssg-tint: rgba(128, 128, 128, 0.08);
	--ssg-tint: color-mix(in srgb, currentColor 5%, transparent);

	--ssg-muted: rgba(128, 128, 128, 1);
	--ssg-muted: color-mix(in srgb, currentColor 62%, transparent);

	--ssg-accent-tint: rgba(128, 128, 128, 0.1);
	--ssg-accent-tint: color-mix(in srgb, var(--ssg-accent) 10%, transparent);

	--ssg-radius: 8px;

	/*
	 * Full width of whatever it is placed in, centred, and stopped before it
	 * gets unreadable on a wide screen. In a full-width section that lands at
	 * roughly 80%; in a container the theme has already narrowed it fills it
	 * rather than adding margins of its own.
	 */
	width: 100%;
	max-width: var(--ssg-max-width, 1100px);
	margin-left: auto;
	margin-right: auto;
	box-sizing: border-box;
}

.ssg-track *,
.ssg-track *::before,
.ssg-track *::after {
	box-sizing: border-box;
}

/* ----------------------------------------------------------------------
   The form
   ---------------------------------------------------------------------- */

.ssg-track__form {
	background: var(--ssg-tint);
	border: 1px solid var(--ssg-line);
	border-radius: var(--ssg-radius);
	padding: clamp(14px, 2.2vw, 22px);
	margin-bottom: 20px;
}

.ssg-track__label {
	display: block;
	font-size: 0.8em;
	font-weight: 600;
	color: var(--ssg-muted);
	margin-bottom: 8px;
}

.ssg-track__row {
	display: flex;
	gap: 10px;
	align-items: stretch;
	flex-wrap: wrap;
}

/*
 * Zero specificity, so a theme's own input and button rules beat these without
 * needing !important on their side. What is left here is only what a theme has
 * no opinion about: how the two share the row.
 */
:where(.ssg-track .ssg-track__input) {
	flex: 1 1 240px;
	min-width: 0;
	padding: 0.7em 0.85em;
	border: 1px solid var(--ssg-line);
	border-radius: var(--ssg-radius);
	background: transparent;
	color: inherit;
	font: inherit;
}

:where(.ssg-track .ssg-track__button) {
	flex: 0 0 auto;
	padding: 0.7em 1.9em;
	border: 1px solid var(--ssg-accent);
	border-radius: var(--ssg-radius);
	background: var(--ssg-accent);
	color: var(--wp--preset--color--base, #fff);
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}

/* ----------------------------------------------------------------------
   Result
   ---------------------------------------------------------------------- */

.ssg-track__result {
	border: 1px solid var(--ssg-line);
	border-radius: var(--ssg-radius);
	overflow: hidden;
}

/*
 * The status band is tinted with the accent rather than filled with it.
 *
 * A solid accent needs light text, and nothing here can know whether the
 * theme's accent is dark enough to carry it — a pale brand colour would leave
 * the status unreadable on the one panel that matters most. A tint keeps the
 * theme's own text colour, so it is legible whatever the accent turns out to
 * be, and the accent still shows in the rule, the badge and the steps.
 */
.ssg-track__hero {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 16px;
	padding: clamp(16px, 2.4vw, 24px);
	background: var(--ssg-accent-tint);
	border-left: 4px solid var(--ssg-accent);
}

.ssg-track__hero.is-returned {
	border-left-color: var(--ssg-muted);
}

.ssg-track__hero-main {
	min-width: 0;
}

.ssg-track__hero p {
	margin: 0;
	color: inherit;
}

.ssg-track__hero-label {
	font-size: 0.72em;
	font-weight: 700;
	letter-spacing: 0.09em;
	text-transform: uppercase;
	color: var(--ssg-muted);
}

.ssg-track__hero-status {
	font-size: 1.5em;
	font-weight: 700;
	line-height: 1.25;
	margin-top: 4px !important;
}

.ssg-track__hero-date {
	font-size: 0.9em;
	color: var(--ssg-muted);
	margin-top: 3px !important;
}

.ssg-track__badge {
	flex: 0 0 auto;
	padding: 0.25em 0.9em;
	border: 1px solid var(--ssg-accent);
	border-radius: 999px;
	color: var(--ssg-accent);
	font-size: 0.78em;
	font-weight: 600;
	white-space: nowrap;
}

.ssg-track__plain {
	margin: 0 !important;
	padding: 14px clamp(16px, 2.4vw, 24px);
	border-top: 1px solid var(--ssg-line);
	font-size: 0.95em;
	color: var(--ssg-muted);
}

/* ----------------------------------------------------------------------
   Stepper
   ---------------------------------------------------------------------- */

.ssg-track__steps {
	display: flex;
	list-style: none;
	margin: 0 !important;
	padding: clamp(20px, 3vw, 30px) clamp(16px, 2.4vw, 24px) clamp(16px, 2vw, 22px);
	border-top: 1px solid var(--ssg-line);
}

.ssg-track__step {
	flex: 1 1 0;
	position: relative;
	text-align: center;
	margin: 0 !important;
	padding: 0 4px;
	list-style: none;
}

.ssg-track__step::before {
	/*
	 * The connector, drawn backwards from each step to the one before it. Done
	 * this way the first step simply has none, and the line can never overshoot
	 * the end of the row.
	 */
	content: "";
	position: absolute;
	top: 6px;
	right: 50%;
	width: 100%;
	height: 2px;
	background: var(--ssg-line);
}

.ssg-track__step:first-child::before {
	display: none;
}

.ssg-track__step.is-done::before,
.ssg-track__step.is-current::before {
	background: var(--ssg-accent);
}

.ssg-track__dot {
	position: relative;
	z-index: 1;
	display: block;
	width: 14px;
	height: 14px;
	margin: 0 auto 10px;
	border-radius: 50%;
	background: var(--ssg-line);
}

.ssg-track__step.is-done .ssg-track__dot,
.ssg-track__step.is-current .ssg-track__dot {
	background: var(--ssg-accent);
}

.ssg-track__step.is-current .ssg-track__dot {
	box-shadow: 0 0 0 4px var(--ssg-accent-tint);
}

.ssg-track__step-label {
	display: block;
	font-size: 0.82em;
	line-height: 1.35;
	color: var(--ssg-muted);
}

.ssg-track__step.is-done .ssg-track__step-label,
.ssg-track__step.is-current .ssg-track__step-label {
	color: inherit;
	font-weight: 600;
}

/* ----------------------------------------------------------------------
   Facts
   ---------------------------------------------------------------------- */

.ssg-track__facts {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
	gap: 18px 24px;
	margin: 0 !important;
	padding: clamp(16px, 2.4vw, 24px);
	border-top: 1px solid var(--ssg-line);
}

.ssg-track__fact {
	min-width: 0;
}

.ssg-track__facts dt {
	margin: 0;
	font-size: 0.7em;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--ssg-muted);
}

.ssg-track__facts dd {
	margin: 4px 0 0 !important;
	font-size: 0.98em;
	font-weight: 600;
	overflow-wrap: break-word;
}

/* ----------------------------------------------------------------------
   History
   ---------------------------------------------------------------------- */

.ssg-track__history {
	padding: clamp(16px, 2.4vw, 24px) clamp(16px, 2.4vw, 24px) 6px;
	border-top: 1px solid var(--ssg-line);
	background: var(--ssg-tint);
}

.ssg-track__history-title {
	margin: 0 0 16px !important;
	font-size: 1em;
	font-weight: 700;
}

.ssg-track__events {
	list-style: none;
	margin: 0 !important;
	padding: 0 0 0 22px;
}

.ssg-track__event {
	position: relative;
	margin: 0 0 18px !important;
	padding: 0;
	list-style: none;
}

.ssg-track__event::before {
	content: "";
	position: absolute;
	left: -22px;
	top: 5px;
	width: 9px;
	height: 9px;
	border-radius: 50%;
	background: var(--ssg-line);
}

.ssg-track__event.is-latest::before {
	background: var(--ssg-accent);
}

.ssg-track__event::after {
	/*
	 * The line down to the next checkpoint, drawn downward and suppressed on
	 * the last entry, so the timeline ends with the history instead of trailing
	 * past it.
	 */
	content: "";
	position: absolute;
	left: -18.5px;
	top: 16px;
	width: 2px;
	height: calc(100% + 6px);
	background: var(--ssg-line);
}

.ssg-track__event:last-child::after {
	display: none;
}

.ssg-track__event-status {
	display: block;
	font-weight: 600;
	font-size: 0.98em;
}

.ssg-track__event-date,
.ssg-track__event-where {
	display: block;
	color: var(--ssg-muted);
}

.ssg-track__event-date {
	font-size: 0.87em;
}

.ssg-track__event-where {
	text-transform: uppercase;
	letter-spacing: 0.05em;
	font-size: 0.76em;
}

/* ----------------------------------------------------------------------
   Messages
   ---------------------------------------------------------------------- */

.ssg-track__pending,
.ssg-track__external {
	margin: 0 !important;
	padding: 15px clamp(16px, 2.4vw, 24px);
	border-top: 1px solid var(--ssg-line);
	font-size: 0.92em;
}

.ssg-track__pending {
	color: var(--ssg-muted);
}

.ssg-track__error {
	margin: 0 !important;
	padding: 14px 16px;
	border: 1px solid var(--ssg-line);
	border-left: 4px solid var(--ssg-accent);
	border-radius: var(--ssg-radius);
	background: var(--ssg-tint);
}

/* ----------------------------------------------------------------------
   Order page block
   ---------------------------------------------------------------------- */

.ssg-tracking-links a + a {
	margin-left: 4px;
}

/* ----------------------------------------------------------------------
   Narrow screens
   ---------------------------------------------------------------------- */

@media (max-width: 600px) {
	.ssg-track__hero {
		flex-direction: column;
		gap: 10px;
	}

	/*
	 * The stepper turns vertical rather than shrinking. Four labels squeezed
	 * across a phone wrap into unreadable stacks of one word each, and the
	 * progress they are there to show is the first thing lost.
	 */
	.ssg-track__steps {
		display: block;
		padding-left: clamp(16px, 5vw, 24px);
	}

	.ssg-track__step {
		display: flex;
		align-items: center;
		gap: 12px;
		text-align: left;
		padding: 0 0 14px;
	}

	.ssg-track__step:last-child {
		padding-bottom: 0;
	}

	.ssg-track__step::before {
		top: auto;
		right: auto;
		bottom: -7px;
		left: 6px;
		width: 2px;
		height: calc(100% - 14px);
	}

	.ssg-track__step:first-child::before {
		display: block;
	}

	.ssg-track__step:last-child::before {
		display: none;
	}

	/* Vertically the connector belongs to the step above it, so the colour
	   comes from that step rather than the one it points at. */
	.ssg-track__step::before {
		background: var(--ssg-line);
	}

	.ssg-track__step.is-done::before {
		background: var(--ssg-accent);
	}

	.ssg-track__step.is-current::before {
		background: var(--ssg-line);
	}

	.ssg-track__dot {
		margin: 0;
		flex: 0 0 auto;
	}
}

/* The date each step was reached, read from the history that fills the bar. */
.ssg-track__step-date {
	display: block;
	margin-top: 3px;
	font-size: 0.72em;
	color: var(--ssg-muted);
}

.ssg-track__step:not(.is-done):not(.is-current) .ssg-track__step-date {
	display: none;
}
