/* NIGHT_103 T2 — defined-term POPOVER (never a modal).
 *
 * THEME-AWARE BY CONSTRUCTION (the NIGHT_85 lesson): every color below is a
 * design_tokens.css var — ZERO hardcoded hex in this file or the journey strip.
 * The active-node green resolves via --color-brand-primary (emerald-500 dark /
 * emerald-600 light), the brand-green token pair.
 *
 * NOT A MODAL: no backdrop element, no scroll-lock, no focus-trap. Reveal is pure
 * CSS on :hover / :focus-within (+ .is-open for tap). Esc-dismiss works because the
 * hover/focus reveal is gated behind :not([data-tt-dismissed]); term_popover.js sets
 * that attribute on Esc and clears it on mouseleave/focusout. */

.term-anchor {
  position: relative;
  display: inline;
}

/* ---- Anchors ---------------------------------------------------------- */
/* Technical / column mode: the acronym as a defined term. */
.term-def--technical {
  text-decoration: underline dotted;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  cursor: help;
  border: 0;
}
.term-def--technical:focus-visible {
  outline: 2px solid var(--color-brand-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Simple mode: plain label + styled "i" badge trigger. NIGHT_107 UX
 * (2026-07-18 operator directive): the previous unicode &#9432; blended into
 * body text at 0.85em with only a color change. New design = a real badge:
 * emerald-brand background circle, italic-serif "i", positioned superscript-
 * high so it flies just above the baseline without disturbing line-height.
 * Contrast per operator preference: light theme = white letter on emerald-600;
 * dark theme = deep-green letter on emerald-500 (WCAG AA both directions).
 * Size stays near-body so it reads as a callout without dominating the line. */
.term-def--simple {
  cursor: default;
}

/* NIGHT_107 — green-term affordance. Every term() label renders in
 * brand-emerald so the label + (i) badge read as one interactive unit
 * and the same visual pattern the H1 uses ("U.S. employer filings" on
 * /perm-real) is extended to inline body prose. The badge's own color
 * is unchanged (--color-brand-primary bg + white/deep-green letter);
 * only the label prose text-color moves to emerald.
 *
 * .term-def--simple WRAPS the .term-info badge button, but .term-info
 * declares its own color (#052e16 dark / #ffffff light), and a
 * declaration on the child always beats a value inherited from the
 * parent — so the badge letter is immune to this rule. Verified
 * in-browser at T3. */
.term-def--simple,
.term-def--technical {
  color: var(--color-brand-primary);
}

/* NIGHT_107 — light-theme legibility floor. --color-brand-primary is
 * emerald-600 (#059669) in light theme, which measures 3.77:1 on the
 * #ffffff page background and 3.70:1 on the composited elevated surface
 * used by /company — both under the 4.5:1 WCAG AA floor for body text.
 * Darken the LABEL only, derived from the token rather than hardcoded,
 * so the (i) badge, journey-strip active node, source link and every
 * other --color-brand-primary consumer are untouched. Resolves to
 * rgb(4,120,84) = 5.50:1 on #ffffff / 5.40:1 on #fdfdfd.
 *
 * Dark theme is deliberately NOT overridden — emerald-500 on #0a0a0a is
 * already 7.80:1 and stays byte-identical.
 *
 * Precedent: NIGHT_85C light-theme "Rule 4 — MUTED TEXT floor", and the
 * --color-text-tertiary #737373 -> #525252 bump made for the same AA
 * reason with dark left untouched. */
[data-theme="light"] .term-def--simple,
[data-theme="light"] .term-def--technical {
  /* Operator ruling 2026-07-19: Option 1 at 87%. Pass 2's earlier 80% pick
   * cleared AA at 5.50:1 but overshot the requested emerald by 22%; 87% lands
   * at 4.83:1 on #ffffff / 4.75:1 on the composited /company #fdfdfd surface
   * (both ≥ AA 4.5:1 with a 5% cushion) while landing 34% closer to raw
   * emerald-600 in dE. Derives from the token so the token itself stays
   * canonical for every other brand consumer (NIGHT_109 addresses the token
   * escalation separately). */
  color: color-mix(in srgb, var(--color-brand-primary) 87%, black);
}

/* NIGHT_107 — hover / focus glow on the label. Filter brightness +
 * saturate is portable, cheap, and stays inline-safe (unlike transform
 * scale which jitters the surrounding text baseline). The subtle
 * text-shadow ring echoes the badge's box-shadow glow at operator-
 * confirmed weight.
 *
 * Scoped to the ANCHOR, not the label, so hovering anywhere on the
 * interactive unit — label OR badge — lights up the label. That is the
 * "one interactive unit" the operator asked for.
 *
 * The transition lives on the hovered state rather than the base rule so
 * the initial paint is instant and only the hover-in animates. */
.term-anchor:hover .term-def--simple,
.term-anchor:hover .term-def--technical,
.term-anchor:focus-within .term-def--simple,
.term-anchor:focus-within .term-def--technical {
  filter: brightness(1.15) saturate(1.05);
  text-shadow: 0 0 6px color-mix(in srgb, var(--color-brand-primary) 35%, transparent);
  transition: filter var(--transition-fast), text-shadow var(--transition-fast);
}
.term-info {
  appearance: none;
  background: var(--color-brand-primary);
  border: 0;
  padding: 0;
  margin: 0 0.05em 0 0.2em;
  font: inherit;
  font-family: Georgia, "Times New Roman", "Noto Serif", serif;
  font-style: italic;
  font-weight: 700;
  font-size: 0.78em;
  line-height: 1;
  color: #052e16;                    /* dark mode DEFAULT: deep-green letter on emerald-500 */
  cursor: pointer;
  vertical-align: baseline;
  position: relative;
  top: -0.5em;                        /* flies up; sits just above baseline */
  width: 1.35em;
  height: 1.35em;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}
[data-theme="light"] .term-info {
  color: #ffffff;                     /* light mode: white letter on emerald-600 */
}
.term-info__glyph {
  display: inline-block;
  transform: translateY(-0.02em);     /* nudge the "i" optically-centered inside the circle */
  pointer-events: none;
}
.term-info:hover,
.term-info:focus-visible {
  transform: scale(1.06);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-brand-primary) 25%, transparent);
}
.term-info:focus-visible {
  outline: 2px solid var(--color-brand-primary);
  outline-offset: 2px;
}
/* When the popover is PINNED (click-open), the badge stays highlighted so the
 * operator knows the popover is anchored, not just hovered. */
.term-anchor.is-open > .term-def--simple .term-info,
.term-anchor.is-open > .term-def--technical {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-brand-primary) 45%, transparent);
}

/* ---- Popover card ----------------------------------------------------- */
/* NIGHT_107 UX widths: max-width bumped from 360px -> min(720px, viewport-24px)
 * so the journey strip fits without horizontal scroll on any laptop-class
 * screen; on mobile the clamp collapses to viewport-24px = full-width bubble.
 * The hover-continuity bridge (::before) is the invisible padded strip the
 * mouse crosses when moving from the trigger DOWN to the popover — without it,
 * the 8px visual gap breaks :hover and the popover disappears mid-scroll. */
.term-pop {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: max-content;
  max-width: min(720px, calc(100vw - 24px));
  min-width: 280px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-bg-overlay);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-strong);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-normal);
  text-align: left;
  white-space: normal;
  /* hidden by default; no layout jump, not focusable, not clickable.
   * HIDE path: fade opacity out, THEN flip visibility to hidden (0s delayed by
   * the fade duration) so the popover fades out instead of vanishing. */
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast), visibility 0s var(--transition-fast);
}
/* Invisible hover-continuity bridge across the 8px visual gap between the
 * trigger and the popover body. Without it, mouse-moving from the (i) DOWN to
 * scroll/click inside the popover crosses a dead-zone where neither element
 * has :hover, the parent :hover flickers off, pointer-events flip to none, and
 * the popover disappears. The bridge extends the popover's hit-box up to the
 * anchor's baseline; it inherits visibility+opacity from the parent so it's
 * completely inert until the popover is showing. */
.term-pop::before {
  content: "";
  position: absolute;
  top: -12px;
  left: 0;
  right: 0;
  height: 12px;
  background: transparent;
}

/* Edge handling (term_popover.js sets these; defaults are safe). */
.term-anchor[data-pop-halign="end"] .term-pop {
  left: auto;
  right: 0;
}
.term-anchor[data-pop-pos="top"] .term-pop {
  top: auto;
  bottom: calc(100% + 8px);
}

/* Reveal — hover / focus-within / tap. Gated behind :not([data-tt-dismissed])
 * so Esc can hide it even while the pointer still hovers (WCAG 1.4.13).
 * SHOW path: visibility flips to visible INSTANTLY (0s 0s), opacity fades in. */
.term-anchor:hover:not([data-tt-dismissed]) > .term-pop,
.term-anchor:focus-within:not([data-tt-dismissed]) > .term-pop,
.term-anchor.is-open > .term-pop {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transition: opacity var(--transition-fast), visibility 0s 0s;
}
/* ~150ms hover-intent delay (hover/focus only). Tap (.is-open) opens instantly. */
.term-anchor:hover:not([data-tt-dismissed]) > .term-pop,
.term-anchor:focus-within:not([data-tt-dismissed]) > .term-pop {
  transition: opacity var(--transition-fast) 150ms, visibility 0s 150ms;
}

.term-pop__head {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
}
.term-pop__head strong {
  font-weight: var(--font-weight-bold);
}
.term-pop__def {
  color: var(--color-text-secondary);
}
.term-pop__nuance {
  color: var(--color-text-tertiary);
  font-style: italic;
}
.term-pop__caption {
  color: var(--color-text-tertiary);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-2);
}

/* ---- Journey strip ---------------------------------------------------- */
/* NIGHT_107 UX: dropped horizontal scroll (was overflow-x:auto). At the new
 * max-width the strip fits on desktop without scroll; when it does wrap on
 * narrow screens, wrapping is more readable than a hidden scrollbar. */
.term-pop__strip {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: var(--space-2);
  padding-bottom: 0;
}
.term-pop__node {
  flex: 0 1 auto;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
}
.term-pop__node.is-active {
  color: var(--color-brand-primary);
  border-color: var(--color-brand-primary);
  font-weight: var(--font-weight-semibold);
}
.term-pop__dot {
  color: var(--color-brand-primary);
}
.term-pop__arrow {
  flex: 0 0 auto;
  align-self: center;
  color: var(--color-text-tertiary);
}

/* ---- Source link ------------------------------------------------------ */
.term-pop__src {
  color: var(--color-brand-primary);
  text-decoration: none;
  font-weight: var(--font-weight-medium);
  align-self: flex-start;
}
.term-pop__src:hover,
.term-pop__src:focus-visible {
  text-decoration: underline;
}

/* ---- Pin affordance --------------------------------------------------- */
/* Subtle hint at the bottom-right; visible only while UNPINNED, hidden the
 * moment the user clicks anywhere inside the popover (JS toggles .is-open).
 * The click-to-pin interaction itself lives in term_popover.js. */
.term-pop::after {
  content: "click to pin";
  position: absolute;
  bottom: var(--space-2);
  right: var(--space-3);
  font-size: 0.65rem;
  color: var(--color-text-tertiary);
  opacity: 0.7;
  pointer-events: none;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  transition: opacity var(--transition-fast);
}
.term-anchor.is-open > .term-pop::after {
  content: "pinned — click outside to close";
  color: var(--color-brand-primary);
  opacity: 0.85;
}

/* Screen-reader-only helper, scoped so it never collides with a global rule. */
.term-pop .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .term-pop {
    transition: none;
  }
  .term-anchor:hover:not([data-tt-dismissed]) > .term-pop {
    transition-delay: 0ms;
  }
  /* NIGHT_107 — the hover glow still applies (it is an affordance, not
   * decoration), it just arrives instantly instead of fading. */
  .term-anchor:hover .term-def--simple,
  .term-anchor:hover .term-def--technical,
  .term-anchor:focus-within .term-def--simple,
  .term-anchor:focus-within .term-def--technical {
    transition: none;
  }
}

/* ---- D3 / I-123: a HIDDEN popover must not create horizontal scroll ------
 *
 * MEASURED 2026-08-19: 80 of 116 page loads scrolled sideways, up to 477px, at
 * desktop 1280 as well as mobile 390. The culprit on nearly every page was this
 * component: `.term-pop` is `position:absolute; left:0` inside an inline anchor,
 * `width:max-content` up to 720px -- and `visibility:hidden` STILL CONTRIBUTES
 * TO THE SCROLLABLE OVERFLOW AREA. An anchor sitting at x=800 therefore pushes
 * an invisible 720px card out to 1520px on a 1280 viewport, and the page gains a
 * horizontal scrollbar nobody can explain because the thing causing it cannot
 * be seen.
 *
 * `overflow-x: clip` (NOT `hidden`) is the fix: it suppresses the scrollable
 * area without creating a scroll container, so `position: sticky`, scroll
 * anchoring and in-page `#fragment` jumps all keep working -- `hidden` would
 * silently break sticky headers.
 *
 * Scoped to `body` rather than `html` so the viewport's own scrolling is
 * untouched. The popover itself already clamps to `calc(100vw - 24px)` and the
 * JS flips `data-pop-halign="end"` near the right edge, so a SHOWN popover
 * stays inside the viewport and is not clipped by this rule -- proven before
 * shipping, not assumed.
 */
body {
  overflow-x: clip;
}

/* U7 (2026-08-22) — the balloon shattered the mobile hero.
   The inline info badge wraps mid-headline at narrow widths, breaking the
   line into pieces. Hidden at <=768px: U3's always-visible table legend now
   carries the same explanation on mobile, and carries it better -- static
   text a thumb never has to find, rather than a target it has to hit. */
@media (max-width: 768px) {
  .term-info { display: none !important; }
}
