/* PosnerTopbar — the hub's posner-topbar glass-bar language, lifted into the
   canon (Lane 1, hub-topbar-port 2026-10-15; reference: the p31ca hub
   `apps/p31ca/src/styles/topbar.css`). Full-width sticky glass bar with named
   slots: brand · absolute-centered center · chip cluster · overflow.

   Token-only (canon no-raw-values contract): every color routes through a
   --p31-* token or a color-mix of one. Length/geometry values follow the canon
   recipe stance (token where a token exists, fixed where the recipe does).

   @scope isolation (posner-namespace-two-models / M1, Wave C P9): the shared
   `.posner-topbar` namespace spans TWO markup models — the hub Astro "acts"
   model (apps/p31ca CanonTopbar: .posner-acts/.posner-utils/.posner-chip) and
   this canon "center/chips/overflow" model. Both render a `.posner-topbar`
   root, so an unscoped rule in one model's CSS can cross-contaminate the
   other. Per the plan this is isolated with the NATIVE mechanism (@scope, no
   rename): every rule below is scoped to `[data-posner-topbar]` — the marker
   the app model's markup carries in every world (React PosnerTopbar, the
   canon-parts spec tree, and the generated capital TopbarChrome) and the hub
   root does NOT carry. The hub-side `@scope (.posner-topbar--hub)` wrap is
   filed (apps/p31ca is a protected target; see
   docs/fix-plans/p31ca-wavec-defect-sweep-2026-10-16.md).

   :scope root rules (Wave 2 lane L-A): `@scope` compiles a plain `.foo`
   selector inside the wrapper to `marker .foo` — an implied descendant
   combinator — and an element is not its own descendant, so a plain
   `.posner-topbar { … }` root rule would never match the scoping root (the
   bar itself). The root rules therefore target `:scope` explicitly. The
   `[data-spoons]` + reduced-motion rules ALSO name the root, so their subject
   is `:scope` (or `:scope *` for the descendant-of-root form); an ancestor
   `[data-spoons='n']` outside the scoping subtree stays legal because `:scope`
   marks the in-subtree element and the ancestor chain may cross the boundary.
   */

@scope ([data-posner-topbar]) {
/* ─── Layer 1: container-query layout ─────────────────────────────── */
/* The bar wrapper is a layout container: container-type: inline-size makes it
   the query root. Breakpoints switch on the container's OWN width via @container
   in em — the same component then adapts to a wide marketing header, a narrow
   dashboard rail, or an embedded panel without viewport media queries. */
:scope {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--p31-space-2, 8px);
  /* Header-height contract: owned by --p31-header-height (the ratified single
     header token, 4rem); a wired canon token wins via the fallback. */
  height: var(--p31-header-height, var(--p31-topbar-height, 64px));
  /* The bar is a flex item in every portal shell (column flex, 100vh). Without
     this it shrinks below its own height contract whenever page content
     overflows — qpj measured 51.3px instead of 64px. */
  flex-shrink: 0;
  padding: 0 clamp(var(--p31-space-3, 12px), 3vw, var(--p31-space-7, 28px));
  border-bottom: 1px solid var(--p31-glass-border);
  background: color-mix(in oklch, var(--p31-bg, var(--p31-void)) 86%, transparent);
  backdrop-filter: var(--p31-glass-blur) saturate(150%);
  -webkit-backdrop-filter: var(--p31-glass-blur) saturate(150%);
}

/* Container-query center collapse: below 40em of the bar's OWN width the
   centered search hides and the overflow keeps every control reachable. This is
   the container-query answer to "responsive" — it tracks the bar, not the
   screen, and the same @container block works in a sidebar rail etc. */
:scope[data-topbar-profile="compact"] .posner-topbar__center,
:scope[data-topbar-profile="minimal"] .posner-topbar__center { display: none; }

/* ─── Brand zone ────────────────────────────────────────────────── */
.posner-topbar__brand-zone {
  display: inline-flex;
  align-items: center;
  gap: var(--p31-space-2, 8px);
  flex-shrink: 0;
}
.posner-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--p31-space-2, 8px);
  padding: var(--p31-space-1, 4px) var(--p31-space-2, 8px);
  border: 0;
  border-radius: var(--p31-radius-candy);
  background: none;
  cursor: pointer;
  color: var(--p31-text);
  font-family: inherit;
  flex-shrink: 0;
}
.posner-brand:hover { background: var(--p31-accent-soft); }
.posner-brand__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--p31-radius-md, 12px);
  background: var(--p31-accent);
  color: var(--p31-void);
  font-weight: 800;
  font-size: 13px;
}
.posner-brand__name {
  font-weight: 700;
  font-size: clamp(0.88rem, 1.2vw + 0.4rem, 1rem);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
@media (max-width: 640px) { .posner-brand__name { display: none; } }
.posner-theme-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  /* SSR-safe: reads --p31-theme-dot (set by the shell's theme prefs + the
     brand-click handler); fallback to the live accent token. */
  background: var(--p31-theme-dot, var(--p31-accent));
}

/* ─── Center slot — ABSOLUTE on the bar's geometric midpoint ───── */
.posner-topbar__center {
  /* Screen-center, not flex-center: absolutely positioned on the bar's
     horizontal midpoint, independent of the side zones' widths. The fluid
     width keeps the slot clear of the trailing cluster at every width. */
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--p31-space-2, 8px);
  min-width: 0;
  /* 500px reserves the brand + trailing clusters. Without it the
     absolutely-centred slot overlaps the brand on narrower shells
     (qpj: 932px header → "P31 Q…" was clipped by the search). */
  width: min(40vw, 560px, calc(100% - 500px));
}
/* Canon search pattern for the center slot. Portals that don't ship shell.css
   (qpj) would otherwise render a bare input whose line-box is taller than the
   bar. Design portal overrides width/height in its own unlayered sheet. */
.posner-topbar__center .search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  height: 40px;
}
.posner-topbar__center .search-box {
  display: flex;
  align-items: center;
  gap: var(--p31-space-2, 8px);
  width: 100%;
  height: 40px;
  padding: 0 44px 0 var(--p31-space-3, 12px);
  border: 1px solid var(--p31-glass-border);
  border-radius: var(--p31-radius-md, 12px);
  background: var(--p31-surface2);
  color: var(--p31-text);
  font-family: inherit;
  font-size: var(--p31-text-sm, 14px);
}
/* The slot is a wrapper + input in some portals and a bare input in others.
   Reset the inner field so the UA control chrome never leaks through. */
.posner-topbar__center .search-box > input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  outline: none;
}
.posner-topbar__center .search-kbd {
  position: absolute;
  right: var(--p31-space-2, 8px);
  top: 50%;
  transform: translateY(-50%);
  margin: 0;
  padding: 2px 6px;
  border: 1px solid var(--p31-glass-border);
  border-radius: 4px;
  background: var(--p31-surface);
  color: var(--p31-text-secondary);
  font-family: var(--p31-font-mono, monospace);
  font-size: var(--p31-text-xs, 12px);
  pointer-events: none;
}
/* No room for a wide search beside brand + trailing on phones — hide the
   center (matches the portal's pre-port mobile affordance; the overflow keeps
   every control reachable). */
@media (max-width: 560px) {
  .posner-topbar__center { display: none; }
}

/* ─── SIMPLIFIED MOBILE TOPBAR (duplicated-mobile-topbar-css fix-plan) ───
   The shared ≤768px topbar override every portal used to patch locally (design
   workspace.css, workspace/workspace.css, mcp-marketplace/globals.css,
   monetization/workspace.css — byte-similar copies) now lives HERE: the canon
   owns the responsive behavior, token-only (all geometry, no colors). At ≤768px
   the topbar is brand | FULL-WIDTH search (flex-1) | ONE overflow trigger; the
   chips hide (their controls live inside the overflow menu — ARIA intact) and
   the search stretches between brand and the overflow button — overriding the
   ≤560px center-hide above so the search stays up. The portal sheets keep their
   (identical) copies until the protected-portal removal wave (filed in the Wave
   C summary); this block lands after the 560px rule so the cascade order the
   portals relied on is preserved. */
@media (max-width: 768px) {
  .posner-chips { display: none; }
  .posner-topbar__center {
    position: static;
    transform: none;
    width: auto;
    max-width: none;
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
  }
  .posner-topbar__brand-zone,
  .posner-topbar__trailing { flex-shrink: 0; }
  .search-kbd { display: none; }
}
/* The mobile-only overflow rows (GitHub + identity chips, the Lane-C rows) —
   shown at ≤768px (the hidden chips' controls stay reachable), hidden ≥769px so
   the desktop overflow remains the enterprise-cluster-only menu. */
.posner-overflow__item--mobile { display: none; }
@media (max-width: 768px) {
  .posner-overflow__item--mobile { display: flex; }
}

/* ─── Trailing cluster (chips + overflow) ───────────────────────── */
.posner-topbar__trailing {
  display: inline-flex;
  align-items: center;
  gap: var(--p31-space-2, 8px);
  flex-shrink: 0;
}
.posner-chips { display: inline-flex; align-items: center; gap: var(--p31-space-2, 8px); flex-shrink: 0; }

/* ─── Compact INLINE ACTIONS (compact profile — L1) ────────────────
   The compact topbar's trailing cluster holds the capability controls
   directly (no chips row, no overflow disclosure). Same layout stance as the
   chips cluster; the actions never become an overflow. */
.posner-topbar__actions {
  display: inline-flex;
  align-items: center;
  gap: var(--p31-space-2, 8px);
  flex-shrink: 0;
}
.posner-topbar__action {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

/* ─── Overflow ──────────────────────────────────────────────────── */
.posner-overflow { display: inline-flex; flex-shrink: 0; }
.posner-overflow__trigger {
  anchor-name: --panel;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: var(--p31-space-1, 4px) var(--p31-space-2, 8px);
  border-radius: var(--p31-radius-candy);
  border: 1px solid var(--p31-glass-border);
  background: var(--p31-surface);
  color: var(--p31-text-secondary);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.posner-overflow__trigger:hover {
  border-color: var(--p31-glass-border-strong);
  color: var(--p31-text);
}
.posner-overflow__menu {
  right: 0;
  min-width: 240px;
  max-width: min(92vw, 320px);
  padding: var(--p31-space-2, 8px);
  background: var(--p31-glass-bg-strong);
  border: 1px solid var(--p31-glass-border);
  border-radius: 16px;
  box-shadow: 0 20px 50px oklch(0% 0 0 / 0.6);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  z-index: 2100;
  display: flex;
  flex-direction: column;
  gap: var(--p31-space-1, 4px);
}
/* The UA sheet hides a closed popover with a NON-!important rule, so any
   author `display` wins and a closed panel would keep painting. Re-assert
   the closed state explicitly. */
.posner-overflow__menu:not(:popover-open) { display: none; }
/* Invisible bridge across the 10px gap between trigger and menu — the
   pointer stays "inside" while crossing, so the menu doesn't close mid-move. */
.posner-overflow__menu::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 0;
  right: 0;
  height: 10px;
}
/* Menu row — the overflow slot's controls render as full-width rows. */
.posner-overflow__item {
  display: flex;
  align-items: center;
  gap: var(--p31-space-2, 8px);
  width: 100%;
  min-height: 38px;
  padding: var(--p31-space-1, 4px) var(--p31-space-3, 12px);
  border: 0;
  border-radius: var(--p31-radius-md, 12px);
  background: none;
  color: var(--p31-text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  transition: background 0.12s ease;
}
.posner-overflow__item:hover { background: var(--p31-surface2); }

/* Sensory-rest at spoons 0/1 REDUCES the bar — never removes it (the old
   display:none trap made it impossible to restore the topbar). The bar dims
   and loses motion; every control stays reachable. `:scope` (not the class) is
   the subject: the scoping root IS the .posner-topbar element, and the
   [data-spoons] ancestor lives outside the scoping subtree, which the rule may
   cross because the in-subtree element is marked with :scope. */
[data-spoons='0'] :scope,
[data-spoons='1'] :scope {
  opacity: 0.55;
}
[data-spoons='0'] :scope *,
[data-spoons='1'] :scope * {
  transition-duration: 0ms !important;
}
/* ---------- Layer 2: top-layer overlays + anchor positioning ---------- */
/* The trigger establishes the anchor name the panel positions against.
   Anchor positioning renders the panel relative to its trigger via
   anchor-name / position-anchor - never inside an overflow ancestor that
   could clip it. */

/* Base layer (ALL browsers): popover in top layer = no clipping.
   position-anchor + position-area place the panel under the trigger.
   No position-try-fallbacks here — the browser's default top-layer
   positioning handles edge overflow without flipping. This is the
   degradation contract: even without fallback flipping, the popover
   never clips because it lives in the top layer. */

.posner-act__panel {
  position: fixed;
  inset: auto;
  margin: 0;
  position-area: block-end span-inline-end;
  position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
}
:scope[data-topbar-profile="compact"] .posner-act__panel { min-width: 180px; }
.posner-overflow__menu {
  position: fixed;
  position-anchor: --panel;
  inset: auto;
  margin: 0;
  position-area: block-end span-inline-end;
  position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
  min-width: 240px;
  max-width: min(92vw, 360px);
}
:scope[data-topbar-profile="compact"] .posner-overflow__menu { min-width: 180px; max-width: min(92vw, 300px); }
.posner-act__panel::before,
.posner-overflow__menu::before {
  content: ''; position: absolute;
  top: -10px; left: 0; right: 0; height: 10px;
}
.posner-act__panel-item:focus-visible,
.posner-overflow__item:focus-visible {
  outline: 2px solid var(--p31-accent);
  outline-offset: 2px;
}

/* Enhanced layer (Chrome/Edge 143+ only): flip at viewport edges.
   Safari 26 reports position-try-fallbacks as supported but the behavior
   is inert (WebKit Bug 302261). Use a runtime browser check instead of
   @supports for this tier. The base layer already prevents clipping. */
/* position-try-fallbacks is NOT applied via @supports — Safari's false
   positive would cause incorrect styling. Apply via JS feature detection
   in topbar-policy.ts instead. */

/* Optimal layer removed: anchored container queries are Chrome-only and
   conflict with container-type. The panel is now a sibling of the header
   (outside the flex row) and uses implicit anchoring from popovertarget.
   No anchor-name. No position-anchor. No container-type. */

.posner-topbar[data-topbar-profile="compact"] .posner-overflow__menu { min-width: 180px; max-width: min(92vw, 300px); }
.posner-topbar[data-topbar-profile="minimal"] .posner-chips { display: none; }

/* ---------- Layer 3: OS and preference adaptation ---------- */
@media (prefers-color-scheme: dark) {
  :scope {
    background: color-mix(in oklch, var(--p31-bg, var(--p31-void)) 92%, transparent);
    backdrop-filter: var(--p31-glass-blur) saturate(150%);
    -webkit-backdrop-filter: var(--p31-glass-blur) saturate(150%);
  }
}
@media (forced-colors: active) {
  .posner-brand { color: CanvasText; }
  .posner-text { color: CanvasText; }
  .posner-chip { color: CanvasText; }
  .posner-text-secondary { color: GrayText; }
  .posner-accent { color: Highlight; }
  .posner-overflow__item { color: CanvasText; }
}
/* Reduced transparency: disable glass blur so the bar stays opaque */
@media (prefers-reduced-transparency: reduce) {
  :scope { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
  .posner-overflow__menu { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
}
/* Reduced contrast: stronger focus rings on interactive rows */
@media (prefers-reduced-contrast: high) {
  .posner-overflow__item { outline: 2px solid var(--p31-accent); }
  .posner-act__panel-item:focus-visible,
  .posner-overflow__item:focus-visible { outline: 2px solid var(--p31-accent); }
}

/* ---------- Layer 3: reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  :scope * {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
  }
  :scope { backdrop-filter: none; -webkit-backdrop-filter: none; }
}
} /* /@scope ([data-posner-topbar]) — the canon app-model chrome is isolated from
     the hub acts model by the native scoping mechanism (no rename). */