/*
 * Печать и сохранение в PDF.
 * Кнопка «.PDF» открывает системный диалог печати — там выбирается
 * «Сохранить как PDF». Так не нужна внешняя библиотека, а раскладка
 * остаётся ровно той, что человек видел на экране.
 */
@media print {
  @page { size: A4 portrait; margin: 10mm; }

  html, body { background: #fff !important; color: #000; font-size: 11pt; }

  /* Всё, что не относится к результату расчёта, на бумаге не нужно. */
  .hdr, .ftr, .hero, .faq, .toasts, .modal-back,
  .sec, .run-row, .res-actions, .tabs, .no-print { display: none !important; }

  .wrap { max-width: none; padding: 0; }

  /* На печать уходят все вкладки результата сразу, а не только активная. */
  .tab-panel { display: block !important; page-break-inside: auto; }
  .tab-panel + .tab-panel { margin-top: 10mm; }
  .tab-panel::before {
    content: attr(data-print-title);
    display: block;
    font-family: Unbounded, Manrope, sans-serif;
    font-weight: 700;
    font-size: 13pt;
    margin: 0 0 4mm;
    padding-bottom: 2mm;
    border-bottom: 1pt solid #000;
  }

  .print-head { display: block !important; margin-bottom: 6mm; }
  .print-head .ph-top { display: flex; align-items: center; gap: 4mm; }
  .print-head .ph-logo {
    width: 12mm; height: 12mm; border: 1pt solid #000; border-radius: 2mm;
    display: grid; place-items: center; font-weight: 800; font-size: 14pt;
  }
  .print-head h1 { font-size: 15pt; margin: 0; }
  .print-head .ph-sub { font-size: 9pt; color: #444; }
  .print-head .ph-meta { font-size: 9pt; color: #333; margin-top: 3mm; display: flex; gap: 6mm; flex-wrap: wrap; }

  .kpis { grid-template-columns: repeat(4, 1fr); gap: 2mm; }
  .kpi { border: 0.5pt solid #999; box-shadow: none; padding: 2mm 3mm; break-inside: avoid; }
  .kpi .v { font-size: 13pt; }
  .kpi-brand { background: none !important; }

  .pattern { border: 0.5pt solid #999; box-shadow: none; break-inside: avoid; page-break-inside: avoid; margin-bottom: 3mm; padding: 2.5mm 3mm; }
  .pattern-mult { background: #000 !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .bar { height: 9mm; border: 0.5pt solid #666; }
  .bar-piece {
    background: #e0e0e0 !important; color: #000 !important; border-right: 0.5pt solid #000;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .bar-piece:nth-child(even) { background: #c4c4c4 !important; }
  .bar-rest { background: #fff !important; color: #000 !important; }
  .bar-rest.is-useful { background: #f0f0f0 !important; }
  .bar-trim { background: #888 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  table.data { box-shadow: none; border: 0.5pt solid #999; font-size: 9.5pt; }
  table.data th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.data td, table.data th { border-bottom: 0.5pt solid #ccc; padding: 1.5mm 2mm; }
  thead { display: table-header-group; }

  .labels { grid-template-columns: repeat(4, 1fr); gap: 2mm; }
  .label { border: 0.5pt dashed #000; padding: 2mm; }

  .quote-grid { grid-template-columns: 1fr 1fr; gap: 4mm; }
  .quote-card { border: 0.5pt solid #999; box-shadow: none; padding: 3mm; break-inside: avoid; }
  .money-total .m-v { color: #000; }

  .notice { border: 0.5pt solid #666 !important; background: none !important; color: #000 !important; padding: 2mm 3mm; }

  /* Итоговая сводка нужна на бумаге всегда — её и переписывают в заявку. */
  .totals { page-break-inside: avoid; border-top: 1pt solid #000; margin-top: 6mm; padding-top: 3mm; }
  .totals-title { font-size: 12pt; }
  .totals-grid { grid-template-columns: repeat(3, 1fr); gap: 3mm; }
  .totals .quote-card { break-inside: avoid; }
  .totals-money { background: none !important; border: 0.5pt solid #666; border-radius: 0; }
  .tm-item { border-right: 0.5pt solid #999; padding: 2mm 3mm; }
  .tm-item span { color: #444 !important; }
  .tm-item b { color: #000 !important; font-size: 12pt; }
  .tm-total { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .tm-total b { color: #000 !important; }
  .totals-note { color: #333 !important; }

  a { color: #000; text-decoration: none; }
  a[href^="http"]::after { content: ""; }

  .print-foot {
    display: block !important; margin-top: 6mm; padding-top: 2mm; border-top: 0.5pt solid #999;
    font-size: 8.5pt; color: #444;
  }
}

/* Печать двух режимов: скрытая mode-panel никогда не раскрывается правилами
   вкладок результата. Листовой SVG и таблица печатаются только в sheet-mode. */
@media print {
  body[data-cut-mode="linear"] #sheetModePanel,
  body[data-cut-mode="sheet"] #linearModePanel { display: none !important; }

  body[data-cut-mode="sheet"] #sheetModePanel {
    display: block !important;
    margin: 0 !important;
  }
  body[data-cut-mode="sheet"] #sheetModePanel > .notice,
  body[data-cut-mode="sheet"] .sheet-mode-head,
  body[data-cut-mode="sheet"] .sheet-work-step,
  body[data-cut-mode="sheet"] .sheet-run-row,
  body[data-cut-mode="sheet"] .sheet-input-error,
  body[data-cut-mode="sheet"] .sheet-map-nav { display: none !important; }

  body[data-cut-mode="sheet"] .sheet-map-stage,
  body[data-cut-mode="sheet"] .sheet-piece-key-wrap,
  body[data-cut-mode="sheet"] .sheet-result-table-wrap,
  body[data-cut-mode="sheet"] .sheet-remnants,
  body[data-cut-mode="sheet"] .sheet-map-legend { display: none !important; }

  body[data-cut-mode="sheet"] .sheet-print-layouts { display: block !important; }
  body[data-cut-mode="sheet"] .sheet-print-layout {
    display: block !important;
    break-after: page;
    page-break-after: always;
  }
  body[data-cut-mode="sheet"] .sheet-print-layout:last-child {
    break-after: auto;
    page-break-after: auto;
  }
  body[data-cut-mode="sheet"] .sheet-print-title { margin: 0 0 1mm; font-size: 14pt; }
  body[data-cut-mode="sheet"] .sheet-print-size { margin: 0 0 3mm; color: #333; }
  body[data-cut-mode="sheet"] .sheet-print-map { break-inside: avoid; page-break-inside: avoid; }
  body[data-cut-mode="sheet"] .sheet-print-layout .sheet-map-svg {
    width: 100% !important;
    height: auto !important;
    max-width: 190mm !important;
    max-height: 120mm !important;
    margin: 0 auto 4mm !important;
    filter: none !important;
  }

  body[data-cut-mode="sheet"] .sheet-result {
    display: block !important;
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
  }
  .sheet-result-lead,
  .sheet-kpis { break-inside: avoid; }
  .sheet-kpis { grid-template-columns: repeat(4, 1fr) !important; }
  .sheet-map-stage {
    min-height: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    border: 0 !important;
    background: #fff !important;
    break-inside: avoid;
  }
  .sheet-map-svg { filter: none !important; }
  .sheet-map-stock { fill: #eee !important; stroke: #000 !important; }
  .sheet-map-free { fill: #fff !important; stroke: #777 !important; }
  .sheet-map-piece rect { fill: #ccc !important; stroke: #111 !important; }
  .sheet-map-piece text { fill: #000 !important; }
  .sheet-result-table { font-size: 9pt !important; }
  .sheet-result-table thead { display: table-header-group; }
  .sheet-result-table tr { break-inside: avoid; }
}

/* На экране служебные блоки печати скрыты. */
.print-head, .print-foot { display: none; }
