/* ════════════════════════════════════════════════════════════════════
   App layout — sidebar + main content + page header + status footer
   ════════════════════════════════════════════════════════════════════ */

.app-shell { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar width — adapts to viewport via clamp() so the rail takes a
   roughly constant percentage of the page at any zoom level. Browser
   zoom shrinks the CSS-px viewport, so a fixed 256px sidebar would
   dominate a larger fraction of the page at higher zoom; this scales
   it down in lockstep. Floor 192px keeps the shorter labels legible;
   longer labels ("Stock Basis Scanner", "Fund Management") fall back
   to text-overflow: ellipsis cleanly. Ceiling 256px matches the
   original wide-display width. 16.5vw hits 256 at ~1550px viewport.

   The inner blocks (.sidebar-brand, .sidebar-nav, .sidebar-footer)
   now track the rail's actual width — no 256px content-pin — so
   the helmet + brand text center on the visible rail and nav labels
   truncate via ellipsis instead of being clipped mid-character. */
:root {
  --sidebar-width: clamp(192px, 16.5vw, 256px);
}

/* ── Sidebar ───────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; left: 0; top: 0;
  width: var(--sidebar-width); height: 100vh;
  background: var(--background);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 40;
  /* Inner content fills the rail at its current width — there is no
     256px pin anymore. The collapse animation handles label fade via
     opacity on the second span of each nav-item (see below); width
     transitions on .sidebar drive the rail's actual width down to
     64px. Text labels use text-overflow: ellipsis so they truncate
     cleanly at narrow widths instead of being clipped mid-character. */
  overflow: hidden;
}
.sidebar-brand {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  /* Don't let column-flex steal the brand block's height when total nav
     content exceeds the viewport — the .sidebar-nav below scrolls
     internally instead. */
  flex-shrink: 0;
}
/* Helmet — centered via left: 50% inside the now-fluid .sidebar-brand
   (which fills the rail's actual width). Fixed 128px width keeps the
   helmet at a consistent visual size across the clamp() range and
   guarantees the right half fills the 64px rail in collapsed mode
   (where `left: 0` slides the helmet so its midline sits at x=0 and
   its right half spans x=0 → x=64). A percentage width would have
   shrunk to 32px when the parent collapsed to 64, leaving an empty
   strip. */
.sidebar-brand .helmet {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 128px; height: 180%;
  opacity: .06; pointer-events: none;
  object-fit: contain;
  user-select: none;
  transition: left .22s cubic-bezier(.4, 0, .2, 1),
              opacity .22s ease;
}
:root[data-theme="dark"]  .sidebar-brand .helmet-on-light { display: none; }
:root[data-theme="light"] .sidebar-brand .helmet-on-dark  { display: none; }
:root[data-theme="light"] .sidebar-brand .helmet { opacity: .10; }
.sidebar-brand .brand-text {
  position: relative;
  padding: 18px 24px;
  text-align: center;
  z-index: 1;
  /* Fade the entire text block on collapse — keeps the brand block
     dimensions identical between expanded and collapsed states so
     downstream Y positions never shift. */
  transition: opacity .14s ease;
}
.sidebar-brand h1 {
  margin: 0; font-size: 12px; font-weight: 500;
  text-transform: uppercase; letter-spacing: .1em;
  white-space: nowrap;
}
.sidebar-brand .sub {
  margin-top: 4px;
  font-size: 10px; color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .2em;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1; padding: 0; overflow-y: auto;
  display: flex; flex-direction: column;
  /* Hide the scrollbar so opening a nav-group (which can push total
     content past the viewport) never renders a visible scrollbar that
     would shift every row left by its width. Reserving the gutter via
     scrollbar-gutter:stable would prevent the shift but leaves a
     permanent 6-px column on the right — short-cutting the row dividers
     and pulling absolutely-positioned chevrons inward. The nav is sized
     to fit without scrolling (see .nav-group-children max-height), and
     wheel/touch still scroll for rare overflow cases. */
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { width: 0; height: 0; display: none; }
/* Pushes the Administration section + Settings to the bottom, leaving the
   Workspace section flush against the brand. */
.sidebar-nav .nav-spacer { flex: 1; min-height: 16px; }

/* Section headers ("Workspace", "Research", "Administration"). Small
   uppercase muted label with the same horizontal padding as the items
   below. Darker background than the sidebar surface so each section
   reads as its own band — visually separates the groups beyond the
   single divider line. */
.sidebar-nav .nav-section-label {
  padding: 10px 24px 6px;
  font-size: 9px; font-weight: 600;
  color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .18em;
  background: transparent;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  user-select: none;
  white-space: nowrap;
  transition: color .14s ease;
  /* Pin the natural height — see .sidebar-brand for why. */
  flex-shrink: 0;
}
/* First label sits at the top of the sidebar — no rule above it. */
.sidebar-nav .nav-section-label:first-child { border-top: none; }
/* The first nav-item directly under a header would otherwise duplicate
   the divider (its own border-top + the header's border-bottom). Suppress
   the item's top border so we only ever draw one line at the boundary. */
.sidebar-nav .nav-section-label + .nav-item { border-top: none; }
/* The way back to the redesigned app (.nav-home): a link in the nav's own
   row style, above the first section. An anchor, so its underline is taken
   off; first in the nav, so it draws no rule above itself. */
.sidebar-nav a.nav-item { text-decoration: none; }
.sidebar-nav > a.nav-item:first-child { border-top: none; }

.sidebar-nav .nav-item {
  display: flex; align-items: center; gap: 12px;
  /* 13px vertical padding is tighter than the original 16px so all 14
     items + brand + footer fit a 1080p viewport when Portfolio is open
     (children add ~52px each, Δ4 = ~210px), but still gives the items
     comfortable breathing room around the 13px text. */
  padding: 13px 24px;
  border-top: 1px solid var(--border);
  color: var(--muted-foreground);
  font-size: 13px; cursor: pointer;
  transition: background .2s ease, color .2s ease, transform .2s ease;
  background: transparent;
  width: 100%; text-align: left;
  white-space: nowrap;
  /* Pin the natural row height. Without this, when total nav content
     exceeds .sidebar-nav's available height (browser zoom > 100%, short
     viewports), column-flex shrinks every item proportionally — and rows
     near the bottom (Portfolio's children, Administration items) end up
     compressed or visually overlapped instead of scrolling. */
  flex-shrink: 0;
}
/* The nav-item label (2nd span, after .nav-icon) — fades on collapse so
   the row's box is unchanged but the text disappears. Slight delay on
   the expand direction so the text only appears once the sidebar has
   visibly widened, instead of flickering inside the still-narrow rail.
   Flex sizing + ellipsis: takes the remaining row width and truncates
   gracefully when the rail's actual width can't fit the full label
   (e.g. "Stock Basis Scanner" at sidebar 192px). Without min-width: 0,
   the flex item refuses to shrink below its intrinsic content width
   and overflow: hidden / text-overflow: ellipsis never engage. */
.sidebar-nav .nav-item > span:nth-of-type(2) {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity .14s ease .08s;
}
.sidebar-nav .nav-item:hover {
  background: var(--surface-elevated);
  color: var(--foreground);
  transform: translateY(-1px);
}
.sidebar-nav .nav-item.active {
  color: var(--foreground);
  background: var(--surface-elevated);
}
.sidebar-nav .nav-item .nav-icon {
  width: 16px; height: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: currentColor;
}
.sidebar-nav .nav-item .nav-icon svg { width: 16px; height: 16px; }

/* ── Sidebar collapsible groups (e.g. Portfolio → Deals/Positions/…) ── */
.sidebar-nav .nav-group { display: contents; }
.sidebar-nav .nav-group-header {
  /* Inherits .nav-item base; chevron + slightly muted feel for non-page header.
     position:relative anchors the absolute-positioned chevron below — keeping
     the chevron out of flex flow means its x-position is driven by `right`
     (which lerps cleanly), not by the label's width snapping to zero on
     collapse, which is what was making the chevron jump. */
  position: relative;
  font-weight: 500;
}
.sidebar-nav .nav-group-header > span:nth-of-type(2) {
  /* The label (2nd span, after .nav-icon) flexes to fill the row.
     Extra padding-right reserves space for the absolute-positioned
     chevron so the label's ellipsis truncates BEFORE running into it,
     instead of overlapping at narrow widths. */
  flex: 1;
  padding-right: 22px;
}
.sidebar-nav .nav-group-chev {
  /* Anchored 24px from the parent's right edge — since the parent
     (.nav-group-header) now fills the rail's actual width (no more
     256px inner-pin), this puts the chevron at the visible right
     edge in both narrow and wide rails. translateY(-50%) centers
     vertically. The SVG inside rotates on group-open, not this
     wrapper — keeps the bounding rect stable so neighbouring
     chevrons don't visually shift during the rotation transition.
     Hidden via opacity in collapsed mode (see :root rule below). */
  position: absolute;
  right: 24px;
  top: 50%;
  width: 14px; height: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted-foreground);
  transform: translateY(-50%);
  transition: color .2s ease,
              opacity .14s ease .08s;
}
.sidebar-nav .nav-group-chev svg {
  width: 14px; height: 14px;
  transition: transform .42s cubic-bezier(.25, 1, .5, 1);
}
.sidebar-nav .nav-group.is-open .nav-group-chev svg {
  transform: rotate(90deg);
}
.sidebar-nav .nav-group-header:hover .nav-group-chev { color: var(--foreground); }

/* Open: cap sized for 4 children at the desktop nav-item height
   (13px padding × 2 + ~18px line + 1px border ≈ 45px → 4 × 45 = 180px).
   280px gives generous headroom for browser font-metric variance and
   any future 5th child without further tuning. */
.sidebar-nav .nav-group-children {
  overflow: hidden;
  max-height: 0;
  transition: max-height .42s cubic-bezier(.25, 1, .5, 1);
  /* Critical for short viewports: `overflow: hidden` zeroes the flex
     min-height floor (per CSS spec), so a column-flex parent under
     pressure will shrink THIS container ahead of the un-clipped rows
     above. The result was Deals/Positions/Analysis/Funding being
     clipped while Research items below them stayed at full height —
     reading visually as "Research overlaps the children". Pinning
     flex-shrink to 0 keeps the children at their full height; if the
     total still doesn't fit, .sidebar-nav's `overflow-y: auto` takes
     over and the user can scroll. */
  flex-shrink: 0;
}
.sidebar-nav .nav-group.is-open .nav-group-children { max-height: 280px; }
/* Fund Management bundles 6 children (Funds + CEX + DeFi + Investors +
   Reconciliation + Report), so 6×45 = 270px just barely fits 280px and
   leaves zero font-metric slack. Give it its own taller cap. Scanners
   reached 6 children too with Live Arb (Basis + Funding + Live Arb +
   Stock Basis + Earn + OTC Deal Scanner) so it shares every 6-child cap. */
.sidebar-nav .nav-group[data-nav-group="fund-management"].is-open .nav-group-children,
.sidebar-nav .nav-group[data-nav-group="scanners"].is-open .nav-group-children { max-height: 340px; }
/* Indent children so the hierarchy reads at a glance. The padding-left
   transition lerps the child icons (Deals/Positions/…) from x=44 → x=24
   as the sidebar collapses, instead of snapping. Duration matches the
   sidebar's width animation so they slide in lockstep. */
.sidebar-nav .nav-child {
  padding-left: 44px;
  font-size: 12px;
  transition: padding-left .22s cubic-bezier(.4, 0, .2, 1),
              background .2s ease, color .2s ease, transform .2s ease;
}
@media (prefers-reduced-motion: reduce) {
  .sidebar-nav .nav-group-children { transition: none; }
  .sidebar-nav .nav-group-chev { transition: none; }
  .sidebar-nav .nav-child { transition: none; }
}

/* ── Sidebar footer / status indicator ─────────────────────────────── */
.sidebar-footer {
  /* padding-left of 28 (vs 24 elsewhere) puts the 8-px pulse-dot's
     center at x=32, matching the 16-px nav icons' centers above and
     the geometric center of the 64-px collapsed rail — so the dot is
     aligned in both states with no shift on collapse. */
  padding: 13px 24px 13px 28px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--muted-foreground);
  transition: color .2s;
  /* Pin the natural height — see .sidebar-brand for why. */
  flex-shrink: 0;
}
.sidebar-footer .status-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
  transition: opacity .14s ease;
}
/* Status dot with concentric pulse rings.
   The dot itself stays solid — two pseudo-element halos expand outward in
   the dot's color and fade, staggered by half the duration so the ripple
   feels continuous rather than blinking. --pulse-color is the single
   source of truth and is overridden per data-state. */
.sidebar-footer .pulse-dot {
  position: relative;
  width: 8px; height: 8px; border-radius: 50%;
  /* Lock the circle's footprint. Without this, the default flex-shrink
     (1) lets the sidebar's narrow/collapsed states squeeze the dot
     horizontally so it reads as a thin "()" instead of a round "O". */
  flex: 0 0 8px;
  min-width: 8px; min-height: 8px;
  --pulse-color: var(--profit);
  background: var(--pulse-color);
  box-shadow: 0 0 6px color-mix(in srgb, var(--pulse-color) 60%, transparent);
  transition: background .2s, box-shadow .2s;
}
.sidebar-footer .pulse-dot::before,
.sidebar-footer .pulse-dot::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  background: var(--pulse-color);
  animation: pulse-ring 2.4s cubic-bezier(.32, 0, .2, 1) infinite;
  pointer-events: none;
  z-index: -1;     /* sit behind the solid dot */
}
.sidebar-footer .pulse-dot::after { animation-delay: 1.2s; }
@keyframes pulse-ring {
  0%   { transform: scale(1);    opacity: .55; }
  80%  { transform: scale(3.2);  opacity: 0; }
  100% { transform: scale(3.2);  opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar-footer .pulse-dot::before,
  .sidebar-footer .pulse-dot::after { animation: none; opacity: 0; }
}

/* Status states — drives the existing "System Online" dot to also act as the
   document-save indicator (replaces the old top-right pill). */
.sidebar-footer[data-state="saving"] .pulse-dot { --pulse-color: var(--status-dev); }
.sidebar-footer[data-state="saving"] .pulse-dot::before,
.sidebar-footer[data-state="saving"] .pulse-dot::after {
  animation-duration: 1.2s;     /* faster ripple while in flight */
}
.sidebar-footer[data-state="saving"] .pulse-dot::after { animation-delay: .6s; }
.sidebar-footer[data-state="saving"] { color: var(--status-dev); }
.sidebar-footer[data-state="error"] .pulse-dot { --pulse-color: var(--loss); }
.sidebar-footer[data-state="error"] .pulse-dot::before,
.sidebar-footer[data-state="error"] .pulse-dot::after {
  animation: none;              /* steady red — demands attention */
  opacity: 0;
}
.sidebar-footer[data-state="error"] { color: var(--loss); }
.sidebar-footer[data-state="saved"] .pulse-dot { --pulse-color: var(--profit); }

/* ── Main content area ────────────────────────────────────────────── */
.main {
  /* --main-pad-x lets the sticky .page-header below extend edge-to-edge
     of .main via a matching negative margin at every responsive
     breakpoint (32 → 20 → 16px). Override on each media block, never
     hardcode the px in the header rule. */
  --main-pad-x: 32px;
  margin-left: var(--sidebar-width);
  /* No padding-top — the sticky header lives flush with the viewport
     top so once it pins (.is-stuck) the glass surface touches y=0
     with no gap above. Vertical breathing room above the title at
     scroll=0 comes from the header's own internal padding instead. */
  padding: 0 var(--main-pad-x) var(--main-pad-x);
  flex: 1; height: 100vh;
  overflow-y: auto;
  /* Reserve the scrollbar gutter at all times so content width is
     constant whether the scrollbar is actually visible or not.
     Without this, any height change that crosses the viewport
     threshold (e.g. CEX timeline rows toggling display:none on
     scrub) flips the scrollbar in/out, content width shifts by the
     scrollbar width, and any percentage-column tables (timeline
     breakdown) jitter their column widths frame-by-frame. */
  scrollbar-gutter: stable;
  /* Belt-and-braces against horizontal overflow. Each grid container in
     the page (chart-grid, an-grid, report-shell, …) has min-width:0 on
     its items so 1fr tracks shrink properly and Chart.js canvases reflow
     instead of pushing the layout sideways. This `overflow-x: hidden`
     catches anything that still leaks (e.g. a third-party widget with a
     hardcoded width) so the user never gets a sideways-scrolling page —
     they get a contained scroll inside whichever card actually overflowed. */
  overflow-x: hidden;
  position: relative;
  min-width: 0;
}

/* ── Page header (sticky shy-glass app bar) ──────────────────────────
   At scroll=0 the bar reads as a normal page header — H1 + actions
   inline, transparent surface, no border or glass. Once the user
   scrolls .main past y=0, app.js flips .is-stuck and the glass
   background + blur + border + shadow fade in (the bar pins to
   viewport top via the sticky `top: 0` simultaneously, so the glass
   appears the instant the bar touches the top — no gap). Scrolling
   back to the top reverses everything. Matched .25s transitions on
   every glass property make the morph read as one motion.

   container-type: inline-size lets the title fade out when the
   bar's OWN width drops below 720px — fires when the sidebar's
   hover-expansion squeezes the header, not just when the viewport
   narrows. Actions never wrap or shrink; title is the only thing
   that gives way under width pressure. */
.page-header {
  position: sticky;
  top: 0;
  z-index: 30;                      /* below sidebar (40), above content */
  display: flex; justify-content: space-between; align-items: center;
  /* Parent never wraps — title block + actions block must stay on the
     same header row. Narrowing priority is enforced by flex-shrink
     ratios on the children (see .page-header-titles and
     .page-header-actions): (1) both visible on one row, (2) title
     clips/fades out, actions still on one row, (3) actions wraps
     its own controls onto a 2nd row with the title still hidden.
     The action block dropping beneath the title was a design no-go. */
  flex-wrap: nowrap;
  gap: 16px;
  /* Left margin carries --header-inset, set only while the rail is
     auto-hover-expanded (see the "hover-expand floats; pin reflows" block
     below). It shifts the header right by (railWidth − 64) so the sticky
     bar stays clear of the floating rail while the body content underneath
     stays put. Default inset 0 → bleeds to .main's edge like the right
     margin (cancels .main's padding so the glass bar runs edge-to-edge). */
  margin: 0 calc(-1 * var(--main-pad-x)) 0 calc(var(--header-inset, 0px) - var(--main-pad-x));
  padding: 14px var(--main-pad-x);
  /* Resting state — transparent surface, no border, no glass. The
     bar reads as ordinary page content. */
  background: transparent;
  border-bottom: 1px solid transparent;
  box-shadow: none;
  -webkit-backdrop-filter: none;
          backdrop-filter: none;
  transition: background .25s ease,
              border-bottom-color .25s ease,
              box-shadow .25s ease,
              -webkit-backdrop-filter .25s ease,
              backdrop-filter .25s ease,
              /* Lockstep with the rail width + .main margin (.22s, same
                 easing) so the header's left edge tracks the rail's right
                 edge through every expand/collapse/pin transition.
                 --header-motion is zeroed under prefers-reduced-motion so
                 the shift snaps with the rail (the glass fade above is a
                 color/opacity change, not motion, so it stays). */
              margin var(--header-motion, .22s cubic-bezier(.4, 0, .2, 1));
  /* container-type lets the title's fade-out below respond to the
     header's OWN width (which shrinks as the sidebar expands or the
     viewport narrows), not the viewport's. Means the title hides
     when squeezed by the sidebar opening, not just when the window
     itself is small. */
  container-type: inline-size;
}
.page-header.is-stuck {
  /* Stuck state — glass surface fades in once the bar pins to the
     viewport top. Translucent fill + backdrop blur let scrolled
     content show through, the bottom border + shadow make the
     boundary unambiguous. */
  background: rgba(20, 20, 20, .55);
  border-bottom-color: var(--border);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
          backdrop-filter: blur(10px) saturate(120%);
  box-shadow:
    0 1px 0 rgba(255,255,255,.03) inset,
    0 6px 20px rgba(0, 0, 0, .25);
}
:root[data-theme="light"] .page-header.is-stuck {
  background: rgba(255, 255, 255, .55);
  box-shadow:
    0 1px 0 rgba(255,255,255,.6) inset,
    0 4px 16px rgba(17, 17, 17, .06);
}

/* Title block — H1 only now, lives on the left side of the bar.
   min-width: 0 + overflow: hidden lets it shrink (down to 0). The
   high flex-shrink ratio (1000 vs the actions row's default 1)
   absorbs ~all of any horizontal overflow into the title, so the
   OVERVIEW text clips out from the right BEFORE the actions row
   loses any of its width. Once the title is fully clipped, only
   then does the actions row begin to shrink (and wrap, see
   .page-header-actions). This intrinsic mechanism replaces the
   earlier magic-number @container thresholds — it adapts per-page
   automatically because the actions' natural width drives where
   the wrap kicks in. */
.page-header-titles {
  min-width: 0;
  flex-shrink: 1000;
  overflow: hidden;
  transition: opacity .2s ease;
}
.page-header-titles h1 {
  margin: 0; font-size: 30px; font-weight: 500;
  text-transform: uppercase; letter-spacing: .2em;
  white-space: nowrap;
}
/* Below ~1400px of bar width — about where the actions row's natural
   width (fund + val-date + live + EOM + calc + add-deal + theme ≈
   1100px) plus the title's natural width (≈150px) + gap + padding
   stops fitting — fade the title out entirely and reclaim its row
   space for the actions. The previous 720px threshold was calibrated
   for a much-smaller actions row and let the title clip mid-word
   ("OVERVI…") against the toggles. Fires the moment the sidebar's
   hover-expansion squeezes the header, too, not just on narrow
   viewports. */
@container (max-width: 1400px) {
  .page-header-titles {
    opacity: 0;
    pointer-events: none;
    flex-basis: 0;
    flex-grow: 0;
  }
}

/* Subtitle in normal page flow under the header. Scrolls away with
   content; the pinned glass bar above keeps the page identity. */
.page-sub {
  margin: 8px 0 10px;
  font-size: 12px;
  color: var(--muted-foreground);
}

/* Mobile-only controls toggle — fixed top-left, mirrors the
   .mobile-nav-toggle's glass style. Hidden on desktop where the
   action row is always inline in the pinned bar. */
.page-header-actions-toggle {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 70;                      /* same band as .mobile-nav-toggle */
  width: 44px; height: 44px;
  padding: 0;
  background: var(--surface-card);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-backdrop-filter: blur(14px) saturate(130%);
          backdrop-filter: blur(14px) saturate(130%);
  box-shadow:
    0 1px 0 rgba(255,255,255,.03) inset,
    0 8px 24px rgba(0,0,0,.40);
  transition: background .2s ease, border-color .2s ease,
              transform .15s ease, box-shadow .2s ease;
}
:root[data-theme="light"] .page-header-actions-toggle {
  background: rgba(255,255,255,.78);
  box-shadow:
    0 1px 0 rgba(255,255,255,.6) inset,
    0 6px 18px rgba(17,17,17,.10);
}
.page-header-actions-toggle:hover { border-color: var(--border-strong); }
.page-header-actions-toggle:active { transform: scale(.96); }
.page-header-actions-toggle svg {
  width: 20px; height: 20px;
  transition: transform .2s ease;
}
.page-header-actions-toggle[aria-expanded="true"] svg {
  transform: rotate(180deg);
}
.page-header-actions {
  /* Wrap-allowed by default, but the title's much-higher flex-shrink
     (1000 vs our default 1) means in practice the title clips out
     first and the actions block holds its full natural width as the
     bar narrows. Only once the title has clipped to 0 does this
     block start shrinking — and at that point, because flex-wrap is
     wrap, the controls reflow to a 2nd row instead of overflowing
     off the right edge. Priority order as the bar narrows is thus
     (1) title + actions on one row, (2) title clipped, actions on
     one row, (3) title clipped, actions wrapped to 2 rows. No
     magic-number breakpoints — the transition points adapt to each
     page's natural action-row width automatically.
     justify-content: flex-end keeps the wrapped 2nd row aligned
     under the rightmost item of the 1st row (instead of orphaned
     left). */
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  /* Unified height across every control in the action row. Without this,
     the row mixes five different intrinsic heights (field-inline + fund-
     select stacks double padding to ~44px, .primary 35.5px, .ghost
     35.5px, .switch 30.5px, .theme-toggle 32×32) which reads as
     haphazard. Pinning all of them to --nav-control-h with
     box-sizing: border-box gives a clean strip aligned to the fund
     selector. */
  --nav-control-h: 36px;
}
.page-header-actions > .field-inline,
.page-header-actions > .switch,
.page-header-actions > button.primary,
.page-header-actions > button.ghost,
.page-header-actions > button.theme-toggle {
  height: var(--nav-control-h);
  box-sizing: border-box;
}
.page-header-actions > button.theme-toggle {
  /* Square footprint at the unified height — overrides the 32×32
     default in components/buttons.css when sitting in this row. */
  width: var(--nav-control-h);
}
/* Drop the outer .field-inline's vertical padding inside the action row
   so the wrapper itself fits the unified 36px height. The embedded
   .fund-select also gets trimmed padding so it reads as a clearly-
   nested control inside the wrapper (visible inset on top + bottom)
   rather than fusing into one slab — the .field-inline pill carries
   the label + tinted background; the .fund-select carries its own
   border + opaque surface inside it. Without trimming the select's
   own padding it grows to ~34px and visually fills the 34px wrapper
   content area, defeating the nested-control look. */
.page-header-actions > .field-inline {
  padding-top: 0;
  padding-bottom: 0;
}
.page-header-actions > .field-inline .fund-select {
  padding-top: 3px;
  padding-bottom: 3px;
}

/* ── Tabs (sidebar handles primary nav, but kept for tab-panel switch) ─ */
.tabs { display: none; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade-in .25s ease-out; }
/* Pre-paint visibility — show the panel matching the URL-derived active
   tab before app.js boots, so a reload on any path lands on its panel
   directly instead of flashing the previously-remembered tab. The list
   below MUST cover every tab in lib/tab-routes.ts; anything missing
   reverts to a blank shell until JS toggles .active on the panel. */
html[data-active-tab="liveoverview"] #tab-liveoverview,
html[data-active-tab="risk"]     #tab-risk,
html[data-active-tab="overview"] #tab-overview,
html[data-active-tab="deals"]    #tab-deals,
html[data-active-tab="positions"] #tab-positions,
html[data-active-tab="analysis"] #tab-analysis,
html[data-active-tab="funding"]  #tab-funding,
html[data-active-tab="report"]   #tab-report,
html[data-active-tab="backtest"] #tab-backtest,
html[data-active-tab="tokendd"]  #tab-tokendd,
html[data-active-tab="fundingscan"] #tab-fundingscan,
html[data-active-tab="fundingarb"]  #tab-fundingarb,
html[data-active-tab="livearb"]     #tab-livearb,
html[data-active-tab="stockbasis"]  #tab-stockbasis,
html[data-active-tab="earnscan"]    #tab-earnscan,
html[data-active-tab="funds"]    #tab-funds,
html[data-active-tab="cex"]      #tab-cex,
html[data-active-tab="defi"]     #tab-defi,
html[data-active-tab="users"]    #tab-users,
html[data-active-tab="investors"] #tab-investors,
html[data-active-tab="reconciliation"] #tab-reconciliation,
html[data-active-tab="settings"] #tab-settings { display: block; animation: fade-in .25s ease-out; }

/* ── Desktop sidebar collapse ──────────────────────────────────────────
   Two-level state model (wired in app.js bindSidebarCollapse):
     data-sidebar-mode      = "auto" | "pinned"   (user intent)
     data-sidebar-collapsed = "1"                 (current visual state)
   Mode "auto" is the default — the rail sits at 64px and hover-expands;
   leaving the rail (or clicking a leaf tab) re-collapses it. Mode
   "pinned" forces the rail open regardless of cursor position. The
   chevron icon flips 180° via [data-sidebar-mode="auto"] so it reads
   `>>` (pin) while in auto and `<<` (unpin) while pinned. Both attrs
   are pre-applied in index.html's inline boot script to avoid a width
   flash on reload. */
.sidebar-toggle {
  display: flex; align-items: center; justify-content: center;
  height: 36px;
  padding: 0;
  background: transparent;
  border: none;
  border-top: 1px solid var(--border);
  border-radius: 0;
  color: var(--muted-foreground);
  cursor: pointer;
  flex-shrink: 0;
  transition: color .2s ease, background .2s ease;
}
.sidebar-toggle:hover {
  color: var(--foreground);
  background: var(--surface-elevated);
}
.sidebar-toggle svg {
  width: 14px; height: 14px;
  transition: transform .25s ease;
}
/* Chevron points right (`>>`) in auto mode — clicking pins the rail
   open. Pinned flips it to `<<` (default unrotated state) — clicking
   returns to auto. Bound to mode, not collapsed: a hover-expanded auto
   rail still shows `>>` because the auto-expand is ephemeral. */
:root[data-sidebar-mode="auto"] .sidebar-toggle svg {
  transform: rotate(180deg);
}

/* Vestigial from the prior drag-resize model. The dynamic sidebar
   (hover-expand + >> pin toggle) made every interaction here either
   redundant or wrong — so the strip becomes a purely visual marker
   and pointer-events: none lets cursor + click pass straight through
   to whatever's behind it (.main content). The element stays in the
   DOM in case we want to repurpose the slot, but it eats no input. */
.sidebar-resize-handle {
  position: absolute;
  top: 0; right: -3px; bottom: 0;
  width: 6px;
  z-index: 41;
  pointer-events: none;
  background: transparent;
}

/* Sidebar width and .main's margin-left both animate over .22s — the
   page layout genuinely reflows so bentos / page header / banners
   resize smoothly into the new space (rather than translating as a
   block). The expensive part of a per-frame reflow on this app is
   Chart.js, whose ResizeObserver fires every frame and triggers a
   full canvas redraw; that's suspended in JS during the .22s and
   replayed once at the end. Tables relayout natively in the browser
   and are fast enough not to need special handling. */
.sidebar { transition: width .22s cubic-bezier(.4, 0, .2, 1); }
.main    { transition: margin-left .22s cubic-bezier(.4, 0, .2, 1); }

/* While any rail/main transition is in flight (`data-sidebar-animating`
   set from JS — on a hover toggle the rail width animates; on a pin/unpin
   .main reflows too), suppress hover transforms inside the sidebar so the
   items don't jitter as the cursor crosses them, and contain layout to the
   sidebar/main subtrees so reflows from the width change don't escape
   upward. */
:root[data-sidebar-animating="1"] .sidebar-nav .nav-item:hover {
  transform: none;
}
:root[data-sidebar-animating="1"] .sidebar,
:root[data-sidebar-animating="1"] .main {
  /* `layout` only — not `paint` — so any popover/tooltip positioned to
     escape .main (e.g. token-dd dropdown overflowing the column edge)
     still renders correctly during the .22s transition. */
  contain: layout;
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .main, .sidebar-toggle svg, .sidebar-brand .helmet { transition: none; }
  /* Snap the sticky header's rail-clearance shift in step with the rail. */
  :root { --header-motion: 0s; }
}

/* ── Collapsed state (desktop only) ──
   64 px wide rail. Critical principle: every element keeps the EXACT
   same outer dimensions, padding, and Y position as in expanded mode.
   The only thing that changes is opacity on the text content + the
   sidebar's visible width (which clips the right side of each row via
   overflow:hidden). This guarantees that toggling the sidebar never
   shifts the vertical position of any nav item — icons stay locked to
   their Y coordinates whether you're collapsed, expanded, or mid-drag.
   Icons are already visually centered in the 64 px rail because the
   row's padding-left (24 px) plus the icon width (16 px) reaches x=40,
   leaving 24 px on the right too.

   Wrapped in min-width: 721 px so a stale data-sidebar-collapsed="1"
   from a previous desktop session doesn't bleed through to the mobile
   full-screen overlay (which doesn't have a collapsed concept at all). */
@media (min-width: 721px) {
  /* The rail's own visible width is keyed on hover state (collapsed=1 →
     64px icon rail, else the full clamp() width). */
  :root[data-sidebar-collapsed="1"] .sidebar { width: 64px; }

  /* ── Hover-expand floats; pin reflows ──────────────────────────────
     The BODY margin is keyed on MODE, not hover state. In "auto" mode
     .main holds at the 64px collapsed offset no matter what the rail is
     doing — a hover-expanded rail simply floats OVER the content (it's
     position:fixed, z-index 40, opaque-backgrounded), so .main never
     changes width and no bento/chart per-frame reflow fires on hover
     (smooth on low-power devices). PINNING switches the mode to "pinned",
     which drops this override so the baseline `.main { margin-left:
     var(--sidebar-width) }` applies and the page reflows out to make
     room for the rail — once, on the pin/unpin. */
  :root[data-sidebar-mode="auto"] .main { margin-left: 64px; }

  /* While auto-hover-expanded, the rail overlaps the body's left edge,
     but the sticky header must stay clear of it — so ONLY the header
     shifts right by (railWidth − 64), via the --header-inset it feeds
     into .page-header's left margin. It transitions in lockstep with the
     rail width, so the header's left edge tracks the rail's right edge
     throughout. Collapsed (auto, not hovered) and pinned both leave inset
     0: collapsed needs no shift, pinned already reserved the space in
     .main. */
  :root[data-sidebar-mode="auto"][data-sidebar-collapsed="0"] {
    --header-inset: calc(var(--sidebar-width) - 64px);
  }

  /* Brand: fade the text to 0 but keep brand-text padding, so the brand
     block height matches the expanded state pixel-for-pixel. The helmet
     stays visible — it slides leftward so its right half peeks out from
     the 64-px rail. The transition on .helmet's `left` (declared at the
     .sidebar-brand .helmet rule above) carries this lerp smoothly in
     both directions. */
  :root[data-sidebar-collapsed="1"] .sidebar-brand .brand-text { opacity: 0; }
  :root[data-sidebar-collapsed="1"] .sidebar-brand .helmet {
    /* Helmet center sits at x=0 (the rail's left edge). With width
       128px (fixed) and translateX(-50%), the helmet spans -64px to
       +64px — its left half is clipped by overflow:hidden and its
       right half (0 → 64px) exactly fills the 64px collapsed rail. */
    left: 0;
    opacity: .12;
  }

  /* Nav items: keep padding + gap identical so the icon X position
     stays put. The 16-px icon at padding-left 24 already centers
     mathematically in the 64-px rail (24 + 16 + 24 = 64). The label
     fades via opacity; zero-width + pointer-events:none stops it from
     intercepting hover/clicks once invisible. */
  :root[data-sidebar-collapsed="1"] .sidebar-nav .nav-item > span:nth-of-type(2) {
    opacity: 0;
    pointer-events: none;
    width: 0;
    flex: 0 0 0;
    overflow: hidden;
  }

  /* nav-child rows are indented by padding-left:44 in expanded mode for
     visual hierarchy (Deals/Positions/Analysis/Funding under Portfolio).
     In the 64-px rail that 44 + 16 + 4 layout puts the icon at x=52,
     visibly right-shifted vs. their parent items. Override to 24 so
     children's icons line up under the standalone nav-icons above. */
  :root[data-sidebar-collapsed="1"] .sidebar-nav .nav-child {
    padding-left: 24px;
  }

  /* Group-header chevron is hidden in collapsed mode — the labels are
     invisible there anyway, so the "expandable" affordance has no
     job to do. (Previously it slid to right: 197px to peek next to
     the icon, but that math was hand-calibrated for the 256px
     inner-pin which doesn't exist anymore. Hiding is cleaner.) */
  :root[data-sidebar-collapsed="1"] .sidebar-nav .nav-group-chev {
    opacity: 0;
  }

  /* Section labels: fade text via color, keep box dimensions intact so
     the section bands look identical in height between collapsed and
     expanded. Top/bottom borders still draw because they're not tied
     to the text color. */
  :root[data-sidebar-collapsed="1"] .sidebar-nav .nav-section-label {
    color: transparent;
  }

  /* Status text fades on collapse; dot stays put since the footer's
     28-px padding-left already centers it at x=32 in both states. */
  :root[data-sidebar-collapsed="1"] .sidebar-footer .status-text { opacity: 0; }
}

/* Two floating popups share this glass treatment, both appended to
   <body> so they escape .sidebar-nav's overflow-y:auto clip:
     #nav-tooltip — transient, shown on collapsed nav-item hover
     #status-popup — persistent, shown while #status-text != "System Online"
   They live in separate DOM elements with separate lifecycles
   (hideNavTooltip is called all over the place to dismiss the transient
   one; the persistent badge stays alive until status reverts). aria-
   label on each nav-item still feeds screen readers. */
#nav-tooltip,
#status-popup {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  padding: 6px 10px;
  /* Liquid-glass surface: translucent fill + backdrop blur+saturate so
     whatever sits behind the popup (page chrome, charts) shows
     through. Mirrors the auth-card on the sign-in screen. The light-
     theme override below picks an explicit translucent white because
     --surface-card is opaque #ffffff in light mode. */
  background: var(--surface-card, var(--background));
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .02em;
  white-space: nowrap;
  /* translateY(-50%) vertically centers on the source item; X coordinate
     is set per-show in JS to sit just right of the sidebar. */
  transform: translateY(-50%);
  opacity: 0;
  -webkit-backdrop-filter: blur(10px) saturate(120%);
          backdrop-filter: blur(10px) saturate(120%);
  box-shadow:
    0 1px 0 rgba(255,255,255,.04) inset,
    0 8px 24px rgba(0, 0, 0, .35);
  transition: opacity .08s ease;
}
/* #status-popup additionally animates its position so it tracks the
   sidebar's width smoothly during collapse/expand. The nav-tooltip
   should jump between items (no slide), so it sticks with the base
   opacity-only transition above. */
#status-popup {
  transition: opacity .08s ease,
              left .22s cubic-bezier(.4, 0, .2, 1),
              top .22s cubic-bezier(.4, 0, .2, 1);
}
:root[data-theme="light"] #nav-tooltip,
:root[data-theme="light"] #status-popup {
  /* Dropped from .78 to .55 so light-mode reads as glass like dark,
     instead of opaque white. Page content behind a popup is small
     and ephemeral — legibility risk is minimal. */
  background: rgba(255,255,255,.55);
  box-shadow:
    0 1px 0 rgba(255,255,255,.6) inset,
    0 8px 20px rgba(17,17,17,.10);
}
#nav-tooltip.is-visible,
#status-popup.is-visible { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  #nav-tooltip, #status-popup { transition: none; }
}
/* Hide on mobile — the sidebar is a full-screen overlay there, not an
   icon rail, so the popup model doesn't apply (mobile gets its own
   floating status bubble at the bottom-right). */
@media (max-width: 720px) {
  #nav-tooltip, #status-popup { display: none; }
}

/* ── Responsive: tighten main padding on narrow desktop widths ─────
   Sidebar width itself adapts via the viewport-responsive clamp() at
   the top of this file — no per-breakpoint width override needed.
   --main-pad-x flows through to .page-header's negative margin so the
   pinned glass bar stays edge-to-edge at every breakpoint. */
@media (max-width: 900px) {
  .main { --main-pad-x: 20px; }
}
/* Collapsed-state width override is scoped to the desktop band only.
   Without the explicit `min-width: 721px` lower bound, this rule's
   (0,0,2,0) specificity outranks the mobile sidebar's `.sidebar`
   width:100% (0,0,1,0) — so flipping to mobile while
   data-sidebar-collapsed="1" was set on desktop would render the
   full-screen overlay as a 64-px sliver, cutting the nav off on
   the left. */
@media (min-width: 721px) and (max-width: 900px) {
  :root[data-sidebar-collapsed="1"] .sidebar { width: 64px; }
  :root[data-sidebar-collapsed="1"] .main    { margin-left: 64px; }
}

/* ── Short desktop viewports: tighten nav rows so the full menu fits ──
   Triggered by browser zoom > 100% (which shrinks the CSS-px viewport),
   small laptop displays, or split windows. Without this the nav still
   functions — `.sidebar-nav { overflow-y: auto }` lets the user scroll —
   but tightening the rows keeps every item visible on common zoom levels
   so the user never has to discover the scroll. Two breakpoints so the
   degradation is graceful: first shave padding, then collapse the
   section labels to slim dividers. Below ~620px we let scroll take over.
   Scoped to `min-width: 721px` so the mobile overlay (which has its
   own clamp()-based tightening at the bottom of this file) is unaffected. */
@media (min-width: 721px) and (max-height: 820px) {
  .sidebar-brand .brand-text { padding: 12px 24px; }
  .sidebar-nav .nav-item { padding: 9px 24px; }
  .sidebar-nav .nav-section-label { padding: 6px 24px 4px; }
  .sidebar-footer { padding: 9px 24px 9px 28px; }
  /* Recompute max-height for the open Portfolio group — at 9px padding
     the children are ~37px each, so 4×37 + slack = ~170px. */
  .sidebar-nav .nav-group.is-open .nav-group-children { max-height: 200px; }
  /* Fund Management has 6 children — 6×37 = 222px exceeds the
     Portfolio-sized cap above. */
  .sidebar-nav .nav-group[data-nav-group="fund-management"].is-open .nav-group-children,
  .sidebar-nav .nav-group[data-nav-group="scanners"].is-open .nav-group-children { max-height: 250px; }
}
@media (min-width: 721px) and (max-height: 700px) {
  .sidebar-brand .brand-text { padding: 8px 24px; }
  .sidebar-brand h1 { font-size: 11px; }
  .sidebar-brand .sub { font-size: 9px; margin-top: 2px; }
  .sidebar-nav .nav-item { padding: 6px 24px; font-size: 12px; }
  /* Section labels collapse to a slim double-rule divider — the existing
     border-top + border-bottom on .nav-section-label become the visible
     line, with text suppressed via font-size: 0. Mirrors the mobile
     cramped-viewport rule (max-width: 720px and max-height: 620px). */
  .sidebar-nav .nav-section-label {
    padding: 0 24px;
    height: 4px;
    line-height: 0;
    font-size: 0;
    overflow: hidden;
  }
  .sidebar-nav .nav-group.is-open .nav-group-children { max-height: 160px; }
  /* Fund Management 6-child override — 6×32 ≈ 192px. */
  .sidebar-nav .nav-group[data-nav-group="fund-management"].is-open .nav-group-children,
  .sidebar-nav .nav-group[data-nav-group="scanners"].is-open .nav-group-children { max-height: 220px; }
  .sidebar-footer { padding: 7px 24px 7px 28px; font-size: 10px; }
}

/* ── Mobile-only chrome: hamburger toggle + floating status bubble ──
   Both are placed in the DOM at all viewport sizes (kept simple — no
   conditional rendering) and shown only at ≤ 720px via the media block
   below. They live as siblings of .app-shell so position:fixed anchors
   them to the viewport rather than to the (overflow:hidden) shell. */

/* Hamburger / X button. Glassy surface lifted from the auth card —
   --surface-card translucent fill + matching backdrop-blur + saturate
   so the hamburger reads as the same family of "console" objects as
   the sign-in panel. Pure CSS bars↔X animation driven off
   aria-expanded keeps the markup minimal and the open state announced
   to assistive tech. The button is hidden on desktop and only laid
   out at ≤ 720px. */
.mobile-nav-toggle {
  display: none;
  position: fixed;
  top: 12px; right: 12px;
  z-index: 70;                      /* above the sidebar panel (60) */
  width: 44px; height: 44px;
  padding: 0;
  background: var(--surface-card);
  color: var(--foreground);
  border: 1px solid var(--border);
  /* Match the bento/card/button radius (var(--radius) = 4px) so the
     hamburger reads as part of the same control family rather than a
     stand-out 10-px-rounded outlier. */
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-backdrop-filter: blur(14px) saturate(130%);
          backdrop-filter: blur(14px) saturate(130%);
  box-shadow:
    0 1px 0 rgba(255,255,255,.03) inset,
    0 8px 24px rgba(0,0,0,.40);
  transition: background .2s ease, border-color .2s ease,
              transform .15s ease, box-shadow .2s ease;
}
:root[data-theme="light"] .mobile-nav-toggle {
  background: rgba(255,255,255,.78);
  box-shadow:
    0 1px 0 rgba(255,255,255,.6) inset,
    0 6px 18px rgba(17,17,17,.10);
}
.mobile-nav-toggle:hover { border-color: var(--border-strong); }
.mobile-nav-toggle:active { transform: scale(.96); }
.mobile-nav-bars {
  position: relative;
  display: inline-block;
  width: 20px; height: 14px;
  vertical-align: middle;
}
.mobile-nav-bars > span {
  position: absolute; left: 0;
  width: 100%; height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: transform .28s cubic-bezier(.65,.05,.36,1),
              opacity   .18s ease,
              top       .28s cubic-bezier(.65,.05,.36,1);
}
.mobile-nav-bars > span:nth-child(1) { top: 0; }
.mobile-nav-bars > span:nth-child(2) { top: 6px; }
.mobile-nav-bars > span:nth-child(3) { top: 12px; }
/* Open state — the outer bars converge on the middle and rotate into
   an X; the middle bar fades out behind them. */
.mobile-nav-toggle[aria-expanded="true"] .mobile-nav-bars > span:nth-child(1) {
  top: 6px; transform: rotate(45deg);
}
.mobile-nav-toggle[aria-expanded="true"] .mobile-nav-bars > span:nth-child(2) {
  opacity: 0;
}
.mobile-nav-toggle[aria-expanded="true"] .mobile-nav-bars > span:nth-child(3) {
  top: 6px; transform: rotate(-45deg);
}

/* Floating status pill, bottom-right on mobile. Reuses the .pulse-dot
   styling defined for .sidebar-footer above by dropping the same
   data-state-driven rules onto the .status-bar shared class — see the
   status-bar shared rules at the bottom of this block. */
/* Pre-auth state hides the whole app-shell (see base.css) — match that
   for the mobile-only chrome so the login screen isn't littered with
   a hamburger and a status bubble pointing at nothing. */
body.auth-mode .mobile-nav-toggle,
body.auth-mode .mobile-status-bubble,
body.auth-mode .page-header-actions-toggle { display: none !important; }

.mobile-status-bubble {
  display: none;
  position: fixed;
  bottom: 16px; right: 16px;
  z-index: 80;                      /* sits above the open sidebar panel
                                       (60) so live status updates stay
                                       visible while the menu is open */
  padding: 8px 14px;
  background: var(--surface-card);
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  border-radius: 999px;
  -webkit-backdrop-filter: blur(10px) saturate(120%);
          backdrop-filter: blur(10px) saturate(120%);
  box-shadow:
    0 1px 0 rgba(255,255,255,.03) inset,
    0 8px 24px rgba(0,0,0,.40);
  font-size: 11px;
  align-items: center; gap: 8px;
  transition: color .2s ease;
  pointer-events: none;             /* purely informational */
  user-select: none;
}
:root[data-theme="light"] .mobile-status-bubble {
  background: rgba(255,255,255,.78);
  box-shadow:
    0 1px 0 rgba(255,255,255,.6) inset,
    0 6px 18px rgba(17,17,17,.10);
}

/* Shared status-bar pulse rules. The sidebar-footer block above already
   styles `.sidebar-footer .pulse-dot` and its data-state variants; mirror
   those onto the .status-bar class so the floating mobile bubble picks
   up the same dot/colour/pulse-ring behaviour without duplicating each
   keyframe. */
.status-bar .pulse-dot {
  position: relative;
  width: 8px; height: 8px; border-radius: 50%;
  /* Same anti-squeeze treatment as .sidebar-footer .pulse-dot above. */
  flex: 0 0 8px;
  min-width: 8px; min-height: 8px;
  --pulse-color: var(--profit);
  background: var(--pulse-color);
  box-shadow: 0 0 6px color-mix(in srgb, var(--pulse-color) 60%, transparent);
  transition: background .2s, box-shadow .2s;
}
.status-bar .pulse-dot::before,
.status-bar .pulse-dot::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  background: var(--pulse-color);
  animation: pulse-ring 2.4s cubic-bezier(.32, 0, .2, 1) infinite;
  pointer-events: none;
  z-index: -1;
}
.status-bar .pulse-dot::after { animation-delay: 1.2s; }
@media (prefers-reduced-motion: reduce) {
  .status-bar .pulse-dot::before,
  .status-bar .pulse-dot::after { animation: none; opacity: 0; }
}
.status-bar[data-state="saving"] .pulse-dot { --pulse-color: var(--status-dev); }
.status-bar[data-state="saving"] .pulse-dot::before,
.status-bar[data-state="saving"] .pulse-dot::after { animation-duration: 1.2s; }
.status-bar[data-state="saving"] .pulse-dot::after { animation-delay: .6s; }
.status-bar[data-state="saving"] { color: var(--status-dev); }
.status-bar[data-state="error"]  .pulse-dot { --pulse-color: var(--loss); }
.status-bar[data-state="error"]  .pulse-dot::before,
.status-bar[data-state="error"]  .pulse-dot::after { animation: none; opacity: 0; }
.status-bar[data-state="error"]  { color: var(--loss); }
.status-bar[data-state="saved"]  .pulse-dot { --pulse-color: var(--profit); }

@media (max-width: 720px) {
  /* Document-scroll on mobile. The desktop layout pins .app-shell to
     100vh and lets .main scroll internally — fine on resizable
     desktops, broken on iOS Safari where the address bar's collapse
     animation makes 100vh larger than the visible viewport, leaving
     the bottom of .main's scroll-area trapped behind the browser
     chrome. Switching to natural document scrolling lets the browser
     handle its own chrome and the user can reach every element. */
  html, body { height: auto; min-height: 100vh; overflow: visible; }
  .app-shell { display: block; height: auto; overflow: visible; }
  .main {
    --main-pad-x: 16px;
    margin-left: 0;
    padding: 0 var(--main-pad-x);
    /* Top inset matches the hamburger size + breathing room so the
       page header isn't tucked under the fixed button. */
    padding-top: 64px;
    /* Bottom inset clears the floating status bubble. */
    padding-bottom: 80px;
    height: auto;
    overflow-y: visible;
  }
  /* On mobile the .page-header drops back to in-flow (no sticky
     behavior) and lays its children out vertically: title block on
     its own row, actions hidden behind the top-left fixed toggle.
     Both resting AND .is-stuck states are reset to transparent —
     mobile doesn't get the shy-glass treatment because the document
     scrolls (not .main), so the sentinel-based observer doesn't fire
     here anyway. */
  .page-header,
  .page-header.is-stuck,
  :root[data-theme="light"] .page-header,
  :root[data-theme="light"] .page-header.is-stuck {
    position: static;
    margin: 0;
    padding: 0;
    background: transparent;
    border-bottom: none;
    -webkit-backdrop-filter: none;
            backdrop-filter: none;
    box-shadow: none;
    min-height: 0;
  }
  .page-header-titles {
    flex-basis: 100%;
    margin: 0 0 16px;
    /* On mobile the title block lays out full-width in normal flow
       (no flex squeeze from sibling actions, since actions are in a
       fixed-position popup). The container query above doesn't apply
       on mobile because .page-header has no glass treatment and the
       title is the only thing in the bar. */
    opacity: 1;
    flex-grow: 1;
  }
  .page-header-actions-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .page-header-actions {
    /* Hidden by default — surfaced via [data-actions-open="1"] on the
       parent .page-header (mirrored from the toggle button's aria-
       expanded). Popup glass panel anchored top-left below the
       fixed controls toggle; max-height plus internal scroll keeps it
       usable on short phones with many controls. */
    display: none;
    position: fixed;
    top: 64px;
    left: 12px;
    right: 12px;
    z-index: 65;                    /* below toggle (70), above content */
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    -webkit-backdrop-filter: blur(14px) saturate(130%);
            backdrop-filter: blur(14px) saturate(130%);
    box-shadow:
      0 1px 0 rgba(255,255,255,.03) inset,
      0 8px 24px rgba(0,0,0,.30);
  }
  :root[data-theme="light"] .page-header-actions {
    background: rgba(255,255,255,.85);
    box-shadow:
      0 1px 0 rgba(255,255,255,.6) inset,
      0 6px 18px rgba(17,17,17,.10);
  }
  .page-header[data-actions-open="1"] .page-header-actions { display: flex; }
  /* Each control fills the row width on mobile so taps are easy. */
  .page-header[data-actions-open="1"] .page-header-actions > .field-inline,
  .page-header[data-actions-open="1"] .page-header-actions > .switch,
  .page-header[data-actions-open="1"] .page-header-actions > button.primary,
  .page-header[data-actions-open="1"] .page-header-actions > button.ghost {
    width: 100%;
    justify-content: space-between;
  }


  /* Sidebar becomes a full-screen overlay at ≤ 720px. Open/close is
     driven by [data-mobile-nav] on <html>; we keep the existing
     markup intact so every nav-item, group toggle, and tab handler
     works without modification.

     Animation strategy — instead of a single bland translateY slide,
     the panel itself fades in fast (the surface "appears") and the
     nav contents decompose into a staggered left-to-right cascade:
     each section label, item, and group header eases in from -28px
     with opacity 0→1, indexed by --stagger-i (set in JS via
     ensureStaggerIndices() in app.js — walks DOM order once and pins
     the index on every animated element). The result reads as
     "panel arrives, contents compose themselves" instead of "slab
     slides down". */
  .sidebar {
    display: flex;                   /* override desktop's `display:none`-on-mobile from before */
    position: fixed;
    inset: 0;                        /* full screen */
    width: 100%; height: 100vh; height: 100dvh;
    border-right: none;
    /* Mobile sidebar surface — much more opaque than --surface-card
       on its own. With only 30% fill behind the blur, dark-mode page
       contents (chart canvases, KPI tiles, table cells) bleed through
       enough to fight the menu text contrast. Bumping to ~78% alpha
       and a stronger blur+saturate keeps the glassy feel while making
       every text label legible against any underlying page. */
    background: rgba(13, 13, 13, .78);
    z-index: 60;                     /* below the toggle button (70) */
    /* Pre-open state: invisible, surface not yet rendered, and
       pointer-events:none so the closed panel doesn't intercept
       taps on the page beneath. */
    opacity: 0;
    pointer-events: none;
    -webkit-backdrop-filter: blur(0) saturate(100%);
            backdrop-filter: blur(0) saturate(100%);
    transition: opacity .22s ease,
                backdrop-filter .28s ease,
                -webkit-backdrop-filter .28s ease;
    /* Make the panel itself scrollable when the nav list is taller
       than the viewport (a real risk on small phones with all the
       sections expanded). */
    overflow-y: auto;
  }
  /* Light mode at .72 (was .82) lets the blurred page show through
     enough to read as glass instead of frosted opaque, while staying
     legible against busy dashboards underneath. Stronger blur on
     open (28px) compensates by dissolving high-frequency page content
     more aggressively. */
  :root[data-theme="light"] .sidebar { background: rgba(255, 255, 255, .72); }
  :root[data-mobile-nav="open"] .sidebar {
    opacity: 1;
    pointer-events: auto;
    /* Stronger blur on open so any movement on the page underneath
       (chart animations, scrolling carry-over) is dissolved well
       past the recognizable threshold. */
    -webkit-backdrop-filter: blur(22px) saturate(140%);
            backdrop-filter: blur(22px) saturate(140%);
  }
  :root[data-theme="light"][data-mobile-nav="open"] .sidebar {
    -webkit-backdrop-filter: blur(28px) saturate(140%);
            backdrop-filter: blur(28px) saturate(140%);
  }

  /* The in-panel "System Online" footer is redundant on mobile —
     the floating bubble shows the same status without taking up a
     row inside the (already height-constrained) nav. */
  .sidebar .sidebar-footer { display: none; }

  /* Compact brand block on mobile so the helmet/title doesn't eat a
     fifth of the viewport. */
  .sidebar-brand .brand-text { padding: clamp(12px, 2.4vh, 24px); }

  /* Staggered child reveal — animation-driven (not transition-driven)
     so the open and close cases can have asymmetric motion. The
     CLOSE state is the resting state: opacity 0, no horizontal
     offset. When [data-mobile-nav="open"] applies, a keyframe
     animation runs each item in from -28px → 0 with a per-element
     delay (--stagger-i, set in JS by ensureStaggerIndices() over the
     DOM order so the cascade follows visual reading order across
     mixed nesting depths). When the open state is removed, the
     animation rule disappears and the element collapses back via
     the opacity transition only — no left-swipe on close, which is
     what made the previous close motion feel "swipe off to the
     left, not classy". */
  .sidebar-brand,
  .sidebar-nav .nav-section-label,
  .sidebar-nav > .nav-item,
  .sidebar-nav .nav-group-header,
  .sidebar-nav .nav-group-children .nav-item {
    opacity: 0;
    transform: none;
    transition: opacity .18s ease;   /* close = quick in-place fade */
    will-change: transform, opacity;
  }
  :root[data-mobile-nav="open"] .sidebar-brand,
  :root[data-mobile-nav="open"] .sidebar-nav .nav-section-label,
  :root[data-mobile-nav="open"] .sidebar-nav > .nav-item,
  :root[data-mobile-nav="open"] .sidebar-nav .nav-group-header,
  :root[data-mobile-nav="open"] .sidebar-nav .nav-group-children .nav-item {
    /* Wavefront tuning — earlier this read as N discrete arrivals
       because each element's 420ms ease-out deceleration was long
       enough (and offset large enough at -28px) to be individually
       legible against the 32ms stagger. Shorter per-element motion
       (260ms), smaller offset (-14px), and a tighter 22ms stagger
       compress the active wavefront to ~3–4 elements at any moment,
       so the eye reads one continuous sweep travelling down the list
       rather than a queue of arrivals. Total cascade for ~15 indexed
       elements: 80 + 14*22 + 260 ≈ 650ms — slightly longer wall-clock
       than before but feels faster because the motion is unified.
       `backwards` fill keeps each element invisible through its delay
       window. cubic-bezier(.4, 0, .2, 1) is the standard
       material-style ease that decelerates without overshooting,
       which keeps adjacent items from visibly "settling" out of sync
       with the wavefront. */
    animation: nav-item-rise .26s cubic-bezier(.4, 0, .2, 1) backwards;
    animation-delay: calc(80ms + var(--stagger-i, 0) * 22ms);
    opacity: 1;                      /* steady-state after animation */
  }

  /* Reduced-motion: skip the cascade entirely. Items appear as the
     panel fades — no horizontal motion, no per-element delay. */
  @media (prefers-reduced-motion: reduce) {
    .sidebar-brand,
    .sidebar-nav .nav-section-label,
    .sidebar-nav > .nav-item,
    .sidebar-nav .nav-group-header,
    .sidebar-nav .nav-group-children .nav-item {
      transition: opacity .15s ease;
    }
    :root[data-mobile-nav="open"] .sidebar-brand,
    :root[data-mobile-nav="open"] .sidebar-nav .nav-section-label,
    :root[data-mobile-nav="open"] .sidebar-nav > .nav-item,
    :root[data-mobile-nav="open"] .sidebar-nav .nav-group-header,
    :root[data-mobile-nav="open"] .sidebar-nav .nav-group-children .nav-item {
      animation: none;
      opacity: 1;
    }
  }

  /* Lock background scroll while the menu is open so the user can't
     scroll the page underneath the panel. */
  :root[data-mobile-nav="open"] body { overflow: hidden; }

  /* Show the mobile-only chrome. */
  .mobile-nav-toggle    { display: inline-flex; align-items: center; justify-content: center; }
  .mobile-status-bubble { display: inline-flex; }

  /* Desktop-only sidebar collapse machinery — hide on mobile where the
     hamburger overlay model takes over. */
  .sidebar-toggle,
  .sidebar-resize-handle { display: none; }

  /* Viewport-relative item heights so the menu adapts to short
     phones — 8px floor (~one fingertip-thickness of breathing room
     above a 14px text line), 18px ceiling. clamp() means a 600px-
     tall viewport gets ~10px padding, an 800px gets ~13px, anything
     over 1125px caps at 18px. The Settings tab no longer falls
     below the viewport on a 360×640 device. */
  .sidebar-nav .nav-item {
    padding: clamp(8px, 1.6vh, 18px) 24px;
    font-size: 14px;
  }
  .sidebar-nav .nav-section-label {
    padding: clamp(6px, 1.1vh, 12px) 24px clamp(4px, .8vh, 8px);
  }
  .sidebar-nav .nav-child { padding-left: 56px; }

  /* Mobile rows are taller than the desktop assumption (font-size 14px +
     clamp(...,18px) padding ≈ 50–57px each), so lift the open-group cap
     to clear all four children. Inherits the rest of the collapse
     mechanism (max-height: 0 + transition) from the desktop rule. */
  .sidebar-nav .nav-group.is-open .nav-group-children { max-height: 320px; }
  /* Fund Management 6-child override — 6×55 ≈ 330px exceeds the
     Portfolio-sized cap above. */
  .sidebar-nav .nav-group[data-nav-group="fund-management"].is-open .nav-group-children,
  .sidebar-nav .nav-group[data-nav-group="scanners"].is-open .nav-group-children { max-height: 400px; }

  /* Classy page transition on mobile. Replaces the desktop's flat
     fade-in with a brief rise-from-below + fade so the new tab
     reads as "the page composed itself" rather than "content
     appeared mid-air". Pairs naturally with the menu close: items
     fade out in place, panel fades, new page rises. */
  html[data-active-tab="liveoverview"]    #tab-liveoverview,
  html[data-active-tab="risk"]      #tab-risk,
  html[data-active-tab="overview"]  #tab-overview,
  html[data-active-tab="deals"]     #tab-deals,
  html[data-active-tab="positions"] #tab-positions,
  html[data-active-tab="analysis"]  #tab-analysis,
  html[data-active-tab="funding"]   #tab-funding,
  html[data-active-tab="report"]    #tab-report,
  html[data-active-tab="backtest"]  #tab-backtest,
  html[data-active-tab="tokendd"]   #tab-tokendd,
  html[data-active-tab="fundingscan"] #tab-fundingscan,
  html[data-active-tab="fundingarb"]  #tab-fundingarb,
  html[data-active-tab="livearb"]     #tab-livearb,
  html[data-active-tab="stockbasis"]  #tab-stockbasis,
  html[data-active-tab="earnscan"]    #tab-earnscan,
  html[data-active-tab="funds"]     #tab-funds,
  html[data-active-tab="cex"]       #tab-cex,
  html[data-active-tab="defi"]      #tab-defi,
  html[data-active-tab="users"]     #tab-users,
  html[data-active-tab="investors"] #tab-investors,
  html[data-active-tab="reconciliation"] #tab-reconciliation,
  html[data-active-tab="settings"]  #tab-settings {
    animation: mobile-page-rise .42s cubic-bezier(.22, 1, .36, 1);
  }
  @media (prefers-reduced-motion: reduce) {
    html[data-active-tab="liveoverview"]    #tab-liveoverview,
    html[data-active-tab="risk"]      #tab-risk,
    html[data-active-tab="overview"]  #tab-overview,
    html[data-active-tab="deals"]     #tab-deals,
    html[data-active-tab="positions"] #tab-positions,
    html[data-active-tab="analysis"]  #tab-analysis,
    html[data-active-tab="funding"]   #tab-funding,
    html[data-active-tab="report"]    #tab-report,
    html[data-active-tab="backtest"]  #tab-backtest,
    html[data-active-tab="tokendd"]   #tab-tokendd,
    html[data-active-tab="fundingscan"] #tab-fundingscan,
    html[data-active-tab="fundingarb"]  #tab-fundingarb,
    html[data-active-tab="livearb"]     #tab-livearb,
    html[data-active-tab="stockbasis"]  #tab-stockbasis,
    html[data-active-tab="earnscan"]    #tab-earnscan,
    html[data-active-tab="funds"]     #tab-funds,
    html[data-active-tab="cex"]       #tab-cex,
    html[data-active-tab="defi"]      #tab-defi,
    html[data-active-tab="users"]     #tab-users,
    html[data-active-tab="investors"] #tab-investors,
    html[data-active-tab="reconciliation"] #tab-reconciliation,
    html[data-active-tab="settings"]  #tab-settings {
      animation: fade-in .2s ease-out;
    }
  }
}

/* Cramped viewports — applies to landscape phones (≤720×620) AND
   narrow portrait phones (≤480px wide), where the menu's 10 nav rows +
   3 section labels + brand block + status pill overflow without
   tightening. The "WORKSPACE / RESEARCH / ADMINISTRATION" labels still
   cost a row each: collapse them to a slim double-rule divider — kill
   the text, keep the top + bottom borders so each section boundary
   still reads at a glance. Also tighten the brand block and shave
   nav-item padding so a fully-expanded menu (Portfolio open) fits an
   iPhone-SE-class portrait viewport without scroll. */
@media (max-width: 720px) and (max-height: 620px),
       (max-width: 480px) {
  .sidebar-nav .nav-section-label {
    height: 4px;
    padding: 0;
    font-size: 0;
    line-height: 0;
    overflow: hidden;
    /* Existing background + top/bottom borders (defined on
       .sidebar-nav .nav-section-label up the file) become the
       visible divider. */
  }
  /* Pull the brand block tighter too. */
  .sidebar-brand .brand-text { padding: 10px; }
  .sidebar-brand h1 { font-size: 11px; }
  .sidebar-brand .sub { font-size: 9px; margin-top: 2px; }
  /* Tighter rows so the Portfolio-expanded menu (10 + 4 children)
     stops overflowing on small portrait phones. */
  .sidebar-nav .nav-item { padding: 10px 20px; font-size: 13px; }
  .sidebar-nav .nav-child { padding-left: 44px; font-size: 12px; }
  .sidebar-nav .nav-group.is-open .nav-group-children { max-height: 240px; }
  /* Fund Management 6-child override — 6×37 = 222px fits, but give some
     font-metric slack so the bottom item doesn't get clipped. */
  .sidebar-nav .nav-group[data-nav-group="fund-management"].is-open .nav-group-children,
  .sidebar-nav .nav-group[data-nav-group="scanners"].is-open .nav-group-children { max-height: 290px; }
}

/* Keyframes for the mobile nav reveal. Defined outside the media
   block so the animation is reachable from prefers-reduced-motion's
   override (which switches it off) without re-declaring inside. */
@keyframes nav-item-rise {
  from { opacity: 0; transform: translateX(-14px); }
  to   { opacity: 1; transform: none; }
}
@keyframes mobile-page-rise {
  from { opacity: 0; transform: translateY(18px) scale(.985); }
  to   { opacity: 1; transform: none; }
}
