/*
 * The document-verification page, on paper.
 *
 * Everything the page looks like is inline in the design canvas and in
 * dc.css. This file carries the two things an inline style cannot express:
 * the print sheet, and one correction that has to override an inline value —
 * the archive photograph, which the canvas crops and which must not be. The
 * hooks are added by rv_template() in app/src/report_view.php — the canvas
 * itself has no class names.
 *
 * The target is one sheet for an ordinary document and two for a wordy one.
 * The screen layout does not get there on its own: its rhythm is built for a
 * scrolling page, and a document that runs a little long turns into three
 * sheets, two of them nearly empty.
 */

/* Without this the margins are whatever the print dialogue happens to be set
   to, which is how the same document comes out edge-to-edge on one machine
   and inset on another. It is not enough on its own: the dialogue's own
   margin setting overrides @page, and on "None" it wins and the content goes
   back to the paper edge. So the sheet also carries its own side padding
   further down, which nothing outside the page can switch off. */
@page {
  size: A4;
  margin: 10mm;
}

/* Paper only. The screen has the site header for this. */
.rv-print-logo { display: none; }

/* Under the document type, on screen and on paper: this is a downloaded copy,
   not the original. Boxed so it cannot be mistaken for part of the data. */
.rv-copy-note {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid #8a2a2a;
  border-radius: 2px;
  color: #8a2a2a;
  font-size: 12px;
  line-height: 1.5;
}
.rv-copy-note-tr {
  font-style: italic;
  margin-top: 8px;
}

/* A diamond's frame holds the drawn diagram, not a photo: instead of the
   grey stripes of the photo placeholder it gets the background of the home
   page's laboratory scene - white to pale blue, with the blue 40px grid. */
.rv-result [style*="aspect-ratio:1"]:has(.rv-diagram) {
  background:
    linear-gradient(rgba(94,140,163,.10) 1px, transparent 1px),
    linear-gradient(90deg, rgba(94,140,163,.10) 1px, transparent 1px),
    linear-gradient(180deg, #ffffff, #eef3f6) !important;
  background-size: 40px 40px, 40px 40px, 100% 100% !important;
  border-color: rgba(94,140,163,.25) !important;
}

/* Below the search hero the page picks its background up again towards the
   bottom: the hero's hexagon image (fondo-scaled.jpg) under the same warm
   veil, fading in from plain at the top of the results to the hero's density
   at the foot of the page - the two ends of the page match. */
div:has(> .rv-band) {
  /* Pale blue, the tone of the hero's hexagons and of the home page's
     laboratory scene, rather than the canvas's warm white. */
  background:
    linear-gradient(180deg, #eef3f6 0%, rgba(238,243,246,.97) 40%, rgba(238,243,246,.8) 80%, rgba(238,243,246,.66) 100%),
    url('/media/2020/10/fondo-scaled.jpg') center bottom / 100% auto no-repeat,
    #e4ecf0;
}

/* The search hero ended on a hard edge, grey above and the page's warm
   white below. Its last 160px now fade into that white (#f6f5f2, where the
   results background starts); the hero's content is lifted above the fade so
   the search box and the note are not veiled. */
.rv-chrome[style*="background:#e9e7e1"]::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 160px;
  background: linear-gradient(180deg, rgba(238,243,246,0), #eef3f6);
  pointer-events: none;
}
.rv-chrome[style*="background:#e9e7e1"] > div:last-child {
  z-index: 1;
}

/* The document number, a quarter smaller than the canvas's 30–48px: it is a
   reference to read, not a headline. Print sets its own size below. */
.rv-result [style*="--dc-numSize"] {
  font-size: clamp(24px, 3.3vw, 36px) !important;
}

/* Screen only, under the copy notice: the sheet has .rv-print-logo instead. */
.rv-screen-logo {
  text-align: center;
  margin-top: 28px;
}
.rv-screen-logo img {
  height: 78px;
  width: auto;
  display: inline-block;
}

/* ------------------------------------------------ the archive photograph */

/*
 * It must never be cropped, on screen or on paper.
 *
 * The canvas draws the photo in a square frame and fills it with
 * object-fit:cover, which crops whatever does not fit that square. Not one of
 * twenty-five sampled archive photos is square — 640x446 is typical — so a
 * third of the picture was being thrown away, every time, on the one page
 * whose purpose is letting someone compare the stone in their hand with the
 * one on file. A detail cropped out of the frame is a detail they cannot
 * check.
 *
 * So the frame takes the picture's own shape: the image leaves the absolute
 * positioning and returns to the flow, and contain guarantees that whatever
 * the proportions, all of it is there.
 *
 * :has() keeps this to frames that actually hold a photo. The ones without
 * stay square, because that is the box the canvas draws the placeholder gem
 * and its "[ foto archivio ]" caption in.
 */
.rv-result [style*="aspect-ratio:1"]:has(img) {
  aspect-ratio: auto !important;
  height: auto !important;
}
/* Relative, not static: a static link paints under the absolutely positioned
   placeholder gem, which then swallowed every click in the middle of the
   photo. The z-index keeps the link on top. */
.rv-result [style*="aspect-ratio:1"] > a {
  position: relative !important;
  z-index: 1;
  display: block !important;
  width: 100%;
  cursor: zoom-in;
}

/* The enlarged photo: at most 2.5 times its size on the page, never past the
   viewport or its own pixels. The size is set by the script in report_view.php. */
.rv-zoom {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(21, 32, 31, .82);
  cursor: zoom-out;
}
.rv-zoom img {
  max-width: 92vw;
  max-height: 92vh;
  height: auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .4);
}
.rv-result [style*="aspect-ratio:1"] img {
  height: auto !important;
  object-fit: contain !important;
}

@media print {
  /* The canvas fades content in with `animation: fadeUp .4s ease both`, and
     `both` holds the opening frame — opacity 0 — until the animation runs.
     Print can snapshot the page before it has, which puts faded or missing
     content on the sheet. Nothing here needs to animate. */
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }

  /* Header and navigation, the hero with the search form, and the footer. */
  .rv-chrome { display: none !important; }

  /* The toolbar buttons only mean something on screen. */
  [data-print] { display: none !important; }

  /* Paper stays white: no background image behind the document. */
  div:has(> .rv-band) { background: none !important; }

  /* The sheet already carries the logo at the top. */
  .rv-screen-logo, .rv-zoom { display: none !important; }

  /* On screen the site is a card floating on a tinted ground; on paper the
     card is the page, and @page owns the margins. */
  .rv-page {
    padding: 0 !important;
    min-height: 0 !important;
    display: block !important;
  }
  .rv-frame {
    max-width: none !important;
    min-height: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
  }

  /* 56px above and 96px below is a sixth of a sheet spent on nothing. The
     sides are the opposite case: they keep a real margin, in the element
     itself, so the text stays off the paper edge even when the print dialogue
     is set to "None" and @page above is overruled. */
  .rv-band {
    padding: 8mm 8mm 0 !important;
    max-width: none !important;
    gap: 16px !important;
  }

  /* The logo, since the header is not printed and the sheet would otherwise
     carry nothing saying who issued the document. */
  .rv-print-logo {
    display: block !important;
    text-align: center;
    margin: 0 0 7mm;
  }
  .rv-print-logo img {
    height: 17mm;
    width: auto;
    display: inline-block;
  }

  /* The copy notice, tighter on paper. */
  .rv-copy-note {
    margin-top: 4mm;
    padding: 3mm 3.5mm;
    font-size: 10px;
    line-height: 1.45;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .rv-copy-note-tr { margin-top: 2mm; }

  /* "Documento in archivio" answers a question the reader of a printout is
     not asking — they are holding the document — and the closing note about
     the reference number is addressed to someone still on the site. Both are
     screen furniture, and on paper they cost the space the fields need. */
  .rv-result > div:first-child,
  .rv-result [style*="font-size:12.5px"] {
    display: none !important;
  }

  /* A block taller than the sheet cannot avoid being broken. Asking it to
     anyway is what produced the blank first page: Chrome honours the request
     by pushing the block to the next page, finds it still does not fit, and
     breaks it there — leaving the page it came from empty. So the document
     flows, and only the parts small enough to keep whole ask to be kept. */
  .rv-result {
    break-inside: auto;
    page-break-inside: auto;
    gap: 14px !important;
  }

  /* Only blocks that genuinely fit on a sheet may ask not to be broken. Aim
     this at a container instead — the field column, say, which for a wordy
     appraisal is taller than the page — and the same blank sheet comes back:
     the browser pushes the block on, it still does not fit, and the page it
     left stays empty. So: the photo aside and the individual field rows.
     Nothing that can outgrow a sheet. */
  .rv-result [style*="--dc-resultAsidePos"],
  .rv-result [style*="auto-fit"] > div {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* The number is set for a screen headline. On paper it is a reference to
     check against the document in your hand, not the thing you are reading. */
  .rv-result [style*="--dc-numSize"] {
    font-size: 30px !important;
  }

  /* Two columns, stated rather than inferred. The grid asks for
     auto-fit/minmax(220px), so the number of columns depends on the width
     left over — and it flipped to one, doubling the document's length, the
     moment the side padding above narrowed the sheet by 16mm. A print layout
     that changes shape when a margin is adjusted is a trap; on paper the
     answer is always two. */
  .rv-result [style*="auto-fit"] {
    grid-template-columns: 1fr 1fr !important;
  }

  /* 36px of vertical padding per field row is the right rhythm for a page you
     scroll. Across the thirty-five fields of a diamond it is a whole sheet,
     which is the difference between the tail of the document landing on page
     two and not existing. The rows keep their rules and their spacing, just
     tighter. */
  .rv-result [style*="auto-fit"] > div {
    padding: 8px 12px 8px 0 !important;
    gap: 2px !important;
  }

  /* The right-hand column puts 36px between the heading, the field table and
     the closing note, and the heading carries 24px of its own below the rule.
     On screen that is the rhythm of the page; on paper it is the last 70px
     standing between a diamond's thirty-five fields and a single sheet. */
  .rv-result [style*="gap:36px"] { gap: 14px !important; }
  .rv-result [style*="padding-bottom:24px"] { padding-bottom: 10px !important; }

  /* The photograph is sized for a wide screen column. Do not touch the <img>
     to shrink it: it is absolutely positioned at inset:0 inside a square
     frame, so giving it an auto width makes it fall back to the source's own
     size and print straight over the document number. The frame is square and
     takes the width of its grid column, so the column is what caps it.
     Only the layout grid is named here — the field grid below it sizes itself
     with auto-fit and lands on two columns at this width, which is what keeps
     an ordinary document on one sheet. */
  .rv-result [style*="--dc-resultCols"] {
    grid-template-columns: 56mm 1fr !important;
    gap: 10mm !important;
  }

  /* The aside is sticky on screen; on paper sticky positioning just leaves a
     gap where the element would have scrolled. */
  .rv-result [style*="position:var(--dc-resultAsidePos)"],
  .rv-result [style*="position: sticky"] {
    position: static !important;
    top: auto !important;
  }

  /* Print colour: backgrounds carry meaning here (the green "in archivio"
     banner, the tinted photo frame), so keep them rather than letting the
     browser drop them and print a bare outline. */
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
