@use "sass:math";
@use "@wordpress/base-styles/mixins" as *;
@use "@wordpress/base-styles/variables" as *;

.components-radio-control {
	border: 0;
	margin: 0;
	padding: 0;

	font-family: $default-font;
	font-size: $default-font-size;
}

.components-radio-control__help {
	color: var(--wpds-color-foreground-content-neutral-weak);
}

.components-radio-control__option {
	display: grid;
	grid-template-columns: auto 1fr;
	grid-template-rows: auto minmax(0, max-content);
	column-gap: $grid-unit-10;
	align-items: center;
}

.components-radio-control__input[type="radio"] {
	grid-column: 1;
	grid-row: 1;

	border: var(--wpds-border-width-xs) solid var(--wpds-color-stroke-interactive-neutral);
	background: var(--wpds-color-background-interactive-neutral-weak);
	transition: none;
	border-radius: $radius-round;
	width: $radio-input-size;
	height: $radio-input-size;
	min-width: $radio-input-size;
	max-width: $radio-input-size;
	position: relative;

	&::after {
		content: "";
		position: absolute;
		top: 50%;
		left: 50%;
		width: $grid-unit-30;
		aspect-ratio: 1;
		transform: translate(-50%, -50%);
	}

	&:focus {
		@include outset-ring__focus();
		border-color: var(--wpds-color-stroke-interactive-neutral);

		// Override the focus shadow from wp-admin forms.css.
		box-shadow: none;
	}

	&:hover {
		border-color: var(--wpds-color-stroke-interactive-neutral-active);
	}

	&:checked::before {
		box-sizing: inherit;
		width: math.div($radio-input-size, 2);
		height: math.div($radio-input-size, 2);
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		margin: 0;
		background-color: currentColor;

		// This border serves as a background color in Windows High Contrast mode.
		border: 4px solid currentColor;
	}

	&:checked {
		background: var(--wpds-color-background-interactive-brand-strong);
		border-color: transparent;
		color: var(--wpds-color-foreground-interactive-brand-strong);
	}

	&[aria-disabled="true"],
	&:disabled {
		background: var(--wpds-color-background-interactive-neutral-weak-disabled);
		border-color: var(--wpds-color-stroke-interactive-neutral-disabled);
		color: var(--wpds-color-foreground-interactive-neutral-disabled);
		cursor: default;
		opacity: 1; // Override opacity inherited from wp-admin forms.css.

		@media (forced-colors: active) {
			color: GrayText;
			border-color: GrayText;
		}
	}

	display: inline-flex;
	margin: 0;
	padding: 0;
	appearance: none;

	&:not(:disabled) {
		cursor: var(--wpds-cursor-control);
	}

	&:checked {
		&::before {
			content: "";
			border-radius: $radius-round;
		}
	}

	&:disabled:checked::before {
		opacity: 1; // Override style from wp-admin forms.css.
	}
}

.components-radio-control__label {
	grid-column: 2;
	grid-row: 1;
	color: var(--wpds-color-foreground-content-neutral);

	.components-radio-control__input:not(:disabled) + & {
		cursor: var(--wpds-cursor-control);
	}

	line-height: $radio-input-size;
}

.components-radio-control__option-description {
	grid-column: 2;
	grid-row: 2;

	padding-block-start: $grid-unit-05;

	// Override the top margin of the StyledHelp component from BaseControl.
	// TODO: we should tweak the StyledHelp component to not have a top margin.
	&.components-radio-control__option-description {
		margin-top: 0;
	}
}
