/*
 * Tools, deck pages and templates (/tools/, /decks/, /templates/).
 * Everything is scoped under .tool, .deck-page, .tpl or .sp-print-root, and uses only the tokens of tokens.css.
 */

/* ---------- Shared pieces ---------- */
.tool,
.deck-page,
.tpl {
	font-family: var(--font);
	color: var(--ink);
	font-variant-numeric: lining-nums tabular-nums;
	margin: var(--s-5) 0 var(--s-7);
	max-width: 100%;
}
.tool *,
.deck-page *,
.tpl * {
	box-sizing: border-box;
}
.tool [hidden],
.tpl [hidden] {
	display: none !important;
}

.tool .tl-panel,
.tpl .tl-panel {
	background: var(--surface);
	border-radius: var(--r-lg);
	padding: var(--s-5);
}
.tool .tl-panel + .tl-panel {
	margin-top: var(--s-4);
}
.tool .tl-title,
.tpl .tl-title {
	font-family: var(--font-display);
	font-weight: 700;
	font-size: var(--t-lg);
	letter-spacing: -0.02em;
	line-height: 1.2;
	margin: 0 0 var(--s-4);
	color: var(--ink);
}
.tool .tl-note {
	font-size: var(--t-sm);
	color: var(--ink-3);
	line-height: 1.5;
	margin: var(--s-3) 0 0;
}

/* Secondary button: own fallback, does not depend on site.css */
.tool .tl-btn,
.tpl .tl-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--s-2);
	min-height: 44px;
	padding: 0 var(--s-4);
	font: inherit;
	font-size: var(--t-base);
	font-weight: 600;
	color: var(--ink);
	background: var(--surface);
	border: 1px solid var(--line-strong);
	border-radius: var(--r-pill);
	cursor: pointer;
	transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.tool .tl-btn:hover,
.tpl .tl-btn:hover {
	background: var(--surface-2);
	border-color: var(--ink-3);
}
.tool .tl-btn-primary,
.tpl .tl-btn-primary {
	color: var(--on-accent);
	background: var(--accent);
	border-color: var(--accent);
}
.tool .tl-btn-primary:hover,
.tpl .tl-btn-primary:hover {
	background: var(--accent-hover);
	border-color: var(--accent-hover);
}
.tool .tl-btn-quiet {
	min-height: 44px;
	min-width: 44px;
	padding: 0 var(--s-3);
	color: var(--ink-2);
	background: transparent;
	border-color: transparent;
	font-weight: 500;
}
.tool .tl-btn-quiet:hover {
	color: var(--danger);
	background: var(--danger-soft);
	border-color: transparent;
}
.tool :focus-visible,
.tpl :focus-visible,
.deck-page :focus-visible {
	outline: 2px solid var(--focus);
	outline-offset: 2px;
}

/* ---------- Form layout ---------- */
.tool .tl-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
	gap: var(--s-4);
	align-items: start;
}
.tool .tl-field {
	display: flex;
	flex-direction: column;
	gap: 6px;
	min-width: 0;
}
.tool .tl-field-wide {
	grid-column: 1 / -1;
}
.tool .tl-grid-lead {
	grid-template-columns: minmax(0, 280px);
	margin-bottom: var(--s-5);
}
.tool label,
.tool .tl-label {
	font-size: var(--t-sm);
	font-weight: 600;
	color: var(--ink-2);
}
.tool .tl-hint {
	font-size: var(--t-xs);
	color: var(--ink-3);
	line-height: 1.45;
}
.tool input[type="text"],
.tool input[type="number"],
.tool input[type="date"],
.tool select {
	width: 100%;
	min-height: 44px;
	padding: 0 var(--s-3);
	font: inherit;
	font-size: 1rem;
	color: var(--ink);
	background: var(--bg);
	border: 1px solid var(--line-strong);
	border-radius: var(--r-sm);
	font-variant-numeric: lining-nums tabular-nums;
}
.tool input:hover,
.tool select:hover {
	border-color: var(--ink-3);
}
.tool input[aria-invalid="true"] {
	border-color: var(--danger);
}
.tool .tl-checks {
	display: flex;
	flex-wrap: wrap;
	gap: var(--s-2) var(--s-5);
}
.tool .tl-check {
	display: inline-flex;
	align-items: center;
	gap: var(--s-2);
	min-height: 44px;
	font-size: var(--t-base);
	font-weight: 500;
	color: var(--ink);
	cursor: pointer;
}
.tool .tl-check input {
	width: 18px;
	height: 18px;
	accent-color: var(--accent);
}
.tool .tl-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--s-3);
	margin-top: var(--s-5);
}
.tool .tl-error {
	color: var(--danger);
	font-size: var(--t-sm);
	font-weight: 500;
	margin: var(--s-3) 0 0;
}

/* ---------- Results ---------- */
.tool .tl-results {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
	gap: var(--s-4) var(--s-5);
	margin: 0;
}
.tool .tl-stat {
	margin: 0;
	padding-top: var(--s-3);
	border-top: 1px solid var(--line);
	min-width: 0;
}
.tool .tl-stat dt {
	font-size: var(--t-sm);
	font-weight: 600;
	color: var(--ink-2);
}
.tool .tl-stat dd {
	margin: 4px 0 0;
	font-family: var(--font-display);
	font-weight: 700;
	font-size: clamp(1.75rem, 5vw, 2.5rem);
	letter-spacing: -0.02em;
	line-height: 1.1;
	color: var(--ink);
	overflow-wrap: anywhere;
}
.tool .tl-stat dd small {
	display: block;
	margin-top: 4px;
	font-family: var(--font);
	font-size: var(--t-sm);
	font-weight: 500;
	letter-spacing: 0;
	line-height: 1.4;
	color: var(--ink-3);
}
.tool .tl-stat-key {
	padding: var(--s-3) var(--s-4);
	border-top: 0;
	border-radius: var(--r);
	background: var(--tint-green);
}
.tool .tl-stat-key dd {
	color: var(--on-tint-green);
}
.tool .tl-formula {
	margin: var(--s-5) 0 0;
	padding: var(--s-3) var(--s-4);
	background: var(--surface-2);
	border: 1px solid var(--line);
	border-radius: var(--r-sm);
	font-size: var(--t-sm);
	line-height: 1.6;
	color: var(--ink-2);
}
.tool .tl-formula strong {
	color: var(--ink);
}

/* ---------- Capacity: member rows ---------- */
.tool .tl-rows {
	display: grid;
	gap: var(--s-3);
	margin: 0 0 var(--s-4);
	padding: 0;
	list-style: none;
}
.tool .tl-row {
	display: grid;
	grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr)) 44px;
	gap: var(--s-3);
	align-items: end;
	margin: 0;
	padding: 0;
	border: 0;
	min-width: 0;
}
.tool .tl-row legend {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}
.tool .tl-row .tl-btn-quiet {
	padding: 0;
	font-size: 1.25rem;
	line-height: 1;
}
@media (min-width: 641px) {
	/* On wide screens the column labels are shown once, on the first row */
	.tool .tl-rows li + li label {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(0 0 0 0);
		white-space: nowrap;
	}
}
@media (max-width: 640px) {
	.tool .tl-panel,
	.tpl .tl-panel {
		padding: var(--s-4);
	}
	.tool .tl-row {
		grid-template-columns: repeat(3, minmax(0, 1fr));
		padding-bottom: var(--s-3);
		border-bottom: 1px solid var(--line);
	}
	.tool .tl-row .tl-field-name {
		grid-column: 1 / 3;
	}
	.tool .tl-row .tl-btn-quiet {
		grid-column: 3;
		grid-row: 1;
		justify-self: end;
	}
}

/* ---------- Forecast: table and chart ---------- */
.tool .tl-table {
	width: 100%;
	border-collapse: collapse;
	margin: var(--s-5) 0 0;
	font-size: var(--t-base);
}
.tool .tl-table caption {
	text-align: left;
	font-size: var(--t-sm);
	color: var(--ink-3);
	padding-bottom: var(--s-2);
}
.tool .tl-table th,
.tool .tl-table td {
	padding: var(--s-3) var(--s-2) var(--s-3) 0;
	text-align: left;
	border-top: 1px solid var(--line);
	vertical-align: baseline;
}
.tool .tl-table thead th {
	border-top: 0;
	font-size: var(--t-sm);
	font-weight: 600;
	color: var(--ink-2);
}
.tool .tl-table tbody th {
	font-weight: 600;
}
.tool .tl-table tbody th small {
	display: block;
	font-weight: 400;
	font-size: var(--t-xs);
	color: var(--ink-3);
}
.tool .tl-table td.tl-big {
	font-family: var(--font-display);
	font-weight: 700;
	font-size: var(--t-xl);
	letter-spacing: -0.02em;
	line-height: 1.1;
}
.tool .tl-table tr.tl-likely td.tl-big {
	color: var(--accent);
}
.tool .tl-chart {
	display: block;
	width: 100%;
	height: auto;
	margin-top: var(--s-5);
	font-family: var(--font);
}
.tool .tl-chart .c-bar {
	fill: var(--chart-1);
}
.tool .tl-chart .c-axis {
	stroke: var(--line-strong);
	stroke-width: 1;
}
.tool .tl-chart .c-text {
	fill: var(--ink-2);
	font-size: 12px;
}
.tool .tl-chart .c-val-in {
	fill: var(--card);
	font-size: 12px;
	font-weight: 600;
}
.tool .tl-chart .c-val {
	fill: var(--ink);
	font-size: 12px;
	font-weight: 600;
}
.tool .tl-chart .c-line {
	stroke-width: 1.5;
	fill: none;
}
.tool .tl-chart .c-mean {
	stroke: var(--ink);
}
.tool .tl-chart .c-best {
	stroke: var(--on-tint-green);
	stroke-dasharray: 6 4;
}
.tool .tl-chart .c-worst {
	stroke: var(--on-tint-violet);
	stroke-dasharray: 2 4;
}
.tool .tl-legend {
	display: flex;
	flex-wrap: wrap;
	gap: var(--s-2) var(--s-5);
	margin: var(--s-3) 0 0;
	padding: 0;
	list-style: none;
	font-size: var(--t-sm);
	color: var(--ink-2);
}
.tool .tl-legend li {
	display: inline-flex;
	align-items: center;
	gap: var(--s-2);
	margin: 0;
	padding: 0;
}
.tool .tl-legend i {
	display: inline-block;
	width: 22px;
	border-top: 2px solid var(--ink);
}
.tool .tl-legend .l-bar {
	height: 10px;
	width: 10px;
	border: 0;
	border-radius: 2px;
	background: var(--chart-1);
}
.tool .tl-legend .l-best {
	border-top: 2px dashed var(--on-tint-green);
}
.tool .tl-legend .l-worst {
	border-top: 2px dotted var(--on-tint-violet);
}

/* ---------- The card (white face with a 2px navy outline, solid navy back) ---------- */
.tool .pcard,
.deck-page .pcard,
.sp-print-root .pcard {
	--w: 84px;
	position: relative;
	display: grid;
	place-items: center;
	flex: none;
	width: var(--w);
	aspect-ratio: 5 / 7;
	border-radius: calc(var(--w) * 0.16);
	background: var(--card);
	color: var(--ink-card);
	font-family: var(--font-display);
	font-variant-numeric: lining-nums tabular-nums;
	box-shadow: inset 0 0 0 2px var(--card-line);
}
.tool .pcard b,
.deck-page .pcard b,
.sp-print-root .pcard b {
	font-size: calc(var(--w) * 0.42);
	font-weight: 800;
	letter-spacing: -0.03em;
	line-height: 1;
}
.tool .pcard[data-len="3"] b,
.deck-page .pcard[data-len="3"] b,
.sp-print-root .pcard[data-len="3"] b {
	font-size: calc(var(--w) * 0.32);
}
.tool .pcard[data-len="4"] b,
.deck-page .pcard[data-len="4"] b,
.sp-print-root .pcard[data-len="4"] b {
	font-size: calc(var(--w) * 0.24);
}
.tool .pcard[data-len="5"] b,
.deck-page .pcard[data-len="5"] b,
.sp-print-root .pcard[data-len="5"] b {
	font-size: calc(var(--w) * 0.17);
	letter-spacing: -0.01em;
}
.tool .pcard i,
.deck-page .pcard i,
.sp-print-root .pcard i {
	position: absolute;
	max-width: 60%;
	overflow: hidden;
	white-space: nowrap;
	font-style: normal;
	font-size: calc(var(--w) * 0.13);
	font-weight: 700;
	line-height: 1;
	opacity: 0.7;
}
.tool .pcard i:first-of-type,
.deck-page .pcard i:first-of-type,
.sp-print-root .pcard i:first-of-type {
	top: calc(var(--w) * 0.13);
	left: calc(var(--w) * 0.14);
}
.tool .pcard i:last-of-type,
.deck-page .pcard i:last-of-type,
.sp-print-root .pcard i:last-of-type {
	right: calc(var(--w) * 0.14);
	bottom: calc(var(--w) * 0.13);
	transform: rotate(180deg);
}
.tool .pcard-back,
.deck-page .pcard-back,
.sp-print-root .pcard-back {
	background: var(--card-back);
	box-shadow: none;
}
.tool .pcard-back::after,
.deck-page .pcard-back::after,
.sp-print-root .pcard-back::after {
	content: "";
	width: 30%;
	aspect-ratio: 1;
	border-radius: 50%;
	background: var(--sun);
}

/* Preview of the cards tool */
.tool .tl-preview {
	display: flex;
	flex-wrap: wrap;
	gap: var(--s-3);
	margin: 0;
	padding: 0;
	list-style: none;
}
.tool .tl-preview li {
	display: block;
	margin: 0;
	padding: 0;
}
.tool .tl-preview .pcard {
	--w: 76px;
}
.tool .tl-summary {
	margin: 0 0 var(--s-4);
	font-size: var(--t-base);
	color: var(--ink-2);
}
.tool .tl-summary strong {
	color: var(--ink);
}

/* ---------- Deck pages: the deck laid out on a white panel, cards tinted in turn ---------- */
.deck-page .deck-stage {
	background: var(--surface);
	border-radius: var(--r-lg);
	padding: var(--s-6) var(--s-5);
	box-shadow: var(--shadow-2);
}
.deck-page .deck-row {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: var(--s-3);
	margin: 0;
	padding: 0;
	list-style: none;
}
.deck-page .deck-row li {
	display: block;
	margin: 0;
	padding: 0;
}
.deck-page .deck-row .pcard {
	--w: clamp(58px, 7.2vw, 88px);
	background: var(--tint-blue);
	color: var(--ink);
	box-shadow: none;
}
.deck-page .deck-row li:nth-child(5n + 2) .pcard {
	background: var(--tint-green);
}
.deck-page .deck-row li:nth-child(5n + 3) .pcard {
	background: var(--tint-yellow);
}
.deck-page .deck-row li:nth-child(5n + 4) .pcard {
	background: var(--tint-violet);
}
.deck-page .deck-row li:nth-child(5n) .pcard {
	background: var(--tint-sky);
}
.deck-page .deck-caption {
	margin: var(--s-5) 0 0;
	text-align: center;
	font-size: var(--t-sm);
	line-height: 1.5;
	color: var(--ink-2);
}
.deck-page .deck-actions {
	display: flex;
	justify-content: center;
	margin-top: var(--s-4);
}
.deck-page .deck-start {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 0 var(--s-5);
	font-size: var(--t-base);
	font-weight: 600;
	text-decoration: none;
	color: var(--on-accent);
	background: var(--accent);
	border-radius: var(--r-pill);
	transition: background var(--fast) var(--ease);
}
.deck-page .deck-start:hover {
	background: var(--accent-hover);
}
@media (max-width: 480px) {
	.deck-page .deck-stage {
		padding: var(--s-5) var(--s-3);
	}
	.deck-page .deck-row {
		gap: var(--s-2);
	}
}

/* ---------- Templates ---------- */
.tpl .tpl-bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--s-3);
	margin-bottom: var(--s-4);
	padding-bottom: var(--s-4);
	border-bottom: 1px solid var(--line);
}
.tpl .tpl-bar .tl-title {
	margin: 0;
}
.tpl .tpl-buttons {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--s-2);
}
.tpl .tpl-status {
	flex-basis: 100%;
	min-height: 1.3em;
	margin: 0;
	font-size: var(--t-sm);
	color: var(--ok);
	text-align: right;
}
.tpl .tpl-doc {
	font-size: var(--t-base);
	line-height: 1.55;
	color: var(--ink);
}
.tpl .tpl-doc h3 {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: var(--s-1) var(--s-4);
	margin: var(--s-5) 0 var(--s-2);
	font-family: var(--font-display);
	font-size: var(--t-md);
	font-weight: 700;
	letter-spacing: -0.01em;
	line-height: 1.3;
	color: var(--ink);
}
.tpl .tpl-doc h3:first-child {
	margin-top: 0;
}
.tpl .tpl-doc h3 span {
	font-family: var(--font);
	font-size: var(--t-sm);
	font-weight: 500;
	letter-spacing: 0;
	color: var(--ink-3);
}
.tpl .tpl-doc p {
	margin: 0 0 var(--s-2);
	color: var(--ink-2);
}
.tpl .tpl-doc ul {
	margin: 0;
	padding: 0;
	list-style: none;
}
.tpl .tpl-doc li {
	position: relative;
	margin: 0;
	padding: 6px 0 6px 30px;
}
.tpl .tpl-doc li::before {
	content: "";
	position: absolute;
	left: 2px;
	top: 0.62em;
	width: 15px;
	height: 15px;
	border: 1.5px solid var(--line-strong);
	border-radius: 4px;
	background: var(--bg);
}
.tpl .tpl-status:empty {
	min-height: 0;
	margin-top: calc(-1 * var(--s-3));
}
@media (max-width: 480px) {
	.tpl .tpl-status {
		text-align: left;
	}
}

@media (prefers-reduced-motion: reduce) {
	.tool *,
	.tpl *,
	.deck-page * {
		transition: none !important;
	}
}

/* ---------- Print: only the card sheets (cards tool) ---------- */
.sp-print-root {
	display: none;
}
@media print {
	@page {
		margin: 10mm;
	}
	html.sp-has-print,
	html.sp-has-print body {
		background: #fff !important;
		margin: 0 !important;
		padding: 0 !important;
	}
	html.sp-has-print body > *:not(.sp-print-root) {
		display: none !important;
	}
	html.sp-has-print .sp-print-root {
		display: block;
	}
	/* Sheet sizes fit both A4 and Letter inside 10mm margins (190mm by 259mm usable) */
	.sp-print-root .sp-sheet {
		--cw: 60mm;
		--cols: 3;
		display: grid;
		grid-template-columns: repeat(var(--cols), var(--cw));
		justify-content: center;
		align-content: start;
		break-after: page;
		page-break-after: always;
		break-inside: avoid;
	}
	.sp-print-root .sp-sheet:last-child {
		break-after: auto;
		page-break-after: auto;
	}
	.sp-print-root .sp-sheet[data-per="4"] {
		--cw: 85mm;
		--cols: 2;
	}
	.sp-print-root .sp-sheet[data-per="16"] {
		--cw: 45mm;
		--cols: 4;
	}
	.sp-print-root .sp-sheet-backs {
		direction: rtl;
	}
	/* Each cell is one card: cut along the dashed lines */
	.sp-print-root .sp-cell {
		position: relative;
		width: var(--cw);
		height: calc(var(--cw) * 1.4);
		break-inside: avoid;
	}
	.sp-print-root .sp-cell::after {
		content: "";
		position: absolute;
		inset: -0.15mm;
		border: 0.3mm dashed #6c6c88;
		pointer-events: none;
	}
	.sp-print-root .sp-sheet-backs .sp-cell::after {
		border-color: rgba(255, 255, 255, 0.55);
	}
	.sp-print-root .pcard {
		--w: var(--cw);
		direction: ltr;
		width: 100%;
		height: 100%;
		aspect-ratio: auto;
		border-radius: 0;
		box-shadow: none;
		background: #fff;
		color: #1b1b3a;
		-webkit-print-color-adjust: exact;
		print-color-adjust: exact;
	}
	/* Navy outline inside the cut line */
	.sp-print-root .pcard::before {
		content: "";
		position: absolute;
		inset: calc(var(--w) * 0.07);
		border: 0.6mm solid #1b1b3a;
		border-radius: calc(var(--w) * 0.1);
		pointer-events: none;
	}
	.sp-print-root .pcard i:first-of-type {
		top: calc(var(--w) * 0.15);
		left: calc(var(--w) * 0.16);
	}
	.sp-print-root .pcard i:last-of-type {
		right: calc(var(--w) * 0.16);
		bottom: calc(var(--w) * 0.15);
	}
	/* Plain navy in print: no pattern, so a slightly off cut does not show */
	.sp-print-root .pcard-back {
		background: #1b1b3a;
	}
	.sp-print-root .pcard-back::before,
	.sp-print-root .pcard-back::after {
		content: none;
	}
}
@media (max-width: 480px) {
	.tool .tl-table {
		table-layout: fixed;
		font-size: var(--t-sm);
	}
	.tool .tl-table th,
	.tool .tl-table td {
		overflow-wrap: anywhere;
	}
}
