/* =============================================================================
   ehr_style_14_raceresults.css — finished-race chart          2026-08-05
   THEMED_20261101: colours now come from the ehr_base.css tokens, so the card
   follows main / derby / dark / light. Nothing below hard-codes a surface,
   text or border colour any more, except the few that are meant to be fixed
   in every theme (see "fixed on purpose").
   =============================================================================
   Styles races_complete.j2. Built from the same palette as
   ehr_style_12_raceslist.css so a finished race reads as the same site as the
   entries list it came from.

   Token map (was -> now)
       #f8f9fa card                    --ehr-surface-bg
       #E8E8D0 / #c8c8a0 head + rule   --ehr-surface-subtle / --ehr-border-strong  (NEW, see ehr_base.css)
       #1e293b  #374151  text          --ehr-text-primary
       #6b7280           muted         --ehr-text-secondary
       #94a3b8           labels        --ehr-text-muted
       #e5e7eb           dividers      --ehr-border
       #1d4ed8 / #166534 links         --ehr-link
       light-blue buttons              --ehr-button-secondary-bg / -text
       hover #f0f4f8                   --ehr-hover-bg
       chips                           one hue each (--chip), tint and text derived per theme
       payout green                    --rr-money, derived per theme

   Fixed on purpose (same in every theme):
       post-position colours (racesdrawn_pp_* in ehr_legacy_05_racesdrawn.css),
       the W / P / S ribbons, and the green Results bar on phones.

   The rr_ prefix keeps this clear of the legacy raceresults_* rules in
   ehr_legacy_06_raceresults.css, which still style the old markup and are left
   alone.
   ============================================================================= */


/* ── page frame ─────────────────────────────────────────────────────────── */

.rr_wrap {
  width: 100%;
  max-width: 1300px;
  margin: auto;
  box-sizing: border-box;
}

.rr_empty {
  padding: 18px;
  color: var(--ehr-text-secondary);
  font-size: 13px;
}

/* Expand-all / collapse-all bar — only rendered when >1 race is on the page */
.rr_allbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 2px 0 2px;
}

/* Small utility buttons (expand/collapse all, one pager, toggle) use the
   secondary button tokens like every other secondary button on the site. */
.rr_allbtn,
.rr_tool {
  color: var(--ehr-button-secondary-text);
  background: var(--ehr-button-secondary-bg);
  border: 1px solid var(--ehr-button-secondary-bg);
  border-radius: 3px;
  cursor: pointer;
  user-select: none;
}

.rr_allbtn:hover,
.rr_tool:hover {
  background: color-mix(in srgb, var(--ehr-button-secondary-bg) 85%, var(--ehr-button-secondary-text));
}

.rr_allbtn {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 3px 8px;
}

.rr_allcount {
  font-size: 11px;
  color: var(--ehr-text-muted);
  margin-left: auto;
}


/* ── one race ───────────────────────────────────────────────────────────── */

.rr_race {
  /* payout green: readable on both light and dark cards */
  --rr-money: color-mix(in srgb, #16a34a 70%, var(--ehr-text-primary));

  background: var(--ehr-surface-bg);
  color: var(--ehr-text-primary);
  border: 1px solid var(--ehr-border-strong);
  border-radius: 6px;
  padding: 12px 16px;
  margin-top: 16px;
  margin-bottom: 10px;
}

.rr_head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  border-bottom: 1px solid var(--ehr-border);
  padding-bottom: 6px;
  margin-bottom: 8px;
}

.rr_track {
  font-size: 17px;
  font-weight: 700;
  color: var(--ehr-text-primary);
}

.rr_trackcode {
  font-size: 13px;
  font-weight: 600;
  color: var(--ehr-text-secondary);
}

.rr_when {
  font-size: 11px;
  color: var(--ehr-text-muted);
  margin-top: 2px;
}

.rr_head_side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}


/* ── chips (racetype / distance / surface / age / sex) ──────────────────── */

.rr_chips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* One hue per chip (--chip). The tint, border and text are mixed from it with
   the theme's surface and text colours, so every chip is a pale tint with dark
   text on light themes and a deep tint with light text on dark. */
.rr_chip {
  --chip: #9c9c5c;
  display: inline-block;
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  cursor: default;
  background: color-mix(in srgb, var(--chip) 16%, var(--ehr-surface-bg));
  border: 1px solid color-mix(in srgb, var(--chip) 45%, var(--ehr-surface-bg));
  color: color-mix(in srgb, var(--chip) 55%, var(--ehr-text-primary));
}

/* Race type. Codes come straight out of calc_fn_race_name's CASE:
   M / MC maiden, A allowance, C / O claiming, S starter, ST / G1-G3 black type.
   Graded races get the strongest treatment, claimers the plainest. */
.rr_chip_ty_M,
.rr_chip_ty_MC  { --chip: #3f63ad; }
.rr_chip_ty_A   { --chip: #7c3aed; }
.rr_chip_ty_S   { --chip: #059669; }
.rr_chip_ty_C,
.rr_chip_ty_O   { --chip: #64748b; }
.rr_chip_ty_ST,
.rr_chip_ty_G3  { --chip: #d97706; }
.rr_chip_ty_G1  { --chip: #dc2626; }
.rr_chip_ty_G2  { --chip: #ea580c; }

.rr_chip_dist { --chip: #64748b; }

/* Surface — D dirt, T turf, P synthetic */
.rr_chip_surf_D { --chip: #9a6b34; }
.rr_chip_surf_T { --chip: #059669; }
.rr_chip_surf_P { --chip: #2563eb; }

.rr_chip_age { --chip: #0d9488; }
.rr_chip_sex { --chip: #db2777; }


/* ── header tools ───────────────────────────────────────────────────────── */

.rr_tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rr_tool {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 2px 6px;
  white-space: nowrap;
}

.rr_tool_toggle {
  font-size: 11px;
  padding: 2px 7px;
}


/* ── conditions block ───────────────────────────────────────────────────── */

.rr_title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ehr-text-primary);
  margin-bottom: 6px;
}

.rr_lines {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.rr_line {
  font-size: 12px;
  color: var(--ehr-text-primary);
  padding: 3px 0;
}

.rr_split {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.rr_muted { color: var(--ehr-text-secondary); }

.rr_tag {
  font-weight: 700;
  color: color-mix(in srgb, #c2410c 55%, var(--ehr-text-primary));
  white-space: nowrap;
}

.rr_surf {
  color: var(--ehr-text-primary);
  white-space: nowrap;
}


/* ── collapsible body ───────────────────────────────────────────────────── */

.rr_body_closed { display: none; }


/* ── tables (shared) ────────────────────────────────────────────────────── */

.rr_table {
  width: 100%;
  border-collapse: collapse;
  background: var(--ehr-surface-bg);
  margin-top: 10px;
}

/* RRPPS_20261006: the head / cell rules below are DIRECT-CHILD (was .rr_table thead tr / th / td). A runner's expand
   row now holds the horse-page PP table (rr_togglePPs), and the old descendant rules reached into it: later in the
   cascade at equal specificity, they beat .horsepage_pps_table th / td and its phone compaction (padding, font size,
   the header colour and alignment). Same values for the results tables themselves. */
.rr_table > thead > tr { background-color: var(--ehr-surface-subtle); }

.rr_table > thead > tr > th {
  padding: 8px 6px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  color: var(--ehr-text-primary);
  border-bottom: 2px solid var(--ehr-border-strong);
  white-space: nowrap;
}

.rr_table > tbody > tr > td {
  padding: 6px 6px;
  font-size: 12px;
  vertical-align: middle;
  border-bottom: 1px solid var(--ehr-border);
}

.rr_num { text-align: right; }

/* Same specificity trap as the sire screen's .sd_num (found there on review
   2026-08-05): bare .rr_num at (0,1,0) loses to `.rr_table th`'s
   text-align:left at (0,1,1), leaving Win/Place/Show/Odds headers flush left
   over flush-right money. Restated at (0,2,1) so numeric headers align with
   their columns. RRPPS_20261006: both are direct-child now, (0,1,3) and the
   restatement (0,2,3). */
.rr_table > thead > tr > th.rr_num { text-align: right; }   /* RRPPS_20261006: direct-child, as above */

.rr_c_pp { width: 30px; }

.rr_pp {
  text-align: center;
  border-color: var(--ehr-text-muted);
  border-width: 1px;
}

.rr_hname {
  font-weight: 700;
  color: var(--ehr-text-primary);
}

.rr_stable,
.rr_owner { color: var(--ehr-link); }

/* the viewer's own stable, wherever it shows up in the chart */
.rr_mine {
  --chip: #059669;
  font-weight: 700;
  color: color-mix(in srgb, var(--chip) 55%, var(--ehr-text-primary));
  background: color-mix(in srgb, var(--chip) 16%, var(--ehr-surface-bg));
  border-radius: 3px;
  padding: 0 3px;
}

.rr_money {
  color: var(--rr-money);
  font-weight: 700;
}


/* ── win / place / show ─────────────────────────────────────────────────── */

.rr_top tbody tr:nth-child(odd) { background-color: color-mix(in srgb, var(--ehr-text-primary) 3%, transparent); }


/* ── also ran ───────────────────────────────────────────────────────────── */

.rr_alsoran {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: var(--ehr-text-primary);
  padding: 10px 2px 2px 2px;
}

.rr_alsoran_lbl {
  font-weight: 700;
  color: var(--ehr-text-secondary);
  white-space: nowrap;
}


/* ── exotics + final time ───────────────────────────────────────────────── */

.rr_payline {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
  padding: 10px 2px 2px 2px;
}

.rr_exotics {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 190px;
}

.rr_exotic {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 12px;
  color: var(--ehr-text-primary);
}

.rr_exotic span { font-weight: 700; }
.rr_exotic b    { color: var(--rr-money); }

.rr_timeline {
  font-size: 12px;
  color: var(--ehr-text-primary);
  flex: 1 1 auto;
}

.rr_frac {
  color: var(--ehr-text-secondary);
  margin-left: 6px;
}

.rr_timeline sup,
.rr_frac sup { font-size: 9px; }


/* ── the chart ──────────────────────────────────────────────────────────── */

/* ── the three that got paid ──────────────────────────────────────────────
   The tint goes on the ROW and never on its cells.

   A td's own background paints over the row's, so `.rr_inmoney td` covered two
   things it had no business covering: the saddlecloth colour on the
   post-position cell, and the :hover highlight. Specificity made it worse --
   `.rr_chart .rr_inmoney td` is (0,2,1) and beats
   `.racesdrawn_post_position.racesdrawn_pp_5` at (0,2,0), so the top three
   horses lost their number colours entirely and did not light up on mouseover.

   At tr level the pp colours paint over the tint the way they should.
   ------------------------------------------------------------------------- */
.rr_chart tbody tr.rr_inmoney { background-color: color-mix(in srgb, #16a34a 6%, var(--ehr-surface-bg)); }

/* Hover has to out-specify the tint above, which means going to cell level --
   so it is scoped away from .rr_pp, or it would eat the saddlecloth colour on
   the way past. Same rule for both tables.
   RRPPS_20261006: direct-child. As a descendant rule it painted EVERY cell of the PP table inside an open expand row
   whenever the mouse was anywhere in that row. */
.rr_chart > tbody > tr:hover > td:not(.rr_pp),
.rr_top   > tbody > tr:hover > td:not(.rr_pp) { background-color: var(--ehr-hover-bg); }

.rr_sp { font-weight: 700; }
.rr_sp sup { font-size: 9px; }

.rr_c_call sup { font-size: 9px; color: var(--ehr-text-secondary); }

.rr_c_lb { white-space: nowrap; }

.rr_dash { color: color-mix(in srgb, var(--ehr-text-muted) 50%, transparent); }

.rr_chart .rl_td_expand {
  width: 30px;
  text-align: center;
  padding-left: 10px;
  padding-right: 6px;
}

/* RRPPS_20261006: the chart no longer carries rl_table (races_complete.j2). Of the rules that class brought, the only
   value .rr_table did not already repeat was overflow:hidden on the head cells -- kept here, chart only. */
.rr_chart > thead > tr > th { overflow: hidden; }


/* ── past performances in a runner's expand row ── RRPPS_20261006 ──────────
   rr_togglePPs loads horsepage/horse_pps_get.py (the horse page PP table) into
   div.rr_pps once. THEMED_20261101: the card follows the theme now, so the bar,
   the notes and the loading text use the theme colours too. */
.rr_pps_bar {
  padding: 8px 2px 6px 2px;
  font-size: 12px;
}

.rr_pps_horselink {
  color: var(--ehr-link);
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--ehr-text-muted);
  text-underline-offset: 2px;
}

.rr_pps_horselink:hover {
  text-decoration: none;
  background-color: var(--ehr-hover-bg);
}

.rr_pps { color: var(--ehr-text-primary); }

.rr_pps_msg {
  padding: 6px 2px;
  font-size: 12px;
  color: var(--ehr-text-secondary);
}

.rr_pps .horsepage_pps_section {
  margin-bottom: 0;
  border: 1px solid var(--ehr-border-strong);
  border-radius: 4px;
}

/* Phones: the PP table only adds columns as its own box widens and clips what
   does not fit (Fin / Odd / icons / the expand button sit on the right). Here it
   sits inside the race card and the expand row, so it is narrower than on the
   horse page -- take the side padding off the expand row and the table box. */
@media (max-width: 600px) {
  .rr_chart .stable_horse_list_expanded_info { padding-left: 0; padding-right: 0; }
  .rr_pps .horsepage_pps_table_container     { padding-left: 0; padding-right: 0; }
  /* RRPPS_20261006 (review): on the narrowest phones (about 375px) the expand button column still ends past the
     box; let the PP box scroll sideways here instead of clipping it (the horse page itself keeps clipping). */
  .rr_pps .horsepage_pps_section             { overflow-x: auto; }
}


/* ── responsive ─────────────────────────────────────────────────────────────
   Columns drop in the order the old chart dropped them: the calls and the
   breeding detail go first because the expand row carries every one of them,
   so nothing is actually lost on a phone -- it moves one tap away.
   ------------------------------------------------------------------------- */

@media (max-width: 1400px) { .rr_c_jockey { display: none; } }
@media (max-width: 1300px) { .rr_c_bred   { display: none; } }
@media (max-width: 1200px) { .rr_c_badges { display: none; } }
@media (max-width: 1100px) { .rr_c_call2  { display: none; } }
@media (max-width: 1000px) { .rr_c_call3  { display: none; } }
@media (max-width:  900px) { .rr_c_call1, .rr_c_stable { display: none; } }
@media (max-width:  800px) { .rr_c_owner  { display: none; } }
@media (max-width:  700px) { .rr_c_as, .rr_c_show { display: none; } }
@media (max-width:  600px) { .rr_c_odds, .rr_c_place { display: none; } }

/* RRODDS_20261021 (owner 10-21): no half payout board. Where the screen cannot fit Win, Place AND Show, all three
   hide and the board shows one Odds column instead (each horse odds, the chart Odds value).
   RRESBAR_20261021 (owner 10-21): at the same width the board also gets a Results bar over the headers and a Fin
   column (W / P / S) beside the Odds, so a finished race still looks finished without the prices. */
.rr_top .rr_c_topodds,
.rr_top .rr_c_topfin,
.rr_top > thead > tr.rr_c_resbar { display: none; }
@media (max-width:  700px) {
  .rr_top .rr_c_win, .rr_top .rr_c_place, .rr_top .rr_c_show { display: none; }
  .rr_top .rr_c_topodds, .rr_top .rr_c_topfin { display: table-cell; }
  .rr_top > thead > tr.rr_c_resbar { display: table-row; }
}

/* fixed on purpose: a status band, the same in every theme */
.rr_top > thead > tr.rr_c_resbar { background-color: #15803d; }
.rr_top > thead > tr.rr_c_resbar > th {
  color: #ffffff;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: center;
  padding: 5px 6px;
  border-bottom: 0;
}

.rr_top .rr_c_topfin { text-align: center; width: 34px; }
.rr_wps {
  display: inline-block;
  min-width: 18px;
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 700;
  color: #ffffff;
  text-align: center;
}
/* fixed on purpose: ribbon colours, the same in every theme.
   RIBBON_20261021 (owner 10-21): ribbon colours, 1st blue, 2nd red, 3rd a light grey (dark letter on it).
   DARKRIBBON_20261021 (owner 10-21): VERY dark blue and red, so W and P never look like the post 3 (#0000FF) and
   post 1 (#FF0000) saddle cloths in the # column (ehr_legacy_05_racesdrawn.css). */
.rr_wps_w { background-color: #172554; }
.rr_wps_p { background-color: #7f1d1d; }
.rr_wps_s { background-color: #d1d5db; color: #374151; }

@media (max-width: 768px) {
  .rr_race { padding: 10px 12px; }

  .rr_head {
    flex-direction: column;
    align-items: stretch;
  }

  .rr_head_side {
    align-items: flex-start;
    flex-direction: row;
    justify-content: space-between;
    width: 100%;
  }

  .rr_chips { justify-content: flex-start; }

  .rr_split {
    flex-direction: column;
    gap: 2px;
  }

  .rr_payline { flex-direction: column; gap: 10px; }
}