/* Browsers give form controls (button/input/select/textarea) their own UI
   font instead of inheriting the page's font-family - without this reset the
   try-on button and every control inside the modal render in the browser's
   default UI font rather than the store's theme font. */
.tryonpro-open-btn,
.tryonpro-modal,
.tryonpro-modal button,
.tryonpro-modal input,
.tryonpro-modal select,
.tryonpro-modal textarea {
	font-family: inherit;
}

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

/* The "button" class in the markup (class-tryonpro-render.php) piggybacks
   WooCommerce's/the theme's own button styling - free padding, border-radius,
   font and hover behaviour that already matches every other button on this
   site, instead of guessing values that look right on some themes and wrong
   on others. public/js/tryonpro.js then copies the exact computed padding/
   line-height/font-size/border-radius off the real add-to-cart button next
   to this one, so it matches precisely rather than however "button" happens
   to be styled in general; the values below are only the fallback for
   contexts with no sibling add-to-cart button to copy from (e.g. the
   [tryonpro] shortcode on a non-product page).

   Themes do still routinely apply their own full-width-on-mobile, floated,
   or absolutely-positioned rules to buttons inside form.cart - which is what
   actually made this button look "stretched" - so those specific layout
   properties are forced regardless of where the size values come from. */
.tryonpro-open-btn {
	box-sizing: border-box;
	display: inline-block;
	width: auto !important;
	max-width: 100% !important;
	float: none !important;
	position: static !important;
	margin: 10px 8px 10px 0;
	padding: 12px 20px;
	border-radius: 6px;
	font-size: 14px;
	font-weight: 600;
	line-height: 1.4;
	text-align: center;
	white-space: nowrap;
	cursor: pointer;
	transition: opacity 0.15s ease, transform 0.05s ease;
}
.tryonpro-open-btn:hover { opacity: 0.9; }
.tryonpro-open-btn:active { transform: scale( 0.98 ); }
.tryonpro-open-btn:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

/* public/js/tryonpro.js wraps this button and the theme's real add-to-cart
   button in this row so they render on the same line at their own natural
   (already size-matched) width, instead of relying on the theme's own
   float/flex handling of form.cart - which is exactly what varies theme to
   theme. `align-items: stretch` (the flex default) also equalizes their
   rendered height for free, without extra JS measuring. */
.tryonpro-btn-row {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin: 10px 0;
}
.tryonpro-btn-row > .tryonpro-open-btn { margin: 0; }

.tryonpro-noscroll { overflow: hidden; }

.tryonpro-modal {
	position: fixed;
	inset: 0;
	display: none;
	z-index: 100000;
	font-size: 14px;
	line-height: 1.5;
}
.tryonpro-modal.is-open { display: block; }
.tryonpro-modal__backdrop {
	position: absolute;
	inset: 0;
	background: rgba( 0, 0, 0, 0.6 );
	animation: tryonpro-fade-in 0.18s ease;
}
.tryonpro-modal__dialog {
	position: relative;
	max-width: 560px;
	width: calc( 100% - 24px );
	margin: 4vh auto;
	max-height: 92vh;
	overflow: auto;
	background: var( --tryonpro-popup-bg, #fff );
	color: var( --tryonpro-popup-text, #111 );
	border-radius: 12px;
	box-shadow: 0 10px 40px rgba( 0, 0, 0, 0.3 );
	animation: tryonpro-pop-in 0.18s ease;
}
.tryonpro-modal__close {
	position: absolute;
	top: 8px;
	right: 12px;
	width: 32px;
	height: 32px;
	border: 0;
	border-radius: 50%;
	background: transparent;
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
	color: inherit;
	transition: background-color 0.15s ease;
}
.tryonpro-modal__close:hover { background: rgba( 128, 128, 128, 0.15 ); }
.tryonpro-modal__body { padding: 28px; }

@keyframes tryonpro-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes tryonpro-pop-in {
	from { opacity: 0; transform: translateY( 8px ) scale( 0.98 ); }
	to { opacity: 1; transform: translateY( 0 ) scale( 1 ); }
}

.tryonpro-screen h2 { margin: 0 0 12px; font-size: 19px; font-weight: 600; line-height: 1.3; }
.tryonpro-guidance { opacity: 0.8; margin: 0 0 12px; }
.tryonpro-sample { max-width: 120px; border-radius: 8px; margin-bottom: 12px; }

.tryonpro-preview img,
.tryonpro-result img { max-width: 100%; border-radius: 8px; }
.tryonpro-preview { margin: 12px 0; min-height: 4px; }

.tryonpro-controls { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; }

.tryonpro-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 11px 18px;
	border: 1px solid var( --tryonpro-popup-btn, #111 );
	border-radius: 6px;
	background: transparent;
	color: inherit;
	font-weight: 600;
	cursor: pointer;
	transition: background-color 0.15s ease, opacity 0.15s ease;
}
.tryonpro-btn:hover { background: rgba( 128, 128, 128, 0.1 ); }
.tryonpro-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tryonpro-btn--primary {
	background: var( --tryonpro-popup-btn, #111 );
	color: #fff;
}
.tryonpro-btn--primary:hover { opacity: 0.88; background: var( --tryonpro-popup-btn, #111 ); }
.tryonpro-btn--file input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.tryonpro-link {
	background: none;
	border: 0;
	text-decoration: underline;
	cursor: pointer;
	color: inherit;
	padding: 0;
	margin: 6px 0;
}

.tryonpro-gallery__label,
.tryonpro-variation-row label { font-size: 13px; font-weight: 600; display: block; margin: 10px 0 6px; }
.tryonpro-gallery__strip { display: flex; gap: 8px; flex-wrap: wrap; }
.tryonpro-thumb {
	width: 56px; height: 56px;
	padding: 0;
	border: 2px solid transparent;
	border-radius: 6px;
	overflow: hidden;
	cursor: pointer;
	background: none;
	transition: border-color 0.15s ease;
}
.tryonpro-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tryonpro-thumb.is-selected { border-color: var( --tryonpro-popup-btn, #111 ); }

.tryonpro-variations { margin: 8px 0; }
.tryonpro-variation-row { margin-bottom: 8px; }
.tryonpro-variation-row select {
	width: 100%;
	padding: 8px 10px;
	border: 1px solid rgba( 128, 128, 128, 0.4 );
	border-radius: 6px;
	background-color: var( --tryonpro-popup-bg, #fff );
	color: inherit;
}

.tryonpro-consent {
	display: flex;
	gap: 8px;
	align-items: flex-start;
	margin: 14px 0;
	font-size: 13px;
	line-height: 1.4;
}

.tryonpro-msg { color: #b32d2e; min-height: 1em; }

.tryonpro-loading { text-align: center; padding: 40px 0; }
.tryonpro-spinner {
	width: 42px;
	height: 42px;
	margin: 0 auto 16px;
	border: 4px solid rgba( 0, 0, 0, 0.15 );
	border-top-color: var( --tryonpro-popup-btn, #111 );
	border-radius: 50%;
	animation: tryonpro-spin 0.9s linear infinite;
}
@keyframes tryonpro-spin { to { transform: rotate( 360deg ); } }

/* Before/after slider.
   Both images fill one shared box, so the comparison is like with like: same
   size, same scale, same position. The box takes its shape from the shopper's
   photo (--tryonpro-compare-ar, measured in JS) because that is the framing the
   shopper expects, and it is the ratio the generation now asks the model for -
   so in the normal case both images fill it exactly. A result that still comes
   back at a different shape is fitted with `contain`: it may letterbox, but it
   is never cropped, and cropping a try-on can cut off the garment. */
.tryonpro-slider {
	position: relative;
	overflow: hidden;
	border-radius: 8px;
	line-height: 0;
	user-select: none;
	aspect-ratio: var( --tryonpro-compare-ar, 3 / 4 );
	--tryonpro-split: 50%;
}
.tryonpro-slider img {
	display: block;
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: contain;
}
.tryonpro-slider__before-wrap {
	position: absolute;
	inset: 0;
	/* Clipped rather than width-constrained. A wrap that shrank to the split
	   would rescale the before image as the handle moved, so the two halves
	   never showed the same pixel at the same place; clipping keeps it at full
	   box size and only changes how much of it is revealed. */
	-webkit-clip-path: inset( 0 calc( 100% - var( --tryonpro-split ) ) 0 0 );
	clip-path: inset( 0 calc( 100% - var( --tryonpro-split ) ) 0 0 );
}
.tryonpro-slider__handle {
	position: absolute;
	top: 0; bottom: 0;
	left: var( --tryonpro-split );
	width: 2px;
	background: #fff;
	box-shadow: 0 0 0 1px rgba( 0, 0, 0, 0.3 );
	pointer-events: none;
}
.tryonpro-slider__range {
	position: absolute;
	inset: 0;
	width: 100%;
	margin: 0;
	opacity: 0;
	cursor: ew-resize;
}

/* View toggle (slider vs. side-by-side) */
.tryonpro-view-toggle { display: flex; gap: 6px; margin-bottom: 10px; }
.tryonpro-view-btn {
	padding: 6px 12px;
	border: 1px solid var( --tryonpro-popup-btn, #111 );
	border-radius: 6px;
	background: transparent;
	color: inherit;
	font-size: 12px;
	cursor: pointer;
	transition: background-color 0.15s ease;
}
.tryonpro-view-btn.is-active {
	background: var( --tryonpro-popup-btn, #111 );
	color: #fff;
}

/* Side-by-side compare */
.tryonpro-sidebyside {
	display: flex;
	gap: 10px;
}
.tryonpro-sidebyside > div { flex: 1; text-align: center; }
/* Same shared box as the slider: equal columns plus one ratio means before and
   after are always rendered at identical size, whatever shape each file is. */
.tryonpro-sidebyside img {
	width: 100%;
	aspect-ratio: var( --tryonpro-compare-ar, 3 / 4 );
	object-fit: contain;
	border-radius: 8px;
	display: block;
}
.tryonpro-sidebyside span { display: block; font-size: 12px; opacity: 0.75; margin-top: 4px; }

.tryonpro-share-msg { font-size: 12px; align-self: center; opacity: 0.85; }

/* Previous try-ons / try more products */
.tryonpro-related { margin-top: 20px; }
.tryonpro-related__grid {
	display: grid;
	grid-template-columns: repeat( auto-fill, minmax( 90px, 1fr ) );
	gap: 10px;
}
.tryonpro-related__item {
	text-decoration: none;
	color: inherit;
	font-size: 11px;
	text-align: center;
	display: block;
}
.tryonpro-related__item img {
	width: 100%;
	aspect-ratio: 1 / 1;
	object-fit: cover;
	border-radius: 6px;
	display: block;
	margin-bottom: 4px;
}
.tryonpro-previous { margin-top: 10px; }

/* Shown when another extension owns the product form and the shopper has to
   finish adding to cart there - see requires_product_form(). */
.tryonpro-note {
	margin: 8px 0 0;
	font-size: 13px;
	opacity: 0.85;
}

@media ( max-width: 480px ) {
	.tryonpro-modal__dialog { margin: 0; width: 100%; max-height: 100vh; border-radius: 0; }
	.tryonpro-sidebyside { flex-direction: column; }
}

@media ( prefers-reduced-motion: reduce ) {
	.tryonpro-modal__backdrop,
	.tryonpro-modal__dialog { animation: none; }
	.tryonpro-slider__before-wrap,
	.tryonpro-slider__handle { transition: none; }
}

/* ---------------------------------------------------------------------------
   Accessibility
   WordPress Accessibility Coding Standards compliance is a Woo Marketplace
   submission requirement, and a themes-vary-wildly reality: a theme that resets
   :focus to `outline: none` would otherwise leave this modal unusable by
   keyboard. These rules are deliberately specific enough to survive that.
   --------------------------------------------------------------------------- */

.tryonpro-modal :focus-visible,
.tryonpro-open-btn:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
	border-radius: 2px;
}

/* Fallback for browsers without :focus-visible support. */
.tryonpro-modal button:focus,
.tryonpro-modal a:focus,
.tryonpro-modal input:focus,
.tryonpro-modal select:focus,
.tryonpro-modal textarea:focus {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

/* The dialog takes focus programmatically on open; that is a scroll anchor for
   assistive tech, not something to draw a box around. */
.tryonpro-modal__dialog:focus {
	outline: none;
}

/* The range input is the accessible control that drives the compare slider. It
   is visually hidden behind the handle but must stay operable and hit-testable,
   so it is never display:none or visibility:hidden. */
.tryonpro-slider__range:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 4px;
}

/* Honour forced-colors / high-contrast mode, where custom colours are dropped
   and a transparent-bordered control can disappear entirely. */
@media ( forced-colors: active ) {
	.tryonpro-modal__dialog { border: 1px solid CanvasText; }
	.tryonpro-view-btn[aria-pressed="true"] { border: 2px solid Highlight; }
}
