/**
 * Overlay behavior runtime CSS (static, enqueued by
 * includes/behaviors/class-overlay.php only on pages using the behavior).
 *
 * House rule: every base rule sits in :where() (zero specificity) so
 * per-instance contract CSS and author classes always win.
 *
 * Positioning model (behaviors spec 6.2 + contract E1): the view module
 * writes --lumitra-x/--lumitra-y via floating-ui; this file consumes them. The
 * anchored absolute position only applies once the island is hydrated
 * (.lumitra-hydrated on the root): before hydration and without JS the panel
 * stays IN FLOW, which is exactly the details/summary and visible-list
 * degradation contract (contract 6.2).
 */

/* Root wrapper: the positioning context for anchored kinds. */
:where(.lumitra-overlay) {
	position: relative;
}

/* Anchored panel, hydrated: floating-ui drives the coordinates. */
:where(.lumitra-overlay.lumitra-hydrated .lumitra-overlay__panel.is-anchored) {
	position: absolute;
	left: var(--lumitra-x, 0);
	top: var(--lumitra-y, calc(100% + 8px));
	z-index: var(--lumitra-z-overlay, 30);
	min-width: max-content;
}

/* Panels never inherit stray margins into the anchored box. */
:where(.lumitra-overlay__panel.is-anchored) {
	margin: 0;
}

/* --------------------------------------------------------------------- */
/* Modal (<dialog>)                                                      */
/* --------------------------------------------------------------------- */

:where(dialog.lumitra-overlay__panel) {
	padding: 0;
	border: none;
	max-width: min(90vw, 64rem);
	max-height: 85vh;
	overflow: auto;
}

/*
 * Closed dialog: the UA `dialog:not([open]) { display: none }` sits in the
 * user-agent origin and loses to ANY author declaration - including the
 * zero-specificity frame base `display: flex`. Without this functional rule
 * the closed dialog renders in flow and swallows clicks meant for the
 * trigger. Real specificity on purpose (functional, must win).
 */
dialog.lumitra-overlay__panel:not([open]) {
	display: none;
}

:where(dialog.lumitra-overlay__panel)::backdrop {
	background: rgba(0, 0, 0, 0.5);
}

/* scrim: false keeps the top layer but shows no visual backdrop. */
:where(dialog.lumitra-overlay__panel.no-scrim)::backdrop {
	background: transparent;
}

/* --------------------------------------------------------------------- */
/* Tooltip                                                               */
/* --------------------------------------------------------------------- */

:where(.lumitra-overlay__panel.is-tooltip) {
	max-width: min(90vw, 36ch);
	width: max-content;
	pointer-events: auto; /* WCAG 1.4.13: hoverable */
}

/* --------------------------------------------------------------------- */
/* Details/summary no-JS fallback (nav kinds, contract 6.2)              */
/* --------------------------------------------------------------------- */

/* The summary is a real disclosure trigger; keep it clickable and let the
   author's button styling apply. The native marker stays (no-JS affordance)
   unless the author removes it. */
:where(details.lumitra-overlay > summary.lumitra-overlay__trigger) {
	cursor: pointer;
}

/* --------------------------------------------------------------------- */
/* Open/close motion (shared vocabulary subset, scoped to overlay panels  */
/* so the shared lumitra-behaviors stylesheet stays the single generic      */
/* definition of lumitra-anim-*)                                            */
/* --------------------------------------------------------------------- */

:where(.lumitra-overlay__panel.lumitra-anim-fade,
	.lumitra-overlay__panel.lumitra-anim-scale,
	.lumitra-overlay__panel.lumitra-anim-slide-down) {
	opacity: 0;
	transition:
		opacity var(--lumitra-dur, 250ms) var(--lumitra-ease, ease),
		transform var(--lumitra-dur, 250ms) var(--lumitra-ease, ease);
}

:where(.lumitra-overlay__panel.lumitra-anim-scale) {
	transform: scale(0.95);
}

:where(.lumitra-overlay__panel.lumitra-anim-slide-down) {
	transform: translateY(-8px);
}

:where(.lumitra-overlay__panel.is-open) {
	opacity: 1;
	transform: none;
}

/* Entry from display:none / hidden (browsers without @starting-style simply
   snap to the open state; state correctness is JS-side). */
@starting-style {
	:where(.lumitra-overlay__panel.is-open) {
		opacity: 0;
	}

	:where(.lumitra-overlay__panel.lumitra-anim-scale.is-open) {
		transform: scale(0.95);
	}

	:where(.lumitra-overlay__panel.lumitra-anim-slide-down.is-open) {
		transform: translateY(-8px);
	}
}

/* Reduced motion: 1ms (not 0) so transitionend-based logic can never hang
   (behaviors spec 2.3), scoped to overlay selectors; the shared behaviors
   stylesheet owns the global rule. */
@media (prefers-reduced-motion: reduce) {
	:where(.lumitra-overlay__panel) {
		transition-duration: 1ms !important;
		animation-duration: 1ms !important;
	}
}
