/* The printed document (PDF) for both editors, built by static/js/print-document.js. Frames shows it only
   when printing (frames.css keeps it off screen); the Pro print page (templates/pdf_layout.html) is only
   ever loaded in a hidden frame and printed.

   Quiet by design: ink, paper and hairlines. Red appears only where it means something: the step number
   (the customer's accent), the Katamatics square and dot, and the warning's rule and triangle (always
   safety red, whatever the brand). Everything else is ink or grey, so the instruction, the picture and
   the warning lead.

   Pages are always light. A customer's brand reaches them through --accent and --font-text, set on the
   root by the page (Frames: applyBranding in editor-core/editor.js; Pro: the branding block in
   pdf_layout.html).

   Type on paper is set in points from the fixed scale below (design system section 3.4). The page has no
   @page margin, so the browser has nowhere to print its own URL and date: the padding is the margin, and
   the left one is wider so pages can be hole-punched. MARGIN and GATHER in print-document.js mirror these
   sizes; change both together. */
.kdoc {
  --kd-ink: #0E0F11; --kd-soft: #3E434A; --kd-faint: #6C7176;
  --kd-line: #DCDEE1; --kd-line-soft: #E9EAEC; --kd-rule: #9A9EA4;
  --kd-accent: var(--accent, #D72638);
  --kd-red: #D72638;
  --kd-margin: 14mm 14mm 14mm 18mm;
  /* The print type scale (pt), the only sizes on paper. */
  --kd-fs-tech: 7.5pt; --kd-fs-small: 9pt; --kd-fs-body: 11.5pt; --kd-fs-lead: 15pt;
  --kd-fs-step: 18pt; --kd-fs-num: 24pt; --kd-fs-title: 24pt; --kd-fs-cover: 36pt;
  color: var(--kd-ink);
  background: #FFFFFF;
  font-family: var(--font-text);
  font-size: var(--kd-fs-body);
  line-height: 1.5;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.kdoc *, .kdoc *::before, .kdoc *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* One sheet, exactly. A page whose text would not fit (a very long Details text) is marked .is-long by
   print-document.js: it grows onto the next sheet with a smaller picture rather than cutting the text off. */
.kd-page {
  display: flex; flex-direction: column;
  width: var(--kd-page-w, 210mm);
  height: calc(var(--kd-page-h, 297mm) - 1mm);
  padding: var(--kd-margin);
  background: #FFFFFF;
  break-after: page; page-break-after: always;
}
.kd-page:last-child { break-after: auto; page-break-after: auto; }
.kd-page.is-long { height: auto; min-height: calc(var(--kd-page-h, 297mm) - 1mm); --kd-photo-max: 90mm; }

/* Labels: the tech face, small and grey. */
.kd-label, .kd-kicker, .kd-warning-title, .kd-tools li {
  font-family: var(--font-tech); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; line-height: 1.2;
}
.kd-label { display: block; margin-bottom: 1.5mm; font-size: var(--kd-fs-tech); color: var(--kd-faint); }
.kd-kicker { font-size: var(--kd-fs-tech); color: var(--kd-faint); }

/* Brand: logo, company name or the Katamatics logo (an inline SVG, so it prints as vectors; 0.72em tall). */
.kd-logo { display: block; max-height: 7mm; max-width: 45mm; width: auto; height: auto; }
.kd-brand-name { font-size: var(--kd-fs-small); font-weight: 600; white-space: nowrap; }
.kd-wordmark { display: block; flex: none; height: .717em; width: auto; overflow: visible; font-size: 11pt; color: var(--kd-ink); }

/* Header and footer on every page after the cover: one quiet line each. */
.kd-header {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 8mm;
  padding-bottom: 2.5mm; margin-bottom: 8mm; border-bottom: .5pt solid var(--kd-rule);
}
.kd-header-meta { margin-left: auto; text-align: right; min-width: 0; }
.kd-header-title { font-size: var(--kd-fs-small); font-weight: 500; line-height: 1.25; color: var(--kd-soft); overflow-wrap: anywhere; }
.kd-header-sub, .kd-footer, .kd-credit, .kd-cover-note {
  font-family: var(--font-tech); font-size: var(--kd-fs-tech); font-weight: 400; letter-spacing: .04em; line-height: 1.3; color: var(--kd-faint);
}
.kd-header-sub { margin-top: .8mm; }
.kd-footer {
  display: flex; justify-content: space-between; gap: 6mm;
  margin-top: auto; padding-top: 2.5mm; border-top: .5pt solid var(--kd-line);
}
.kd-footer span { overflow-wrap: anywhere; }
.kd-footer .kd-foot-note { flex: 1; text-align: center; }
.kd-footer .kd-foot-right { text-align: right; white-space: nowrap; }
.kd-credit { padding-top: 1.2mm; text-align: right; }

/* Cover. Landscape (or no) picture: title, then the picture full width, then the details.
   Portrait picture: the words and details on the left, the picture on the right at full height. */
.kd-cover-brand { display: flex; align-items: center; padding-bottom: 3mm; margin-bottom: 14mm; border-bottom: .5pt solid var(--kd-rule); }
.kd-cover-brand .kd-wordmark { font-size: 15pt; }
.kd-cover-brand .kd-logo { max-height: 11mm; max-width: 65mm; }
.kd-cover-brand .kd-brand-name { font-size: var(--kd-fs-lead); }
/* The frame holds the size the cover's grid measures against (an element can't query its own size). */
.kd-cover-frame { flex: 1 1 0; min-height: 0; container-type: size; }
.kd-cover-body { height: 100%; display: flex; flex-direction: column; }
.kd-cover-text { display: flex; flex-direction: column; min-width: 0; }
.kd-cover-title {
  margin-top: 3mm; font-family: var(--font-display); font-size: var(--kd-fs-cover); font-weight: 500;
  line-height: 1.08; letter-spacing: -.02em; overflow-wrap: anywhere;
}
.kd-cover-desc {
  margin-top: 5mm; max-width: 150mm; font-family: var(--font-display); font-style: italic;
  font-size: var(--kd-fs-lead); line-height: 1.4; color: var(--kd-soft); white-space: pre-wrap; overflow-wrap: anywhere;
}
/* The whole picture, never cropped, lined up with the left margin. */
.kd-cover-hero { flex: 1 1 0; min-height: 50mm; margin: 10mm 0; container-type: size; display: flex; align-items: flex-start; justify-content: flex-start; }
.kd-cover-hero img { display: block; width: min(100cqw, 100cqh * var(--r, 1.333)); height: auto; }
.kd-cover-gap { flex: 1 1 auto; }
.kd-cover-meta { padding-top: 3mm; border-top: .5pt solid var(--kd-line); }
.kd-cover-id { margin-bottom: 4mm; }
.kd-cover-id .kd-meta-val { font-family: var(--font-tech); font-size: var(--kd-fs-small); font-weight: 400; letter-spacing: .02em; }
.kd-cover-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(30mm, 1fr)); gap: 4mm 6mm; }
.kd-meta-val { display: block; font-weight: 500; overflow-wrap: anywhere; }
.kd-cover-note { margin-top: 4mm; }

/* Portrait picture: the words across the top, then the picture filling a 6:5 box the full width of the page,
   cropped around the focus point the owner chose (--kd-focus, "x% y%"; centre when none), then the details.
   The box has a fixed shape so the editors' previews (the Frames title page, the Workshop's hero picture)
   can show exactly the crop that prints. COVER_BOX in cover-focus.js mirrors the 6:5. */
.kd-cover.is-portrait .kd-cover-hero {
  /* 6:5 at full width; it gives up height (cropping a little more) only if a very long title needs it. */
  flex: 0 1 auto; display: block; min-height: 60mm; margin: 10mm 0 0; container-type: normal;
  width: 100%; aspect-ratio: 6 / 5; overflow: hidden;
}
.kd-cover.is-portrait .kd-cover-hero img {
  width: 100%; height: 100%; object-fit: cover; object-position: var(--kd-focus, 50% 50%);
}
.kd-cover.is-portrait .kd-cover-meta { margin-top: auto; padding-top: 3mm; }
.kd-cover.is-portrait .kd-cover-body { gap: 0; }

/* Before you start */
.kd-gather-head { margin-bottom: 6mm; }
.kd-gather-title { margin-top: 2.5mm; font-family: var(--font-display); font-size: var(--kd-fs-title); font-weight: 500; line-height: 1.15; }
.kd-gather-intro { margin-top: 2mm; color: var(--kd-soft); }
.kd-gather-cols { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 0 8mm; align-items: start; }
.kd-gather-cols ul { list-style: none; }
.kd-gather-cols li {
  position: relative; padding: 1.4mm 0 1.4mm 7mm; border-bottom: .5pt solid var(--kd-line-soft);
  line-height: 1.35; overflow-wrap: anywhere; break-inside: avoid;
}
.kd-gather-cols li::before { content: ''; position: absolute; left: 0; top: 2.1mm; width: 3.4mm; height: 3.4mm; border: .6pt solid var(--kd-ink); border-radius: .5mm; }

/* A step */
.kd-step-head { display: flex; align-items: baseline; gap: 5mm; margin-bottom: 7mm; }
.kd-step-num { flex: 0 0 auto; font-family: var(--font-num); font-size: var(--kd-fs-num); font-weight: 400; line-height: 1; color: var(--kd-accent); }
.kd-instruction { font-family: var(--font-display); font-size: var(--kd-fs-step); font-weight: 500; line-height: 1.25; white-space: pre-wrap; overflow-wrap: anywhere; }
.kd-instruction.none { color: var(--kd-faint); font-style: italic; }

/* The body fills the page down to the footer. The picture's row is as tall as the picture at its column's
   width (its ratio, --r, is set by print-document.js) or as tall as the page allows, whichever is less;
   any space left over sits above the footer, never between the picture and its text. */
.kd-step-body {
  /* min-height 0: left at auto, the grid would ask for its picture at full size and push the page taller.
     Text that doesn't fit is caught by markLongPages instead, and the page grows (.is-long). */
  /* The margin keeps the last of the text (a parts list, say) clear of the footer's line. */
  flex: 1 1 0; min-height: 0; display: grid; gap: 0 8mm; align-content: start; margin-bottom: 6mm;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(55mm, min(var(--kd-photo-max, 1000mm), calc(var(--kd-content-w) / var(--r, 1.333)))) auto auto;
  grid-template-areas: "warn" "photo" "details" "tools";
}
.kd-step .kd-side { display: contents; }
/* Portrait picture: the picture on the left at two thirds of the width, and beside it, in the same order as
   the landscape pages, the warning, the details, then the tools and parts. */
.kd-step.is-portrait .kd-step-body {
  grid-template-columns: 66% minmax(0, 1fr);
  grid-template-rows: auto auto auto minmax(0, 1fr);
  grid-template-areas: "photo warn" "photo details" "photo tools" "photo .";
}
.kd-step.is-portrait .kd-warning { margin: 0 0 6mm; }
.kd-step.is-portrait .kd-details { margin: 0 0 6mm; max-width: none; }
.kd-step.is-portrait .kd-tools { margin: 0; }
.kd-page.is-long .kd-step-body { flex: none; }
.kd-step.no-photo .kd-step-body { grid-template-rows: auto auto auto auto; }

/* Warning: a triangle and the word, then the text in red at the heaviest text weight. No rule or indent, so it
   lines up with the text around it; no fill, and the weight still stands out in black and white. */
.kd-warning { grid-area: warn; margin-bottom: 6mm; break-inside: avoid; }
.kd-warning-title { display: flex; align-items: center; gap: 1.6mm; font-size: var(--kd-fs-tech); color: var(--kd-red); }
.kd-warning-icon { flex: 0 0 auto; width: 3.4mm; height: 3.4mm; }
.kd-warning-text { margin-top: 1.5mm; line-height: 1.45; color: var(--kd-red); font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Pictures sit on the left margin, never centred. */
.kd-photo { grid-area: photo; min-height: 55mm; container-type: size; display: flex; align-items: flex-start; justify-content: flex-start; }
/* Scaled up or down to fit the box, keeping its shape. */
.kd-photo img { display: block; width: min(100cqw, 100cqh * var(--r, 1.333)); height: auto; outline: .5pt solid var(--kd-line); outline-offset: -.25pt; }
.kd-photo.is-empty { min-height: 0; container-type: normal; padding: 6mm; border: .5pt dashed var(--kd-rule); color: var(--kd-faint); font-style: italic; }
/* Under a picture narrower than the page, the details are no wider than it (--kd-img-w, set by
   print-document.js), so the text doesn't run out past the picture's edge. */
.kd-details { grid-area: details; margin-top: 6mm; max-width: var(--kd-img-w, none); }
/* Supporting text: the body size (pages are read on screens as well as paper) in the softer grey, so the
   instruction and picture still lead. */
.kd-details-text { font-size: var(--kd-fs-body); line-height: 1.5; color: var(--kd-soft); white-space: pre-wrap; overflow-wrap: anywhere; }
.kd-tools { grid-area: tools; margin-top: 6mm; break-inside: avoid; }
.kd-tools ul { display: flex; flex-wrap: wrap; gap: 1.5mm; list-style: none; }
.kd-tools li { padding: .9mm 2.2mm; border: .5pt solid var(--kd-rule); border-radius: .6mm; font-size: var(--kd-fs-tech); font-weight: 400; letter-spacing: .06em; color: var(--kd-ink); }
.kd-tools ul + .kd-parts-label { display: block; margin-top: 3mm; }
.kd-gather-cols li.kd-gather-sub { padding-left: 0; font-family: var(--font-tech); font-size: var(--kd-fs-tech); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--kd-soft); }
.kd-gather-cols li.kd-gather-sub::before { content: none; }
.kd-gather-cols li + li.kd-gather-sub { padding-top: 5mm; }

/* Landscape pages (.kd-landscape, set on the root by print-document.js). */

/* Landscape page, picture narrower than 1.7:1 (portrait, square, 4:3, 3:2): the picture on the left in a
   column of fixed width (55%, PHOTO_COLUMN in print-document.js), as wide as the column or as tall as the page
   allows. Beside it, in order of importance: the instruction, the warning, the details, then the tools and
   parts. The text starts in the same place on every page. A portrait picture takes the full height and the
   footer sits beside it; one that ends above the footer at the column's width (.foot-across) has the footer
   across the page under it. */
.kdoc.kd-landscape .kd-step:not(.is-wide):not(.no-photo) {
  display: grid; column-gap: 10mm;
  grid-template-columns: 55% minmax(0, 1fr);
  grid-template-rows: auto auto auto auto auto minmax(0, 1fr) auto auto;
  grid-template-areas: "photo header" "photo head" "photo warn" "photo details" "photo tools" "photo ." "photo footer" "photo credit";
}
.kdoc.kd-landscape .kd-step.foot-across:not(.is-wide):not(.no-photo) {
  grid-template-areas: "photo header" "photo head" "photo warn" "photo details" "photo tools" "photo ." "footer footer" "credit credit";
}
.kdoc.kd-landscape .kd-step:not(.is-wide):not(.no-photo) .kd-step-body,
.kdoc.kd-landscape .kd-step:not(.is-wide):not(.no-photo) .kd-side { display: contents; }
.kdoc.kd-landscape .kd-step:not(.is-wide):not(.no-photo) .kd-header { grid-area: header; }
.kdoc.kd-landscape .kd-step:not(.is-wide):not(.no-photo) .kd-step-head { grid-area: head; }
.kdoc.kd-landscape .kd-step:not(.is-wide):not(.no-photo) .kd-photo { grid-area: photo; min-height: 0; justify-content: flex-start; }
.kdoc.kd-landscape .kd-step:not(.is-wide):not(.no-photo) .kd-warning { grid-area: warn; margin: 0 0 6mm; }
.kdoc.kd-landscape .kd-step:not(.is-wide):not(.no-photo) .kd-details { grid-area: details; margin: 0 0 6mm; }
.kdoc.kd-landscape .kd-step:not(.is-wide):not(.no-photo) .kd-tools { grid-area: tools; margin: 0; }
.kdoc.kd-landscape .kd-step:not(.is-wide):not(.no-photo) .kd-footer { grid-area: footer; margin-top: 6mm; }
.kdoc.kd-landscape .kd-step:not(.is-wide):not(.no-photo) .kd-credit { grid-area: credit; }

/* Landscape page, wide picture (1.7:1 and wider: 16:9, panoramas): the instruction across the top, then the
   picture on the left, left-aligned at 72% of the width, and beside it a narrower column in the same order as
   the square layout: the warning, the details, then the tools and parts. A step with none of those has the
   picture across the whole width. */
.kdoc.kd-landscape .kd-step.is-wide .kd-step-body {
  grid-template-columns: 72% minmax(0, 1fr); column-gap: 10mm;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  grid-template-areas: "photo warn" "photo details" "photo tools" "photo .";
}
.kdoc.kd-landscape .kd-step.is-wide.no-side.no-details .kd-step-body { grid-template-areas: "photo photo" "photo photo" "photo photo" "photo photo"; }
.kdoc.kd-landscape .kd-step.is-wide .kd-side { display: contents; }
.kdoc.kd-landscape .kd-step.is-wide .kd-photo { justify-content: flex-start; }
.kdoc.kd-landscape .kd-step.is-wide .kd-warning { grid-area: warn; margin: 0 0 6mm; }
.kdoc.kd-landscape .kd-step.is-wide .kd-details { grid-area: details; margin: 0 0 6mm; }
.kdoc.kd-landscape .kd-step.is-wide .kd-tools { grid-area: tools; margin: 0; }
