/* The authored `compare` block (two responses, images, metrics or tables in
 * one report), not the Compare view, which is css/compare.css. It borrows the
 * Compare view's language: role badges for the sides (A is the human set, B
 * the agent set), and the separate difference channel for changed lines, so a
 * role colour never marks a difference. */
.compare { min-width: 0; }
.compare__prompt {
  /* At the reading size, so the measure (in em) is the prompt text's own:
   * the measure plus this box's padding and rule (18 + 18 + 3 px). */
  max-width: calc(var(--measure) + 39px);
  margin-bottom: 20px;
  padding: 14px 18px;
  border-left: 3px solid var(--border-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-2);
  font-size: var(--reading-size);
}
.compare__prompt > span { display: block; margin-bottom: 4px; font-size: var(--text-xs); font-weight: 600; color: var(--text-secondary); }
.compare__prompt p { max-width: var(--measure); font-family: var(--font-reading); line-height: 1.55; white-space: pre-wrap; }

/* Layout switch and the side switch: the segmented control. */
.compare__tools { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.compare__layouts,
.compare__switch {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-1);
}
.compare__switch { margin-bottom: 12px; }
.compare__layouts button,
.compare__switch button {
  min-height: 30px;
  padding: 0 11px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
}
.compare__layouts button:hover,
.compare__switch button:hover { background: var(--surface-2); color: var(--text-primary); }
.compare__layouts button[aria-pressed="true"],
.compare__switch button[aria-pressed="true"] { background: var(--action); color: var(--on-action); }

/* Highlight changes: a toggle whose box carries the state. */
.compare__highlight {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: 500;
}
.compare__highlight:hover { background: var(--surface-2); }
.compare__highlight::before {
  content: "";
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  color: var(--on-action);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.compare__highlight[aria-pressed="true"]::before { content: "\2713"; border-color: var(--action); background: var(--action); }

.compare__panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--border);
  border-radius: var(--radius-sheet);
  overflow: clip;
}
.compare--toggle .compare__panels { grid-template-columns: minmax(0, 1fr); }
.compare__panel { min-width: 0; padding: 20px 24px 24px; }
.compare--side .compare__panel + .compare__panel { border-left: 1px solid var(--border); }
.compare__panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.compare__label { display: flex; align-items: center; gap: 10px; min-width: 0; margin: 0; font-size: var(--text-sm); font-weight: 600; }
.compare__letter {
  --role: var(--role-human);
  --role-soft: var(--role-human-soft);
  --role-ink: var(--role-human-ink);
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  border: 1.5px solid var(--role);
  border-radius: var(--radius-sm);
  background: var(--role-soft);
  color: var(--role-ink);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1;
}
[data-side="right"] .compare__letter { --role: var(--role-agent); --role-soft: var(--role-agent-soft); --role-ink: var(--role-agent-ink); }
.compare__length { flex-shrink: 0; color: var(--text-secondary); font-size: var(--text-xs); font-variant-numeric: var(--numerals-data); }
.compare__caption { margin: -4px 0 16px; font-size: var(--text-xs); color: var(--text-secondary); }
.compare__code { font-family: var(--font-mono); font-size: var(--text-xs); line-height: 1.7; overflow-x: auto; }
.compare__code code { font: inherit; }
/* Inline blocks, not blocks: the newline between two rows in the <pre> then
 * ends a row instead of adding an empty one. */
.compare__code .compare__line { display: inline-block; width: 100%; vertical-align: top; }
.compare__prose {
  font-family: var(--font-reading);
  font-size: var(--reading-size);
  line-height: 1.6;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}
/* Each line holds to the measure, which resolves at the reading size here.
 * In "One at a time" the panel is the sheet's full width and lines ran to
 * 107 characters. A marked line adds its 28 px sign gutter to the measure,
 * so its text keeps the same length as the lines around it. */
.compare__prose p { max-width: var(--measure); margin: 0; white-space: pre-wrap; }
.compare__prose p + p { margin-top: .5em; }
/* A blank line in the source: a paragraph's space, as .block-prose p + p. A
 * single newline keeps the .5em above, so a label stays close to its text. */
.compare__prose p.compare__line--para { margin-top: 1em; }
.compare[data-highlight="on"] .compare__prose .compare__line--removed,
.compare[data-highlight="on"] .compare__prose .compare__line--added { max-width: calc(var(--measure) + 28px); }

/* Changed lines: the difference channel, never a role colour. A removed line
 * has a single bar and a minus, an added line a double bar and a plus, both
 * on their own pale tint; the sign is the first cue, the tint the last. */
.compare__line { display: block; position: relative; }
.compare[data-highlight="on"] .compare__line--removed,
.compare[data-highlight="on"] .compare__line--added { padding-left: 28px; border-radius: 1px; }
.compare[data-highlight="on"] .compare__line--removed { background: var(--diff-del-unit); box-shadow: inset 2px 0 0 var(--diff-del-line); }
.compare[data-highlight="on"] .compare__line--added { background: var(--diff-ins-unit); box-shadow: inset 2px 0 0 var(--diff-ins-line), inset 6px 0 0 var(--diff-ins-unit), inset 8px 0 0 var(--diff-ins-line); }
.compare__change { display: none; }
.compare[data-highlight="on"] .compare__change {
  position: absolute;
  left: 9px;
  display: inline;
  font-family: var(--font-ui);
  font-weight: 700;
}
.compare[data-highlight="on"] .compare__line--added .compare__change { left: 13px; color: var(--diff-ins-line); }
.compare[data-highlight="on"] .compare__line--removed .compare__change { color: var(--diff-del-line); }
.compare__summary { margin-top: 12px; font-size: var(--text-xs); color: var(--text-secondary); }
.compare[data-highlight="off"] .compare__summary { display: none; }
.compare__metrics { display: grid; gap: 20px; }
.compare__metrics .metric-tile { padding: 0; border: 0; }
.compare__metrics .metric-tile + .metric-tile { border-left: 0; }
.compare__tablewrap { overflow-x: auto; }
.compare__table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); font-variant-numeric: var(--numerals-data); }
.compare__table th,
.compare__table td { padding: 8px; text-align: left; border-bottom: 1px solid var(--border); }
.compare__table th { font-size: var(--text-xs); font-weight: 600; color: var(--text-secondary); border-bottom: 2px solid var(--text-primary); }

/* ── Wipe and overlay ──────────────────────────────────────────────────── */

.compare__frame {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sheet);
  border: 1px solid var(--border);
  background: var(--surface-2);
  line-height: 0;
}

.compare__img { display: block; width: 100%; height: auto; }

.compare--slider .compare__img--after { position: relative; }

/* The wipe is one clip-path driven by --wipe, which the range input sets. No
   layout work, no second image load, and it animates for free. */
.compare--slider .compare__img--before {
  position: absolute;
  inset: 0;
  clip-path: inset(0 calc(100% - var(--wipe, 50%)) 0 0);
}

/* An ink line with a paper halo reads on any image. */
.compare--slider .compare__seam {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--wipe, 50%);
  width: 2px;
  background: var(--text-primary);
  box-shadow: 0 0 0 1px var(--surface-1);
  pointer-events: none;
}

.compare--overlay .compare__img--fade {
  position: absolute;
  inset: 0;
  opacity: var(--fade, .5);
}

.compare--overlay .compare__frame > .compare__img:first-child { position: relative; }

.compare__control { display: block; margin-top: var(--space-2); }
.compare__control input[type="range"] { width: 100%; accent-color: var(--action); }

.compare__legend {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

@container sheet (max-width: 640px) {
  .compare__panels { grid-template-columns: minmax(0, 1fr); }
  .compare--side .compare__panel + .compare__panel { border-left: 0; border-top: 1px solid var(--border); }
  .compare__panel { padding: 16px; }
}
@media print {
  .compare__tools, .compare__switch, .compare__control { display: none; }
  .compare--toggle .compare__panels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compare__face[hidden] { display: block !important; }
  .compare--slider .compare__img--before { position: relative; clip-path: none; }
  .compare--slider .compare__seam { display: none; }
  .compare--overlay .compare__img--fade { position: relative; opacity: 1; }
}

/* ── Paired bars and trend charts ─────────────────────────────────────── */

/* A figure with a rule on top, no box. Values sit in their own column and
 * never wrap mid-number. */
.grouped-chart,
.trend-chart { min-width: 0; margin: 0; padding: 14px 0 0; border: 0; border-top: 1px solid var(--border); border-radius: 0; }
.grouped-chart figcaption,
.trend-chart figcaption { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 12px; }
.grouped-chart figcaption strong,
.trend-chart figcaption strong { font-size: var(--text-sm); font-weight: 600; }
.grouped-chart figcaption > span,
.trend-chart figcaption > span { font-size: var(--text-xs); color: var(--text-secondary); font-variant-numeric: var(--numerals-data); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 20px; margin: 0 0 20px; padding: 0; list-style: none; color: var(--text-secondary); font-size: var(--text-xs); }
.chart-legend li { display: flex; align-items: center; gap: 7px; }
.chart-legend__swatch { width: 10px; height: 10px; border-radius: 2px; }
.chart-bar-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 40px; }
.chart-bar-group h4 { margin-bottom: 8px; font-size: var(--text-sm); font-weight: 600; }
.chart-bar-row { display: grid; grid-template-columns: minmax(64px, 96px) minmax(40px, 1fr) max-content; align-items: center; gap: 10px; margin-top: 8px; }
.chart-bar-row__series { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-xs); color: var(--text-secondary); }
.chart-bar-track { position: relative; height: 10px; border-radius: 2px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }
.chart-bar-track::before { content: ""; position: absolute; left: var(--zero); top: -2px; height: 14px; width: 1px; background: var(--text-secondary); }
.chart-bar { position: absolute; height: 100%; border-radius: 2px; }
.chart-bar-value { min-width: 3ch; font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 600; font-variant-numeric: var(--numerals-data); text-align: right; white-space: nowrap; }
.chart-axis-note { margin-top: 20px; font-size: var(--text-xs); color: var(--text-secondary); }
.chart-values { margin-top: 16px; font-size: var(--text-xs); color: var(--text-secondary); }
.chart-values summary { margin-bottom: 8px; cursor: pointer; }

/* ── Trend charts (js/render/trend.js) ─────────────────────────────────
 * A fixed-height plot: only the lines are SVG, stretched to the box; every
 * piece of text is HTML placed by percentage, so it stays 13 px at every
 * width and the x labels sit under their points. */
.trend-plot { display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: 10px; }
.trend-plot--ends { grid-template-columns: max-content minmax(0, 1fr) 52px; }
.trend-area,
.trend-y { position: relative; height: 200px; margin-block: 24px 10px; }
/* Room around a plot labelled on every point, for a label under a low point. */
.trend-plot--values { margin-block: 24px; }
.trend-y { font-family: var(--font-ui); font-size: var(--text-xs); line-height: 1; color: var(--text-secondary); font-variant-numeric: var(--numerals-data); text-align: right; }
.trend-y > span { position: absolute; right: 0; transform: translateY(-50%); white-space: nowrap; }
.trend-y > .trend-y__sizer { position: static; display: block; height: 0; overflow: hidden; visibility: hidden; transform: none; }
.trend-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.trend-svg .viz-line { vector-effect: non-scaling-stroke; stroke-width: 2; }
.trend-grid { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--viz-grid); }
.trend-marks { position: absolute; inset: 0; pointer-events: none; }
.trend-dot { position: absolute; width: 7px; height: 7px; border-radius: 50%; transform: translate(-50%, -50%); box-shadow: 0 0 0 2px var(--surface-1); }
.trend-value,
.trend-end { font-family: var(--font-ui); font-size: var(--text-xs); line-height: 1.2; font-weight: 600; color: var(--text-primary); font-variant-numeric: var(--numerals-data); white-space: nowrap; }
.trend-value { position: absolute; }
.trend-value--above { transform: translate(-50%, calc(-100% - 7px)); }
.trend-value--below { transform: translate(-50%, 7px); }
.trend-end { position: absolute; left: calc(100% + 10px); display: flex; align-items: center; gap: 5px; transform: translateY(-50%); }
.trend-end i { flex: none; width: 8px; height: 8px; border-radius: 2px; }
.trend-ref { position: absolute; left: 0; right: 0; height: 0; border-top: 1.5px dashed var(--text-primary); }
.trend-ref > span { position: absolute; right: 0; bottom: 3px; padding: 0 4px; font-family: var(--font-ui); font-size: var(--text-xs); line-height: 1.2; color: var(--text-secondary); background: var(--surface-1); white-space: nowrap; }
.trend-x { grid-column: 2; position: relative; height: 1.4em; font-family: var(--font-ui); font-size: var(--text-xs); color: var(--text-secondary); font-variant-numeric: var(--numerals-data); }
.trend-x > span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.trend-x > span:first-child { left: 0 !important; transform: none; }
.trend-x > span:last-child { left: auto !important; right: 0; transform: none; }
.trend-x > span:only-child { left: 50% !important; right: auto; transform: translateX(-50%); }
@media print { .trend-chart { break-inside: avoid; } }
@container sheet (max-width: 640px) { .chart-bar-groups { grid-template-columns: minmax(0, 1fr); gap: 24px; } }
@container sheet (max-width: 480px) {
  .chart-bar-row { grid-template-columns: minmax(56px, 74px) minmax(32px, 1fr) max-content; gap: 6px; }
  .trend-area,
  .trend-y { height: 160px; }
  .trend-value:not(.trend-value--last),
  .trend-x__minor { display: none; }
}
