/* Simulated comparisons page only. Builds on src/ui/styles.css. */

/* ---- settings ---- */
input[type="number"], input[type="file"] {
  width: 100%;
  min-height: 44px;
  font: inherit;
  font-variant-numeric: tabular-nums lining-nums;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--muted);
  border-radius: 2px;
  background: var(--sheet);
  color: var(--ink);
}

input[aria-invalid="true"] { border: 2px solid var(--paused); background: var(--paused-wash); }

.fields {
  display: grid;
  gap: 0.9rem 1rem;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  align-items: end;
}

fieldset { min-width: 0; margin: 1.5rem 0 0; padding: 0; border: 0; }
legend { width: 100%; padding: 0.8rem 0 0.3rem; border-top: 1px solid var(--ink); font-size: 0.9375rem; font-weight: 700; }

/* One setting per line: name and resulting case count on the left, the number on the right. */
.rate {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 5.5rem;
  column-gap: 1rem;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--rule);
}
.rate label { grid-column: 1; grid-row: 1; margin: 0; font-weight: 500; }
.rate .quota { grid-column: 1; grid-row: 2; }
.rate input { grid-column: 2; grid-row: 1 / span 2; text-align: right; }
.quota { margin: 0; min-height: 1.4em; font-size: 0.875rem; color: var(--muted); font-variant-numeric: tabular-nums lining-nums; }
.pick { padding: 0.6rem 0; }

/* Reference lines. Above the run button, what each run will assign for the chosen setting: teal
   for the original group and plum after the change, as in the chart, the case and the saved
   image. Under the chart, the reason there is no changed case to open. */
.plan, .no-case {
  margin: 0;
  padding: 0.45rem 0.8rem;
  background: var(--sheet);
  border-left: 3px solid var(--teal);
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums lining-nums;
}
.plan { margin-top: 0.6rem; }
.plan-after { margin-top: 2px; border-left-color: var(--plum); }
.no-case { max-width: 46rem; padding: 0.6rem 0.8rem; border-left-color: var(--ink); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin: 0.75rem 0; }
.action {
  min-height: 44px;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 0.45rem 1rem;
  cursor: pointer;
}
.action:hover { background: var(--sheet); }
.action-primary { flex: 1 1 100%; min-height: 48px; font-size: 1.0625rem; color: var(--paper); background: var(--ink); }
.action-primary:hover { background: #45294a; }
.action-quiet { padding-left: 0; padding-right: 0; border-color: transparent; font-weight: 400; text-decoration: underline; text-underline-offset: 0.2em; }

.status { font-weight: 600; }
.status:empty { display: none; }
.load { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--rule); }

.advanced { margin-top: 1.25rem; padding-bottom: 0.5rem; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--rule); }
.advanced > summary { padding: 0.7rem 0; }
.advanced[open] > summary { margin-bottom: 0.5rem; }

/* ---- comparison ---- */
.sheet h2, .empty { padding-top: 0.9rem; border-top: 1px solid var(--ink); }
.empty { margin: 0; font: italic 1.2rem/1.4 var(--serif); color: var(--muted); }
/* The one sentence to read aloud: both counts and the group size, directly above the chart. */
.takeaway { max-width: 40rem; margin: 0; font-size: 1.1875rem; font-weight: 600; line-height: 1.4; font-variant-numeric: tabular-nums lining-nums; }
#results h3 { margin-top: 2.5rem; }

.figure {
  margin: 1.75rem 0 0;
  padding: 1.25rem 0 0.25rem;
  border-top: 3px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}
.figure-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 0.75rem 1.5rem; margin-bottom: 1.25rem; }
.figure-name { flex: 1 1 18rem; max-width: 34rem; }
.figure-title { margin: 0; font: 600 1.3rem/1.2 var(--serif); }
.figure-name .small { margin: 0.35rem 0 0; font-variant-numeric: tabular-nums lining-nums; }
.case-jump { margin: 1.25rem 0 1rem; }

/* Under the chart: what was assigned, what was recorded, what the review did. One line each. */
.reading { max-width: 46rem; margin: 1rem 0; border-top: 1px solid var(--rule); font-size: 0.9375rem; font-variant-numeric: tabular-nums lining-nums; }
.reading > div { display: grid; grid-template-columns: 5.5rem minmax(0, 1fr); column-gap: 1rem; padding: 0.45rem 0; border-bottom: 1px solid var(--rule); }
/* Where "Show a changed case" lands: a little air above the heading. */
#changed-heading { scroll-margin-top: 1rem; }

.views { display: flex; }
.view {
  min-height: 44px;
  min-width: 5rem;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 0;
  padding: 0.3rem 0.9rem;
  cursor: pointer;
}
.view + .view { border-left: 0; }
/* The two buttons touch: the focused one comes forward, so its ring is whole on every side. */
.view:focus-visible { position: relative; z-index: 1; }
.view[aria-pressed="true"] { color: var(--paper); background: var(--ink); font-weight: 700; }

/* The chart. chart-view.js sets --divisions from the model's ticks and --count to the width of
   the widest count label. Every bar, dot, tick and the cue is placed as a share of the same
   rail, which always runs from 0 to the group size. */
.chart { --name: 8.5rem; --count: 11ch; --divisions: 4; max-width: 46rem; margin: 0 auto; }

.plot-row { padding: 0.8rem 0 0.5rem; border-top: 1px solid var(--rule); }
.plot-label { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0 1rem; margin: 0 0 0.35rem; }
.plot-name { font-weight: 600; }
.plot-detail { font-size: 0.875rem; color: var(--muted); font-variant-numeric: tabular-nums lining-nums; }
/* The measure that follows the changed setting reads first: a heavier rule and name, taller
   bars. The order of the rows never changes. */
.plot-focus { border-top: 2px solid var(--ink); }
.plot-focus .plot-name { font-size: 1.0625rem; font-weight: 700; }

/* One run of one measure: its name, its bar on the rail, and its count in a column of its own,
   so the label stays where it is whatever the length of the bar. */
.track, .axis {
  display: grid;
  grid-template-columns: [name] var(--name) [rail] minmax(0, 1fr) [count] var(--count);
  column-gap: 0.75rem;
  align-items: center;
}
.series-name { grid-area: 1 / name; font-size: 0.875rem; color: var(--muted); }
.count { grid-area: 1 / count; text-align: right; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums lining-nums; }
.rail, .strip { grid-area: 1 / rail; position: relative; display: block; }
.rail {
  height: 1.2rem;
  border-right: 1px solid var(--rule);
  background-image: repeating-linear-gradient(90deg, var(--rule) 0, var(--rule) 1px, transparent 1px, transparent calc(100% / var(--divisions)));
}
.plot-focus .rail { height: 1.7rem; }
/* No minimum width: a count of zero fills nothing, and its label still reads "0 of". */
.bar { position: absolute; left: 0; top: 0.2rem; bottom: 0.2rem; }
.bar-before { background: var(--teal); }
.bar-after { background: var(--plum); }

/* The strip under the changed row, empty at rest. After "Run comparison" a thin line traces
   the interval between the two counts in it, once. Decoration only: the bars and numbers above
   are already final. */
.strip { height: 0.5rem; }
.cue { position: absolute; top: 0.1rem; height: 3px; background: var(--ink); pointer-events: none; }

.axis { margin-top: 0.4rem; }
.axis-scale { grid-area: 1 / rail; position: relative; height: 1.7rem; border-top: 1px solid var(--ink); }
.tick { position: absolute; top: 0.35rem; transform: translateX(-50%); font-size: 0.8125rem; font-variant-numeric: tabular-nums lining-nums; }
.tick::before { content: ""; position: absolute; left: 50%; top: -0.35rem; height: 0.3rem; border-left: 1px solid var(--ink); }
/* Under bars, the first and last numbers are set inside the scale, so they never overhang it. */
.chart-bars .tick:first-child { transform: none; }
.chart-bars .tick:first-child::before { left: 0; }
.chart-bars .tick:last-child { transform: translateX(-100%); }
.chart-bars .tick:last-child::before { left: auto; right: 0; }
.axis-label { grid-area: 2 / rail / auto / -1; margin: 0.1rem 0 0; font-size: 0.8125rem; color: var(--muted); }

/* Compact layout: one line per measure, a ring for the original group, a diamond after the
   change. The diamond fits inside the ring, so two equal counts still show both shapes. */
.chart-compact .track, .chart-compact .axis { grid-template-columns: [name rail count] minmax(0, 1fr); padding: 0 0.75rem; }
.chart-compact .rail {
  height: 1.7rem;
  background-image:
    linear-gradient(var(--ink), var(--ink)),
    repeating-linear-gradient(90deg, var(--rule) 0, var(--rule) 1px, transparent 1px, transparent calc(100% / var(--divisions)));
  background-size: 100% 2px, auto;
  background-position: center, 0 0;
  background-repeat: no-repeat, repeat;
}
.legend { display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; list-style: none; margin: 0 0 0.6rem; padding: 0; font-size: 0.9375rem; }
.legend li { display: flex; align-items: center; gap: 0.5rem; }
.mark { flex: none; }
.dot { position: absolute; top: 50%; }
.dot-before, .mark-before {
  width: 1.3rem;
  height: 1.3rem;
  border: 0.22rem solid var(--teal);
  border-radius: 50%;
  background: var(--paper);
}
.dot-after, .mark-after { width: 0.6rem; height: 0.6rem; background: var(--plum); }
.dot-before { transform: translate(-50%, -50%); }
.dot-after { transform: translate(-50%, -50%) rotate(45deg); }
.mark-after { margin: 0 0.35rem; transform: rotate(45deg); }

/* ---- tables ---- */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums lining-nums; }
caption { text-align: left; font-size: 0.875rem; color: var(--muted); padding-bottom: 0.4rem; }
th, td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
th:first-child { padding-left: 0; }
thead th { border-bottom-color: var(--ink); font-size: 0.875rem; vertical-align: bottom; }
td, thead th + th { text-align: right; }
td:last-child { font-weight: 700; }
tbody th[scope="row"] { font-weight: 400; }
tbody th[scope="rowgroup"] { padding-top: 1.2rem; font-size: 0.875rem; }

/* ---- one changed case: every item once, its two values next to each other ---- */
.compare { margin-top: 1rem; }
.compare h4 { font: 600 1.15rem/1.2 var(--serif); letter-spacing: 0; text-transform: none; color: var(--ink); }
.compare h5 { margin-top: 1.1rem; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.pairs { margin: 0.25rem 0; border-top: 1px solid var(--rule); }
/* Narrow first: the item's name on its own line, then the two runs side by side under it. */
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.3rem 1rem; padding: 0.55rem 0; border-bottom: 1px solid var(--rule); }
.pair dt { grid-column: 1 / -1; }
.pair dt .chip { margin-left: 0.6rem; }
/* Teal for the original group, plum after the change, always with the run's name in words. */
.pair-value { min-width: 0; padding-left: 0.6rem; border-left: 3px solid var(--teal); overflow-wrap: anywhere; }
.pair-after { border-left-color: var(--plum); }
.pair-run { display: block; font-size: 0.8125rem; font-weight: 600; color: var(--teal); }
.pair-after .pair-run { color: var(--plum); }
.pair-differs .value { font-weight: 700; }
.pair-head { display: none; }

@media (max-width: 34rem) {
  /* Run name and count share a line above each bar, so the bar keeps the full width. */
  .chart-bars .track { grid-template-columns: [name] minmax(0, 1fr) [count] auto; }
  .chart-bars .track + .track { margin-top: 0.25rem; }
  .chart-bars .rail { grid-area: 2 / 1 / auto / -1; }
  .chart-bars .strip { grid-column: 1 / -1; }
  .chart-bars .axis { grid-template-columns: [name rail count] minmax(0, 1fr); }
}

@media (min-width: 40rem) {
  /* Room for three columns: name, original group, after change. The run names move to one line
     above the values and stay in each cell for screen readers only. */
  .pair { grid-template-columns: 13rem repeat(2, minmax(0, 1fr)); }
  .pair dt { grid-column: auto; }
  .pair-head { display: grid; position: sticky; top: 0; padding-bottom: 0.35rem; border-bottom: 1px solid var(--ink); background: var(--paper); }
  .pairs .pair-run { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

/* Keep controls and their values together at high text magnification. */
.aside, .sheet { container-type: inline-size; }
@container (max-width: 16em) {
  .rate, .reading > div, .fields, .pair { grid-template-columns: minmax(0, 1fr); }
  .rate label, .rate input, .rate .quota { grid-area: auto; }
  .rate input { text-align: start; }
  .views { max-width: 100%; flex-wrap: wrap; }
  .view { min-width: 44px; padding-inline: 0.4rem; }
  .chart-bars .track { grid-template-columns: minmax(0, 1fr); }
  .chart-bars .series-name, .chart-bars .count, .chart-bars .rail { grid-area: auto; }
  .chart-bars .count { white-space: normal; text-align: start; }
  .actions > button { max-width: 100%; overflow-wrap: anywhere; }
}

/* The static chart is complete without the cue; page code also stops it when this setting changes. */
@media (prefers-reduced-motion: reduce) {
  .cue { display: none; }
}

/* The marks keep their shapes in the reader's own colours. Bars are told apart by their names,
   and the original group's bar is hatched. */
@media (forced-colors: active) {
  .chart { --ink: CanvasText; --teal: CanvasText; --plum: CanvasText; --rule: GrayText; --paper: Canvas; }
  .bar, .mark, .dot, .rail, .cue { forced-color-adjust: none; }
  .bar-before { background: repeating-linear-gradient(135deg, CanvasText 0 2px, Canvas 2px 5px); }
}
