/**
 * My Account subscription styles.
 *
 * These components render *inside* whatever theme the merchant is running, so
 * the palette is derived from the theme rather than declared.
 *
 * An earlier version declared its own light and dark palettes and switched on
 * `prefers-color-scheme`. That is wrong for embedded components and axe caught
 * it: on a light-only theme, a visitor whose OS is set to dark got this
 * plugin's light text (#edeff2) painted onto the theme's white page — a
 * contrast ratio of 1.15:1, effectively invisible. The preference describes the
 * user's OS, not the background this markup actually lands on.
 *
 * So neutral colours now derive from `currentColor`, which is whatever the
 * theme set. That adapts correctly to a light theme, a dark theme, or a
 * high-contrast one, with no media query and nothing to keep in sync.
 *
 * The semantic colours (success, warning, error) are the exception: they carry
 * meaning, so they are fixed — and every one of them sets *both* its foreground
 * and its background, which makes their contrast deterministic no matter what
 * the surrounding theme does.
 */

/*
 * The `hidden` attribute must actually hide.
 *
 * `hidden` works through a UA stylesheet rule with the lowest possible
 * precedence, so any author rule setting `display` beats it — and several of
 * these components set `display: flex` on the same element that carries
 * `hidden`. The result was every unavailable action still being offered:
 * the customer saw a Pause button on an already-paused subscription, clicked
 * it, and got "that action is not available".
 *
 * Scoped to this plugin's containers so it cannot affect the theme, and
 * !important because hiding is not negotiable by a layout rule.
 */
.ftgws-detail [hidden],
.ftgws-subscriptions [hidden] {
	display: none !important;
}

.ftgws-detail,
.ftgws-subscriptions {
	--ftgws-radius: 8px;
	--ftgws-gap: 1rem;

	/* Derived from the theme's own text colour, so contrast follows it. */
	--ftgws-border: color-mix( in srgb, currentColor 20%, transparent );
	--ftgws-surface: transparent;
	--ftgws-surface-muted: color-mix( in srgb, currentColor 6%, transparent );
	--ftgws-text-muted: color-mix( in srgb, currentColor 72%, transparent );

	/* Fixed, because they mean something. Each is paired with its own
	   background below so the ratio never depends on the theme. */
	--ftgws-accent: #1d4ed8;
	--ftgws-success-ink: #0f5132;
	--ftgws-success-bg: #e3f4ea;
	--ftgws-warning-ink: #6b4900;
	--ftgws-warning-bg: #fbf2d9;
	--ftgws-error-ink: #8a1620;
	--ftgws-error-bg: #fcecee;

	color: inherit;
}

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

.ftgws-subscriptions {
	display: grid;
	gap: var(--ftgws-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

.ftgws-card {
	display: grid;
	gap: 0.5rem;
	padding: 1.25rem;
	border: 1px solid var(--ftgws-border);
	border-radius: var(--ftgws-radius);
	background: var(--ftgws-surface);
}

.ftgws-card--error {
	border-color: var(--ftgws-error-ink);
	border-left-width: 4px;
}

.ftgws-card__header {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
	align-items: center;
	justify-content: space-between;
}

.ftgws-card__id {
	font-size: 0.8125rem;
	color: var(--ftgws-text-muted);
}

.ftgws-card__price {
	margin: 0;
	font-size: 1.25rem;
	font-weight: 600;
}

.ftgws-card__items {
	margin: 0;
	padding: 0;
	list-style: none;
	font-size: 0.9375rem;
	color: var(--ftgws-text-muted);
}

.ftgws-card__status,
.ftgws-card__next {
	margin: 0;
	font-size: 0.875rem;
	color: var(--ftgws-text-muted);
}

/* --- Badges -------------------------------------------------------------- */

.ftgws-badge {
	display: inline-block;
	padding: 0.2em 0.7em;
	border-radius: 999px;
	font-size: 0.75rem;
	font-weight: 600;
	letter-spacing: 0.02em;
	text-transform: uppercase;
	background: var(--ftgws-surface-muted);
	color: var(--ftgws-text-muted);
}

.ftgws-badge--success {
	background: var(--ftgws-success-bg);
	color: var(--ftgws-success-ink);
}

.ftgws-badge--warning {
	background: var(--ftgws-warning-bg);
	color: var(--ftgws-warning-ink);
}

.ftgws-badge--error {
	background: var(--ftgws-error-bg);
	color: var(--ftgws-error-ink);
}

/* --- Alerts -------------------------------------------------------------- */

.ftgws-alert {
	display: grid;
	gap: 0.5rem;
	margin-bottom: var(--ftgws-gap);
	padding: 1.25rem;
	border-radius: var(--ftgws-radius);
	border: 1px solid var(--ftgws-error-ink);
	/* Both set: a failed-payment alert must stay legible on any theme. */
	background: var(--ftgws-error-bg);
	color: var(--ftgws-error-ink);
}

.ftgws-alert__title {
	margin: 0;
	font-size: 1rem;
	color: inherit;
}

.ftgws-alert__body {
	margin: 0;
}

/* --- Detail -------------------------------------------------------------- */

.ftgws-detail {
	display: grid;
	gap: 2rem;
	color: inherit;
}

.ftgws-detail__header {
	display: grid;
	gap: 0.5rem;
	justify-items: start;
}

.ftgws-detail__title {
	margin: 0;
	font-size: 1.5rem;
}

.ftgws-detail__status,
.ftgws-detail__subtitle {
	margin: 0;
}

.ftgws-detail__subtitle {
	margin-bottom: 0.75rem;
	font-size: 1rem;
}

.ftgws-facts {
	display: grid;
	gap: 0.75rem;
	margin: 0;
	padding: 1.25rem;
	border-radius: var(--ftgws-radius);
	background: var(--ftgws-surface-muted);
}

.ftgws-facts__row {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	justify-content: space-between;
}

.ftgws-facts dt {
	font-weight: 600;
}

.ftgws-facts dd {
	margin: 0;
	text-align: right;
}

.ftgws-facts__hint {
	display: block;
	font-size: 0.8125rem;
	color: var(--ftgws-text-muted);
}

.ftgws-items,
.ftgws-actions {
	display: grid;
	gap: 0.75rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ftgws-items__item {
	padding-bottom: 0.5rem;
	border-bottom: 1px solid var(--ftgws-border);
}

.ftgws-items__line {
	display: flex;
	justify-content: space-between;
}

/**
 * The choices the subscriber configured at checkout — WooCommerce's own
 * item-meta markup from wc_display_item_meta(), restyled from a bulleted
 * list into quiet label–value lines under the plan name. The value arrives
 * wrapped in a block-level <p>, which is what put every value on its own
 * line; forcing it inline keeps "License plate: ABC 123" one line.
 */
.ftgws-items .wc-item-meta {
	margin: 0.375rem 0 0;
	padding: 0;
	list-style: none;
	font-size: 0.9375em;
	color: var(--ftgws-text-muted);
	line-height: 1.55;
}

.ftgws-items .wc-item-meta li {
	margin: 0 0 0.125rem;
}

.ftgws-items .wc-item-meta li:last-child {
	margin-bottom: 0;
}

.ftgws-items .wc-item-meta p {
	display: inline;
	margin: 0;
}

.ftgws-items .wc-item-meta-label {
	font-weight: 500;
}

/**
 * The product's short description — the merchant's own list of what the plan
 * includes. Quieter than the name it sits under, but a real block of content:
 * lists keep their bullets, paragraphs keep their spacing, because this is the
 * text that answers "what am I actually paying for every month".
 */
.ftgws-items__inclusions {
	margin-top: 0.375rem;
	font-size: 0.9375em;
	color: var(--ftgws-text-muted);
	line-height: 1.55;
}

.ftgws-items__inclusions p {
	margin: 0 0 0.5em;
}

.ftgws-items__inclusions p:last-child {
	margin-bottom: 0;
}

.ftgws-items__inclusions ul,
.ftgws-items__inclusions ol {
	margin: 0.25em 0 0.5em;
	padding-left: 1.25em;
	list-style: disc;
}

.ftgws-items__inclusions ol {
	list-style: decimal;
}

.ftgws-items__inclusions li {
	margin-bottom: 0.25em;
}

.ftgws-actions__item {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
	align-items: center;
	justify-content: space-between;
	padding: 0.875rem 1rem;
	border: 1px solid var(--ftgws-border);
	border-radius: var(--ftgws-radius);
}

.ftgws-actions__text {
	display: grid;
	gap: 0.125rem;
}

.ftgws-actions__label {
	font-weight: 600;
}

.ftgws-actions__description {
	font-size: 0.8125rem;
	color: var(--ftgws-text-muted);
}

.ftgws-actions__form {
	display: flex;
	gap: 0.5rem;
	align-items: center;
}

/* --- Buttons ------------------------------------------------------------- */

.ftgws-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px; /* A comfortable touch target. */
	padding: 0.5rem 1.125rem;
	border: 1px solid transparent;
	border-radius: var(--ftgws-radius);
	font: inherit;
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none;
	cursor: pointer;
}

.ftgws-button:focus-visible {
	outline: 2px solid var(--ftgws-accent);
	outline-offset: 2px;
}

.ftgws-button[disabled],
.ftgws-button[aria-busy="true"] {
	opacity: 0.6;
	cursor: progress;
}

.ftgws-button--primary {
	background: var(--ftgws-accent);
	color: #fff;
}

.ftgws-button--secondary {
	/* Inherits the theme's text colour, so it stays readable whatever the
	   surrounding page does. */
	border-color: var(--ftgws-border);
	background: transparent;
	color: inherit;
}

.ftgws-button--danger {
	/* Sets both, so a destructive action is never rendered illegibly. */
	border-color: var(--ftgws-error-ink);
	background: var(--ftgws-error-bg);
	color: var(--ftgws-error-ink);
}

.ftgws-button--ghost {
	background: transparent;
	color: var(--ftgws-text-muted);
}

/* --- Live region --------------------------------------------------------- */

.ftgws-live:empty {
	display: none;
}

.ftgws-live {
	padding: 0.875rem 1rem;
	border-radius: var(--ftgws-radius);
	background: var(--ftgws-success-bg);
	color: var(--ftgws-success-ink);
}

.ftgws-live--error {
	background: var(--ftgws-error-bg);
	color: var(--ftgws-error-ink);
}

/* --- Modal --------------------------------------------------------------- */

.ftgws-modal {
	position: fixed;
	inset: 0;
	display: grid;
	place-items: center;
	padding: 1rem;
	background: rgba( 0, 0, 0, 0.55 );
	z-index: 9999;
}

.ftgws-modal[hidden] {
	display: none;
}

.ftgws-modal__panel {
	/* An overlay sits above the page, so it cannot inherit a background —
	   both are set explicitly, and Canvas/CanvasText follow the OS safely
	   here because we own the whole surface. */
	background: Canvas;
	color: CanvasText;
	display: grid;
	gap: 1rem;
	width: min( 32rem, 100% );
	max-height: 90vh;
	overflow-y: auto;
	padding: 1.75rem;
	border-radius: var(--ftgws-radius);
}

.ftgws-modal__title {
	margin: 0;
	font-size: 1.25rem;
}

.ftgws-modal__body {
	margin: 0;
	color: var(--ftgws-text-muted);
}

.ftgws-modal__offers {
	display: grid;
	gap: 0.75rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ftgws-modal__offers li {
	display: grid;
	gap: 0.375rem;
	padding: 0.875rem;
	border: 1px solid var(--ftgws-border);
	border-radius: var(--ftgws-radius);
	font-size: 0.875rem;
	color: var(--ftgws-text-muted);
}

.ftgws-modal__footer {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
	justify-content: flex-end;
	padding-top: 0.5rem;
	border-top: 1px solid var(--ftgws-border);
}

/* --- Timeline ------------------------------------------------------------ */

.ftgws-timeline {
	display: grid;
	gap: 1rem;
	margin: 0;
	padding: 0 0 0 1.25rem;
	list-style: none;
	border-left: 2px solid var(--ftgws-border);
}

.ftgws-timeline__entry {
	position: relative;
}

.ftgws-timeline__entry::before {
	content: "";
	position: absolute;
	top: 0.4rem;
	left: -1.6rem;
	width: 0.6rem;
	height: 0.6rem;
	border-radius: 50%;
	background: var(--ftgws-border);
}

.ftgws-timeline__entry--payment::before {
	background: var(--ftgws-success-ink);
}

.ftgws-timeline__entry--status::before {
	background: var(--ftgws-accent);
}

.ftgws-timeline__date {
	display: block;
	font-size: 0.75rem;
	color: var(--ftgws-text-muted);
}

.ftgws-timeline__content {
	margin: 0.125rem 0 0;
	font-size: 0.9375rem;
}

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

.ftgws-empty {
	display: grid;
	gap: 0.75rem;
	justify-items: center;
	padding: 3rem 1.5rem;
	border: 1px dashed var(--ftgws-border);
	border-radius: var(--ftgws-radius);
	text-align: center;
}

.ftgws-empty__title {
	margin: 0;
	font-size: 1.25rem;
}

.ftgws-empty__body {
	margin: 0;
	max-width: 34rem;
	color: var(--ftgws-text-muted);
}

/* --- Motion -------------------------------------------------------------- */

@media ( prefers-reduced-motion: reduce ) {
	.ftgws-button,
	.ftgws-modal__panel {
		transition: none !important;
		animation: none !important;
	}
}

/* --- Action feedback ------------------------------------------------------
 *
 * A control that is working must say so without losing its label, and a result
 * must appear next to what produced it. The spinner is a border trick rather
 * than an image so it inherits the theme's colour and needs no asset.
 */

.ftgws-spinner {
	display: inline-block;
	width: 0.85em;
	height: 0.85em;
	margin-right: 0.5em;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	vertical-align: -0.1em;
	animation: ftgws-spin 0.7s linear infinite;
}

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

.ftgws-button.is-busy {
	cursor: progress;
}

/* The result of one action, shown beside that action. */
.ftgws-inline-result {
	flex-basis: 100%;
	margin: 0.5rem 0 0;
	padding: 0.5rem 0.75rem;
	border-radius: var(--ftgws-radius);
	font-size: 0.875rem;
	opacity: 1;
	transition: opacity 0.5s ease;
}

.ftgws-inline-result.is-fading {
	opacity: 0;
}

.ftgws-inline-result--success {
	background: var(--ftgws-success-bg);
	color: var(--ftgws-success-ink);
}

.ftgws-inline-result--error {
	background: var(--ftgws-error-bg);
	color: var(--ftgws-error-ink);
}

/* A brief highlight so a changed status is noticed, not merely present. */
.ftgws-badge--changed {
	animation: ftgws-flash 1.4s ease-out;
}

@keyframes ftgws-flash {
	0%,
	40% {
		box-shadow: 0 0 0 3px color-mix( in srgb, currentColor 35%, transparent );
	}
	100% {
		box-shadow: 0 0 0 0 transparent;
	}
}

/* The live region is focusable so a keyboard user can be moved to the
   confirmation when the control they used has just been hidden. */
.ftgws-live:focus {
	outline: 2px solid var(--ftgws-accent);
	outline-offset: 2px;
}

@media ( prefers-reduced-motion: reduce ) {
	.ftgws-spinner {
		animation: none;
		/* Still visibly different from an idle control, just not moving. */
		border-right-color: currentColor;
		opacity: 0.4;
	}

	.ftgws-badge--changed {
		animation: none;
		outline: 2px solid currentColor;
		outline-offset: 2px;
	}

	.ftgws-inline-result {
		transition: none;
	}
}
