/* Explanations (guide G-02, FORM-36): ONE trigger (a small circled sans-serif i, 20 px visual, 24 px target on
   desktop, 44 px on phones), the "About this page" secondary button in the page header actions row, and one
   popover anchored to its trigger (a bottom sheet on phones, <= 600 px). Placement rules live here and in
   ui.explain / ui.section_heading so templates cannot drift: a section (i) follows the heading text on the same
   line, a field (i) follows the label, never between action buttons, never alone on a line. */
.explain { display: inline-flex; align-items: center; vertical-align: middle; position: relative; flex: 0 0 auto; }
.explain-button { display: inline-grid; place-items: center; width: 24px; height: 24px; min-height: 0; padding: 0; margin: 0 !important; border: 0; border-radius: 50%; background: transparent; color: var(--info); box-shadow: none; font-weight: 700; }
.explain-button:hover { background: var(--info-surface); color: var(--info); border-color: transparent; }
.explain-button:active { background: var(--info-line); }
.explain-button[aria-expanded="true"] { background: var(--info-surface); color: var(--info); }
.explain-glyph { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid currentColor; font-family: inherit; font-size: 12px; font-style: normal; font-weight: 700; line-height: 1; }
.explain-button[aria-expanded="true"] .explain-glyph { background: var(--info); border-color: var(--info); color: var(--brand-ink); }
.explain-tip { position: absolute; left: 50%; bottom: calc(100% + 4px); z-index: 30; transform: translateX(-50%); width: max-content; max-width: 16rem; padding: .25rem .5rem; border-radius: var(--small-radius); background: var(--brand); color: var(--brand-ink); font-size: var(--text-meta); font-weight: 500; line-height: 1.3; text-align: center; pointer-events: none; display: none; }
.explain-button:hover + .explain-tip, .explain-button:focus-visible + .explain-tip { display: block; }
.explain-button[aria-expanded="true"] + .explain-tip { display: none; }
/* In a side panel the tip grows leftwards from the (i): a centred tip near the panel edge widened the panel (scrollWidth). */
.sheet .explain-tip { left: auto; right: 0; transform: none; }
/* The page-level button: a secondary header button with the icon and the words */
.explain-page .explain-button { width: auto; height: auto; min-height: 2.5rem; padding: .5rem .9rem; gap: .45rem; display: inline-flex; border: 1px solid var(--control-line); border-radius: var(--control-radius); background: var(--paper); color: var(--ink); font-size: var(--text-ui); font-weight: 600; box-shadow: var(--shadow-xs); }
.explain-page .explain-button:hover { background: var(--hover); border-color: var(--control-hover-line); color: var(--ink); }
.explain-page .explain-button[aria-expanded="true"] { background: var(--selected); color: var(--selected-ink); border-color: var(--control-line); }
.explain-page .explain-glyph { color: var(--info); }
.explain-words { font-size: var(--text-ui); font-weight: 600; color: inherit; }
.page-actions-solo { justify-content: flex-end; margin: 0 0 1rem; }
/* The popover: fixed (no scrolling parent clips it), positioned by ris.js from the trigger */
.explain-popover { position: fixed; z-index: 40; top: 0; left: 0; display: flex; flex-direction: column; width: min(26rem, calc(100vw - 2rem)); max-height: 70vh; padding: 1rem 0 1rem 1.1rem; background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); font-size: var(--text-ui); line-height: 1.5; text-align: left; font-weight: 400; }
.explain-popover[hidden] { display: none; }
.explain-arrow { position: absolute; left: var(--arrow-x, 1.5rem); width: 12px; height: 12px; margin-left: -6px; background: var(--paper); border: 1px solid var(--line); transform: rotate(45deg); pointer-events: none; }
.explain-popover[data-placement="below"] .explain-arrow { top: -7px; border-right: 0; border-bottom: 0; }
.explain-popover[data-placement="above"] .explain-arrow { bottom: -7px; border-left: 0; border-top: 0; }
.explain-handle { display: none; }
.explain-body { display: block; flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-right: 2.75rem; overscroll-behavior: contain; }
.explain-loading { display: block; }
.explain-close { position: absolute; top: .5rem; right: .5rem; display: grid; place-items: center; width: 1.75rem; height: 1.75rem; min-height: 0; padding: 0; margin: 0 !important; border: 0; border-radius: 50%; background: transparent; color: var(--ink-soft); box-shadow: none; font-size: 1.25rem; font-weight: 400; line-height: 1; }
.explain-close:hover { background: var(--hover); color: var(--ink); }
.explain-popover h2 { margin: 0 0 .5rem; font-size: 1rem; line-height: 1.3; }
.explain-popover h3 { margin: .7rem 0 .15rem; font-size: var(--text-meta); font-weight: 650; color: var(--ink-soft); }
.explain-popover h4 { margin: .7rem 0 .2rem; font-size: var(--text-ui); }
.explain-popover p, .explain-popover ul { margin: .2rem 0 .4rem; }
.explain-popover ul { padding-left: 1.2rem; }
/* The heading takes programmatic focus (tabindex -1): the ring is the :focus-visible one, so pointer users see none. */
.explain-popover [data-explain-heading]:focus-visible { outline-offset: 3px; }
.explain-references { list-style: none; padding-left: 0 !important; margin-top: .35rem !important; font-size: var(--text-meta); }
.explain-references li { display: flex; align-items: baseline; gap: .5rem; min-width: 0; }
.explain-references li + li { margin-top: .15rem; }
.explain-references a { flex: 0 0 auto; white-space: nowrap; }
.explain-citation { display: block; min-width: 0; overflow-wrap: anywhere; color: var(--ink-soft); }
.explain-facts { display: grid; grid-template-columns: minmax(0, 9rem) minmax(0, 1fr); gap: .25rem .7rem; margin: .25rem 0 .4rem; }
.explain-facts dt { color: var(--ink-soft); }
.explain-facts dd { margin: 0; overflow-wrap: anywhere; }
.explain-fact-kind { display: inline-block; margin-left: .4rem; padding: 0 .35rem; border: 1px solid var(--line); border-radius: var(--small-radius); font-size: var(--text-meta); color: var(--ink-soft); }
.explain-note, .explain-loading { color: var(--ink-soft); font-size: var(--text-meta); }
.explain-footer { margin: .8rem 0 0; padding-top: .5rem; border-top: 1px solid var(--line); color: var(--ink-soft); font-size: var(--text-meta); line-height: 1.4; }
.explain-backdrop { position: fixed; inset: 0; z-index: 39; background: var(--scrim); }
.explain-backdrop[hidden] { display: none; }
/* A field label with its (i) */
.field-label-row { display: flex; align-items: center; gap: .15rem; margin-bottom: .25rem; }
.field-label-row label { margin-bottom: 0; }
/* A section heading with its (i) right after the text, same line, vertically centred */
.section-heading, .heading-with-help { display: flex; flex-wrap: nowrap; align-items: center; justify-content: flex-start; gap: .1rem .35rem; margin-bottom: 1.1rem; }
.section-heading > :is(h1, h2, h3), .heading-with-help > :is(h1, h2, h3) { flex: 0 1 auto; min-width: 0; }
.section-heading:has(> :is(a, form, span:not(.explain), .page-actions, .export-buttons)) { flex-wrap: wrap; }
/* The page (i) beside the H1 on a phone (ris.js moves it): an icon without words. */
.explain-page.in-heading .explain-words { display: none; }
.explain-page.in-heading .explain-button { width: var(--touch); height: var(--touch); min-height: 0; padding: 0; margin: -.5rem -.4rem !important; border: 0; background: transparent; box-shadow: none; }
.section-heading > :is(a, form, span:not(.explain), .page-actions, .export-buttons), .heading-with-help > :is(a, form, .page-actions) { margin-left: auto; }
.section-heading h2, .section-heading h3, .heading-with-help h2 { margin: 0; }
.page-context { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .5rem 1rem; margin: 0 0 1rem; }
.page-context:has([data-guide-bar][hidden]) { display: none; }
.page-context-launcher { display: inline-flex; flex-wrap: wrap; gap: .5rem; }
.training-banner .explain { margin-left: auto; }
/* Phones: the popover is a bottom sheet over a dimmed page that does not scroll */
@media (max-width: 600px) {
  .explain-button { width: 44px; height: 44px; margin: -.5rem -.4rem !important; }
  .explain-page .explain-button { width: auto; height: auto; margin: 0 !important; min-height: var(--touch); }
  .explain-tip { display: none; }
  .explain-popover { top: auto !important; left: 0 !important; right: 0; bottom: 0; width: auto; max-height: 80vh; padding: 1.6rem 0 calc(1.25rem + env(safe-area-inset-bottom)) 1.1rem; border-width: 1px 0 0; border-radius: var(--radius-sheet) var(--radius-sheet) 0 0; box-shadow: var(--shadow-lg); overscroll-behavior: contain; }
  .explain-arrow { display: none; }
  .explain-handle { display: block; position: absolute; top: .5rem; left: 50%; width: 2.5rem; height: 4px; margin-left: -1.25rem; border-radius: 2px; background: var(--control-line); }
  .explain-close { top: .5rem; right: .5rem; width: var(--touch); height: var(--touch); }
  .explain-popover h2 { padding-right: 2rem; }
  .explain-facts { grid-template-columns: minmax(0, 1fr); }
  html.explain-sheet-open, html.explain-sheet-open body { overflow: hidden; }
}
/* Guided walkthrough (guide, G-06; DESIGN ADR-G08): the narration panel, its bar and the highlighted target.
   The target uses the focus-ring token; the panel and the explanation sheet share the phone bottom-sheet rules. */
.guide-bar { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.guide-bar[hidden] { display: none; }
.guide-bar-text { font-size: var(--text-meta); color: var(--ink-soft); }
.guide-target { outline: 3px solid var(--focus-ring); outline-offset: 2px; box-shadow: 0 0 0 2px var(--paper); background: var(--selected); }
.guide-panel { position: fixed; z-index: 35; right: 1rem; bottom: calc(1rem + var(--guide-panel-offset, 0px)); width: min(26rem, calc(100vw - 2rem)); max-height: 60vh; overflow-y: auto; padding: .5rem 1.1rem 1rem; background: var(--paper); color: var(--ink); border: 1px solid var(--control-line); border-radius: var(--radius); box-shadow: var(--shadow-md); font-size: var(--text-ui); line-height: 1.55; }
.guide-panel[hidden], .guide-panel-body[hidden], .guide-key[hidden] { display: none; }
.guide-panel-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.guide-title { margin: .4rem 0; font-size: var(--text-body-sm); }
.guide-toggle { flex: 0 0 auto; min-height: 2rem; padding: .25rem .7rem; font-size: var(--text-ui); }
.guide-collapsed { padding-bottom: .5rem; }
.guide-who { margin: .3rem 0; }
.guide-label { margin-left: .25rem; }
.guide-narration p, .guide-narration ul { margin: .3rem 0 .6rem; }
.guide-narration ul { padding-left: 1.2rem; }
.guide-hint, .guide-status, .guide-key { margin: .4rem 0; color: var(--ink-soft); font-size: var(--text-meta); }
.guide-controls { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
body.guide-active { padding-bottom: var(--guide-panel-height, 0px); }
@media (max-width: 639px) {
  .guide-panel { left: 0; right: 0; bottom: var(--guide-panel-offset, 0px); width: auto; max-height: 45vh; padding-bottom: 1.25rem; border-radius: var(--radius) var(--radius) 0 0; }
  .guide-collapsed { padding-bottom: .5rem; }
  .guide-panel button, .guide-panel .button { min-height: 44px; }
  body.guide-active { padding-bottom: calc(var(--guide-panel-height, 0px) + var(--guide-panel-offset, 0px)); }
  body.guide-active .explain-popover { max-height: 55vh; }
}

@media (max-width: 800px) {
  .explain-close, .guide-toggle { min-height: var(--touch); }
}
