/* ═══════════════════════════════════════════════════════════════
   Jetfolio Navigation — Slate & Paper top bar (Initiative 18.2)
   Navy bar, paper ink, three category menus + a Reference link, tool-finder,
   Zulu, Crew Portal link, avatar.
   No drawer, no scrim, no transform. Hairlines; ONE shadow (floating panels).
   Positioning is unchanged from the drawer era: relative at ≥1100px,
   fixed-pin below (commit 798d5f8). Not sticky (R10).
   ═══════════════════════════════════════════════════════════════ */

/* App-wide header height. Other layouts compute viewport-minus-header
   with var(--jf-topbar-h, 54px); keep the fallback in sync with this. */
:root { --jf-topbar-h: 54px; }

/* Chrome-local values. --shadow-overlay is not in css/tokens.css, and
   --radius-* are redefined by tools/Aircraft-ProForma-Generator.html, so the
   bar pins its own under a jf- prefix and is identical on every page. */
nav-bar, .jf-finder {
    --jf-shadow-overlay: 0 8px 22px rgba(22, 32, 46, 0.14);
    --jf-r-sm: 6px;
    --jf-r-lg: 10px;
    --jf-bar-pad: 24px;
    --jf-bar-line: rgba(246, 242, 234, 0.22);
    --jf-bar-hover: rgba(246, 242, 234, 0.10);
}

/* The hidden attribute is the one open/closed signal for every panel and
   the one gate for role-gated items. It must beat every display rule
   below, so it is stated once, with !important, at the top (R7). */
nav-bar [hidden] { display: none !important; }

/* The bar's min-heights assume border-box, and most pages get that from
   global.css's universal reset — but a page that loads only tokens + kit
   (pages/reference.html) does not, and every <a> in the bar grew by its
   padding (40px min-height became 56px; found 2026-09-06). The bar owns its
   own box model so it renders identically on every page. */
nav-bar *, nav-bar *::before, nav-bar *::after,
.jf-finder, .jf-finder * { box-sizing: border-box; }

/* ── Top bar ─────────────────────────────────────────────────── */

.jf-topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 var(--jf-bar-pad, 24px);
    height: var(--jf-topbar-h, 54px);
    background: var(--bar-bg, #1e3a5f);
    color: var(--bar-ink, #f6f2ea);
    position: relative;
    z-index: var(--z-header, 600);   /* above page-level sticky sub-navs (SMS, TQG); position unchanged (R10) */
    font-family: var(--font-family, 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif);
    font-size: 14px;
    line-height: 1.5;
}

.jf-topbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.jf-topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

/* ── Logo ────────────────────────────────────────────────────── */

.jf-logo-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--bar-ink, #f6f2ea);
    text-decoration: none;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
    padding: 4px 6px;
    margin-left: -6px;
    border-radius: var(--jf-r-sm);
    /* 40px minimum hit area (WCAG 2.5.8). */
    min-height: 40px;
}

.jf-logo-link:hover { background: var(--jf-bar-hover); text-decoration: none; }
.jf-logo-mark { width: 18px; height: 18px; flex: none; }
.jf-logo-text { color: var(--bar-ink, #f6f2ea); }

/* ── Back link ("← Category") — the locator, in the bar (R5) ─── */

.jf-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--bar-ink-dim, rgba(246, 242, 234, 0.72));
    text-decoration: none;
    white-space: nowrap;
    padding: 4px 8px;
    min-height: 40px;
    border-left: 1px solid var(--jf-bar-line);
}

.jf-back:hover { color: var(--bar-ink, #f6f2ea); text-decoration: underline; }

/* ── Category menus ──────────────────────────────────────────── */

.jf-menus { display: flex; gap: 4px; margin-left: 8px; }
.jf-menu { position: relative; }

.jf-menu-btn {
    appearance: none;
    background: none;
    border: 0;
    margin: 0;
    cursor: pointer;
    padding: 8px 12px;
    min-height: 40px;
    border-radius: var(--jf-r-sm);
    color: var(--bar-ink-dim, rgba(246, 242, 234, 0.72));
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.jf-menu-btn:hover,
.jf-menu-btn[aria-expanded="true"] { color: var(--bar-ink, #f6f2ea); background: var(--jf-bar-hover); }

/* The category this page belongs to. Not by colour alone: an underline. */
.jf-menu-btn[aria-current="true"] {
    color: var(--bar-ink, #f6f2ea);
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 5px;
}

/* The Reference link shares the menu-button treatment but is an anchor: no
   chevron, no panel, and never an underline except as the current-location
   mark above. */
a.jf-menu-btn { text-decoration: none; }
a.jf-menu-btn:hover { text-decoration: none; }

.jf-menu-chev { width: 12px; height: 12px; opacity: 0.7; flex: none; }
.jf-menu-btn[aria-expanded="true"] .jf-menu-chev { transform: rotate(180deg); }
@media (prefers-reduced-motion: no-preference) { .jf-menu-chev { transition: transform 0.15s ease; } }

/* ── Inline nav tabs (scheduler-system only, until 18.5 — R3) ─────────────────────────────────────────── */

.jf-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: 12px;
    min-width: 0;
}

.jf-nav-link {
    font-size: 11.5px;
    color: rgba(255,255,255,0.72);
    padding: 7px 13px;
    border-radius: 8px;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.12s, color 0.12s;
}

.jf-nav-link:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.jf-nav-link.active {
    background: rgba(255,255,255,0.14);
    color: #fff;
}

/* R3 keeps the scheduler tab strip; with the menus beside it the left cluster can exceed
   the viewport between 1100px and ~1750px. Scroll the strip instead of overlapping the
   finder / Zulu / avatar (18.2 verify lens). */
.jf-topbar--tabs .jf-nav { flex: 1 1 0; min-width: 0; overflow-x: auto; scrollbar-width: thin; }
.jf-topbar--tabs .jf-menus { flex: none; }

/* ── Panels: category, mobile, account ───────────────────────── */

.jf-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 360px;
    background: var(--surface, #ffffff);
    color: var(--ink, #16202e);
    border: 1px solid var(--line, #e2dbcc);
    border-radius: var(--jf-r-lg);
    box-shadow: var(--jf-shadow-overlay);
    padding: 8px;
    z-index: 1;
    display: block;
}

/* Bridge the 8px gap so a hover-opened panel is not "left" on the way down. */
.jf-menu > .jf-panel::before { content: ''; position: absolute; left: 0; right: 0; top: -9px; height: 9px; }

/* Account panel: anchored to the bar's right edge (the bar is the
   containing block: position:relative ≥1100px, fixed below). */
.jf-panel-right { left: auto; right: var(--jf-bar-pad, 24px); min-width: 240px; }

.jf-panel a[role="menuitem"],
.jf-panel button[role="menuitem"] {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 0;
    margin: 0;
    background: none;
    border-radius: var(--jf-r-sm);
    color: var(--ink, #16202e);
    font: inherit;
    font-size: 14px;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.jf-panel [role="menuitem"]:hover,
.jf-panel [role="menuitem"]:focus-visible { background: var(--wash, #faf8f4); text-decoration: none; }
.jf-panel [role="menuitem"] small { color: var(--ink-muted, #5b6779); font-family: var(--font-mono, ui-monospace, Menlo, monospace); font-size: 11px; }
.jf-panel [role="menuitem"][aria-current="page"] { font-weight: 600; }
.jf-panel a.jf-panel-all { margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--line, #e2dbcc); color: var(--accent, #2c5282); font-weight: 500; border-radius: 0 0 var(--jf-r-sm) var(--jf-r-sm); }
.jf-panel button.jf-panel-signout { margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--line, #e2dbcc); border-radius: 0 0 var(--jf-r-sm) var(--jf-r-sm); }

/* Mobile panel furniture (outside the media query so it exists whenever the panel does) */
.jf-panel-group-label { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted, #5b6779); padding: 8px 10px 4px; }
.jf-panel-group + .jf-panel-group { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line, #e2dbcc); }
.jf-panel button.jf-panel-find { display: flex; align-items: center; gap: 8px; color: var(--ink-2, #55627a); }
.jf-panel-find svg { width: 14px; height: 14px; }

/* Account panel header (where the drawer's user card went) */
.jf-panel-user { display: flex; flex-direction: column; gap: 1px; padding: 6px 10px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line, #e2dbcc); }
.jf-panel-user-name  { font-size: 14px; font-weight: 600; color: var(--ink, #16202e); }
.jf-panel-user-email { font-size: 12px; color: var(--ink-2, #55627a); }
.jf-panel-user-role  { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted, #5b6779); margin-top: 3px; }
.jf-account-version  { font-size: 11px; font-family: var(--font-mono, ui-monospace, Menlo, monospace); color: var(--ink-muted, #5b6779); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Tool-finder trigger ─────────────────────────────────────── */

.jf-search {
    appearance: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    min-height: 34px;
    min-width: 220px;
    border: 1px solid var(--jf-bar-line);
    border-radius: var(--jf-r-sm);
    background: none;
    color: var(--bar-ink-dim, rgba(246, 242, 234, 0.72));
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.jf-search:hover { color: var(--bar-ink, #f6f2ea); border-color: rgba(246, 242, 234, 0.4); }
.jf-search-icon { width: 14px; height: 14px; flex: none; }
.jf-search-kbd { margin-left: auto; font-family: var(--font-mono, ui-monospace, Menlo, monospace); font-size: 11px; padding: 1px 5px; border: 1px solid rgba(246, 242, 234, 0.25); border-radius: 4px; }

/* ── Mobile "Tools" menu — hidden until the 1080px block ─────── */

.jf-mobile-btn { display: none; color: var(--bar-ink, #f6f2ea); padding: 8px; }
.jf-panel-mobile { display: none; }

/* ── Top bar right items ─────────────────────────────────────── */

.jf-zulu {
    font-family: var(--font-mono, ui-monospace, Menlo, monospace);
    font-size: 13px;
    color: var(--bar-ink, #f6f2ea);
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

/* Crew Portal — a permanent link to the crew's own sign-in, opened in a new
   tab. Sits where the deploy stamp was (the stamp lives on in the account
   panel header). Outlined like the finder trigger so the paper Sign In /
   avatar stays the one filled item on the right. */
.jf-topbar-portal {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    min-height: 40px;              /* the style guide's touch floor (owner, 2026-09-26, P-7); was 34px */
    border: 1px solid var(--jf-bar-line);
    border-radius: var(--jf-r-sm);
    color: var(--bar-ink, #f6f2ea);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.jf-topbar-portal:hover { background: var(--jf-bar-hover); border-color: rgba(246, 242, 234, 0.4); text-decoration: none; }
.jf-ext-icon { width: 12px; height: 12px; opacity: 0.8; flex: none; }

/* Screen-reader-only text (the "opens in a new tab" note on the portal link). */
.jf-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; }

.jf-topbar-icon {
    background: none;
    border: none;
    color: var(--bar-ink, #f6f2ea);
    cursor: pointer;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    /* 40px minimum hit area (WCAG 2.5.8). */
    min-width: 40px;
    min-height: 40px;
}

.jf-topbar-icon svg { display: block; }

.jf-topbar-login {
    padding: 6px 14px;
    min-height: 34px;
    background: var(--paper, #f6f2ea);
    border: 1px solid transparent;
    border-radius: var(--jf-r-sm);
    color: var(--accent-deep, #1e3a5f);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.jf-topbar-login:hover { background: var(--surface, #ffffff); }

/* ── Avatar ──────────────────────────────────────────────────── */

.jf-avatar-btn { padding: 0 !important; }

.jf-avatar-circle {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--paper, #f6f2ea);
    color: var(--accent-deep, #1e3a5f);
    font-weight: 600;
    font-size: 12px;
    display: grid;
    place-items: center;
}

.jf-avatar-btn:hover .jf-avatar-circle,
.jf-avatar-btn[aria-expanded="true"] .jf-avatar-circle { box-shadow: 0 0 0 2px rgba(246, 242, 234, 0.35); }

/* ── Focus rings. kit.css:24 paints outline: 2px solid var(--accent) —
   #2c5282 on the #1e3a5f bar is ~1.4:1, invisible. Paper ring on the bar;
   accent ring inside the paper panels (declared AFTER so it wins the tie). */
.jf-topbar :focus-visible { outline: 2px solid var(--bar-ink, #f6f2ea); outline-offset: 2px; }
.jf-panel :focus-visible,
.jf-finder :focus-visible { outline: 2px solid var(--accent, #2c5282); outline-offset: -2px; }

/* ── Tool-finder dialog (kit .jf-dialog chrome, css/kit.css:225-259; lives on <body>) ── */

.jf-finder { max-width: min(92vw, 34rem); margin: 12vh auto auto; }
.jf-finder::backdrop { background: var(--scrim, rgba(16, 28, 46, 0.55)); }
.jf-finder .jf-dialog-panel { padding: 8px; gap: 4px; border-radius: var(--jf-r-lg); box-shadow: var(--jf-shadow-overlay); }
.jf-finder-input {
    width: 100%;
    box-sizing: border-box;
    font: inherit;
    font-size: 15px;
    padding: 10px 12px;
    border: 0;
    border-bottom: 1px solid var(--line, #e2dbcc);
    border-radius: 0;
    background: transparent;
    color: var(--ink, #16202e);
}
.jf-finder-input:focus-visible { outline: none; border-bottom: 2px solid var(--accent, #2c5282); }
.jf-finder-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.jf-finder-list li { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 10px; border-radius: var(--jf-r-sm); font-size: 14px; color: var(--ink, #16202e); cursor: pointer; }
.jf-finder-list li[aria-selected="true"] { background: var(--wash, #faf8f4); }
.jf-finder-list li > span { white-space: nowrap; }
.jf-finder-list li small { display: block; width: 100%; color: var(--ink-muted, #5b6779); font-size: 12px; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.jf-finder-empty { color: var(--ink-muted, #5b6779); cursor: default; }

/* ── Between the fold and 1460px the full bar does not fit, so drop the back
   link (the underlined menu already marks the category) and make the finder
   icon-only; the Cmd-K chord and the mobile panel keep it reachable.
   Was 1300px for three menus (measured 2026-09-06: left cluster to 773px,
   right cluster 477px). The Training menu (2026-09-17) pushed the left
   cluster to 871px with '← Safety & Compliance', and the right cluster is
   539px signed in with the notes button, so the full bar needs ~1458px. ── */
@media (min-width: 1081px) and (max-width: 1460px) {
    .jf-back { display: none; }
    .jf-search { min-width: 0; padding: 6px 9px; }
    .jf-search-label, .jf-search-kbd { display: none; }
}

/* ── Mobile (≤ 1080px): the category menus become one "Tools" menu; the finder
   trigger moves inside it. One panel, anchored to the bar. No overlay.
   (Was 860px; raised 2026-09-06 — below ~1000px the four bar items cannot
   share the row with the right cluster. Raised to 1080px 2026-09-17: with
   the Training menu the compact bar measures ~1041px signed in.) ── */
@media (max-width: 1080px) {
    nav-bar { --jf-bar-pad: 16px; }
    .jf-topbar { gap: 12px; }
    .jf-menus  { display: none; }
    .jf-search { display: none; }
    .jf-back   { display: none; }
    .jf-mobile-btn { display: flex; }
    .jf-panel-mobile {
        display: block;
        left: 0;
        right: 0;
        top: 100%;
        min-width: 0;
        border-top: 0;
        border-radius: 0 0 var(--jf-r-lg) var(--jf-r-lg);
        max-height: calc(100vh - var(--jf-topbar-h, 54px));
        max-height: calc(100dvh - var(--jf-topbar-h, 54px));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .jf-panel-mobile [role="menuitem"] { white-space: normal; padding: 10px; min-height: 44px; }   /* --touch-target-min */
    .jf-panel-right { min-width: 220px; }
}

/* ── Mobile responsive ───────────────────────────────────────── */

/* Below ~1100px the eight inline tabs would crowd the right-side items
   (or overflow on iPad landscape) — hide them and let the hamburger
   drawer carry navigation. */
@media (max-width: 1100px) {
    .jf-nav {
        display: none;
    }

    /* Pin the topbar to the VISUAL viewport, not the document. Below this
       breakpoint a page's content (e.g. the scheduler grid) can be wider
       than the viewport; on iOS a pinch-zoom/pan then drags a merely
       position:relative topbar off-screen along with the rest of the
       document, taking the hamburger — the only way back to the drawer's
       full nav — with it. position:fixed keeps it anchored regardless of
       zoom/pan state. (The drawer/overlay are already position:fixed with
       top:var(--jf-topbar-h) — see below — so they're unaffected.)
       Must ship together with the body padding-top rule right below: every
       page shell (.scheduler-shell, .rv-shell, .crew-shell, .me-shell, …)
       sizes itself as calc(100vh - var(--jf-topbar-h)), assuming the bar
       still reserves that height via normal flow. Taking the bar out of
       flow without restoring that space would hide each shell's top
       ~54px behind the now-fixed bar. */
    .jf-topbar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
    }

    /* `html body` (0,0,0,2), not `body` (0,0,0,1): training.css ships a
       later-loaded, always-on `body { padding-top: env(safe-area-inset-top) }`
       (no page here sets viewport-fit=cover, so that resolves to a literal
       0px) that would otherwise win the cascade on load order alone and
       silently cancel this reservation — hiding every training-system
       page's top ~54px behind the now-fixed bar. The specificity bump wins
       regardless of any other subsystem's own body rule, present or future,
       without touching that file. */
    html body {
        padding-top: var(--jf-topbar-h, 54px);
    }
}

@media (max-width: 768px) {
    .jf-zulu {
        display: none;
    }
}

/* Phones: logo mark only, tighter gaps, so logo · Tools · Crew Portal · avatar
   fit in 375px without pushing the avatar off the right edge (measured 391px
   with the wordmark, 2026-09-06). */
@media (max-width: 480px) {
    .jf-logo-text { display: none; }
    .jf-topbar { gap: 8px; }
    .jf-topbar-right { gap: 10px; }
    .jf-topbar-portal { padding: 6px 10px; }
}

/* ── Hide old navbar elements (backward compat) ──────────────── */

.navbar { display: none !important; }
.navbar-container { display: none !important; }

/* ── Skip link (visually hidden until focused) ───────────────── */
.skip-to-content, .skip-link {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
    z-index: 9999;
    padding: 8px 16px;
    background: #2c5282;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 6px 0;
    font-family: var(--font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif);
}
.skip-to-content:focus, .skip-link:focus {
    position: fixed;
    left: 0;
    top: 0;
    width: auto;
    height: auto;
    overflow: visible;
}

/* ── Hide glass footer (navigation lives in the bar) ─────────── */
glass-footer { display: none !important; }
