/*
 * Verification letter generator: the block's own component styles (loaded only where the block is).
 * Ported from the approved mockup (mock.css + the tool page's generator rules).
 *
 * Token bridge: every value below reads a theme.json variable (--wp--preset--* / --wp--custom--*).
 * The fallback after each comma is the approved token value, used only if the theme does not define it.
 * Literal px left in the rules are component dimensions (radii, the checkbox, the signature line).
 * Buttons are the theme.json button element (.wp-element-button); the two statute callouts are the
 * theme's own callout block style with its citation row (.is-style-cites). Nothing here styles anything
 * outside the block, except the print rules at the end, which print the letter alone (Article VII record
 * in the site docs).
 */

.wp-block-esservices-verification-letter,
.esvl-print-root {
	--esvl-surface: var(--wp--custom--color--surface, #FDFCFE);
	--esvl-surface-inset: var(--wp--custom--color--surface-inset, #F6F5F9);
	--esvl-text: var(--wp--custom--color--text, #1B1721);
	--esvl-text-strong: var(--wp--custom--color--text-strong, #0F0D14);
	--esvl-text-muted: var(--wp--custom--color--text-muted, #575261);
	--esvl-text-quiet: var(--wp--custom--color--text-quiet, #726D7B);
	--esvl-line: var(--wp--custom--color--line, #DDDBE4);
	--esvl-line-strong: var(--wp--custom--color--line-strong, #8E8A97);
	--esvl-action: var(--wp--custom--color--action, #723FB4);
	--esvl-callout-label: var(--wp--custom--color--callout-label, #592D91);
	--esvl-status-action: var(--wp--custom--color--status-action, #935A11);
	--esvl-selected: var(--wp--preset--color--purple-50, #F7F4FE);
	--esvl-highlight: var(--wp--preset--color--mint-100, #D1F7E7);
	--esvl-paper: var(--wp--preset--color--neutral-0, #FDFCFE);
	--esvl-paper-text: var(--wp--preset--color--neutral-900, #1B1721);
	--esvl-paper-strong: var(--wp--preset--color--neutral-950, #0F0D14);
	--esvl-paper-muted: var(--wp--preset--color--neutral-600, #575261);
	--esvl-paper-rule: var(--wp--preset--color--neutral-400, #8E8A97);
	--esvl-paper-shadow: var(--wp--preset--color--purple-900, #2B1349);

	--esvl-font: var(--wp--preset--font-family--inter, "Inter", system-ui, -apple-system, "Segoe UI", sans-serif);
	--esvl-mono: var(--wp--preset--font-family--mono, "JetBrains Mono", ui-monospace, SFMono-Regular, monospace);
	--esvl-caption: var(--wp--preset--font-size--caption, 0.75rem);
	--esvl-small: var(--wp--preset--font-size--small, 0.875rem);
	--esvl-body: var(--wp--preset--font-size--body, 1.0625rem);

	--esvl-hairline: var(--wp--preset--spacing--hairline, 0.25rem);
	--esvl-tight: var(--wp--preset--spacing--tight, 0.375rem);
	--esvl-snug: var(--wp--preset--spacing--snug, 0.625rem);
	--esvl-base: var(--wp--preset--spacing--base, 1rem);
	--esvl-loose: var(--wp--preset--spacing--loose, 1.625rem);
	--esvl-wide: var(--wp--preset--spacing--wide, 2.625rem);

	--esvl-leading-body: var(--wp--custom--leading--body, 1.6);
	--esvl-leading-ui: var(--wp--custom--leading--ui, 1.4);
	--esvl-tracking-body: var(--wp--custom--tracking--body, 0em);
	--esvl-tracking-ui: var(--wp--custom--tracking--ui, 0.01em);
	--esvl-tracking-label: var(--wp--custom--tracking--label, 0.08em);
}

/* Resets inside the component only (the theme sets neither border-box sizing nor these margins). */
.wp-block-esservices-verification-letter *,
.wp-block-esservices-verification-letter *::before,
.wp-block-esservices-verification-letter *::after,
.esvl-print-root * { box-sizing: border-box; }
.wp-block-esservices-verification-letter :where(p, h3, fieldset, legend) { margin: 0; }
.wp-block-esservices-verification-letter [hidden] { display: none !important; }
.wp-block-esservices-verification-letter :focus-visible { outline: 2px solid var(--esvl-action); outline-offset: 2px; }

/* The structural (mono) voice: label + meta, as in the mockup. */
.esvl-label { font: 500 var(--esvl-caption)/var(--esvl-leading-ui) var(--esvl-mono); letter-spacing: var(--esvl-tracking-label); text-transform: uppercase; }
.esvl-meta { font: 400 var(--esvl-caption)/var(--esvl-leading-body) var(--esvl-mono); letter-spacing: var(--esvl-tracking-body); }
.esvl-sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.esvl-cite { font: 500 var(--esvl-caption)/var(--esvl-leading-ui) var(--esvl-mono); letter-spacing: var(--esvl-tracking-ui); color: var(--esvl-callout-label); white-space: nowrap; }
.esvl-cite:hover { color: var(--esvl-action); }

/* Buttons: the theme.json button element sets color, type, padding and radius; the quiet variant is here. */
.wp-block-esservices-verification-letter .esvl-btn {
	display: inline-flex; align-items: center; justify-content: center; gap: var(--esvl-tight);
	white-space: nowrap; cursor: pointer;
}
.wp-block-esservices-verification-letter .esvl-btn-quiet,
.wp-block-esservices-verification-letter .esvl-btn-quiet:hover {
	background: var(--esvl-surface); color: var(--esvl-text-strong); box-shadow: inset 0 0 0 1px var(--esvl-line-strong);
}
.wp-block-esservices-verification-letter .esvl-btn-quiet:hover { box-shadow: inset 0 0 0 1px var(--esvl-text-strong); }
.wp-block-esservices-verification-letter .esvl-btn[aria-disabled="true"] { cursor: progress; }

/* ── The generator: form panel (4) + letter column (8) ── */
.esvl-gen { display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 8fr); gap: var(--esvl-wide); align-items: start; }
.esvl-panel { background: var(--esvl-surface-inset); border-radius: 8px; padding: var(--esvl-loose); }
.esvl-panel fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.esvl-panel > fieldset + fieldset { margin-top: var(--esvl-loose); padding-top: var(--esvl-loose); border-top: 1px solid var(--esvl-line); }
.esvl-panel legend { float: left; width: 100%; padding: 0; margin: 0 0 var(--esvl-base); color: var(--esvl-text-muted); }
.esvl-panel legend + * { clear: both; }

/* Segmented choices (radio cards) */
.esvl-seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--esvl-snug); margin: 0 0 var(--esvl-base); }
.esvl-seg label { position: relative; display: block; cursor: pointer; }
.esvl-seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.esvl-seg span { display: block; height: 100%; background: var(--esvl-surface); border: 1px solid var(--esvl-line-strong); border-radius: 6px; padding: var(--esvl-snug); font-size: var(--esvl-small); line-height: var(--esvl-leading-ui); }
.esvl-seg span b { display: block; font-weight: 600; color: var(--esvl-text-strong); }
.esvl-seg span i { display: block; font-style: normal; color: var(--esvl-text-muted); }
.esvl-seg input:checked + span { border-color: var(--esvl-action); box-shadow: inset 0 0 0 1px var(--esvl-action); background: var(--esvl-selected); }
.esvl-seg input:focus-visible + span { outline: 2px solid var(--esvl-action); outline-offset: 2px; }
.esvl-sub legend { float: none; width: auto; margin: 0 0 var(--esvl-tight); font-size: var(--esvl-small); font-weight: 500; line-height: var(--esvl-leading-ui); color: var(--esvl-text-strong); }

/* Fields */
.esvl-f { display: block; margin: 0 0 var(--esvl-base); }
.esvl-f > span { display: block; font-size: var(--esvl-small); font-weight: 500; line-height: var(--esvl-leading-ui); color: var(--esvl-text-strong); margin-bottom: var(--esvl-tight); }
.esvl-f > span em, .esvl-check em { font-style: normal; font-weight: 400; color: var(--esvl-text-muted); }
.esvl-f input, .esvl-f select {
	display: block; width: 100%; min-width: 0; box-sizing: border-box;
	font: 400 var(--esvl-body)/var(--esvl-leading-ui) var(--esvl-font); color: var(--esvl-text-strong);
	background: var(--esvl-surface); border: 1px solid var(--esvl-line-strong); border-radius: 5px; padding: var(--esvl-snug);
}
.esvl-f input::placeholder { color: var(--esvl-text-quiet); opacity: 1; }
.esvl-f input:focus, .esvl-f select:focus { outline: 2px solid var(--esvl-action); outline-offset: 1px; border-color: var(--esvl-action); }
.esvl-f.esvl-is-empty input { border-color: var(--esvl-status-action); box-shadow: inset 3px 0 0 var(--esvl-status-action); }
.esvl-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--esvl-base); }
.esvl-check { display: flex; gap: var(--esvl-snug); align-items: flex-start; font-size: var(--esvl-small); line-height: var(--esvl-leading-ui); margin: 0 0 var(--esvl-base); cursor: pointer; }
.esvl-check input { flex: none; width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--esvl-action); }
.esvl-check input:disabled + span { color: var(--esvl-text-quiet); }
.wp-block-esservices-verification-letter .esvl-hint { font-size: var(--esvl-small); line-height: var(--esvl-leading-body); color: var(--esvl-text-muted); margin: calc(-1 * var(--esvl-snug)) 0 var(--esvl-base); }

/* Notes inside the form: the theme's statute callout, and the pay status (amber until the box is checked) */
.wp-block-esservices-verification-letter .esvl-callout { margin: 0 0 var(--esvl-base); }
.esvl-status {
	margin: 0 0 var(--esvl-base); padding: var(--esvl-snug) var(--esvl-base);
	font-size: var(--esvl-small); line-height: var(--esvl-leading-body);
	border-left: 3px solid var(--esvl-line-strong); background: var(--esvl-surface);
}
.esvl-status.esvl-is-action { border-left-color: var(--esvl-status-action); background: color-mix(in srgb, var(--esvl-status-action) 8%, var(--esvl-surface)); }
.esvl-status:not(.esvl-is-action) .esvl-act { display: none; }
.esvl-status-k { display: block; color: var(--esvl-status-action); margin-bottom: var(--esvl-hairline); }
.esvl-status .esvl-cite { display: inline-block; margin-top: var(--esvl-hairline); }

/* ── The letter column ── */
.esvl-mbar { display: none; }
.esvl-out { position: sticky; top: var(--esvl-loose); }
.esvl-out-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--esvl-base); margin-bottom: var(--esvl-snug); }
.wp-block-esservices-verification-letter .esvl-out-head h3 { color: var(--esvl-text-muted); }
.esvl-edit { display: none; font-size: var(--esvl-small); font-weight: 500; }
.esvl-toolbar { display: flex; flex-wrap: wrap; gap: var(--esvl-snug); }
.wp-block-esservices-verification-letter .esvl-notes { margin-top: var(--esvl-snug); margin-bottom: var(--esvl-base); color: var(--esvl-text-muted); }
.esvl-left.esvl-is-action { color: var(--esvl-status-action); }

/* The sheet */
.esvl-paper {
	overflow-wrap: anywhere;
	background: var(--esvl-paper); border: 1px solid var(--esvl-line); border-radius: 3px;
	box-shadow: 0 24px 50px -30px color-mix(in srgb, var(--esvl-paper-shadow) 35%, transparent);
	padding: var(--esvl-loose) var(--esvl-wide) var(--esvl-wide);
	font-size: var(--esvl-small); line-height: var(--esvl-leading-body); color: var(--esvl-paper-text);
}
.esvl-paper :where(p) { margin: 0; }
.esvl-paper p + p { margin-top: var(--esvl-base); }
.esvl-lh { border-bottom: 1px solid var(--esvl-line); padding-bottom: var(--esvl-snug); margin-bottom: var(--esvl-base); }
.esvl-lh b { display: block; font-size: var(--esvl-body); line-height: var(--esvl-leading-ui); color: var(--esvl-paper-strong); }
.esvl-lh small { display: block; font-size: var(--esvl-caption); line-height: var(--esvl-leading-body); color: var(--esvl-paper-muted); }
.esvl-paper .esvl-sig { margin-top: var(--esvl-loose); }
.esvl-sigline { height: var(--esvl-wide); border-bottom: 1px solid var(--esvl-paper-rule); width: min(260px, 70%); margin: var(--esvl-base) 0 var(--esvl-tight); }
.esvl-paper .esvl-sig-name { margin-top: 0; }
.esvl-v { background: var(--esvl-highlight); box-shadow: 0 0 0 2px var(--esvl-highlight); border-radius: 1px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.esvl-v.esvl-nw { white-space: nowrap; }
.esvl-v.esvl-empty { background: none; box-shadow: none; border-bottom: 1px dashed var(--esvl-line-strong); color: var(--esvl-text-quiet); }

@media (forced-colors: active) {
	.esvl-seg input:checked + span { border: 3px solid Highlight; padding: calc(var(--esvl-snug) - 2px); }
}

/* ── Narrow screens: one column, a sticky "Preview letter" bar, an "Edit details" link back ── */
@media (max-width: 1023px) {
	:root:has(.wp-block-esservices-verification-letter) { scroll-padding-bottom: calc(var(--wp--preset--spacing--section, 4.25rem) + var(--wp--preset--spacing--snug, 0.625rem) + env(safe-area-inset-bottom)); }
	.esvl-gen { grid-template-columns: minmax(0, 1fr); }
	.esvl-out { position: static; }
	#esvl-letter { scroll-margin-top: var(--esvl-snug); }
	.esvl-edit { display: inline; }
	.esvl-mbar {
		display: flex; position: sticky; bottom: 0; z-index: 2;
		margin: var(--esvl-loose) calc(-1 * var(--esvl-loose)) calc(-1 * var(--esvl-loose));
		padding: var(--esvl-snug) var(--esvl-loose) calc(var(--esvl-snug) + env(safe-area-inset-bottom));
		background: var(--esvl-surface-inset); border-top: 1px solid var(--esvl-line-strong); border-radius: 0 0 8px 8px;
	}
	.esvl-mbar .esvl-btn { flex: 1; }
}
@media (max-width: 760px) {
	.esvl-panel { padding: var(--esvl-base); }
	.esvl-mbar { margin: var(--esvl-loose) calc(-1 * var(--esvl-base)) calc(-1 * var(--esvl-base)); padding-inline: var(--esvl-base); }
	.esvl-paper {
	overflow-wrap: anywhere; padding: var(--esvl-loose) var(--esvl-base); }
}
@media (max-width: 560px) {
	.esvl-row { grid-template-columns: minmax(0, 1fr); }
	.esvl-toolbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ── The editor card (editor.js): the block has no settings; the generator renders on the page ── */
.wp-block-esservices-verification-letter.esvl-editor-card {
	background: var(--esvl-surface-inset); border: 1px dashed var(--esvl-line-strong); border-radius: 8px;
	padding: var(--esvl-loose); font-family: var(--esvl-font); color: var(--esvl-text);
}
.esvl-editor-card .esvl-editor-card__title { font-size: var(--esvl-body); font-weight: 600; line-height: var(--esvl-leading-ui); color: var(--esvl-text-strong); }
.esvl-editor-card .esvl-editor-card__note { margin-top: var(--esvl-hairline); font-size: var(--esvl-small); line-height: var(--esvl-leading-body); color: var(--esvl-text-muted); }

/* ── Print: the letter alone. view.js keeps a copy of the letter in .esvl-print-root (a direct child
   of body, hidden on screen); printing shows only that copy. Scoped with :has() so a page without
   the copy prints normally. ── */
.esvl-print-root { display: none; }
@media print {
	@page { margin: 1in; }
	body:has(> .esvl-print-root) > :not(.esvl-print-root) { display: none !important; }
	body:has(> .esvl-print-root) { background: none; margin: 0; padding: 0; }
	.esvl-print-root { display: block; overflow-wrap: anywhere; font-family: var(--esvl-font); font-size: var(--esvl-body); line-height: var(--esvl-leading-body); color: var(--esvl-paper-text); background: none; }
	.esvl-print-root p { margin: 0; }
	.esvl-print-root p + p { margin-top: var(--esvl-base); }
	.esvl-print-root .esvl-sig { margin-top: var(--esvl-loose); }
	.esvl-print-root .esvl-sigline { height: 0.75in; }
	.esvl-print-root .esvl-sig-name { margin-top: 0; }
	.esvl-print-root .esvl-v { background: none; box-shadow: none; }
	.esvl-print-root .esvl-v.esvl-empty { border-bottom: 0; color: inherit; }
}
