/*
 * print.css
 * Version: 2026-11-26d
 * Print buttons on route pages (screen) and the paper version of a route (@media print).
 * Works together with /js/print-route.js.
 */

/* ---------- Screen: the print bar under every leg ---------- */
.print-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin: 18px 0 6px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-b2c2bf, #b2c2bf);
  text-align: left;
}
.print-button {
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-b2c2bf, #b2c2bf);
  background: var(--bg-f4f7f6, #f4f7f6);
  color: inherit;
}
.print-button:hover { filter: brightness(0.95); }
.print-nearby-label { cursor: pointer; font-size: 0.95em; }
.print-route-all {
  justify-content: center;
  border-top: 2px solid var(--border-b2c2bf, #b2c2bf);
  margin: 28px 0 18px;
}
.print-route-all .print-button { font-size: 1.05em; padding: 8px 18px; }
.print-extra { display: none; }

/* ---------- Paper ---------- */
@media print {
  @page {
    size: A4;
    margin: 14mm 14mm 16mm;
    @bottom-right { content: "Page " counter(page) " of " counter(pages); font-size: 8pt; }
  }

  /* Black and white, light background */
  html, body { background: #fff !important; }
  *, *::before, *::after {
    color: #000 !important;
    background: transparent !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
  body { font-size: 10.5pt; line-height: 1.35; }

  /* Let long sections run over several pages. merged.tidy.min.css has an older print rule
     (.logbook-entry { break-inside: avoid }) that pushes a long leg to page 2 and leaves page 1 empty.
     A flex body also splits badly over pages, so use normal block layout on paper. */
  body, #page, #content { display: block !important; }
  .logbook-entry, .tech-entry, .forecast, blockquote, .rr-wrap, .rr-section, .rr-wp-list {
    break-inside: auto !important;
  }
  #page { margin: 0 !important; padding: 0 !important; }
  img { filter: grayscale(1) !important; max-height: 70mm; }
  .flag-icon { display: none !important; }
  a { text-decoration: underline; }

  /* Things that only make sense on a screen */
  .breadcrumb-container,
  nav.menu, figure:has(> nav.menu),
  .button-link, #scrollKnop, #scrollEindeKnop,
  .print-bar,
  route-downloads,
  video, figure:has(video),
  iframe, figure:has(iframe),
  .leaflet-container, [id^="rr-map-"], figure:has([id^="rr-map-"]),
  .rr-collapsed-hint, .rr-chevron,
  #footer-head, #footer-foot, #buyuscoffee, #knrm, #copyright, footer {
    display: none !important;
  }

  /* Open the collapsed route details (waypoints, locks, bridges) */
  .rr-section [id$="-body"] { display: block !important; }

  /* Nearby services only when chosen */
  body:not(.print-with-nearby) nearby-services { display: none !important; }

  /* One leg: hide everything else */
  body.print-mode-leg .header,
  body.print-mode-leg #content > :not(.print-target) { display: none !important; }

  /* Whole route: every leg on a new page */
  body.print-mode-all .print-leg-section { break-before: page; }
  body.print-mode-all .print-leg-section.print-first { break-before: auto; }

  /* Keep things together */
  h1, h2, h3, h4 { break-after: avoid; break-inside: avoid; }
  /* Keep a section title together with the first object below it. */
  .logbook-section > h3 + .objects-list > :first-child { break-before: avoid; }
  tr, figure, li, pro-tip, skipper-note, .kv, .rr-section-bar { break-inside: avoid; }

  /* Objects (locks, bridges, marinas, lights...): never split one over two pages.
     If an object does not fit on the rest of the page, it starts on the next page. */
  .obj-card { break-inside: avoid !important; }
  .obj-head, .rr-wp-name, .rr-wp-coord { break-after: avoid; }

  /* Summary cards ("Route from ...", "About the ...") stay in one piece;
     the long list of objects itself may run over several pages. */
  .logbook-section { break-inside: avoid; }
  .logbook-section:has(.objects-list), .objects-list { break-inside: auto !important; }

  /* Leg header with QR code */
  .print-extra { display: block !important; }
  .print-head {
    display: flex !important;
    gap: 5mm;
    align-items: center;
    margin: 2mm 0 5mm;
    padding: 3mm 0;
    border-top: 0.4pt solid #000;
    border-bottom: 0.4pt solid #000;
    font-size: 9pt;
  }
  .print-qr { flex: 0 0 26mm; width: 26mm; height: 26mm; }
  .print-qr svg { width: 100%; height: 100%; display: block; }
  .print-qr svg rect[fill="black"], .print-qr svg path { fill: #000 !important; }
  .print-head-text { text-align: left; }
  .print-qr-note { font-style: italic; }

  /* Route details: label and value side by side, a bit smaller */
  .rr-wrap { font-size: 9pt; }
  .kv { grid-template-columns: 38mm 1fr !important; column-gap: 3mm !important; row-gap: 0.5mm !important; align-items: baseline; }
  .kv .k, .kv .v { margin: 0 !important; padding: 0 !important; }
  .obj-card { margin: 0 0 2mm !important; padding: 1.5mm 0 !important; border: 0 !important; border-top: 0.4pt solid #999 !important; border-radius: 0 !important; }

  /* List of links at the end of a leg */
  .print-links {
    margin-top: 6mm;
    padding-top: 3mm;
    border-top: 0.4pt solid #000;
    font-size: 8.5pt;
    break-inside: auto;
  }
  .print-links h4 { margin: 0 0 2mm; font-size: 9.5pt; }
  .print-links ol { margin: 0 0 0 6mm; padding: 0; }
  .print-links li { margin: 0 0 1mm; break-inside: avoid; }
  .print-url { word-break: break-all; }
}
