.gem-frame-row:has(turbo-frame:empty) {
  display: none;
}

/* Gated on the frame row being displayed so an expanded row whose frame has not
   loaded yet keeps its normal border instead of looking open-ended. The gate
   is turbo-frame:not(:empty) because :has() cannot contain another :has(), and
   a browser drops the whole rule when it does. The transparent border keeps its
   width, so the row height does not shift. The transparent --bs-table-bg-state
   outranks Bootstrap's table-hover state, so an open block does not light up
   under the pointer. */
tr[aria-expanded="true"]:has(+ .gem-frame-row turbo-frame:not(:empty)) > td {
  --bs-table-bg-state: transparent;
  border-bottom-color: transparent;
}

/* The tint sets --bs-table-bg on the cells, which would shadow the --bs-table-bg
   that .table-warning sets on the row, so a highlighted row keeps its own. */
tr[aria-expanded="true"]:not(.table-warning):has(+ .gem-frame-row turbo-frame:not(:empty)) > td {
  --bs-table-bg: var(--bs-secondary-bg);
}

/* tr.gem-frame-row is needed to match the specificity of Bootstrap's hover
   rule, which a bare .gem-frame-row > td would lose to. */
.table-hover > tbody > tr.gem-frame-row > td {
  --bs-table-bg-state: transparent;
}

/* The left padding is Bootstrap's .5rem cell padding, which has no variable to
   build on, plus the chevron and its gap, which indents the detail past the
   chevron column. The child combinator keeps it off the nested sub-table's
   cells. */
.gem-frame-row > td {
  --bs-table-bg: var(--bs-secondary-bg);
  border-bottom: calc(var(--bs-border-width) * 2) solid var(--bs-border-color);
  padding-left: calc(.5rem + 1.25rem);
  padding-bottom: .75rem;
}

/* The bar is listed before Bootstrap's own 9999px cell shadow so both paint,
   with the bar on top. A shadow, unlike a border or pseudo-element, takes no
   layout space and leaves the cell non-positioned, so it still scrolls beneath
   the sticky header. */
tr[aria-expanded="true"]:has(+ .gem-frame-row turbo-frame:not(:empty)) > td:first-child,
.gem-frame-row > td {
  box-shadow:
    inset 3px 0 0 var(--bs-link-color),
    inset 0 0 0 9999px var(--bs-table-bg-state, var(--bs-table-bg-type, var(--bs-table-accent-bg)));
}

/* A nested .table re-declares --bs-table-bg on its own element, so the outer
   cell's tint does not reach it and it needs its own override. */
.gem-frame-row .table {
  --bs-table-bg: var(--bs-secondary-bg);
  font-size: .875em;
}

.gem-frame-row .table th {
  font-weight: 600;
  color: var(--bs-secondary-color);
}

/* application.css gives .sort-indicator a fixed gray that would otherwise
   ignore the header color in both color modes. */
.gem-frame-row .sort-indicator {
  color: inherit;
}

/* Keys off the summary row's aria-expanded, not an anchor's, so it cannot
   share the .collapse-toggle rule in application.css. */
tr[aria-expanded="false"] .row-expand-chevron {
  transform: rotate(-90deg);
}
