/* ==========================================================================
   Zakat calculator (GIVING): .calc with the variants panel (Home) and equation (Zakat hero).
   Loaded on Home and Zakat. giving.js computes 2.5%, formats it and carries the amount into the
   checkout link. Surfaces allowed by A4: the calculator panel and the equation bar (no shadow).
   ========================================================================== */

.calc {
	--calc-input-h: 56px;
	--calc-row-h: 44px;
}

/* The plain rule: visible without JavaScript (in place of the field), read with the field otherwise. */
.calc__rule {
	color: var(--c-blue-950);
	font: 600 var(--fs-lede)/1.4 var(--ff-display);
	letter-spacing: -.01em;
}

.js .calc__rule {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

html:not(.js) :is(.calc__field, .calc__op, .calc__result, .calc__dest) {
	display: none;
}

/* Without JavaScript the equation bar keeps only its button: no empty frame around it. */
html:not(.js) .calc__bar {
	display: flex;
	justify-content: center;
	padding: 0;
	border: 0;
	background: none;
}

html:not(.js) .calc__bar .calc__give {
	margin: 0;
}

/* Field ------------------------------------------------------------------- */
.calc__field {
	min-width: 0;
}

.calc__label,
.calc__result-label {
	display: block;
	color: var(--c-ink-2);
	font: 600 var(--fs-small)/1.3 var(--ff-sans);
}

.calc__input {
	display: flex;
	align-items: center;
	gap: 6px;
	min-height: var(--calc-input-h);
	margin-top: 6px;
	padding: 0 16px;
	border: 1px solid var(--c-field);
	border-radius: var(--radius);
	background: var(--c-white);
	cursor: text;
	transition: border-color var(--dur-fast) var(--ease-out);
}

.calc__input:hover {
	border-color: var(--c-ink-3);
}

/* The wrapper carries the focus ring, so the $ prefix sits inside it. */
.calc__input:focus-within {
	border-color: var(--c-blue);
	outline: 2px solid var(--c-blue);
	outline-offset: 0;
}

.calc__prefix {
	flex: none;
	color: var(--c-ink-3);
	font: 500 1.25rem/1 var(--ff-display);
}

.calc__input input {
	flex: 1 1 auto;
	width: 100%;
	min-width: 0;
	height: calc(var(--calc-input-h) - 2px);
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	color: var(--c-blue-950);
	font: 600 1.25rem/1 var(--ff-display);
	letter-spacing: -.01em;
	font-variant-numeric: tabular-nums;
}

.calc__input input:focus {
	outline: none;
}

.calc__input input::placeholder {
	color: var(--c-ink-3);
	opacity: 1;
}

/* Result ------------------------------------------------------------------ */
.calc__result {
	min-width: 0;
}

.calc__value {
	display: flex;
	align-items: center;
	min-height: var(--calc-row-h);
	color: var(--c-blue-950);
	font: 700 var(--fs-stat)/1 var(--ff-display);
	letter-spacing: -.03em;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.calc__value.is-long {
	font-size: clamp(1.625rem, 1.3rem + 1vw, 2.25rem);
}

.calc__note {
	color: var(--c-ink-2);
	font-size: var(--fs-xs);
	line-height: 1.5;
}

/* Panel (Home): sky tool panel, no shadow ---------------------------------- */
.calc--panel {
	display: grid;
	gap: 18px;
	padding: clamp(1.25rem, .9rem + 1.4vw, 1.75rem);
	border-radius: var(--radius-m);
	background: var(--c-sky);
}

.calc--panel .calc__value {
	margin-top: 4px;
}

.calc--panel .calc__give {
	width: 100%;
}

.calc__more {
	margin-top: -6px;
}

/* Equation (Zakat hero): wealth × 2.5% = Zakat, then Give ------------------- */
.calc--equation {
	display: grid;
	justify-items: center;
	gap: 16px;
	margin-top: clamp(1.5rem, 1rem + 1.6vw, 2.25rem);
}

.calc__bar {
	--calc-input-h: 64px;
	display: grid;
	grid-template-columns: auto auto minmax(0, 1fr);
	grid-template-areas:
		"field field field"
		"times equals result"
		"give give give";
	align-items: end;
	gap: 12px 14px;
	width: 100%;
	max-width: 1080px;
	padding: 16px;
	border: 1px solid var(--c-line);
	border-radius: var(--radius-l);
	background: var(--c-white);
	text-align: start;
}

.calc__bar .calc__field {
	grid-area: field;
}

.calc__bar .calc__result {
	grid-area: result;
}

.calc__bar .calc__give {
	grid-area: give;
}

.calc__op--times {
	grid-area: times;
}

.calc__op--equals {
	grid-area: equals;
}

.calc__bar .calc__input input {
	font-size: 1.5rem;
}

/* Same 6px label gap as the field, so both labels sit on one line. */
.calc__bar .calc__value {
	margin-top: 6px;
}

.calc__op {
	display: flex;
	align-items: center;
	min-height: var(--calc-row-h);
	color: var(--c-ink-3);
	font: 500 1.25rem/1 var(--ff-display);
	letter-spacing: -.01em;
	white-space: nowrap;
}

/* Destinations: the CORE segmented control, 2×2 on phones. */
.calc__dest {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	width: 100%;
}

.calc--equation .calc__note {
	max-width: 62ch;
	text-align: center;
}

@media (min-width: 48em) {
	.calc__bar {
		--calc-row-h: 64px;
		grid-template-columns: minmax(0, 1.4fr) auto auto minmax(0, 1fr);
		grid-template-areas:
			"field times equals result"
			"give give give give";
		column-gap: 16px;
		padding: 12px 12px 12px 20px;
	}

	.calc__op {
		font-size: 1.75rem;
	}

	.calc__dest {
		display: inline-flex;
		width: auto;
	}
}

@media (min-width: 64em) {
	.calc__bar {
		grid-template-columns: minmax(0, 1.4fr) auto auto minmax(0, 1fr) auto;
		grid-template-areas: "field times equals result give";
	}

	/* Centre the 52px button on the 64px control row. The minimum width holds labels up to
	   "Give $250,000 Zakat", so the field and result columns do not shift while typing. */
	.calc__bar .calc__give {
		min-width: 15.5rem;
		margin-bottom: calc((var(--calc-row-h) - 52px) / 2);
	}
}

/* Forced colours: keep the panel and bar edges. */
@media (forced-colors: active) {
	.calc--panel,
	.calc__bar,
	.calc__input {
		border: 1px solid CanvasText;
	}
}
