/* =============================================================
   CLIENT PORTAL — CALCULATORS (v4 layout, Phase 2)
   Markup: bluesilver-advisory-core/includes/resources/calculator-p4.php
   Behaviour: bluesilver-advisory-core/assets/js/portal/portal.js
   Mockups: Calculator-Laptop, Mobile-Calculator, CostPlanner-Laptop, CostPlanner-Phone

   ≥1024px: calculator takes the full width (resource list hidden), inputs on
            the left, results column sticky on the right.
   <1024px: results first, inputs below; a live-result bar appears once the
            results card scrolls away.
   Loads after portal-shell.css and calculator.css, which it overrides.
   ============================================================= */

/* ---- Viewer while a calculator is open (any width) ---- */
.bsa-p4 .bsa-p4-view.is-wide .bsa-portal-col3.bsa-p4-viewer {
	overflow: visible;          /* sticky results need no clipping ancestor */
	background: transparent;
	border: 0;
	border-radius: 0;
	min-height: 0;
}

/* Laptops: the resource list stays on the left; the calculator scrolls with the page. */
@media (min-width: 1024px) {
	.bsa-p4 .bsa-p4-view.is-wide .bsa-portal-col3.bsa-p4-viewer {
		position: static;
		height: auto;
	}
	/* The list is right there, so no Back button. */
	.bsa-p4 .bsa-p4-calc .bsa-p4-calc__back { display: none; }
}

.bsa-p4 .bsa-p4-calc.is-active { display: block; }
.bsa-p4 .bsa-p4-calc { flex: none; min-height: 0; }

/* Reset the generic results-table look from calculator.css */
.bsa-p4 .bsa-p4-calc .bsa-calc-output {
	display: block;
	padding: 0;
	border: 0;
	gap: 0;
}

/* Values take the colour and size of where they sit (navy cards use white text) */
.bsa-p4 .bsa-p4-calc .bsa-calc-output__value {
	color: inherit;
	font-size: inherit;
	font-weight: inherit;
	font-family: inherit;
	line-height: inherit;
	letter-spacing: inherit;
}

/* =============================================================
   HEAD
   ============================================================= */

.bsa-p4-calc__head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px 16px;
	margin-bottom: 18px;
}

.bsa-p4 .bsa-p4-calc__back {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	height: 40px;
	padding: 0 12px;
	border-radius: var(--bsa-radius, 10px);
	border: 1px solid #C9D3DE;
	background: #FFFFFF;
	color: var(--p4-navy);
	font: inherit;
	font-size: var(--p4-fs-sm);
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
}

.bsa-p4 .bsa-p4-calc__back:hover { border-color: var(--p4-primary); color: var(--p4-primary); background: #FFFFFF; }

.bsa-p4-calc__titles { display: flex; flex-direction: column; min-width: 0; }
.bsa-p4-calc__kind { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: #2F6B4F; }
.bsa-p4 .bsa-p4-calc__title { font-size: var(--p4-fs-h2); line-height: 1.2; }
.bsa-p4-calc--cost .bsa-p4-calc__title { font-size: var(--p4-fs-h1); }

.bsa-p4-calc__desc { margin: 0; font-size: var(--p4-fs-base); color: var(--p4-body); line-height: 1.5; }
.bsa-p4-calc__desc--head { max-width: 420px; margin-left: 4px; }

.bsa-p4-calc__actions { margin-left: auto; display: flex; gap: 8px; }

/* Favourite star shown as a "Save" button */
.bsa-p4 .bsa-resource-favorite.bsa-p4-calc__save {
	position: static;
	transform: none;
	width: auto;
	height: 40px;
	padding: 0 12px;
	gap: 6px;
	border-radius: var(--bsa-radius, 10px);
	border: 1px solid #C9D3DE;
	background: #FFFFFF;
	color: var(--p4-navy);
	font-size: var(--p4-fs-sm);
	font-weight: 600;
}

.bsa-p4 .bsa-resource-favorite.bsa-p4-calc__save svg { width: 17px; height: 17px; }
.bsa-p4 .bsa-resource-favorite.bsa-p4-calc__save::after { content: 'Save'; }
.bsa-p4 .bsa-resource-favorite.bsa-p4-calc__save.is-favourite { color: #B45309; border-color: #E8C58F; background: #FFF8EC; }
.bsa-p4 .bsa-resource-favorite.bsa-p4-calc__save.is-favourite::after { content: 'Saved'; }

/* =============================================================
   GRID + INPUTS
   ============================================================= */

.bsa-p4-calc__grid {
	display: grid;
	grid-template-columns: minmax(0, 1fr) 400px;
	gap: 20px;
	align-items: start;
}

.bsa-p4-calc--cost .bsa-p4-calc__grid { grid-template-columns: minmax(0, 1fr) 460px; }

.bsa-p4-calc__inputs {
	background: #FFFFFF;
	border: 1px solid var(--p4-border);
	border-radius: var(--bsa-radius, 10px);
	padding: 20px 24px;
	display: flex;
	flex-direction: column;
	gap: 20px;
	min-width: 0;
}

.bsa-p4-calc__group { display: flex; flex-direction: column; gap: 12px; }

.bsa-p4 .bsa-p4-calc__group-title { margin: 0; font: inherit; }

.bsa-p4-calc__group-head {
	display: flex;
	align-items: center;
	gap: 10px;
	width: 100%;
	padding: 4px 0;
	border: 0;
	background: none;
	font: inherit;
	font-size: var(--p4-fs-xs);
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--p4-muted);
	text-align: left;
	cursor: pointer;
}

.bsa-p4-calc__group--in .bsa-p4-calc__group-head  { color: #2F6B4F; }
.bsa-p4-calc__group--out .bsa-p4-calc__group-head { color: #A3342B; }

.bsa-p4-calc__group-name { flex: 1; }
.bsa-p4-calc__group-count,
.bsa-p4 .bsa-p4-calc .bsa-p4-calc__group-title .bsa-p4-calc__group-sum { display: none; }   /* subtotals show on phones only */

.bsa-p4-calc__group-head svg { transition: transform 0.15s; flex-shrink: 0; opacity: 0.7; }
.bsa-p4-calc__group.is-collapsed .bsa-p4-calc__group-head svg { transform: rotate(-90deg); }
.bsa-p4-calc__group.is-collapsed .bsa-p4-calc__rows { display: none; }

.bsa-p4-calc__rows { display: flex; flex-direction: column; gap: 12px; }

.bsa-p4-calc__row {
	display: grid;
	grid-template-columns: 200px minmax(0, 1fr) 180px;
	gap: 16px;
	align-items: center;
}

.bsa-p4-calc__row--noslider .bsa-p4-calc__field { grid-column: 3; }

.bsa-p4-calc__label { font-size: var(--p4-fs-base); font-weight: 400; color: var(--p4-text); line-height: 1.3; }

.bsa-p4-calc__field {
	display: flex;
	align-items: center;
	height: 42px;
	border: 1px solid #C9D3DE;
	border-radius: var(--bsa-radius, 10px);
	background: #FFFFFF;
	overflow: hidden;
	min-width: 0;
	transition: border-color 0.15s, box-shadow 0.15s;
}

.bsa-p4-calc__field:focus-within { border-color: var(--p4-primary); box-shadow: 0 0 0 3px rgba(44, 95, 138, 0.18); }

.bsa-p4-calc__affix {
	display: flex;
	align-items: center;
	height: 100%;
	padding: 0 10px;
	background: #F4F5F7;
	color: var(--p4-muted);
	font-size: var(--p4-fs-sm);
	flex-shrink: 0;
}

.bsa-p4 .bsa-p4-calc__field .bsa-calc-input {
	flex: 1;
	min-width: 0;
	height: 100%;
	padding: 0 10px !important;
	border: 0 !important;
	border-radius: 0 !important;
	outline: none !important;
	box-shadow: none !important;
	background: transparent !important;
	font: inherit;
	font-size: 16px;
	font-weight: 400;
	color: var(--p4-text);
}

/* Sliders: tone matches the group (purchase blue, income green, costs red) */
.bsa-p4 .bsa-p4-calc__slider { margin: 0; height: 6px; border-radius: 3px; }
.bsa-p4-calc__group--in .bsa-calc-slider::-webkit-slider-thumb  { background: #2F6B4F; }
.bsa-p4-calc__group--out .bsa-calc-slider::-webkit-slider-thumb { background: #A3342B; }
.bsa-p4-calc__group--in .bsa-calc-slider::-moz-range-thumb  { background: #2F6B4F; }
.bsa-p4-calc__group--out .bsa-calc-slider::-moz-range-thumb { background: #A3342B; }

/* Cost Planner: typed values, no sliders (as in the mockup) */
.bsa-p4-calc--cost .bsa-p4-calc__slider { display: none; }
.bsa-p4-calc--cost .bsa-p4-calc__row { grid-template-columns: 240px 220px minmax(0, 1fr); }
.bsa-p4-calc--cost .bsa-p4-calc__row--noslider .bsa-p4-calc__field,
.bsa-p4-calc--cost .bsa-p4-calc__field { grid-column: 2; }

.bsa-p4-calc__row--price .bsa-p4-calc__label { font-size: var(--p4-fs-base); font-weight: 700; }
.bsa-p4-calc__row--price .bsa-p4-calc__field { height: 46px; border: 2px solid var(--p4-navy); }
.bsa-p4 .bsa-p4-calc__row--price .bsa-calc-input { font-size: 17px; font-weight: 700; }

.bsa-p4 .bsa-p4-calc__row--auto .bsa-p4-calc__value {
	display: flex;
	align-items: center;
	height: 42px;
	padding: 0 12px;
	border-radius: var(--bsa-radius, 10px);
	background: #F4F5F7;
	font-size: var(--p4-fs-base);
	font-weight: 400;
	color: var(--p4-text);
}

/* Range hint under % fields (e.g. agent commission) */
.bsa-p4-calc__hint { grid-column: 2 / -1; margin-top: -8px; font-size: var(--p4-fs-xs); color: var(--p4-muted); }
.bsa-p4-calc--cost .bsa-p4-calc__hint { grid-column: 2; }

.bsa-p4-calc__pill {
	justify-self: start;
	padding: 3px 9px;
	border-radius: var(--bsa-radius, 10px);
	background: #E3EDF6;
	color: #1F4C72;
	font-size: 12px;
	font-weight: 700;
	letter-spacing: 0.02em;
	text-transform: uppercase;
	white-space: nowrap;
}

/* =============================================================
   RESULTS COLUMN
   ============================================================= */

.bsa-p4-calc__results {
	display: flex;
	flex-direction: column;
	gap: 12px;
	min-width: 0;
}

@media (min-width: 1024px) {
	.bsa-p4-calc__results {
		position: sticky;
		top: calc(var(--p4-sticky-top) + 16px);
		max-height: calc(100dvh - var(--p4-sticky-top) - 32px);
		overflow-y: auto;
		overscroll-behavior: contain;
		scrollbar-width: thin;
	}
}

.bsa-p4-calc__card {
	border-radius: var(--bsa-radius, 10px);
	padding: 20px 22px;
}

.bsa-p4-calc__card--result {
	background: var(--p4-navy);
	color: #FFFFFF;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.bsa-p4-calc--yield .bsa-p4-calc__card--result { align-items: center; }

.bsa-p4-calc__eyebrow {
	margin: 0;
	align-self: flex-start;
	font-size: var(--p4-fs-xs);
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--p4-sky);
}

/* Gauge (same SVG arc the engine animates) */
.bsa-p4-gauge { position: relative; width: 240px; max-width: 100%; }
.bsa-p4 .bsa-p4-gauge .bsa-calc-gauge { width: 100% !important; height: auto; display: block; }

.bsa-p4 .bsa-p4-calc .bsa-p4-gauge__center {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 4px;
	display: flex;
	flex-direction: column;
	align-items: center;
}

.bsa-p4 .bsa-p4-calc .bsa-p4-gauge__center .bsa-calc-output__value {
	font-family: 'PT Serif', Georgia, serif;
	font-size: 44px;
	font-weight: 700;
	line-height: 1;
	color: #FFFFFF;
}

.bsa-p4-gauge__center .bsa-calc-output__label,
.bsa-p4-calc__tile .bsa-calc-output__label {
	margin-top: 4px;
	font-size: 12px;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--p4-sky);
}

.bsa-p4-gauge__scale {
	display: flex;
	justify-content: space-between;
	padding: 2px 6px 0;
	font-size: 12px;
	color: var(--p4-sky);
}

.bsa-p4-calc__tiles {
	width: 100%;
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 10px;
}

.bsa-p4 .bsa-p4-calc .bsa-p4-calc__tile {
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
	background: var(--p4-navy-2);
	border-radius: var(--bsa-radius, 10px);
	padding: 12px 14px;
}

.bsa-p4-calc__tile .bsa-calc-output__label { margin: 0; order: 0; }
.bsa-p4 .bsa-p4-calc .bsa-p4-calc__tile .bsa-calc-output__value { order: 1; margin-top: 4px; font-size: 20px; font-weight: 700; color: #FFFFFF; }

/* Cost Planner results */
.bsa-p4 .bsa-p4-calc .bsa-p4-calc__big {
	margin: 0;
	font-family: 'PT Serif', Georgia, serif;
	font-size: 40px;
	font-weight: 700;
	line-height: 1.1;
}

.bsa-p4 .bsa-p4-calc .bsa-p4-calc__card--bars h2 .bsa-calc-output,
.bsa-p4 .bsa-p4-calc .bsa-p4-calc__live-values .bsa-calc-output { display: inline; }

.bsa-p4-calc__card--year {
	background: var(--p4-navy-2);
	color: #FFFFFF;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding-top: 16px;
	padding-bottom: 16px;
}

.bsa-p4 .bsa-p4-calc .bsa-p4-calc__mid { margin: 4px 0 0; font-size: 28px; font-weight: 700; line-height: 1.15; }

.bsa-p4-calc__card--bars {
	background: #F8FAFC;
	border: 1px solid #E8EDF2;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.bsa-p4 .bsa-p4-calc__card--bars h2 { font-size: var(--p4-fs-lg); }

/* Fee breakdown: right after One-Off Costs, behind a toggle switch (hidden by default) */
.bsa-p4-calc__breakdown { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.bsa-p4-calc__group.is-collapsed .bsa-p4-calc__breakdown { display: none; }

.bsa-p4-calc__breakdown-toggle {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	width: 100%;
	min-height: 48px;
	padding: 8px 14px;
	border: 1px solid #E8EDF2;
	border-radius: var(--bsa-radius, 10px);
	background: #F8FAFC;
	color: var(--p4-text);
	font: inherit;
	font-family: 'PT Serif', Georgia, serif;
	font-size: var(--p4-fs-base);
	font-weight: 400;
	text-align: left;
	cursor: pointer;
}

.bsa-p4-calc__breakdown-toggle:hover { border-color: #C9D3DE; }
.bsa-p4 .bsa-p4-calc .bsa-p4-calc__breakdown-title .bsa-calc-output { display: inline; font-weight: 700; }

.bsa-p4-calc__breakdown-icon { display: inline-flex; flex-shrink: 0; color: var(--p4-muted); opacity: 0.7; }
.bsa-p4-calc__breakdown-icon svg { transition: transform 0.15s; }
.bsa-p4-calc__breakdown-toggle[aria-expanded="true"] .bsa-p4-calc__breakdown-icon svg { transform: rotate(180deg); }

.bsa-p4-bars {
	display: grid;
	grid-template-columns: minmax(150px, 240px) minmax(0, 1fr) 90px;
	gap: 8px 12px;
	align-items: center;
	font-size: var(--p4-fs-sm);
	color: var(--p4-text);
}

/* Closing total row under the charges list */
.bsa-p4-bars__total {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: 12px;
	margin: 4px 0 0;
	padding-top: 10px;
	border-top: 1px solid #DDE4EC;
	font-size: var(--p4-fs-base);
	font-weight: 700;
	color: var(--p4-text);
}
.bsa-p4-bars__total span:last-child { text-align: right; font-weight: 600; }
.bsa-p4 .bsa-p4-calc .bsa-p4-bars__total .bsa-calc-output { display: inline; }

.bsa-p4-bars__track { height: 10px; border-radius: 999px; background: #EEF1F5; overflow: hidden; }
.bsa-p4-bars__fill { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--p4-primary); transition: width 0.4s ease; }
.bsa-p4 .bsa-p4-calc .bsa-p4-bars__value { text-align: right; font-weight: 700; }

/* Buttons + note: after the last field, inside the inputs card */
.bsa-p4-calc__footer {
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding-top: 18px;
	border-top: 1px solid #E8EDF2;
}

.bsa-p4-calc__buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.bsa-p4-calc__buttons svg { width: 18px !important; height: 18px !important; flex-shrink: 0; }

.bsa-p4-btn--primary { background: var(--p4-primary); color: #FFFFFF !important; border: 1px solid var(--p4-primary); }
.bsa-p4-btn--primary:hover { background: var(--p4-navy); border-color: var(--p4-navy); }
.bsa-p4-btn--primary[disabled] { opacity: 0.6; cursor: progress; }

.bsa-p4 .bsa-p4-calc .bsa-calc-reset {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: auto;
	min-height: 44px;
	margin: 0;
	padding: 0 14px;
	border-radius: var(--bsa-radius, 10px);
	border: 1px solid #C9D3DE;
	background: #FFFFFF;
	color: var(--p4-navy);
	font: inherit;
	font-size: var(--p4-fs-sm);
	font-weight: 600;
	letter-spacing: var(--p4-ls);
	text-transform: none;
}

.bsa-p4 .bsa-p4-calc .bsa-calc-reset:hover { border-color: var(--p4-primary); color: var(--p4-primary); }

.bsa-p4-calc__notes { margin: 0; font-size: var(--p4-fs-xs); color: var(--p4-muted); line-height: 1.45; }

/* Live result bar: tablets and phones only */
.bsa-p4-calc__live { display: none; }

/* =============================================================
   RESPONSIVE
   ============================================================= */

/* Viewer narrower than ~980px (laptops, beside the list): label above each field. */
@media (min-width: 1024px) {
	@container p4viewer (max-width: 979.98px) {
		.bsa-p4-calc__grid { grid-template-columns: minmax(0, 1fr) 320px; }
		.bsa-p4-calc--cost .bsa-p4-calc__grid { grid-template-columns: minmax(0, 1fr) 340px; }
		.bsa-p4-calc__row { grid-template-columns: minmax(0, 1fr) 150px; gap: 8px 14px; }
		.bsa-p4-calc__row .bsa-p4-calc__label,
		.bsa-p4-calc__row .bsa-p4-calc__hint { grid-column: 1 / -1; }
		.bsa-p4-calc__row--noslider .bsa-p4-calc__field { grid-column: 2; }
		.bsa-p4-calc--cost .bsa-p4-calc__row { grid-template-columns: minmax(0, 220px) minmax(0, 1fr); }
		.bsa-p4-calc--cost .bsa-p4-calc__field,
		.bsa-p4-calc--cost .bsa-p4-calc__row--noslider .bsa-p4-calc__field,
		.bsa-p4 .bsa-p4-calc--cost .bsa-p4-calc__row--auto .bsa-p4-calc__value { grid-column: 1; }
		.bsa-p4-calc--cost .bsa-p4-calc__pill { grid-column: 2; }
		.bsa-p4-calc__desc--head { flex-basis: 100%; order: 3; margin-left: 0; max-width: none; }
		.bsa-p4-bars { grid-template-columns: minmax(120px, 190px) minmax(0, 1fr) 80px; }
	}

	/* Very narrow viewer (e.g. 1024px screens): results on top, inputs below. */
	@container p4viewer (max-width: 719.98px) {
		.bsa-p4-calc__grid,
		.bsa-p4-calc--cost .bsa-p4-calc__grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
		.bsa-p4-calc__results { order: -1; position: static; max-height: none; overflow: visible; }
	}
}

/* Short laptop windows (e.g. 1366×657, 1280×650) and narrow ones (1024–1279px):
   keep the results column within the screen */
@media (min-width: 1024px) and (max-height: 820px), (min-width: 1024px) and (max-width: 1279.98px) {
	.bsa-p4-calc__head { margin-bottom: 14px; }
	.bsa-p4-calc__card { padding: 16px 20px; }
	.bsa-p4-calc__card--result { gap: 10px; }
	.bsa-p4-gauge { width: 200px; }
	.bsa-p4 .bsa-p4-calc .bsa-p4-gauge__center .bsa-calc-output__value { font-size: 36px; }
	.bsa-p4 .bsa-p4-calc .bsa-p4-calc__tile { padding: 10px 12px; }
	.bsa-p4 .bsa-p4-calc .bsa-p4-calc__tile .bsa-calc-output__value { font-size: 18px; }
	.bsa-p4 .bsa-p4-calc .bsa-p4-calc__big { font-size: 34px; }
	.bsa-p4 .bsa-p4-calc .bsa-p4-calc__mid { font-size: 24px; }
	.bsa-p4-calc__card--year { padding-top: 12px; padding-bottom: 12px; }
	.bsa-p4-calc__card--bars { gap: 8px; }
	.bsa-p4 .bsa-p4-calc__card--bars h2 { font-size: var(--p4-fs-base); }
	.bsa-p4-bars { gap: 4px 12px; font-size: var(--p4-fs-xs); }
	.bsa-p4-calc__results { gap: 8px; }
	.bsa-p4-calc__card { padding: 14px 18px; }
	.bsa-p4-calc__buttons .bsa-p4-btn,
	.bsa-p4 .bsa-p4-calc .bsa-calc-reset { min-height: 40px; }
	.bsa-p4-calc__notes { font-size: 12px; line-height: 1.35; }
	.bsa-p4-calc__inputs { gap: 16px; }
}

/* ---- Tablets and phones: results first, then inputs, live bar ---- */
@media (max-width: 1023.98px) {
	.bsa-p4-calc__grid,
	.bsa-p4-calc--cost .bsa-p4-calc__grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
	.bsa-p4-calc__results { order: -1; }
	.bsa-p4-calc__desc--head { flex-basis: 100%; order: 3; margin-left: 0; max-width: none; }
	.bsa-p4 .bsa-p4-calc { padding-bottom: 84px; }

	.bsa-p4-calc.is-live .bsa-p4-calc__live {
		display: flex;
		align-items: center;
		gap: 12px;
		position: fixed;
		left: 0;
		right: 0;
		bottom: var(--p4-tabbar-h);
		z-index: 850;
		padding: 10px 16px;
		background: var(--p4-navy-2);
		color: #FFFFFF;
		box-shadow: 0 -6px 18px rgba(3, 18, 43, 0.22);
		animation: bsa-p4-live-in 0.18s ease-out;
	}

	.bsa-p4-calc__live-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
	.bsa-p4-calc__live-label { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--p4-sky); }
	.bsa-p4-calc__live-values { font-size: var(--p4-fs-base); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

	.bsa-p4-calc__to-results {
		flex-shrink: 0;
		height: 44px;
		padding: 0 14px;
		border: 0;
		border-radius: var(--bsa-radius, 10px);
		background: #FFFFFF;
		color: var(--p4-navy);
		font: inherit;
		font-size: var(--p4-fs-sm);
		font-weight: 700;
		cursor: pointer;
	}
}

@keyframes bsa-p4-live-in { from { transform: translateY(100%); } to { transform: translateY(0); } }

@media (min-width: 600px) and (max-width: 1023.98px) {
	.bsa-p4-calc.is-live .bsa-p4-calc__live { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
}

/* ---- Phones ---- */
@media (max-width: 599.98px) {
	.bsa-p4-calc__head { gap: 10px 12px; margin-bottom: 14px; }
	.bsa-p4 .bsa-p4-calc__title,
	.bsa-p4-calc--cost .bsa-p4-calc__title { font-size: var(--p4-fs-h2); }
	.bsa-p4-calc__titles { order: 2; flex-basis: 100%; }
	.bsa-p4-calc__actions { order: 1; }

	.bsa-p4-calc__inputs { padding: 16px; gap: 16px; border-radius: var(--bsa-radius, 10px); }

	/* Stack each field: label, input, slider */
	.bsa-p4-calc__row,
	.bsa-p4-calc--cost .bsa-p4-calc__row { grid-template-columns: minmax(0, 1fr); gap: 8px; }
	.bsa-p4-calc__row--noslider .bsa-p4-calc__field,
	.bsa-p4-calc--cost .bsa-p4-calc__field { grid-column: auto; }
	.bsa-p4-calc__slider { order: 3; height: 8px; }
	.bsa-p4-calc__hint,
	.bsa-p4-calc--cost .bsa-p4-calc__hint { grid-column: auto; order: 4; margin-top: -2px; }
	.bsa-p4-calc__field { height: 48px; }
	.bsa-p4-calc__row--price .bsa-p4-calc__field { height: 52px; }

	.bsa-p4-calc__row--auto { grid-template-columns: minmax(0, 1fr) auto; }
	.bsa-p4-calc__row--auto .bsa-p4-calc__label { grid-column: 1; grid-row: 1; }
	.bsa-p4-calc__row--auto .bsa-p4-calc__pill { grid-column: 2; grid-row: 1; justify-self: end; }
	.bsa-p4 .bsa-p4-calc__row--auto .bsa-p4-calc__value { grid-column: 1 / -1; grid-row: 2; height: 46px; width: 100%; }

	/* Collapsible cost groups become tappable summary rows with the subtotal */
	.bsa-p4-calc__group[data-phone-collapsed] .bsa-p4-calc__group-head {
		min-height: 52px;
		padding: 0 14px;
		border: 1px solid var(--p4-border);
		border-radius: var(--bsa-radius, 10px);
		background: #F4F5F7;
		font-size: var(--p4-fs-base);
		letter-spacing: var(--p4-ls);
		text-transform: none;
	}

	.bsa-p4-calc__group[data-phone-collapsed] .bsa-p4-calc__group-count { display: inline; font-weight: 600; }
	.bsa-p4 .bsa-p4-calc .bsa-p4-calc__group[data-phone-collapsed] .bsa-p4-calc__group-sum { display: inline; color: var(--p4-text); font-weight: 700; white-space: nowrap; }

	.bsa-p4-calc__card { padding: 16px; border-radius: var(--bsa-radius, 10px); }
	.bsa-p4-gauge { width: 220px; }
	.bsa-p4 .bsa-p4-calc .bsa-p4-gauge__center .bsa-calc-output__value { font-size: 38px; }
	.bsa-p4-calc__tiles { gap: 8px; }
	.bsa-p4 .bsa-p4-calc .bsa-p4-calc__tile { padding: 10px 12px; }
	.bsa-p4 .bsa-p4-calc .bsa-p4-calc__tile .bsa-calc-output__value { font-size: 18px; }
	.bsa-p4 .bsa-p4-calc .bsa-p4-calc__big { font-size: 32px; }
	.bsa-p4 .bsa-p4-calc .bsa-p4-calc__mid { font-size: 22px; }
	.bsa-p4-calc__card--year { flex-wrap: wrap; }
	.bsa-p4-bars { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) 64px; gap: 8px 10px; font-size: var(--p4-fs-xs); }
}

/* =============================================================
   LOOK & FEEL (theme 24.2)
   Group colours tie each input group to its result; depth, focus and
   calculated-value styling. Same fields and wording as before.
   ============================================================= */

/* Accent per group. One-off and annual colours repeat on the matching result. */
.bsa-p4-calc { --p4-acc-oneoff: #4A7FA5; --p4-acc-year: #A8C4DE; }
.bsa-p4-calc__group { --p4-acc: #6B7C8D; }
.bsa-p4-calc__group--oneoff,
.bsa-p4-calc__group--purchase  { --p4-acc: var(--p4-acc-oneoff); }
.bsa-p4-calc__group--recurring { --p4-acc: var(--p4-acc-year); }
.bsa-p4-calc__group--in        { --p4-acc: #2F6B4F; }
.bsa-p4-calc__group--out       { --p4-acc: #A3342B; }

/* Inputs card: a little depth, same radius as the result cards */
.bsa-p4-calc__inputs {
	border-color: #E3E8EE;
	border-radius: var(--bsa-radius, 10px);
	box-shadow: 0 1px 2px rgba(15, 31, 56, 0.04), 0 8px 24px rgba(15, 31, 56, 0.06);
}

/* Coloured stripe down the side of each titled group */
.bsa-p4-calc__group:has(.bsa-p4-calc__group-title) {
	position: relative;
	padding-left: 16px;
}

.bsa-p4-calc__group:has(.bsa-p4-calc__group-title)::before {
	content: '';
	position: absolute;
	left: 0;
	top: 2px;
	bottom: 2px;
	width: 3px;
	border-radius: 3px;
	background: var(--p4-acc);
}

.bsa-p4-calc__group--oneoff .bsa-p4-calc__group-head,
.bsa-p4-calc__group--purchase .bsa-p4-calc__group-head { color: #2C5F8A; }
.bsa-p4-calc__group--recurring .bsa-p4-calc__group-head { color: #4A7FA5; }

/* Fields: clearer hover and focus */
.bsa-p4-calc__field:hover { border-color: #A8B8C8; }

.bsa-p4-calc__field:focus-within {
	border-color: var(--p4-primary);
	box-shadow: 0 0 0 4px rgba(44, 95, 138, 0.16), 0 2px 8px rgba(15, 31, 56, 0.08);
}

.bsa-p4-calc__affix { transition: background-color 0.15s, color 0.15s; }
.bsa-p4-calc__field:focus-within .bsa-p4-calc__affix { background: #E3EDF6; color: #1F4C72; }

.bsa-p4-calc__row--price .bsa-p4-calc__field:focus-within { border-color: var(--p4-navy); }

/* Calculated values read as "worked out for you", not as disabled fields */
.bsa-p4 .bsa-p4-calc__row--auto .bsa-p4-calc__value {
	gap: 8px;
	border: 1px solid #D6E4F0;
	background: #EEF4FA;
	color: #1A2E44;
}

.bsa-p4 .bsa-p4-calc__row--auto .bsa-p4-calc__value::before {
	content: '';
	flex-shrink: 0;
	width: 15px;
	height: 15px;
	background: #4A7FA5;
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71'/%3E%3Cpath d='M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71'/%3E%3C/svg%3E") center / contain no-repeat;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71'/%3E%3Cpath d='M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71'/%3E%3C/svg%3E") center / contain no-repeat;
}

.bsa-p4-calc__pill { background: #DCE8F3; }

.bsa-p4 .bsa-p4-calc__row--auto .bsa-p4-calc__value .bsa-calc-output__value { flex: 1; text-align: left; }

/* ---- Cost Planner results: one card, two sections ---- */
.bsa-p4-calc--cost .bsa-p4-calc__results { gap: 0; }

.bsa-p4-calc--cost .bsa-p4-calc__card--result:has(+ .bsa-p4-calc__card--year) {
	border-bottom-left-radius: 0;
	border-bottom-right-radius: 0;
	padding-bottom: 18px;
}

.bsa-p4-calc--cost .bsa-p4-calc__card--result + .bsa-p4-calc__card--year {
	border-top: 1px solid rgba(255, 255, 255, 0.12);
	border-top-left-radius: 0;
	border-top-right-radius: 0;
	background: var(--p4-navy);
}

.bsa-p4-calc--cost .bsa-p4-calc__card--result,
.bsa-p4-calc--cost .bsa-p4-calc__card--year { box-shadow: 0 10px 28px rgba(15, 31, 56, 0.16); }

/* Result labels carry the colour of their input group */
.bsa-p4-calc--cost .bsa-p4-calc__eyebrow {
	padding-left: 10px;
	border-left: 3px solid var(--p4-acc-oneoff);
	line-height: 1.2;
}

.bsa-p4-calc--cost .bsa-p4-calc__card--year .bsa-p4-calc__eyebrow { border-left-color: var(--p4-acc-year); }

/* Purchase price vs charges, as shares of the one-off total */
.bsa-p4-split { display: flex; flex-direction: column; gap: 10px; margin-top: 2px; }

.bsa-p4-split__track {
	display: flex;
	gap: 3px;
	height: 10px;
	border-radius: 999px;
	overflow: hidden;
	background: rgba(255, 255, 255, 0.08);
}

.bsa-p4-split__part { flex: 0 0 0; transition: flex-basis 0.45s cubic-bezier(0.22, 1, 0.36, 1); }
.bsa-p4-split__part--price { background: rgba(168, 196, 222, 0.45); }
.bsa-p4-split__part--fees  { background: #FFFFFF; min-width: 6px; }

.bsa-p4 .bsa-p4-calc .bsa-p4-split__legend {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: 6px 16px;
	margin: 0;
	font-size: var(--p4-fs-sm);
	color: #C9D7E5;
}

.bsa-p4-split__key { display: inline-flex; align-items: center; gap: 6px; }

.bsa-p4-split__key::before {
	content: '';
	width: 9px;
	height: 9px;
	border-radius: 2px;
	flex-shrink: 0;
}

.bsa-p4-split__key--price::before { background: rgba(168, 196, 222, 0.6); }
.bsa-p4-split__key--fees::before  { background: #FFFFFF; }

.bsa-p4 .bsa-p4-calc .bsa-p4-split__key .bsa-calc-output { display: inline; color: #FFFFFF; font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
	.bsa-p4-split__part { transition: none; }
}

/* ---- Cost Planner inputs: two fields per line where the card is wide enough ---- */
.bsa-p4-calc--cost .bsa-p4-calc__inputs { container: p4inputs / inline-size; }

@container p4inputs (min-width: 480px) {
	.bsa-p4 .bsa-p4-calc--cost .bsa-p4-calc__rows {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 18px 24px;
		align-items: start;
	}

	.bsa-p4 .bsa-p4-calc--cost .bsa-p4-calc__rows .bsa-p4-calc__row {
		grid-template-columns: minmax(0, 1fr) auto;
		gap: 8px 10px;
	}

	.bsa-p4 .bsa-p4-calc--cost .bsa-p4-calc__rows .bsa-p4-calc__label { grid-column: 1 / -1; grid-row: 1; }
	/* AUTO tag sits inside the calculated value, so labels keep the full width */
	.bsa-p4 .bsa-p4-calc--cost .bsa-p4-calc__rows .bsa-p4-calc__pill { grid-column: 1 / -1; grid-row: 2; justify-self: end; align-self: center; margin-right: 8px; position: relative; }

	.bsa-p4 .bsa-p4-calc--cost .bsa-p4-calc__rows .bsa-p4-calc__field,
	.bsa-p4 .bsa-p4-calc--cost .bsa-p4-calc__rows .bsa-p4-calc__row--noslider .bsa-p4-calc__field,
	.bsa-p4 .bsa-p4-calc--cost .bsa-p4-calc__rows .bsa-p4-calc__row--auto .bsa-p4-calc__value { grid-column: 1 / -1; grid-row: 2; }

	.bsa-p4 .bsa-p4-calc--cost .bsa-p4-calc__rows .bsa-p4-calc__hint { grid-column: 1 / -1; grid-row: 3; margin-top: -2px; }

	/* Purchase price lines up with the left column below it */
	.bsa-p4 .bsa-p4-calc--cost .bsa-p4-calc__price .bsa-p4-calc__row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 24px; }
	.bsa-p4 .bsa-p4-calc--cost .bsa-p4-calc__price .bsa-p4-calc__label { grid-column: 1 / -1; grid-row: 1; }
	.bsa-p4 .bsa-p4-calc--cost .bsa-p4-calc__price .bsa-p4-calc__field { grid-column: 1; grid-row: 2; }
}

/* Phones: calculated rows use the full width, like the typed fields */
@media (max-width: 599.98px) {
	.bsa-p4-calc--cost .bsa-p4-calc__row--auto { grid-template-columns: minmax(0, 1fr) auto; }
}
