/* ============================================================================
   nav.css — THE PLATFORM NAVIGATION STRIP (`pnav`). ONE implementation, two apps.
   Spec: docs/Platform_Navigation_SSO_Spec_2026-09-08.md §2–§3 (Lincoln's rulings
   ① one strip on every page of both apps, ② built from the promoted design system).

   Served by sitewalk-server at GET /sitewalk/static/nav.css and included by BOTH
   the Sitewalk pages (whose `page()` renders the markup server-side) and the board
   templates (where nav.js builds it into #platform-nav).

   ⛔⛔ EVERY COLOUR, SIZE AND WEIGHT BELOW COMES FROM design/design-system/tokens.css
   AND NOTHING IS INVENTED (ruling ②, design/README.md §1.0). The literals in the
   `var(--token, LITERAL)` fallbacks are the tokens.css values verbatim — they exist
   because the BOARD pages define these custom properties in their own :root (they
   inject board_css_primitives(), which lifts board_v2.html's :root, which was itself
   extracted from the same north-star winner) while SITEWALK pages define none of
   them. So on the board the strip inherits the page's tokens; on Sitewalk it falls
   back to the identical tokens.css value. ⛔ Never "simplify" a fallback to a hex
   you like better: that is the recorded T1/T1b/T2-prompt-v1 baseline-anchoring
   failure, one surface further out.
   ============================================================================ */

/* The bar's height is published as a custom property because TWO other stylesheets
   have to leave room for it: `body > header` below (every app's own sticky header)
   and board_v2.html's full-height flex body. ⚡ Both read it with a `0px` fallback,
   so if THIS FILE FAILS TO LOAD (sitewalk-server down) the property is undefined,
   the fallback applies, and every page lays out exactly as it did before the strip
   existed — spec §3's "a board page must still render". */
:root { --pnav-h: 44px; }

/* --- the box --------------------------------------------------------------- */
/* On Sitewalk the <nav class="pnav"> is a direct child of <body>; on the board it
   sits inside the empty <div id="platform-nav"> nav.js fills. Whichever is the
   outermost element is the one that positions. */
#platform-nav,
body > .pnav {
  position: sticky;
  top: 0;
  /* Above the apps' own sticky headers (z-index 5 on all eight CRM templates and
     on Sitewalk's) and above their sticky table heads (z-index 1). */
  z-index: 60;
}

/* ⚠ board_v2.html ONLY. Its <body> is `display:flex; height:100vh; overflow:hidden`
   — a full-height flex ROW — so a sticky child becomes a narrow left-hand column
   instead of a bar. `fixed` takes the strip out of that flow entirely; board_v2's
   own body rule then leaves room for it with margin-top/height read off --pnav-h. */
#platform-nav[data-fixed] { position: fixed; left: 0; right: 0; }

.pnav {
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--pnav-h);
  padding: 0 10px;
  background: var(--card-bg, #FFFFFF);
  border-bottom: 1px solid var(--line, #E4E4E7);
  color: var(--ink, #1C1917);
  font-family: var(--font-ui, "Inter", system-ui, -apple-system, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif);
  font-size: var(--fs-ms, 12.5px);
  line-height: 1;
  box-sizing: border-box;
}
.pnav * { box-sizing: border-box; }

/* --- the lockup (board_v2.html's, verbatim: same viewBox, same three paths) --- */
.pnav-home {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: none;
  color: inherit;
  text-decoration: none;
  padding: 0 6px;
  min-height: 40px;                 /* tap target, spec §2.4 */
  border-radius: var(--r-sm, 6px);
}
.pnav-home:hover { background: var(--line3, #EEEEF1); }
.pnav-home svg { display: block; flex: none; }
.pnav-home .pnav-word {
  font-size: var(--fs-base, 15px);
  font-weight: var(--fw-bold, 700);
  letter-spacing: var(--ls-lockup, 0.22em);
}

/* --- ‹ › — the pair from design-system/sections/topbar.html ----------------- */
.pnav-hist { display: flex; gap: 4px; flex: none; margin-left: 4px; }
.pnav-btn {
  /* ≥40×40 tap target on every surface, spec §2.4. */
  min-width: 40px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--linebtn, #DADADE);
  background: var(--card-bg, #FFFFFF);
  color: var(--muted, #6E6E76);
  border-radius: var(--r-sm, 6px);
  font-family: inherit;
  font-size: var(--fs-lg, 17px);
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.pnav-btn:hover:not([disabled]) { border-color: var(--faint, #AEADB3); color: var(--ink, #1C1917); }
.pnav-btn[disabled] { color: var(--faint, #AEADB3); cursor: not-allowed; opacity: .65; }
.pnav-btn:focus-visible { outline: 2px solid var(--blue, #2563C9); outline-offset: 1px; }

/* --- the app links --------------------------------------------------------- */
.pnav-apps { display: flex; align-items: center; margin-left: 8px; min-width: 0; }
/* ⚠ ONE ELEMENT MORE THAN SPEC §2.1's SKETCH: the links live in a wrapper rather
   than being bare children of <details>. It buys the phone panel below a single
   `position:absolute` on one box instead of a hand-computed `top:` per link, which
   is a rule that silently breaks the day a sixth app is added. Same links, same
   order, same semantics. */
.pnav-applist { display: flex; align-items: center; gap: 2px; }
.pnav-apps > summary {
  /* Hidden above 640px: the links show inline and there is nothing to open.
     ⚠⚠ THE <details> IS RENDERED `open` AND THAT IS LOAD-BEARING, not a default
     somebody forgot. A CLOSED <details> hides its non-summary content in the UA
     stylesheet, by a mechanism (`::details-content` / an unrendered slot) that a
     `display:flex` on the child does NOT reliably override — so shipping it closed
     would make the desktop app links INVISIBLE. It ships open; nav.js closes it below
     640px and re-syncs only when that breakpoint is CROSSED, so a menu the user opened
     on a phone is never yanked shut under them. With no JS at all the links simply
     stay listed rather than collapsing — degraded, still navigable. */
  display: none;
  list-style: none;
  cursor: pointer;
}
.pnav-apps > summary::-webkit-details-marker { display: none; }
.pnav-apps a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 9px;
  border-radius: var(--r-sm, 6px);
  color: var(--muted, #6E6E76);
  text-decoration: none;
  font-size: var(--fs-md, 13px);
  white-space: nowrap;
}
.pnav-apps a:hover { background: var(--line3, #EEEEF1); color: var(--ink, #1C1917); }
.pnav-apps a[aria-current="page"] {
  color: var(--ink, #1C1917);
  font-weight: var(--fw-semi, 600);
  box-shadow: inset 0 -2px 0 var(--blue-hover, #1E4FA3);
}

/* --- the right-hand end ---------------------------------------------------- */
.pnav-sp { flex: 1 1 auto; }
.pnav-who {
  color: var(--muted, #6E6E76);
  font-size: var(--fs-ms, 12.5px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 30ch;
  padding-right: 4px;
}
/* The sign-out control is the CURRENT APP'S OWN (spec §4.4): a <form> POST on
   Sitewalk, an <a href="/logout"> on the board. Styled the same either way. */
.pnav-out { display: flex; align-items: center; flex: none; margin: 0; }
.pnav-out button, .pnav-out a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--linebtn, #DADADE);
  border-radius: var(--r-sm, 6px);
  background: var(--card-bg, #FFFFFF);
  color: var(--ink, #1C1917);
  font-family: inherit;
  font-size: var(--fs-md, 13px);
  text-decoration: none;
  cursor: pointer;
}
.pnav-out button:hover, .pnav-out a:hover { border-color: var(--faint, #AEADB3); }

/* --- every app's own sticky header sits BELOW the strip --------------------- */
/* ⚡ ONE rule instead of an edit to nine templates' CSS. `body > header` (0,0,2)
   outranks the templates' bare `header` (0,0,1), and this file is included inside
   <body> so it also loses no cascade race. Inert on board_v2, whose header is not
   sticky. ⚠ The `0px` fallback is what makes a failed load harmless. */
body > header { top: var(--pnav-h, 0px); }

/* --- phone ----------------------------------------------------------------- */
@media (max-width: 640px) {
  :root { --pnav-h: 48px; }
  .pnav { padding: 0 6px; gap: 2px; }
  /* Lockup icon only — the POPE wordmark is the first thing to go. */
  .pnav-home .pnav-word { display: none; }
  .pnav-who { display: none; }
  /* The app links collapse into the zero-JS <details> menu. */
  .pnav-apps { position: relative; margin-left: 2px; }
  .pnav-apps > summary {
    display: inline-flex;
    align-items: center;
    min-width: 40px;
    min-height: 40px;
    padding: 0 10px;
    border: 1px solid var(--linebtn, #DADADE);
    border-radius: var(--r-sm, 6px);
    color: var(--muted, #6E6E76);
    font-size: var(--fs-md, 13px);
  }
  .pnav-apps[open] > summary { color: var(--ink, #1C1917); }
  /* The open menu is a panel hanging off the bar, not a reflow of it — ONE
     positioned box, so adding a sixth app costs nothing here. */
  .pnav-applist {
    display: none;
    position: absolute;
    top: calc(var(--pnav-h) - 2px);
    left: 0;
    flex-direction: column;
    gap: 0;
    min-width: 176px;
    padding: 4px;
    background: var(--card-bg, #FFFFFF);
    border: 1px solid var(--line, #E4E4E7);
    border-radius: var(--r-sm, 6px);
    box-shadow: var(--shadow, 0 2px 10px rgba(28, 25, 23, 0.10));
  }
  .pnav-apps[open] .pnav-applist { display: flex; }
  .pnav-applist a { min-height: 44px; padding: 0 12px; }
}

/* --- dark ------------------------------------------------------------------ */
/* ⛔ SCOPED TO data-app="sitewalk" ON PURPOSE (spec §2.4). Sitewalk's pages carry a
   `prefers-color-scheme: dark` block; the BOARD has none and the strip must not be
   the thing that introduces one there — a dark bar over an otherwise light CRM page
   is worse than no dark mode at all. The values below are the ones Sitewalk's own
   dark block already overrides (`sitewalk_server.CSS`), so the strip matches the
   header it sits above rather than inventing a third palette. */
@media (prefers-color-scheme: dark) {
  .pnav[data-app="sitewalk"] {
    background: #0f1319;
    border-bottom-color: #2b313c;
    color: #e6e9ef;
  }
  .pnav[data-app="sitewalk"] .pnav-btn,
  .pnav[data-app="sitewalk"] .pnav-out button,
  .pnav[data-app="sitewalk"] .pnav-out a {
    background: #1b1f26;
    border-color: #39404d;
    color: #e6e9ef;
  }
  .pnav[data-app="sitewalk"] .pnav-btn { color: #95a0b3; }
  .pnav[data-app="sitewalk"] .pnav-btn[disabled] { color: #5b6472; }
  .pnav[data-app="sitewalk"] .pnav-apps a,
  .pnav[data-app="sitewalk"] .pnav-who { color: #95a0b3; }
  .pnav[data-app="sitewalk"] .pnav-apps a:hover,
  .pnav[data-app="sitewalk"] .pnav-home:hover { background: #232833; color: #e6e9ef; }
  .pnav[data-app="sitewalk"] .pnav-apps a[aria-current="page"] {
    color: #e6e9ef;
    box-shadow: inset 0 -2px 0 #8fb4ff;
  }
  .pnav[data-app="sitewalk"] .pnav-applist {
    background: #1b1f26;
    border-color: #2b313c;
  }
}
