/* ───────────────────────────────────────────────────────────────────────────
   Billing run detail (/Billing/Runs/{id}) — the run as a report card.

   Everything here is scoped under .leaf-ds and uses only the existing tokens
   (leaf-ds.css). Two deliberate departures from the shared vocabulary:

   1. `.br-chip.st-ok` is a NEUTRAL chip with a small green dot, not the green
      `.lf-tag.tone-ok` pill. A run whose five steps all succeeded should read
      calm; five saturated green pills is the noise this screen removes. The
      global tone is left alone because other screens rely on it.
   2. `.br-issue` carries two literal tints (#fdf7f6 / #fdfaf1) — the tinted
      card wash the palette has no token for. They are the only literals here;
      promote them to tokens if a third surface needs them.
   ─────────────────────────────────────────────────────────────────────────── */

.leaf-ds .br-page { max-width: 940px; margin: 0 auto; }

/* ── breadcrumb ─────────────────────────────────────────────────────────── */
.leaf-ds .br-crumb {
    display: flex; align-items: center; gap: 6px;
    font-size: 11.5px; color: var(--ink-3); margin-bottom: 14px;
}
.leaf-ds .br-crumb a { color: var(--ink-3); text-decoration: none; }
.leaf-ds .br-crumb a:hover { color: var(--accent); text-decoration: underline; }
.leaf-ds .br-crumb svg { color: var(--ink-4); flex: 0 0 auto; }

/* ── header ─────────────────────────────────────────────────────────────── */
.leaf-ds .br-hd {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 24px; margin-bottom: 18px;
}
.leaf-ds .br-hd-ttl { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.leaf-ds .br-hd h1 { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -0.015em; }
.leaf-ds .br-meta {
    display: flex; flex-wrap: wrap; gap: 4px 14px;
    margin-top: 7px; font-size: 11.5px; color: var(--ink-3);
}
.leaf-ds .br-meta b { font-weight: 600; color: var(--ink-2); }
.leaf-ds .br-meta .is-dim { color: var(--ink-4); }
.leaf-ds .br-acts { display: flex; gap: 8px; flex-shrink: 0; flex-wrap: wrap; }

/* ── chips ──────────────────────────────────────────────────────────────── */
.leaf-ds .br-chip {
    display: inline-flex; align-items: center; gap: 5px;
    height: 22px; padding: 0 9px; border-radius: var(--r-pill);
    border: 1px solid var(--line); background: var(--surface-2);
    font-size: 11px; font-weight: 600; color: var(--ink-2); white-space: nowrap;
}
.leaf-ds .br-chip .br-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .85; }
.leaf-ds .br-chip.is-lg { height: 26px; padding: 0 11px; font-size: 12px; }

.leaf-ds .br-chip.st-ok { background: var(--surface-2); color: var(--ink-2); border-color: var(--line); }
.leaf-ds .br-chip.st-ok .br-dot { background: var(--accent); opacity: 1; }
.leaf-ds .br-chip.st-run { background: var(--c-live-bg); color: var(--c-live-fg); border-color: var(--c-live-bd); }
.leaf-ds .br-chip.st-run .br-dot { animation: br-pulse 1.4s ease-in-out infinite; }
.leaf-ds .br-chip.st-wait { background: var(--c-warn-bg); color: var(--c-warn-fg); border-color: var(--c-warn-bd); }
.leaf-ds .br-chip.st-fail { background: var(--c-conf-bg); color: var(--c-conf-fg); border-color: var(--c-conf-bd); }
.leaf-ds .br-chip.st-pending { background: transparent; color: var(--ink-3); border-color: var(--line); }
.leaf-ds .br-chip.st-pending .br-dot,
.leaf-ds .br-chip.st-skip .br-dot { display: none; }
.leaf-ds .br-chip.st-skip { background: var(--surface-2); color: var(--ink-3); border-color: var(--line); }

@keyframes br-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .35; transform: scale(.8); }
}
@media (prefers-reduced-motion: reduce) {
    .leaf-ds .br-chip.st-run .br-dot,
    .leaf-ds .br-live .br-dot { animation: none; }
}

/* ── attention banner — the "what do I do" layer ────────────────────────── */
.leaf-ds .br-banner {
    display: flex; gap: 13px; padding: 15px 17px;
    border-radius: var(--r-card); border: 1px solid var(--line);
    background: var(--surface); box-shadow: var(--shadow-1); margin-bottom: 16px;
}
.leaf-ds .br-banner-ic {
    width: 26px; height: 26px; border-radius: 50%;
    display: grid; place-items: center; flex-shrink: 0; margin-top: 1px;
}
.leaf-ds .br-banner h2 { margin: 0 0 4px; font-size: 14.5px; font-weight: 700; letter-spacing: -0.008em; }
.leaf-ds .br-banner p {
    margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--ink-2);
    text-wrap: pretty; max-width: 64ch;
}
.leaf-ds .br-banner-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }

/* The left rail is an inset shadow so the card keeps a normal border. */
.leaf-ds .br-banner.tone-fail {
    border-color: var(--c-conf-bd);
    box-shadow: inset 3px 0 0 var(--gap-fg), var(--shadow-1);
}
.leaf-ds .br-banner.tone-fail .br-banner-ic { background: var(--c-conf-bg); color: var(--c-conf-fg); }
.leaf-ds .br-banner.tone-fail h2 { color: var(--c-conf-fg); }
.leaf-ds .br-banner.tone-wait {
    border-color: var(--c-warn-bd);
    box-shadow: inset 3px 0 0 var(--warn), var(--shadow-1);
}
.leaf-ds .br-banner.tone-wait .br-banner-ic { background: var(--c-warn-bg); color: var(--c-warn-fg); }
.leaf-ds .br-banner.tone-live .br-banner-ic { background: var(--c-live-bg); color: var(--c-live-fg); }
.leaf-ds .br-banner.tone-done { box-shadow: inset 3px 0 0 var(--accent), var(--shadow-1); }
.leaf-ds .br-banner.tone-done .br-banner-ic { background: var(--accent-soft); color: var(--accent-ink); }
.leaf-ds .br-banner.tone-neutral .br-banner-ic { background: var(--surface-2); color: var(--ink-3); }

.leaf-ds .br-live {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 11px; font-weight: 600; color: var(--c-live-fg);
}
.leaf-ds .br-live .br-dot {
    width: 6px; height: 6px; border-radius: 50%; background: currentColor;
    animation: br-pulse 1.4s ease-in-out infinite;
}

/* ── numbers ────────────────────────────────────────────────────────────── */
.leaf-ds .br-tiles {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px;
    background: var(--line); border: 1px solid var(--line);
    border-radius: var(--r-card); overflow: hidden; margin-bottom: 9px;
}
.leaf-ds .br-tile { background: var(--surface); padding: 13px 16px 14px; }
.leaf-ds .br-tile-k {
    font-size: 9.5px; font-weight: 700; color: var(--ink-3);
    text-transform: uppercase; letter-spacing: .07em;
}
.leaf-ds .br-tile-v {
    margin-top: 5px; font-family: var(--font-mono); font-variant-numeric: tabular-nums;
    font-size: 23px; font-weight: 600; letter-spacing: -0.02em; line-height: 1;
}
.leaf-ds .br-tile-s { margin-top: 4px; font-size: 11px; color: var(--ink-3); }

.leaf-ds .br-subfacts {
    display: flex; flex-wrap: wrap; gap: 3px 10px;
    font-size: 11.5px; color: var(--ink-3); margin-bottom: 26px; padding: 0 3px;
}
.leaf-ds .br-subfacts b {
    font-weight: 600; color: var(--ink-2);
    font-family: var(--font-mono); font-variant-numeric: tabular-nums;
}
.leaf-ds .br-subfacts .br-sep { color: var(--ink-4); }

/* ── section head ───────────────────────────────────────────────────────── */
.leaf-ds .br-sh {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: 12px; margin: 0 0 11px;
}
.leaf-ds .br-sh h3 { margin: 0; font-size: 13.5px; font-weight: 700; letter-spacing: -0.005em; }
.leaf-ds .br-sh .br-note { font-size: 11.5px; color: var(--ink-3); text-align: right; }

/* ── steps ──────────────────────────────────────────────────────────────── */
.leaf-ds .br-steps {
    border: 1px solid var(--line); border-radius: var(--r-card);
    background: var(--surface); overflow: hidden; margin-bottom: 26px;
}
.leaf-ds .br-step { border-top: 1px solid var(--line-2); }
.leaf-ds .br-step:first-child { border-top: 0; }
.leaf-ds .br-step-top {
    position: relative;
    display: grid; grid-template-columns: 34px 1fr auto; align-items: start;
    gap: 0 12px; padding: 13px 15px 13px 13px;
}

/* The hit target is an overlay BEHIND the content, not a wrapping <button>:
   the result area contains buttons and a <details>, and nesting those inside a
   button makes the parser hoist them out of the row. */
.leaf-ds .br-step-hit {
    position: absolute; inset: 0; z-index: 0;
    background: none; border: 0; padding: 0; cursor: pointer;
}
.leaf-ds .br-step-hit:hover { background: var(--surface-2); }
.leaf-ds .br-step-hit:focus-visible { outline: none; box-shadow: inset var(--focus-ring); }
.leaf-ds .br-step-rail,
.leaf-ds .br-step-mid,
.leaf-ds .br-step-right { position: relative; z-index: 1; }
.leaf-ds .br-step-mid { pointer-events: none; }
.leaf-ds .br-step-mid .br-issue { pointer-events: auto; }

.leaf-ds .br-step-rail { display: flex; justify-content: center; padding-top: 1px; position: relative; height: 100%; }
.leaf-ds .br-node {
    width: 20px; height: 20px; border-radius: 50%;
    border: 1.5px solid var(--line); background: var(--surface);
    display: grid; place-items: center; z-index: 1;
    font-family: var(--font-mono); font-size: 10px; font-weight: 600; line-height: 1;
    color: var(--ink-3);
}
.leaf-ds .br-step-rail:after {
    content: ""; position: absolute; top: 20px; bottom: -14px; left: 50%;
    width: 1.5px; background: var(--line-2); transform: translateX(-50%);
}
.leaf-ds .br-step:last-child .br-step-rail:after { display: none; }
.leaf-ds .br-node.n-ok { border-color: var(--accent); color: var(--accent); }
.leaf-ds .br-node.n-live { border-color: var(--c-live-fg); color: var(--c-live-fg); }
.leaf-ds .br-node.n-wait { border-color: var(--warn); color: var(--c-warn-fg); }
.leaf-ds .br-node.n-fail { border-color: var(--gap-fg); background: var(--gap-fg); color: #fff; }
.leaf-ds .br-node.n-pending { border-style: dashed; border-color: var(--ink-4); color: var(--ink-4); }
.leaf-ds .br-node.n-skip { border-style: dashed; border-color: var(--line); color: var(--ink-4); }

.leaf-ds .br-step-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.leaf-ds .br-step-name strong { font-size: 13px; font-weight: 600; }
.leaf-ds .br-step-res {
    margin-top: 5px; font-size: 12px; line-height: 1.5; color: var(--ink-2); text-wrap: pretty;
}
.leaf-ds .br-step-res.is-dim { color: var(--ink-3); }
.leaf-ds .br-step-right { display: flex; align-items: center; gap: 9px; padding-top: 1px; }
.leaf-ds .br-dur {
    font-family: var(--font-mono); font-size: 11px; color: var(--ink-3);
    font-variant-numeric: tabular-nums;
}
.leaf-ds .br-cv { color: var(--ink-4); transition: transform .16s ease; flex: 0 0 auto; }
.leaf-ds .br-step.is-open .br-cv { transform: rotate(90deg); }

/* the fact drawer — all the machinery */
.leaf-ds .br-drawer { padding: 0 15px 15px 59px; }
.leaf-ds .br-dl {
    display: grid; grid-template-columns: auto 1fr; gap: 6px 16px;
    padding: 11px 13px; border-radius: var(--r-6);
    background: var(--surface-2); border: 1px solid var(--line-2); font-size: 12px;
}
.leaf-ds .br-dl dt {
    font-size: 9.5px; font-weight: 700; color: var(--ink-3);
    text-transform: uppercase; letter-spacing: .06em; padding-top: 2px;
}
.leaf-ds .br-dl dd { margin: 0; font-size: 11.5px; color: var(--ink-1); overflow-wrap: anywhere; }
.leaf-ds .br-dl dd.is-mono {
    font-family: var(--font-mono); font-variant-numeric: tabular-nums; word-break: break-all;
}

/* ── issue blocks — one per code, never per occurrence ──────────────────── */
.leaf-ds .br-issue {
    margin-top: 9px; border: 1px solid var(--line);
    border-radius: var(--r-6); overflow: hidden;
}
.leaf-ds .br-issue + .br-issue { margin-top: 7px; }
.leaf-ds .br-issue-hd { display: flex; align-items: flex-start; gap: 9px; padding: 10px 12px; }
.leaf-ds .br-lv {
    width: 16px; height: 16px; border-radius: 50%;
    display: grid; place-items: center; flex-shrink: 0; margin-top: 1px;
}
.leaf-ds .br-issue-tt { display: block; font-size: 12.5px; font-weight: 600; line-height: 1.4; }
.leaf-ds .br-issue-bd {
    display: block; margin-top: 3px; font-size: 12px; line-height: 1.5;
    color: var(--ink-2); text-wrap: pretty; max-width: 66ch;
}
.leaf-ds .br-issue-cnt { margin-left: auto; flex-shrink: 0; }

.leaf-ds .br-issue.lv-error { border-color: var(--c-conf-bd); background: #fdf7f6; }
.leaf-ds .br-issue.lv-error .br-issue-tt { color: var(--c-conf-fg); }
.leaf-ds .br-issue.lv-error .br-lv { background: var(--c-conf-bg); color: var(--c-conf-fg); }
.leaf-ds .br-issue.lv-warn { border-color: var(--c-warn-bd); background: #fdfaf1; }
.leaf-ds .br-issue.lv-warn .br-lv { background: var(--c-warn-bg); color: var(--c-warn-fg); }
.leaf-ds .br-issue.lv-info { background: var(--surface-2); }
.leaf-ds .br-issue.lv-info .br-lv { background: var(--surface-2); color: var(--ink-3); border: 1px solid var(--line); }

.leaf-ds .br-aff { border-top: 1px solid var(--line-2); padding: 2px 0; }
.leaf-ds .br-aff-row {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 12px; font-size: 12px; border-top: 1px solid var(--line-2);
}
.leaf-ds .br-aff-row:first-child { border-top: 0; }
.leaf-ds .br-aff-who { font-weight: 600; }
.leaf-ds .br-aff-id { font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); }
.leaf-ds .br-aff-fix { margin-left: auto; flex-shrink: 0; }
.leaf-ds .br-aff-more {
    padding: 7px 12px; font-size: 11.5px; color: var(--ink-3);
    border-top: 1px solid var(--line-2);
}

.leaf-ds .br-tech { border-top: 1px solid var(--line-2); }
.leaf-ds .br-tech > summary {
    list-style: none; cursor: pointer; padding: 8px 12px;
    font-size: 11px; font-weight: 600; color: var(--ink-3);
    display: flex; align-items: center; gap: 6px;
}
.leaf-ds .br-tech > summary::-webkit-details-marker { display: none; }
.leaf-ds .br-tech > summary:hover { color: var(--ink-1); }
.leaf-ds .br-tech > summary svg { transition: transform .16s ease; }
.leaf-ds .br-tech[open] > summary svg { transform: rotate(90deg); }
.leaf-ds .br-tech pre {
    margin: 0; padding: 0 12px 12px;
    font-family: var(--font-mono); font-size: 10.5px; line-height: 1.6; color: var(--ink-2);
    white-space: pre-wrap; word-break: break-word; max-height: 170px; overflow: auto;
}

/* ── claims ─────────────────────────────────────────────────────────────── */
.leaf-ds .br-tbl {
    border: 1px solid var(--line); border-radius: var(--r-card);
    background: var(--surface); overflow: hidden;
}
.leaf-ds .br-tr {
    display: grid; grid-template-columns: 1fr 90px 130px 80px 110px 20px;
    align-items: center; gap: 12px; padding: 10px 15px;
    border-top: 1px solid var(--line-2); font-size: 12.5px; text-align: left;
}
.leaf-ds .br-thead { border-top: 0; background: var(--surface-2); padding: 8px 15px; }
.leaf-ds .br-thead > div {
    font-size: 9.5px; font-weight: 700; color: var(--ink-3);
    text-transform: uppercase; letter-spacing: .06em;
}
.leaf-ds .br-num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.leaf-ds .br-grp > .br-tr {
    cursor: pointer; background: none; border-left: 0; border-right: 0; border-bottom: 0;
    width: 100%; font: inherit; color: inherit;
}
.leaf-ds .br-grp > .br-tr:hover { background: var(--surface-2); }
.leaf-ds .br-grp > .br-tr:focus-visible { outline: none; box-shadow: inset var(--focus-ring); }
.leaf-ds .br-grp-who { font-weight: 600; }
.leaf-ds .br-grp-id {
    font-weight: 500; color: var(--ink-3);
    font-family: var(--font-mono); font-size: 11px; margin-left: 5px;
}
.leaf-ds .br-lines { background: var(--surface-2); padding: 2px 0 6px; }
.leaf-ds .br-lines .br-tr {
    padding: 6px 15px 6px 27px; border-top: 1px solid var(--line-2);
    font-size: 12px; color: var(--ink-2);
}
.leaf-ds .br-tfoot {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 11px 15px; border-top: 1px solid var(--line);
    background: var(--surface-2); font-size: 12.5px;
}
.leaf-ds .br-tfoot .br-tot {
    font-family: var(--font-mono); font-variant-numeric: tabular-nums;
    font-weight: 600; font-size: 14px;
}

/* ── responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
    .leaf-ds .br-tiles { grid-template-columns: 1fr; }
    .leaf-ds .br-hd { flex-direction: column; gap: 12px; }
    .leaf-ds .br-step-top { grid-template-columns: 34px 1fr; }
    .leaf-ds .br-step-right {
        grid-column: 2; justify-content: flex-start; padding-top: 6px;
    }
    /* Drop Service dates + Units; Client / Claims / Amount is the story. */
    .leaf-ds .br-tr { grid-template-columns: 1fr 60px 100px 20px; }
    .leaf-ds .br-tr > .br-hide-sm { display: none; }
    .leaf-ds .br-drawer { padding-left: 15px; }
}

/* ── start-run dialog ───────────────────────────────────────────────────── */
.leaf-ds .br-dlg-lede {
    margin: 0 0 16px; font-size: 12.5px; line-height: 1.5; color: var(--ink-2); max-width: 60ch;
}
.leaf-ds .br-fld { margin-bottom: 16px; }
.leaf-ds .br-lb {
    display: block; font-size: 9.5px; font-weight: 700; color: var(--ink-3);
    text-transform: uppercase; letter-spacing: .07em; margin-bottom: 6px;
}
.leaf-ds .br-opts { display: grid; gap: 6px; }
.leaf-ds .br-opt {
    display: flex; align-items: flex-start; gap: 9px; padding: 9px 11px;
    border: 1px solid var(--line); border-radius: var(--r-4);
    background: var(--surface); cursor: pointer;
}
.leaf-ds .br-opt:hover { border-color: var(--ink-4); }
.leaf-ds .br-opt input { margin: 2px 0 0; accent-color: var(--accent); }
.leaf-ds .br-opt-t { display: block; font-size: 12.5px; font-weight: 600; }
.leaf-ds .br-opt-d { display: block; font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.leaf-ds .br-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.leaf-ds .br-opt.is-disabled { cursor: not-allowed; opacity: .6; }

.leaf-ds .br-ro {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    height: 34px; padding: 0 11px; border: 1px solid var(--line); border-radius: var(--r-4);
    background: var(--surface-2); font-size: 12.5px; color: var(--ink-1);
}
.leaf-ds .br-ro > span:last-child { font-size: 11px; color: var(--ink-3); }

.leaf-ds .br-presets { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.leaf-ds .br-presets button {
    height: 26px; padding: 0 10px; border-radius: var(--r-pill);
    border: 1px solid var(--line); background: var(--surface);
    font-family: var(--font-ui); font-size: 11.5px; font-weight: 600; line-height: 1;
    color: var(--ink-2); cursor: pointer;
}
.leaf-ds .br-presets button:hover { border-color: var(--ink-4); color: var(--ink-1); }
.leaf-ds .br-presets button[aria-pressed="true"] {
    background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink);
}
.leaf-ds .br-presets button:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.leaf-ds .br-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.leaf-ds .br-preflight {
    display: flex; gap: 9px; padding: 11px 12px; border-radius: var(--r-6);
    background: var(--accent-soft); font-size: 12px; line-height: 1.5; color: var(--accent-ink);
}
.leaf-ds .br-preflight svg { flex: 0 0 auto; margin-top: 2px; }
