/**
 * {CODICTS} Voxel Custom Fields - frontend field styles.
 *
 * The accent is borrowed from Voxel so a field matches the site's brand; every
 * other color is derived from `currentColor`, which is what keeps these
 * controls legible on a light or a dark theme without guessing.
 *
 * The range inputs need !important. Voxel styles form inputs broadly (a range
 * input computed to height 44px / padding 16px / background none inside the
 * create-post form), which flattens a slider into something that looks exactly
 * like an empty text box.
 */

.cdts-slider,
.cdts-range,
.cdts-rating,
.cdts-color {
	/*
	 * Only the accent is borrowed from Voxel. Its --ts-shade-N scale runs
	 * LIGHT to DARK as N goes UP on this theme (--ts-shade-6 is #f8f8f8), which
	 * is the reverse of what the name suggests - mapping text onto shade-6
	 * painted it white on a white form.
	 *
	 * Everything else is derived from `currentColor`, so the component follows
	 * whatever text color the theme has set and cannot be invisible on either
	 * a light or a dark site.
	 */
	--cdts-accent: var(--ts-accent-1, #5346e5);
	/*
	 * The thumb diameter, declared ONCE.
	 *
	 * A range input's thumb centre travels from thumb/2 to width - thumb/2,
	 * never 0 to width, so anything that has to line up under the knob - the
	 * step marks, the filled part of the track - has to be positioned on that
	 * inset track. Marks laid out with `space-between` sat on the full width
	 * instead and were out by up to a whole thumb width at the quarter
	 * points: only the midpoint ever agreed.
	 */
	--cdts-thumb: 20px;
	--cdts-rail: color-mix(in srgb, currentColor 14%, transparent);
	--cdts-border: color-mix(in srgb, currentColor 18%, transparent);
	--cdts-radius: var(--ts-radius, 8px);
}

/* ---------------------------------------------------------------- slider */

.cdts-slider-descriptions {
	display: grid;
	grid-template-columns: repeat(var(--cdts-cols, 3), minmax(0, 1fr));
	gap: 8px;
	margin-bottom: 12px;
}

.cdts-slider-desc {
	padding: 10px 12px;
	border: 1px solid var(--cdts-border);
	border-radius: var(--cdts-radius);
	cursor: pointer;
	transition: border-color .15s, background-color .15s;
	min-width: 0;
}

.cdts-slider-desc:hover {
	border-color: var(--cdts-accent);
}

.cdts-slider-desc.is-current {
	border-color: var(--cdts-accent);
	background: color-mix(in srgb, var(--cdts-accent) 8%, transparent);
}

.cdts-slider-desc-head {
	display: block;
	font-weight: 600;
	font-size: 13px;
	color: inherit;
	margin-bottom: 4px;
}

.cdts-slider-desc-body {
	display: block;
	font-size: 12px;
	line-height: 1.45;
	color: inherit;
	opacity: .7;
}

.cdts-slider-track-wrap {
	padding: 4px 0 0;
}

/*
 * The fill is painted with a gradient on the track itself rather than an extra
 * element, so there is nothing overlaying the input to swallow pointer events.
 */
.cdts-slider-input {
	-webkit-appearance: none;
	appearance: none;
	width: 100%;
	height: 6px;
	margin: 0;
	border-radius: 999px;
	background: linear-gradient(
		to right,
		var(--cdts-accent) 0%,
		var(--cdts-accent) calc(var(--cdts-thumb) / 2 + var(--cdts-fill-p, 0) * (100% - var(--cdts-thumb))),
		var(--cdts-rail) calc(var(--cdts-thumb) / 2 + var(--cdts-fill-p, 0) * (100% - var(--cdts-thumb))),
		var(--cdts-rail) 100%
	);
	cursor: pointer;
	outline: none;
}

.cdts-is-untouched .cdts-slider-input {
	background: var(--cdts-rail);
}

.cdts-slider-input::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: #fff;
	border: 2px solid var(--cdts-accent);
	box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
	cursor: grab;
}

.cdts-slider-input::-moz-range-thumb {
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: #fff;
	border: 2px solid var(--cdts-accent);
	box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
	cursor: grab;
}

/*
 * An untouched slider used to draw a faded thumb, but a thumb that is visible
 * at all still reads as an answer at whatever position it happens to rest -
 * so the question looked answered and only the caption said otherwise. Hidden
 * outright, the track alone reads as "nothing chosen yet".
 *
 * Opacity, not display:none - the input must stay draggable, and hiding the
 * thumb outright takes the hit area with it.
 */
.cdts-hide-handle .cdts-slider-input::-webkit-slider-thumb {
	opacity: 0;
}

.cdts-hide-handle .cdts-slider-input::-moz-range-thumb {
	opacity: 0;
}

/* Fading rather than hiding, where the handle is kept. */
.cdts-is-untouched:not(.cdts-hide-handle) .cdts-slider-input::-webkit-slider-thumb {
	border-color: color-mix(in srgb, currentColor 45%, transparent);
}

.cdts-is-untouched:not(.cdts-hide-handle) .cdts-slider-input::-moz-range-thumb {
	border-color: color-mix(in srgb, currentColor 45%, transparent);
}

/*
 * Each mark is placed at the exact x the knob occupies for its value:
 *   thumb/2 + p * (track - thumb)
 * with `--p` (0..1) set per mark by the component. The knob's geometry stays
 * entirely in CSS this way, so the template cannot drift out of step with it.
 */
.cdts-slider-marks {
	position: relative;
	margin-top: 6px;
	min-height: 22px;
}

.cdts-slider-mark {
	position: absolute;
	top: 0;
	left: calc(var(--cdts-thumb) / 2 + var(--p, 0) * (100% - var(--cdts-thumb)));
	transform: translateX(-50%);
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 2px;
	cursor: pointer;
	font-size: 11px;
	color: inherit;
	opacity: .7;
	white-space: nowrap;
}

.cdts-slider-mark:first-child { align-items: flex-start; }
.cdts-slider-mark:last-child { align-items: flex-end; }

.cdts-slider-mark.is-current {
	color: var(--cdts-accent);
	font-weight: 600;
	opacity: 1;
}

.cdts-slider-tick {
	width: 1px;
	height: 5px;
	background: var(--cdts-rail);
	display: block;
}

.cdts-slider-mark em {
	font-style: normal;
	white-space: nowrap;
}

.cdts-slider-value {
	margin-top: 10px;
	font-size: 13px;
	color: inherit;
	display: flex;
	align-items: center;
	gap: 8px;
	min-height: 32px;
}

/* The caption is the quiet half of the row, not the button beside it. */
.cdts-slider-value .cdts-slider-value-label {
	opacity: .7;
}

.cdts-slider-value-num {
	font-size: 16px;
	font-weight: 600;
	color: var(--cdts-accent);
}

/*
 * Clear control. Pushed to the far end of the read-out row so it reads as an
 * action on the answer rather than as part of it, and deliberately quiet -
 * it is an escape hatch, not a call to action.
 *
 * Sizing and appearance are forced because the framework styles every button
 * inside a form group; without this it inherits a full-width filled button.
 */
/*
 * ts-btn-1 supplies the border, background and colour - the same ones the
 * form's own Previous/Next carry - so nothing here touches them. All this does
 * is stop the framework stretching a button inside a form group to full width
 * and sizing it like an input, and make it smaller than the step navigation,
 * because clearing one answer is a lesser action than moving through the form.
 */
.cdts-slider .cdts-slider-clear.ts-btn {
	margin-left: auto;
	width: auto;
	min-width: 0;
	flex: 0 0 auto;
	height: 32px;
	min-height: 0;
	padding: 0 12px;
	font-size: 12px;
	gap: 6px;
}

.cdts-slider .cdts-slider-clear.ts-btn svg {
	width: 12px;
	height: 12px;
	flex: 0 0 auto;
}

/*
 * Track overrides. Kept in one block so it is obvious that these exist to win
 * against the theme rather than to describe the design.
 */
.cdts-slider .cdts-slider-track-wrap input[type="range"].cdts-slider-input,
.cdts-range .cdts-range-track-wrap input[type="range"].cdts-range-input {
	-webkit-appearance: none !important;
	appearance: none !important;
	min-height: 0 !important;
	padding: 0 !important;
	border: 0 !important;
	box-shadow: none !important;
	outline: none !important;
	line-height: normal !important;
}

.cdts-slider .cdts-slider-track-wrap input[type="range"].cdts-slider-input {
	height: 6px !important;
	border-radius: 999px !important;
	background: linear-gradient(
		to right,
		var(--cdts-accent) 0%,
		var(--cdts-accent) calc(var(--cdts-thumb) / 2 + var(--cdts-fill-p, 0) * (100% - var(--cdts-thumb))),
		var(--cdts-rail) calc(var(--cdts-thumb) / 2 + var(--cdts-fill-p, 0) * (100% - var(--cdts-thumb))),
		var(--cdts-rail) 100%
	) !important;
}

.cdts-slider.cdts-is-untouched .cdts-slider-track-wrap input[type="range"].cdts-slider-input {
	background: var(--cdts-rail) !important;
}

.cdts-range .cdts-range-track-wrap input[type="range"].cdts-range-input {
	height: 28px !important;
	background: none !important;
	border-radius: 0 !important;
}

/* ----------------------------------------------------------- range slider */

.cdts-range-track-wrap {
	position: relative;
	height: 28px;
	display: flex;
	align-items: center;
}

.cdts-range-rail,
.cdts-range-fill {
	position: absolute;
	height: 6px;
	border-radius: 999px;
	pointer-events: none;
}

.cdts-range-rail {
	left: 0;
	right: 0;
	background: var(--cdts-rail);
}

/*
 * The band runs between the two THUMB CENTRES, which travel on the inset
 * track (thumb/2 .. width - thumb/2), not from 0 to width. Anchoring it to
 * raw percentages left it out by up to half a thumb at each end, so the
 * colour crept past the handles at the extremes. Same fix, and the same
 * single --cdts-thumb, as the single-handle slider's marks.
 */
.cdts-range-fill {
	left: calc(var(--cdts-thumb) / 2 + var(--cdts-from-p, 0) * (100% - var(--cdts-thumb)));
	right: calc(100% - (var(--cdts-thumb) / 2 + var(--cdts-to-p, 1) * (100% - var(--cdts-thumb))));
	background: var(--cdts-accent);
}

/*
 * Both inputs are stacked. The track is transparent and ignores the pointer so
 * whichever thumb is nearer wins the drag; only the thumbs are clickable.
 */
.cdts-range-input {
	-webkit-appearance: none;
	appearance: none;
	position: absolute;
	left: 0;
	width: 100%;
	height: 28px;
	margin: 0;
	background: none;
	pointer-events: none;
	outline: none;
}

.cdts-range-input::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	pointer-events: auto;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: #fff;
	border: 2px solid var(--cdts-accent);
	box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
	cursor: grab;
}

.cdts-range-input::-moz-range-thumb {
	pointer-events: auto;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: #fff;
	border: 2px solid var(--cdts-accent);
	box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
	cursor: grab;
}

.cdts-range-input::-moz-range-track {
	background: none;
	border: none;
}

.cdts-range-value {
	margin-top: 10px;
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 14px;
	font-weight: 600;
	color: var(--cdts-accent);
}

.cdts-range-dash {
	color: inherit;
	opacity: .7;
	font-weight: 400;
}

/* ---------------------------------------------------------------- rating */

.cdts-rating-icons {
	display: flex;
	align-items: center;
	gap: 4px;
}

.cdts-rating-icon {
	position: relative;
	width: 30px;
	height: 30px;
	padding: 0;
	border: 0;
	background: none;
	cursor: pointer;
	line-height: 1;
}

.cdts-rating-glyph {
	position: absolute;
	inset: 0;
	background: var(--cdts-rail);
	transition: background-color .12s;
}

.cdts-rating-glyph-on {
	background: var(--cdts-accent);
	width: 0;
	overflow: hidden;
}

.cdts-rating-icon.is-on .cdts-rating-glyph-on { width: 100%; }
.cdts-rating-icon.is-half .cdts-rating-glyph-on { width: 50%; }

/* The shape is a mask, so one element covers every icon style. */
.cdts-rating-star .cdts-rating-glyph {
	-webkit-mask: var(--cdts-star) center / contain no-repeat;
	mask: var(--cdts-star) center / contain no-repeat;
}

.cdts-rating-heart .cdts-rating-glyph {
	-webkit-mask: var(--cdts-heart) center / contain no-repeat;
	mask: var(--cdts-heart) center / contain no-repeat;
}

.cdts-rating-circle .cdts-rating-glyph { border-radius: 50%; }
.cdts-rating-square .cdts-rating-glyph { border-radius: 3px; }

.cdts-rating {
	--cdts-star: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z'/%3E%3C/svg%3E");
	--cdts-heart: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21s-8-4.9-8-10.5A4.5 4.5 0 0 1 12 7a4.5 4.5 0 0 1 8 3.5C20 16.1 12 21 12 21z'/%3E%3C/svg%3E");
}

.cdts-rating-value {
	margin-left: 8px;
	font-size: 13px;
	color: inherit;
	opacity: .7;
}

/* ---------------------------------------------------------------- color */

.cdts-color-palette {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-bottom: 10px;
}

.cdts-color-swatch {
	width: 30px;
	height: 30px;
	padding: 0;
	border: 2px solid transparent;
	box-shadow: 0 0 0 1px var(--cdts-border) inset;
	cursor: pointer;
	transition: transform .12s, border-color .12s;
}

.cdts-color-circle .cdts-color-swatch { border-radius: 50%; }
.cdts-color-square .cdts-color-swatch { border-radius: 6px; }

.cdts-color-swatch:hover { transform: scale(1.08); }

.cdts-color-swatch.is-on {
	border-color: inherit;
	box-shadow: 0 0 0 2px #fff inset;
}

/* A diagonal stroke reads as "none" without needing an icon font. */
.cdts-color-clear {
	background:
		linear-gradient(to top right,
			transparent calc(50% - 1px), #d9534f calc(50% - 1px),
			#d9534f calc(50% + 1px), transparent calc(50% + 1px));
	box-shadow: 0 0 0 1px var(--cdts-border) inset;
}

.cdts-color-custom {
	display: flex;
	align-items: center;
	gap: 10px;
}

.cdts-color-custom .input-container { flex: 1 1 auto; min-width: 0; }

/*
 * The native swatch is hidden behind a styled label. A bare input[type=color]
 * inherits the theme's input background and paints over the chosen color, so
 * the color is shown on the label instead.
 */
.cdts-color-native {
	position: relative;
	display: block;
	width: 38px;
	height: 38px;
	flex: 0 0 38px;
	border-radius: 8px;
	box-shadow: 0 0 0 1px var(--cdts-border) inset;
	cursor: pointer;
	overflow: hidden;
}

.cdts-color-native input {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	border: 0;
	padding: 0;
	cursor: pointer;
}

.cdts-color-clear-btn { flex: 0 0 auto; }

@media (max-width: 600px) {
	.cdts-slider-descriptions {
		grid-template-columns: 1fr;
	}
}
