/*
 * Calculator Engine – calculator UI.
 * Colours come from theme custom properties with safe fallbacks, so the
 * calculators look right in any theme.
 */
.ce-calculator,
.ce-contact {
	--_bg: var(--cuk-bg, #fff);
	--_surface: var(--cuk-surface, #f5f7fa);
	--_text: var(--cuk-text, #14213d);
	--_muted: var(--cuk-muted, #4f5d75);
	--_border: var(--cuk-border, #d5dce6);
	--_primary: var(--cuk-primary, #1a5fb4);
	--_primary-dark: var(--cuk-primary-dark, #134a8e);
	--_primary-soft: var(--cuk-primary-soft, #e9f1fb);
	--_error: var(--cuk-error, #b42318);
	--_success: var(--cuk-success, #1e7b4c);
	--_radius: var(--cuk-radius, 6px);
	--_focus: var(--cuk-focus, #1a5fb4);
	color: var(--_text);
}

.ce-calculator {
	display: grid;
	gap: 20px;
	margin: 0 0 28px;
	padding: 20px;
	background: var(--_bg);
	border: 1px solid var(--_border);
	border-radius: calc(var(--_radius) + 2px);
	box-shadow: 0 1px 2px rgba(20, 33, 61, .05);
}

@media (min-width: 1100px) {
	.ce-calculator:not(.ce-sci) {
		grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
		align-items: start;
	}
}

/* ---------- Form ---------- */
.ce-fields {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 14px 14px;
}

.ce-field {
	grid-column: 1 / -1;
	min-width: 0;
	margin: 0;
}

@media (min-width: 420px) {
	.ce-field--half { grid-column: span 1; }
}

.ce-field[hidden] { display: none; }

.ce-label {
	display: block;
	margin: 0 0 5px;
	padding: 0;
	font-size: .9375rem;
	font-weight: 600;
	line-height: 1.35;
	color: var(--_text);
}

.ce-input,
.ce-select,
.ce-textarea {
	display: block;
	width: 100%;
	min-height: 44px;
	padding: 9px 11px;
	font: inherit;
	font-size: 1rem;
	line-height: 1.4;
	color: var(--_text);
	background: var(--_bg);
	border: 1px solid #8a96a8;
	border-radius: var(--_radius);
	box-sizing: border-box;
	-webkit-appearance: none;
	appearance: none;
}

.ce-select {
	padding-right: 34px;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2314213d' d='M1.4 0 6 4.6 10.6 0 12 1.4l-6 6-6-6z'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 12px center;
}

.ce-textarea { min-height: 96px; resize: vertical; }

.ce-input:focus,
.ce-select:focus,
.ce-textarea:focus {
	outline: 3px solid var(--_focus);
	outline-offset: 0;
	border-color: var(--_text);
}

.ce-input::-webkit-outer-spin-button,
.ce-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ce-input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.ce-affix-wrap {
	display: flex;
	align-items: stretch;
}

.ce-affix-wrap .ce-input { flex: 1 1 auto; min-width: 0; }

.ce-affix {
	display: flex;
	align-items: center;
	padding: 0 10px;
	font-size: .9375rem;
	color: var(--_muted);
	background: var(--_surface);
	border: 1px solid #8a96a8;
	white-space: nowrap;
}

.ce-affix--pre { border-right: 0; border-radius: var(--_radius) 0 0 var(--_radius); }
.ce-affix--post { border-left: 0; border-radius: 0 var(--_radius) var(--_radius) 0; }
.ce-affix--pre + .ce-input { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.ce-affix-wrap .ce-input:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }

.ce-help {
	margin: 5px 0 0;
	font-size: .8125rem;
	line-height: 1.45;
	color: var(--_muted);
}

.ce-error {
	margin: 5px 0 0;
	font-size: .875rem;
	font-weight: 600;
	color: var(--_error);
}

.ce-error[hidden] { display: none; }

.is-invalid .ce-input,
.is-invalid .ce-select,
.is-invalid .ce-textarea,
.ce-input[aria-invalid="true"] {
	border-color: var(--_error);
	box-shadow: inset 0 0 0 1px var(--_error);
}

/* Radio as segmented control */
.ce-radio-group { margin: 0; padding: 0; border: 0; min-width: 0; }

.ce-segmented {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.ce-segment {
	position: relative;
	flex: 1 1 auto;
	cursor: pointer;
}

.ce-segment input {
	position: absolute;
	opacity: 0;
	width: 1px;
	height: 1px;
}

.ce-segment span {
	display: block;
	min-height: 42px;
	padding: 10px 12px;
	font-size: .9375rem;
	line-height: 1.3;
	text-align: center;
	color: var(--_text);
	background: var(--_bg);
	border: 1px solid #8a96a8;
	border-radius: var(--_radius);
	box-sizing: border-box;
}

.ce-segment input:checked + span {
	color: #fff;
	background: var(--_primary);
	border-color: var(--_primary);
	font-weight: 600;
}

.ce-segment input:focus-visible + span {
	outline: 3px solid var(--_focus);
	outline-offset: 2px;
}

/* Repeatable rows */
.ce-field--rows { border: 0; padding: 0; margin: 0; min-width: 0; }

.ce-rows { display: grid; gap: 10px; }

.ce-row {
	display: grid;
	grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr) 40px;
	gap: 8px;
	align-items: end;
	padding: 10px;
	background: var(--_surface);
	border-radius: var(--_radius);
}

.ce-row .ce-label { font-size: .8125rem; font-weight: 600; }

@media (max-width: 479px) {
	.ce-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 40px; }
	.ce-row-cell--label { grid-column: 1 / -1; }
}

.ce-row-remove {
	width: 40px;
	height: 44px;
	padding: 0;
	font-size: 1.375rem;
	line-height: 1;
	color: var(--_muted);
	background: transparent;
	border: 1px solid var(--_border);
	border-radius: var(--_radius);
	cursor: pointer;
}

.ce-row-remove:hover:not(:disabled) { color: var(--_error); border-color: var(--_error); }
.ce-row-remove:disabled { opacity: .35; cursor: not-allowed; }

/* Buttons */
.ce-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin-top: 18px;
}

.ce-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 10px 22px;
	font: inherit;
	font-size: 1rem;
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none;
	border-radius: var(--_radius);
	border: 2px solid transparent;
	cursor: pointer;
}

.ce-btn--primary { color: #fff; background: var(--_primary); border-color: var(--_primary); }
.ce-btn--primary:hover { background: var(--_primary-dark); border-color: var(--_primary-dark); }
.ce-btn--secondary { color: var(--_text); background: var(--_bg); border-color: #8a96a8; }
.ce-btn--secondary:hover { background: var(--_surface); }
.ce-btn--ghost { margin-top: 10px; min-height: 40px; padding: 8px 14px; font-size: .9375rem; color: var(--_primary); background: transparent; border: 1px dashed var(--_primary); }
.ce-btn--ghost:disabled { opacity: .45; cursor: not-allowed; }
.ce-btn:focus-visible,
.ce-row-remove:focus-visible { outline: 3px solid var(--_focus); outline-offset: 2px; }

.ce-noscript { margin: 12px 0 0; color: var(--_error); }
.ce-admin-warning { padding: 12px; color: var(--_error); border: 1px solid var(--_error); }

/* ---------- Result ---------- */
.ce-result {
	min-width: 0;
	padding: 18px;
	background: var(--_surface);
	border: 1px solid var(--_border);
	border-radius: var(--_radius);
	scroll-margin-top: 80px;
}

.ce-result.is-empty { display: flex; align-items: center; justify-content: center; min-height: 120px; }
.ce-result-placeholder { margin: 0; text-align: center; color: var(--_muted); }
.ce-result.is-error { border-color: var(--_error); background: #fdf3f2; }
.ce-result-error { margin: 0; color: var(--_error); font-weight: 600; }

.ce-result-title {
	margin: 0 0 12px;
	font-size: .8125rem;
	font-weight: 700;
	letter-spacing: .06em;
	text-transform: uppercase;
	color: var(--_muted);
}

.ce-summary {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
	gap: 10px;
	margin-bottom: 14px;
}

.ce-stat {
	display: flex;
	flex-direction: column;
	gap: 2px;
	padding: 10px 12px;
	background: var(--_bg);
	border: 1px solid var(--_border);
	border-radius: var(--_radius);
	min-width: 0;
}

.ce-stat--primary {
	grid-column: 1 / -1;
	background: var(--_primary-soft);
	border-color: transparent;
	border-left: 4px solid var(--_primary);
}

.ce-stat-label { font-size: .875rem; color: var(--_muted); line-height: 1.35; }
.ce-stat-value { font-size: 1.25rem; font-weight: 700; line-height: 1.25; color: var(--_text); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.ce-stat--primary .ce-stat-value { font-size: 1.875rem; color: var(--_primary-dark); }
.ce-stat-sub { font-size: .875rem; color: var(--_muted); }

.ce-kv {
	width: 100%;
	margin: 0 0 12px;
	border-collapse: collapse;
	font-size: .9375rem;
}

.ce-kv th,
.ce-kv td {
	padding: 8px 0;
	border-bottom: 1px solid var(--_border);
	vertical-align: top;
}

.ce-kv th { font-weight: 400; text-align: left; color: var(--_muted); padding-right: 12px; }
.ce-kv td { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ce-kv tr.is-strong th,
.ce-kv tr.is-strong td { color: var(--_text); font-weight: 700; }

/* Proportion bar */
.ce-bar-wrap { margin: 0 0 14px; }
.ce-bar {
	display: flex;
	height: 14px;
	overflow: hidden;
	background: var(--_border);
	border-radius: 7px;
}
.ce-bar-seg { display: block; height: 100%; }
.ce-bar-seg--0, .ce-bar-key--0 .ce-bar-swatch { background: #1a5fb4; }
.ce-bar-seg--1, .ce-bar-key--1 .ce-bar-swatch { background: #e07b24; }
.ce-bar-seg--2, .ce-bar-key--2 .ce-bar-swatch { background: #2b8a57; }
.ce-bar-seg--3, .ce-bar-key--3 .ce-bar-swatch { background: #7b4fb0; }
.ce-bar-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 0; padding: 0; list-style: none; font-size: .8125rem; color: var(--_muted); }
.ce-bar-key { display: inline-flex; align-items: center; gap: 6px; }
.ce-bar-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }

/* Tables & working */
.ce-table-wrap,
.ce-steps-wrap {
	margin: 12px 0 0;
	background: var(--_bg);
	border: 1px solid var(--_border);
	border-radius: var(--_radius);
}

.ce-table-wrap > summary,
.ce-steps-wrap > summary {
	padding: 10px 12px;
	font-weight: 600;
	color: var(--_primary-dark);
	cursor: pointer;
}

.ce-table-wrap > summary:focus-visible,
.ce-steps-wrap > summary:focus-visible { outline: 3px solid var(--_focus); outline-offset: -3px; }

.ce-table-scroll { overflow-x: auto; max-height: 460px; overflow-y: auto; }
.ce-table-scroll:focus-visible { outline: 3px solid var(--_focus); }

.ce-table {
	width: 100%;
	border-collapse: collapse;
	font-size: .875rem;
	font-variant-numeric: tabular-nums;
}

.ce-table th,
.ce-table td {
	padding: 7px 10px;
	text-align: right;
	white-space: nowrap;
	border-top: 1px solid var(--_border);
}

.ce-table thead th {
	position: sticky;
	top: 0;
	font-weight: 600;
	color: var(--_text);
	background: var(--_surface);
	border-top: 0;
}

.ce-table tbody th { text-align: left; font-weight: 600; }
.ce-table thead th:first-child { text-align: left; }
.ce-table tbody tr:nth-child(even) { background: #fafbfd; }

.ce-steps { margin: 0; padding: 4px 14px 12px 34px; font-size: .9375rem; }
.ce-steps li { margin: 4px 0; font-variant-numeric: tabular-nums; }

.ce-notes {
	margin: 14px 0 0;
	padding: 0 0 0 18px;
	font-size: .8125rem;
	line-height: 1.5;
	color: var(--_muted);
}
.ce-notes li { margin: 4px 0; }

/* ---------- Scientific calculator ---------- */
.ce-sci { max-width: 720px; }

.ce-sci-screen {
	padding: 12px 14px;
	background: #0f1b33;
	border-radius: var(--_radius);
	color: #fff;
}

.ce-sci-input {
	width: 100%;
	padding: 4px 0;
	font: 500 1.375rem/1.3 ui-monospace, "SFMono-Regular", Consolas, monospace;
	color: #fff;
	text-align: right;
	background: transparent;
	border: 0;
	box-sizing: border-box;
}

.ce-sci-input:focus { outline: 2px solid #7fb2ff; outline-offset: 2px; }
.ce-sci-input::placeholder { color: #9fb0cc; }

.ce-sci-output {
	display: block;
	min-height: 1.6em;
	font: 700 1.75rem/1.3 ui-monospace, "SFMono-Regular", Consolas, monospace;
	text-align: right;
	overflow-wrap: anywhere;
}

.ce-sci-output.is-error { font-size: 1rem; font-weight: 600; color: #ffb4ab; }

.ce-sci-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 16px; }
.ce-sci-bar .ce-help { margin: 0; }
.ce-sci-angle { display: flex; gap: 14px; margin: 0; padding: 0; border: 0; font-size: .9375rem; }
.ce-sci-angle label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }

.ce-sci-keys { display: grid; gap: 10px; }
@media (min-width: 640px) { .ce-sci-keys { grid-template-columns: minmax(0, 5fr) minmax(0, 4fr); } }

.ce-sci-fn { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.ce-sci-pad { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }

.ce-key {
	min-height: 46px;
	padding: 6px 2px;
	font: inherit;
	font-size: 1.0625rem;
	font-weight: 600;
	color: var(--_text);
	background: var(--_bg);
	border: 1px solid var(--_border);
	border-radius: var(--_radius);
	cursor: pointer;
	touch-action: manipulation;
}

.ce-key:hover { background: var(--_surface); }
.ce-key:active { transform: translateY(1px); }
.ce-key:focus-visible { outline: 3px solid var(--_focus); outline-offset: 1px; }
.ce-key--fn { font-size: .9375rem; font-weight: 500; background: var(--_surface); }
.ce-key--op { color: var(--_primary-dark); background: var(--_primary-soft); }
.ce-key--clear { color: var(--_error); }
.ce-key--eq { color: #fff; background: var(--_primary); border-color: var(--_primary); }
.ce-key--eq:hover { background: var(--_primary-dark); }

.ce-sci-history-wrap { border-top: 1px solid var(--_border); padding-top: 10px; }
.ce-sci-history-title { margin: 0 0 6px; font-size: .875rem; color: var(--_muted); }
.ce-sci-history { margin: 0; padding: 0; list-style: none; }
.ce-sci-history:empty::after { content: "Your calculations will appear here."; font-size: .875rem; color: var(--_muted); }
.ce-sci-hist-item { display: block; width: 100%; padding: 4px 0; font: .9375rem ui-monospace, Consolas, monospace; text-align: left; color: var(--_primary-dark); background: none; border: 0; cursor: pointer; overflow-wrap: anywhere; }
.ce-sci-hist-item:hover { text-decoration: underline; }

/* ---------- Contact form ---------- */
.ce-contact-form { display: grid; gap: 14px; max-width: 560px; }
.ce-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; overflow: hidden; }
.ce-alert { padding: 12px 14px; border-radius: var(--_radius); font-weight: 600; }
.ce-alert--success { color: var(--_success); background: #eaf6ef; border: 1px solid var(--_success); }
.ce-alert--error { color: var(--_error); background: #fdf3f2; border: 1px solid var(--_error); }

/* ---------- Ads ---------- */
.ce-ad { margin: 24px 0; min-height: 100px; text-align: center; }
.ce-ad-label { display: block; margin-bottom: 4px; font-size: .6875rem; letter-spacing: .08em; text-transform: uppercase; color: var(--cuk-muted, #4f5d75); }

.screen-reader-text {
	position: absolute !important;
	width: 1px; height: 1px;
	padding: 0; margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* ==========================================================================
   1.2.0 – panel form with inline labels, result box with header bar
   ========================================================================== */
.ce-calculator { padding: 0; gap: 18px; background: transparent; border: 0; box-shadow: none; }
@media (min-width: 1100px) { .ce-calculator:not(.ce-sci) { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

.ce-form {
	padding: 14px 16px 16px;
	background: #eef2f7;
	border: 1px solid #c3cedc;
	border-radius: var(--_radius);
}
.ce-fields { gap: 10px 12px; }

/* Label to the left of the input on wider screens. */
@media (min-width: 560px) {
	.ce-form .ce-fields { grid-template-columns: minmax(0, 1fr); }
	.ce-form .ce-field--number,
	.ce-form .ce-field--select,
	.ce-form .ce-field--date,
	.ce-form .ce-field--text {
		display: grid;
		grid-template-columns: minmax(0, 9fr) minmax(0, 11fr);
		column-gap: 12px;
		align-items: center;
	}
	.ce-form .ce-field--number[hidden],
	.ce-form .ce-field--select[hidden],
	.ce-form .ce-field--date[hidden],
	.ce-form .ce-field--text[hidden] { display: none; }
	.ce-form .ce-field--number > .ce-label,
	.ce-form .ce-field--select > .ce-label,
	.ce-form .ce-field--date > .ce-label,
	.ce-form .ce-field--text > .ce-label { margin: 0; font-size: .9rem; }
	.ce-form .ce-field > .ce-help,
	.ce-form .ce-field > .ce-error { grid-column: 2; }
}
.ce-input, .ce-select { min-height: 40px; padding: 7px 10px; }
.ce-select { padding-right: 32px; }
.ce-affix { padding: 0 8px; background: #e2e8f0; }
.ce-segment span { min-height: 38px; padding: 8px 10px; font-size: .9rem; }
.ce-row { background: #fff; border: 1px solid #d5dce6; }

.ce-actions { margin-top: 14px; gap: 8px; }
.ce-btn--primary::before { content: ""; display: inline-block; margin-right: 8px; border-style: solid; border-width: 5px 0 5px 8px; border-color: transparent transparent transparent currentColor; }
.ce-btn--secondary { background: #e2e8f0; border-color: #c3cedc; }
.ce-btn--secondary:hover { background: #d5dde8; }

/* Result: header bar + white body */
.ce-result { padding: 0 14px 14px; background: #fff; border: 1px solid #c3cedc; overflow: hidden; }
.ce-result-title {
	margin: 0 -14px 12px;
	padding: 8px 14px;
	font-size: 1rem;
	letter-spacing: 0;
	text-transform: none;
	color: #fff;
	background: var(--cuk-navy, #14213d);
}
.ce-result.is-error .ce-result-title { background: var(--_error); }
.ce-result.is-empty { padding: 14px; background: #f8fafc; }
.ce-stat--primary { background: #eaf3ff; }
.ce-summary { gap: 8px; }
.ce-stat { padding: 8px 10px; }
.ce-kv th, .ce-kv td { padding: 6px 0; }

/* Scientific calculator keeps its own card look */
.ce-sci { padding: 14px; background: #fff; border: 1px solid #c3cedc; border-radius: calc(var(--_radius) + 2px); }

@media print {
	.ce-actions, .ce-sci-keys, .ce-ad { display: none !important; }
	.ce-calculator { box-shadow: none; }
}
