/**
 * Loving Obituary Assistant — launcher and panel.
 *
 * Quiet on purpose. This sits on a page somebody reached on the worst week of
 * their life, so nothing pulses, bounces or demands attention.
 *
 * Two layout rules are load-bearing rather than cosmetic. The launcher sits
 * above the safe-area inset on phones, so it never lands under a home
 * indicator; and it carries a generous bottom offset so it clears a sticky
 * "Add to Cart" bar or a cookie notice rather than covering one. Both were
 * requirements, not preferences, and both are unchanged.
 *
 * The colours are the house palette, the same tokens the Partner Portal and the
 * funeral-partner pages use: navy, gold, cream. They are declared locally
 * rather than imported so this plugin keeps working with the portal switched
 * off, and they are scoped to .ldoa- so nothing here can bleed into a theme.
 *
 * Contrast was measured, not eyeballed. Cream on navy is 15.1:1 and the gold
 * pen on navy is 8.5:1, both far past AA. The focus ring is deliberately two
 * rings -- gold against the navy pill, navy against the page -- because a
 * gold-only ring is 2.4:1 on a white background and would have failed the 3:1
 * that WCAG 2.2 asks of a focus indicator.
 */

.ldoa-launcher {
	/* Repeated here, not inherited: the launcher is a direct child of <body>. */
	--ldoa-navy: #0b1f3a;
	--ldoa-navy-2: #102a4c;
	--ldoa-gold: #c9a227;
	--ldoa-gold-2: #d9b73f;
	--ldoa-cream: #f7f5ef;

	position: fixed;
	right: 16px;
	bottom: calc( 84px + env( safe-area-inset-bottom, 0px ) );
	z-index: 99990;
	display: inline-flex;
	align-items: center;
	gap: 9px;
	max-width: calc( 100vw - 32px );
	padding: 11px 20px 11px 17px;
	border: 0;
	border-radius: 999px;
	background: linear-gradient( 160deg, var( --ldoa-navy-2 ) 0%, var( --ldoa-navy ) 100% );
	color: var( --ldoa-cream );
	font: inherit;
	font-size: 15px;
	font-weight: 600;
	letter-spacing: .01em;
	line-height: 1.2;

	/*
	 * The hairline is the whole difference between this and a generic dark
	 * chatbot bubble: a thread of gold around the navy, the same edge the
	 * portal puts on its cards.
	 */
	box-shadow:
		inset 0 0 0 1px rgba( 201, 162, 39, .45 ),
		0 10px 28px rgba( 11, 31, 58, .28 ),
		0 2px 6px rgba( 11, 31, 58, .18 );

	cursor: pointer;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
	transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease, opacity .18s ease;

	/* Plays once on arrival, and never again. Nothing here loops. */
	/*
	 * backwards, not both, and the difference is load-bearing. A filled
	 * animation outranks ordinary declarations for as long as it is filling,
	 * so `both` would hold opacity at 1 for the life of the page and quietly
	 * defeat the [aria-expanded="true"] rule below. backwards covers the delay
	 * and then gets out of the way.
	 */
	animation: ldoa-launcher-in .45s cubic-bezier( .22, .8, .3, 1 ) .35s backwards;
}

.ldoa-launcher__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	color: var( --ldoa-gold-2 );
}

.ldoa-launcher__label {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.ldoa-launcher:hover {
	background: linear-gradient( 160deg, #16365e 0%, var( --ldoa-navy-2 ) 100% );
	transform: translateY( -1px );
	box-shadow:
		inset 0 0 0 1px rgba( 201, 162, 39, .7 ),
		0 14px 34px rgba( 11, 31, 58, .32 ),
		0 2px 6px rgba( 11, 31, 58, .2 );
}

.ldoa-launcher:active {
	transform: translateY( 0 ) scale( .985 );
	box-shadow:
		inset 0 0 0 1px rgba( 201, 162, 39, .7 ),
		0 6px 16px rgba( 11, 31, 58, .3 );
}

/*
 * Two rings, so the indicator survives whatever the theme puts behind it: gold
 * against the pill, navy against the page. Measured at 8.5:1 and 16.5:1.
 */
.ldoa-launcher:focus-visible {
	outline: 3px solid var( --ldoa-navy );
	outline-offset: 3px;
	box-shadow:
		0 0 0 3px var( --ldoa-gold-2 ),
		0 10px 28px rgba( 11, 31, 58, .28 );
}

/* Older browsers, which have :focus but not :focus-visible. */
.ldoa-launcher:focus:not( :focus-visible ) { outline: none; }

/*
 * Opening the panel hands the corner over to it. The launcher settles back
 * rather than sitting lit under the backdrop, and the dialog grows out of the
 * same corner, so the two read as one movement. Driven entirely by the
 * aria-expanded the button already keeps honest -- no class, no extra script.
 */
.ldoa-launcher[aria-expanded="true"] {
	opacity: 0;
	transform: scale( .92 );
	pointer-events: none;
}

@keyframes ldoa-launcher-in {
	from { opacity: 0; transform: translateY( 10px ) scale( .96 ); }
	to   { opacity: 1; transform: none; }
}

@keyframes ldoa-dialog-in {
	from { opacity: 0; transform: translateY( 12px ) scale( .98 ); }
	to   { opacity: 1; transform: none; }
}

/*
 * Phones. The pill grows into a proper 48x48 target -- the floor the WCAG 2.2
 * target-size rule asks for, and the floor a thumb asks for on a moving bus --
 * and it keeps its words, because an unlabelled icon in the corner of a funeral
 * home's website is a riddle nobody grieving should have to solve.
 */
@media ( max-width: 600px ) {
	.ldoa-launcher {
		right: 14px;
		min-height: 48px;
		min-width: 48px;
		padding: 12px 20px 12px 16px;
		font-size: 15.5px;
		box-shadow:
			inset 0 0 0 1px rgba( 201, 162, 39, .5 ),
			0 12px 30px rgba( 11, 31, 58, .34 ),
			0 2px 6px rgba( 11, 31, 58, .2 );
	}
}

/* The panel ------------------------------------------------------------- */

.ldoa-panel {
	position: fixed;
	inset: 0;
	z-index: 99991;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20px;
}

.ldoa-panel[hidden] { display: none; }

.ldoa-panel__backdrop {
	position: absolute;
	inset: 0;
	background: rgba( 22, 26, 30, .55 );
}

.ldoa-panel__dialog {
	position: relative;
	width: 100%;
	max-width: 620px;
	transform-origin: bottom right;
	animation: ldoa-dialog-in .26s cubic-bezier( .22, .8, .3, 1 ) backwards;
	max-height: calc( 100vh - 40px );
	overflow-y: auto;
	padding: 24px;
	border-radius: 12px;
	background: #fff;
	color: #1d2327;
	box-shadow: 0 18px 50px rgba( 0, 0, 0, .3 );
}

.ldoa-panel__head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
}

.ldoa-panel__title { margin: 0; font-size: 21px; line-height: 1.3; }

.ldoa-panel__close {
	flex: 0 0 auto;
	width: 36px;
	height: 36px;
	border: 0;
	border-radius: 50%;
	background: #f1f2f3;
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
}
.ldoa-panel__close:focus-visible { outline: 3px solid #c9a227; outline-offset: 2px; }

.ldoa-panel__intro { margin: 10px 0 18px; color: #4a5560; font-size: 15px; }
.ldoa-panel__foot { margin: 18px 0 0; padding-top: 14px; border-top: 1px solid #e6e8ea; color: #6b7680; font-size: 13px; }

/* Steps and fields ------------------------------------------------------ */

.ldoa-steps { margin: 0; padding: 0; list-style: none; }
.ldoa-step__title { margin: 0 0 4px; font-size: 17px; }
.ldoa-step__intro { margin: 0 0 16px; color: #5a6570; font-size: 14px; }

.ldoa-field { margin: 0 0 16px; }
.ldoa-field__label { display: block; margin: 0 0 4px; font-weight: 600; font-size: 15px; }
.ldoa-field__hint { margin: 0 0 6px; color: #6b7680; font-size: 13px; }
.ldoa-req { font-weight: 400; color: #6b7680; font-size: 13px; }

.ldoa-field input[type="text"],
.ldoa-field textarea,
.ldoa-field select,
.ldoa-refine input[type="text"],
.ldoa-draft {
	width: 100%;
	padding: 10px 12px;
	border: 1px solid #c3c7cb;
	border-radius: 6px;
	background: #fff;
	color: inherit;
	font: inherit;
	font-size: 15px;
	box-sizing: border-box;
}

.ldoa-field input:focus-visible,
.ldoa-field textarea:focus-visible,
.ldoa-field select:focus-visible,
.ldoa-refine input:focus-visible,
.ldoa-draft:focus-visible {
	outline: 3px solid #c9a227;
	outline-offset: 1px;
	border-color: #8a8f94;
}

.ldoa-field [aria-invalid="true"] { border-color: #8c3b2f; }
.ldoa-field__error { margin: 6px 0 0; color: #8c3b2f; font-size: 13px; }
.ldoa-field__error[hidden] { display: none; }

/* The honeypot. Removed from the page for anyone who can perceive it. */
.ldoa-hp {
	position: absolute;
	left: -9999px;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

/* Navigation and buttons ------------------------------------------------ */

.ldoa-nav {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-top: 20px;
	padding-top: 16px;
	border-top: 1px solid #e6e8ea;
}

.ldoa-progress { margin-left: auto; color: #6b7680; font-size: 13px; }

.ldoa-btn {
	padding: 10px 18px;
	border: 1px solid #2f3a44;
	border-radius: 6px;
	background: #fff;
	color: #2f3a44;
	font: inherit;
	font-size: 15px;
	cursor: pointer;
}
.ldoa-btn:focus-visible { outline: 3px solid #c9a227; outline-offset: 2px; }
.ldoa-btn:disabled { opacity: .55; cursor: default; }
/*
 * Written as a compound class, and the colour marked important.
 *
 * This panel is injected into whatever theme a site happens to run, and on
 * staging the theme won: the dark background applied and the white text did
 * not, leaving "Write my draft" in near-black on near-black. A single class is
 * 0-1-0, which any theme rule of equal weight beats simply by loading later --
 * a block theme's generated .wp-element-button does exactly that.
 *
 * Repeating the class raises this to 0-2-0, which beats equal-weight and most
 * descendant rules. !important on the colour ALONE covers the rest, including
 * an id-scoped theme rule, and is deliberately not applied to anything else
 * here: the risk being bought off is a button a grieving family cannot read.
 *
 * It cannot be scoped under .ldoa-panel for specificity instead -- the resume
 * page uses these same classes outside the panel, and one of them is an <a>
 * rather than a <button>, so an element-qualified selector would miss it too.
 */
.ldoa-btn.ldoa-btn--primary { background: #2f3a44; color: #fff !important; }
.ldoa-btn--quiet { border-color: #c3c7cb; color: #4a5560; }
.ldoa-btn[hidden] { display: none; }

/* The draft ------------------------------------------------------------- */

.ldoa-result[hidden] { display: none; }
.ldoa-result__title { margin: 0 0 4px; font-size: 18px; }
.ldoa-result__note { margin: 0 0 12px; color: #5a6570; font-size: 14px; }
.ldoa-draft { min-height: 260px; line-height: 1.6; resize: vertical; }

.ldoa-refine { margin-top: 18px; }
.ldoa-refine input[type="text"] { margin-bottom: 10px; }

.ldoa-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

.ldoa-status { margin: 14px 0 0; min-height: 1.4em; color: #4a5560; font-size: 14px; }
.ldoa-panel.is-busy .ldoa-status { color: #2f3a44; font-weight: 600; }

.screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect( 1px, 1px, 1px, 1px );
	white-space: nowrap;
}

/*
 * Asked for less movement, given less movement -- the entrance, the dialog's
 * arrival, the hover lift and every transition. What is left is the plain
 * change of state, which is the point of the animation anyway. The launcher
 * still disappears when the panel opens; it just stops sliding to do it.
 */
@media ( prefers-reduced-motion: reduce ) {
	.ldoa-launcher,
	.ldoa-btn,
	.ldoa-panel__dialog {
		transition: none;
		animation: none;
	}
	.ldoa-launcher:hover,
	.ldoa-launcher:active { transform: none; }
	.ldoa-launcher[aria-expanded="true"] { transform: none; }
}

/* Come back to this later ---------------------------------------------- */

.ldoa-keep {
	margin-top: 20px;
	padding-top: 16px;
	border-top: 1px solid #e6e8ea;
}
.ldoa-keep__title { margin: 0 0 6px; font-size: 15px; }
.ldoa-keep input[type="email"] {
	width: 100%;
	margin-bottom: 10px;
	padding: 10px 12px;
	border: 1px solid #c3c7cb;
	border-radius: 6px;
	font: inherit;
	font-size: 15px;
	box-sizing: border-box;
}
.ldoa-keep input[type="email"]:focus-visible {
	outline: 3px solid #c9a227;
	outline-offset: 1px;
	border-color: #8a8f94;
}
.ldoa-keep input[aria-invalid="true"] { border-color: #8c3b2f; }

.ldoa-order { margin-top: 18px; padding-top: 16px; border-top: 1px solid #e6e8ea; }

/* Complete your obituary program ---------------------------------------- *
 *
 * The three screens between an approved obituary and an order. They borrow the
 * questionnaire's type and spacing on purpose: a family should not be able to
 * tell that they have crossed from one part of this panel into another, because
 * as far as they are concerned they have not.
 */

.ldoa-stage__title {
	margin: 0 0 4px;
	font-size: 17px;
}
.ldoa-stage__intro {
	margin: 0 0 16px;
	color: #5a6570;
	font-size: 14px;
}

/*
 * The heading takes focus when a screen appears, so that a screen reader is
 * told where it now is. It is not an interactive control and must not look like
 * one -- but it still needs a visible ring, because somebody navigating by
 * keyboard needs to see where focus went as much as anyone.
 */
.ldoa-stage__title:focus { outline: none; }
.ldoa-stage__title:focus-visible {
	outline: 3px solid #c9a227;
	outline-offset: 3px;
}

/* Choosing a format ------------------------------------------------------ *
 *
 * Each option is a whole tappable row rather than a small circle with words
 * beside it. On a phone, held one-handed, by somebody who has been crying, a
 * 13px radio is not a target — the row is, and the words are its label, so
 * they are read out with it too.
 */
.ldoa-formats {
	margin: 0 0 12px;
	padding: 0;
	border: 0;
}

.ldoa-format {
	display: flex;
	align-items: center;
	gap: 12px;
	min-height: 52px;
	margin-bottom: 8px;
	padding: 10px 14px;
	border: 1px solid #c3c7cb;
	border-radius: 8px;
	cursor: pointer;
	font-size: 15px;
	line-height: 1.4;
}
.ldoa-format:hover { border-color: #8a8f94; }

.ldoa-format input[type="radio"] {
	flex: 0 0 auto;
	width: 20px;
	height: 20px;
	margin: 0;
	accent-color: #2f3a44;
}
/*
 * The ring goes on the ROW, not on the control, so keyboard focus lands on
 * something the size of the thing being chosen.
 */
.ldoa-format:focus-within {
	outline: 3px solid #c9a227;
	outline-offset: 2px;
	border-color: #8a8f94;
}
/*
 * Checked state carries a border and a background, not colour alone: about one
 * man in twelve would otherwise be told which format he had chosen by a hue he
 * cannot separate from the one beside it.
 */
.ldoa-format:has( input:checked ) {
	border-color: #2f3a44;
	border-width: 2px;
	background: #f4f6f8;
	padding: 9px 13px;
}
.ldoa-format__label { flex: 1 1 auto; }

/*
 * What changing format does to what they wrote. Bordered rather than tinted,
 * for the same reason as above, and it appears in place rather than replacing
 * the screen — a family should be able to read it while still looking at the
 * choice it describes.
 */
.ldoa-format__change {
	margin: 0 0 14px;
	padding: 12px 14px;
	border-left: 4px solid #c9a227;
	background: #fbf9f2;
	font-size: 14px;
	line-height: 1.55;
}
.ldoa-format__change p { margin: 0 0 8px; }
.ldoa-format__change p:last-child { margin-bottom: 0; }

.ldoa-remaining {
	margin: 8px 0 0;
	padding-left: 20px;
	color: #4a5560;
	font-size: 14px;
	line-height: 1.6;
}
.ldoa-remaining li { margin-bottom: 6px; }

/*
 * Consent, and the reason it is styled at all.
 *
 * The whole control is the label, so the words are tappable and are read out
 * with the box. min-height keeps the tap target at 44px even when the wording
 * wraps to one line on a wide phone, and the checkbox itself is enlarged --
 * a 13px default checkbox is not something to hand somebody who is grieving,
 * tired, and holding the phone in one hand.
 */
.ldoa-field__check {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	min-height: 44px;
	padding: 6px 0;
	cursor: pointer;
	font-size: 15px;
	line-height: 1.5;
}
.ldoa-field__check input[type="checkbox"] {
	flex: 0 0 auto;
	width: 22px;
	height: 22px;
	margin: 0;
	accent-color: #2f3a44;
}
.ldoa-field__check input[type="checkbox"]:focus-visible {
	outline: 3px solid #c9a227;
	outline-offset: 2px;
}

/*
 * On a phone the stage buttons stack and go full width, so neither is a small
 * target beside another small target, and Continue is never a thumb-width away
 * from Back.
 */
@media ( max-width: 480px ) {
	.ldoa-stage .ldoa-nav {
		flex-direction: column-reverse;
		align-items: stretch;
	}
	.ldoa-stage .ldoa-nav .ldoa-btn {
		width: 100%;
		min-height: 48px;
	}
}

/* The resume page ------------------------------------------------------- */

.ldoa-resume {
	max-width: 680px;
	margin: 0 auto;
	padding: 40px 20px 60px;
	font: 16px/1.6 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
	color: #1d2327;
}
.ldoa-resume__title { margin: 0 0 12px; font-size: 26px; font-weight: 600; }
.ldoa-resume__subtitle { margin: 0 0 8px; font-size: 17px; font-weight: 600; }
.ldoa-resume__note { margin: 0 0 16px; font-size: 17px; }
.ldoa-resume__hint { margin: 0 0 12px; color: #5a6570; font-size: 15px; }
.ldoa-resume__privacy {
	margin-top: 32px;
	padding-top: 20px;
	border-top: 1px solid #e6e8ea;
}
.ldoa-resume__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.ldoa-btn--danger { border-color: #8c3b2f; color: #8c3b2f; }
/* Same trap as the primary button: this one turns solid red on hover, so a
   theme holding the text dark makes "Delete my draft" unreadable at the moment
   somebody is reaching for it. */
.ldoa-btn.ldoa-btn--danger:hover { background: #8c3b2f; color: #fff !important; }
.ldoa-resume-page .ldoa-launcher { display: none; }
