/* Work Order app — print / PDF layout (M4).
 * Reproduces the Word docs: front page = page 1, one task card per page.
 * The print DOM (#print-root) is built by js/print.js on demand; everything
 * else in the app is hidden while printing. */

@media print {
  @page { size: A4 portrait; margin: 12mm 14mm; }

  html, body { background: #fff !important; }

  /* Hide all app chrome; only the print root is visible. */
  body > *:not(#print-root) { display: none !important; }

  .print-root { display: block !important; }

  .print-page {
    page-break-after: always;
    break-after: page;
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 10.5pt;
    color: #000;
    line-height: 1.35;
  }
  .print-page:last-child { page-break-after: auto; break-after: auto; }

  /* --- page header (docx-style bordered table) / footer ---------------------- */
  .pp-head-tbl {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    margin-bottom: 8px;
  }
  .pp-head-tbl td { border: 1px solid #000; padding: 3px 6px; vertical-align: middle; }
  .pp-head-logo { width: 29%; text-align: center; }
  .pp-head-logo img { max-width: 100%; height: auto; max-height: 42pt; }
  .pp-head-title {
    width: 59%;
    text-align: center;
    font-size: 14pt;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.5px;
  }
  /* Page numbering — single cell at the far right, no inner borders.
     Centered group: labels right-aligned, numbers left-aligned. */
  .pp-head-pagenum { width: 12%; font-weight: 600; line-height: 1.4; }
  .pp-pagenum-row { display: flex; justify-content: center; white-space: nowrap; }
  .pp-pagenum-label { text-align: right; min-width: 36px; }
  .pp-pagenum-value { text-align: left; min-width: 12px; margin-left: 4px; }

  .pp-footer {
    margin-top: 10px;
    border-top: 1px solid #000;
    padding-top: 3px;
    font-size: 8pt;
    color: #000;
  }

  /* --- fields --------------------------------------------------------------- */
  .pp-fields { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 6px 0; }
  /* flex-end keeps every value's border-bottom on the same line even when a
   * value is empty (baseline alignment used to elevate empty fields). */
  .pp-field { display: flex; align-items: flex-end; gap: 5px; min-width: 120px; }
  .pp-label { font-size: 8pt; color: #000; white-space: nowrap; padding-bottom: 1px; }
  .pp-value {
    border-bottom: 1px solid #000;
    padding: 0 6px 1px;
    min-width: 70px;
    min-height: 14px;
    flex: 1;
  }

  /* --- text blocks (remark / work performed): 3 rows divided by lines -------- */
  /* Row 1 grey label with a line under, row 2 data with a line under,
   * row 3 two columns: reference label | value. Outer border around all. */
  .pp-block { margin: 6px 0; border: 1px solid #000; }
  /* Title row same font size as the data cells (page default 10.5pt). */
  .pp-block .pp-label { display: block; padding: 2px 6px; background: #eee; font-weight: 600; font-size: inherit; border-bottom: 1px solid #000; }
  .pp-block-text { min-height: 34px; padding: 4px 6px; white-space: pre-wrap; border-bottom: 1px solid #000; }
  .pp-ref-row { display: flex; gap: 6px; padding: 2px 6px; }
  .pp-ref-row .pp-ref-label { width: 30%; font-weight: 600; }

  /* --- aircraft & order block (6-row table: grey label rows + data rows) ------- */
  /* Fixed layout: row 1's four cells define the columns at 25% each, so the
   * colSpan=2 cells in rows 3-6 land on exactly 50%. */
  .pp-ao-tbl { table-layout: fixed; }
  .pp-ao-val { min-height: 14px; }
  .pp-ao-text-cell { min-height: 30px; white-space: pre-wrap; }

  /* --- sections --------------------------------------------------------------- */
  .pp-section { margin: 8px 0; }
  .pp-section h4 {
    margin: 0 0 4px;
    font-size: 9.5pt;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .pp-table { width: 100%; border-collapse: collapse; }
  .pp-table th, .pp-table td {
    border: 1px solid #000;
    padding: 2px 6px;
    text-align: left;
    vertical-align: top;
  }
  .pp-table th { background: #eee; font-size: 8.5pt; }

  /* Data cells in the front-page tables are centered horizontally + vertically.
   * (Grey label rows keep their default left/top alignment.) Placed after the
   * base .pp-table rule so it wins the cascade at equal specificity. */
  .pp-ao-tbl td, .pp-manpower td, .pp-insp td { text-align: center; vertical-align: middle; }
  /* Grey label (header) rows of the same tables are centered too. */
  .pp-ao-tbl th, .pp-manpower th, .pp-insp th, .pp-crs-tbl th { text-align: center; vertical-align: middle; }

  /* manpower */
  /* Manpower columns: # | Tech/Mech checkboxes | Name | Signature. */
  .pp-manpower td:nth-child(1) { width: 5%; }
  .pp-manpower td:nth-child(2) { width: 30%; }
  .pp-manpower td:nth-child(3) { width: 40%; }

  /* inspectors — # | name | AML lic no | AML exp | A/C type | Signature.
   * Both rows keep the same height even when one is empty. */
  .pp-insp td:nth-child(1) { width: 5%; }
  .pp-insp td:nth-child(2) { width: 28%; }
  .pp-insp td:nth-child(6) { width: 18%; }
  .pp-insp tr { height: 26px; }
  .pp-pen { min-height: 14px; }

  /* parts */
  .pp-parts .pp-col-desc { width: 34%; }
  .pp-parts .pp-col-grn { width: 8%; }
  .pp-sep { border-left: 1px solid #000 !important; background: none; padding: 0 !important; width: 0; }

  /* --- checklist (table with grey header + borders) ----------------------------- */
  .pp-checklist td:nth-child(2) { width: 10%; }
  /* needs the .pp-checklist prefix to beat .pp-table td (left/top) */
  .pp-checklist .pp-check-sig-cell { text-align: center; vertical-align: middle; }

  /* --- flags / error capturing --------------------------------------------------- */
  .pp-flags { display: flex; gap: 16px; margin: 8px 0; }
  .pp-check { display: inline-flex; align-items: center; gap: 5px; font-size: 9.5pt; }
  .pp-box {
    display: inline-block;
    width: 11px; height: 11px;
    border: 1px solid #000;
    text-align: center;
    line-height: 10px;
    font-size: 9pt;
    font-weight: 700;
  }

  .pp-ec { border: 1px solid #000; padding: 6px 8px; }
  .pp-ec-grid { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 6px; }

  /* --- CRS (bordered table like the Word front page) ------------------------------ */
  .pp-crs-tbl { width: 100%; }
  .pp-crs-tbl th, .pp-crs-tbl td { padding: 1px 6px; }
  .pp-crs-title { background: #eee; font-weight: 600; text-align: center; }
  .pp-crs-tbl th:nth-child(1) { width: 13%; }
  .pp-crs-tbl th:nth-child(2) { width: 18%; }
  .pp-crs-tbl th:nth-child(3) { width: 26%; }
  .pp-crs-tbl th:nth-child(4) { width: 29%; }
  .pp-crs-tbl th:nth-child(5) { width: 14%; }
  .pp-crs-tbl td { text-align: center; vertical-align: middle; }
  /* Release statement row stays left/top-aligned, untouched. */
  .pp-crs-tbl tr:nth-child(2) td { text-align: left; vertical-align: top; }
  .pp-crs-val { min-height: 14px; }
  .pp-crs-sig { height: 20px; }
  /* Values row (Location/Date/Name/Signature/Stamp): extra vertical padding so
   * the signature and stamp fields have a bit more height. */
  .pp-crs-tbl tr:last-child td { padding-top: 10px; padding-bottom: 10px; }

  /* Work-card signature table — same style as the front-page CRS table. */
  .pp-sig-tbl th { text-align: center; vertical-align: middle; }
  .pp-sig-tbl td { text-align: center; vertical-align: middle; min-height: 14px; }

  /* Front page footer sits right under the CRS block — no grey rule there. */
  .pp-footer-plain { border-top: none; padding-top: 0; }
}

/* On screen the print root is never visible (it only exists while printing). */
.print-root { display: none; }
