/*
 * Contextual-help system — shared styles (admin kit).
 *
 * Two surfaces render OUTSIDE `.main` (directly in <body>), so they can't
 * inherit the `.main`-scoped light tokens. Every colour therefore reads a
 * design token with an explicit literal fallback equal to the token value,
 * so the popover / modal render correctly regardless of token scope:
 *   - .pe-help-pop      : the mini tooltip popover (info ⓘ triggers)
 *   - .pe-help-modal    : the scrollable "Guide" documentation modal
 * The injected ⓘ trigger (.pe-help-trigger) and the section "Guide" button
 * (.pe-help-guide-btn) live inline inside `.main`, so they can lean on the
 * inherited kit tokens directly.
 */

/* ─── Injected info ⓘ trigger ─────────────────────────────────────────── */
.pe-help-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 6px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--color-text-muted, #667085);
    cursor: help;
    vertical-align: middle;
    line-height: 0;
    flex: 0 0 auto;
    /* Expand the hit area to a comfortable touch target without
       growing the visual footprint (keeps the glyph discreet). */
    position: relative;
    transition: color 140ms ease, background-color 140ms ease;
}
.pe-help-trigger::after {
    /* Invisible 44×44 tap target centred on the 16px glyph. */
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 44px;
    height: 44px;
    transform: translate(-50%, -50%);
}
.pe-help-trigger svg { width: 14px; height: 14px; display: block; }
.pe-help-trigger:hover,
.pe-help-trigger[aria-expanded="true"] {
    color: var(--color-text, #101828);
    background: color-mix(in srgb, var(--color-accent, #F5C842) 22%, transparent);
}
.pe-help-trigger:focus-visible {
    outline: none;
    color: var(--color-text, #101828);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent, #F5C842) 45%, transparent);
}
/* Column-header triggers sit on their own baseline — nudge to align. */
th .pe-help-trigger { margin-left: 4px; }

/* ─── Section "Guide" button ──────────────────────────────────────────── */
.pe-help-guide-btn {
    gap: 6px;
}
.pe-help-guide-btn svg { width: 16px; height: 16px; }

/* The popover and Guide modal render in <body>, OUTSIDE `.main`, so they
   inherit the app's DARK :root tokens instead of the `.main`-scoped light
   palette (same trap `.modal--light` solves). Re-scope the light palette
   onto both surfaces so every `var(--color-*)` resolves light and matches
   the admin kit. */
.pe-help-pop,
.pe-help-modal-overlay {
    --color-surface: #FFFFFF;
    --color-text: #101828;
    --color-text-secondary: #475467;
    --color-text-muted: #667085;
    --color-border: #E4E7EC;
    --color-accent: #F5C842;
    --color-accent-hover: #E7B62E;
    --surface-sunken: #F4F5F7;
    --surface-hover: #F9FAFB;
}

/* ─── Popover ─────────────────────────────────────────────────────────── */
.pe-help-pop {
    position: fixed;
    z-index: 2000;
    max-width: 280px;
    margin: 0;
    padding: 12px 14px;
    border: 1px solid var(--color-border, #E4E7EC);
    border-radius: 12px;
    background: var(--color-surface, #FFFFFF);
    color: var(--color-text-secondary, #475467);
    box-shadow: 0 12px 28px rgba(16, 24, 40, 0.14), 0 2px 6px rgba(16, 24, 40, 0.08);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.55;
    /* Hidden by default; shown via .is-open. */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(3px);
    transition: opacity 140ms ease, transform 140ms ease, visibility 0s linear 140ms;
}
.pe-help-pop.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition: opacity 140ms ease, transform 140ms ease, visibility 0s;
}
.pe-help-pop__title {
    margin: 0 0 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text, #101828);
    letter-spacing: -0.01em;
}
.pe-help-pop__body { margin: 0; }
.pe-help-pop__body :last-child { margin-bottom: 0; }
.pe-help-pop code {
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--surface-sunken, #F4F5F7);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.86em;
    color: var(--color-text, #101828);
}
/* Arrow — a rotated square straddling the popover edge. --arrow-x is set
   by JS to keep the tip pointing at the trigger even after clamping. */
.pe-help-pop::before {
    content: "";
    position: absolute;
    left: var(--arrow-x, 50%);
    width: 10px;
    height: 10px;
    background: var(--color-surface, #FFFFFF);
    border: 1px solid var(--color-border, #E4E7EC);
    transform: translateX(-50%) rotate(45deg);
}
.pe-help-pop[data-placement="top"]::before {
    bottom: -6px;
    border-top: 0;
    border-left: 0;
}
.pe-help-pop[data-placement="bottom"]::before {
    top: -6px;
    border-bottom: 0;
    border-right: 0;
}

/* ─── Guide modal ─────────────────────────────────────────────────────── */
.pe-help-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(16, 24, 40, 0.55);
    opacity: 0;
    transition: opacity 160ms ease;
}
.pe-help-modal-overlay.is-open { opacity: 1; }
.pe-help-modal {
    display: flex;
    flex-direction: column;
    width: min(760px, 100%);
    max-height: min(86vh, 900px);
    border-radius: 16px;
    background: var(--color-surface, #FFFFFF);
    color: var(--color-text, #101828);
    box-shadow: 0 24px 60px rgba(16, 24, 40, 0.28);
    overflow: hidden;
    font-family: inherit;
    transform: translateY(8px) scale(0.99);
    transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1);
}
.pe-help-modal-overlay.is-open .pe-help-modal { transform: translateY(0) scale(1); }
.pe-help-modal__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--color-border, #E4E7EC);
    flex: 0 0 auto;
}
.pe-help-modal__eyebrow {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-accent-hover, #E7B62E);
    margin: 0 0 2px;
}
.pe-help-modal__title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--color-text, #101828);
}
.pe-help-modal__close {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--color-border, #E4E7EC);
    border-radius: 10px;
    background: var(--color-surface, #FFFFFF);
    color: var(--color-text-secondary, #475467);
    cursor: pointer;
    flex: 0 0 auto;
    transition: background-color 140ms ease, color 140ms ease;
}
.pe-help-modal__close:hover { background: var(--surface-hover, #F9FAFB); color: var(--color-text, #101828); }
.pe-help-modal__close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent, #F5C842) 45%, transparent);
}
.pe-help-modal__body {
    padding: 8px 24px 28px;
    overflow-y: auto;
    flex: 1 1 auto;
    -webkit-overflow-scrolling: touch;
}
.pe-help-modal__state {
    padding: 48px 8px;
    text-align: center;
    color: var(--color-text-muted, #667085);
    font-size: 14px;
}

/* ─── Prose (documentation fragment) ──────────────────────────────────── */
.pe-doc { color: var(--color-text-secondary, #475467); font-size: 14px; line-height: 1.7; }
.pe-doc h1, .pe-doc h2, .pe-doc h3 {
    color: var(--color-text, #101828);
    letter-spacing: -0.01em;
    line-height: 1.3;
}
.pe-doc h1 { font-size: 22px; font-weight: 700; margin: 20px 0 8px; }
.pe-doc h2 {
    font-size: 17px; font-weight: 700; margin: 26px 0 10px;
    padding-top: 18px; border-top: 1px solid var(--color-border, #E4E7EC);
}
.pe-doc > h1:first-child, .pe-doc > *:first-child { margin-top: 4px; }
.pe-doc h2:first-of-type { border-top: 0; padding-top: 0; }
.pe-doc h3 { font-size: 14px; font-weight: 600; margin: 18px 0 6px; }
.pe-doc p { margin: 0 0 12px; max-width: 66ch; }
.pe-doc ul, .pe-doc ol { margin: 0 0 14px; padding-left: 20px; max-width: 66ch; }
.pe-doc li { margin: 0 0 6px; }
.pe-doc li::marker { color: var(--color-text-muted, #667085); }
.pe-doc strong { color: var(--color-text, #101828); font-weight: 600; }
.pe-doc a { color: var(--color-accent-hover, #E7B62E); text-decoration: underline; }
.pe-doc code {
    padding: 1.5px 6px;
    border-radius: 6px;
    background: var(--surface-sunken, #F4F5F7);
    border: 1px solid var(--color-border, #E4E7EC);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.85em;
    color: var(--color-text, #101828);
}
.pe-doc table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 18px;
    font-size: 13.5px;
}
.pe-doc th, .pe-doc td {
    text-align: left;
    padding: 9px 12px;
    border: 1px solid var(--color-border, #E4E7EC);
    vertical-align: top;
}
.pe-doc thead th {
    background: var(--surface-sunken, #F4F5F7);
    color: var(--color-text, #101828);
    font-weight: 600;
}
/* Callout box — "live vs restart", tips, notes. */
.pe-doc__note {
    margin: 0 0 18px;
    padding: 14px 16px;
    border: 1px solid var(--color-border, #E4E7EC);
    border-left: 3px solid var(--color-accent, #F5C842);
    border-radius: 10px;
    background: color-mix(in srgb, var(--color-accent, #F5C842) 7%, var(--color-surface, #FFFFFF));
}
.pe-doc__note > :last-child { margin-bottom: 0; }
.pe-doc__note--info { border-left-color: #2E90FA; background: color-mix(in srgb, #2E90FA 6%, var(--color-surface, #FFFFFF)); }
.pe-doc__note-title {
    display: block;
    font-weight: 600;
    color: var(--color-text, #101828);
    margin-bottom: 4px;
    font-size: 13.5px;
}

/* ─── Responsive (narrow ≈430px) ──────────────────────────────────────── */
@media (max-width: 560px) {
    .pe-help-modal-overlay { padding: 0; }
    .pe-help-modal {
        width: 100%;
        max-height: 100%;
        height: 100%;
        border-radius: 0;
    }
    .pe-doc table { font-size: 12.5px; }
    .pe-doc th, .pe-doc td { padding: 7px 9px; }
}

/* Let a wide doc table scroll inside its own frame rather than
   forcing the modal body to scroll horizontally. */
.pe-doc__table-scroll { overflow-x: auto; margin: 0 0 18px; }
.pe-doc__table-scroll table { margin-bottom: 0; }

/* ─── Reduced motion ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .pe-help-pop,
    .pe-help-pop.is-open,
    .pe-help-modal-overlay,
    .pe-help-modal { transition: none; }
    .pe-help-pop { transform: none; }
    .pe-help-modal { transform: none; }
}

/* ─── Doc figure (screenshot + caption) ───────────────────────────────────
   Shared with the standalone doc site (Documentation/Index.html). Styles the
   figures rendered inside the "Guide" modal's `.pe-doc` prose. Fallback chain
   resolves the doc-site tokens (--border/--text-muted) OR the admin-kit tokens
   (--color-*) OR a literal, so one block works in both contexts. */
.pe-doc-figure { margin: 4px 0 20px; }
.pe-doc-figure img {
    width: 100%;
    height: auto;
    display: block;
    border: 1px solid var(--border, var(--color-border, #E4E7EC));
    border-radius: 10px;
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(16, 24, 40, 0.05));
}
.pe-doc-figure img[role="button"] { cursor: zoom-in; }
.pe-doc-figure figcaption {
    margin-top: 8px;
    font-size: 13px;
    font-style: italic;
    color: var(--text-muted, var(--color-text-muted, #667085));
}
