/* ============================================================================
   /backtest/ — the research record, in the 2026 visual system.
   ============================================================================

   Page-scoped and linked directly from templates/backtest_history.html, so it
   is outside every bundle and needs no build step.

   The drawing is am-system.css: .am-page-head, .am-metrics/.am-metric,
   .am-filterbar, .am-chart, .am-table, .am-chip, .am-state, .am-btn,
   .c-disclosure. What is here is the four things only this route knows:

     1. the identity row — run id, methodology version, freshness;
     2. the daily-accuracy bar series, which is CSS over the real daily rates
        because this page loads no charting library and adding one for a
        thirty-bar figure would cost more than the figure is worth;
     3. the two tables' narrow-screen strategies, restated at the specificity
        the shared table primitive now needs;
     4. the answers to the site-wide blanket rules.

   On (4): {% block extra_css %} sits *before* bundle-shell.css in base.html,
   so every rule in this file loses a specificity tie to canvas-2026.css,
   am-system.css and page-unification.css. Rules that have to hold name the
   system class too (`.am-table.bt-records`), and the handful answering an
   `!important` blanket are at the foot of the file with the blanket named.

   One legacy shape is deliberately preserved: the page's outermost element
   stays a <div>, because page-unification.css and theme-foundation.css both
   give `.page-backtest_history .main-content > .container > section:first-child`
   a boxed gradient hero with !important. The head is not a hero and must not
   be drawn as one.

   Tokens only, logical properties only, 12px label floor, 44px targets at
   767px and below.
   ============================================================================ */


/* ---------------------------------------------------------------------------
   Page ground
   --------------------------------------------------------------------------- */
.bt-page {
  max-inline-size: var(--layout-workspace-max);
  margin-inline: auto;
  padding-block: var(--c-space-4) var(--c-space-7);
  min-width: 0;
}
.bt-section { margin-block-end: var(--c-space-6); }
.bt-section:last-child { margin-block-end: 0; }


/* ---------------------------------------------------------------------------
   Identity: which measurement this is, and whether it is still being written
   ---------------------------------------------------------------------------
   The run id and the methodology version are what make a figure quoted off
   this page checkable — same strategy, same filters, same data range, same id
   — so they are visible without opening anything. The freshness status is the
   other half: a run id identifies a measurement, it does not say whether the
   record behind it is still being added to. */
/* The row itself is the shared `.am-page-head__meta`; the one thing this
   page's version of it needs is more air between the facts than between a
   key and its value, because every fact here is a labelled pair and two
   pairs three pixels apart read as one four-part fact. */
.bt-ids { column-gap: var(--c-space-4); }
.bt-ids__k { color: var(--c-text-faint); }
.bt-ids__v {
  color: var(--c-text-secondary);
  font-family: var(--c-mono);
  font-variant-numeric: tabular-nums;
}
.bt-ids__link {
  color: var(--c-text-muted);
  text-decoration: none;
  border-block-end: 1px solid var(--c-line-strong);
}
.bt-ids__link:hover { color: var(--c-text); }
.bt-ids__link:focus-visible {
  outline: 2px solid var(--c-evidence);
  outline-offset: 2px;
}


/* ---------------------------------------------------------------------------
   Primary figures
   ---------------------------------------------------------------------------
   Three, not four: the shared metric row is a four-up grid by default and
   three cards in it left a hole where a reader looks for a fourth number.
   The override is scoped under .bt-page rather than written against the
   shared class, because two stylesheets writing rules for one canvas class
   name is what test_canvas_classes_do_not_collide_with_any_other_stylesheet
   exists to catch -- and the page scope is the more specific selector this
   sheet needs anyway, loading as it does before bundle-shell.css. */
.bt-page .bt-kpis {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-block-end: 0;
}


/* ---------------------------------------------------------------------------
   Parameters
   ---------------------------------------------------------------------------
   The filter row is a bar of controls, not a settings form: four selects, an
   apply and a reset, on the inset ground, above the record they narrow. */
/* Page-scoped, and it has to be: `.am-filterbar` sets `align-items: center`
   and a `gap` shorthand, it is one class like `.bt-controls` is, and
   bundle-shell.css loads *after* this sheet -- so a tie goes to the shared
   rule and the apply button floated a third of a row above the selects it
   acts on. A control and the button that submits it share a baseline. */
.bt-page .bt-controls {
  align-items: flex-end;
  column-gap: var(--c-space-3);
  row-gap: var(--c-space-4);
}
/* `margin: 0` is not decoration: dashboard.css carries a `form label`
   blanket with `margin-bottom: .5rem`, and this field is a <label>. With the
   bar bottom-aligned, that stray half-rem is part of the field's margin box,
   so the control sat 8px above the button that submits it at every width. */
.bt-field {
  display: flex;
  flex-direction: column;
  gap: var(--c-space-2);
  margin: 0;
  min-width: 0;
}
.bt-field > span {
  color: var(--c-text-muted);
  font-size: var(--c-t-label);
  font-weight: var(--c-w-medium);
}
.bt-field__control {
  min-block-size: 44px;
  min-inline-size: 9.5rem;
  padding-block: var(--c-space-2);
  padding-inline: var(--c-space-3);
  border: 1px solid var(--c-line);
  border-radius: var(--c-r-control);
  background: var(--c-inset);
  color: var(--c-text);
  font: inherit;
  font-size: var(--c-t-meta);
}
.bt-field__control:focus-visible {
  outline: 2px solid var(--c-evidence);
  outline-offset: 1px;
}
.bt-controls__actions {
  display: flex;
  align-items: center;
  gap: var(--c-space-2);
  min-width: 0;
}


/* ---------------------------------------------------------------------------
   The daily series
   ---------------------------------------------------------------------------
   Thirty bars, one per day the scorer wrote in the window, each as tall as
   that day's directional accuracy, with a dashed rule at the accuracy of the
   whole record in view. Every height is a stored rate: nothing is smoothed,
   interpolated or extended to fill the box.

   CSS rather than a chart library: this page loads none, and pulling one in
   for a thirty-bar figure would cost 200 KB to draw what a flex row draws.
   The figure is aria-hidden and the table under it is its accessible
   equivalent — the same numbers, addressable and sortable by a reader's own
   tools. */
.bt-spark { position: relative; display: block; block-size: 100%; }
.bt-spark__bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  block-size: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}
/* A bar is capped, not divided: with three days in the window `flex: 1 1 0`
   gave each day a third of the panel and the figure read as three slabs
   rather than as a short series. Capped and packed from the reading edge, a
   three-day window looks like three days. */
.bt-spark__bar {
  flex: 1 1 0;
  min-inline-size: 2px;
  max-inline-size: 26px;
  display: flex;
  align-items: flex-end;
  block-size: 100%;
}
.bt-spark__fill {
  display: block;
  inline-size: 100%;
  /* 2px so a day that scored nothing is still a mark rather than a gap: an
     absent bar and a 0% bar are different facts. */
  min-block-size: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--c-chart-blue);
}
.bt-spark__mean {
  position: absolute;
  inset-inline: 0;
  border-block-start: 1px dashed var(--c-line-strong);
  pointer-events: none;
}
.bt-spark__scale {
  display: flex;
  justify-content: space-between;
  gap: var(--c-space-3);
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--c-text-muted);
  font-size: var(--c-t-label);
  font-variant-numeric: tabular-nums;
}
.bt-spark__scale bdi { direction: ltr; unicode-bidi: isolate; }


/* ---------------------------------------------------------------------------
   Tables
   ---------------------------------------------------------------------------
   Three, and each keeps the narrow-screen strategy that suits what it is
   rather than all three getting horizontal scroll:

     daily       four columns compared down a column. Nothing hidden, nothing
                 stacked — thirty rows stacked into thirty blocks is worse
                 than the table.
     providers   the first column is the row's identity and the names are
                 long, so the figures scroll past a pinned engine name.
     records     seven columns, and each row is one record a reader reads on
                 its own rather than a line they compare across. Below 40rem
                 each row becomes a labelled block and nothing scrolls.

   The stack and sticky strategies are canvas-2026.css's (.c-table--stack,
   .c-table--sticky-first) and they are written for `.c-table`'s own padding.
   .am-table's cell rule is one element more specific than theirs, so the two
   properties they need back are restated here at a specificity that holds. */
.bt-table-cap {
  margin: 0 0 var(--c-space-3);
  color: var(--c-text-muted);
  font-size: var(--c-t-label);
  line-height: 1.5;
}
.bt-nowrap { white-space: nowrap; }
.bt-mid { text-align: center; }
.bt-sym { font-family: var(--c-mono); font-weight: var(--c-w-semi); }
/* A hit and a miss carry a glyph as well as a colour, and the glyph is
   mirrored by a screen-reader-only word in the markup: a result is never
   colour alone. */
.bt-hit { color: var(--c-up-ink); font-weight: var(--c-w-semi); }
.bt-miss { color: var(--c-down-ink); font-weight: var(--c-w-semi); }
.bt-none { color: var(--c-text-muted); }
/* One flag per non-AI row in the provider table, the same classification
   /compare/ carries. It is drawn as .am-chip--sm--outline is drawn, but it
   keeps its own class rather than borrowing the component's: the whole class
   attribute is pinned by markets/tests/test_polish_compare_and_backtest.py
   as the proof that the benchmark row is flagged at all, and that assertion
   is worth more than one fewer rule here. Muted, not a coloured pill -- it
   is a fact about the row, not a warning about it. */
.bt-kind {
  display: inline-flex;
  align-items: center;
  min-block-size: 22px;
  margin-inline-start: var(--c-space-2);
  padding: 2px 8px;
  border: 1px solid var(--c-line);
  border-radius: var(--c-r-pill);
  background: var(--c-surface);
  color: var(--c-text-secondary);
  font-size: var(--c-t-label);
  font-weight: var(--c-w-medium);
  white-space: nowrap;
}
.am-table.bt-providers tbody tr:hover th:first-child { background: var(--c-inset); }

@media (max-width: 40rem) {
  /* .c-table--stack's own padding and border reset, restated: `.am-table td`
     is `.c-table--stack td` plus one element, so without this the cells keep
     22px of padding and a hairline inside a block that is already a row. */
  .am-table.bt-records tbody td,
  .am-table.bt-records tbody th {
    padding-block: var(--c-space-1);
    padding-inline: 0;
    border: 0;
  }
  .am-table.bt-records tbody tr {
    border-block-end: 1px solid color-mix(in srgb, var(--c-line) 70%, transparent);
  }
  .am-table.bt-records tbody tr:last-child { border-block-end: 0; }
}


/* ---------------------------------------------------------------------------
   Recently scored calls
   --------------------------------------------------------------------------- */
.bt-pair {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
  gap: var(--c-space-5);
  align-items: start;
}
.bt-subhead {
  margin: 0 0 var(--c-space-3);
  color: var(--c-text);
  font-size: var(--c-t-body);
  font-weight: var(--c-w-semi);
}
.bt-list { margin: 0; padding: 0; list-style: none; }
.bt-list > li {
  padding-block: var(--c-space-3);
  border-block-end: 1px solid color-mix(in srgb, var(--c-line) 70%, transparent);
}
.bt-list > li:last-child { border-block-end: 0; }
.bt-list__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--c-space-2);
  color: var(--c-text);
  font-size: var(--c-t-meta);
  font-weight: var(--c-w-semi);
}
.bt-list__sent { color: var(--c-text-secondary); font-weight: var(--c-w-medium); }
.bt-list__meta {
  display: block;
  margin-block-start: var(--c-space-1);
  color: var(--c-text-muted);
  font-size: var(--c-t-label);
}
.bt-list__link {
  display: inline-block;
  margin-block-start: var(--c-space-2);
  color: var(--c-evidence);
  font-size: var(--c-t-meta);
  line-height: 1.5;
  text-decoration: none;
}
.bt-list__link:hover { text-decoration: underline; }
.bt-list__link:focus-visible {
  outline: 2px solid var(--c-evidence);
  outline-offset: 2px;
}


/* ---------------------------------------------------------------------------
   Pagination
   --------------------------------------------------------------------------- */
.bt-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--c-space-3);
  margin-block-start: var(--c-space-4);
}
.bt-pager__at {
  color: var(--c-text-muted);
  font-size: var(--c-t-meta);
  font-variant-numeric: tabular-nums;
}


/* ---------------------------------------------------------------------------
   Method and assumptions
   ---------------------------------------------------------------------------
   All eleven disclosures, entire, in a disclosure at the foot with an anchor
   the head links to. Nothing is shortened: the fix for "it overwhelms the
   first screen" is where it sits, not how much of it there is. */
.bt-method { margin-block-start: var(--c-space-6); scroll-margin-block-start: 5rem; }
.bt-method__lede {
  margin: 0 0 var(--c-space-4);
  max-inline-size: 78ch;
  color: var(--c-text-muted);
  font-size: var(--c-t-meta);
  line-height: 1.65;
}
.bt-method__list {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(10rem, 15rem) minmax(0, 1fr);
  gap: 0 var(--c-space-6);
}
.bt-method__list dt {
  padding-block: var(--c-space-3);
  border-block-start: 1px solid var(--c-line);
  color: var(--c-text-muted);
  font-size: var(--c-t-meta);
  font-weight: var(--c-w-semi);
}
.bt-method__list dd {
  margin: 0;
  padding-block: var(--c-space-3);
  border-block-start: 1px solid var(--c-line);
  color: var(--c-text-secondary);
  font-size: var(--c-t-meta);
  line-height: 1.65;
}
.bt-method__flag {
  display: inline-block;
  margin-inline-end: var(--c-space-2);
  color: var(--c-attention);
  font-size: var(--c-t-label);
  font-weight: var(--c-w-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
[dir="rtl"] .bt-method__flag { letter-spacing: 0; }
.bt-method__mono {
  color: var(--c-text);
  font-family: var(--c-mono);
  font-variant-numeric: tabular-nums;
}


/* ---------------------------------------------------------------------------
   Narrow widths
   --------------------------------------------------------------------------- */
@media (max-width: 62rem) {
  .bt-page .bt-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 47.9375rem) {
  /* Two columns and the accuracy across the full width under them: it is the
     one figure the page exists to publish, and in a three-up grid at this
     width it was the narrowest of the three. */
  .bt-page .bt-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bt-page .bt-kpis > .bt-kpi--headline { grid-column: 1 / -1; }
}
@media (max-width: 40rem) {
  .bt-field { flex: 1 1 100%; }
  .bt-field__control { inline-size: 100%; min-inline-size: 0; }
  .bt-controls__actions { inline-size: 100%; }
  .bt-method__list { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .bt-method__list dd { border-block-start: 0; padding-block-start: 0; }
}
@media (forced-colors: active) {
  .bt-spark__fill { background: CanvasText; }
  .bt-spark__mean { border-block-start-color: CanvasText; }
}


/* ===========================================================================
   The blankets, answered
   ===========================================================================
   Each block names the rule it is answering. Nothing here invents a value:
   every one restates what am-system.css already says, at the weight needed to
   keep it against a sheet that loads later.

   Why `#main-content`. Two of the three blankets below are `:is(...)` groups
   whose widest argument carries `:not(…, #search-input)` — and `:not()` takes
   the specificity of its most specific argument, so an id inside it makes the
   whole selector id-weighted. No chain of classes can outrank that. The one
   id every page body already sits inside is `#main-content` in base.html, so
   that is the anchor: one id, three classes, and the fight is over. It is
   also why these rules are down here and commented rather than sprinkled
   through the file.
   =========================================================================== */

/* page-unification.css: `.page-backtest_history form[method="get"]` is in the
   "one card/surface language" group, which paints it with the legacy card
   gradient, a 14px radius and a drop shadow. The parameter row is a bar of
   controls on the inset ground, which is what the 2026 FilterBar is. */
#main-content .bt-page form.bt-controls[method="get"] {
  border: 0 !important;
  border-radius: 0 !important;
  background: none !important;
  box-shadow: none !important;
  color: var(--c-text) !important;
}

/* page-unification.css and theme-foundation.css: five separate rules paint
   every `select` on the site with a legacy card or near-white fill, three of
   them id-weighted through that `:not(…, #search-input)`. A filter control in
   the 2026 system sits on the inset ground with a hairline. */
#main-content .bt-page .bt-field .bt-field__control {
  border: 1px solid var(--c-line) !important;
  border-radius: var(--c-r-control) !important;
  background: var(--c-inset) !important;
  color: var(--c-text) !important;
  box-shadow: none !important;
}

/* page-unification.css: `:is(button[type="submit"]:not(.am-form__submit,
   .rf-search__go, .nf-search-submit, .am-search__submit), …)` paints every
   other submit button with the legacy brand gradient — #245b83 through
   #08753f — in white text at weight 800, and theme-foundation.css repeats it
   per theme. .am-btn is in none of those exclusion lists. The 2026 primary
   button inverts against the ground: a dark pill, the same mechanic as the
   active segment. */
#main-content .bt-page .bt-controls .bt-apply.am-btn--primary {
  min-height: 44px !important;
  border: 1px solid var(--c-text) !important;
  border-radius: var(--c-r-pill) !important;
  background-color: var(--c-text) !important;
  background-image: none !important;
  color: var(--c-canvas) !important;
  -webkit-text-fill-color: var(--c-canvas) !important;
  font-weight: var(--c-w-semi) !important;
  box-shadow: none !important;
}
#main-content .bt-page .bt-controls .bt-apply.am-btn--primary:hover {
  background-color: color-mix(in srgb, var(--c-text) 86%, var(--c-canvas)) !important;
}

/* page-unification.css `body[class^="page-"] .main-content p { color: inherit }`
   and canvas-bridge.css's light-theme paragraph net decide the ink of every
   paragraph here. Neither is id-weighted, so the page, the page ground and
   the paragraph's own class are enough, and the value is the one declared
   above rather than a new decision. */
body.page-backtest_history .bt-page p.bt-method__lede,
body.page-backtest_history .bt-page p.bt-table-cap { color: var(--c-text-muted); }

/* canvas-bridge.css: `a[class*="btn"][class*="primary"]` and its button
   sibling predate any real button component and force an accent fill on
   anything whose class merely contains both words. The reset link is a ghost
   button and must stay one. */
#main-content .bt-page a.bt-reset.am-btn {
  background: none !important;
  border-color: transparent !important;
  color: var(--c-text-secondary) !important;
  -webkit-text-fill-color: currentcolor !important;
}
#main-content .bt-page a.bt-reset.am-btn:hover {
  background: var(--c-inset) !important;
  color: var(--c-text) !important;
}

/* The pinned first header cell is opaque (it must be, to cover the figures
   scrolling under it) but it was painted in the surface colour while the rest
   of the header row carries the inset tint, so the shading started mid-row.
   Same tint, still opaque. */
.am-table.bt-providers thead th:first-child { background: var(--c-inset); }
