/* =============================================================================
   04 Blueprint · css/reviews.css · Sheet 03, Inspection reports (reviews.html)
   Page styles only. Shared tokens and components live in css/base.css; read
   COMPONENTS.md before adding anything here. Sections (DESIGN.md 6.3):
   #inspection-reports, #selected-reports, #field-notes, #repeat-clients, #register.
   The review markup is generated by tools/reviews_gen.py.
   Order: layout, sections, motion, media queries (min-width).
   ============================================================================= */

/* -----------------------------------------------------------------------------
   1. Hero (#inspection-reports): copy, three figure stamps, jump link
   ----------------------------------------------------------------------------- */
.hero-grid {
  display: grid;
  grid-template-areas:
    "copy"
    "stamps"
    "jump";
  row-gap: var(--s-6);
}

.hero-copy {
  grid-area: copy;
  min-width: 0;
}

/* Three stamps in one row; each caption states the fact of its stamp in plain text */
.hero-stamps {
  grid-area: stamps;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: var(--s-3);
  max-width: 30rem;
}

.hero-stamps li {
  display: grid;
  align-content: start;
  justify-items: center;
  gap: var(--s-3);
  text-align: center;
}

.hero-stamps .stamp {
  width: 100%;
  max-width: 5.5rem;
  height: auto;
  aspect-ratio: 1;
}

.hero-stamps li:nth-child(1) .stamp {
  rotate: -7deg;
}

.hero-stamps li:nth-child(2) .stamp {
  rotate: 4deg;
}

.hero-stamps li:nth-child(3) .stamp {
  rotate: -3deg;
}

/* The figure leads in drawing capitals, the label follows on its own line */
.hero-stamps .stamp-caption b {
  display: flex;
  justify-content: center;
  margin-bottom: var(--s-1);
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-stretch: 62.5%;
  letter-spacing: 0.02em;
  line-height: 1;
}

.hero-jump {
  grid-area: jump;
  justify-self: start;
  min-height: 3rem;
}

/* The up arrow of the sprite, turned to point down the sheet (the hover nudge follows the rotation) */
.hero-jump .icon {
  width: 1rem;
  height: 1rem;
  rotate: 180deg;
}

.hero-jump:hover .icon {
  transform: translateY(-0.1875rem);
}

/* -----------------------------------------------------------------------------
   2. Selected reports (#selected-reports): three large report cards
   ----------------------------------------------------------------------------- */
.selected {
  display: grid;
  gap: var(--s-7) var(--gutter);
}

.report--selected {
  display: flex;
}

.report--selected .report-figure {
  grid-template-rows: auto 1fr auto auto;
  width: 100%;
  padding-bottom: var(--s-7);
}

.report-title {
  color: var(--ink-2);
  font-size: var(--fs-micro);
  letter-spacing: 0.1em;
  line-height: 1.3;
  text-transform: uppercase;
}

.report--selected blockquote {
  max-width: 44rem;
  font-size: 1.125rem;
  line-height: 1.5;
}

/* The opening mark: a 4rem accent quote in the drawing capitals face */
.report--selected blockquote::before {
  display: block;
  height: 2.25rem;
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 4rem;
  font-stretch: 62.5%;
  font-weight: 700;
  line-height: 1;
}

.report--selected figcaption {
  padding-right: 0;
}

/* The tag row keeps clear of the stamp */
.report--selected .tag-list {
  padding-right: 6.5rem;
}

.report--selected .stamp {
  right: 1rem;
  bottom: -1.25rem;
  width: 6rem;
  height: 6rem;
}

/* -----------------------------------------------------------------------------
   3. Field notes (#field-notes): short quotes on accent leaders, ruled rows
   ----------------------------------------------------------------------------- */
.field-notes {
  display: grid;
  column-gap: var(--gutter);
  border-bottom: 1px solid var(--rule);
}

.note {
  display: grid;
  align-content: start;
  gap: var(--s-3);
  padding-block: var(--s-5);
  border-top: 1px solid var(--rule);
}

.note-no {
  color: var(--ink-3);
  font-size: var(--fs-micro);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.1em;
  line-height: 1.3;
}

.note .receipt {
  max-width: 36rem;
}

.note .receipt blockquote {
  font-size: 1.25rem;
  line-height: 1.4;
}

/* The leader sits on the first text line of the larger quote */
.note .receipt::before {
  margin-top: 0.82rem;
}

/* -----------------------------------------------------------------------------
   4. Re-inspections (#repeat-clients): a ruled log with REPEAT CLIENT stamps
   ----------------------------------------------------------------------------- */
.reinspection-dim {
  display: none;
}

.reinspection-log {
  border-bottom: 1px solid var(--rule);
}

.log-row {
  position: relative;
}

/* The top rule of a row (it draws on entry) */
.log-row::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 1px;
  background: var(--rule);
  transform-origin: left;
}

.log-figure {
  display: grid;
  grid-template-areas:
    "no stamp"
    "quote quote"
    "cap cap";
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s-3) var(--s-4);
  padding-block: var(--s-5);
}

.log-no {
  grid-area: no;
  color: var(--ink-3);
  font-size: var(--fs-micro);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.1em;
  line-height: 1.3;
}

.log-figure blockquote {
  grid-area: quote;
  max-width: 44rem;
  font-size: var(--fs-quote);
  line-height: 1.4;
}

.log-figure figcaption {
  grid-area: cap;
  color: var(--ink-3);
  font-size: var(--fs-micro);
  letter-spacing: 0.1em;
  line-height: 1.3;
  text-transform: uppercase;
}

/* Rectangular stamp, viewBox 120 x 48 */
.stamp--repeat {
  grid-area: stamp;
  width: 6rem;
  height: 2.4rem;
}

.log-row:nth-child(3n + 1) .stamp {
  rotate: -4deg;
}

.log-row:nth-child(3n + 2) .stamp {
  rotate: 3deg;
}

.log-row:nth-child(3n + 3) .stamp {
  rotate: -1.5deg;
}

/* -----------------------------------------------------------------------------
   5. Register (#register): criteria filter (native radios; CSS :has() filters)
   ----------------------------------------------------------------------------- */
/* Phones: a two-column grid of equal boxes, "All" across the full row (flex from 48rem).
   The radios are absolutely positioned, so they take no grid cells. */
.filter {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
  margin: 0 0 var(--s-6);
  padding: 1px 0 0 1px;
  border: 0;
}

.filter legend {
  margin-bottom: var(--s-3);
  padding: 0;
  color: var(--ink-3);
  font-size: var(--fs-label);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Visually hidden, still focusable and announced */
.filter input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

/* Segmented boxes: neighbours share their 1px border */
.filter label {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 3rem;
  margin: -1px 0 0 -1px;
  padding: 0 0.875rem;
  border: 1px solid var(--ink-3);
  color: var(--ink-2);
  font-size: var(--fs-label);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color var(--dur-1) linear, color var(--dur-1) linear;
}

.filter label:first-of-type {
  grid-column: 1 / -1;
}

.filter label span {
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.filter input:checked + label {
  position: relative;
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

.filter input:checked + label span {
  color: var(--paper);
}

.filter input:focus-visible + label {
  position: relative;
  z-index: 1;
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

/* Status line (js/reviews.js shows it): an accent datum mark, then the count in words */
.filter-status {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  max-width: none;
  margin: calc(-1 * var(--s-3)) 0 var(--s-6);
  color: var(--ink-2);
  font-size: var(--fs-label);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.filter-status[hidden] {
  display: none;
}

.filter-status::before {
  content: "";
  flex: none;
  width: 0.5rem;
  height: 0.4375rem;
  background: var(--accent);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

#register:has(#c-speed:checked) .report:not([data-tags~="speed"]),
#register:has(#c-communication:checked) .report:not([data-tags~="communication"]),
#register:has(#c-quality:checked) .report:not([data-tags~="quality"]),
#register:has(#c-repeat:checked) .report:not([data-tags~="repeat"]),
#register:has(#c-trading:checked) .report:not([data-tags~="trading"]),
#register:has(#c-trust:checked) .report:not([data-tags~="trust"]) {
  display: none;
}

/* The reports: 12 lists of 14 or 15 (tools/reviews_gen.py), masonry by CSS columns (1, 2 from
   48rem, 3 from 80rem). A list is laid out and painted only when it comes near the viewport
   (content-visibility), so 174 cards cost nothing at load, nothing when the fonts swap, and the
   first sight of a list lays out 15 cards, not 174. --register-all is the measured height
   of all 12 lists at the width named beside each value; one twelfth of it is reserved for a list
   until its first layout (the real height is remembered after that). It is an estimate: the
   real height changes with every width, so a jump to an anchor below the register can land a
   few hundred pixels off until the lists near it are laid out. The 2rem margin under the last card of a
   list keeps its stamp inside the paint box of the list. */
.register {
  --register-all: 3046rem; /* measured at 390px */
  column-gap: 1.5rem;
  content-visibility: auto;
  contain-intrinsic-size: auto 0 auto calc(var(--register-all) / 12);
}

/* Each list opens with its range on a rule ("Reports IR-030 to IR-058", the text of its
   aria-label), so the uneven column ends of the list before it read as the end of a sheet. */
.register::before {
  content: attr(aria-label) / "";
  display: block;
  column-span: all;
  margin-bottom: var(--s-5);
  padding-top: var(--s-2);
  border-top: 1px solid var(--rule);
  color: var(--ink-3);
  font-size: var(--fs-micro);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.1em;
  line-height: 1.3;
  text-transform: uppercase;
}

/* With a criterion checked at most 56 reports show: every list is laid out, so the page length
   is exact (also when the browser restores the criterion on a history navigation), and the
   ranges go (a list can be empty then). The lists are also laid out while the focus is on the
   filter: the next Tab stop is below the register, and the browser must know its real place
   to bring it into view (the heights are remembered after that). */
#register:has(.filter input:not(#c-all):checked) .register,
#register:focus-within .register {
  content-visibility: visible;
}

#register:has(.filter input:not(#c-all):checked) .register::before {
  display: none;
}

.register .report {
  margin-bottom: 2rem;
}

/* 174 stamps in a row: a smaller, lighter mark than on the selected reports */
.register .stamp {
  bottom: -0.5rem;
  width: 3.5rem;
  height: 3.5rem;
  color: color-mix(in srgb, var(--accent) 72%, var(--paper));
}

/* -----------------------------------------------------------------------------
   6. Motion (motion allowed only; js/main.js and js/reviews.js set .rv, .is-in and
   --reveal-delay, see "Scroll reveals" in css/base.css)
   ----------------------------------------------------------------------------- */

/* Hero stamps: printed with the first frame below 64rem. From 64rem they hit in the intro
   (SM5), with the same 400ms CSS deadline as the headline (see the 64rem block). */
html.motion-ok .hero-stamps .stamp[data-intro] {
  opacity: 0.92;
}

@keyframes stamp-deadline {
  to {
    opacity: 0.92;
  }
}

/* Selected reports rise 90ms apart; each stamp follows (BP.stamp) */
.selected .report.rv {
  transition:
    opacity var(--dur-3) var(--ease-settle) var(--reveal-delay, 0ms),
    translate var(--dur-3) var(--ease-settle) var(--reveal-delay, 0ms);
}

.selected .report.rv:not(.is-in) {
  opacity: 0;
  translate: 0 0.75rem;
}

/* Register: the stamps wait until js/reviews.js lands them (one class arms the whole list).
   The hit itself is CSS (the SM5 values of BP.stamp: from 1.9x, 6px up, 320ms, then the card
   settles 1.5px): js/reviews.js only marks the report, so 15 reports that enter in one frame
   cost one style pass. With GSAP each stamp read its computed style after the last one wrote. */
.register.is-armed .report:not([data-stamped]) .stamp {
  opacity: 0;
}

.register.is-armed .report[data-stamped="hit"] {
  animation: register-settle 180ms var(--ease-settle) calc(var(--stamp-delay, 0ms) + 140ms) backwards;
}

.register.is-armed .report[data-stamped="hit"] .stamp {
  animation: register-stamp 320ms var(--ease-stamp) var(--stamp-delay, 0ms) backwards;
}

@keyframes register-stamp {
  from {
    opacity: 0;
    scale: 1.9;
    translate: 0 -6px;
  }
}

@keyframes register-settle {
  from {
    translate: 0 1.5px;
  }
}

/* Log rows: the top rule draws, the row rises, then its stamp hits (BP.stamp) */
.log-row.rv::before {
  transition: scale var(--dur-3) var(--ease-draft) var(--reveal-delay, 0ms);
}

.log-row.rv .log-figure > :not(.stamp) {
  transition:
    opacity var(--dur-3) var(--ease-settle) calc(var(--reveal-delay, 0ms) + 200ms),
    translate var(--dur-3) var(--ease-settle) calc(var(--reveal-delay, 0ms) + 200ms);
}

.log-row.rv:not(.is-in)::before {
  scale: 0 1;
}

.log-row.rv:not(.is-in) .log-figure > :not(.stamp) {
  opacity: 0;
  translate: 0 0.75rem;
}

/* The 60%+ dimension opens from its centre along the log, then its text shows */
.reinspection.rv .dim-line {
  transition: scale var(--dur-4) var(--ease-draft);
}

.reinspection.rv .dim-text {
  transition: opacity var(--dur-3) var(--ease-settle) 300ms;
}

.reinspection.rv:not(.is-in) .dim-line {
  scale: 1 0;
}

.reinspection.rv:not(.is-in) .dim-text {
  opacity: 0;
}

/* -----------------------------------------------------------------------------
   7. Media queries
   ----------------------------------------------------------------------------- */
@media (hover: hover) {
  .filter input:not(:checked) + label:hover {
    background: var(--paper-3);
    color: var(--ink);
  }
}

@media (min-width: 30rem) {
  .report--selected blockquote {
    font-size: var(--fs-quote);
  }
}

@media (min-width: 48rem) {
  .field-notes {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .log-figure {
    grid-template-areas:
      "no quote stamp"
      "no cap stamp";
    grid-template-columns: 5rem minmax(0, 1fr) auto;
    column-gap: var(--gutter);
  }

  /* The report number sits on the first text line of the quote */
  .log-no {
    align-self: start;
    padding-top: 0.6em;
  }

  .filter {
    display: flex;
    flex-wrap: wrap;
  }

  .filter label {
    justify-content: flex-start;
    min-height: 2.25rem;
  }

  /* Tablets: the three stamps share the full row */
  .hero-stamps {
    max-width: none;
  }

  .hero-stamps .stamp {
    max-width: 7rem;
  }

  .register {
    --register-all: 1707rem; /* measured at 768px */
    columns: 2;
  }
}

@media (min-width: 64rem) {
  .register {
    --register-all: 1456rem; /* measured at 1024px */
  }

  /* The stamps are the main figure of this hero: half of the sheet, up to 10.5rem each. The
     three captions share one line; only the angles differ (hand-stamped). */
  .hero-grid {
    grid-template-areas:
      "copy stamps"
      "jump stamps";
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: var(--gutter);
  }

  .hero-stamps {
    align-self: center;
    justify-self: end;
    column-gap: var(--s-5);
    width: 100%;
    max-width: 36rem;
    margin-top: var(--s-6);
  }

  .hero-stamps .stamp {
    max-width: 10.5rem;
  }

  .hero-stamps .stamp-caption b {
    font-size: 2rem;
  }

  html.motion-ok:not(.arrived, .motion-fallback) .hero-stamps .stamp[data-intro] {
    opacity: 0;
  }

  html.motion-ok:not(.intro-on) .hero-stamps .stamp[data-intro] {
    animation: stamp-deadline 1ms linear 400ms forwards;
  }

  /* A vertical dimension spans the whole log on its left */
  .reinspection {
    display: grid;
    grid-template-columns: 2.5rem minmax(0, 1fr);
    column-gap: var(--s-6);
  }

  .reinspection-dim {
    --ext-below: var(--s-5);
    display: flex;
  }
}

@media (min-width: 80rem) {
  .selected {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .register {
    --register-all: 1080rem; /* measured at 1280px */
    columns: 3;
  }
}

@media (min-width: 90rem) {
  .register {
    --register-all: 1022rem; /* measured at 1440px; the content width is fixed from 1408px */
  }
}
