/* ============================================================
   Reports & Analytics (desk/staff) and the per-case diversion report.
   Both pages are built from design-system components; this sheet only
   places them and adjusts a component inside its own page context.
   Structure in @layer layout, paint in @layer design. It reads only --t-*,
   --c-* and the shared --mea-* letter-spacing tokens (D10).
   ============================================================ */

@layer layout {
  .reports-content { display: grid; gap: var(--t-space-5); }

  /* The five half-width panels stay in document order (language, pipeline,
     failure, charges, timeline) at every width, so what is read and tabbed
     is what is seen. On a wide page grid placement puts them in two columns
     without tying a short panel's height to its neighbour's:
     - pipeline-tall: the pipeline spans the right column's four rows and the
       other four stack on the left. The last row is 1fr, so any height the
       pipeline needs beyond the left stack opens under the timeline, not
       between the panels.
     - otherwise: the pipeline is short and heads the right column with
       charges and the timeline under it; deal failure spans the two rows
       beside them. */
  .reports-columns { display: grid; gap: var(--t-space-5); grid-template-columns: minmax(0, 1fr); }
  .reports-columns > .pane { min-inline-size: 0; }
  @container (min-width: 44rem) {
    .reports-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }

    .reports-columns.pipeline-tall { grid-template-rows: auto auto auto 1fr; }
    .reports-columns.pipeline-tall > .language { grid-area: 1 / 1; }
    .reports-columns.pipeline-tall > .pipeline { grid-area: 1 / 2 / span 4 / 3; }
    .reports-columns.pipeline-tall > .failure { grid-area: 2 / 1; }
    .reports-columns.pipeline-tall > .charges { grid-area: 3 / 1; }
    .reports-columns.pipeline-tall > .timeline { grid-area: 4 / 1; }

    .reports-columns:not(.pipeline-tall) { grid-template-rows: auto auto 1fr; }
    .reports-columns:not(.pipeline-tall) > .language { grid-area: 1 / 1; }
    .reports-columns:not(.pipeline-tall) > .pipeline { grid-area: 1 / 2; }
    .reports-columns:not(.pipeline-tall) > .failure { grid-area: 2 / 1 / span 2 / 2; }
    .reports-columns:not(.pipeline-tall) > .charges { grid-area: 2 / 2; }
    .reports-columns:not(.pipeline-tall) > .timeline { grid-area: 3 / 2; }
  }

  /* Savings hero: the interactive banner. Its figure sits on the left and its
     name on the right, with the basis under both, as the base drew it. */
  .reports .savings > .body { gap: var(--t-space-1); padding: var(--t-space-6);
                              justify-items: center; text-align: center; }
  .reports .savings .figure.spread { inline-size: 100%; }
  .reports .savings .figure .value { font-size: var(--t-font-size-hero);
                                     font-weight: var(--t-font-weight-extrabold); }
  .reports .savings .figure .caption { font-size: var(--t-font-size-lg);
                                       font-weight: var(--t-font-weight-semibold);
                                       letter-spacing: var(--mea-ls-caps); }
  /* On a narrow page the figure and its name stack, as the base did. */
  @container (max-width: 34rem) {
    .reports .savings .figure.spread { grid-template-columns: minmax(0, 1fr); }
  }
  .reports .savings-basis { margin: 0; font-size: var(--t-font-size-sm); }

  /* Deal failure: two headline figures side by side, then the three buckets
     as divided label/value rows with the value at the right edge. */
  .reports .failure-figures { gap: var(--t-space-6); padding-block-start: var(--t-space-2); }

  /* Divided fact rows (deal-failure buckets, cost savings): the label on the
     left, its figure at the right edge, one rule above each row. */
  .reports :is(.failure-facts, .cost-facts) { grid-template-columns: minmax(0, 1fr) auto;
                                              gap: 0; margin: 0; }
  .reports :is(.failure-facts, .cost-facts) .fact {
    align-items: baseline; padding-block: var(--t-space-2);
    border-block-start-style: solid;
    border-block-start-width: var(--t-border-width-interactive);
  }
  .reports .failure-facts dt { font-size: var(--t-font-size-sm); }
  .reports .failure-facts dd { font-size: var(--t-font-size-md);
                               font-weight: var(--t-font-weight-bold); text-align: end; }
  /* The pane's header already rules off the body, so the first cost row
     draws no rule of its own above it. */
  .reports .cost-facts .fact:first-child { border-block-start-width: 0; }
  .reports .cost-facts dt { font-size: var(--t-font-size-sm); }
  .reports .cost-facts dd { font-size: var(--t-font-size-lg);
                            font-weight: var(--t-font-weight-bold); text-align: end; }

  /* Charge breakdown's total is one line: the figure, then its name. */
  .reports .outcome-total { margin: 0; }

  /* Charge rows: coloured dot and label, bar, count, all on one line, with
     no dividers -- the base listed them as a legend, not a table. */
  .reports .charge-rows { gap: var(--t-space-2); }
  .reports .charge-rows > .row { gap: var(--t-space-2); padding: 0;
                                 border-block-end-width: 0; }
  .reports .charge-rows .title { display: flex; align-items: center;
                                 gap: var(--t-space-2); white-space: nowrap;
                                 font-weight: var(--t-font-weight-normal); }
  .reports .charge-rows .aside { font-size: var(--t-font-size-sm);
                                 font-weight: var(--t-font-weight-bold);
                                 white-space: nowrap; }
  /* Jail impact: one bold line, then its basis. */
  .reports .jail-line { margin: 0; font-size: var(--t-font-size-md);
                        font-weight: var(--t-font-weight-bold); }
  .reports .jail-formula { margin: 0; }

  /* Language/share rows: one compact line -- code and name, bar, count. The
     base listed them without dividers, so the page takes the rows component's
     padding and divider off and keeps its one-line grid. */
  .reports .language-rows { gap: var(--t-space-3); }
  .reports .language-rows > .row { gap: var(--t-space-2); padding: 0;
                                   border-block-end-width: 0; }
  .reports .language-rows .title { display: flex; align-items: baseline;
                                   gap: var(--t-space-2); white-space: nowrap; }
  .reports .language-rows .code { font-size: var(--t-font-size-xs);
                                  font-weight: var(--t-font-weight-bold); }
  .reports .language-rows .aside { font-size: var(--t-font-size-sm);
                                   white-space: nowrap; }

  /* ── Pipeline tables (shared by /reports and /reports/diversion-cases) ── */
  .pipeline-body { display: grid; gap: var(--t-space-4); align-content: start; }
  .reports .pipeline :is(td.count, td:last-child),
  .diversion-report .pipeline :is(td.count, td:last-child) { text-align: end; }
  .reports .pipeline thead th:not(:first-child),
  .diversion-report .pipeline thead th:not(:first-child) { text-align: end; }
  .reports .pipeline td.count,
  .diversion-report .pipeline td.count { white-space: nowrap; }
  /* Each stage's bar and share sit on a row of their own, spanning the
     table under its status and count, so a narrow panel never pushes the bar
     out of view. */
  .reports .pipeline tr.stage :is(th, td),
  .diversion-report .pipeline tr.stage :is(th, td) { border-block-end: 0; padding-block-end: 0; }
  .reports .pipeline .percent,
  .diversion-report .pipeline .percent { display: flex; align-items: center; gap: var(--t-space-2); }
  /* The percent label takes its widest width in every row -- one fixed column
     for the figure -- and the track fills what is left. Without that, the
     label's own width set the split row by row and a 15% bar could draw a
     longer track than a 100% one. */
  .reports .pipeline .percent progress,
  .diversion-report .pipeline .percent progress { flex: 1 1 0; min-inline-size: 0; }
  .reports .pipeline .percent span,
  .diversion-report .pipeline .percent span { flex: 0 0 3.5rem;
                                              text-align: end;
                                              font-size: var(--t-font-size-sm);
                                              font-weight: var(--t-font-weight-semibold); }
  .reports .pipeline .name,
  .diversion-report .pipeline .name { display: block; font-size: var(--t-font-size-sm);
                                      font-weight: var(--t-font-weight-semibold); }
  .reports .pipeline .basis,
  .diversion-report .pipeline .basis { display: block; font-size: var(--t-font-size-xs); }
  /* The pipeline sub-headings are section labels at the panel-title size, as
     the base drew them; the heading component's own h1-h4 is hero-sized for a
     page title. */
  .reports .pipeline-heading,
  .diversion-report .pipeline-heading { margin: 0; }
  .reports .pipeline-heading :is(h3, h4),
  .diversion-report .pipeline-heading :is(h3, h4) { font-size: var(--t-font-size-lg);
                                                   font-weight: var(--t-font-weight-bold); }

  /* Per-case diversion report (diversion_cases.html): page-level placement. */
  .diversion-report { display: grid; gap: var(--t-space-5); }
  .diversion-report .refresh { display: flex; flex-wrap: wrap; align-items: center;
                               gap: var(--t-space-3); }
  /* The three panels stay in document order (pipeline, by status, by
     offense). On a wide page the status list spans the narrow column's two
     rows and by offense sits under the pipeline, so a short pipeline (its
     unavailable notice is one line) does not push by offense below the
     status list. The last row is 1fr, so any height the status list needs
     beyond the wide column opens under by offense, not between the panels. */
  .diversion-columns { display: grid; gap: var(--t-space-5); align-items: start;
                       grid-template-columns: minmax(0, 1fr); }
  .diversion-columns > .pane { min-inline-size: 0; }

  @media (min-width: 56rem) {
    .diversion-columns { grid-template-columns: minmax(0, 3fr) minmax(0, 1fr);
                         grid-template-rows: auto 1fr; }
    .diversion-columns > .stages { grid-area: 1 / 1; }
    .diversion-columns > .by-status { grid-area: 1 / 2 / span 2 / 3; }
    .diversion-columns > .by-offense { grid-area: 2 / 1; }
  }
}

@layer design {
  .reports .savings .figure .value { color: var(--c-surface-text-color-base); }
  .reports .savings .figure .caption,
  .reports .savings-basis { color: var(--c-surface-text-color-muted); }

  .reports :is(.failure-facts, .cost-facts) .fact {
    border-block-start-color: var(--t-border);
  }

  .reports .charge-rows .title { color: var(--c-surface-text-color-muted); }

  .reports .outcome-total .caption { color: var(--c-surface-text-color-muted); }

  .reports .jail-formula { color: var(--c-surface-text-color-muted); }

  .reports .language-rows .code { color: var(--c-surface-text-color-muted); }
  .reports .language-rows .aside { color: var(--c-surface-text-color-muted); }

  .reports .pipeline .percent span,
  .diversion-report .pipeline .percent span { color: var(--c-surface-text-color-muted); }
  .reports .pipeline .name,
  .diversion-report .pipeline .name { color: var(--c-surface-text-color-base); }
  .reports .pipeline .basis,
  .diversion-report .pipeline .basis { color: var(--c-surface-text-color-muted); }
}
