/**
 * EM ISI — front-end styles.
 *
 * Dependency-free, theme-independent. Neutral palettes only (regulatory:
 * no brand styling inside the ISI). Hand-authored CSS — no build step.
 */

/* -------------------------------------------------------------------------- *
 * Color schemes (neutral only)
 * -------------------------------------------------------------------------- */
.em-isi {
	--em-isi-bg: #f4f5f6;
	--em-isi-text: #1a1a1a;
	--em-isi-link: #0b57d0;
	--em-isi-border: #d0d3d6;
	--em-isi-bar-bg: #e6e8ea;
	/* One viewport-height unit. Plain vh is the tallest the viewport gets, with a
	   phone's browser toolbars hidden; svh is the height with them showing, so the
	   tray's caps never run past what's visible. Old browsers fall back to vh. */
	--em-isi-vh: 1vh;
	--em-isi-collapsed-height: calc(33 * var(--em-isi-vh));
	/* Indication share of the two-column row; overridden from Settings. */
	--em-isi-indication-width: 35%;
	/* Space between stacked sections (Indication, Safety, PI links, References). */
	--em-isi-section-gap: 15px;

	box-sizing: border-box;
	color: var(--em-isi-text);
	background: var(--em-isi-bg);
}

@supports (height: 1svh) {
	.em-isi {
		--em-isi-vh: 1svh;
	}
}

/* -------------------------------------------------------------------------- *
 * Typography
 *
 * The plugin's own font family / sizes / line heights live under
 * .em-isi--own-type (the default). Settings → "Use the theme's typography"
 * swaps that class for .em-isi--theme-type, so none of these declarations
 * apply and the theme's body and heading rules show through.
 * -------------------------------------------------------------------------- */
.em-isi--own-type {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 12px;
	line-height: 1.5;
}

.em-isi--own-type h1,
.em-isi--own-type h2,
.em-isi--own-type h3,
.em-isi--own-type h4 {
	font-size: 13px;
	line-height: 1.3;
}

.em-isi--own-type .em-isi-references__content {
	font-size: 11px;
}

.em-isi--own-type .em-isi__toggle {
	font-size: 12px;
}

/* Buttons don't inherit type from their parent by default. */
.em-isi--theme-type .em-isi__toggle {
	font-family: inherit;
	font-size: inherit;
}

.em-isi *,
.em-isi *::before,
.em-isi *::after {
	box-sizing: border-box;
}

.em-isi--scheme-white {
	--em-isi-bg: #ffffff;
	--em-isi-text: #1a1a1a;
	--em-isi-link: #0b57d0;
	--em-isi-border: #d9d9d9;
	--em-isi-bar-bg: #f2f2f2;
}

.em-isi--scheme-light-gray {
	--em-isi-bg: #f4f5f6;
	--em-isi-text: #1a1a1a;
	--em-isi-link: #0b57d0;
	--em-isi-border: #d0d3d6;
	--em-isi-bar-bg: #e6e8ea;
}

.em-isi--scheme-dark-slate {
	--em-isi-bg: #2b303a;
	--em-isi-text: #f0f1f3;
	--em-isi-link: #9ec1ff;
	--em-isi-border: #454b57;
	--em-isi-bar-bg: #1f242c;
}

.em-isi a {
	color: var(--em-isi-link);
	text-decoration: underline;
}

.em-isi h1,
.em-isi h2,
.em-isi h3,
.em-isi h4 {
	margin: 0.6em 0 0.3em;
}

.em-isi p,
.em-isi ul,
.em-isi ol {
	margin: 0 0 0.6em;
}

/* Sections are spaced by --em-isi-section-gap (the content's row-gap), not by
   their contents' margins: the first element of a section starts flush at the top
   and the last ends flush at the bottom. Scoped under .em-isi so it also outranks
   a theme's heading margins, e.g. `.em-isi .em-isi__content h2`. */
.em-isi .em-isi-region__inner > :first-child,
.em-isi .em-isi-references__content > :first-child {
	margin-top: 0;
}

.em-isi .em-isi-region__inner > :last-child,
.em-isi .em-isi-references__content > :last-child {
	margin-bottom: 0;
}

/* -------------------------------------------------------------------------- *
 * Content layout — flex-wrap (two-column by default)
 *
 * Indication + Safety sit on the first row; PI links and References wrap onto
 * their own full-width rows below. Using flex-wrap (not grid tracks) means a
 * very long Safety block just makes its row taller and the scroll container
 * scrolls — its content can never bleed into the rows beneath it.
 * -------------------------------------------------------------------------- */
.em-isi__content {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-start;
	column-gap: 24px;
	row-gap: var(--em-isi-section-gap);
	padding: 12px 24px;
}

.em-isi-region {
	min-width: 0;
}

.em-isi-region--indication {
	flex: 0 0 var(--em-isi-indication-width);
	max-width: var(--em-isi-indication-width);
}

.em-isi-region--safety {
	/* Fills the rest of the first row next to Indication. */
	flex: 1 1 0;
	min-width: 0;
}

/* Full safety body copy — a continuation of the Safety column, so it matches
   that column's width (the row minus Indication and the gap) and aligns beneath it. */
.em-isi-region--safety-body {
	flex: 0 0 auto;
	width: calc(100% - var(--em-isi-indication-width) - 24px);
	max-width: calc(100% - var(--em-isi-indication-width) - 24px);
	margin-left: auto;
}

.em-isi-region--pi-links {
	flex: 0 0 100%;
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding-top: 8px;
	border-top: 1px solid var(--em-isi-border);
}

.em-isi-region--references {
	flex: 0 0 100%;
}

.em-isi-pi-link {
	display: inline-block;
	padding: 8px 14px;
	color: var(--em-isi-link);
	font-weight: 600;
	text-decoration: none;
	border: 1px solid var(--em-isi-link);
	border-radius: 3px;
}

.em-isi-pi-link:hover,
.em-isi-pi-link:focus {
	text-decoration: underline;
}

.em-isi-references__title {
	font-weight: 700;
}

/* -------------------------------------------------------------------------- *
 * Full-width layout — every region on its own full-width row.
 *
 * The inline footer carries .em-isi--full-width. The floating tray carries one
 * layout class per state (collapsed / expanded) so it can change layout when
 * it expands.
 * -------------------------------------------------------------------------- */
.em-isi--full-width .em-isi-region,
.em-isi--sticky.em-isi--collapsed-full-width:not(.is-expanded) .em-isi-region,
.em-isi--sticky.em-isi--expanded-full-width.is-expanded .em-isi-region {
	flex: 0 0 100%;
	width: 100%;
	max-width: 100%;
	margin-left: 0;
}

/* One column: regions flow into one another, so there's no gap between them. */
.em-isi--full-width .em-isi__content,
.em-isi--sticky.em-isi--collapsed-full-width:not(.is-expanded) .em-isi__content,
.em-isi--sticky.em-isi--expanded-full-width.is-expanded .em-isi__content {
	gap: 0;
}

/* -------------------------------------------------------------------------- *
 * Floating (sticky) tray
 * -------------------------------------------------------------------------- */
.em-isi--sticky {
	position: fixed;
	bottom: 0;
	left: 0;
	z-index: 9990;
	display: flex;
	flex-direction: column;
	width: 100%;
	max-height: var(--em-isi-collapsed-height);
	/* Clip the box; the inner .em-isi__content is the scroller. */
	overflow: hidden;
	/* Matches the bar when a custom bar color is set. */
	border-top: 1px solid var(--em-isi-bar-custom-bg, var(--em-isi-border));
	box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.12);
	transition: max-height 0.25s ease;
}

/* Toggle bar stays pinned at the top of the tray, above the scrolling content. */
.em-isi--sticky .em-isi__bar {
	flex: 0 0 auto;
}

/*
 * The content box is the single scroll area. An explicit max-height
 * (tray height − toggle bar) guarantees it scrolls, independent of any
 * flexbox shrink behaviour — so the safety text can never overflow the tray.
 */
.em-isi--sticky .em-isi__content {
	flex: 1 1 auto;
	min-height: 0;
	max-height: calc(
		var(--em-isi-collapsed-height) - var(--em-isi-bar-height, 52px)
	);
	overflow-y: auto;
	overscroll-behavior: contain;
}

/* The collapsed peek is never a scroller at any width: text past the capped
   height is simply clipped by the tray, and the page scrolls instead. "Keep in
   view" (desktop) restores scrolling below, as a safety net for a very tall
   summary. */
.em-isi--sticky:not(.is-expanded) .em-isi__content {
	overflow-y: hidden;
}

/* Expanded state — grow upward but stop just below a fixed/sticky header
   (--em-isi-header-offset is measured in JS; falls back to a small gap). */
.em-isi--sticky.is-expanded {
	max-height: calc(100 * var(--em-isi-vh) - var(--em-isi-header-offset, 16px));
}

.em-isi--sticky.is-expanded .em-isi__content {
	max-height: calc(
		100 * var(--em-isi-vh) - var(--em-isi-header-offset, 16px) - var(--em-isi-bar-height, 52px)
	);
}

/* Hidden once the inline footer scrolls into view. */
.em-isi--sticky.is-docked {
	display: none;
}

/* Collapsed tray shows only the Indication + Safety peek. Expanding the tray
   (and the inline footer) reveals the rest of the ISI. */
.em-isi--sticky:not(.is-expanded) .em-isi-region--safety-body,
.em-isi--sticky:not(.is-expanded) .em-isi-region--pi-links,
.em-isi--sticky:not(.is-expanded) .em-isi-region--references {
	display: none;
}

/*
 * "Keep in view" (.em-isi--tray-fit): size the COLLAPSED tray to fit its
 * content (Indication + Safety) so it's fully visible, instead of the fixed
 * collapsed peek — bounded by the viewport (minus header/bar) so it stays
 * onscreen and scrolls only if the summary itself is very tall. The
 * Expand/Collapse toggle is untouched and still expands to the full viewport.
 *
 * Desktop only: on small screens a content-sized tray would cover the page, so
 * mobile always uses the fixed collapsed height.
 */
@media (min-width: 768px) {
	.em-isi--sticky.em-isi--tray-fit:not(.is-expanded) {
		max-height: calc(100 * var(--em-isi-vh) - var(--em-isi-header-offset, 16px));
	}

	.em-isi--sticky.em-isi--tray-fit:not(.is-expanded) .em-isi__content {
		max-height: calc(
			100 * var(--em-isi-vh) - var(--em-isi-header-offset, 16px) - var(--em-isi-bar-height, 52px)
		);
		overflow-y: auto;
	}
}

/*
 * Optional desktop minimize (.em-isi--desktop-minimize, from Settings): once the
 * tray has been expanded and collapsed again (.is-minimized, set by the JS) it
 * condenses to just the bar. The mobile equivalent (.em-isi--mobile-minimize)
 * is in the mobile block below. The tray still opens at the collapsed height;
 * the toggle brings it back.
 */
@media (min-width: 768px) {
	.em-isi--sticky.em-isi--desktop-minimize.is-minimized .em-isi__content {
		display: none;
	}
}

/* -------------------------------------------------------------------------- *
 * Toggle bar
 * -------------------------------------------------------------------------- */
.em-isi__bar {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 12px;
	padding: 4px 24px;
	/* The custom properties are only set when a bar color / bar text color is
	   chosen in Settings; otherwise the color scheme's values apply. */
	color: var(--em-isi-bar-custom-text, var(--em-isi-text));
	background: var(--em-isi-bar-custom-bg, var(--em-isi-bar-bg));
	border-bottom: 1px solid var(--em-isi-bar-custom-bg, var(--em-isi-border));
}

/* Desktop bar with text: the text is centered on the bar (equal side tracks),
   with the toggle pinned to the right. */
/* Both side tracks are at least as wide as the toggle (--em-isi-toggle-width,
   measured in em-isi.js), so the text stays centered but can never run
   underneath the Expand/Collapse control; long text truncates or wraps instead. */
.em-isi__bar--labeled {
	display: grid;
	grid-template-columns:
		minmax(var(--em-isi-toggle-width, auto), 1fr)
		auto
		minmax(var(--em-isi-toggle-width, auto), 1fr);
}

.em-isi__bar--labeled .em-isi__desktop-label {
	grid-column: 2;
}

.em-isi__bar--labeled .em-isi__toggle {
	grid-column: 3;
	justify-self: end;
}

/* Desktop text aligned left or right (Settings): the text gets the space beside
   the toggle instead of the centered middle track. */
.em-isi__bar--desktop-left,
.em-isi__bar--desktop-right {
	grid-template-columns: minmax(0, 1fr) auto;
}

.em-isi__bar--desktop-left .em-isi__desktop-label,
.em-isi__bar--desktop-right .em-isi__desktop-label {
	grid-column: 1;
}

.em-isi__bar--desktop-left .em-isi__toggle,
.em-isi__bar--desktop-right .em-isi__toggle {
	grid-column: 2;
}

.em-isi__bar--desktop-left .em-isi__desktop-label,
.em-isi__bar--mobile-left .em-isi__mobile-label {
	text-align: left;
}

.em-isi__bar--desktop-right .em-isi__desktop-label,
.em-isi__bar--mobile-right .em-isi__mobile-label {
	text-align: right;
}

.em-isi__desktop-label,
.em-isi__mobile-label {
	flex: 1 1 auto;
	font-weight: 700;
	text-align: center;
	text-transform: uppercase;
	letter-spacing: 0.02em;
}

/* Superscript / subscript in the bar text: shifted with `top` rather than vertical-align
   so they don't stretch the line box (which would grow the bar or get clipped). */
.em-isi__desktop-label :is(sup, sub),
.em-isi__mobile-label :is(sup, sub) {
	position: relative;
	font-size: 0.65em;
	line-height: 0;
	vertical-align: baseline;
}

.em-isi__desktop-label sup,
.em-isi__mobile-label sup {
	top: -0.5em;
}

.em-isi__desktop-label sub,
.em-isi__mobile-label sub {
	top: 0.25em;
}

/* Mobile-only; the desktop bar uses .em-isi__desktop-label (when set). */
.em-isi__mobile-label {
	display: none;
}

.em-isi__toggle {
	display: inline-flex;
	/* Never squeezed by long bar text: the text gives way, not the control (and its icon). */
	flex: 0 0 auto;
	align-items: center;
	justify-content: center;
	gap: 8px;
	/* Accessible 44x44 tap target. */
	min-width: 44px;
	min-height: 44px;
	padding: 0 8px;
	color: var(--em-isi-bar-custom-text, var(--em-isi-link));
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.02em;
	background: none;
	border: 0;
	cursor: pointer;
}

/*
 * Optional fixed bar height (.em-isi--bar-height, from Settings): the bar is
 * exactly --em-isi-bar-custom-height tall, border included, instead of growing
 * to fit the 44px toggle. The toggle drops its min-height and stretches to the
 * bar (it keeps its 44px min-width), and the labels stay on one line so a
 * narrow screen can't wrap the bar taller than the setting.
 */
.em-isi--sticky.em-isi--bar-height .em-isi__bar {
	box-sizing: border-box;
	height: var(--em-isi-bar-custom-height);
	padding-top: 0;
	padding-bottom: 0;
}

.em-isi--sticky.em-isi--bar-height .em-isi__toggle {
	align-self: stretch;
	min-height: 0;
	line-height: 1;
}

.em-isi--sticky.em-isi--bar-height .em-isi__desktop-label,
.em-isi--sticky.em-isi--bar-height .em-isi__mobile-label {
	min-width: 0;
	overflow: hidden;
	line-height: 1;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.em-isi__toggle-icon {
	width: 0;
	height: 0;
	border-right: 5px solid transparent;
	border-bottom: 6px solid currentColor;
	border-left: 5px solid transparent;
	transition: transform 0.2s ease;
}

.em-isi--sticky.is-expanded .em-isi__toggle-icon {
	transform: rotate(180deg);
}

/* -------------------------------------------------------------------------- *
 * Inline static footer
 * -------------------------------------------------------------------------- */
.em-isi--static {
	position: relative;
	border-top: 1px solid var(--em-isi-border);
}

/*
 * The inline band always spans the full viewport, so its background and top
 * border reach the edges in BOTH width modes. We target by ID + !important to
 * beat theme container rules (e.g. `.site-content > :not(.alignwide)...`) that
 * impose a max-width, centering, and padding on direct children. Bottom margin
 * is zeroed so the band sits flush to the footer; top spacing stays with the
 * theme.
 */
#em-isi-static.em-isi--static {
	left: 50%;
	right: 50%;
	width: 100vw !important;
	max-width: 100vw !important;
	margin-right: -50vw !important;
	margin-left: -50vw !important;
	margin-bottom: 0 !important;
	padding-right: 0 !important;
	padding-left: 0 !important;
}

/*
 * "Site content width" mode: the band stays full-bleed, but its CONTENT is
 * constrained to the theme's content width and centered — so the copy, PI
 * links and references line up with the rest of the page. Uses the embark
 * content-width variable with a fallback for non-embark themes. "Full width"
 * mode omits em-isi--contained, so the content fills the band.
 */
#em-isi-static.em-isi--contained .em-isi__content {
	max-width: var(--em--width--default, 1200px);
	margin-right: auto;
	margin-left: auto;
}

.em-isi--static .em-isi__bar {
	display: none;
}
/* The static footer is fully expanded — no cap, no internal scroll; the
   flex-wrap layout shows every region. */

/* -------------------------------------------------------------------------- *
 * Bar text wrapping, phones and tablets (.em-isi--mobile-wrap, from Settings):
 * instead of truncating with an ellipsis, the text wraps and the bar grows to
 * hold it. A custom bar height becomes the minimum; the bar gets back a little
 * vertical padding so wrapped lines don't touch its edges. Covers both bar
 * texts: the mobile one below 768px, the desktop one up to 1000px.
 * -------------------------------------------------------------------------- */
@media (max-width: 1000px) {
	.em-isi--sticky.em-isi--mobile-wrap .em-isi__bar {
		height: auto;
		min-height: var(--em-isi-bar-custom-height, 0);
		padding-top: 4px;
		padding-bottom: 4px;
	}

	.em-isi--sticky.em-isi--mobile-wrap .em-isi__desktop-label,
	.em-isi--sticky.em-isi--mobile-wrap .em-isi__mobile-label {
		overflow: visible;
		line-height: 1.25;
		text-overflow: clip;
		white-space: normal;
	}
}

/* -------------------------------------------------------------------------- *
 * Mobile — stack columns. The tray opens at the same collapsed height as
 * desktop; once it has been expanded and collapsed again (.is-minimized) it
 * condenses to just the bar + toggle.
 * -------------------------------------------------------------------------- */
@media (max-width: 767px) {
	/* Single column: every region full width, stacked in reading order. */
	.em-isi-region--indication,
	.em-isi-region--safety,
	.em-isi-region--safety-body {
		flex: 0 0 100%;
		width: 100%;
		max-width: 100%;
		margin-left: 0;
	}

	.em-isi__content {
		column-gap: 0;
	}

	.em-isi__desktop-label {
		display: none;
	}

	.em-isi__mobile-label {
		display: block;
	}

	/* Label centered in the space beside the toggle. */
	.em-isi__bar,
	.em-isi__bar--labeled {
		display: flex;
		justify-content: space-between;
	}

	/* Minimized on mobile (when enabled in Settings): only the single-line bar shows. */
	.em-isi--sticky.em-isi--mobile-minimize.is-minimized .em-isi__content {
		display: none;
	}
}
