/**
 * print.css — the print preview overlay and the @media print rules
 *
 * TWO SEPARATE JOBS
 * -----------------
 * 1. The print *preview* (printPreview.js) is an on-screen overlay showing the
 *    chosen paper, orientation and margins with the work laid out inside it.
 *    It is ordinary screen CSS and lives in the first half of this file.
 *
 * 2. The print *output* is produced by printTool.js, which clones the board
 *    into a dedicated print document.  Rather than fighting the app chrome with
 *    a long list of display:none rules — which is fragile, and silently breaks
 *    every time a new element is added — School Data prints from a purpose-built
 *    document that contains only the work.  The @media print block here is the
 *    safety net for a user who presses Ctrl+P without opening the print dialog:
 *    it hides the chrome and prints the board directly.
 *
 * WHY A SEPARATE PRINT DOCUMENT
 * -----------------------------
 * The board uses CSS Grid, sticky headers and scrolling containers.  All three
 * behave unpredictably across print engines.  The print document flattens them:
 * no sticky positioning, no overflow, explicit page-break rules, and a fixed
 * millimetre page box driven by an @page rule.  The result is that what the
 * preview shows is what comes out of the printer.
 */

/* ══════════════════════════════════════════════════════════════════════════
   1. On-screen print preview overlay
   ══════════════════════════════════════════════════════════════════════════ */
.preview-host[hidden] {
  display: none;
}

.preview-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  background: #4b5563;
}

.preview-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.6rem 0.9rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line-strong);
  box-shadow: var(--shadow-2);
}

.preview-bar h2 {
  margin: 0;
  font-size: 1.05rem;
  flex: 0 0 auto;
}

.preview-bar .spacer {
  flex: 1 1 auto;
}

.preview-stage {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  scrollbar-width: thin;
}

/* One .preview-page per printed sheet.  Its width and height are set inline in
   millimetres by printPreview.js from the chosen paper size, and the browser
   converts mm to device pixels for us — so the proportions on screen match the
   paper exactly, at any zoom level. */
.preview-page {
  position: relative;
  flex: 0 0 auto;
  background: #ffffff;
  color: #111111;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

/* The margin guide: a dashed rectangle showing the printable area.  Drawn with
   an inset box-shadow plus an outline so it needs no extra element and cannot
   be mistaken for page content. */
.preview-margin-guide {
  position: absolute;
  border: 1px dashed #9ca3af;
  pointer-events: none;
}

.preview-content {
  position: absolute;
  overflow: hidden;
  /* transform-origin top-left plus a scale set inline gives an exact,
     non-reflowing reduction of the board to page width — the same scale factor
     the print document uses, so preview and output agree. */
  transform-origin: top left;
}

.preview-page-number {
  position: absolute;
  bottom: 4mm;
  right: 6mm;
  font-size: 9pt;
  color: #6b7280;
}

.preview-caption {
  color: #f9fafb;
  font-size: var(--font-size-sm);
  font-weight: 600;
}

/* ══════════════════════════════════════════════════════════════════════════
   2. The print document's own stylesheet
   ══════════════════════════════════════════════════════════════════════════
   printTool.js injects these rules into the print window it builds.  They are
   kept here, in a normal stylesheet, rather than as a JavaScript template
   string, so they are readable, lintable and cache-friendly.  The file is
   fetched and inlined by printTool.js at print time. */
.print-doc {
  margin: 0;
  padding: 0;
  background: #ffffff;
  color: #000000;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.4;
}

.print-sheet {
  box-sizing: border-box;
  page-break-after: always;
  break-after: page;
  overflow: hidden;
}

.print-sheet:last-child {
  page-break-after: auto;
  break-after: auto;
}

.print-header {
  border-bottom: 2px solid #000000;
  padding-bottom: 3mm;
  margin-bottom: 5mm;
}

.print-title {
  margin: 0;
  font-size: 16pt;
}

.print-question {
  margin: 1mm 0 0;
  font-size: 11pt;
  font-style: italic;
}

.print-footer {
  margin-top: 5mm;
  padding-top: 2mm;
  border-top: 1px solid #6b7280;
  font-size: 8pt;
  color: #374151;
  display: flex;
  justify-content: space-between;
}

/* Name / date / class line, so a printed sheet can be handed straight out. */
.print-nameline {
  display: flex;
  gap: 8mm;
  margin-bottom: 4mm;
  font-size: 10pt;
}

.print-nameline span {
  flex: 1;
  border-bottom: 1px solid #000000;
  padding-bottom: 1mm;
}

/* An SVG chart must never be split across a page boundary: half a pie or half
   a scatter graph is not a chart, it is a mistake. */
.print-doc .chart-svg,
.print-doc .chart-pie-wrap,
.print-doc .chart-legend {
  page-break-inside: avoid;
  break-inside: avoid;
}

/* SVG charts are drawn with a viewBox, so they scale to the printable width
   without the browser re-laying anything out. Cap the height so a tall chart
   still leaves room for its caption and table on the same sheet. */
.print-doc .chart-svg {
  width: 100%;
  max-width: 160mm;
  max-height: 110mm;
  margin: 0 auto;
}

/* Printers vary in how they honour currentColor inside SVG, so the chart
   strokes are pinned to black rather than left to the theme. */
.print-doc .chart-svg-axis,
.print-doc .chart-svg-line {
  stroke: #000000;
}

.print-doc .chart-svg-gridline {
  stroke: #9ca3af;
}

.print-doc .chart-svg-axis-label,
.print-doc .chart-svg-tick,
.print-doc .chart-svg-value {
  fill: #000000;
}

.print-doc .chart-pie-slice,
.print-doc .chart-svg-dot {
  stroke: #ffffff;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.print-doc .chart-legend {
  columns: 2;
  column-gap: 8mm;
  font-size: 9pt;
}

/* Keep a category's label with its bar, and never split a table row. */
.print-doc tr,
.print-doc .pictogram-label,
.print-doc .pictogram-symbols,
.print-doc .tally-label,
.print-doc .tally-marks,
.print-doc .chart-bar-wrap,
.print-doc .chart-legend-item,
.print-doc .branch-node,
.print-doc .record-card {
  page-break-inside: avoid;
  break-inside: avoid;
}

.print-doc thead {
  display: table-header-group;
}

/* Charts must be ink-frugal but still distinguishable, so print uses the same
   pattern overlays as the screen with a heavier outline. */
.print-doc .chart-bar,
.print-doc .chart-bar-h {
  border: 1.5pt solid #000000 !important;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.print-doc .data-table th,
.print-doc .data-table td {
  border: 0.75pt solid #000000;
  padding: 1.5mm 2mm;
}

.print-doc .data-table thead th {
  background: #e5e7eb !important;
  position: static;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* Anything interactive is meaningless on paper. */
.print-doc button,
.print-doc input,
.print-doc select,
.print-doc .row-actions,
.print-doc .records-toolbar,
.print-doc .board-empty-actions {
  display: none !important;
}

.print-doc .branch-pan-hint,
.print-doc .branch-tree-viewport {
  display: none !important;
}

/* The screen-reader table is normally .sr-only; in print it is shown or hidden
   depending on the "Include the data table" option, which printTool.js toggles
   with this class on the sheet. */
.print-doc.with-table .sr-only.data-table-wrap {
  position: static !important;
  width: auto;
  height: auto;
  margin: 5mm 0 0;
  overflow: visible;
  clip: auto;
  clip-path: none;
  white-space: normal;
}

/* ══════════════════════════════════════════════════════════════════════════
   3. Direct Ctrl+P fallback
   ══════════════════════════════════════════════════════════════════════════
   If the user prints the app itself rather than going through the print
   dialog, strip the chrome and print the board.  Deliberately conservative: it
   is a fallback, not the primary path. */
@media print {
  @page {
    size: A4 portrait;
    margin: 12mm;
  }

  html,
  body {
    height: auto !important;
    overflow: visible !important;
    background: #ffffff !important;
    color: #000000 !important;
  }

  .topbar,
  .left-panel,
  .bottombar,
  .skip-links,
  .modal-host,
  .preview-host,
  .menu-backdrop,
  .toast-stack,
  .tool-tip,
  .svg-sprite {
    display: none !important;
  }

  .app {
    display: block !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .workspace,
  .board-scroll {
    overflow: visible !important;
    height: auto !important;
    padding: 0 !important;
  }

  .board {
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    min-height: 0;
  }

  .branch-pan-hint {
    display: none !important;
  }

  .branch-tree-viewport {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    border: 0 !important;
  }

  /* Show the data table in the fallback print, because a chart without its
     numbers is much less useful on paper. */
  .data-table-wrap.sr-only {
    position: static !important;
    width: auto;
    height: auto;
    margin-top: 6mm;
    overflow: visible;
    clip: auto;
    clip-path: none;
    white-space: normal;
  }

  .chart-bar,
  .chart-bar-h,
  .data-table thead th,
  .board-key {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Expose link destinations, which are otherwise lost on paper. */
  .board a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #374151;
  }
}
