/*
 * TSW WooCommerce Withdrawal — front-end styles.
 *
 * Everything is scoped inside .tsw-wd-wrap. No element is styled globally and
 * no theme rule is overridden outside this wrapper.
 *
 * Colours come from CSS custom properties that FIRST try the host theme's own
 * tokens and fall back to neutral values, so the form inherits a client's
 * palette automatically and still looks finished on a theme that defines
 * nothing.
 *
 * Specificity note: WooCommerce's bundled stylesheet carries a real
 * ".woocommerce ... button.button" rule (2 classes + 1 type once :where()'s
 * zero specificity is accounted for) that would otherwise repaint our buttons
 * with the pale default WooCommerce look. Our own button/input rules are
 * therefore written at three classes so they win outright, without !important.
 */

.tsw-wd-wrap {
	/* ---- layout ---- */
	--tsw-wd-max: 860px;

	/* ---- shape ---- */
	--tsw-wd-radius: var(--radius-medium, 10px);
	--tsw-wd-radius-sm: var(--radius-small, 6px);

	/* ---- type ---- */
	--tsw-wd-font: var(--font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif);

	/* ---- surfaces ---- */
	--tsw-wd-surface: var(--color-background-surface, #ffffff);
	--tsw-wd-surface-2: var(--color-background-muted, #f5f6f8);

	/* ---- text ---- */
	--tsw-wd-text: var(--color-text-primary, #1b1f24);
	--tsw-wd-text-muted: var(--color-text-secondary, #59626d);

	/* ---- lines ---- */
	--tsw-wd-border: var(--color-border-default, rgba(20, 24, 31, 0.18));
	--tsw-wd-border-subtle: var(--color-border-subtle, rgba(20, 24, 31, 0.09));

	/* ---- accent ---- */
	--tsw-wd-accent: var(--color-primary, #1f6feb);
	--tsw-wd-accent-hover: var(--color-primary-hover, #1a5fd0);
	--tsw-wd-on-accent: #ffffff;
	/* Plain-rgba default so the ring still renders where color-mix() is not
	   supported; override it to match a client's accent exactly. */
	--tsw-wd-focus-ring: rgba(31, 111, 235, 0.35);

	/* ---- semantic ---- */
	--tsw-wd-error: var(--color-error, #b42318);
	--tsw-wd-error-bg: var(--color-error-bg, #fdeeec);
	--tsw-wd-success: var(--color-success, #2f6b4f);
	--tsw-wd-success-bg: var(--color-success-bg, #e7f2ec);
	--tsw-wd-warning: var(--color-warning, #9a6700);
	--tsw-wd-warning-bg: var(--color-warning-bg, #fbf4e4);

	box-sizing: border-box;
	width: 100%;
	max-width: var(--tsw-wd-max);
	margin-inline: auto;
	padding: clamp(20px, 3vw, 36px) clamp(16px, 4vw, 32px) clamp(40px, 6vw, 72px);
	font-family: var(--tsw-wd-font);
	font-size: 16px;
	line-height: 1.6;
	color: var(--tsw-wd-text);
}

/* A theme that defines no tokens at all still needs a sane dark palette. */
@media (prefers-color-scheme: dark) {
	.tsw-wd-wrap {
		--tsw-wd-surface: var(--color-background-surface, #16181d);
		--tsw-wd-surface-2: var(--color-background-muted, #1e2127);
		--tsw-wd-text: var(--color-text-primary, #f2f4f7);
		--tsw-wd-text-muted: var(--color-text-secondary, #a4adba);
		--tsw-wd-border: var(--color-border-default, rgba(255, 255, 255, 0.18));
		--tsw-wd-border-subtle: var(--color-border-subtle, rgba(255, 255, 255, 0.09));
	}
}

.tsw-wd-wrap *,
.tsw-wd-wrap *::before,
.tsw-wd-wrap *::after {
	box-sizing: border-box;
}

.tsw-wd-wrap > * + * {
	margin-top: clamp(20px, 3vw, 28px);
}

/*
 * The ONE rule that touches an element outside .tsw-wd-wrap.
 *
 * Themes commonly print the page <h1> in their own template, outside anything
 * this plugin controls, and a full-bleed title above a centred form reads as
 * broken. ":has(> .tsw-wd-wrap)" resolves to our wrapper's own direct parent
 * and nothing else, and body.tsw-wd-page only ever exists on this plugin's
 * page — so this cannot affect any other page, on any theme. Browsers without
 * :has() simply ignore it and the title keeps the theme's own alignment.
 */
body.tsw-wd-page :has(> .tsw-wd-wrap) > h1 {
	box-sizing: border-box;
	max-width: 860px;
	margin-inline: auto;
	padding-inline: clamp(16px, 4vw, 32px);
	/*
	 * Breathing room under the theme's sticky navigation, which otherwise
	 * sits flush against the title (measured gap: 0px).
	 *
	 * padding, not margin: a top margin here would collapse through the
	 * article and main wrappers - both have margin-top:0 and no padding or
	 * border to stop it - and would end up pushing the whole page down
	 * instead of separating the title. Padding cannot collapse, and because
	 * it is inside the h1 box the sticky header scrolls over empty space
	 * rather than over the text.
	 *
	 * clamp: 32px floor, 4vw in between, 56px ceiling on desktop. The floor is
	 * 32 rather than 28 because the h1's line box adds roughly a pixel of
	 * ascender lead, so a 28px floor measured 27px between the navigation and
	 * the actual glyphs - just under the intended range.
	 */
	padding-top: clamp(32px, 4vw, 56px);
}

/* -------------------------------------------------------------- typography */

.tsw-wd-wrap .tsw-wd-lead {
	margin: 0;
	font-size: clamp(16px, 1.6vw, 18px);
	line-height: 1.65;
	color: var(--tsw-wd-text);
}

.tsw-wd-wrap .tsw-wd-h2 {
	margin: 0 0 6px;
	font-family: var(--font-family-display, var(--tsw-wd-font));
	font-size: clamp(19px, 2.2vw, 23px);
	font-weight: 700;
	line-height: 1.25;
	color: var(--tsw-wd-text);
	text-wrap: balance;
}

.tsw-wd-wrap .tsw-wd-step-hint {
	margin: 0 0 20px;
	font-size: 14px;
	color: var(--tsw-wd-text-muted);
}

/* --------------------------------------------------------------- info box */

.tsw-wd-wrap .tsw-wd-info {
	margin: 0;
	padding: 18px 20px;
	border: 1px solid var(--tsw-wd-border-subtle);
	border-left: 3px solid var(--tsw-wd-accent);
	border-radius: var(--tsw-wd-radius-sm);
	background: var(--tsw-wd-surface-2);
}

.tsw-wd-wrap .tsw-wd-info-title {
	margin: 0 0 10px;
	font-size: 13px;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--tsw-wd-text-muted);
}

.tsw-wd-wrap .tsw-wd-info ul {
	margin: 0;
	padding: 0;
	list-style: none;
	display: grid;
	gap: 10px;
}

.tsw-wd-wrap .tsw-wd-info li {
	position: relative;
	margin: 0;
	padding-left: 22px;
	font-size: 14.5px;
	line-height: 1.55;
	color: var(--tsw-wd-text-muted);
}

.tsw-wd-wrap .tsw-wd-info li::before {
	content: "";
	position: absolute;
	top: 0.62em;
	left: 4px;
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--tsw-wd-accent);
}

.tsw-wd-wrap .tsw-wd-privacy {
	margin: 0;
	font-size: 13px;
	line-height: 1.55;
	color: var(--tsw-wd-text-muted);
}

/* -------------------------------------------------------------- form card */

.tsw-wd-wrap .tsw-wd-card {
	padding: clamp(20px, 3vw, 32px);
	border: 1px solid var(--tsw-wd-border-subtle);
	border-radius: var(--tsw-wd-radius);
	background: var(--tsw-wd-surface);
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
}

.tsw-wd-wrap .tsw-wd-form {
	margin: 0;
}

.tsw-wd-wrap .tsw-wd-form .tsw-wd-field {
	display: block;
	margin: 0 0 20px;
	padding: 0;
}

.tsw-wd-wrap .tsw-wd-form .tsw-wd-field:last-of-type {
	margin-bottom: 0;
}

.tsw-wd-wrap .tsw-wd-form .tsw-wd-field label {
	display: block;
	margin: 0 0 7px;
	font-size: 14px;
	font-weight: 600;
	line-height: 1.4;
	color: var(--tsw-wd-text);
}

.tsw-wd-wrap .tsw-wd-req {
	color: var(--tsw-wd-error);
	font-weight: 700;
}

.tsw-wd-wrap .tsw-wd-opt {
	font-weight: 400;
	color: var(--tsw-wd-text-muted);
}

.tsw-wd-wrap .tsw-wd-hint {
	display: block;
	margin-top: 7px;
	font-size: 13px;
	line-height: 1.5;
	color: var(--tsw-wd-text-muted);
}

/* ----------------------------------------------------------------- fields */

.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-input,
.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-select,
.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-textarea {
	display: block;
	width: 100%;
	max-width: 100%;
	margin: 0;
	padding: 12px 14px;
	border: 1px solid var(--tsw-wd-border);
	border-radius: var(--tsw-wd-radius-sm);
	background-color: var(--tsw-wd-surface-2);
	background-image: none;
	color: var(--tsw-wd-text);
	font-family: inherit;
	font-size: 16px; /* 16px keeps iOS from zooming on focus. */
	line-height: 1.45;
	box-shadow: none;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
	-webkit-appearance: none;
	appearance: none;
}

.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-input,
.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-select {
	height: 48px;
}

.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-textarea {
	min-height: 110px;
	height: auto;
	resize: vertical;
}

.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-select {
	padding-right: 40px;
	background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
	background-position: calc(100% - 20px) calc(50% + 2px), calc(100% - 14px) calc(50% + 2px);
	background-size: 6px 6px, 6px 6px;
	background-repeat: no-repeat;
	cursor: pointer;
}

.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-input::placeholder,
.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-textarea::placeholder {
	color: var(--tsw-wd-text-muted);
	opacity: 1;
}

.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-input:hover,
.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-select:hover,
.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-textarea:hover {
	border-color: var(--tsw-wd-border);
}

/*
 * Focus is declared in two separate blocks on purpose. A single list mixing
 * :focus with :focus-visible would be discarded whole by any engine that does
 * not know :focus-visible, taking the plain :focus ring down with it.
 *
 * The ring is drawn with box-shadow as well as outline: themes and reset
 * sheets very often set "outline: none" on focused inputs, and a spread
 * shadow survives that, so the field can never end up with no visible focus
 * state at all.
 */
.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-input:focus,
.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-select:focus,
.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-textarea:focus {
	border-color: var(--tsw-wd-accent);
	outline: 2px solid var(--tsw-wd-accent);
	outline-offset: 2px;
	box-shadow: 0 0 0 3px var(--tsw-wd-focus-ring);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--tsw-wd-accent) 35%, transparent);
}

.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-input:focus-visible,
.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-select:focus-visible,
.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-textarea:focus-visible {
	border-color: var(--tsw-wd-accent);
	outline: 2px solid var(--tsw-wd-accent);
	outline-offset: 2px;
}

/* ---------------------------------------------------------------- buttons */

.tsw-wd-wrap .tsw-wd-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 16px;
	margin: 26px 0 0;
	padding-top: 22px;
	border-top: 1px solid var(--tsw-wd-border-subtle);
}

.tsw-wd-wrap .tsw-wd-form button.tsw-wd-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 48px;
	padding: 12px 28px;
	border: 2px solid var(--tsw-wd-accent);
	border-radius: var(--tsw-wd-radius-sm);
	background-color: var(--tsw-wd-accent);
	color: var(--tsw-wd-on-accent);
	font-family: inherit;
	font-size: 13px;
	font-weight: 800;
	letter-spacing: 0.04em;
	line-height: 1.2;
	text-transform: uppercase;
	text-decoration: none;
	text-shadow: none;
	cursor: pointer;
	transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
	-webkit-appearance: none;
	appearance: none;
}

.tsw-wd-wrap .tsw-wd-form button.tsw-wd-button:hover,
.tsw-wd-wrap .tsw-wd-form button.tsw-wd-button:focus {
	background-color: var(--tsw-wd-accent-hover);
	border-color: var(--tsw-wd-accent-hover);
	color: var(--tsw-wd-on-accent);
	transform: translateY(-1px);
}

.tsw-wd-wrap .tsw-wd-form button.tsw-wd-button:focus {
	outline: 2px solid var(--tsw-wd-accent);
	outline-offset: 3px;
	box-shadow: 0 0 0 3px var(--tsw-wd-focus-ring);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--tsw-wd-accent) 35%, transparent);
}

.tsw-wd-wrap .tsw-wd-form button.tsw-wd-button:focus-visible {
	outline: 2px solid var(--tsw-wd-accent);
	outline-offset: 3px;
}

.tsw-wd-wrap .tsw-wd-form button.tsw-wd-button:active {
	transform: translateY(0);
}

.tsw-wd-wrap .tsw-wd-back {
	color: var(--tsw-wd-text-muted);
	font-size: 14px;
	text-decoration: underline;
	text-underline-offset: 3px;
}

.tsw-wd-wrap .tsw-wd-back:hover,
.tsw-wd-wrap .tsw-wd-back:focus,
.tsw-wd-wrap .tsw-wd-back:focus-visible {
	color: var(--tsw-wd-text);
}

.tsw-wd-wrap .tsw-wd-back:focus-visible {
	outline: 2px solid var(--tsw-wd-accent);
	outline-offset: 3px;
	border-radius: 3px;
}

/* ------------------------------------------------------- review (step two) */

.tsw-wd-wrap .tsw-wd-review {
	width: 100%;
	margin: 0 0 22px;
	border: 1px solid var(--tsw-wd-border-subtle);
	border-radius: var(--tsw-wd-radius-sm);
	border-collapse: separate;
	border-spacing: 0;
	overflow: hidden;
}

.tsw-wd-wrap .tsw-wd-review th,
.tsw-wd-wrap .tsw-wd-review td {
	padding: 13px 16px;
	border: 0;
	border-bottom: 1px solid var(--tsw-wd-border-subtle);
	font-size: 14.5px;
	line-height: 1.5;
	text-align: left;
	vertical-align: top;
	word-break: break-word;
}

.tsw-wd-wrap .tsw-wd-review tr:last-child th,
.tsw-wd-wrap .tsw-wd-review tr:last-child td {
	border-bottom: 0;
}

.tsw-wd-wrap .tsw-wd-review th {
	width: 38%;
	background: var(--tsw-wd-surface-2);
	color: var(--tsw-wd-text-muted);
	font-weight: 600;
}

.tsw-wd-wrap .tsw-wd-review td {
	color: var(--tsw-wd-text);
}

/* ------------------------------------------------------------ alert boxes */

.tsw-wd-wrap .tsw-wd-error,
.tsw-wd-wrap .tsw-wd-notice,
.tsw-wd-wrap .tsw-wd-success {
	margin: 0 0 22px;
	padding: 15px 18px;
	border: 1px solid transparent;
	border-left-width: 4px;
	border-radius: var(--tsw-wd-radius-sm);
	font-size: 14.5px;
	line-height: 1.55;
}

.tsw-wd-wrap .tsw-wd-error {
	border-color: var(--tsw-wd-error);
	background: var(--tsw-wd-error-bg);
	color: var(--tsw-wd-error);
	font-weight: 500;
}

.tsw-wd-wrap .tsw-wd-notice {
	border-color: var(--tsw-wd-warning);
	background: var(--tsw-wd-warning-bg);
	color: var(--tsw-wd-warning);
}

.tsw-wd-wrap .tsw-wd-success {
	margin-bottom: 0;
	padding: clamp(22px, 3vw, 30px);
	border-color: var(--tsw-wd-success);
	background: var(--tsw-wd-success-bg);
	color: var(--tsw-wd-success);
}

.tsw-wd-wrap .tsw-wd-success .tsw-wd-h2 {
	color: var(--tsw-wd-success);
	margin-bottom: 12px;
}

.tsw-wd-wrap .tsw-wd-success p {
	margin: 0 0 10px;
	color: inherit;
}

.tsw-wd-wrap .tsw-wd-success p:last-child {
	margin-bottom: 0;
}

.tsw-wd-wrap .tsw-wd-id {
	display: inline-block;
	padding: 3px 9px;
	border-radius: 4px;
	background: rgba(0, 0, 0, 0.07);
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 0.95em;
	letter-spacing: 0.03em;
	word-break: break-all;
}

/* --------------------------------------------------------------- honeypot */

.tsw-wd-wrap .tsw-wd-hp {
	position: absolute !important;
	left: -9999px !important;
	width: 1px;
	height: 1px;
	margin: 0;
	overflow: hidden;
}

/* ------------------------------------------------------- link on order view */

.tsw-wd-order-link {
	margin: 18px 0 0;
}

/* ----------------------------------------------------------------- mobile */

@media (max-width: 600px) {
	.tsw-wd-wrap .tsw-wd-card {
		padding: 20px 16px;
	}

	.tsw-wd-wrap .tsw-wd-actions {
		flex-direction: column;
		align-items: stretch;
		gap: 12px;
	}

	.tsw-wd-wrap .tsw-wd-form button.tsw-wd-button {
		width: 100%;
	}

	.tsw-wd-wrap .tsw-wd-back {
		text-align: center;
	}

	.tsw-wd-wrap .tsw-wd-review th,
	.tsw-wd-wrap .tsw-wd-review td {
		display: block;
		width: auto;
	}

	.tsw-wd-wrap .tsw-wd-review th {
		border-bottom: 0;
		padding-bottom: 4px;
		font-size: 12.5px;
		letter-spacing: 0.04em;
		text-transform: uppercase;
	}
}

@media (prefers-reduced-motion: reduce) {
	.tsw-wd-wrap .tsw-wd-form button.tsw-wd-button,
	.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-input,
	.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-select,
	.tsw-wd-wrap .tsw-wd-form .tsw-wd-field .tsw-wd-textarea {
		transition: none;
	}

	.tsw-wd-wrap .tsw-wd-form button.tsw-wd-button:hover {
		transform: none;
	}
}
