/*
 * CUDA Accessible Loan Calculator — styles.
 *
 * THEMING RULE (P4-SOL-001 v0.6.0 s6.7): the calculator inherits the host page.
 *
 * There is no `color-scheme` declaration, no `prefers-color-scheme` colour rule
 * and no system colour keyword anywhere in this file, and there must never be
 * one again. Version 1.1 painted itself from the OS preference: on a light page
 * viewed in a browser set to dark it rendered a dark panel with dark text, which
 * is precisely the contrast failure this component exists to prevent. A site
 * that offers its own dark mode is followed automatically, because everything
 * here inherits.
 *
 * What that means in practice:
 *   - No colour is declared for text, backgrounds or borders. They inherit.
 *   - Native controls (select, number input, buttons) are left to the site
 *     theme. Only layout and target size are set here.
 *   - The plugin styles only what it owns: the slider track and thumb, the focus
 *     indicator, and the statutory warning box.
 *   - `--cuda-calc-accent` and `--cuda-calc-focus` are the configured brand
 *     tokens. Both default to values that inherit, so an unconfigured deployment
 *     looks like its own site rather than like this plugin.
 *
 * BOXES CARRY MEANING (s4.3, s9.6): the only bordered element the plugin renders
 * is a statutory warning. Nothing else draws a border. Do not add decorative
 * exceptions — a member who sees a box needs it to mean "regulatory statement".
 * Deployments that want a frame can add one via the documented cuda-calc-* hook
 * classes; see the class inventory in README.md.
 *
 * `prefers-reduced-motion` stays. That one is a user need, not a colour scheme.
 */

.cuda-calc {
	/* accent-color: auto is the browser/theme default, so an unbranded
	   deployment gets the site's own control colour rather than ours. */
	--cuda-calc-accent: auto;
	--cuda-calc-focus: currentColor;

	box-sizing: border-box;
	display: block;
}

.cuda-calc *,
.cuda-calc *::before,
.cuda-calc *::after {
	box-sizing: border-box;
}

/* ---------------------------------------------------------------------------
 * Opting out of Gravity Forms' own field chrome
 *
 * Two defects from the North East Credit Union trial, both caused by Gravity
 * Forms and theme CSS reaching into markup this field renders itself. Fixed
 * here, at plugin level, so every deployment gets the fix rather than each site
 * patching its own theme.
 * ------------------------------------------------------------------------ */

/*
 * 1. The "Untitled" heading leak.
 *
 * The field supplies its own group label, fieldsets and legends, so any label or
 * description Gravity Forms emits at field level is both redundant and — when no
 * label has been set — a visible "Untitled" above the calculator. display:none
 * rather than a clipping technique, deliberately: this must leave the
 * accessibility tree as well as the page, or it becomes a second, competing
 * accessible name for the same content.
 */
.gform_wrapper .gfield--type-cuda_loan_calculator > .gfield_label,
.gform_wrapper .gfield--type-cuda_loan_calculator > legend.gfield_label,
.gform_wrapper .gfield--type-cuda_loan_calculator > .gfield_description:not(.validation_message) {
	display: none;
}

/*
 * 2. The choice-decoration artifact.
 *
 * Gravity Forms' Orbital theme and the Styles Pro add-on decorate radio and
 * checkbox inputs inside .gfield with generated content and background images.
 * On the trial page that surfaced as a small grey box with a cross beside every
 * product radio — a decoration whose asset never resolved.
 *
 * These controls are plugin-rendered and are not GF choices, so the field opts
 * out of that decoration and restores the native control. !important is
 * warranted here and nowhere else in this file: the rules being overridden are
 * injected by another plugin whose stylesheet load order we do not control.
 */
.cuda-calc input[type="radio"],
.cuda-calc input[type="checkbox"] {
	appearance: auto !important;
	-webkit-appearance: auto !important;
	width: auto !important;
	height: auto !important;
	min-width: 0 !important;
	min-height: 0 !important;
	padding: 0 !important;
	border: initial !important;
	border-radius: initial !important;
	background: initial !important;
	background-image: none !important;
	box-shadow: none !important;
	accent-color: var(--cuda-calc-accent);
}

.cuda-calc input[type="radio"]::before,
.cuda-calc input[type="radio"]::after,
.cuda-calc input[type="checkbox"]::before,
.cuda-calc input[type="checkbox"]::after,
.cuda-calc .cuda-calc__choice label::before,
.cuda-calc .cuda-calc__choice label::after {
	content: none !important;
	display: none !important;
}

.cuda-calc select {
	appearance: auto !important;
	-webkit-appearance: auto !important;
	background-image: none !important;
}

/* ---------------------------------------------------------------------------
 * Structure
 * ------------------------------------------------------------------------ */

/* Visually hidden but available to assistive technology. Used for the announcer,
   and for the slider labels — which remain real <label> elements providing the
   accessible name (P4-SOL-001 v0.6.0 s5.1). */
.cuda-calc__visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.cuda-calc__title,
.cuda-calc__results-title {
	display: block;
	margin-bottom: 0.5rem;
	font-size: 1.125rem;
	font-weight: 700;
	line-height: 1.3;
}

/* Fieldsets keep their grouping semantics and lose their drawn border. */
.cuda-calc__field {
	margin: 0 0 1.5rem;
	padding: 0;
	border: 0;
}

.cuda-calc__field legend,
.cuda-calc__field-label {
	display: block;
	padding: 0;
	font-size: 1.125rem;
	font-weight: 700;
}

.cuda-calc__hint {
	max-width: 42rem;
	margin: 0.25rem 0 0.75rem;
}

.cuda-calc__control-grid {
	display: flex;
	align-items: end;
	gap: 1rem;
	flex-wrap: wrap;
}

.cuda-calc__slider-wrap {
	flex: 1 1 18rem;
}

.cuda-calc__number-wrap {
	flex: 0 1 12rem;
}

.cuda-calc label {
	display: block;
	margin-bottom: 0.35rem;
	font-weight: 700;
}

.cuda-calc__choices {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem 1.5rem;
}

.cuda-calc__choice {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	min-height: 44px;
}

.cuda-calc__choice label {
	margin-bottom: 0;
	font-weight: 400;
}

/*
 * Native controls: layout and target size only.
 *
 * No border, background or colour is set. WCAG 2.2 SC 2.5.8 target size is an
 * accessibility requirement rather than a styling preference, so min-height
 * stays; everything about how the control looks belongs to the site theme.
 */
.cuda-calc__number,
.cuda-calc__frequency-select,
.cuda-calc__product-select {
	width: 100%;
	min-height: 44px;
	font: inherit;
}

.cuda-calc__product-select {
	max-width: 28rem;
}

.cuda-calc__stepper {
	min-width: 44px;
	min-height: 44px;
	font: inherit;
	font-size: 1.25rem;
	font-weight: 700;
	cursor: pointer;
}

.cuda-calc__stepper-group {
	display: flex;
	gap: 0.5rem;
}

/*
 * A class setting display would otherwise beat the user agent's own
 * [hidden] { display: none }, leaving a "hidden" stepper group on screen while
 * assistive technology correctly reports it as absent — the worst of both. One
 * class plus one attribute outranks the class rules above, so no !important is
 * needed to win it.
 */
.cuda-calc [hidden] {
	display: none;
}

/* The slider is plugin-owned: it is the one control whose appearance this
   stylesheet sets, and the accent token is what a deployment brands. */
.cuda-calc__slider {
	width: 100%;
	min-height: 44px;
	accent-color: var(--cuda-calc-accent);
}

.cuda-calc__slider::-webkit-slider-thumb {
	min-width: 44px;
	min-height: 44px;
}

.cuda-calc__slider::-moz-range-thumb {
	min-width: 44px;
	min-height: 44px;
}

/* ---------------------------------------------------------------------------
 * Summary row: repayment frequency and the headline repayment, paired
 * ------------------------------------------------------------------------ */

/*
 * Two columns of the same shape — a bold label over a value — so the control and
 * the figure it drives read as a pair. The headline is a quick visual reference
 * and sits outside the representative example; see render_headline() in the
 * field class for why that is safe.
 */
.cuda-calc__summary {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-start;
	gap: 1rem 3rem;
	margin-bottom: 1.5rem;
}

.cuda-calc__frequency {
	flex: 0 1 14rem;
	max-width: 18rem;
	margin: 0;
}

.cuda-calc__headline {
	flex: 0 1 auto;
	margin: 0;
}

/* Mirrors the .cuda-calc label rule so the two column headings line up. */
.cuda-calc__headline .cuda-calc-headline-label {
	display: block;
	margin-bottom: 0.35rem;
	font-weight: 700;
}

.cuda-calc__headline strong {
	display: block;
	font-size: 1.75rem;
	font-weight: 700;
	line-height: 1.2;
}

/* The representative example gets its own full-width line beneath the row. */
.cuda-calc__results {
	margin: 0;
}

.cuda-calc__badge {
	display: inline-block;
	margin-top: 0.35rem;
	font-size: 0.875rem;
	font-weight: 700;
}

.cuda-calc__badge[hidden] {
	display: none;
}

.cuda-calc__note {
	margin: 0 0 0.75rem;
}

/*
 * The narrative sentence is the only visible carrier of the number of
 * repayments, the APR, the total cost of credit and the total amount repayable
 * (s9.3). Body text at full inherited contrast — never muted, never smaller.
 *
 * min-height is set at runtime by calculator.js from an offscreen measurement of
 * the longest sentence any product/frequency combination produces, so the page
 * below the calculator does not move when the figures change (s11).
 */
.cuda-calc__quote {
	margin: 0 0 0.75rem;
}

.cuda-calc__quote:empty {
	display: none;
}

.cuda-calc__disclaimer {
	margin: 0;
}

/* ---------------------------------------------------------------------------
 * Statutory warnings — the only boxed elements in the calculator
 * ------------------------------------------------------------------------ */

/*
 * Box plus bold is the Consumer Protection Code prominence presentation (s9.6).
 *
 * Neutral by design: the border inherits the page's text colour, there is no
 * fill, and no red or amber anywhere. A warning statement is standing disclosure,
 * not an error — it must not read as something the member has done wrong, and it
 * must stay visually distinct from .cuda-calc__errors.
 */
/*
 * An unused placement collapses entirely. A placement that some product in the
 * catalogue does use keeps its reserved height even while empty — otherwise
 * selecting a product with a warning would push everything below the calculator
 * down by the height of the box (s11). calculator.js sets data-reserved on the
 * slots it has measured.
 */
.cuda-calc__warnings:empty:not([data-reserved]) {
	display: none;
}

.cuda-calc__warnings {
	margin: 1.5rem 0;
}

.cuda-calc__warning {
	margin: 0 0 0.75rem;
	padding: 0.75rem 1rem;
	border: 2px solid;
	font-weight: 700;
}

.cuda-calc__warning:last-child {
	margin-bottom: 0;
}

/* ---------------------------------------------------------------------------
 * Errors and focus
 * ------------------------------------------------------------------------ */

/*
 * Error text inherits the page's colour and is distinguished by weight and by
 * role="alert", not by a fixed red. A hardcoded red is exactly what failed on a
 * dark background in v1, and since the calculator no longer knows what colour it
 * is sitting on, it cannot pick one safely. Weight-plus-role also means colour is
 * never the only means of conveying the error (WCAG 1.4.1).
 *
 * A deployment that knows its palette can set --cuda-calc-danger in site CSS.
 */
.cuda-calc {
	--cuda-calc-danger: currentColor;
}

.cuda-calc__errors {
	min-height: 1.5rem;
	margin-bottom: 1rem;
	color: var(--cuda-calc-danger);
	font-weight: 700;
}

.cuda-calc__errors:empty {
	margin-bottom: 0;
}

.cuda-calc :focus-visible {
	outline: 3px solid var(--cuda-calc-focus);
	outline-offset: 2px;
}

@media (max-width: 44rem) {
	.cuda-calc__control-grid {
		display: block;
	}

	.cuda-calc__slider-wrap,
	.cuda-calc__number-wrap,
	.cuda-calc__stepper-group {
		margin-bottom: 1rem;
	}

	.cuda-calc__summary {
		display: block;
	}

	.cuda-calc__frequency {
		max-width: none;
		margin-bottom: 1rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.cuda-calc *,
	.cuda-calc *::before,
	.cuda-calc *::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		scroll-behavior: auto !important;
		transition-duration: 0.01ms !important;
	}
}

/* ---------------------------------------------------------------------------
 * Form editor
 *
 * Admin-only styling. Fixed colours are fine here: the WordPress admin palette
 * is known, unlike a credit union's front end.
 * ------------------------------------------------------------------------ */

.cuda-calc-preview {
	padding: 1rem;
	border: 1px dashed #8c8f94;
	border-radius: 0.25rem;
}

.cuda-calc-preview__summary {
	margin: 0 0 0.5rem;
	font-weight: 600;
}

.cuda-calc-preview__errors {
	margin: 0 0 0.5rem 1.25rem;
	color: #b10e1e;
	list-style: disc;
}

.cuda-calc-preview__note {
	margin: 0;
	color: #50575e;
	font-style: italic;
}

.cuda-calc-setting-block {
	margin-top: 0.75rem;
}

.cuda-calc-setting-note {
	margin: 0.5rem 0;
	color: #50575e;
	font-size: 0.8125rem;
}

.cuda-calc-setting-input,
#cuda_calc_catalogue_json {
	width: 100%;
}

#cuda_calc_catalogue_json {
	font-family: Menlo, Consolas, monospace;
	font-size: 0.8125rem;
}

.cuda-calc-setting-errors ul {
	margin: 0 0 0 1.25rem;
	color: #b10e1e;
	list-style: disc;
}

.cuda-calc-setting-warnings ul {
	margin: 0 0 0 1.25rem;
	color: #8a6100;
	list-style: disc;
}

.cuda-calc-setting-ok {
	margin: 0;
	color: #1a7f37;
}

.cuda-calc-setting-table {
	width: 100%;
	border-collapse: collapse;
}

.cuda-calc-setting-table th {
	width: 45%;
	padding: 0.25rem 0.5rem 0.25rem 0;
	text-align: left;
	font-weight: 400;
}

.cuda-calc-setting-table select {
	width: 100%;
}

.cuda-calc-repeater__product,
.cuda-calc-repeater__globals {
	margin: 0.75rem 0;
	padding: 0.75rem;
	border: 1px solid #c3c4c7;
	border-radius: 0.25rem;
}

.cuda-calc-repeater__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 0.5rem;
}

.cuda-calc-repeater__row {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	align-items: end;
	margin-bottom: 0.5rem;
}

.cuda-calc-repeater__cell {
	display: block;
	flex: 1 1 8rem;
}

.cuda-calc-repeater__cell span {
	display: block;
	font-size: 0.75rem;
	font-weight: 600;
}

/*
 * Text, number and date boxes fill their column. Checkboxes and radios are
 * excluded rather than corrected afterwards.
 *
 * The first attempt at this stretched every input and then set the checkbox back
 * with width: auto. That is right against a native checkbox and wrong in
 * wp-admin, which paints checkboxes with appearance: none — and a replaced
 * control with no appearance has no intrinsic width, so auto collapsed it to its
 * two borders. Not touching the control at all is the only version of this rule
 * that cannot be wrong: whatever the admin theme sizes it to is correct by
 * definition, in this WordPress version and the next one.
 */
.cuda-calc-repeater__cell input:not([type="checkbox"]):not([type="radio"]),
.cuda-calc-repeater__cell select,
.cuda-calc-repeater__cell textarea {
	width: 100%;
}

.cuda-calc-repeater__inline {
	display: inline-flex;
	align-items: center;
	gap: 0.25rem;
	margin-right: 0.75rem;
}

.cuda-calc-repeater__inline span {
	display: inline;
	font-weight: 400;
}

/*
 * The checkbox is drawn as a native control, whatever the editor around it does.
 *
 * Two rounds of this were lost to the assumption that a checkbox in the form
 * editor renders like a checkbox. Gravity Forms' admin theme replaces its own
 * checkboxes with a styled pseudo-element on a specific label class and hides
 * the real input — a normal, sensible pattern, and fatal to any checkbox that
 * does not carry GF's markup. Ours does not: it is plugin-rendered inside the
 * plugin's own panel, so it inherited the hiding and none of the decoration, and
 * appeared as a label with no control beside it. It still toggled when the text
 * was clicked, which is why the setting saved correctly all along.
 *
 * !important is warranted here for the same reason the front-end block above
 * gives: the rules being overridden belong to another stylesheet whose load
 * order and future contents this plugin does not control. Scoped to the
 * plugin's own container so nothing else in the editor is touched.
 *
 * Every property here undoes one documented way of hiding a control. They are
 * listed in full rather than trimmed to what a current version happens to need,
 * because the next GF release may reach for a different one.
 */
#cuda_calc_catalogue_repeater input[type="checkbox"] {
	flex: 0 0 auto;
	appearance: auto !important;
	-webkit-appearance: auto !important;
	position: static !important;
	opacity: 1 !important;
	clip: auto !important;
	clip-path: none !important;
	width: 1rem !important;
	height: 1rem !important;
	min-width: 1rem !important;
	min-height: 1rem !important;
	max-width: none !important;
	max-height: none !important;
	margin: 0 !important;
	padding: 0 !important;
	border: initial !important;
	background: initial !important;
	background-image: none !important;
	box-shadow: none !important;
	display: inline-block !important;
	visibility: visible !important;
	pointer-events: auto !important;
	transform: none !important;
}

/*
 * And remove any decoration the editor theme draws in place of the control it
 * hid — otherwise a checkmark or box can appear alongside the native one.
 */
#cuda_calc_catalogue_repeater input[type="checkbox"]::before,
#cuda_calc_catalogue_repeater input[type="checkbox"]::after,
#cuda_calc_catalogue_repeater .cuda-calc-repeater__inline::before,
#cuda_calc_catalogue_repeater .cuda-calc-repeater__inline::after {
	content: none !important;
	display: none !important;
}

.cuda-calc-repeater__note {
	margin: 0.35rem 0 0;
	font-size: 0.85em;
	font-weight: 400;
	color: #50575e;
}

.cuda-calc-repeater__bands {
	margin-top: 0.75rem;
	padding-top: 0.5rem;
	border-top: 1px solid #dcdcde;
}

.cuda-calc-repeater__bands-title {
	display: block;
	margin-bottom: 0.5rem;
	font-weight: 700;
}
