/* Geo content region */

.wp-block-commerce7-geo-region,
.wp-block-commerce7-geo-variant {
	box-sizing: border-box;
	width: 100%;
}

.commerce7-geo-region__viewport {
	position: relative;
}

.commerce7-geo-region__stack {
	display: grid;
}

/*
 * Variants are hidden by default and revealed via [data-geo-active]. The block
 * server-renders the default variant with data-geo-active, so it stays visible
 * without JavaScript; the runtime only switches which variant is active.
 */
.commerce7-geo-variant {
	grid-area: 1 / 1;
	visibility: hidden;
	opacity: 0;
	pointer-events: none;
	overflow: hidden;
	transition: opacity 0.2s ease, visibility 0.2s ease;

	&[data-geo-active] {
		visibility: visible;
		opacity: 1;
		pointer-events: auto;
	}
}

/*
 * Instant swaps (first paint / geo detect) suppress the cross-fade so the
 * default→resolved switch is not a noticeable flash. User-driven switches
 * leave this attribute unset and keep the CSS transition.
 */
.commerce7-geo-region[data-geo-instant] .commerce7-geo-variant {
	transition: none;
}

@media (prefers-reduced-motion: reduce) {
	.commerce7-geo-variant {
		transition: none;
	}
}

/* Theme-independent screen-reader-text (geo live region + switcher labels). */
.commerce7-geo-region .screen-reader-text {
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	width: 1px;
	word-wrap: normal !important;
}

/*
 * No-JS safety net: if no variant carries the server-rendered active marker
 * (unexpected markup, or the runtime never ran), reveal the first variant so
 * the region is never blank for no-JS users, crawlers, or on script failure.
 */
.commerce7-geo-region__stack:not(:has(> .commerce7-geo-variant[data-geo-active])) > .commerce7-geo-variant:first-child {
	visibility: visible;
	opacity: 1;
	pointer-events: auto;
}

.commerce7-geo-region--no-default .commerce7-geo-region__stack:not(:has(> .commerce7-geo-variant[data-geo-active])) > .commerce7-geo-variant:first-child {
	display: none;
	visibility: hidden;
	opacity: 0;
	pointer-events: none;
}

/*
 * No-default regions gate content: inactive variants must not reserve layout space.
 * Use display:none instead of the stacked grid overlay used for cross-fade switching.
 */
.commerce7-geo-region--no-default .commerce7-geo-region__stack {
	display: block;
}

.commerce7-geo-region--no-default .commerce7-geo-variant {
	display: none;
	grid-area: auto;
	visibility: visible;
	opacity: 1;
	pointer-events: none;
	overflow: visible;

	&[data-geo-active] {
		display: block;
		pointer-events: auto;
	}
}

/* Switcher placement */
.commerce7-geo-region--switcher-above:not(.commerce7-geo-region--switcher-hidden) .commerce7-geo-switcher {
	margin-block-end: 1.5rem;
	margin-block-start: 0;
}

.commerce7-geo-region--switcher-below:not(.commerce7-geo-region--switcher-hidden) .commerce7-geo-switcher {
	margin-block-start: 1.5rem;
	margin-block-end: 0;
}

.commerce7-geo-region--switcher-hidden .commerce7-geo-switcher {
	display: none;
}

/* Dropdown switcher */
.commerce7-geo-switcher--dropdown {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.75rem;
}

.commerce7-geo-switcher__label {
	font-weight: 600;
}

.commerce7-geo-switcher__select {
	min-width: 12rem;
	min-height: 2.75rem;
	padding: 0.5rem 2rem 0.5rem 0.75rem;
	border-radius: 0.375rem;
	border: 1px solid currentColor;
	background-color: transparent;
	color: inherit;
	font: inherit;

	option {
		color: initial;
	}

	&:focus-visible {
		outline: 2px solid currentColor;
		outline-offset: 2px;
	}
}

/* Inline heading switcher */
.commerce7-geo-switcher--inline {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 0.35rem;
}

.commerce7-geo-heading {
	display: inline;
	margin: 0;
	font: inherit;
	color: inherit;
}

.commerce7-geo-switcher__control {
	position: relative;
	display: inline-flex;
	align-items: center;
}

.commerce7-geo-switcher__trigger {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	min-height: 2.75rem;
	padding: 0;
	border: none;
	background: transparent;
	color: inherit;
	font: inherit;
	cursor: pointer;

	&[aria-expanded="true"] .commerce7-geo-switcher__icon::before {
		transform: rotate(-135deg) translateY(-0.15rem) translateX(-0.15rem);
	}

	&:focus-visible {
		outline: 2px solid currentColor;
		outline-offset: 2px;
	}

	/*
	 * No-JS / pre-enhance: country label stays visible and readable to SRs, but
	 * the control is inert (disabled) and the chevron affordance is hidden.
	 */
	&:disabled,
	&[aria-disabled="true"] {
		cursor: default;
		pointer-events: none;
	}

	&:disabled:focus,
	&:disabled:focus-visible,
	&[aria-disabled="true"]:focus,
	&[aria-disabled="true"]:focus-visible {
		outline: none;
	}

	&:disabled .commerce7-geo-switcher__icon,
	&[aria-disabled="true"] .commerce7-geo-switcher__icon {
		display: none;
	}
}

.commerce7-geo-switcher__select:disabled {
	cursor: default;
	opacity: 1;
	pointer-events: none;
}

.commerce7-geo-switcher__icon {
	padding: 0.25rem;
	border: 1px solid color-mix(in srgb, currentColor 25%, transparent);
	border-radius: 2em;
	aspect-ratio: 1 / 1;
	width: 32px;
	display: grid;
  place-items: center;

	&::before {
		content: "";
		display: inline-block;
		width: 0.45rem;
		height: 0.45rem;
		border-right: 2px solid currentColor;
		border-bottom: 2px solid currentColor;
		transform: rotate(45deg) translateY(0.05rem) translateX(-0.05rem);
    transform-origin: center;
	}
}

.commerce7-geo-switcher__list {
	position: absolute;
	z-index: 20;
	bottom: calc(100% + 0.35rem);
	right: 0;
	left: auto;
	min-width: min(12rem, calc(100vw - 2rem));
	max-width: min(12rem, calc(100vw - 2rem));
	margin: 0;
	padding: 0.35rem 0;
	list-style: none;
	border-radius: 0.5rem;
	border: 1px solid color-mix(in srgb, currentColor 25%, transparent);
	background: color-mix(in srgb, Canvas 92%, #13283c);
	box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 18%);
}

.commerce7-geo-region--switcher-above .commerce7-geo-switcher__list {
	top: calc(100% + 0.35rem);
	bottom: auto;
}

.commerce7-geo-switcher__option {
	padding: 0.65rem 1rem;
	cursor: pointer;
	color: color-mix(in srgb, Canvas 5%, black) !important;

	&[aria-selected="true"],
	&:hover,
	&:focus {
		background: color-mix(in srgb, currentColor 12%, transparent);
	}

	&:focus-visible {
		outline: 2px solid currentColor;
		outline-offset: 2px;
	}
}

/* Editor — outline chrome so border/radius block supports stay visible */
.commerce7-geo-region-editor {
	outline: 1px dashed color-mix(in srgb, currentColor 35%, transparent);
	outline-offset: -1px;
}

.commerce7-geo-region-editor--switcher-above .commerce7-geo-switcher--editor {
	margin-block-end: 1rem;
	margin-block-start: 0;
}

.commerce7-geo-region-editor--switcher-below .commerce7-geo-switcher--editor {
	margin-block-start: 1rem;
	margin-block-end: 0;
}

.commerce7-geo-variant-editor {
	position: relative;
	margin-block-end: 1rem;

	&:not(.is-selected):not(.has-child-selected) {
		outline: 1px dashed color-mix(in srgb, currentColor 20%, transparent);
		outline-offset: -1px;
	}
}

.commerce7-geo-variant-editor--hidden {
	display: none;
}

.commerce7-geo-variant-editor__badge {
	position: absolute;
	top: 0.5rem;
	right: 0.5rem;
	padding: 0.15rem 0.5rem;
	border-radius: 999px;
	font-size: 0.75rem;
	font-weight: 600;
	background: color-mix(in srgb, currentColor 12%, transparent);
}

/* Slider display mode without the Swiper runtime: stack variants like stack mode. */
.commerce7-geo-region--slider .commerce7-geo-region__slider:not(.swiper-initialized) {
	overflow: hidden;

	.commerce7-geo-variant {
		display: none;

		&[data-geo-active] {
			display: block;
		}
	}

	/* No-JS safety net mirroring stack mode: show the first slide if none active. */
	&:not(:has(.commerce7-geo-variant[data-geo-active])) .commerce7-geo-variant:first-child {
		display: block;
	}
}

.commerce7-geo-region--no-default.commerce7-geo-region--slider .commerce7-geo-region__slider:not(.swiper-initialized) {
	&:not(:has(.commerce7-geo-variant[data-geo-active])) .commerce7-geo-variant:first-child {
		display: none;
	}
}
