/*
 * Adverse action letter generator: the block's own component styles (loaded only where the block is).
 * Same look as the verification letter generator (es-verification-letter/style.css): the form panel,
 * segmented radios, labeled fields and hints, the paper sheet. Added here: the textarea, three-up radios,
 * the check boxes, the short "Check first" line above the sheet (its full list is a section under the sheet),
 * the response deadline box, a page the tool prints
 * after the letter (New Jersey's rights page), and the "Send with this letter", "Before you send", "After
 * you send" and rules lists under the sheet (the section pattern of the waiting period calculator,
 * es-adverse-action/style.css).
 *
 * 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).
 * Status is amber (a step to take), crimson (no date, or something missing or wrong: tool 2's
 * status-deficiency) or ink. Never mint as text: mint is only the value highlight on the sheet.
 * Buttons are the theme.json button element (.wp-element-button). Nothing here styles anything outside
 * the block, except the print rules at the end, which print the letter alone when the Print button is
 * used (Article VII record in docs/decisions.md, tool 3). Ctrl/Cmd+P prints the whole page.
 */

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

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

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

	--esal-leading-body: var(--wp--custom--leading--body, 1.6);
	--esal-leading-ui: var(--wp--custom--leading--ui, 1.4);
	--esal-tracking-body: var(--wp--custom--tracking--body, 0em);
	--esal-tracking-ui: var(--wp--custom--tracking--ui, 0.01em);
	--esal-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-adverse-action-letter *,
.wp-block-esservices-adverse-action-letter *::before,
.wp-block-esservices-adverse-action-letter *::after,
.esal-print-root * { box-sizing: border-box; }
.wp-block-esservices-adverse-action-letter :where(p, h3, h4, ul, li, fieldset, legend) { margin: 0; }
.wp-block-esservices-adverse-action-letter [hidden] { display: none !important; }
.wp-block-esservices-adverse-action-letter :focus-visible { outline: 2px solid var(--esal-action); outline-offset: 2px; }

/* The structural (mono) voice: label + meta, as in tool 1. */
.esal-label { font: 500 var(--esal-caption)/var(--esal-leading-ui) var(--esal-mono); letter-spacing: var(--esal-tracking-label); text-transform: uppercase; }
.esal-meta { font: 400 var(--esal-caption)/var(--esal-leading-body) var(--esal-mono); letter-spacing: var(--esal-tracking-body); }
.esal-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; }
.esal-cite { font: 500 var(--esal-caption)/var(--esal-leading-ui) var(--esal-mono); letter-spacing: var(--esal-tracking-ui); color: var(--esal-callout-label); overflow-wrap: anywhere; }
a.esal-cite { text-decoration: underline; }
a.esal-cite:hover { color: var(--esal-action); }
.wp-block-esservices-adverse-action-letter .esal-unavailable { font-size: var(--esal-small); color: var(--esal-text-muted); }

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

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

/* Segmented choices (radio cards) */
.esal-seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--esal-snug); margin: 0 0 var(--esal-base); }
.esal-seg-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
/* One card per row: the issue question, whose labels are too long for three columns in the form panel. */
.esal-seg-stack { grid-template-columns: minmax(0, 1fr); }
.esal-seg label { position: relative; display: block; cursor: pointer; }
.esal-seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.esal-seg span { display: block; height: 100%; background: var(--esal-surface); border: 1px solid var(--esal-line-strong); border-radius: 6px; padding: var(--esal-snug); font-size: var(--esal-small); line-height: var(--esal-leading-ui); }
.esal-seg span b { display: block; font-weight: 600; color: var(--esal-text-strong); }
.esal-seg span i { display: block; font-style: normal; color: var(--esal-text-muted); }
.esal-seg input:checked + span { border-color: var(--esal-action); box-shadow: inset 0 0 0 1px var(--esal-action); background: var(--esal-selected); }
.esal-seg input:focus-visible + span { outline: 2px solid var(--esal-action); outline-offset: 2px; }
.esal-sub legend { float: none; width: auto; margin: 0 0 var(--esal-tight); font-size: var(--esal-small); font-weight: 500; line-height: var(--esal-leading-ui); color: var(--esal-text-strong); }
.esal-sub legend em { font-style: normal; font-weight: 400; color: var(--esal-text-muted); }

/* Check boxes: the optional facts about the report, the city contracts, Missouri's record source. */
.esal-checks { display: grid; gap: var(--esal-tight); margin: 0 0 var(--esal-base); }
.esal-check { display: flex; align-items: flex-start; gap: var(--esal-tight); font-size: var(--esal-small); line-height: var(--esal-leading-ui); color: var(--esal-text-strong); cursor: pointer; }
.esal-check input { flex: none; width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--esal-action); cursor: pointer; }
.esal-panel .esal-check + .esal-f, .esal-panel .esal-f + .esal-check { margin-top: calc(-1 * var(--esal-tight)); }
.esal-panel > fieldset > .esal-check { margin: 0 0 var(--esal-base); }

/* Fields */
.esal-f { display: block; margin: 0 0 var(--esal-base); }
.esal-f > span { display: block; font-size: var(--esal-small); font-weight: 500; line-height: var(--esal-leading-ui); color: var(--esal-text-strong); margin-bottom: var(--esal-tight); }
.esal-f > span em { font-style: normal; font-weight: 400; color: var(--esal-text-muted); }
.esal-f > span em.esal-req { color: var(--esal-status-action); }
.esal-f input, .esal-f select, .esal-f textarea {
	display: block; width: 100%; min-width: 0; box-sizing: border-box;
	font: 400 var(--esal-body)/var(--esal-leading-ui) var(--esal-font); color: var(--esal-text-strong);
	background: var(--esal-surface); border: 1px solid var(--esal-line-strong); border-radius: 5px; padding: var(--esal-snug);
}
.esal-f textarea { resize: vertical; min-height: 5.5em; }
.esal-f input::placeholder, .esal-f textarea::placeholder { color: var(--esal-text-quiet); opacity: 1; }
.esal-f input:focus, .esal-f select:focus, .esal-f textarea:focus { outline: 2px solid var(--esal-action); outline-offset: 1px; border-color: var(--esal-action); }
.esal-f.esal-is-empty input, .esal-f.esal-is-empty textarea { border-color: var(--esal-status-action); box-shadow: inset 3px 0 0 var(--esal-status-action); }
.esal-f.esal-is-bad input { border-color: var(--esal-status-deficiency); box-shadow: inset 3px 0 0 var(--esal-status-deficiency); }
.esal-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--esal-base); }
.wp-block-esservices-adverse-action-letter .esal-hint { font-size: var(--esal-small); line-height: var(--esal-leading-body); color: var(--esal-text-muted); margin: calc(-1 * var(--esal-snug)) 0 var(--esal-base); }
.wp-block-esservices-adverse-action-letter .esal-hint.esal-is-action { color: var(--esal-status-action); }
.wp-block-esservices-adverse-action-letter .esal-hint.esal-is-bad { color: var(--esal-status-deficiency); }

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

/* The response deadline: ink with a left rule; amber when a date or a step is missing (tool 1's status pattern). */
.esal-deadline {
	margin: 0 0 var(--esal-base); padding: var(--esal-snug) var(--esal-base);
	font-size: var(--esal-small); line-height: var(--esal-leading-body);
	border-left: 3px solid var(--esal-line-strong); background: var(--esal-surface);
}
.esal-deadline:empty { display: none; }
.esal-deadline.esal-is-action { border-left-color: var(--esal-status-action); background: color-mix(in srgb, var(--esal-status-action) 8%, var(--esal-surface)); }
.esal-deadline.esal-is-bad { border-left-color: var(--esal-status-deficiency); background: color-mix(in srgb, var(--esal-status-deficiency) 6%, var(--esal-surface)); }
.esal-deadline b { font-weight: 600; color: var(--esal-text-strong); }
.esal-deadline .esal-dl-bad b { color: var(--esal-status-deficiency); }
.esal-conds { margin-top: var(--esal-tight); padding-left: 1.25em; display: grid; gap: var(--esal-hairline); color: var(--esal-text-muted); }

/* What to check first: one short amber line above the sheet (the count, and the required forms that go with
   this letter); the full list is the first section under the sheet. */
.esal-warn {
	margin: 0 0 var(--esal-base); padding: var(--esal-snug) var(--esal-base);
	font-size: var(--esal-small); line-height: var(--esal-leading-body);
	border-left: 3px solid var(--esal-status-action); background: color-mix(in srgb, var(--esal-status-action) 6%, var(--esal-surface));
}
.esal-warn b { font-weight: 600; color: var(--esal-status-action); }
.esal-warn .esal-list { margin-top: var(--esal-tight); }
.wp-block-esservices-adverse-action-letter .esal-sec-warn > h4 { color: var(--esal-status-action); }
.esal-warn a, .esal-list a { overflow-wrap: anywhere; }

/* The sheet */
.esal-paper {
	overflow-wrap: anywhere;
	background: var(--esal-paper); border: 1px solid var(--esal-line); border-radius: 3px;
	box-shadow: 0 24px 50px -30px color-mix(in srgb, var(--esal-paper-shadow) 35%, transparent);
	padding: var(--esal-loose) var(--esal-wide) var(--esal-wide);
	font-size: var(--esal-small); line-height: var(--esal-leading-body); color: var(--esal-paper-text);
}
.esal-paper :where(p, ul) { margin: 0; }
.esal-paper .esal-loading { color: var(--esal-text-muted); }
.esal-paper :where(p, ul) + :where(p, ul) { margin-top: var(--esal-base); }
.esal-lh { border-bottom: 1px solid var(--esal-line); padding-bottom: var(--esal-snug); margin-bottom: var(--esal-base); }
.esal-lh b { display: block; font-size: var(--esal-body); line-height: var(--esal-leading-ui); color: var(--esal-paper-strong); }
.esal-lh small { display: block; font-size: var(--esal-caption); line-height: var(--esal-leading-body); color: var(--esal-paper-muted); }
.esal-items { padding-left: 1.25em; }
.esal-items li + li { margin-top: var(--esal-hairline); }
.esal-paper .esal-sig { margin-top: var(--esal-loose); }
.esal-sigline { height: var(--esal-wide); border-bottom: 1px solid var(--esal-paper-rule); width: min(260px, 70%); margin: var(--esal-base) 0 var(--esal-tight); }
.esal-paper .esal-sig-name { margin-top: 0; }
.esal-paper .esal-encl { margin-top: var(--esal-loose); }
/* A page printed with the letter (New Jersey's rights page): a dashed rule marks the new page on screen. */
.esal-pagebreak { border-top: 1px dashed var(--esal-line-strong); margin: var(--esal-wide) calc(-1 * var(--esal-wide)) 0; }
.esal-paper .esal-pagebreak + * { margin-top: var(--esal-wide); }
.esal-att-title { font-size: var(--esal-body); font-weight: 600; color: var(--esal-paper-strong); }
.esal-paper .esal-att-h { margin-top: var(--esal-loose); }
.esal-att-src { font-size: var(--esal-caption); color: var(--esal-paper-muted); }
.esal-v { background: var(--esal-highlight); box-shadow: 0 0 0 2px var(--esal-highlight); border-radius: 1px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.esal-v.esal-nw { white-space: nowrap; }
.esal-v.esal-empty { background: none; box-shadow: none; border-bottom: 1px dashed var(--esal-line-strong); color: var(--esal-text-quiet); }

/* The lists under the sheet: "Send with this letter", "Before you send", the rules */
.esal-sec { margin-top: var(--esal-loose); padding-top: var(--esal-base); border-top: 1px solid var(--esal-line); font-size: var(--esal-small); line-height: var(--esal-leading-body); }
.wp-block-esservices-adverse-action-letter .esal-sec > h4 { color: var(--esal-text-muted); margin-bottom: var(--esal-snug); }
.esal-list { padding-left: 1.25em; display: grid; gap: var(--esal-tight); }
.esal-list li.esal-is-action { color: var(--esal-status-action); }
.esal-src { display: block; color: var(--esal-text-muted); font-size: var(--esal-caption); }
.esal-cites { list-style: none; padding: 0; display: grid; gap: var(--esal-tight); }
.esal-cites b { font-weight: 600; color: var(--esal-text-strong); margin-right: var(--esal-tight); }
.wp-block-esservices-adverse-action-letter .esal-sec .esal-notes { margin: var(--esal-snug) 0 0; }

@media (forced-colors: active) {
	.esal-seg input:checked + span { border: 3px solid Highlight; padding: calc(var(--esal-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-adverse-action-letter) { scroll-padding-bottom: calc(var(--wp--preset--spacing--section, 4.25rem) + var(--wp--preset--spacing--snug, 0.625rem) + env(safe-area-inset-bottom)); }
	.esal-gen { grid-template-columns: minmax(0, 1fr); }
	#esal-letter, #esal-paper { scroll-margin-top: var(--esal-snug); }
	.esal-edit { display: inline; }
	.esal-mbar {
		display: flex; position: sticky; bottom: 0; z-index: 2;
		margin: var(--esal-loose) calc(-1 * var(--esal-loose)) calc(-1 * var(--esal-loose));
		padding: var(--esal-snug) var(--esal-loose) calc(var(--esal-snug) + env(safe-area-inset-bottom));
		background: var(--esal-surface-inset); border-top: 1px solid var(--esal-line-strong); border-radius: 0 0 8px 8px;
	}
	.esal-mbar .esal-btn { flex: 1; }
}
@media (max-width: 760px) {
	.esal-panel { padding: var(--esal-base); }
	.esal-pagebreak { margin-inline: calc(-1 * var(--esal-base)); }
	.esal-mbar { margin: var(--esal-loose) calc(-1 * var(--esal-base)) calc(-1 * var(--esal-base)); padding-inline: var(--esal-base); }
	.esal-paper { padding: var(--esal-loose) var(--esal-base); }
}
@media (max-width: 560px) {
	.esal-row, .esal-seg-3 { grid-template-columns: minmax(0, 1fr); }
	.esal-toolbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 380px) {
	.esal-seg { grid-template-columns: minmax(0, 1fr); }
}

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

/* ── Print: the Print button prints the letter alone. view.js then adds .esal-print-root (a copy of the
   letter, a direct child of body, hidden on screen) and the class esal-printing on body, and removes both
   after printing. Ctrl/Cmd+P has neither, so it prints the whole page with its sample letters, table and
   FAQ (tool 2's pattern; Article VII record in docs/decisions.md). ── */
.esal-print-root { display: none; }
@media print {
	@page { margin: 1in; }
	body.esal-printing > :not(.esal-print-root) { display: none !important; }
	body.esal-printing { background: none; margin: 0; padding: 0; }
	.esal-print-root { display: block; overflow-wrap: anywhere; font-family: var(--esal-font); font-size: var(--esal-body); line-height: var(--esal-leading-body); color: var(--esal-paper-text); background: none; }
	.esal-print-root :where(p, ul) { margin: 0; }
	.esal-print-root :where(p, ul) + :where(p, ul) { margin-top: var(--esal-base); }
	.esal-print-root .esal-lh { border-bottom: 1px solid var(--esal-paper-rule); padding-bottom: var(--esal-snug); margin-bottom: var(--esal-base); }
	.esal-print-root .esal-lh b { display: block; color: var(--esal-paper-strong); }
	.esal-print-root .esal-lh small { display: block; font-size: var(--esal-small); color: var(--esal-paper-muted); }
	.esal-print-root .esal-items { padding-left: 1.25em; }
	.esal-print-root .esal-sig { margin-top: var(--esal-loose); break-after: avoid; }
	.esal-print-root .esal-sigline { height: 0.75in; width: 2.5in; border-bottom: 1px solid var(--esal-paper-rule); margin: 0 0 var(--esal-tight); break-after: avoid; }
	.esal-print-root .esal-sig-name { margin-top: 0; }
	.esal-print-root .esal-encl { margin-top: var(--esal-loose); }
	.esal-print-root .esal-v { background: none; box-shadow: none; }
	.esal-print-root .esal-v.esal-empty { border-bottom: 0; color: inherit; }
	.esal-print-root .esal-pagebreak { break-before: page; border: 0; margin: 0; height: 0; }
	.esal-print-root .esal-att-title { font-weight: 600; color: var(--esal-paper-strong); }
	.esal-print-root .esal-att-h { margin-top: var(--esal-loose); break-after: avoid; }
	.esal-print-root .esal-att-src { font-size: var(--esal-small); color: var(--esal-paper-muted); }
}
