/* ========================================================================
   RACE_PROFILER_003C — VIEWPORT / CONTROL CLOSEOUT
   Scope: Race Profiler only. Behaviour and analytical meanings are unchanged.
   ======================================================================== */

/* All responsive child controls must be allowed to shrink inside their grid. */
body[data-workspace-mode="race_profiler"] #page-builder :is(
  .card,
  .range-card,
  .stat-mini,
  .chips,
  .chip,
  .pill-range-input,
  .equal-buttons-2,
  .equal-buttons-3
){
  min-width:0!important;
}

/* ------------------------------------------------------------------------
   DEFINE RACE SETUP — HANDICAP / CLASS RESPONSIVE CONTRACT
   ------------------------------------------------------------------------ */
body[data-workspace-mode="race_profiler"] #race .meta-handicap .chips{
  display:grid!important;
  grid-template-columns:repeat(2,minmax(0,1fr))!important;
  width:min(100%,520px)!important;
  margin-inline:auto!important;
  gap:8px!important;
}
body[data-workspace-mode="race_profiler"] #race .meta-handicap .chip{
  width:100%!important;
  min-width:0!important;
  padding-inline:10px!important;
  white-space:normal!important;
}

/* ------------------------------------------------------------------------
   RUNNER IDENTITY — GENDER WRAPPING
   ------------------------------------------------------------------------ */
body[data-workspace-mode="race_profiler"] #horse .horse-gender-card .chips{
  min-width:0!important;
}
body[data-workspace-mode="race_profiler"] #horse .horse-gender-card .chip{
  width:100%!important;
  min-width:0!important;
  padding-inline:8px!important;
}

/* ------------------------------------------------------------------------
   EXPERIENCE / RECENCY — COMPACT PRIZE VALUES AND SAFE GRID SHRINKING
   ------------------------------------------------------------------------ */
body[data-workspace-mode="race_profiler"] #horse-profile-stats .horse-profile-composed-grid.hp-grid-new > *,
body[data-workspace-mode="race_profiler"] #horse-profile-stats .stat-mini-grid > *{
  min-width:0!important;
}
body[data-workspace-mode="race_profiler"] #horse-profile-stats .horse-prize-strip .stat-mini-title{
  white-space:normal!important;
  overflow-wrap:anywhere!important;
}
body[data-workspace-mode="race_profiler"] #horse-profile-stats .pill-range-input.wide-pill{
  position:relative!important;
  width:100%!important;
  max-width:164px!important;
}
body[data-workspace-mode="race_profiler"] #horse-profile-stats input.race-profiler-compact-money-source{
  color:transparent!important;
  caret-color:transparent!important;
}
body[data-workspace-mode="race_profiler"] #horse-profile-stats .race-profiler-compact-money-label{
  display:none!important;
}
body[data-workspace-mode="race_profiler"] #horse-profile-stats .race-profiler-compact-money-label:not([hidden]){
  position:absolute!important;
  right:0!important;
  bottom:0!important;
  z-index:3!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  width:calc(50% - 5px)!important;
  height:22px!important;
  padding:0 4px!important;
  border-radius:0 999px 999px 0!important;
  background:transparent!important;
  color:#0f172a!important;
  font-size:11px!important;
  font-weight:950!important;
  letter-spacing:.01em!important;
  pointer-events:none!important;
}
body[data-workspace-mode="race_profiler"] #horse-profile-stats .race-profiler-compact-money-label[hidden]{
  display:none!important;
}

/* ------------------------------------------------------------------------
   LAST-RUN / CHANGE CONTROLS — SHRINKABLE CHIP DECKS
   ------------------------------------------------------------------------ */
body[data-workspace-mode="race_profiler"] #lto :is(.equal-buttons-2,.equal-buttons-3),
body[data-workspace-mode="race_profiler"] #changes :is(.equal-buttons-2,.equal-buttons-3){
  display:grid!important;
  gap:7px!important;
}
body[data-workspace-mode="race_profiler"] #lto .equal-buttons-2,
body[data-workspace-mode="race_profiler"] #changes .equal-buttons-2{
  grid-template-columns:repeat(2,minmax(0,1fr))!important;
}
body[data-workspace-mode="race_profiler"] #lto .equal-buttons-3,
body[data-workspace-mode="race_profiler"] #changes .equal-buttons-3{
  grid-template-columns:repeat(3,minmax(0,1fr))!important;
}
body[data-workspace-mode="race_profiler"] #lto :is(.equal-buttons-2,.equal-buttons-3) .chip,
body[data-workspace-mode="race_profiler"] #changes :is(.equal-buttons-2,.equal-buttons-3) .chip{
  width:100%!important;
  min-width:0!important;
  min-height:30px!important;
  padding:6px 7px!important;
  white-space:normal!important;
  line-height:1.08!important;
}

/* ------------------------------------------------------------------------
   RACE CONDITIONS — GOING / SURFACE WRAPPING
   ------------------------------------------------------------------------ */
body[data-workspace-mode="race_profiler"] #race-conditions :is(#going_group,#aw_surface_group){
  min-width:0!important;
}
body[data-workspace-mode="race_profiler"] #race-conditions :is(#going_group,#aw_surface_group) .chip{
  min-width:0!important;
  width:100%!important;
  padding-inline:7px!important;
  white-space:normal!important;
}

/* ========================================================================
   LARGE / MEDIUM DESKTOP — sidebar-visible working width
   ======================================================================== */
@media(max-width:1750px){
  /* Class and subtype remain paired; Handicap receives its own full row. */
  body[data-workspace-mode="race_profiler"] #race .race-meta-class-row{
    grid-template-columns:minmax(0,1.05fr) minmax(0,.95fr)!important;
  }
  body[data-workspace-mode="race_profiler"] #race .meta-handicap{
    grid-column:1/-1!important;
  }

  /* Horse Age and Gender retain useful width; Country of Breeding moves below. */
  body[data-workspace-mode="race_profiler"] #horse .horse-row1{
    grid-template-columns:minmax(0,1fr) minmax(0,1fr)!important;
  }
  body[data-workspace-mode="race_profiler"] #horse .horse-bred-card{
    grid-column:1/-1!important;
  }
  body[data-workspace-mode="race_profiler"] #horse .horse-gender-card .chips{
    display:grid!important;
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
    gap:8px!important;
  }

  /* The four top Experience/Recency cards become full-width rows before their
     internal metric pills are forced into unreadable widths. */
  body[data-workspace-mode="race_profiler"] #horse-profile-stats .horse-profile-composed-grid.hp-grid-new{
    grid-template-columns:1fr!important;
  }
  body[data-workspace-mode="race_profiler"] #horse-profile-stats :is(
    .horse-rolling-run-strip,
    .horse-rolling-win-strip,
    .horse-experience-strip,
    .horse-prize-strip,
    .condition-matrix-strip,
    .horse-condition-strike-strip
  ){
    grid-column:1!important;
    grid-row:auto!important;
  }

  /* Last-run pairs need the whole row before six binary chips begin to overlap. */
  body[data-workspace-mode="race_profiler"] #lto > .section-body > .grid.lower-two{
    grid-template-columns:1fr!important;
  }

  /* Change / Transition uses two top cards, then full-width flags and break rows. */
  body[data-workspace-mode="race_profiler"] #changes .section-body{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
  body[data-workspace-mode="race_profiler"] #changes .section-body > .grid.lower-three:first-of-type > .card:nth-child(1){
    grid-column:1!important;
    grid-row:1!important;
  }
  body[data-workspace-mode="race_profiler"] #changes .section-body > .grid.lower-three:first-of-type > .card:nth-child(2){
    grid-column:2!important;
    grid-row:1!important;
  }
  body[data-workspace-mode="race_profiler"] #changes .section-body > .grid.lower-three:first-of-type > .card:nth-child(3){
    grid-column:1/-1!important;
    grid-row:2!important;
  }
  body[data-workspace-mode="race_profiler"] #changes .section-body > .grid.lower-three:nth-of-type(2) > .card:nth-child(1){
    grid-column:1/-1!important;
    grid-row:3!important;
  }

  /* Going becomes the requested two rows of three; AW becomes two by two. */
  body[data-workspace-mode="race_profiler"] #race-conditions #going_group{
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
    gap:8px!important;
  }
  body[data-workspace-mode="race_profiler"] #race-conditions #aw_surface_group{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:8px!important;
  }
}

/* ========================================================================
   1600 / 1366 VIEWPORT CONTRACTS
   ======================================================================== */
@media(max-width:1500px){
  body[data-workspace-mode="race_profiler"] #race .race-meta-class-row{
    grid-template-columns:1fr!important;
  }
  body[data-workspace-mode="race_profiler"] #horse-profile-stats .horse-rolling-run-strip .stat-mini-grid.five,
  body[data-workspace-mode="race_profiler"] #horse-profile-stats .horse-rolling-win-strip .stat-mini-grid.five{
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
  }
  body[data-workspace-mode="race_profiler"] #horse-profile-stats .horse-experience-strip .stat-mini-grid.four{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
  body[data-workspace-mode="race_profiler"] #horse-profile-stats .horse-prize-strip :is(.stat-mini-grid.three,.prize-level-grid){
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
  }
}

@media(max-width:1250px){
  body[data-workspace-mode="race_profiler"] #horse .horse-row1{
    grid-template-columns:1fr!important;
  }
  body[data-workspace-mode="race_profiler"] #horse .horse-bred-card{
    grid-column:auto!important;
  }
  body[data-workspace-mode="race_profiler"] #changes .section-body{
    display:block!important;
  }
  body[data-workspace-mode="race_profiler"] #changes .section-body > .grid.lower-three{
    display:grid!important;
    grid-template-columns:1fr!important;
  }
  body[data-workspace-mode="race_profiler"] #changes .section-body > .grid.lower-three > .card{
    grid-column:auto!important;
    grid-row:auto!important;
    height:auto!important;
  }
}

@media(max-width:980px){
  body[data-workspace-mode="race_profiler"] #race .meta-handicap .chips{
    grid-template-columns:1fr!important;
    width:min(100%,360px)!important;
  }
  body[data-workspace-mode="race_profiler"] #horse .horse-gender-card .chips{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
  body[data-workspace-mode="race_profiler"] #horse-profile-stats .horse-rolling-run-strip .stat-mini-grid.five,
  body[data-workspace-mode="race_profiler"] #horse-profile-stats .horse-rolling-win-strip .stat-mini-grid.five,
  body[data-workspace-mode="race_profiler"] #horse-profile-stats .horse-experience-strip .stat-mini-grid.four{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
  body[data-workspace-mode="race_profiler"] #horse-profile-stats .horse-prize-strip :is(.stat-mini-grid.three,.prize-level-grid){
    grid-template-columns:1fr!important;
  }
  body[data-workspace-mode="race_profiler"] #lto .stat-mini-grid.three,
  body[data-workspace-mode="race_profiler"] #changes .stat-mini-grid.three{
    grid-template-columns:1fr!important;
  }
  body[data-workspace-mode="race_profiler"] #race-conditions #going_group,
  body[data-workspace-mode="race_profiler"] #race-conditions #aw_surface_group{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
}

@media(max-width:620px){
  body[data-workspace-mode="race_profiler"] #horse .horse-gender-card .chips,
  body[data-workspace-mode="race_profiler"] #race-conditions #going_group,
  body[data-workspace-mode="race_profiler"] #race-conditions #aw_surface_group{
    grid-template-columns:1fr!important;
  }
}
