// Subscription Box — storefront builder.
//
// Themes routinely restyle buttons, inputs, lists and headings, so every rule
// here is written defensively: the overlay owns its own type scale, colours and
// box model, resets inherited decoration on the elements it renders, and uses
// its own class names rather than relying on theme components.

// Tokens (scoped as CSS variables so a site can retheme the builder cleanly).
.arraysubs-box-overlay,
.arraysubs-box-launcher {
	--asb-ink: #1a1a1a;
	--asb-muted: #6b7280;
	--asb-line: #e5e7eb;
	--asb-line-strong: #d1d5db;
	--asb-surface: #ffffff;
	--asb-canvas: #f7f8fa;
	--asb-accent: #111827;
	--asb-accent-ink: #ffffff;
	--asb-success: #0f7b3f;
	--asb-success-bg: #eaf7ef;
	--asb-danger: #b42318;
	--asb-radius: 12px;
	--asb-radius-sm: 8px;
	--asb-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
	--asb-font: inherit;
}

// ---------------------------------------------------------------------------
// Sale pricing for box children (builder cards + cart/checkout contents rows)
// ---------------------------------------------------------------------------
.arraysubs-price {
	// Each price carries a visually-hidden label so "16.00$ 12.00$" is not read
	// as one ambiguous run. Themes are not required to define the class and the
	// builder deliberately inherits no theme CSS, so hide it here.
	.screen-reader-text {
		position: absolute;
		width: 1px;
		height: 1px;
		padding: 0;
		margin: -1px;
		overflow: hidden;
		clip: rect(0, 0, 0, 0);
		clip-path: inset(50%);
		white-space: nowrap;
		border: 0;
	}

	&--was {
		text-decoration: line-through;
		font-weight: 400;
		opacity: 0.7;
	}

	&--now {
		font-weight: 700;
	}
}

// ---------------------------------------------------------------------------
// Product page: schedule line + launcher button
// ---------------------------------------------------------------------------
.arraysubs-box-launcher {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 12px;
	margin: 0 0 20px;
}

.arraysubs-box-info {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin: 0;

	&__schedule {
		display: inline-flex;
		align-items: center;
		gap: 6px;
		padding: 5px 12px;
		border-radius: 999px;
		background: var(--asb-canvas);
		border: 1px solid var(--asb-line);
		color: var(--asb-muted);
		font-size: 13px;
		line-height: 1.4;
		font-weight: 500;
	}
}

.arraysubs-box-price-label {
	font-size: 1em;
	color: var(--asb-ink);
}

.arraysubs-box-unavailable {
	color: var(--asb-muted);
	font-style: italic;
}

// The launcher never inherits theme button styling — it defines its own.
button.arraysubs-box-open {
	appearance: none;
	-webkit-appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	margin: 0;
	padding: 14px 28px;
	min-height: 52px;
	width: auto;
	max-width: 100%;
	border: 0;
	border-radius: var(--asb-radius-sm);
	background: var(--asb-accent);
	color: var(--asb-accent-ink);
	font-family: var(--asb-font);
	font-size: 15px;
	font-weight: 600;
	line-height: 1.2;
	letter-spacing: 0.01em;
	text-transform: none;
	text-decoration: none;
	text-shadow: none;
	cursor: pointer;
	box-shadow: 0 1px 2px rgba(15, 23, 42, 0.16);
	transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;

	&:hover,
	&:focus {
		background: var(--asb-accent);
		color: var(--asb-accent-ink);
		box-shadow: 0 6px 18px rgba(15, 23, 42, 0.24);
		transform: translateY(-1px);
	}

	&:focus-visible {
		outline: 2px solid var(--asb-accent);
		outline-offset: 3px;
	}

	&:active {
		transform: translateY(0);
	}

	svg {
		flex: 0 0 auto;
	}
}

body.arraysubs-box-no-scroll {
	overflow: hidden;
}

// ---------------------------------------------------------------------------
// Overlay + modal shell
// ---------------------------------------------------------------------------
.arraysubs-box-overlay {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 999999;
	padding: 24px;
	background: rgba(15, 23, 42, 0.55);
	backdrop-filter: blur(3px);
	font-family: var(--asb-font);
	color: var(--asb-ink);
	line-height: 1.5;
	box-sizing: border-box;

	&.is-open {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	// The attribute is the source of truth for visibility inside the builder.
	[hidden] {
		display: none !important;
	}

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

	// Neutralize theme typography/decoration inside the modal.
	p,
	ul,
	li,
	h2,
	h3,
	label,
	span,
	div {
		margin: 0;
		font-family: inherit;
	}

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

.arraysubs-box-modal {
	background: var(--asb-surface);
	border-radius: var(--asb-radius);
	width: min(1040px, 100%);
	max-height: min(760px, calc(100vh - 48px));
	display: flex;
	flex-direction: column;
	overflow: hidden;
	box-shadow: var(--asb-shadow);
	animation: arraysubs-box-pop 0.18s ease-out;

	&__header {
		display: flex;
		align-items: flex-start;
		gap: 16px;
		padding: 20px 24px 16px;
		border-bottom: 1px solid var(--asb-line);
	}

	&__titles {
		flex: 1;
		min-width: 0;
		display: flex;
		flex-direction: column;
		gap: 12px;
	}

	&__title {
		margin: 0;
		font-size: 19px;
		font-weight: 700;
		line-height: 1.25;
		letter-spacing: -0.01em;
		color: var(--asb-ink);
	}

	&__chips {
		display: flex;
		flex-wrap: wrap;
		gap: 6px;
	}

	&__close {
		appearance: none;
		-webkit-appearance: none;
		flex: 0 0 auto;
		width: 34px;
		height: 34px;
		padding: 0;
		border: 0;
		border-radius: 50%;
		background: var(--asb-canvas);
		color: var(--asb-muted);
		font-size: 22px;
		line-height: 1;
		cursor: pointer;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		transition: background 0.12s ease, color 0.12s ease;

		&:hover {
			background: var(--asb-line);
			color: var(--asb-ink);
		}
	}

	&__body {
		flex: 1;
		overflow-y: auto;
		padding: 22px 24px;
		background: var(--asb-canvas);
		min-height: 240px;
	}

	&__footer {
		border-top: 1px solid var(--asb-line);
		padding: 16px 24px;
		display: flex;
		align-items: center;
		gap: 20px;
		flex-wrap: wrap;
		background: var(--asb-surface);
	}
}

@keyframes arraysubs-box-pop {
	from {
		opacity: 0;
		transform: translateY(10px) scale(0.99);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

.arraysubs-box-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	font-weight: 600;
	border-radius: 999px;
	padding: 5px 12px;
	background: var(--asb-canvas);
	border: 1px solid var(--asb-line);
	color: var(--asb-muted);
	white-space: nowrap;

	&.is-active {
		background: var(--asb-accent);
		border-color: var(--asb-accent);
		color: var(--asb-accent-ink);
	}

	&.is-done {
		border-color: var(--asb-success);
		color: var(--asb-success);
		background: var(--asb-success-bg);
	}
}

.arraysubs-box-form {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-height: 0;
}

// ---------------------------------------------------------------------------
// Steps + elements
// ---------------------------------------------------------------------------
.arraysubs-box-step {
	display: none;

	&.is-active {
		display: block;
	}

	&__title {
		margin: 0 0 18px;
		font-size: 17px;
		font-weight: 700;
		letter-spacing: -0.01em;
		color: var(--asb-ink);
	}
}

.arraysubs-box-element {
	margin: 0 0 22px;

	&:last-child {
		margin-bottom: 0;
	}

	&__label {
		display: block;
		margin: 0 0 10px;
		font-size: 14px;
		font-weight: 600;
		color: var(--asb-ink);
	}

	&__hint {
		font-weight: 400;
		color: var(--asb-muted);
		font-size: 13px;
		margin-left: 6px;
	}

	&__error {
		display: block;
		margin-top: 8px;
		color: var(--asb-danger);
		font-size: 13px;
		font-weight: 500;
	}

	// Optional element whose products are all unavailable to this visitor.
	&__empty {
		margin: 0 0 10px;
		color: var(--asb-muted);
		font-size: 13px;
		font-style: italic;
	}
}

.arraysubs-box-required {
	color: var(--asb-danger);
	margin-left: 2px;
}

.arraysubs-box-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
	gap: 14px;
}

.arraysubs-box-card {
	position: relative;
	border: 1px solid var(--asb-line);
	border-radius: var(--asb-radius-sm);
	padding: 14px 12px 12px;
	text-align: center;
	display: flex;
	flex-direction: column;
	gap: 8px;
	background: var(--asb-surface);
	transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;

	&:hover {
		border-color: var(--asb-line-strong);
		box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
	}

	&.is-selected {
		border-color: var(--asb-success);
		box-shadow: 0 0 0 2px rgba(15, 123, 63, 0.16);
	}

	&__image {
		display: block;

		img {
			display: block;
			width: 100%;
			height: 104px;
			object-fit: contain;
			margin: 0 auto;
			border-radius: 6px;
			background: var(--asb-canvas);
			box-shadow: none;
			border: 0;
			max-width: 100%;
		}
	}

	&__name {
		font-size: 13px;
		font-weight: 600;
		line-height: 1.35;
		color: var(--asb-ink);
		flex: 1;
	}

	&__price {
		font-size: 13px;
		font-weight: 600;
		color: var(--asb-muted);

		del,
		ins {
			text-decoration: none;
			background: none;
		}

		// On sale: old price struck through and dimmed, sale price emphasised,
		// as WooCommerce prices a discounted product in the catalogue.
		&.is-on-sale {
			display: flex;
			align-items: baseline;
			justify-content: center;
			flex-wrap: wrap;
			gap: 6px;

			.arraysubs-price--now {
				color: var(--asb-ink);
			}
		}
	}

	&__qty {
		display: flex;
		align-items: center;
		justify-content: center;
		gap: 8px;

		button {
			appearance: none;
			-webkit-appearance: none;
			width: 34px;
			height: 34px;
			min-height: 34px;
			padding: 0;
			margin: 0;
			border-radius: 8px;
			border: 1px solid var(--asb-line-strong);
			background: var(--asb-surface);
			color: var(--asb-ink);
			cursor: pointer;
			font-size: 17px;
			font-weight: 600;
			line-height: 1;
			display: inline-flex;
			align-items: center;
			justify-content: center;
			text-shadow: none;
			box-shadow: none;
			transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;

			&:hover {
				background: var(--asb-accent);
				color: var(--asb-accent-ink);
				border-color: var(--asb-accent);
			}
		}

		.arraysubs-box-qty-input {
			width: 54px;
			height: 34px;
			min-height: 34px;
			text-align: center;
			border: 1px solid var(--asb-line-strong);
			border-radius: 8px;
			padding: 0;
			margin: 0;
			font-size: 14px;
			font-weight: 600;
			color: var(--asb-ink);
			background: var(--asb-surface);
			box-shadow: none;
			-moz-appearance: textfield;

			&::-webkit-inner-spin-button,
			&::-webkit-outer-spin-button {
				-webkit-appearance: none;
				margin: 0;
			}

			&:focus {
				outline: 2px solid var(--asb-accent);
				outline-offset: 1px;
			}
		}
	}
}

// Input elements
.arraysubs-box-field {
	display: block;
	width: 100%;
	max-width: 520px;
	min-height: 44px;
	padding: 10px 12px;
	margin: 0;
	border: 1px solid var(--asb-line-strong);
	border-radius: var(--asb-radius-sm);
	background: var(--asb-surface);
	color: var(--asb-ink);
	font-family: inherit;
	font-size: 14px;
	line-height: 1.4;
	box-shadow: none;

	&:focus {
		outline: none;
		border-color: var(--asb-accent);
		box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.1);
	}
}

textarea.arraysubs-box-field {
	min-height: 96px;
	resize: vertical;
}

input[type="file"].arraysubs-box-field {
	padding: 9px 12px;
	min-height: 44px;
	font-size: 13px;
}

.arraysubs-box-choices {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.arraysubs-box-choice {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	padding: 10px 14px;
	border: 1px solid var(--asb-line);
	border-radius: var(--asb-radius-sm);
	background: var(--asb-surface);
	font-size: 14px;
	font-weight: 500;
	color: var(--asb-ink);
	cursor: pointer;
	max-width: 520px;
	transition: border-color 0.12s ease, background 0.12s ease;

	&:hover {
		border-color: var(--asb-line-strong);
	}

	input[type="checkbox"] {
		margin: 0;
		width: 17px;
		height: 17px;
		flex: 0 0 auto;
		accent-color: var(--asb-accent);
	}
}

.arraysubs-box-upload {
	display: flex;
	flex-direction: column;
	gap: 6px;
	max-width: 520px;

	&__status {
		font-size: 13px;
		font-weight: 600;
		color: var(--asb-success);
	}

	&__hint {
		font-size: 12px;
		color: var(--asb-muted);
	}
}

// ---------------------------------------------------------------------------
// Footer: totals + actions
// ---------------------------------------------------------------------------
.arraysubs-box-totals {
	display: flex;
	align-items: baseline;
	gap: 10px;
	flex-wrap: wrap;
	flex: 1;
	min-width: 220px;

	&__label {
		color: var(--asb-muted);
		font-size: 13px;
		font-weight: 500;
	}

	&__subtotal {
		text-decoration: line-through;
		color: var(--asb-muted);
		font-size: 14px;
	}

	&__amount {
		font-size: 24px;
		font-weight: 700;
		letter-spacing: -0.02em;
		color: var(--asb-ink);
	}

	&__suffix {
		color: var(--asb-muted);
		font-size: 13px;
	}

	&__hint {
		flex-basis: 100%;
		display: flex;
		flex-direction: column;
		gap: 3px;
		font-size: 12.5px;
		font-weight: 500;
		color: var(--asb-success);
	}
}

.arraysubs-box-actions {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-wrap: wrap;
	justify-content: flex-end;
}

// Footer buttons define their own look so themes cannot break the flow.
button.arraysubs-box-prev,
button.arraysubs-box-next,
button.arraysubs-box-submit {
	appearance: none;
	-webkit-appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	margin: 0;
	padding: 12px 24px;
	min-height: 46px;
	border: 1px solid transparent;
	border-radius: var(--asb-radius-sm);
	font-family: inherit;
	font-size: 14px;
	font-weight: 600;
	line-height: 1.2;
	text-transform: none;
	text-decoration: none;
	text-shadow: none;
	cursor: pointer;
	box-shadow: none;
	transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

button.arraysubs-box-prev {
	background: var(--asb-surface);
	border-color: var(--asb-line-strong);
	color: var(--asb-ink);

	&:hover {
		background: var(--asb-canvas);
		color: var(--asb-ink);
	}
}

button.arraysubs-box-next,
button.arraysubs-box-submit {
	background: var(--asb-accent);
	color: var(--asb-accent-ink);

	&:hover,
	&:focus {
		background: #000;
		color: var(--asb-accent-ink);
	}
}

.arraysubs-box-notice {
	color: var(--asb-danger);
	font-size: 13px;
	font-weight: 500;
	max-width: 360px;
}

.arraysubs-box-spinner {
	display: inline-block;
	width: 15px;
	height: 15px;
	border: 2px solid rgba(255, 255, 255, 0.35);
	border-top-color: currentColor;
	border-radius: 50%;
	animation: arraysubs-box-frontend-spin 0.7s linear infinite;
	flex: 0 0 auto;
}

@keyframes arraysubs-box-frontend-spin {
	to {
		transform: rotate(360deg);
	}
}

.arraysubs-box-btn--loading {
	opacity: 0.85;
	pointer-events: none;
}

// ---------------------------------------------------------------------------
// Order screens + customer portal
// ---------------------------------------------------------------------------
// Child order-item rows used to be decorated with markup here. WooCommerce's
// `woocommerce_order_item_name` filter has no reliable plain-text signal (the
// third argument is `$is_visible`, and every email template passes `false`),
// so the decoration is now a bare "↳" prefix and a "(Free gift)" suffix added
// in OrderHooks::decorateChildItemName(). No styling hooks remain.

.arraysubs-box-portal-list {
	margin: 0;
	padding: 0;
	list-style: none;

	li {
		margin: 0 0 4px;
	}
}

// Box contents rows in the cart / checkout / order review: one child per line.
.arraysubs-box-contents {
	display: inline-block;
	line-height: 1.7;
}

.arraysubs-box-portal-qty {
	color: #6b7280;
	font-size: 0.85em;
	margin-left: 4px;
}

.arraysubs-box-portal-freebie {
	display: inline-block;
	background: #eaf7ef;
	color: #0f7b3f;
	border-radius: 3px;
	font-size: 0.78em;
	font-weight: 600;
	padding: 1px 7px;
	margin-left: 6px;
}

.arraysubs-box-portal-discount {
	display: inline-block;
	margin-top: 6px;
	color: #0f7b3f;
	font-size: 0.85em;
	font-weight: 600;
}

// Panel shown on a child subscription in place of its action buttons.
.arraysubs-box-managed {
	display: flex;
	align-items: center;
	gap: 20px;
	flex-wrap: wrap;
	margin: 24px 0;
	padding: 18px 20px;
	border: 1px solid #e5e7eb;
	border-left: 4px solid #111827;
	border-radius: 10px;
	background: #f7f8fa;

	&__body {
		flex: 1;
		min-width: 240px;
		display: flex;
		flex-direction: column;
		gap: 4px;
	}

	&__title {
		font-size: 15px;
		font-weight: 700;
		color: #1a1a1a;
	}

	&__text {
		margin: 0;
		font-size: 13.5px;
		line-height: 1.55;
		color: #4b5563;
	}

	&__cta.button {
		flex: 0 0 auto;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		padding: 12px 22px;
		min-height: 46px;
		border: 0;
		border-radius: 8px;
		background: #111827;
		color: #fff;
		font-size: 14px;
		font-weight: 600;
		line-height: 1.2;
		text-decoration: none;
		text-shadow: none;
		box-shadow: none;

		&:hover,
		&:focus {
			background: #000;
			color: #fff;
		}
	}
}

.arraysubs-box-portal-children {
	margin: 0;
	padding: 0;
	list-style: none;

	li {
		margin: 0 0 4px;
	}

	a {
		font-weight: 500;
	}
}

@media (max-width: 600px) {
	.arraysubs-box-managed {
		flex-direction: column;
		align-items: stretch;

		&__cta.button {
			width: 100%;
		}
	}
}

// ---------------------------------------------------------------------------
// Responsive
// ---------------------------------------------------------------------------
@media (max-width: 782px) {
	.arraysubs-box-overlay {
		padding: 0;
	}

	.arraysubs-box-modal {
		border-radius: 0;
		width: 100%;
		max-height: 100vh;
		height: 100dvh;

		&__header {
			padding: 16px 16px 12px;
		}

		&__body {
			padding: 16px;
		}

		&__footer {
			padding: 12px 16px;
			gap: 12px;
		}
	}

	.arraysubs-box-grid {
		grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
		gap: 10px;
	}

	.arraysubs-box-actions {
		width: 100%;

		button {
			flex: 1;
		}
	}

	.arraysubs-box-totals__amount {
		font-size: 20px;
	}
}
