/*
 * EDD markup on commerce pages (checkout, receipt, failed, cart, My Account): forms, tables,
 * buttons, notices. Loaded by templates/commerce-*.php through cp_use_style( 'edd' ).
 *
 * GTM contract: style EDD's markup, never change it. Selectors GTM reads:
 * .edd_cart_item[data-download-id], .edd_checkout_cart_item_title, .edd_cart_item_price,
 * .edd_cart_amount[data-total], #edd_purchase_receipt (rows "Order"/"Payment", "Total").
 *
 * Two parts:
 * 1. @layer components: our own classes (.cp-commerce__*).
 * 2. UNLAYERED on purpose, scoped to .cp-commerce: EDD, EDD Checkout Fields, Stripe, Recurring,
 *    Software Licensing and All Access print unlayered CSS, which beats every layer. These rules
 *    must win over that plugin CSS, so they sit outside the layers (see CLAUDE.md "CSS conventions").
 */

@layer components {
	.cp-commerce__lead { font-size: var(--cp-text-md); color: var(--cp-grey-2); }
	.cp-commerce__card {
		padding: var(--cp-s3);
		border: 1px solid var(--cp-line);
		border-radius: var(--cp-radius);
		background: var(--cp-white);
	}
	@media (min-width: 600px) { .cp-commerce__card { padding: var(--cp-s4); } }
	/* Wide EDD tables scroll inside their own box on phones instead of the page. */
	.cp-commerce__edd { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
	/* Help lines ("Questions about your order? Contact us", "Contact support"): the one link in
	   the line is the action, so it gets a 44px tap height (#46). */
	.cp-commerce > .cp-container > p.cp-muted > a:only-child,
	.cp-checkout__help a, .cp-account__help a { display: inline-flex; align-items: center; min-height: var(--cp-tap); }
}

/* ---------- unlayered: beats EDD/plugin CSS (see header) ---------- */

/* Form fields */
.cp-commerce :is(input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="url"], input[type="number"], select, textarea) {
	width: 100%;
	min-height: var(--cp-tap);
	padding: 10px 12px;
	border: 1px solid var(--cp-grey-2);
	border-radius: var(--cp-radius-sm);
	background: var(--cp-white);
	color: var(--cp-charcoal);
	font-size: 16px; /* 16px stops iOS zooming into the field. */
	line-height: 1.4;
}
.cp-commerce :is(input, select, textarea):focus-visible { outline: var(--cp-focus); outline-offset: 1px; border-color: var(--cp-charcoal); }
.cp-commerce input[type="checkbox"], .cp-commerce input[type="radio"] { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--cp-teal-ink); flex: none; }
.cp-commerce :is(label, .edd-label) { display: block; margin-block-end: var(--cp-s-half); font-weight: 600; }
.cp-commerce .edd-description { display: block; margin-block-end: var(--cp-s-half); font-size: var(--cp-text-sm); color: var(--cp-grey-2); }
.cp-commerce .edd-required-indicator { color: var(--cp-grey-2); margin-inline-start: 2px; text-decoration: none; }
.cp-commerce fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.cp-commerce legend { padding: 0; margin-block-end: var(--cp-s2); font: 600 var(--cp-text-md)/1.3 var(--cp-font-head); }
.cp-commerce :is(p, div)[id$="-wrap"], .cp-commerce .cfm-form .cfm-el, .cp-commerce .edd-login-username, .cp-commerce .edd-login-password { margin: 0 0 var(--cp-s2); }

/* Buttons: EDD submit buttons look like .cp-btn (teal fill, charcoal text, never white). */
.cp-commerce :is(.edd-submit, input.edd-submit, .edd_submit, button.edd-submit, #edd_login_submit, .edd-sl-renewal-form input[type="submit"], .edd_subscription_update_submit) {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: var(--cp-btn-h);
	padding: 0 var(--cp-s3);
	border: 2px solid transparent;
	border-radius: var(--cp-radius-pill);
	background: var(--cp-teal);
	color: var(--cp-charcoal);
	font: 600 var(--cp-text-base)/1.2 var(--cp-font-head);
	text-decoration: none;
	cursor: pointer;
	box-shadow: none;
	-webkit-appearance: none;
	appearance: none;
}
.cp-commerce :is(.edd-submit, .edd_submit, #edd_login_submit):hover { background: var(--cp-charcoal); color: var(--cp-white); }
.cp-commerce :is(.edd-button-secondary, .edd_discount_link) {
	min-height: var(--cp-tap);
	padding: 0;
	border: 0;
	background: none;
	color: var(--cp-teal-ink);
	font: 600 var(--cp-text-base)/1.4 var(--cp-font-body);
	text-decoration: underline;
	text-underline-offset: 0.18em;
	cursor: pointer;
}

/* Notices */
.cp-commerce :is(.edd_errors, .edd-alert, .edd_success, .edd-alert-success, .edd-alert-error, .edd_error) {
	margin: 0 0 var(--cp-s2);
	padding: var(--cp-s2);
	border-radius: var(--cp-radius-sm);
	border-inline-start: 4px solid var(--cp-teal-dark);
	background: var(--cp-grey);
	color: var(--cp-charcoal);
}
.cp-commerce :is(.edd_errors, .edd-alert-error, .edd_error) { border-inline-start-color: var(--cp-charcoal); background: var(--cp-white); outline: 1px solid var(--cp-line); }
.cp-commerce .edd_errors p, .cp-commerce .edd-alert p { margin: 0; }
.cp-commerce #edd-discount-error-wrap[style*="none"] { display: none; }

/* Tables (receipt, purchase history, downloads, licenses, subscriptions, cart shortcode) */
.cp-commerce table { width: 100%; border-collapse: collapse; margin: 0 0 var(--cp-s3); font-size: var(--cp-text-base); }
.cp-commerce :is(th, td) { padding: 12px var(--cp-s2) 12px 0; border: 0; border-bottom: 1px solid var(--cp-line); text-align: start; vertical-align: top; background: none; }
.cp-commerce thead th { font: 600 var(--cp-text-sm)/1.4 var(--cp-font-head); color: var(--cp-grey-2); text-transform: uppercase; letter-spacing: 0.04em; }
.cp-commerce :is(td, th):last-child { padding-inline-end: 0; }
.cp-commerce .edd_download_file + .edd_download_file { margin-block-start: var(--cp-s1); }
.cp-commerce .edd_download_file_link { display: inline-flex; align-items: center; min-height: var(--cp-tap); font-weight: 600; }

/* Receipt ([edd_receipt]): label column muted, values right-aligned. */
.cp-commerce #edd_purchase_receipt th:first-child,
.cp-commerce #edd_purchase_receipt td:first-child { color: var(--cp-grey-2); }
.cp-commerce #edd_purchase_receipt :is(td, th):last-child { text-align: end; }
.cp-commerce #edd_purchase_receipt thead th { color: var(--cp-charcoal); text-transform: none; letter-spacing: 0; font-size: var(--cp-text-md); }
.cp-commerce :is(#edd_purchase_receipt_products, .edd_purchase_receipt_products) { margin-block-start: var(--cp-s3); }
.cp-commerce .edd-blocks__row { display: flex; justify-content: space-between; gap: var(--cp-s2); padding: 12px 0; border-bottom: 1px solid var(--cp-line); }
.cp-commerce .edd-blocks__row-label { color: var(--cp-grey-2); }

/* Login form */
.cp-commerce #edd_login_form fieldset > p, .cp-commerce .edd-login-remember { margin: 0 0 var(--cp-s2); }
.cp-commerce .edd-login-remember label { display: flex; gap: var(--cp-s1); align-items: center; font-weight: 400; min-height: var(--cp-tap); }
.cp-commerce #edd_login_submit { width: 100%; }
.cp-commerce .edd-lost-password a { display: inline-flex; align-items: center; min-height: var(--cp-tap); }

/* Long unbroken values (license keys, invoice links, emails) must wrap, or a 32-character key
   widens the whole table past a phone screen and pushes the right-hand values out of view. */
.cp-commerce :is(td, th) { overflow-wrap: break-word; }
.cp-commerce :is(.edd_sl_license_key, td a) { overflow-wrap: anywhere; }
.cp-commerce #edd_purchase_receipt td[colspan] { text-align: start; color: var(--cp-charcoal); }
.cp-commerce #edd_purchase_receipt td:first-child { width: 45%; }
.cp-commerce .edd_sl_license_key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--cp-text-sm); }
.cp-commerce #edd_subscription_receipt { font-size: var(--cp-text-sm); }
.cp-commerce #edd_subscription_receipt thead th { text-transform: none; letter-spacing: 0; }
.cp-commerce #edd_subscription_receipt :is(td, th) { padding-inline-end: var(--cp-s1); }
.cp-commerce .edd_purchase_receipt_files { margin: var(--cp-s1) 0 0; padding-inline-start: 0; list-style: none; }
/* "Licensed site(s): …" under each licensed product (inc/site/edd-license-sites.php). */
.cp-commerce .cp-license-sites { margin: var(--cp-s1) 0 0; font-size: var(--cp-text-sm); color: var(--cp-charcoal); overflow-wrap: anywhere; }
.cp-commerce .cp-license-sites__label { color: var(--cp-grey-2); }
.cp-commerce .cp-license-sites--none { color: var(--cp-grey-2); }
