/**
 * ESOP Wealth Calculator — front-end styles.
 *
 * Every themeable value is read from a CSS custom property. Those properties
 * are printed inline by Esop_Calc_Assets::build_css_vars(), so this file is
 * static and cacheable no matter how the colours are configured. The
 * fallbacks after each var() are what you get if the inline block is ever
 * missing (for example if a caching plugin strips it).
 *
 * @package Esop_Calculator
 */

.esop-calc-wrapper {
	display: flex;
	flex-wrap: wrap;
	gap: 25px;
	box-sizing: border-box;
	max-width: var( --esop-max-width, 1000px );
	margin: 20px auto;
	padding: 0;
	background: var( --esop-page-bg, transparent );
	color: var( --esop-text, #333 );
	font-family: var( --esop-font, inherit );
	line-height: 1.5;
}

.esop-calc-wrapper *,
.esop-calc-wrapper *::before,
.esop-calc-wrapper *::after {
	box-sizing: inherit;
}

.esop-calc-panel {
	flex: 1 1 320px;
	min-width: 0; /* Lets flex children shrink below their content width. */
	padding: 25px;
	border-radius: var( --esop-radius, 12px );
	background: var( --esop-card-bg, #fff );
	box-shadow: var( --esop-shadow, 0 4px 20px rgba( 0, 0, 0, 0.08 ) );
}

.esop-chart-panel {
	display: flex;
	flex-direction: column;
	justify-content: center;
	min-height: 400px;
}

/* -------------------------------------------------------------------------
 * Typography
 * ---------------------------------------------------------------------- */

.esop-calc-wrapper .esop-calc-title {
	margin: 0 0 20px;
	color: var( --esop-heading, #111 );
	font-size: 22px;
	font-weight: 700;
	line-height: 1.3;
	text-align: center;
}

.esop-calc-wrapper .esop-section-title {
	margin: 20px 0 12px;
	padding-bottom: 6px;
	border-bottom: 1px dashed var( --esop-divider, #e1e0d9 );
	color: var( --esop-accent, #0073aa );
	font-size: 13px;
	font-weight: 700;
	letter-spacing: 0.5px;
	text-transform: uppercase;
}

.esop-calc-wrapper .esop-section-title:first-child {
	margin-top: 0;
}

/* -------------------------------------------------------------------------
 * Form
 * ---------------------------------------------------------------------- */

.esop-form-grid {
	display: grid;
	grid-template-columns: repeat( 2, minmax( 0, 1fr ) );
	gap: 15px;
}

.esop-form-group.esop-full-width {
	grid-column: 1 / -1;
}

.esop-calc-wrapper .esop-form-group label {
	display: block;
	margin-bottom: 6px;
	color: var( --esop-label, #444 );
	font-size: 13px;
	font-weight: 600;
}

.esop-calc-wrapper .esop-form-group input {
	display: block;
	width: 100%;
	max-width: 100%;
	margin: 0;
	padding: 10px;
	border: 1px solid var( --esop-field-border, #ccc );
	border-radius: 6px;
	background: var( --esop-field-bg, #fff );
	color: var( --esop-field-text, #333 );
	font-family: inherit;
	font-size: 15px;
	line-height: 1.4;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.esop-calc-wrapper .esop-form-group input:focus {
	border-color: var( --esop-accent, #0073aa );
	outline: 2px solid transparent; /* Kept for Windows high-contrast mode. */
	outline-offset: 2px;
	box-shadow: 0 0 0 3px color-mix( in srgb, var( --esop-accent, #0073aa ) 30%, transparent );
}

.esop-calc-wrapper .esop-form-group input[aria-invalid="true"] {
	border-color: #d03b3b;
}

.esop-calc-wrapper .esop-calc-btn {
	display: block;
	width: 100%;
	margin-top: 18px;
	padding: 14px;
	border: 1px solid transparent;
	border-radius: 6px;
	background: var( --esop-btn-bg, #0073aa );
	color: var( --esop-btn-text, #fff );
	font-family: inherit;
	font-size: 16px;
	font-weight: 700;
	line-height: 1.2;
	text-align: center;
	cursor: pointer;
	transition: background-color 0.15s ease;
}

.esop-calc-wrapper .esop-calc-btn:hover,
.esop-calc-wrapper .esop-calc-btn:focus {
	background: var( --esop-btn-hover, #005177 );
	color: var( --esop-btn-text, #fff );
}

.esop-calc-wrapper .esop-calc-btn:focus-visible {
	outline: 2px solid var( --esop-accent, #0073aa );
	outline-offset: 2px;
}

.esop-calc-error {
	margin: 12px 0 0;
	color: #b32020;
	font-size: 14px;
	font-weight: 600;
}

/* -------------------------------------------------------------------------
 * Results
 * ---------------------------------------------------------------------- */

.esop-results {
	margin-top: 25px;
	padding-top: 20px;
	border-top: 2px solid var( --esop-divider, #e1e0d9 );
}

.esop-result-list {
	margin: 0;
	padding: 0;
}

.esop-result-row {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 16px;
	margin: 0 0 12px;
	font-size: 15px;
}

.esop-calc-wrapper .esop-result-row dt {
	margin: 0;
	color: var( --esop-text, #333 );
	font-weight: 400;
}

.esop-calc-wrapper .esop-result-row dd {
	margin: 0;
	color: var( --esop-heading, #111 );
	font-weight: 600;
	/* Tabular figures keep the currency columns aligned as values change. */
	font-variant-numeric: tabular-nums;
	text-align: right;
}

.esop-result-row.esop-result-total {
	margin-top: 4px;
	padding-top: 12px;
	border-top: 1px solid var( --esop-divider, #e1e0d9 );
	font-size: 18px;
}

.esop-calc-wrapper .esop-result-total dt,
.esop-calc-wrapper .esop-result-total dd {
	font-weight: 700;
}

.esop-calc-wrapper .esop-result-total dd {
	color: var( --esop-total, #006300 );
}

.esop-calc-disclaimer {
	margin: 18px 0 0;
	color: var( --esop-text, #333 );
	font-size: 12px;
	line-height: 1.5;
	opacity: 0.75;
}

/* -------------------------------------------------------------------------
 * Chart
 * ---------------------------------------------------------------------- */

.esop-chart-placeholder {
	margin: 0;
	color: var( --esop-text, #333 );
	font-style: italic;
	text-align: center;
	opacity: 0.7;
}

.esop-chart-holder {
	display: flex;
	/* Grows to fill the panel once it is revealed, so the rendered chart
	   sits flush rather than floating in the middle of a tall panel. The
	   placeholder, being shorter, stays centred by the panel itself. */
	flex: 1 1 auto;
	flex-direction: column;
	width: 100%;
}

.esop-canvas-wrap {
	position: relative;
	flex: 1 1 auto;
	width: 100%;
	/* Chart.js sizes its canvas to this box. It needs a bounded height from
	   somewhere or the canvas grows on every redraw; the flex parent supplies
	   it, and min-height covers the case where the panel is short. */
	min-height: 300px;
}

.esop-chart-legend {
	display: flex;
	flex-wrap: wrap;
	gap: 8px 18px;
	margin: 0 0 14px;
	padding: 0;
	list-style: none;
}

.esop-calc-wrapper .esop-chart-legend li {
	display: flex;
	align-items: center;
	gap: 7px;
	margin: 0;
	color: var( --esop-text, #333 );
	font-size: 13px;
}

.esop-legend-key {
	display: inline-block;
	flex: 0 0 auto;
	width: 12px;
	height: 3px;
	border-radius: 2px;
}

.esop-table-toggle {
	align-self: flex-start;
	margin-top: 14px;
	padding: 0;
	border: 0;
	background: none;
	color: var( --esop-accent, #0073aa );
	font-family: inherit;
	font-size: 13px;
	font-weight: 600;
	text-decoration: underline;
	cursor: pointer;
}

.esop-table-wrap {
	max-height: 260px;
	margin-top: 12px;
	overflow: auto;
}

.esop-calc-wrapper .esop-table-wrap table {
	width: 100%;
	border-collapse: collapse;
	font-size: 13px;
	font-variant-numeric: tabular-nums;
}

.esop-calc-wrapper .esop-table-wrap caption {
	margin-bottom: 8px;
	color: var( --esop-text, #333 );
	font-size: 12px;
	text-align: left;
}

.esop-calc-wrapper .esop-table-wrap th,
.esop-calc-wrapper .esop-table-wrap td {
	padding: 6px 8px;
	border-bottom: 1px solid var( --esop-divider, #e1e0d9 );
	text-align: right;
}

.esop-calc-wrapper .esop-table-wrap th:first-child,
.esop-calc-wrapper .esop-table-wrap td:first-child {
	text-align: left;
}

.esop-calc-wrapper .esop-table-wrap thead th {
	position: sticky;
	top: 0;
	background: var( --esop-card-bg, #fff );
	color: var( --esop-heading, #111 );
}

/* -------------------------------------------------------------------------
 * Responsive
 * ---------------------------------------------------------------------- */

@media ( max-width: 640px ) {

	.esop-form-grid {
		grid-template-columns: minmax( 0, 1fr );
	}

	.esop-form-group.esop-full-width {
		grid-column: auto;
	}

	.esop-calc-panel {
		padding: 20px;
	}

	/* On a phone the panels stack, so the chart panel no longer needs to
	   match the height of the form beside it. */
	.esop-chart-panel {
		min-height: 0;
	}

	.esop-canvas-wrap {
		min-height: 240px;
		max-height: 300px;
	}
}

/* Respect a visitor's reduced-motion preference. */
@media ( prefers-reduced-motion: reduce ) {

	.esop-calc-wrapper *,
	.esop-calc-wrapper *::before,
	.esop-calc-wrapper *::after {
		transition-duration: 0.01ms !important;
		animation-duration: 0.01ms !important;
	}
}
