/* Market workspace: pinned desktop app shell (28 Nov 2026).
   Loaded last, by digest/next/workspace.html only. Every rule sits behind min-width:1024px (or a container query on
   #workspace-main, which is only a container from 1024px), so phones (<=760px) and tablets (761-1023px) render as before.

   The frame: rail | (header over a scrolling main pane) | conversation panel. The document never scrolls on desktop;
   #workspace-main is the only scroll container and reserves its scrollbar gutter, so switching views can never move the
   header, the rail, the panel or the pane edges, and never changes the page width. Each view's head (eyebrow, title,
   one-line note, actions) is one fixed-height block at the same place, and the content after it starts at the same y. */

@media(min-width:1024px){
  html:has(>body[data-app]),body[data-app]{height:100%;overflow:hidden}
  body[data-app]{
    --shell-pad-x:40px;
    --shell-pad-top:56px;
    --shell-h1:clamp(34px,calc(1.35vw + 18px),50px);
    --shell-head-h:max(108px,calc(20px + 12px + 1.12*var(--shell-h1) + 10px + 22px)); /* >= breadcrumb + instrument head */
    --shell-head-gap:28px;
  }
  body[data-app] .next-app{height:100dvh;min-height:0;overflow:hidden}
  body[data-app] .workspace{display:flex;flex-direction:column;height:100dvh;min-height:0;min-width:0;overflow:hidden}
  body[data-app] .topbar{flex:none;position:relative;top:auto;padding-left:var(--shell-pad-x);padding-right:calc(var(--shell-pad-x) + var(--shell-scrollbar,0px))}
  body[data-app] #workspace-main{
    flex:1 1 auto;min-height:0;width:100%;max-width:none;margin:0;box-sizing:border-box;position:relative;
    padding:var(--shell-pad-top) var(--shell-pad-x) 28px;
    overflow-x:hidden;overflow-y:auto;scrollbar-gutter:stable;overscroll-behavior:contain;
    --workspace-header-height:0px;
    scroll-padding-top:16px;
  }
  body[data-app] #workspace-main:focus{outline:none}
  body[data-app] #workspace-main #news-view{--wn-pad:var(--shell-pad-x)}
  /* Sticky offsets inside the pane are measured from its padding edge: pull the news filter bar up to the pane's top. */
  body[data-app] #workspace-main #news-view .wn-filters{top:calc(-1*var(--shell-pad-top))}
  body[data-app] #workspace-main #news-view .wn-pill-wrap{top:calc(112px - var(--shell-pad-top))}

  /* The conversation panel opens and closes by animating the grid track; the pane reflows with it. */
  @media(prefers-reduced-motion:no-preference){
    body[data-app] .next-app{transition:grid-template-columns 220ms cubic-bezier(.2,.8,.2,1)}
  }

  /* "Back to …" lives in the pane's top padding, so showing it never pushes the view down. */
  body[data-app] #workspace-main>.tf-nav-back{position:absolute;top:14px;left:var(--shell-pad-x);right:var(--shell-pad-x);z-index:2;pointer-events:none}
  body[data-app] #workspace-main>.tf-nav-back button{pointer-events:auto;margin:0}

  /* ---------- One head block for every view ---------- */
  body[data-app] #workspace-main :is(#market-view>.page-intro,#watchlist-view>.page-intro,.research-view>.research-intro,#news-view>.wn-head){
    display:flex;flex-wrap:nowrap;align-items:flex-end;justify-content:space-between;gap:24px;
    box-sizing:border-box;min-height:var(--shell-head-h);margin:0 0 var(--shell-head-gap);padding:0;
  }
  body[data-app] #workspace-main :is(#market-view>.page-intro,#watchlist-view>.page-intro,.research-view>.research-intro,#news-view>.wn-head)>div:first-child{
    align-self:flex-start;min-width:0;max-width:none;flex:1 1 auto;
  }
  body[data-app] #workspace-main :is(#market-view>.page-intro,#watchlist-view>.page-intro,.research-view>.research-intro,#news-view>.wn-head)>div:first-child>:is(.eyebrow,.tf-eyebrow){
    min-height:20px;margin:0;line-height:20px;
  }
  body[data-app] #workspace-main :is(#market-view>.page-intro,#watchlist-view>.page-intro,.research-view>.research-intro,#news-view>.wn-head) h1{
    margin:12px 0 0!important;font-size:var(--shell-h1)!important;line-height:1.12!important;letter-spacing:-.035em;
    white-space:nowrap;overflow:hidden;text-overflow:ellipsis;text-wrap:nowrap;
  }
  /* Two-line titles ("The market. / In perspective.") read on one line on desktop. */
  body[data-app] #workspace-main :is(#market-view>.page-intro,#news-view>.wn-head) h1 br{display:none}
  body[data-app] #workspace-main :is(#market-view>.page-intro,#news-view>.wn-head) h1>span{margin-left:.24em}
  body[data-app] #workspace-main :is(#market-view>.page-intro,#watchlist-view>.page-intro,.research-view>.research-intro)>div:first-child>p:not(.eyebrow){
    margin:10px 0 0;max-width:72ch;min-height:22px;font-size:13px;line-height:22px;
    white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
  }
  /* Actions (market picker, refresh, live status, add instrument) sit bottom-right of the head. */
  body[data-app] #workspace-main :is(#market-view>.page-intro,#watchlist-view>.page-intro,.research-view>.research-intro,#news-view>.wn-head)>:not(:first-child){
    flex:none;align-self:flex-end;margin:0;padding-bottom:0;max-width:none;flex-wrap:nowrap;
  }
  body[data-app] #workspace-main .research-view>.research-intro>.week-edition-label{align-self:flex-end;margin-bottom:4px}

  /* Stock terminal: breadcrumb takes the eyebrow row; the instrument head fills the rest of the same block. */
  body[data-app] #workspace-main #terminal-view>.terminal-breadcrumb{min-height:20px;height:20px;margin:0 0 12px;line-height:20px}
  body[data-app] #workspace-main #terminal-view>.terminal-breadcrumb>button{min-height:20px;min-width:0;padding:0 4px;margin-left:-4px}
  body[data-app] #workspace-main #terminal-view>.instrument-head{box-sizing:border-box;min-height:calc(var(--shell-head-h) - 32px);margin:0 0 var(--shell-head-gap)!important;align-items:flex-end}
  body[data-app] #workspace-main #terminal-view>.instrument-head>.instrument-monogram{align-self:center}
  body[data-app] #workspace-main #terminal-view>.instrument-head>.instrument-identity{align-self:center}

  /* The tab strip directly under a head lands at the same y on every view that has one. */
  body[data-app] #workspace-main #events-view>.research-intro+.desk-tabs{margin-top:0}
  body[data-app] #workspace-main #terminal-view>.terminal-bar{padding-top:0;margin-top:0}
}

/* Stock terminal: the section tabs follow the instrument head at every desktop width (as on Events), and the key stats
   follow the tabs. At >=1080px content they already sit in a right rail beside the chart (workspace-wide.css). */
@container tfmain (max-width:899.98px){
  body[data-app] #next-app .terminal-view:not([hidden]){display:flex;flex-direction:column}
  body[data-app] #next-app .terminal-view>*{order:6;min-width:0}
  body[data-app] #next-app .terminal-view>.market-ribbon-slot{order:0}
  body[data-app] #next-app .terminal-view>.terminal-breadcrumb{order:1}
  body[data-app] #next-app .terminal-view>.instrument-head{order:2}
  body[data-app] #next-app .terminal-view>.instrument-pulse{order:2}
  body[data-app] #next-app .terminal-view>.terminal-bar{order:3}
  body[data-app] #next-app .terminal-view>.instrument-metrics{order:4}
  body[data-app] #next-app .terminal-view>.instrument-shorts{order:5}
  body[data-app] #next-app .terminal-view>.terminal-footnote{order:7}
}
@container tfmain (min-width:900px) and (max-width:1079.98px){
  body[data-app] #next-app .terminal-view>.terminal-bar{grid-row:5}
  body[data-app] #next-app .terminal-view>.instrument-metrics,
  body[data-app] #next-app .terminal-view>.instrument-shorts{grid-row:6}
  body[data-app] #next-app .terminal-view>.chart-workspace,
  body[data-app] #next-app .terminal-view>.stock-overview,
  body[data-app] #next-app .terminal-view>.public-listing-intro{grid-row:7}
  body[data-app] #next-app .terminal-view>.terminal-footnote{grid-row:8}
}
@media(min-width:1024px){
  /* A desk still loading (Crypto takes a few seconds): hold the head block's place so the content doesn't jump up and back. */
  body[data-app] #workspace-main .research-view>.research-loading:first-child{margin-top:calc(var(--shell-head-h) + var(--shell-head-gap))}

  /* Rail: the six views that switch inside this frame come first; the four links that open their own pages
     (Roundups, Stock Chat, Short Tracker, Learn) follow a hairline and carry a small "opens a page" mark. CSS order only,
     so the DOM order (and the 681-760px rail) is unchanged. */
  body[data-app] .rail-nav>button.rail-button{order:1}
  body[data-app] .rail-nav>a.rail-button{order:2;position:relative}
  body[data-app] .rail-nav>a.rail-button[href="/surveillance/"]{margin-top:9px}
  body[data-app] .rail-nav>a.rail-button[href="/surveillance/"]::before{content:"";position:absolute;left:10px;right:10px;top:-11px;height:1px;background:var(--tf-line,#2d3035)}
  body[data-app] .rail-nav>a.rail-button::after{content:"";position:absolute;top:8px;right:8px;width:5px;height:5px;border-top:1.4px solid currentColor;border-right:1.4px solid currentColor;opacity:.55}
}
@media(min-width:1600px){
  body[data-app]{--shell-pad-x:56px}
}
/* Short laptop windows (1280x800 leaves ~700px): the rail fits without clipping the account button. */
@media(min-width:1024px) and (max-height:820px){
  body[data-app] .rail{padding-top:16px;padding-bottom:14px;gap:14px}
  body[data-app] .rail-nav{margin-top:18px;gap:6px}
}

/* ---------- Fill the width: add columns as the pane grows (container = #workspace-main content box) ---------- */
@container tfmain (min-width:1500px){
  /* Home: announcement digest in three columns. */
  body[data-app] #market-intelligence :is(#news-feed,#digest-results){grid-template-columns:repeat(3,minmax(0,1fr))}
  /* World news: three-column river. */
  body[data-app] #news-view .wn-river{grid-template-columns:repeat(3,minmax(0,1fr))}
  /* Market Week: four editions a row. */
  body[data-app] #week-view .week-archive{grid-template-columns:repeat(4,minmax(0,1fr))}
  /* Economic events: three cards a row next to the context rail. */
  body[data-app] #events-view .events-desk-list{grid-template-columns:repeat(3,minmax(0,1fr))}
  /* Market Brain: three calls a row. */
  body[data-app] #brain-view .brain-call-grid{grid-template-columns:repeat(3,minmax(0,1fr))}
}
@container tfmain (min-width:1960px){
  body[data-app] #news-view .wn-river{grid-template-columns:repeat(4,minmax(0,1fr))}
  body[data-app] #week-view .week-archive{grid-template-columns:repeat(5,minmax(0,1fr))}
  /* The lead edition takes three of the five columns; the next two editions sit beside it. */
  body[data-app] #week-view .week-archive>.week-card-lead{grid-column:span 3}
  body[data-app] #events-view .events-desk-list{grid-template-columns:repeat(4,minmax(0,1fr))}
  body[data-app] #brain-view .brain-call-grid{grid-template-columns:repeat(4,minmax(0,1fr))}
}

/* Owner, 28 Nov: "make sure the tabs at the top are pinned". The market desk tabs, the calendar period tabs and the stock
   terminal's section bar stick to the top edge of the pane while you scroll (as the news filters already do); market panels
   keep a floor height so switching tabs never collapses the page under you. */
@media(min-width:1024px){
 body[data-app] #workspace-main :is(#market-view .desk-tabs,#events-view .desk-tabs,#terminal-view>.terminal-bar){position:sticky;
   top:calc(-1*var(--shell-pad-top));z-index:30;background:color-mix(in srgb,var(--tf-bg,#090a0c) 92%,transparent);-webkit-backdrop-filter:blur(14px);backdrop-filter:blur(14px)}
 body[data-app] #workspace-main :is(#market-view .desk-tabs,#events-view .desk-tabs){margin-top:0;padding-top:10px}
 body[data-app] #workspace-main #market-view [data-desk-panel]{min-height:calc(100vh - 220px)}
}
