/* 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 wordmark. The wordmark's red dot is a red copy of the "i"
   trimmed to its top third (overflow, not background-clip, which prints as a stray line in PDFs). */
.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: inline-flex; align-items: center; gap: 2mm; font-family: var(--font-wordmark); font-size: 11pt; font-weight: 600; letter-spacing: -.01em; line-height: 1; white-space: nowrap; color: var(--kd-ink); }
.kd-wordmark-mark { flex: 0 0 2mm; width: 2mm; height: 2mm; background: var(--kd-red); }
.kd-i { position: relative; display: inline-block; line-height: 1; }
.kd-i-dot { position: absolute; left: 0; top: 0; width: 100%; height: .32em; overflow: hidden; color: var(--kd-red); }

/* 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; gap: 2.6mm; }
.kd-cover-brand .kd-wordmark-mark { flex-basis: 2.6mm; width: 2.6mm; height: 2.6mm; }
.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). */
  flex: 1 1 0; min-height: 0; display: grid; gap: 0 8mm; align-content: start;
  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: the picture column starts at 60% and print-document.js widens it (to two thirds at most)
   when the page has height to spare (--kd-photo-w). */
.kd-step.is-portrait:not(.no-side) .kd-step-body {
  grid-template-columns: var(--kd-photo-w, 60%) minmax(0, 1fr);
  grid-template-rows: minmax(auto, min(var(--kd-photo-max, 1000mm), calc(var(--kd-photo-w, var(--kd-content-w) * .6) / var(--r, .75)))) auto;
  grid-template-areas: "photo side" "details details";
}
.kd-step.is-portrait:not(.no-side) .kd-side { display: block; grid-area: side; }
.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, a red rule, the text in ink. No fill, so it reads in black and white. */
.kd-warning { grid-area: warn; margin-bottom: 6mm; padding: .5mm 0 .5mm 4mm; border-left: .9mm solid var(--kd-red); 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; white-space: pre-wrap; overflow-wrap: anywhere; }

.kd-photo { grid-area: photo; min-height: 55mm; container-type: size; display: flex; align-items: flex-start; justify-content: center; }
.kd-step.is-portrait .kd-photo { 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; }
.kd-details { grid-area: details; margin-top: 6mm; }
/* Supporting text: a step down from the body, in the softer grey, so the instruction and picture lead. */
.kd-details-text { font-size: var(--kd-fs-small); line-height: 1.55; color: var(--kd-soft); white-space: pre-wrap; overflow-wrap: anywhere; }
.kd-tools { grid-area: tools; margin-top: 6mm; break-inside: avoid; }
.kd-side .kd-warning:last-child { margin-bottom: 0; }
.kd-step.is-portrait:not(.no-side) .kd-tools { margin-top: 0; }
.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; }
