/*
 * Form fields: .cw-field (label + control + help + error), .cw-input (input, select, textarea) and
 * .cw-choice (checkbox, radio, switch with native inputs). Error state: .cw-field--error and aria-invalid.
 */
.cw-field {
	display: flex;
	flex-direction: column;
	gap: 6px;
	color: var(--cw-color-text-body);
	font-size: 13px;
	font-weight: 600;
}

.cw-field__label {
	color: var(--cw-color-text-body);
}

.cw-field__required {
	margin-left: 2px;
	color: var(--cw-color-accent);
}

.cw-field__control {
	position: relative;
	display: flex;
	align-items: center;
}

.cw-input {
	width: 100%;
	height: var(--cw-input-h);
	padding: 0 14px;
	border: 1px solid var(--cw-color-line-strong);
	border-radius: var(--cw-radius);
	background: var(--cw-color-surface);
	color: var(--cw-color-ink);
	font-size: 15px;
	font-weight: 500;
	line-height: 1.3;
}

.cw-input::placeholder {
	color: var(--cw-color-muted);
	opacity: 1;
}

.cw-input:focus,
.cw-input:focus-visible {
	border-color: var(--cw-color-ink);
	outline: 3px solid var(--cw-color-focus);
	outline-offset: 1px;
}

.cw-input:disabled {
	background: var(--cw-color-subtle);
	color: var(--cw-color-muted);
	cursor: not-allowed;
}

.cw-input--textarea {
	height: auto;
	min-height: calc(var(--cw-input-h) * 2);
	padding: 12px 14px;
	resize: vertical;
}

.cw-input--select {
	padding-right: 44px;
	appearance: none;
	cursor: pointer;
}

.cw-field__chevron {
	position: absolute;
	top: 50%;
	right: 14px;
	width: 18px;
	height: 18px;
	color: var(--cw-color-muted);
	pointer-events: none;
	transform: translateY(-50%);
}

.cw-field__control--password .cw-input {
	padding-right: 52px;
}

.cw-field__toggle {
	position: absolute;
	top: 4px;
	right: 4px;
	display: grid;
	width: 40px;
	height: 40px;
	margin: 0;
	padding: 0;
	place-items: center;
	border: 0;
	border-radius: var(--cw-radius);
	background: transparent;
	color: var(--cw-color-text-2);
	cursor: pointer;
}

.cw-field__toggle:hover {
	background: var(--cw-color-subtle);
	color: var(--cw-color-ink);
}

.cw-field__toggle .cw-icon {
	width: 20px;
	height: 20px;
}

.cw-field__toggle-hide,
.cw-field__toggle[data-visible] .cw-field__toggle-show {
	display: none;
}

.cw-field__toggle[data-visible] .cw-field__toggle-hide {
	display: block;
}

.cw-field__help {
	margin: 0;
	color: var(--cw-color-text-2);
	font-size: 12px;
	font-weight: 400;
}

.cw-field__error {
	display: flex;
	align-items: flex-start;
	gap: 6px;
	margin: 0;
	color: var(--cw-color-accent-strong);
	font-size: 13px;
	font-weight: 600;
}

.cw-field__error .cw-icon {
	width: 16px;
	height: 16px;
	margin-top: 1px;
}

.cw-field--error .cw-input,
.cw-input[aria-invalid="true"] {
	border-color: var(--cw-color-accent);
}

/* Checkbox, radio and switch. */
.cw-choice {
	min-height: 24px;
	display: inline-flex;
	align-items: center;
	gap: 10px;
	color: var(--cw-color-ink);
	font-size: 15px;
	font-weight: 600;
	cursor: pointer;
}

.cw-choice__control {
	position: relative;
	display: inline-flex;
	flex: 0 0 auto;
}

.cw-choice__input {
	margin: 0;
	border: 1.5px solid var(--cw-color-line-strong);
	background: var(--cw-color-surface);
	appearance: none;
	cursor: pointer;
}

.cw-choice--checkbox .cw-choice__input {
	width: 22px;
	height: 22px;
	border-radius: calc(var(--cw-radius) - 2px);
}

.cw-choice--checkbox .cw-choice__input:checked {
	border-color: var(--cw-color-button);
	background: var(--cw-color-button);
}

.cw-choice__check {
	position: absolute;
	inset: 0;
	width: 16px;
	height: 16px;
	margin: auto;
	color: var(--cw-color-button-ink);
	opacity: 0;
	pointer-events: none;
	stroke-width: 2.4;
}

.cw-choice__input:checked + .cw-choice__check {
	opacity: 1;
}

.cw-choice--radio .cw-choice__input {
	width: 20px;
	height: 20px;
	border-width: 2px;
	border-radius: 50%;
}

.cw-choice--radio .cw-choice__input:checked {
	border-color: var(--cw-color-ink);
	background: var(--cw-color-ink);
	box-shadow: inset 0 0 0 3px var(--cw-color-surface);
}

.cw-choice--switch .cw-choice__input {
	width: 40px;
	height: 24px;
	border: 0;
	border-radius: var(--cw-radius-lg);
	background: var(--cw-color-line-strong);
	transition: background .15s ease;
}

.cw-choice--switch .cw-choice__input:checked {
	background: var(--cw-color-button);
}

.cw-choice__knob {
	position: absolute;
	top: 3px;
	left: 3px;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	background: var(--cw-color-surface);
	box-shadow: var(--cw-shadow-sm);
	pointer-events: none;
	transition: transform .15s ease;
}

.cw-choice__input:checked ~ .cw-choice__knob {
	transform: translateX(16px);
}

.cw-choice__input:disabled {
	cursor: not-allowed;
	opacity: .5;
}

.cw-field--error .cw-choice__input:not(:checked) {
	border-color: var(--cw-color-accent);
}

@media (prefers-reduced-motion: reduce) {
	.cw-choice--switch .cw-choice__input,
	.cw-choice__knob {
		transition: none;
	}
}
