/* ═══════════════════════════════════════════════════════════════════════════
   help.css — the operator manual (Run 40). Loaded by admin.html AFTER the
   panel's own sheets, and by public/admin/help/print.html.

   Dark like the rest of the panel (no light theme exists anywhere in it —
   measured, Run 27). The PRINTED document is the exception: `.help-paper` is a
   light, paper-coloured scope used by #helpPrintAll (the panel's own Print) and
   by print.html (the committed PDF) — one set of document rules, two hosts.

   Z-ORDER (amendment A1): modals 100 · tags 30 · THE CIRCLE + DRAWER 2000 ·
   lightbox 2050 · docview 2900 · toasts 3000. While a document is open in the
   docview overlay the circle, drawer and lightbox are lifted to 2950
   (`.help-lifted`) so "where am I" still answers there.

   THE CIRCLE'S POSITION WAS CHOSEN BY MEASUREMENT (A1), per state, because at
   390×844 no single spot is free of the toast band, a tall modal's footer, the
   Inbox composer and the docview header at once. planning/run40-contract.md §7
   records every rectangle measured.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── the circle ─────────────────────────────────────────────────────────── */
.help-fab {
    position: fixed;
    z-index: 2000;
    /* Desktop: inside the sidebar's footer row (beside the signed-in name), so
       it never covers a table row, a form or a modal's footer — modals are
       capped at 85vh and centred, so the bottom 7.5vh is never theirs. */
    left: 184px;
    bottom: 14px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(123, 128, 212, 0.55);
    background: var(--accent-primary, #2E3192);
    color: #fff;
    font-family: var(--font-display, 'Outfit', sans-serif);
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    transition: transform var(--duration-fast, 150ms), background var(--duration-fast, 150ms);
}
.help-fab:hover { background: #3a3dad; transform: translateY(-1px); }
.help-fab:focus-visible { outline: 2px solid var(--accent-light, #7B80D4); outline-offset: 3px; }
.help-fab[hidden] { display: none; }
/* On the Help tab the manual is already the whole screen — the circle would
   only sit on top of its contents. */
body.help-tab-active .help-fab:not(.help-lifted) { display: none; }
.help-fab.help-lifted, .help-drawer.help-lifted { z-index: 2950; }
.help-lightbox.help-lifted { z-index: 2960; }

@media (max-width: 900px) {
    .help-fab {
        left: auto;
        right: 12px;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 96px);
    }
    /* A tall modal's footer sits in the bottom band at 390×844, so while one is
       open the circle moves to the top-right corner, above the modal (which
       starts at 7.5vh) and below nothing. */
    body:has(.modal-overlay.active) .help-fab:not(.help-lifted) {
        top: calc(env(safe-area-inset-top, 0px) + 8px);
        bottom: auto;
    }
    /* The phone sidebar is a drawer over the page; the circle stays out of it. */
    body:has(.sidebar.open) .help-fab { display: none; }
}
/* Run 52 (item 21): while a document is open (the circle is lifted above the
   docview overlay), it sits IN the viewer's top bar, at its right end — at every
   width — instead of at its usual spot, where it covered the page of the document.
   (0,2,0) outranks the (0,1,0) desktop and ≤ 900 px positions above; the
   modal-open rule above excludes .help-lifted. The bar makes room for it, so the
   back control, the file name (which ellipsizes) and ⬇ all end left of it. The
   drawer and the lightbox stay lifted, so "where am I" still answers in the viewer
   (Run 40 A1). */
.help-fab.help-lifted {
    left: auto;
    right: max(8px, env(safe-area-inset-right));
    top: max(6px, env(safe-area-inset-top));
    bottom: auto;
}
body:has(.help-fab.help-lifted) .docview-bar { padding-right: calc(max(8px, env(safe-area-inset-right)) + 50px); }

/* ── the drawer ─────────────────────────────────────────────────────────── */
.help-drawer {
    position: fixed;
    z-index: 2000;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(460px, 100vw);
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary, #101428);
    border-left: 1px solid var(--border-default, rgba(155, 163, 194, 0.12));
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.45);
    padding-top: env(safe-area-inset-top, 0px);
}
.help-drawer[hidden] { display: none; }
.help-drawer-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-default, rgba(155, 163, 194, 0.12));
}
.help-panes { flex: 1 1 auto; display: flex; gap: 4px; min-width: 0; }
.help-drawer-title { font-family: var(--font-display, 'Outfit', sans-serif); font-weight: 600; color: var(--text-primary, #F1F3F9); padding-left: 4px; }
.help-pane-tab {
    padding: 6px 12px; border-radius: 8px; border: 1px solid transparent; background: none; cursor: pointer;
    color: var(--text-secondary, #9BA3C2); font-family: var(--font-body, 'DM Sans', sans-serif); font-size: 0.85rem;
}
.help-pane-tab.active { background: rgba(46, 49, 146, 0.18); color: var(--accent-light, #7B80D4); border-color: rgba(123, 128, 212, 0.35); }
.help-drawer-btn {
    flex: 0 0 auto;
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 0; border-radius: 8px; background: transparent; cursor: pointer;
    color: var(--text-primary, #F1F3F9); font-size: 1.1rem;
}
.help-drawer-btn:hover { background: rgba(148, 163, 184, 0.12); }
.help-drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 16px 18px 40px; -webkit-overflow-scrolling: touch; }
/* FX4 — why "Open in Help tab" is switched off: a window is open behind the
   drawer, and the Help tab would open underneath it. One line under the head. */
.help-drawer-note {
    flex: 0 0 auto;
    margin: 0;
    padding: 8px 14px;
    font-size: 0.8rem;
    color: var(--text-secondary, #9BA3C2);
    border-bottom: 1px solid var(--border-default, rgba(155, 163, 194, 0.12));
}
.help-drawer-note[hidden] { display: none; }
.help-pane[hidden] { display: none; }
@media (max-width: 900px) {
    .help-drawer { width: 100vw; border-left: 0; }
}

/* ── the lightbox ───────────────────────────────────────────────────────── */
.help-lightbox {
    position: fixed; inset: 0; z-index: 2050;
    display: flex; align-items: center; justify-content: center;
    padding: 48px 16px 16px;
    background: rgba(5, 7, 14, 0.92);
    cursor: zoom-out;
}
.help-lightbox[hidden] { display: none; }
.help-lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6); }
.help-lightbox-close { position: absolute; top: calc(env(safe-area-inset-top, 0px) + 8px); right: 8px; }

/* ── the Help tab ───────────────────────────────────────────────────────── */
#view-help { padding-bottom: 80px; }
.help-top {
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
    margin-bottom: 16px;
}
.help-back { color: var(--accent-light, #7B80D4); text-decoration: none; font-size: 0.85rem; white-space: nowrap; }
.help-back:hover { text-decoration: underline; }
.help-search { flex: 1 1 260px; min-width: 200px; }
.help-search input { width: 100%; }
.help-top-actions { display: flex; gap: 8px; }
.help-top-actions a.action-btn { text-decoration: none; }
.help-gen { flex: 1 1 100%; margin: 0; font-size: 0.75rem; color: var(--text-muted, #636D8C); }
.help-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 24px; align-items: start; }
.help-toc {
    position: sticky; top: 12px;
    max-height: calc(100vh - 140px); overflow-y: auto;
    padding-right: 6px;
    font-size: 0.82rem;
}
.help-toc-ch { margin-bottom: 12px; }
.help-toc-ch-title {
    font-family: var(--font-display, 'Outfit', sans-serif); font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--text-muted, #636D8C); margin: 0 0 4px 6px;
}
.help-toc-item {
    display: block; padding: 4px 8px; border-radius: 6px; text-decoration: none;
    color: var(--text-secondary, #9BA3C2); line-height: 1.35;
}
.help-toc-item:hover { background: rgba(148, 163, 184, 0.08); color: var(--text-primary, #F1F3F9); }
.help-toc-item.current { background: rgba(46, 49, 146, 0.16); color: var(--accent-light, #7B80D4); }
.help-toc-sub, .help-toc-modal { padding-left: 20px; font-size: 0.78rem; }
/* FX4 — the lock after a title the account cannot open (was a bare "·" with a
   tooltip, invisible on a touch screen), and the legend line that says what it
   means: at the top of the contents column, or above the phone's menu. */
.help-toc-noaccess { margin-left: 4px; font-size: 0.75rem; }
.help-toc-legend {
    margin: 0 0 10px; padding: 6px 8px; border-radius: 6px;
    font-size: 0.75rem; line-height: 1.4;
    color: var(--text-secondary, #9BA3C2); background: rgba(148, 163, 184, 0.08);
}
.help-toc-legend-phone { display: none; }
.help-toc-select { display: none; width: 100%; margin-bottom: 12px; }
.help-main { min-width: 0; }
.help-loading { color: var(--text-muted, #636D8C); }
.help-results {
    margin-bottom: 18px; padding: 10px; border-radius: 12px;
    background: var(--bg-card, rgba(16, 20, 40, 0.7)); border: 1px solid var(--border-default, rgba(155, 163, 194, 0.12));
}
.help-results-head { font-size: 0.8rem; color: var(--text-muted, #636D8C); margin: 2px 4px 8px; }
.help-result { display: block; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--text-primary, #F1F3F9); }
.help-result:hover { background: rgba(148, 163, 184, 0.08); }
.help-result-title { font-weight: 600; }
.help-result-kind { font-size: 0.7rem; color: var(--text-muted, #636D8C); text-transform: uppercase; letter-spacing: 0.05em; margin-left: 6px; }
.help-result-snip { display: block; font-size: 0.8rem; color: var(--text-secondary, #9BA3C2); margin-top: 2px; }
.help-pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--border-default, rgba(155, 163, 194, 0.12)); }
.help-pager a { color: var(--accent-light, #7B80D4); text-decoration: none; font-size: 0.85rem; }
.help-pager a:hover { text-decoration: underline; }

@media (max-width: 900px) {
    .help-layout { display: block; }
    .help-toc { display: none; }
    .help-toc-select { display: block; }
    .help-toc-legend-phone:not([hidden]) { display: block; }
    .help-top-actions { flex: 1 1 auto; }
}

/* ── a section (shared by the tab, the drawer and the paper document) ───── */
.help-sec { color: var(--text-primary, #F1F3F9); line-height: 1.6; font-size: 0.92rem; max-width: 900px; }
.help-sec p { margin: 0 0 10px; }
.help-sec-head { margin-bottom: 14px; }
.help-crumb { font-size: 0.75rem; color: var(--text-muted, #636D8C); margin-bottom: 4px; }
.help-kind {
    display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 0.68rem;
    border: 1px solid var(--border-default, rgba(155, 163, 194, 0.18)); color: var(--text-secondary, #9BA3C2);
}
.help-sec-title { font-family: var(--font-display, 'Outfit', sans-serif); font-size: 1.45rem; font-weight: 600; margin: 0 0 8px; }
.help-needs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 4px 0 8px; }
.help-needs-chip {
    display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.75rem;
    background: rgba(46, 49, 146, 0.16); color: var(--accent-light, #7B80D4); border: 1px solid rgba(123, 128, 212, 0.3);
}
.help-noaccess {
    display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.72rem;
    color: #F4C27A; background: rgba(244, 194, 122, 0.1); border: 1px solid rgba(244, 194, 122, 0.35);
}
.help-summary { font-size: 0.98rem; color: var(--text-primary, #F1F3F9); }
.help-h3 { font-family: var(--font-display, 'Outfit', sans-serif); font-size: 1.05rem; font-weight: 600; margin: 22px 0 8px; }
.help-block { margin-top: 6px; }
.help-list { margin: 0 0 10px 20px; }
.help-list li { margin: 2px 0; }
.help-sec code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em;
    padding: 1px 5px; border-radius: 5px; background: rgba(148, 163, 184, 0.12);
}
.help-ref { color: var(--accent-light, #7B80D4); text-decoration: none; border-bottom: 1px dotted rgba(123, 128, 212, 0.55); }
.help-ref:hover { border-bottom-style: solid; }
.help-area {
    display: inline-block; padding: 0 7px; border-radius: 999px; font-size: 0.8em;
    background: rgba(46, 49, 146, 0.16); color: var(--accent-light, #7B80D4);
}
.help-stub { color: var(--text-muted, #636D8C); font-style: italic; }
.help-muted { color: var(--text-muted, #636D8C); }
.help-shot { margin: 12px 0 16px; }
.help-shot-btn { display: block; padding: 0; border: 1px solid var(--border-default, rgba(155, 163, 194, 0.18)); border-radius: 10px; background: none; cursor: zoom-in; overflow: hidden; max-width: 100%; }
.help-shot img { display: block; max-width: 100%; height: auto; }
.help-shot-phone .help-shot-btn { max-width: 300px; }
.help-shot figcaption { font-size: 0.78rem; color: var(--text-muted, #636D8C); margin-top: 6px; }
.help-shot-placeholder {
    display: flex; align-items: center; justify-content: center; height: 90px; border-radius: 10px;
    border: 1px dashed var(--border-default, rgba(155, 163, 194, 0.25)); color: var(--text-muted, #636D8C); font-size: 0.8rem;
}
.help-table-wrap { overflow-x: auto; margin: 10px 0 14px; }
.help-controls { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.help-controls th {
    text-align: left; font-weight: 600; font-size: 0.75rem; color: var(--text-muted, #636D8C);
    padding: 6px 10px; border-bottom: 1px solid var(--border-default, rgba(155, 163, 194, 0.18));
}
.help-controls td { vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--border-default, rgba(155, 163, 194, 0.1)); }
.help-ctl-label { font-weight: 600; white-space: nowrap; }
.help-ctl-needs { font-size: 0.78rem; color: var(--text-secondary, #9BA3C2); min-width: 120px; }
.help-options { margin: 6px 0 0 18px; }
.help-cnote, .help-opens { font-size: 0.8rem; color: var(--text-secondary, #9BA3C2); margin-top: 4px; }
.help-scns { margin-top: 20px; }
.help-scn {
    margin: 12px 0 18px; padding: 14px 16px; border-radius: 12px;
    background: var(--bg-card, rgba(16, 20, 40, 0.7)); border: 1px solid var(--border-default, rgba(155, 163, 194, 0.12));
}
.help-scn-title { font-family: var(--font-display, 'Outfit', sans-serif); font-size: 1rem; font-weight: 600; margin: 0 0 4px; }
.help-steps { margin: 10px 0 6px 22px; }
.help-steps > li { margin: 6px 0; padding-left: 2px; }
.help-note {
    font-size: 0.84rem; color: var(--text-secondary, #9BA3C2);
    border-left: 3px solid rgba(244, 194, 122, 0.55); padding: 2px 0 2px 10px; margin: 8px 0;
}
.help-see { font-size: 0.82rem; color: var(--text-secondary, #9BA3C2); margin-top: 10px; }
.help-drawer .help-sec { font-size: 0.88rem; }
.help-drawer .help-sec-title { font-size: 1.2rem; }

/* ── the printed document (light, paper) ────────────────────────────────── */
#helpPrintAll { display: none; }
.help-paper, .help-paper .help-sec { color: #14161f; }
.help-paper { background: #fff; font-family: 'DM Sans', Helvetica, Arial, sans-serif; }
.help-paper .help-sec { max-width: none; }
.help-paper .help-summary, .help-paper .help-sec p { color: #14161f; }
.help-paper .help-crumb, .help-paper .help-shot figcaption, .help-paper .help-muted,
.help-paper .help-controls th, .help-paper .help-ctl-needs, .help-paper .help-see, .help-paper .help-cnote,
.help-paper .help-opens, .help-paper .help-note { color: #4a5068; }
.help-paper .help-needs-chip, .help-paper .help-area { background: #eceefe; color: #2E3192; border-color: #c9ccf3; }
.help-paper .help-noaccess { display: none; }
.help-paper .help-kind { color: #4a5068; border-color: #c8ccd8; }
.help-paper .help-ref { color: #2E3192; border-bottom-color: #9da1e3; }
.help-paper .help-sec code { background: #eef0f5; }
.help-paper .help-scn { background: #f6f7fb; border-color: #dfe2ec; break-inside: auto; }
.help-paper .help-controls td { border-bottom-color: #e3e6ee; }
.help-paper .help-controls th { border-bottom-color: #c8ccd8; }
.help-paper .help-shot-btn { border-color: #c8ccd8; }
.help-paper .help-note { border-left-color: #e0a64a; }
.help-paper .help-cover { padding: 40mm 0 0; break-after: page; }
.help-paper .help-cover h1 { font-family: 'Outfit', Helvetica, Arial, sans-serif; font-size: 30pt; margin: 0 0 8mm; color: #14161f; }
.help-paper .help-cover-line { font-size: 12pt; color: #4a5068; }
.help-paper .help-print-toc { break-after: page; }
.help-paper .help-print-toc h2 { font-family: 'Outfit', Helvetica, Arial, sans-serif; font-size: 18pt; margin: 0 0 4mm; }
.help-paper .help-print-toc ol { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 12mm; }
.help-paper .help-print-toc li { break-inside: avoid; }
.help-paper .help-print-toc a { display: flex; gap: 6px; color: #14161f; text-decoration: none; font-size: 9pt; line-height: 1.55; }
.help-paper .help-toc-t { flex: 1 1 auto; }
.help-paper .help-toc-pg { flex: 0 0 auto; min-width: 2.2em; text-align: right; font-variant-numeric: tabular-nums; color: #4a5068; }
.help-paper .help-toc-ch { break-inside: avoid-column; margin-bottom: 3mm; }
.help-paper .help-toc-ch-title { color: #2E3192; font-size: 8pt; margin-left: 0; }
.help-paper .help-chapter { break-before: page; }
.help-paper .help-chapter-title { font-family: 'Outfit', Helvetica, Arial, sans-serif; font-size: 22pt; color: #2E3192; margin: 0 0 6mm; }
.help-paper .help-sec + .help-sec { margin-top: 10mm; padding-top: 6mm; border-top: 1px solid #dfe2ec; }
.help-paper .help-kind-tab, .help-paper .help-kind-topic { break-before: auto; }
.help-paper .help-sec > p, .help-paper .help-summary p { max-width: 160mm; }
.help-paper .help-shot { break-inside: avoid; }
.help-paper .help-shot img { max-height: 160mm; width: auto; }
.help-paper .help-shot-full img { width: 100%; }
.help-paper .help-shot-phone img { max-width: 70mm; }
.help-paper .help-steps > li { break-inside: avoid; }
.help-paper .help-controls tr { break-inside: avoid; }

/* The panel's own Print button: only the manual, only when Help asked for it. */
@media print {
    body.help-printing > *:not(#helpPrintAll) { display: none !important; }
    body.help-printing #helpPrintAll { display: block !important; }
    body.help-printing { background: #fff !important; }
    body.help-printing .bg-grid, body.help-printing .bg-glow { display: none !important; }
}
