/* ==========================================================================
   DRS Modals
   - Desktop/tablet: centered card, scrolling body, header stays in view.
   - Phone (<= 640px): full-screen sheet with a sticky header, safe-area aware.
   - Accessible: visible focus, 44px targets, 200% zoom / 320px reflow,
     Windows High Contrast (forced-colors), reduced motion.
   Adjust the custom properties below to match the site's brand.
   ========================================================================== */

.drs-modal {
	--drs-modal-width: 50rem;           /* ~800px max on desktop */
	--drs-modal-bg: #ffffff;
	--drs-modal-text: #1b1b1b;          /* 17:1 on white */
	--drs-modal-muted-bg: #f4f5f6;
	--drs-modal-border: #c9ccd1;
	--drs-modal-focus: #005ea2;         /* USWDS-style focus blue, 7:1 on white */
	--drs-modal-radius: 0.5rem;
	--drs-modal-pad: clamp(1rem, 3vw, 2rem);

	box-sizing: border-box;
	width: min(var(--drs-modal-width), calc(100% - 2rem));
	max-width: none;
	max-height: min(90vh, 60rem);
	max-height: min(90dvh, 60rem);
	margin: auto;
	padding: 0;
	border: 0;
	border-radius: var(--drs-modal-radius);
	background: var(--drs-modal-bg);
	color: var(--drs-modal-text);
	box-shadow: 0 1.5rem 3rem rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 0, 0, 0.06);
	overflow: hidden;
	overscroll-behavior: contain;
}

.drs-modal *,
.drs-modal *::before,
.drs-modal *::after {
	box-sizing: border-box;
}

.drs-modal[open] {
	display: flex;
	flex-direction: column;
}

.drs-modal::backdrop {
	background: rgba(17, 24, 39, 0.65);
}

.drs-modal__inner {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	min-height: 0;
}

/* ---------- Header ---------- */

.drs-modal__header {
	flex: 0 0 auto;
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.75rem 0.75rem 0.75rem var(--drs-modal-pad)!important;
	border-bottom: 1px solid var(--drs-modal-border);
	background: var(--drs-modal-bg);
}

.drs-modal__title {
	margin: 0;
	padding-top: 0.45rem;               /* optically centers with 44px button */
	font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.625rem);
	margin-top: 5px !important;
	line-height: 1.25;
	overflow-wrap: anywhere;            /* long words never force sideways scroll */
	color: inherit;
}

.drs-modal__close {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.75rem;                     /* 44px — WCAG 2.5.5 / 2.5.8 */
	height: 2.75rem;
	margin: 0;
	padding: 0;
	border: 1px solid transparent;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 1.75rem;
	line-height: 1;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
	transition: background-color 0.15s ease;
}

.drs-modal__close:hover {
	background: var(--drs-modal-muted-bg);
	border-color: var(--drs-modal-border);
}

/* ---------- Body ---------- */

.drs-modal__body {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overflow-x: hidden;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
	padding: var(--drs-modal-pad);
	padding-bottom: calc(var(--drs-modal-pad) + env(safe-area-inset-bottom, 0px));
	font-size: 1rem;
	line-height: 1.6;
	overflow-wrap: break-word;
}

.drs-modal__body > :first-child { margin-top: 0; }
.drs-modal__body > :last-child  { margin-bottom: 0; }

/* Theme "wide/full" alignments make no sense inside a modal. */
.drs-modal__body .alignwide,
.drs-modal__body .alignfull {
	width: auto;
	max-width: 100%;
	margin-left: 0;
	margin-right: 0;
}

/* Media never overflows. */
.drs-modal__body img,
.drs-modal__body svg,
.drs-modal__body video,
.drs-modal__body canvas,
.drs-modal__body audio,
.drs-modal__body embed,
.drs-modal__body object,
.drs-modal__body iframe {
	max-width: 100%;
}

.drs-modal__body img,
.drs-modal__body video {
	height: auto;
}

.drs-modal__body audio {
	width: 100%;
}

/* Fixed-width widgets (podcast players etc.) shrink to fit; their own height is kept. */
.drs-modal__body iframe {
	width: 100%;
	border: 0;
}

/* Video embeds: always 16:9 and fluid, whether from the Embed block or Custom HTML. */
.drs-modal__body .wp-block-embed.is-type-video iframe,
.drs-modal__body iframe[src*="youtube.com"],
.drs-modal__body iframe[src*="youtube-nocookie.com"],
.drs-modal__body iframe[src*="vimeo.com"],
.drs-modal__body .wp-block-video video {
	width: 100%;
	height: auto;
	aspect-ratio: 16 / 9;
}

/* Undo the theme's padding-hack wrapper so it doesn't double up with aspect-ratio. */
.drs-modal__body .wp-embed-responsive .wp-has-aspect-ratio .wp-block-embed__wrapper::before,
.drs-modal__body .wp-has-aspect-ratio .wp-block-embed__wrapper::before {
	display: none;
}
.drs-modal__body .wp-has-aspect-ratio iframe {
	position: static;
}

.drs-modal__body figure {
	margin-left: 0;
	margin-right: 0;
}

/* Wide tables scroll inside themselves, not the page (WCAG 1.4.10 reflow). */
.drs-modal__body .wp-block-table {
	overflow-x: auto;
}
.drs-modal__body table {
	width: 100%;
	border-collapse: collapse;
}

/* Columns stack on narrow modals even though the viewport may be wide. */
@container (max-width: 37.5rem) {
	.drs-modal__body .wp-block-columns { flex-wrap: wrap !important; }
	.drs-modal__body .wp-block-column { flex-basis: 100% !important; }
}
.drs-modal__body {
	container-type: inline-size;
}

/* ---------- Focus (visible on any background) ---------- */

.drs-modal :focus-visible {
	outline: 3px solid var(--drs-modal-focus);
	outline-offset: 2px;
	box-shadow: 0 0 0 5px #ffffff;
}

.drs-modal__body:focus-visible {
	outline-offset: -3px;               /* keyboard-scrollable region */
	box-shadow: none;
}

/* ---------- Page behind the modal ---------- */

html:has(.drs-modal[open]) {
	overflow: hidden;
	scrollbar-gutter: stable;           /* no layout jump when scrollbar hides */
}

/* ---------- Phones: full-screen sheet ---------- */

@media (max-width: 40rem) {
	.drs-modal {
		--drs-modal-pad: 1.125rem;
		width: 100%;
		height: 100%;
		max-height: none;
		margin: 0;
		border-radius: 0;
		box-shadow: none;
	}

	.drs-modal__header {
		padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
		padding-right: calc(0.5rem + env(safe-area-inset-right, 0px));
		padding-left: calc(var(--drs-modal-pad) + env(safe-area-inset-left, 0px));
		box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
	}

	.drs-modal__body {
		padding-left: calc(var(--drs-modal-pad) + env(safe-area-inset-left, 0px));
		padding-right: calc(var(--drs-modal-pad) + env(safe-area-inset-right, 0px));
	}

	.drs-modal__close {
		background: var(--drs-modal-muted-bg);
	}
}

/* Phones in landscape / very short screens: keep the header compact. */
@media (max-height: 30rem) {
	.drs-modal {
		max-height: 100vh;
		max-height: 100dvh;
	}
	.drs-modal__header {
		padding-top: 0.25rem;
		padding-bottom: 0.25rem;
	}
	.drs-modal__title {
		font-size: 1.125rem;
		padding-top: 0.6rem;
	}
}

/* ---------- Windows High Contrast / forced colors ---------- */

@media (forced-colors: active) {
	.drs-modal {
		border: 2px solid CanvasText;
	}
	.drs-modal__close {
		border-color: ButtonText;
	}
	.drs-modal :focus-visible {
		outline-color: Highlight;
	}
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: no-preference) {
	.drs-modal[open] {
		animation: drs-modal-in 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
	}
	.drs-modal[open]::backdrop {
		animation: drs-modal-fade 0.2s ease-out;
	}
}

@media (prefers-reduced-motion: no-preference) and (max-width: 40rem) {
	.drs-modal[open] {
		animation-name: drs-modal-up;
	}
}

@keyframes drs-modal-in {
	from { opacity: 0; transform: translateY(0.75rem) scale(0.98); }
	to   { opacity: 1; transform: none; }
}

@keyframes drs-modal-up {
	from { transform: translateY(100%); }
	to   { transform: none; }
}

@keyframes drs-modal-fade {
	from { opacity: 0; }
	to   { opacity: 1; }
}

/* ---------- Print: show modal content plainly if a user prints while open ---------- */

@media print {
	.drs-modal::backdrop { background: none; }
	.drs-modal { box-shadow: none; max-height: none; width: 100%; }
	.drs-modal__close { display: none; }
	.drs-modal__body { overflow: visible; }
}
