/*
 * Cornerstone tools — shared look (CSFE-001 FE-34).
 *
 * Registered once as the `cs-tools` style (cs-core/cs-tools.php). Every tool
 * stylesheet (resources, aql, wm, julian, library, presentation-builder quiz)
 * lists it as a dependency, so a tool looks the same embedded on its own or
 * on the Resources page. Only rules that are truly specific to one tool live
 * in that tool's own file.
 *
 * Built on the design tokens in css/app.css / css/tokens.css. Each token is
 * read with a fallback so the tools still render on-brand on a page that
 * doesn't load app.css. The --cst-* names are private aliases, set on the tool
 * roots only; they never redefine the site's --cs-* tokens.
 *
 * Don't use Tailwind utilities in tool markup: app.css is a purged build and
 * classes it doesn't already contain do nothing.
 */

.cs-tool-section,
.cs-resources,
.cs-res-top,
.cornerstone-library,
.cs-lib-card,
.cs-library-entry-details,
.cs-lib-entry-preview,
.cs-pb-quiz {
	--cst-ink: var(--cs-ink, #102B3B);
	--cst-ink-hover: var(--cs-ink-hover, #0A1D28);
	--cst-accent: var(--cs-accent, #0171DF);
	--cst-accent-strong: var(--cs-accent-strong, #014FA0);
	--cst-accent-tint: var(--cs-accent-tint, #EFF6FE);
	--cst-text: var(--cs-text, #102B3B);
	--cst-muted: var(--cs-muted, #56697A);
	--cst-line: var(--cs-line, #E3E8EC);
	--cst-line-strong: var(--cs-line-strong, #CFD8DF);
	--cst-surface: var(--cs-surface, #FFFFFF);
	--cst-surface-2: var(--cs-surface-2, #F5F8FA);
	--cst-pass: var(--cs-pass, #166534);
	--cst-pass-bg: var(--cs-pass-bg, #E7F6EC);
	--cst-warn: var(--cs-warn, #B45309);
	--cst-warn-text: var(--cs-warn-text, #8A4207);
	--cst-warn-bg: var(--cs-warn-bg, #FDF3E0);
	--cst-fail: var(--cs-fail, #B91C1C);
	--cst-fail-bg: var(--cs-fail-bg, #FDECEC);
	--cst-info: var(--cs-info, #014FA0);
	--cst-info-bg: var(--cs-info-bg, #EFF6FE);
	--cst-font-heading: var(--cs-font-heading, "Poppins", ui-sans-serif, system-ui, sans-serif);
	--cst-font-body: var(--cs-font-body, "Open Sauce Sans", ui-sans-serif, system-ui, sans-serif);
	--cst-font-mono: var(--cs-font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
	--cst-radius: var(--cs-radius, 20px);
	--cst-radius-sm: var(--cs-radius-sm, 12px);
	--cst-pill: var(--cs-radius-pill, 999px);
	--cst-control-h: var(--cs-control-h, 44px);
	--cst-shadow: var(--cs-shadow-card, 0 0 63px -16px rgba(16, 43, 59, .20));
	--cst-focus: var(--cs-focus-ring, 0 0 0 3px rgba(1, 113, 223, .35));
	/* Placeholder text: 3.5:1 on white (decorative hint, not a value). */
	--cst-placeholder: #7A8B97;
	/* Sticky site header (72px) + gap, plus the hello bar when it sits on top. */
	--cst-header-offset: calc(96px + var(--cs-hb-h, 0px));
}

.cs-tool-section,
.cs-tool-section *,
.cornerstone-library,
.cornerstone-library *,
.cs-pb-quiz,
.cs-pb-quiz * {
	box-sizing: border-box;
}

/* Screen-reader-only one-line result summary (the live region). */
.cs-tool-live {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* --------------------------------------------------------------- tool sections */

.cs-tool-section {
	margin: 0 0 56px;
	color: var(--cst-text);
	scroll-margin-top: var(--cst-header-offset);
}

@media (min-width: 640px) {
	.cs-tool-section {
		margin-bottom: 72px;
	}
}

.cs-tool-section:last-child {
	margin-bottom: 0;
}

.cs-tool-section-head {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 10px;
	margin: 0 0 18px;
}

.cs-tool-eyebrow {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	border: 1px solid var(--cst-line);
	border-radius: var(--cst-pill);
	padding: 4px 12px;
	font-family: var(--cst-font-body);
	font-size: .6875rem;
	font-weight: 700;
	letter-spacing: .09em;
	text-transform: uppercase;
	color: var(--cst-muted);
	background: var(--cst-surface);
}

.cs-tool-section .cs-tool-section-title {
	display: flex;
	align-items: baseline;
	gap: 10px;
	margin: 0;
	font-family: var(--cst-font-heading);
	font-size: clamp(1.375rem, 1.15rem + .8vw, 1.75rem);
	font-weight: 600;
	line-height: 1.2;
	letter-spacing: -.015em;
	color: var(--cst-ink);
}

/* ------------------------------------------------------------------ tool cards */

.cornerstone-tool,
.cornerstone-aql,
.cornerstone-wm,
.cornerstone-julian,
.cornerstone-library,
.cs-pb-quiz {
	border: 1px solid var(--cst-line);
	border-radius: var(--cst-radius);
	background: var(--cst-surface);
	box-shadow: var(--cst-shadow);
	padding: 22px;
	font-family: var(--cst-font-body);
	color: var(--cst-text);
}

@media (min-width: 640px) {
	.cornerstone-tool,
	.cornerstone-aql,
	.cornerstone-wm,
	.cornerstone-julian,
	.cornerstone-library,
	.cs-pb-quiz {
		padding: 28px;
	}
}

.cs-tool-head {
	margin: 0 0 20px;
	padding: 0 0 18px;
	border-bottom: 1px solid var(--cst-line);
}

.cs-tool-desc {
	margin: 0;
	max-width: 72ch;
	font-size: .9375rem;
	line-height: 1.6;
	color: var(--cst-muted);
}

/* ---------------------------------------------------------------- form controls */

:is(.cs-tool-section, .cornerstone-library) .cs-row {
	display: flex;
	flex-wrap: wrap;
	gap: 16px;
	align-items: flex-end;
	margin: 0 0 18px;
}

:is(.cs-tool-section, .cornerstone-library) .cs-row:last-child {
	margin-bottom: 0;
}

:is(.cs-tool-section, .cornerstone-library) .cs-field {
	flex: 1 1 220px;
	min-width: 200px;
}

/* Fields may carry an inline width; on narrow screens they must go full width,
   which only !important can win against an inline style. */
@media (max-width: 560px) {
	:is(.cs-tool-section, .cornerstone-library) .cs-field,
	.cornerstone-aql .cs-row > label {
		flex: 1 1 100% !important;
		min-width: 0 !important;
	}
}

/* Keeps a button-only field aligned with its labelled neighbours. */
.cs-field-spacer {
	display: block;
	height: calc(.8125rem * 1.4 + 7px);
}

:is(.cs-tool-section, .cornerstone-library, .cs-pb-quiz) label {
	display: block;
	margin: 0 0 7px;
	font-size: .8125rem;
	font-weight: 600;
	line-height: 1.4;
	color: var(--cst-ink);
}

/* AQL wraps each control in its label. */
.cornerstone-aql .cs-row > label {
	display: flex;
	flex-direction: column;
	gap: 7px;
	flex: 1 1 220px;
	min-width: 200px;
	margin: 0;
}

:is(.cs-tool-section, .cornerstone-library, .cs-pb-quiz) :is(input:not([type="radio"]):not([type="checkbox"]):not([type="hidden"]), select, textarea) {
	display: block;
	width: 100%;
	height: auto;
	min-height: var(--cst-control-h);
	margin: 0;
	padding: 10px 12px;
	border: 1px solid var(--cst-line-strong);
	border-radius: var(--cst-radius-sm);
	background-color: var(--cst-surface);
	font: inherit;
	font-size: .9375rem;
	line-height: 1.4;
	color: var(--cst-ink);
	transition: border-color .15s ease, box-shadow .15s ease;
}

:is(.cs-tool-section, .cornerstone-library, .cs-pb-quiz) select {
	appearance: none;
	-webkit-appearance: none;
	padding-right: 36px;
	background-image: linear-gradient(45deg, transparent 50%, var(--cst-muted) 50%), linear-gradient(135deg, var(--cst-muted) 50%, transparent 50%);
	background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
	background-size: 5px 5px, 5px 5px;
	background-repeat: no-repeat;
}

:is(.cs-tool-section, .cornerstone-library, .cs-pb-quiz) textarea {
	min-height: 104px;
	resize: vertical;
}

:is(.cs-tool-section, .cornerstone-library, .cs-pb-quiz) :is(input, select, textarea):focus {
	outline: none;
	border-color: var(--cst-accent);
	box-shadow: var(--cst-focus);
}

:is(.cs-tool-section, .cornerstone-library, .cs-pb-quiz) :is(input, select, textarea):disabled {
	background-color: var(--cst-surface-2);
	color: var(--cst-muted);
}

:is(.cs-tool-section, .cornerstone-library, .cs-pb-quiz) :is(input, textarea)::placeholder {
	color: var(--cst-placeholder);
	opacity: 1;
}

:is(.cs-tool-section, .cs-pb-quiz) input[type="radio"],
:is(.cs-tool-section, .cs-pb-quiz) input[type="checkbox"] {
	width: 18px;
	height: 18px;
	margin: 0 8px 0 0;
	vertical-align: -3px;
	accent-color: var(--cst-ink);
}

/* ---------------------------------------------------------------------- buttons
 * Same as the site's .btn-primary: navy pill, white text. */

:is(.cs-tool-section, .cs-pb-quiz) button,
.cs-tool-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	width: auto;
	min-height: var(--cst-control-h);
	padding: 0 22px;
	border: 1px solid transparent;
	border-radius: var(--cst-pill);
	background: var(--cst-ink);
	font-family: var(--cst-font-body);
	font-size: .9375rem;
	font-weight: 600;
	line-height: 1.2;
	color: #fff;
	text-decoration: none;
	cursor: pointer;
	transition: background-color .15s ease, box-shadow .15s ease, opacity .15s ease;
}

:is(.cs-tool-section, .cs-pb-quiz) button:hover:not(:disabled),
.cs-tool-btn:hover {
	background: var(--cst-ink-hover);
	color: #fff;
}

:is(.cs-tool-section, .cs-pb-quiz) button:focus-visible,
.cs-tool-btn:focus-visible {
	outline: 2px solid var(--cst-accent);
	outline-offset: 2px;
}

:is(.cs-tool-section, .cs-pb-quiz) button:disabled,
.cs-tool-btn[aria-disabled="true"] {
	opacity: .5;
	cursor: not-allowed;
}

.cs-tool-actions,
.cs-wm-actions,
.cs-aql-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	align-items: center;
	margin-top: 18px;
}

/* --------------------------------------------------------------- result panels */

.cs-result,
.cs-aql-result,
.cs-wm-result,
.cs-julian-result {
	margin-top: 22px;
	padding: 18px;
	border: 0;
	border-radius: var(--cst-radius-sm);
	background: var(--cst-surface-2);
	font-size: .9375rem;
}

/* Result panels fill in once a tool has something to say; empty they would
   show as a stray grey bar under the inputs. */
.cs-result:empty,
.cs-aql-result:empty,
.cs-wm-result:empty,
.cs-julian-result:empty {
	display: none;
}

.cs-meta,
.cs-aql-meta,
.cs-wm-meta,
.cs-tool-note {
	margin: 0 0 14px;
	font-size: .875rem;
	line-height: 1.5;
	color: var(--cst-muted);
}

.cs-tool-note {
	margin: 4px 0 0;
	font-size: .8125rem;
}

.cs-error,
.cs-aql-error,
.cs-wm-error {
	margin: 0 0 10px;
	color: var(--cst-fail);
	font-weight: 600;
}

.cs-error:last-child,
.cs-aql-error:last-child,
.cs-wm-error:last-child {
	margin-bottom: 0;
}

/* Verdict chip under a result (capability, GR&R). */
.cs-tool-verdict {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin: 14px 0 0;
	padding: 4px 12px;
	border-radius: var(--cst-pill);
	font-family: var(--cst-font-heading);
	font-size: .8125rem;
	font-weight: 600;
	line-height: 1.4;
	background: var(--cst-info-bg);
	color: var(--cst-info);
}

.cs-tool-verdict.is-pass {
	background: var(--cst-pass-bg);
	color: var(--cst-pass);
}

.cs-tool-verdict.is-warn {
	background: var(--cst-warn-bg);
	color: var(--cst-warn-text);
}

.cs-tool-verdict.is-fail {
	background: var(--cst-fail-bg);
	color: var(--cst-fail);
}

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

.cs-table-scroll {
	width: 100%;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	-webkit-overflow-scrolling: touch;
}

:is(.cs-tool-section, .cs-pb-quiz) table {
	width: 100%;
	max-width: none;
	margin: 0;
	border-collapse: separate;
	border-spacing: 0;
	font-size: .9rem;
}

:is(.cs-tool-section, .cs-pb-quiz) :is(th, td) {
	padding: 11px 12px;
	border: 0;
	border-bottom: 1px solid var(--cst-line);
	background: transparent;
	text-align: left;
	vertical-align: top;
	color: var(--cst-ink);
}

/* Column headers and row labels share the small-caps label look. */
:is(.cs-tool-section, .cs-pb-quiz) th {
	font-size: .75rem;
	font-weight: 700;
	letter-spacing: .06em;
	text-transform: uppercase;
	color: var(--cst-muted);
}

:is(.cs-tool-section, .cs-pb-quiz) thead th {
	white-space: nowrap;
}

:is(.cs-tool-section, .cs-pb-quiz) tbody tr:last-child :is(th, td) {
	border-bottom: 0;
}

/* -------------------------------------------- status lines (barcode, SG cup) */

.cs-bc-status {
	margin-top: 8px;
	font-weight: 700;
}

.cs-bc-status.is-match {
	color: var(--cst-pass);
}

.cs-bc-status.is-mismatch {
	color: var(--cst-fail);
}

.cs-bc-status.is-info {
	font-weight: 400;
}

.cs-bc-status-line {
	display: flex;
	align-items: center;
	gap: 8px;
}

.cs-bc-icon {
	display: inline-block;
	min-width: 18px;
	text-align: center;
	font-size: 18px;
	line-height: 1;
}

/* ----------------------------------------------------- presentation-builder quiz */

.cs-pb-quiz h2 {
	margin: 0 0 12px;
	font-family: var(--cst-font-heading);
	font-size: clamp(1.375rem, 1.15rem + .8vw, 1.75rem);
	font-weight: 600;
	line-height: 1.2;
	color: var(--cst-ink);
}

.cs-pb-quiz h3 {
	margin: 24px 0 10px;
	font-family: var(--cst-font-heading);
	font-size: 1.125rem;
	font-weight: 600;
	color: var(--cst-ink);
}

.cs-pb-quiz p {
	margin: 0 0 16px;
	line-height: 1.6;
}

.cs-pb-quiz fieldset {
	margin: 0 0 16px;
	padding: 16px 18px;
	border: 1px solid var(--cst-line);
	border-radius: var(--cst-radius-sm);
	min-width: 0;
}

.cs-pb-quiz legend {
	padding: 0 6px;
	font-family: var(--cst-font-heading);
	font-weight: 600;
	color: var(--cst-ink);
}

.cs-pb-quiz .cs-pb-quiz__option {
	display: flex;
	align-items: flex-start;
	margin: 0;
	padding: 8px 0;
	font-size: .9375rem;
	font-weight: 400;
	cursor: pointer;
}

.cs-pb-quiz .cs-pb-quiz__option input {
	flex: none;
	margin-top: 1px;
}

.cs-pb-quiz .cs-pb-quiz__field {
	max-width: 520px;
}

.cs-pb-quiz .cs-pb-quiz__field--wide {
	max-width: 720px;
}

.cs-pb-quiz__notice {
	margin: 12px 0 16px;
	padding: 12px 16px;
	border: 1px solid transparent;
	border-left-width: 4px;
	border-radius: var(--cst-radius-sm);
	line-height: 1.5;
}

.cs-pb-quiz__notice.is-pass {
	border-color: var(--cst-pass);
	background: var(--cst-pass-bg);
	color: var(--cst-pass);
}

.cs-pb-quiz__notice.is-fail {
	border-color: var(--cst-fail);
	background: var(--cst-fail-bg);
	color: var(--cst-fail);
}

.cs-pb-quiz__notice.is-info {
	border-color: var(--cst-line-strong);
	background: var(--cst-surface-2);
	color: var(--cst-ink);
}

.cs-pb-quiz__summary div {
	margin: 0 0 6px;
}

/* --------------------------------------------------------------------- a11y/print */

@media (prefers-reduced-motion: reduce) {
	.cs-tool-section *,
	.cornerstone-library *,
	.cs-pb-quiz * {
		transition-duration: .01ms !important;
		animation-duration: .01ms !important;
	}
}

@media print {
	.cs-print-off {
		display: none !important;
	}

	.cornerstone-tool,
	.cornerstone-aql,
	.cornerstone-wm,
	.cornerstone-julian {
		border: none;
		box-shadow: none;
		padding: 0;
	}

	.cs-print-hide {
		display: none !important;
	}

	.cs-result {
		background: transparent;
		padding: 0;
	}
}
