/*
 * calculator.css — the shared calculator shell: input panel, results panel,
 * breakdown tables, and the bracket visualisation.
 *
 * Layout intent: on a wide screen the form sits left and the results stay
 * pinned on the right so a change and its effect are visible together. Below
 * 960px the results move ABOVE the form's fold via order, because on a phone
 * the answer is what the user came for and scrolling back up to find it is the
 * main usability failure of two-column calculators.
 */

/* ---------- page head ---------- */

.calc-head {
	padding: var(--sp-4) 0 0;
}
.calc-head h1 {
	margin-bottom: var(--sp-3);
}

/* ---------- the two-panel shell ---------- */

.calc-shell {
	display: grid;
	grid-template-columns: minmax(0, 1fr) minmax(340px, 400px);
	gap: var(--sp-5);
	align-items: start;
	margin-bottom: var(--sp-6);
}

@media (max-width: 960px) {
	.calc-shell {
		grid-template-columns: minmax(0, 1fr);
	}
	.calc-results {
		order: -1;
	}
}

.calc-form-panel,
.calc-results {
	background: var(--c-surface);
	border: 1px solid var(--c-line);
	border-radius: var(--r-lg);
	box-shadow: var(--shadow-sm);
}

.calc-form-panel {
	padding: var(--sp-5);
}

.calc-results {
	padding: var(--sp-5);
	position: sticky;
	top: calc(var(--header-h) + var(--sp-4));
}
@media (max-width: 960px) {
	.calc-results {
		position: static;
	}
}

/* ---------- form structure ---------- */

.field-group {
	border: 0;
	margin: 0 0 var(--sp-5);
	padding: 0;
}
.field-group:last-of-type {
	margin-bottom: var(--sp-4);
}

.field-group > legend {
	font-size: 0.78rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--c-ink-faint);
	padding: 0 0 var(--sp-3);
	margin: 0;
	width: 100%;
	border-bottom: 1px solid var(--c-line);
}

.field-rows {
	padding-top: var(--sp-4);
	display: grid;
	gap: var(--sp-4);
}
.field-rows.two-up {
	grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.field {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	min-width: 0;
}

.field label {
	font-size: 0.9rem;
	font-weight: 550;
	color: var(--c-ink);
	line-height: 1.35;
}

.field .optional {
	font-weight: 400;
	color: var(--c-ink-faint);
	font-size: 0.82rem;
}

.field .hint {
	font-size: 0.8rem;
	color: var(--c-ink-soft);
	line-height: 1.45;
}

/* Currency and percent inputs get their symbol as a static adornment so the
   value itself stays a clean number for copy/paste and for the parser. */
.input-shell {
	display: flex;
	align-items: stretch;
	border: 1px solid var(--c-line-strong);
	border-radius: var(--r-md);
	background: var(--c-surface);
	overflow: hidden;
}
.input-shell:focus-within {
	border-color: var(--c-focus);
	box-shadow: 0 0 0 3px rgba(28, 111, 184, 0.18);
}

.input-affix {
	display: flex;
	align-items: center;
	padding: 0 0.65rem;
	background: var(--c-canvas-alt);
	color: var(--c-ink-soft);
	font-size: 0.92rem;
	font-weight: 600;
	border-right: 1px solid var(--c-line);
	user-select: none;
}
.input-affix.suffix {
	border-right: 0;
	border-left: 1px solid var(--c-line);
}

.input-shell input {
	flex: 1 1 auto;
	min-width: 0;
	border: 0;
	background: transparent;
	padding: 0.6rem 0.7rem;
	font: inherit;
	font-size: 1rem;
	color: var(--c-ink);
	min-height: 44px;
	font-variant-numeric: tabular-nums;
	text-align: right;
}
.input-shell input:focus {
	outline: none;
}

/* Native controls that stand alone. */
.field select,
.field input[type="text"]:not(.input-shell input),
.field input[type="number"] {
	border: 1px solid var(--c-line-strong);
	border-radius: var(--r-md);
	padding: 0.6rem 0.7rem;
	font: inherit;
	font-size: 1rem;
	min-height: 44px;
	background: var(--c-surface);
	color: var(--c-ink);
	width: 100%;
}
.field select:focus-visible,
.field input:focus-visible {
	outline: 3px solid var(--c-focus);
	outline-offset: 1px;
}

.field-checkbox {
	flex-direction: row;
	align-items: flex-start;
	gap: 0.6rem;
}
.field-checkbox input[type="checkbox"] {
	width: 20px;
	height: 20px;
	margin-top: 0.15rem;
	flex-shrink: 0;
	accent-color: var(--c-brand);
}
.field-checkbox label {
	font-weight: 450;
}

/* Segmented control for two- or three-way mode switches. */
.segmented {
	display: inline-flex;
	border: 1px solid var(--c-line-strong);
	border-radius: var(--r-md);
	overflow: hidden;
	background: var(--c-canvas-alt);
}
.segmented input[type="radio"] {
	position: absolute;
	opacity: 0;
	pointer-events: none;
}
.segmented label {
	padding: 0.6rem 1rem;
	font-size: 0.9rem;
	font-weight: 550;
	color: var(--c-ink-soft);
	cursor: pointer;
	min-height: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-right: 1px solid var(--c-line-strong);
}
.segmented label:last-of-type {
	border-right: 0;
}
.segmented input[type="radio"]:checked + label {
	background: var(--c-brand);
	color: #fff;
}
.segmented input[type="radio"]:focus-visible + label {
	outline: 3px solid var(--c-focus);
	outline-offset: -3px;
}

/* Validation. The message is tied to the input via aria-describedby, so a
   screen reader announces it when focus lands on the field. */
.field-error {
	font-size: 0.82rem;
	color: var(--c-negative);
	font-weight: 550;
}
.field.has-error .input-shell,
.field.has-error select,
.field.has-error input {
	border-color: var(--c-negative);
}
.field.has-warning .hint-warning {
	color: var(--c-accent);
	font-weight: 550;
}

.form-actions {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sp-3);
	align-items: center;
	padding-top: var(--sp-4);
	border-top: 1px solid var(--c-line);
}
.form-actions .btn-primary {
	flex: 1 1 auto;
	min-width: 160px;
}

/* ---------- results ---------- */

.result-headline {
	text-align: center;
	padding: var(--sp-4) var(--sp-3) var(--sp-5);
	border-radius: var(--r-md);
	background: var(--c-canvas-alt);
	margin-bottom: var(--sp-4);
}
.result-headline.is-refund {
	background: var(--c-positive-tint);
}
.result-headline.is-owed {
	background: var(--c-negative-tint);
}

.result-label {
	font-size: 0.83rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--c-ink-soft);
	margin-bottom: var(--sp-2);
}

.result-figure {
	font-size: clamp(2rem, 1.4rem + 2.6vw, 2.75rem);
	font-weight: 700;
	line-height: 1.05;
	letter-spacing: -0.03em;
	font-variant-numeric: tabular-nums;
	color: var(--c-ink);
}
.result-headline.is-refund .result-figure {
	color: var(--c-positive);
}
.result-headline.is-owed .result-figure {
	color: var(--c-negative);
}

.result-sub {
	font-size: 0.88rem;
	color: var(--c-ink-soft);
	margin-top: var(--sp-2);
}

/* Secondary figures shown as a compact stat row. */
.stat-row {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
	gap: var(--sp-3);
	margin-bottom: var(--sp-4);
}
.stat {
	background: var(--c-canvas);
	border: 1px solid var(--c-line);
	border-radius: var(--r-md);
	padding: var(--sp-3);
	text-align: center;
}
.stat-value {
	font-size: 1.2rem;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	letter-spacing: -0.02em;
	color: var(--c-brand-deep);
	line-height: 1.2;
}
.stat-label {
	font-size: 0.76rem;
	color: var(--c-ink-soft);
	margin-top: 0.15rem;
	line-height: 1.3;
}

/* ---------- breakdown tables ---------- */

/* Every table scrolls inside its own container so a wide breakdown can never
   make the page itself scroll sideways on a phone. */
.table-scroll {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	margin-bottom: var(--sp-4);
	border: 1px solid var(--c-line);
	border-radius: var(--r-md);
}

table.breakdown {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.9rem;
	background: var(--c-surface);
}

table.breakdown caption {
	text-align: left;
	font-size: 0.78rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--c-ink-faint);
	padding: var(--sp-3) var(--sp-3) var(--sp-2);
}

table.breakdown th,
table.breakdown td {
	padding: 0.55rem 0.7rem;
	text-align: right;
	border-bottom: 1px solid var(--c-line);
	white-space: nowrap;
}
table.breakdown th:first-child,
table.breakdown td:first-child {
	text-align: left;
	white-space: normal;
	min-width: 150px;
}
table.breakdown thead th {
	background: var(--c-canvas-alt);
	font-size: 0.78rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--c-ink-soft);
	border-bottom: 1px solid var(--c-line-strong);
}
table.breakdown td {
	font-variant-numeric: tabular-nums;
}
table.breakdown tbody tr:last-child td {
	border-bottom: 0;
}
table.breakdown tr.is-total td,
table.breakdown tr.is-total th {
	font-weight: 700;
	background: var(--c-canvas);
	border-top: 2px solid var(--c-line-strong);
	color: var(--c-ink);
}
table.breakdown tr.is-subtle td {
	color: var(--c-ink-soft);
}
table.breakdown td.is-negative {
	color: var(--c-negative);
}

/* ---------- bracket visualisation ---------- */

/*
 * A pure-CSS stacked bar. It is decorative: the same numbers appear in the
 * adjacent table, which is the accessible source of truth, so the bar itself
 * is hidden from assistive technology.
 */
.bracket-bar {
	display: flex;
	width: 100%;
	height: 34px;
	border-radius: var(--r-sm);
	overflow: hidden;
	border: 1px solid var(--c-line-strong);
	margin-bottom: var(--sp-3);
	background: var(--c-canvas-alt);
}
.bracket-seg {
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 0.7rem;
	font-weight: 700;
	color: #fff;
	overflow: hidden;
	min-width: 0;
}
/* Six steps of one hue keep the ramp readable without becoming a rainbow. */
.bracket-seg[data-rate="0.1"] { background: #7fa8c4; }
.bracket-seg[data-rate="0.12"] { background: #5f8fb0; }
.bracket-seg[data-rate="0.22"] { background: #41769b; }
.bracket-seg[data-rate="0.24"] { background: #2b6086; }
.bracket-seg[data-rate="0.32"] { background: #1c4c70; }
.bracket-seg[data-rate="0.35"] { background: #133b59; }
.bracket-seg[data-rate="0.37"] { background: #0a2942; }
.bracket-seg[data-rate="0"] { background: #a9c4d6; color: var(--c-ink); }
.bracket-seg[data-rate="0.15"] { background: #41769b; }
.bracket-seg[data-rate="0.2"] { background: #1c4c70; }

/* ---------- result toolbar ---------- */

.result-tools {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sp-2);
	padding-top: var(--sp-3);
	border-top: 1px solid var(--c-line);
	margin-top: var(--sp-4);
}

.result-empty {
	text-align: center;
	color: var(--c-ink-soft);
	padding: var(--sp-6) var(--sp-3);
	font-size: 0.92rem;
}

/* Transient confirmation after copy / share. */
.toast {
	position: fixed;
	left: 50%;
	bottom: 24px;
	transform: translateX(-50%);
	background: var(--c-ink);
	color: #fff;
	padding: 0.7rem 1.1rem;
	border-radius: var(--r-md);
	font-size: 0.9rem;
	box-shadow: var(--shadow-md);
	z-index: 200;
}
.toast[hidden] {
	display: none;
}

/* ---------- assumptions / disclosure ---------- */

details.disclosure {
	border: 1px solid var(--c-line);
	border-radius: var(--r-md);
	background: var(--c-surface);
	margin-bottom: var(--sp-4);
}
details.disclosure > summary {
	cursor: pointer;
	padding: var(--sp-3) var(--sp-4);
	font-weight: 600;
	font-size: 0.93rem;
	color: var(--c-brand-deep);
	list-style-position: inside;
	min-height: 44px;
	display: flex;
	align-items: center;
}
details.disclosure > summary:hover {
	background: var(--c-brand-tint);
}
details.disclosure[open] > summary {
	border-bottom: 1px solid var(--c-line);
}
.disclosure-body {
	padding: var(--sp-4);
	font-size: 0.9rem;
}
.disclosure-body p:last-child,
.disclosure-body ul:last-child {
	margin-bottom: 0;
}

/* ---------- FAQ ---------- */

.faq-item {
	border-bottom: 1px solid var(--c-line);
	padding: var(--sp-4) 0;
}
.faq-item:last-child {
	border-bottom: 0;
}
.faq-item h3 {
	margin: 0 0 var(--sp-2);
	font-size: 1.02rem;
}
.faq-item p:last-child {
	margin-bottom: 0;
}

/* ---------- search ---------- */

.search-box {
	position: relative;
	max-width: 560px;
}
.search-box input[type="search"] {
	width: 100%;
	border: 1px solid var(--c-line-strong);
	border-radius: var(--r-md);
	padding: 0.75rem 1rem;
	font: inherit;
	font-size: 1rem;
	min-height: 48px;
	background: var(--c-surface);
	color: var(--c-ink);
}
.search-results {
	list-style: none;
	margin: var(--sp-3) 0 0;
	padding: 0;
}
.search-results li {
	margin: 0 0 var(--sp-2);
}
.search-results a {
	display: block;
	padding: var(--sp-3);
	border: 1px solid var(--c-line);
	border-radius: var(--r-md);
	background: var(--c-surface);
	text-decoration: none;
	color: inherit;
}
.search-results a:hover {
	border-color: var(--c-brand);
	background: var(--c-brand-tint);
	color: inherit;
}
.search-empty {
	color: var(--c-ink-soft);
	font-size: 0.92rem;
	padding: var(--sp-3) 0;
}

/* ---------- hero ---------- */

.hero {
	background: linear-gradient(168deg, var(--c-brand-deep) 0%, var(--c-brand) 62%, #17567f 100%);
	color: #fff;
	padding: var(--sp-7) 0;
	margin-bottom: var(--sp-6);
}
.hero h1 {
	color: #fff;
	max-width: 20ch;
}
.hero p {
	color: #d5e3ef;
	font-size: 1.08rem;
	max-width: 60ch;
}
.hero .search-box input[type="search"] {
	border-color: transparent;
}
.hero-actions {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sp-3);
	margin-top: var(--sp-5);
}
.hero .btn-secondary {
	background: rgba(255, 255, 255, 0.1);
	color: #fff;
	border-color: rgba(255, 255, 255, 0.45);
}
.hero .btn-secondary:hover {
	background: rgba(255, 255, 255, 0.2);
	color: #fff;
	border-color: #fff;
}
.hero .btn-primary {
	background: #fff;
	color: var(--c-brand-deep);
	border-color: #fff;
}
.hero .btn-primary:hover {
	background: var(--c-brand-tint);
	color: var(--c-brand-deep);
	border-color: var(--c-brand-tint);
}
