/* Local stock history, aligned with the app frame above its existing footer. */
#trRecentStocks {
  --tr-recent-background: #0e1c23;
  --tr-recent-tab: #112630;
  --tr-recent-hover: #1b303a;
  --tr-recent-border: #35515e;
  --tr-recent-text: #c7dce7;
  --tr-recent-muted: #8faab8;
  --tr-recent-focus: #8bc7dd;
  position: fixed;
  left: max(0px, calc((100% - 1680px) / 2));
  right: max(0px, calc((100% - 1680px) / 2));
  height: 44px;
  z-index: 2002;
  color: var(--tr-recent-text);
  font: 500 12px/1.3 "IBM Plex Sans", sans-serif;
  pointer-events: none;
}
#trRecentStocks, #trRecentStocks * { box-sizing: border-box; }
#trRecentStocks[hidden], #trRecentStocks [hidden] { display: none !important; }
#trRecentStocks button { font: inherit; cursor: pointer; }
#trRecentStocks button:focus-visible { outline: 2px solid var(--tr-recent-focus); outline-offset: -3px; }

/* Only the surface takes clicks: the collapsed rail leaves the page usable. */
#trRecentStocks .tr-recent-surface {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 48px;
  height: 44px;
  overflow: hidden;
  pointer-events: auto;
  background: var(--tr-recent-background);
  border: 0;
  border-radius: 0;
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 0 100%);
  transition: width 260ms cubic-bezier(.2, .75, .2, 1);
}
#trRecentStocks .tr-recent-surface::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--tr-recent-border);
  border-bottom: 0;
  border-radius: inherit;
  pointer-events: none;
}
#trRecentStocks.is-open .tr-recent-surface { width: var(--tr-recent-full-width, 100%); border-radius: 0; }
#trRecentStocks.is-menu-open .tr-recent-surface { visibility: hidden; pointer-events: none; }
#trRecentStocks .tr-recent-toggle {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 48px;
  height: 44px;
  padding: 0;
  border: 0;
  border-right: 1px solid transparent;
  border-radius: 0;
  background: var(--tr-recent-tab);
  color: var(--tr-recent-text);
  touch-action: pan-y;
}
#trRecentStocks.is-open .tr-recent-toggle { border-right-color: var(--tr-recent-border); background: transparent; }
#trRecentStocks .tr-recent-toggle:hover { background: var(--tr-recent-hover); }
#trRecentStocks .tr-recent-toggle svg { width: 18px; height: 18px; }
#trRecentStocks .tr-recent-toggle::after {
  content: "Recent";
  font-size: 9px;
  font-weight: 500;
  line-height: 10px;
  white-space: nowrap;
  pointer-events: none;
}

/* Keep the inner width stable while clipping, preserving horizontal position. */
#trRecentStocks .tr-recent-body {
  position: absolute;
  left: 48px;
  top: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  width: calc(var(--tr-recent-full-width, 100%) - 48px);
  height: 44px;
  padding: 0 calc(4px + var(--tr-recent-wedge-overlap, 27px)) 0 6px;
}
#trRecentStocks .tr-recent-label { display: none; }
#trRecentStocks .tr-recent-viewport { position: relative; flex: 1; min-width: 0; }
#trRecentStocks .tr-recent-viewport.has-more::after {
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  width: 20px;
  background: linear-gradient(to right, transparent, var(--tr-recent-background));
  pointer-events: none;
}
#trRecentStocks ul {
  display: flex;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scroll-padding: 0 14px;
  scrollbar-width: none;
}
#trRecentStocks ul::-webkit-scrollbar { display: none; }
#trRecentStocks li { flex: 0 0 auto; min-width: 48px; scroll-snap-align: start; }
#trRecentStocks .tr-recent-stock {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 44px;
  padding: 0 2px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--tr-recent-text);
  text-align: left;
}
#trRecentStocks .tr-recent-stock:hover { background: var(--tr-recent-hover); }
#trRecentStocks .tr-recent-ticker {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  min-width: 48px;
  height: 32px;
  padding: 0 8px;
  border-radius: 4px;
  background: var(--tr-ticker-fill, var(--tr-recent-tab));
  color: var(--tr-ticker-ink, var(--tr-recent-text));
  box-shadow: inset 0 0 0 1px #ffffff18;
  font-size: 13px;
  font-weight: 600;
  line-height: 16px;
  white-space: nowrap;
}
#trRecentStocks .tr-recent-copy { display: flex; align-items: center; min-width: 0; }
#trRecentStocks .tr-recent-controls { display: flex; flex: 0 0 auto; align-items: center; }
#trRecentStocks .tr-recent-control {
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  width: 34px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  color: var(--tr-recent-muted);
  background: transparent;
}
#trRecentStocks .tr-recent-control:hover { background: var(--tr-recent-hover); color: var(--tr-recent-text); }
#trRecentStocks .tr-recent-control:disabled { opacity: .25; cursor: default; }
#trRecentStocks .tr-recent-control svg { width: 17px; height: 17px; }
#trRecentStocks .tr-recent-all { display: flex; justify-content: center; gap: 1px; min-width: 44px; width: 44px; flex-basis: 44px; font-size: 11px; font-weight: 500; }
#trRecentStocks .tr-recent-all svg { width: 13px; height: 13px; }
#trRecentStocks .tr-recent-menu {
  --tr-recent-panel-cut: max(12px, calc(var(--tr-recent-wedge-overlap, 27px) - 8px));
  position: absolute;
  right: 8px;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: 360px;
  max-width: calc(100% - 16px);
  max-height: min(420px, var(--tr-recent-panel-max-height, calc(100vh - 180px)));
  overflow: hidden;
  padding: 1px;
  border: 0;
  border-radius: 0;
  background: var(--tr-recent-border);
  clip-path: polygon(12px 0, 100% 0, 100% calc(100% - var(--tr-recent-panel-cut)), calc(100% - var(--tr-recent-panel-cut)) 100%, 0 100%, 0 12px);
  isolation: isolate;
  box-shadow: 0 6px 20px #0005;
  pointer-events: auto;
}
#trRecentStocks .tr-recent-menu:focus { outline: none; }
#trRecentStocks .tr-recent-menu::before {
  content: "";
  position: absolute;
  inset: 1px;
  background: var(--tr-recent-background);
  clip-path: polygon(11px 0, 100% 0, 100% calc(100% - var(--tr-recent-panel-cut) + 1px), calc(100% - var(--tr-recent-panel-cut) + 1px) 100%, 0 100%, 0 11px);
  z-index: -1;
  pointer-events: none;
}
#trRecentStocks .tr-recent-menu-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
  min-height: 44px;
  padding-left: 14px;
  border-bottom: 1px solid var(--tr-recent-border);
}
#trRecentStocks .tr-recent-menu h2 { margin: 0; font-size: 16px; line-height: 20px; font-weight: 500; }
#trRecentStocks .tr-recent-menu button { border: 0; border-radius: 0; background: transparent; color: var(--tr-recent-text); }
#trRecentStocks .tr-recent-menu button:hover { background: var(--tr-recent-hover); }
#trRecentStocks .tr-recent-close { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; }
#trRecentStocks .tr-recent-close svg { width: 18px; height: 18px; }
#trRecentStocks .tr-recent-history {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 4px 6px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scroll-snap-type: none;
  scrollbar-width: thin;
  scrollbar-color: var(--tr-recent-border) transparent;
}
#trRecentStocks .tr-recent-history::-webkit-scrollbar { display: block; width: 5px; }
#trRecentStocks .tr-recent-history::-webkit-scrollbar-thumb { background: var(--tr-recent-border); }
#trRecentStocks .tr-recent-history li { min-width: 0; }
#trRecentStocks .tr-recent-history .tr-recent-stock { height: auto; min-height: 52px; padding: 8px; align-items: center; gap: 10px; }
#trRecentStocks .tr-recent-history .tr-recent-ticker { min-width: 60px; height: 30px; padding-inline: 6px; font-size: 12px; }
#trRecentStocks .tr-recent-history .tr-recent-copy { display: flex; flex: 1; flex-direction: column; align-items: flex-start; gap: 2px; }
#trRecentStocks .tr-recent-history .tr-recent-copy > span { display: block; font-size: 12px; font-weight: 500; line-height: 16px; overflow-wrap: anywhere; }
#trRecentStocks .tr-recent-history .tr-recent-copy small { color: var(--tr-recent-muted); font-size: 11px; font-weight: 400; line-height: 14px; }
#trRecentStocks .tr-recent-row-arrow { display: flex; flex: 0 0 12px; color: var(--tr-recent-muted); }
#trRecentStocks .tr-recent-row-arrow svg { width: 12px; height: 12px; }
#trRecentStocks .tr-recent-menu-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: 0 0 auto; padding: 0 max(14px, calc(var(--tr-recent-panel-cut) + 4px)) 0 14px; border-top: 1px solid var(--tr-recent-border); }
#trRecentStocks .tr-recent-count { color: var(--tr-recent-muted); font-size: 11px; font-weight: 400; }
#trRecentStocks .tr-recent-menu-actions button { min-height: 44px; padding: 0 8px; text-align: center; font-size: 11px; font-weight: 400; }
#trRecentStocks .tr-recent-menu-actions .tr-recent-clear { color: var(--tr-recent-muted); }
#trRecentStocks .tr-recent-menu-actions .tr-recent-clear:disabled { opacity: .5; cursor: default; background: transparent; }
#trRecentStocks .tr-recent-empty { margin: 0; padding: 18px 14px; color: var(--tr-recent-muted); font-size: 12px; font-weight: 400; line-height: 18px; }
.tr-recent-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Rankings opens history from the grouping row. Keep the panel outside the
   clipped header and reserve no space for the former floating rail. */
#trRecentStocks.is-rankings-nav { height: 0; }
#trRecentStocks.is-rankings-nav .tr-recent-surface { display: none; }
#trRecentStocks.is-rankings-nav .tr-recent-menu { --tr-recent-panel-cut: 12px; top: 0; bottom: auto; }

@media (max-width: 768px) {
  #trRecentStocks .tr-recent-body { gap: 3px; }
  #trRecentStocks .tr-recent-control { flex-basis: 44px; width: 44px; }
  #trRecentStocks [data-recent-action="previous"], #trRecentStocks [data-recent-action="next"] { display: none; }
}
@media (max-width: 480px) {
  #trRecentStocks .tr-recent-menu { left: 8px; right: 8px; width: auto; max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  #trRecentStocks .tr-recent-surface { transition: none; }
}
html[data-reading-theme="light"]:not([data-reading-palette="dim"]) #trRecentStocks {
  --tr-recent-background: #edf4f5;
  --tr-recent-tab: #e0edf1;
  --tr-recent-hover: #d6e7ed;
  --tr-recent-border: #b1c7ce;
  --tr-recent-text: #225a75;
  --tr-recent-muted: #496775;
  --tr-recent-focus: #236b8a;
}

/* Recent fits around the full, fixed menu wedge. Use the final rail width
   for the cut so opening/closing never moves the notch across its contents. */
body.tr-recent-expanded #trRecentStocks .tr-recent-surface {
  clip-path: polygon(
    0 0,
    var(--tr-recent-full-width) 0,
    var(--tr-recent-full-width) calc(100% - var(--tr-recent-wedge-overlap, 27px)),
    calc(var(--tr-recent-full-width) - var(--tr-recent-wedge-overlap, 27px)) 100%,
    0 100%
  );
}

/* Hide in the same paint that the iframe-owned Filters control unmounts.
   The Recent module then closes its menu and restores it after Filters returns. */
html body #link-header:not(:has(> .tr-rank-filter-nav-control)) > #rankingsRecent,
html body:not([data-guest="1"]) #link-header:not(:has(> .tr-rank-filter-nav-control:not(.tr-rank-filter-nav-control--guest))) > #rankingsRecent {
  visibility: hidden;
  pointer-events: none;
}
