/* Final shared layout contract. Size evidence by its available reading width,
   not the viewport behind the strategy rail. Financial/data code is unchanged. */
.sil-quant-shell ~ main:not(.strategy-research) { container: workspace / inline-size; }
.sil-quant-shell ~ main :is(.content-grid, .glass-card, .card-heading, .card-heading > div) { min-width: 0; }
.sil-quant-shell ~ main .card-heading { flex-wrap: wrap; gap: 12px 18px; }
.sil-quant-shell ~ main :is(.card-heading h2, .position-ledger-meta, .dual-decision-list) { overflow-wrap: anywhere; }
.sil-quant-shell ~ main .position-ledger-meta :is(span, strong, small),
.sil-quant-shell ~ main .dual-decision-list :is(span, strong, small) {
  overflow: visible; text-overflow: clip; white-space: normal;
}
.sil-quant-shell ~ main .dual-decision-list > div { grid-template-columns: minmax(82px, .65fr) minmax(0, 1fr); }

/* Higher specificity is deliberate: the legacy dual-clock selector previously
   defeated the phone breakpoint, leaving the second column off screen. */
.sil-quant-shell ~ main #positions-support {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
}
.sil-quant-shell ~ main #positions-support .event-timeline {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  grid-auto-flow: row; grid-auto-columns: auto;
  gap: 12px; height: auto; overflow: visible; padding-bottom: 0;
  scroll-snap-type: none;
}
.sil-quant-shell ~ main #positions-support .timeline-event { min-height: 0; height: auto; }
.sil-quant-shell ~ main .rules-title { flex-wrap: wrap; align-items: baseline; }
.sil-quant-shell ~ main .rules-title h1 { flex: 1 1 240px; min-width: 0; }

@container workspace (max-width: 900px) {
  #performance, .content-grid[data-workspace="operations"] { grid-template-columns: minmax(0, 1fr); }
  #performance > *, .content-grid[data-workspace="operations"] > * { grid-column: 1 / -1; }
  .position-workspace-heading { flex-wrap: wrap; align-items: start; gap: 16px; }
  .position-workspace-copy { flex: 1 1 280px; }
  .position-ledger-meta { flex: 1 1 280px; max-width: none; }
  .period-card { min-height: 0; }
}
@container workspace (max-width: 620px) {
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-item:nth-child(odd) { border-left: 0; }
  .metric-item:nth-child(n+3) { border-top: 1px solid var(--border); }
  .performance-toolbar { flex-wrap: wrap; gap: 12px; }
  .performance-toolbar .performance-intro { flex: 1 1 240px; }
}

/* Only an explicit rail-collapse action animates layout. Boot and resizing
   must not tween a full-width chart through the desktop sidebar. */
html:not([data-strategy-sidebar-motion]) body.has-strategy-sidebar :is(main, .site-footer, .connection-shell, .strategy-sidebar-shell, .strategy-sidebar) { transition: none; }

@media (max-width: 900px) {
  /* Lock the document scroller, not body: a body-only overflow lock creates
     another scroll container and can move sticky chrome off a scrolled page. */
  html:has(body.strategy-sidebar-open) { overflow-y: hidden; }
  body.strategy-sidebar-open { overflow: visible; }
  .sil-quant-shell ~ main .performance-toolbar { grid-template-columns: minmax(0, 1fr); }
  .sil-quant-shell ~ main .performance-actions { justify-self: start; }
  .sil-quant-shell ~ main .range-sync { width: auto; }
  .range-picker-popover .segmented-control.range-rail button { min-height: 44px; }
  .range-picker-popover { overscroll-behavior: contain; }
  .sil-language-menu { max-height: calc(100dvh - var(--sil-header-height) - 24px); overflow-y: auto; overscroll-behavior: contain; }
  .strategy-sidebar-list { overscroll-behavior: contain; }
}

/* Short landscape: keep all three product links on one real header row.
   The chooser uses the viewport, not the narrow remainder below two bars. */
@media (min-width: 560px) and (max-width: 900px) and (max-height: 500px) {
  html[data-ui-mode="precision-ledger"] { --sil-header-height: 48px; --sil-subbar-height: 52px; --sil-bottom-nav: calc(52px + env(safe-area-inset-bottom, 0px)); }
  .sil-global-header {
    grid-template-columns: minmax(80px, 1fr) auto minmax(88px, 1fr);
    grid-template-rows: 48px; gap: 0 12px;
    padding-inline: max(12px, env(safe-area-inset-left, 0px)) max(12px, env(safe-area-inset-right, 0px));
  }
  .sil-global-header .brand-logo { width: 96px; height: 32px; }
  .sil-global-header .sil-product-nav { grid-column: 2; grid-row: 1; gap: 12px; }
  .sil-global-header .sil-product-nav a { flex: 0 0 auto; font-size: 12px; }
  .sil-global-header .sil-global-tools { grid-column: 3; grid-row: 1; gap: 0; }
  .sil-global-header .sil-global-tools button { padding-inline: 6px; }
  #workspace-navigation.mobile-workspace-nav a { flex-direction: row; gap: 6px; min-height: 44px; }
  body.has-strategy-sidebar .strategy-sidebar {
    z-index: 222; top: max(8px, env(safe-area-inset-top, 0px));
    left: max(12px, env(safe-area-inset-left, 0px));
    width: min(560px, calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
    height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    grid-template-rows: auto auto minmax(0, 1fr);
  }
  body.has-strategy-sidebar .strategy-sidebar-backdrop { z-index: 221; inset: 0; height: 100dvh; }
  body.has-strategy-sidebar .strategy-sidebar-header { min-height: 48px; padding-block: 2px; }
  #strategy-sidebar .strategy-research-entry { min-height: 44px; margin-block: 4px; padding-block: 8px; }
  #strategy-sidebar .strategy-sidebar-option { min-height: 56px; padding-block: 8px; }
  #strategy-sidebar .strategy-option-copy small, #strategy-sidebar .strategy-sidebar-footer { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  body.has-strategy-sidebar :is(main, .site-footer, .connection-shell, .strategy-sidebar-shell, .strategy-sidebar) { transition: none; }
}
