/* ===== 高品質PDF / 印刷用スタイル ===== */
/* window.print() で帳票部分だけをベクター描画で出力する */

@media print {
  /* ----- 1) UI要素をすべて非表示 ----- */
  nav,
  .toolbar,
  .controls-area,
  .col-lg-3 > .d-none,
  #toast-container,
  .modal,
  .modal-backdrop,
  #firstRunNotice,
  #backupModalContainer,
  .help-menu,
  .report-wrapper > .toolbar,
  .example-panel-mobile,
  .flatpickr-calendar,
  .page-background,
  .page-boundary {
    display: none !important;
  }

  /* ----- 2) pdf-mode と同等: 操作系UI非表示 ----- */
  .action-cell,
  .action-col,
  .add-row-wrapper,
  .deleteRowButton,
  #addRowButton,
  .btn-add,
  .date-clear-btn,
  .delete-table-wrapper,
  .add-table-wrapper,
  .deleteTableButton,
  #addTableButton,
  .logo-remove-btn {
    display: none !important;
  }

  /* ----- 3) body / レイアウトリセット ----- */
  html, body {
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    background: white !important;
  }

  .container-fluid {
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
    overflow: visible !important;
  }

  .container-fluid.mt-5 {
    margin-top: 0 !important;
  }

  .row {
    margin: 0 !important;
  }

  .col-lg-9 {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
  }

  /* サイドバーを完全非表示 */
  .col-lg-3 {
    display: none !important;
  }

  .report-wrapper {
    padding: 0 !important;
    margin: 0 !important;
  }

  /* ----- 4) viewport / sizer のスケーリング解除 ----- */
  .report-viewport {
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    padding: 0 !important;
    background: white !important;
  }

  .viewport-pad {
    padding: 0 !important;
    min-width: 0 !important;
  }

  .report-sizer {
    transform: none !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  .report-stage {
    transform: none !important;
    min-height: 0 !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* ----- 5) 帳票エリア ----- */
  .report-area {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    transform: none !important;
    zoom: 1 !important;
    margin: 0 !important;
    border: none !important;
    box-shadow: none !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  /* ページ幅いっぱいに広げる（親のpaddingは0にリセット済み） */
  .report-area.page-A4,
  .report-area.page-B5,
  .report-area.page-Letter {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* プレースホルダー（入力例）を非表示 */
  .editable[data-placeholder]:empty::before,
  td[data-placeholder]:empty::before {
    display: none !important;
  }

  /* editable 装飾を消す（pdf-mode相当） */
  /* 編集モードは Tailwind リセットで border: 0 のため、none にして幅を揃える */
  .editable:not(.mark-cell):not(.profile):not(.quot-client-name):not(.dlv-client-name):not(.insp-client-name):not(.insp-seal-label):not(.insp-seal-area),
  .editable.selected:not(.quot-client-name):not(.dlv-client-name):not(.insp-client-name) {
    border: none !important;
    background-color: transparent !important;
  }

  /* quot-client-name / dlv-client-name / insp-client-name: border-bottom だけ維持し、他の装飾は消す */
  .editable.quot-client-name,
  .editable.dlv-client-name,
  .editable.insp-client-name {
    border-top: none !important;
    border-left: none !important;
    border-right: none !important;
    background-color: transparent !important;
  }

  /* 検収印欄: 罫線維持 */
  .insp-seal-label {
    border-bottom: 1px solid #000 !important;
    background-color: transparent !important;
  }
  .insp-seal-area {
    background-color: transparent !important;
  }
  .insp-seal-box {
    border: 1px solid #000 !important;
  }

  .editable.mark-cell,
  .editable.profile {
    background-color: transparent !important;
  }

  /* profile の下罫線を維持（空でない場合） */
  .profile:not(.is-empty) {
    border-bottom: 1px solid #333 !important;
  }

  /* 日付入力：印刷時はクリアボタン非表示のためpadding/min-width調整 */
  .date-input {
    padding-right: 0 !important;
    min-width: 0 !important;
  }

  /* pdf-underline のスタイル維持 */
  .pdf-underline {
    padding-bottom: 2px !important;
  }

  /* report-content のオーバーフロー解除 */
  /* display: flow-root で BFC を維持し、子要素の margin collapse を防止
     （padding-top ではなく flow-root を使うことでレイアウトへの影響を回避） */
  .report-content {
    overflow: visible !important;
    max-height: none !important;
    height: auto !important;
    display: flow-root !important;
  }

  /* cont-left を透過（flex コンテナはページ分割されにくいため、
     cont がページ境界をわずかに超えると cont 全体が次ページに移動してしまう問題の修正）
     display:contents で wrapper を消し、#cont を親のブロックフローに直接置く */
  .cont-left {
    display: contents !important;
  }

  /* ----- 6) thead のページ繰り返しを抑制 ----- */
  thead {
    display: table-row-group;
  }

  /* ----- 7) 余白の原因となる全要素の高さ制御 ----- */
  .markWrapper {
    margin-top: 30px !important;
  }

  .tbl-space + .memo-space {
    margin-top: 20px !important;
  }

  /* workTable のヘッダーに border-top を追加（隣接テーブルの border-bottom が消える問題の補完） */
  #workTable th {
    border-top: 1px solid #000;
  }
}

/* ===== print-mode クラス（JS付与時にも適用） ===== */
/* afterprint で確実にクラス除去するため、@media print 外にも定義 */
html.print-mode body > *:not(script):not(style):not(link) {
  display: none !important;
}

html.print-mode body > .container-fluid,
html.print-mode .container-fluid {
  display: block !important;
}

html.print-mode .container-fluid > .row {
  display: flex !important;
}

html.print-mode .col-lg-9 {
  display: block !important;
}

html.print-mode .report-wrapper {
  display: block !important;
}

html.print-mode .report-viewport {
  display: block !important;
}

html.print-mode .viewport-pad {
  display: block !important;
}

html.print-mode .report-sizer {
  display: block !important;
}

html.print-mode .report-stage {
  display: block !important;
}

html.print-mode .report-area {
  display: block !important;
}

html.print-mode .report-content {
  display: flow-root !important;
}
