/* ==========================================================================
   Flash Finance — /sector-rotation (extends the shared ff-* market system)
   Only what the rotation page adds: quadrant cards, the RRG frame, the
   heatmap / quilt grids and the strategy blocks. Cards, stat tiles, badges,
   tables and tab panels all come from market.css + seasonality.css.

   Chart palette (validated with the dataviz six checks, all-pairs, on the
   white card surface — see rotation.js for the same values):
     leading #008300 · improving #2a78d6 · weakening #eda100 · lagging #e34948
   The CVD warn band and the sub-3:1 amber are covered by the mandatory
   secondary encoding: every point carries a text label, every quadrant zone
   is titled, and the leaderboard table repeats each quadrant in words.
   ========================================================================== */

:root {
  --rot-lead: #008300;
  --rot-impr: #2a78d6;
  --rot-weak: #eda100;
  --rot-lag:  #e34948;
  --rot-lead-soft: #e3f3e3;
  --rot-impr-soft: #e7f0fc;
  --rot-weak-soft: #fdf4dd;
  --rot-lag-soft:  #fdeaea;
}

/* ---- market-phase banner ---- */
.rot-phase {
  display: flex; flex-wrap: wrap; gap: 14px 28px; align-items: center;
  border-radius: var(--ff-radius); padding: 14px 18px; margin-bottom: 14px;
  border-left: 4px solid var(--ff-neutral);
  background: linear-gradient(90deg, var(--ff-neutral-soft) 0%, #fbfcfe 60%);
}
.rot-phase.t-pos  { border-left-color: var(--rot-lead); background: linear-gradient(90deg, var(--rot-lead-soft) 0%, #fbfefb 60%); }
.rot-phase.t-neg  { border-left-color: var(--rot-lag);  background: linear-gradient(90deg, var(--rot-lag-soft) 0%, #fffbfb 60%); }
.rot-phase.t-warn,
.rot-phase.t-watch{ border-left-color: var(--rot-weak); background: linear-gradient(90deg, var(--rot-weak-soft) 0%, #fffdf7 60%); }
.rot-phase .ph-main { flex: 1 1 340px; min-width: 0; }
.rot-phase .ph-k { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--ff-text-soft); }
.rot-phase .ph-v { font-size: 1.3rem; font-weight: 700; color: var(--ff-primary); line-height: 1.25; margin: 2px 0 4px; }
.rot-phase .ph-note { font-size: .85rem; line-height: 1.55; color: #374151; margin: 0; }
.rot-phase .ph-side { display: flex; gap: 22px; flex-wrap: wrap; }
.rot-phase .ph-side div { font-size: .78rem; color: var(--ff-text-soft); }
.rot-phase .ph-side b { display: block; font-size: 1.05rem; color: var(--ff-primary); font-weight: 700; }

/* ---- RRG ---- */
.rot-rrg-wrap { position: relative; height: 520px; padding: 4px 2px 0; }
@media (max-width: 700px) { .rot-rrg-wrap { height: 400px; } }
.rot-rrg-bar {
  display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center;
  padding: 10px 16px 0; font-size: .78rem; color: var(--ff-text-soft);
}
.rot-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.rot-legend span { display: inline-flex; align-items: center; gap: 6px; font-size: .76rem; color: var(--ff-text); }
.rot-legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.rot-toggle {
  border: 1px solid var(--ff-border); background: #fff; color: var(--ff-text-soft);
  border-radius: 999px; padding: 4px 12px; font-size: .74rem; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.rot-toggle:hover { border-color: var(--ff-accent); color: var(--ff-accent); }
.rot-toggle[aria-pressed="true"] { background: var(--ff-primary); color: #fff; border-color: var(--ff-primary); }

/* ---- quadrant cards ---- */
.rot-quads { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-bottom: 14px; }
.rot-quad {
  background: var(--ff-card); border: 1px solid var(--ff-border);
  border-radius: var(--ff-radius); box-shadow: var(--ff-shadow); overflow: hidden;
}
.rot-quad > h3 {
  margin: 0; padding: 9px 13px; font-size: .82rem; font-weight: 700;
  display: flex; align-items: center; gap: 7px; border-bottom: 1px solid var(--ff-border-soft);
}
.rot-quad > h3 .n { margin-left: auto; font-weight: 600; font-size: .74rem; color: var(--ff-text-soft); }
.rot-quad.q-leading   > h3 { background: var(--rot-lead-soft); color: #075907; }
.rot-quad.q-improving > h3 { background: var(--rot-impr-soft); color: #17457f; }
.rot-quad.q-weakening > h3 { background: var(--rot-weak-soft); color: #7a5300; }
.rot-quad.q-lagging   > h3 { background: var(--rot-lag-soft);  color: #8f2020; }
.rot-quad .desc { font-size: .74rem; color: var(--ff-text-soft); padding: 9px 13px 4px; line-height: 1.5; margin: 0; }
.rot-quad ul { list-style: none; margin: 0; padding: 4px 13px 12px; }
.rot-quad li { display: flex; align-items: baseline; gap: 8px; padding: 4px 0; font-size: .84rem; border-bottom: 1px solid var(--ff-border-soft); }
.rot-quad li:last-child { border-bottom: none; }
.rot-quad li a { color: var(--ff-primary); font-weight: 600; text-decoration: none; }
.rot-quad li a:hover { text-decoration: underline; }
.rot-quad li .v { margin-left: auto; font-variant-numeric: tabular-nums; font-size: .8rem; }
.rot-quad li .new {
  font-size: .6rem; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
  background: var(--ff-watch-soft); color: var(--ff-watch-deep); border-radius: 4px; padding: 1px 5px;
}
.rot-quad .empty { padding: 10px 13px 14px; font-size: .8rem; color: var(--ff-text-faint); }

/* ---- shared grid look for heatmap / quilt / seasonality ---- */
.rot-gridwrap { overflow-x: auto; }
table.rot-grid { border-collapse: collapse; width: 100%; font-size: .76rem; font-variant-numeric: tabular-nums; }
.rot-grid th, .rot-grid td {
  padding: 5px 8px; text-align: right; white-space: nowrap;
  border-bottom: 1px solid var(--ff-border-soft); color: var(--ff-text);
}
.rot-grid thead th {
  background: #f4f6fa; font-size: .65rem; text-transform: uppercase; letter-spacing: .4px;
  color: #56607a; position: sticky; top: 0; z-index: 3; font-weight: 700;
}
.rot-grid th.sec, .rot-grid td.sec {
  position: sticky; left: 0; background: #fff; text-align: left; z-index: 2;
  border-right: 1px solid var(--ff-border); font-weight: 600; min-width: 140px;
}
.rot-grid thead th.sec { background: #f4f6fa; z-index: 4; }
.rot-grid td.sec a { color: var(--ff-primary); text-decoration: none; }
.rot-grid td.sec a:hover { text-decoration: underline; }
.rot-grid tr.agg td { font-weight: 700; background: #fbfcfe; }
.rot-grid tr.agg td.sec { color: var(--ff-text-soft); font-size: .72rem; text-transform: uppercase; letter-spacing: .4px; background: #fbfcfe; }
.rot-grid .na { color: var(--ff-text-faint); }
/* sits on top of a tint, so it needs real ink rather than a faint gray */
.rot-grid .sub { display: block; font-size: .62rem; color: #4b5563; font-weight: 500; }

/* ---- calendar-year quilt ---- */
.rot-quilt { border-collapse: separate; border-spacing: 3px; font-size: .72rem; }
.rot-quilt th { font-size: .7rem; color: var(--ff-text-soft); font-weight: 700; padding: 2px 4px; text-align: center; }
.rot-quilt td { padding: 0; }
.rot-quilt .cell {
  display: block; min-width: 78px; border-radius: 5px; padding: 5px 7px;
  text-decoration: none; color: var(--ff-text); line-height: 1.25;
}
.rot-quilt .cell b { display: block; font-size: .72rem; font-weight: 700; color: var(--ff-primary); }
.rot-quilt .cell span { font-size: .68rem; font-variant-numeric: tabular-nums; }
.rot-quilt .cell:hover { outline: 2px solid var(--ff-accent); outline-offset: -1px; }
.rot-quilt tr.bench .cell { background: var(--ff-neutral-soft); border: 1px dashed var(--ff-border); }

/* ---- correlation matrix ---- */
.rot-corr th, .rot-corr td { padding: 4px 6px; text-align: center; font-size: .7rem; }
.rot-corr td.self { color: var(--ff-text-faint); }
.rot-corr thead th { writing-mode: horizontal-tb; }

/* ---- strategy ---- */
.rot-strat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.rot-hold {
  border: 1px solid var(--ff-border); border-radius: var(--ff-radius-sm);
  padding: 11px 13px; background: #fff;
}
.rot-hold.in  { border-left: 3px solid var(--rot-lead); }
.rot-hold.out { border-left: 3px solid var(--ff-border); opacity: .72; }
.rot-hold .nm { font-weight: 700; color: var(--ff-primary); font-size: .9rem; text-decoration: none; }
.rot-hold .nm:hover { text-decoration: underline; }
.rot-hold .mt { font-size: .72rem; color: var(--ff-text-soft); margin-top: 3px; }
.rot-eq-wrap { position: relative; height: 320px; }
.rot-cell-head { outline: 2px solid var(--ff-primary); outline-offset: -2px; font-weight: 700; }
.rot-grid td.gridcell { text-align: center; line-height: 1.3; }
.rot-grid td.gridcell .mdd { display: block; font-size: .62rem; color: var(--ff-text-soft); }

/* ---- cycle playbook ---- */
.rot-cycle { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 12px; }
.rot-cycle .ph {
  border: 1px solid var(--ff-border); border-radius: var(--ff-radius);
  background: #fff; padding: 13px 15px; position: relative;
}
.rot-cycle .ph h4 { margin: 0 0 3px; font-size: .9rem; color: var(--ff-primary); display: flex; align-items: center; gap: 7px; }
.rot-cycle .ph .when { font-size: .74rem; color: var(--ff-text-soft); margin-bottom: 9px; }
.rot-cycle .ph .tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.rot-cycle .ph .tags span {
  font-size: .7rem; font-weight: 600; background: var(--ff-accent-soft);
  color: #1e40af; border-radius: 5px; padding: 2px 7px;
}
.rot-cycle .ph p { margin: 0; font-size: .78rem; line-height: 1.55; color: #4b5563; }
.rot-step { counter-reset: rot-step; list-style: none; margin: 0; padding: 0; }
.rot-step li { position: relative; padding: 0 0 12px 34px; font-size: .87rem; line-height: 1.6; color: #374151; }
.rot-step li::before {
  counter-increment: rot-step; content: counter(rot-step);
  position: absolute; left: 0; top: 0; width: 23px; height: 23px; border-radius: 50%;
  background: var(--ff-primary); color: #fff; font-size: .72rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.rot-step li b { color: var(--ff-primary); }

/* ---- misc ---- */
.rot-rs { white-space: nowrap; }
.rot-bar { display: inline-block; width: 48px; height: 5px; border-radius: 3px; background: var(--ff-neutral-soft); overflow: hidden; vertical-align: middle; margin-right: 6px; }
.rot-bar i { display: block; height: 100%; border-radius: 3px; background: var(--ff-accent); }
.rot-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; vertical-align: middle; }
.rot-dot.q-leading { background: var(--rot-lead); }
.rot-dot.q-improving { background: var(--rot-impr); }
.rot-dot.q-weakening { background: var(--rot-weak); }
.rot-dot.q-lagging { background: var(--rot-lag); }
.rot-prose { font-size: .88rem; line-height: 1.7; color: #374151; }
@media (min-width: 1100px) {       /* the card's text fills the card: two columns when it is wide */
  div.rot-prose:has(> p ~ p) { columns: 2; column-gap: 44px; }
  div.rot-prose > p { break-inside: avoid; }
}
.rot-prose p { margin: 0 0 11px; }
.rot-prose p:last-child { margin-bottom: 0; }

@media (max-width: 768px) {
  .rot-phase { gap: 10px 18px; }
  .rot-phase .ph-v { font-size: 1.1rem; }
  .rot-grid th, .rot-grid td { padding: 4px 6px; font-size: .7rem; }
  .rot-grid th.sec, .rot-grid td.sec { min-width: 110px; }
}

/* ==========================================================================
   Single-page layout + sticky section nav
   --------------------------------------------------------------------------
   The six tabs were consolidated into one scrolling page (every section is
   always rendered), so the old tab strip became a jump list that has to stay
   reachable from the middle and the bottom of a very long page — hence the
   sticky bar. Two heights matter and neither is a literal:
     --ff-header-h  base_news' sticky site header (market.js measures it;
                    market.css ships a 56/108px fallback per its 900px
                    breakpoint, because the header search wraps under 900px)
     --rot-navh     this nav's own height (rotation.js measures it; the 52px
                    fallback is the one-row chip height)
   --rot-stick is the bottom edge of the two stacked bars: anything that
   sticks below them, and every scroll target, offsets by it.
   ========================================================================== */
:root {
  --rot-navh: 52px;
  --rot-stick: calc(var(--ff-header-h, 56px) + var(--rot-navh));
}

.rot-secnav {
  position: sticky;
  top: var(--ff-header-h, 56px);
  /* above in-page content (rot-grid sticky heads sit at 3-4) but far below
     base_news' header, which owns 100000 for its autocomplete dropdown */
  z-index: 60;
  /* the page scrolls underneath this bar, so it needs base_news' body colour
     behind it — the .content column is transparent */
  background: #f0f2f5;
  padding: 8px 0 6px;
  margin-bottom: 8px;
}
/* one row, always: wrapping would make the sticky bar three rows tall on a
   phone and eat the screen. Scroll it sideways instead, and let rotation.js
   keep the active chip in view. */
.rot-secnav-track {
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0;
  scroll-behavior: smooth;
}
.rot-secnav-track::-webkit-scrollbar { display: none; }
.rot-secnav-track a { flex: none; scroll-margin: 8px; }
/* scroll hint: fades the right edge only while there is more to scroll to */
.rot-secnav.can-scroll::after {
  content: ''; position: absolute; top: 8px; right: 0; bottom: 6px; width: 34px;
  border-radius: 0 var(--ff-radius) var(--ff-radius) 0;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, #fff 78%);
  pointer-events: none;
}
/* ---- sections: all visible, each announced by a divider label ---- */
.rot-sec { scroll-margin-top: calc(var(--rot-stick) + 12px); }
.rot-sec + .rot-sec { margin-top: 6px; }

/* Rendering six sections instead of one is a layout cost, not a download
   cost: every panel was already in the DOM before, just display:none, so the
   byte count is unchanged and only the layout/paint work grows (measured:
   DOMContentLoaded 0.5s -> 1.9s, first paint 0.2s -> 0.45s on a fast
   desktop; worse on a phone). content-visibility hands that work back by
   letting the browser skip layout for a section until it is near the
   viewport. The first section is excluded because it IS the viewport on
   load, and skipping it would only add work.
   contain-intrinsic-size gives each skipped section a placeholder height so
   the scrollbar is roughly right before anything renders; `auto` makes the
   browser remember each section's real height once it has been rendered
   once, so the estimate stops mattering after the first pass.
   This is a rendering hint only — the content stays in the DOM, in the
   accessibility tree, findable by Ctrl+F and visible to crawlers, unlike the
   display:none it replaces. Browsers without support just render everything,
   which is exactly the behaviour this optimises. */
.rot-sec:not(:first-of-type) {
  content-visibility: auto;
  contain-intrinsic-size: auto 1400px;
}
/* ...but only until the page is idle. A skipped section is a GUESSED height,
   and the jump list needs a real one: with six 1400px placeholders standing
   in for sections that are really 1.3k-13k tall, "go to Playbook" computed a
   target thousands of pixels short and landed mid-Strategy. rotation.js adds
   this class once the browser goes idle after load (and immediately, before
   measuring, if a jump happens first), which trades the skipping back for an
   exact layout at a point where the cost is no longer on the critical path.
   Nothing moves under the reader when it flips: content-visibility renders
   whatever is near the viewport anyway, and `contain-intrinsic-size: auto`
   has already recorded the true height of everything they have scrolled
   past, so only the estimates BELOW them are corrected. */
.ff-page.rot-laid-out .rot-sec { content-visibility: visible; }
.rot-sec-label {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  padding: 12px 2px 10px; margin-top: 10px;
  border-top: 2px solid var(--ff-border);
}
.rot-sec:first-of-type .rot-sec-label { border-top: none; margin-top: 0; padding-top: 2px; }
.rot-sec-label .ix {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--ff-primary); color: #fff;
  font-size: .7rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  align-self: center;
}
.rot-sec-label b { font-size: 1.02rem; color: var(--ff-primary); font-weight: 700; }
.rot-sec-label .sub { font-size: .78rem; color: var(--ff-text-soft); flex: 1 1 240px; min-width: 0; }

/* ---- back to top ----
   Bottom LEFT on purpose: base_news parks its floating share button at
   right/bottom 16-20px with z-index 1000, and the push-permission card takes
   the bottom-right corner too. A second control there is either buried or
   fighting for the same thumb. */
.rot-top {
  position: fixed; left: 16px; bottom: 18px; z-index: 61;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; border-radius: 999px; border: 1px solid var(--ff-border);
  background: #fff; color: var(--ff-primary);
  font: 600 .78rem/1 var(--ff-font); cursor: pointer;
  box-shadow: var(--ff-shadow-hover);
  opacity: 0; visibility: hidden; transform: translateY(8px);
  transition: opacity .18s, transform .18s, visibility .18s;
}
.rot-top.show { opacity: 1; visibility: visible; transform: none; }
.rot-top:hover { border-color: var(--ff-accent); color: var(--ff-accent); }

/* NOTE on `.rot-grid thead th { position: sticky; top: 0 }` above: that rule
   is inert and always has been, so do not "fix" it by offsetting it past the
   sticky bars. `.rot-gridwrap` sets overflow-x:auto, which computes overflow-y
   to auto as well, making the WRAPPER — not the viewport — the scroll
   container for the sticky head. The wrapper never scrolls vertically
   (scrollHeight == clientHeight), so the head never pins to anything. Making
   it work would mean capping the wrapper's height and nesting a scroll area
   inside a page whose whole point is one uninterrupted scroll; the grids top
   out around 1200px, so it is not worth that trade.

@media (max-width: 768px) {
  :root { --rot-navh: 46px; }
  .rot-secnav { padding: 6px 0 5px; }
  .rot-sec-label b { font-size: .95rem; }
  .rot-sec-label .sub { flex-basis: 100%; font-size: .74rem; }
  .rot-top { left: 12px; bottom: 12px; padding: 8px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .rot-secnav-track { scroll-behavior: auto; }
  .rot-top { transition: none; }
}
