/* ============================================================
   print.css - 帳票 3種（個別支援計画書、モニタリング報告書、来館児童の目標）
   sample.html ベースの A4 レイアウト
   ============================================================ */

/*
 * Outside the cascade layers on purpose (see tokens.css): these rules beat every screen rule, so the forms keep
 * their look. Change them only when a form is meant to look different (docs/design.md 2.7).
 */

/* ============ 帳票共通: 書体と文字色の固定 ============ */

/* The screen font and colours changed in M4; the printed forms keep the fonts and colours they had before. */
.print-sheet h1,
.monitoring-sheet-title,
.daily-goals-sheet :is(h1, h2) {
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
}
.monitoring-sheet .score-unselected {
  color: #7a7268;
}

/* ============ 個別支援計画書 ============ */

/* ============ A4シートラッパー（画面プレビュー） ============ */

.print-page-wrapper {
  background: #d0d0d0;
  min-height: calc(100vh - 52px);
  padding: 24px 16px 40px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* ============ A4シート本体（sample.html の body スタイルを移植） ============ */

.print-sheet {
  background: #fff;
  /* A4横: 297mm × 210mm、画面では等倍で表示 */
  width: 297mm;
  min-height: 210mm;
  box-sizing: border-box;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);

  /* sample.html の body スタイルをそのまま適用 */
  font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  font-size: 9.5px;
  line-height: 1.3;
  color: #000;
  padding: 10mm;
}

/* ============ sample.html の内部スタイルをそのまま移植 ============ */

.print-sheet * {
  box-sizing: border-box;
}

.print-sheet h1 {
  font-size: 16px;
  text-align: center;
  margin: 0 0 12px 0;
  letter-spacing: 2px;
}

.print-sheet table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
  table-layout: fixed;
}

/* 支援内容テーブル（#ph-support-tbody の親）は文字を小さめに固定 */
.print-sheet #ph-support-tbody td {
  font-size: 8.5px;
  line-height: 1.2;
  word-break: break-all;
  overflow-wrap: anywhere;
  vertical-align: top;
}

.print-sheet th,
.print-sheet td {
  border: 1px solid #000;
  padding: 2px 6px;
  vertical-align: middle;
  word-wrap: break-word;
}

.print-sheet th {
  background-color: #f2f2f2;
  font-weight: normal;
  text-align: center;
}

.print-sheet td {
  text-align: left;
}

.print-sheet .diagonal-line {
  position: relative;
  padding: 0;
}

.print-sheet .diagonal-line-inner {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.print-sheet .ps-item-label {
  vertical-align: middle;
  min-height: 28px;
}

.print-sheet .signature-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
  margin-top: 4px;
}

.print-sheet .signature-left {
  width: 40%;
}

.print-sheet .signature-right {
  width: 59%;
  border: 1px solid #000;
  padding: 8px 10px;
  min-height: 60px;
}

/* ============ contenteditable 編集スタイル ============ */

.print-sheet [contenteditable="true"] {
  outline: 2px solid #4A9078;
  outline-offset: -2px;
  cursor: text;
  background-color: #FAFFF8;
}

.print-sheet [contenteditable="true"]:focus {
  outline: 2px solid #2A7058;
  background-color: #F0FFF8;
}

/* 編集ヒントツールチップ */
.print-sheet [contenteditable="true"]:hover::after {
  content: "クリックして編集";
  position: absolute;
  font-size: 9px;
  background: #2A7058;
  color: #fff;
  padding: 2px 6px;
  border-radius: 3px;
  pointer-events: none;
  white-space: nowrap;
  margin-top: -2px;
}

/* ============ 印刷時スタイル ============ */

@media print {
  /* 画面用要素をすべて非表示 */
  .no-print,
  .global-nav,
  .page-footer,
  .toast {
    display: none !important;
  }

  /* SPAの他ページを非表示、printページのみ表示 */
  .spa-page { display: none !important; }
  body:not(.printing-monitoring):not(.printing-daily-goals) #page-print { display: block !important; }

  body {
    background: white;
    margin: 0;
    padding: 0;
  }

  .print-page-wrapper {
    background: white;
    padding: 0;
    display: block;
  }

  /* 印刷時は sample.html の @media print に完全準拠 */
  .print-sheet {
    width: 100%;
    min-height: auto;
    box-shadow: none;
    padding: 12mm 10mm 5mm 10mm;
    font-size: 9px; /* 画面より少し小さくしてA4横1枚に収める */
  }

  /* テーブル全体の改ページ回避 */
  .print-sheet table {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* 行レベルでも分断を防ぐ */
  .print-sheet tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* 支援内容テーブルは内容が長くなりやすいため行ごとに制御 */
  #ph-support-tbody tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* セル内テキストの折り返し強制 */
  .print-sheet td,
  .print-sheet th {
    word-break: break-all;
    overflow-wrap: anywhere;
  }

  .print-sheet th {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* contenteditable の枠線は印刷しない */
  .print-sheet [contenteditable="true"],
  .print-sheet [contenteditable="true"]:focus {
    outline: none !important;
    background-color: transparent !important;
  }

  @page {
    size: A4 landscape;
    margin: 0;
  }
}

/* ============================================================
   モニタリング報告書 印刷レイアウト（A4横・計画書と同形式）
   ============================================================ */

/* ============ 来館児童の目標（A4横、複数人） ============ */

/* Screen preview: the sheet on a grey desk at A4 landscape size, like the other two forms. */
.daily-goals-wrapper {
  background: #d0d0d0;
  min-height: calc(100vh - 52px);
  padding: 24px 16px 40px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* Same sheet, title, lines and type sizes as the plan form (.print-sheet), so the three forms read as one set. */
.daily-goals-sheet {
  background: #fff;
  width: 297mm;
  min-height: 210mm;
  box-sizing: border-box;
  padding: 10mm;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
  font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  font-size: 9.5px;
  line-height: 1.3;
  color: #000;
}

.daily-goals-head {
  position: relative;
  margin: 0 0 12px;
}

.daily-goals-title {
  margin: 0;
  font-size: 16px;
  text-align: center;
  letter-spacing: 2px;
}

.daily-goals-head p {
  position: absolute;
  inset-block-end: 0;
  inset-inline-end: 0;
  margin: 0;
}

.daily-goals-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.daily-goals-name-col { width: 16%; }

.daily-goals-table :is(th, td) {
  border: 1px solid #000;
  padding: 2px 6px;
  vertical-align: top;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.daily-goals-table thead th {
  background-color: #f2f2f2;
  font-weight: normal;
  text-align: center;
  vertical-align: middle;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* The name is a value like the plan form's 利用者氏名 cell, centred and not bold. */
.daily-goals-table tbody th {
  font-weight: normal;
  text-align: center;
}

.daily-goals-none { color: #7a7268; }

@page daily-goals {
  size: A4 landscape;
  margin: 10mm;
}

@media print {
  body.printing-daily-goals .spa-page { display: none !important; }
  body.printing-daily-goals #page-daily-goals {
    display: block !important;
    page: daily-goals;
  }
  body.printing-daily-goals .daily-goals-wrapper {
    background: white;
    min-height: auto;
    padding: 0;
    display: block;
  }
  body.printing-daily-goals .daily-goals-sheet {
    width: auto;
    min-height: auto;
    padding: 0;
    box-shadow: none;
  }
  .daily-goals-table thead { display: table-header-group; }
  .daily-goals-table tr { break-inside: avoid; }
}

/* ============ A4横ラッパー（画面プレビュー） ============ */

.monitoring-print-wrapper {
  background: #d0d0d0;
  min-height: calc(100vh - 52px);
  padding: 24px 16px 40px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* ============ A4横シート本体（計画書 .print-sheet と同等） ============ */

.monitoring-sheet {
  background: #fff;
  /* A4横: 297mm × 210mm */
  width: 297mm;
  min-height: 210mm;
  box-sizing: border-box;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);

  font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  font-size: 9px;
  line-height: 1.3;
  color: #000;
  padding: 8mm 10mm 6mm;
}

.monitoring-sheet * {
  box-sizing: border-box;
}

/* ============ タイトル ============ */

.monitoring-sheet-title {
  font-size: 14px;
  text-align: center;
  margin: 0 0 6px;
  letter-spacing: 2px;
  font-weight: bold;
}

/* ============ テーブル共通（.m-table） ============ */

.monitoring-sheet .m-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 5px;
  table-layout: fixed;
}

.monitoring-sheet .m-table th,
.monitoring-sheet .m-table td {
  border: 1px solid #000;
  padding: 2px 5px;
  vertical-align: middle;
  word-wrap: break-word;
  word-break: break-all;
  font-size: 8.5px;
  line-height: 1.3;
}

.monitoring-sheet .m-table th {
  background-color: #f2f2f2;
  font-weight: normal;
  text-align: center;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.monitoring-sheet .m-table td {
  text-align: left;
  vertical-align: top;
}

/* 達成状況スコア列：中央寄せ */
.monitoring-sheet .m-table td.score-cell {
  text-align: center;
  vertical-align: middle;
  font-size: 8px;
  line-height: 1.6;
}

/* スコア強調（選択値） */
.monitoring-sheet .m-table td strong {
  font-size: 9.5px;
  font-weight: bold;
}

/* 中央寄せユーティリティ */
.monitoring-sheet .text-center {
  text-align: center !important;
}

/* 達成状況 丸数字横並び（monitoring.html準拠） */
.monitoring-sheet .score-container {
  text-align: center;
  line-height: 1.5;
  vertical-align: middle;
}

.monitoring-sheet .score-list {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  margin-bottom: 2px;
  font-size: 8px;
}

.monitoring-sheet .score-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  box-sizing: border-box;
}

.monitoring-sheet .score-num.circled {
  border: 1px solid #000;
  border-radius: 50%;
  font-weight: bold;
}

/* ============ 印刷時スタイル ============ */

@media print {
  body.printing-monitoring .spa-page { display: none !important; }
  body.printing-monitoring #page-monitoring-print { display: block !important; }

  body.printing-monitoring .monitoring-print-wrapper {
    background: white;
    padding: 0;
    display: block;
  }

  body.printing-monitoring .monitoring-sheet {
    width: 100%;
    min-height: auto;
    box-shadow: none;
    padding: 10mm 10mm 5mm;
    font-size: 9px;
  }

  body.printing-monitoring .monitoring-sheet th {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* テーブル・行の途中改ページ禁止 */
  body.printing-monitoring .monitoring-sheet .m-table {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  body.printing-monitoring .monitoring-sheet tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  body.printing-monitoring .no-print { display: none !important; }
  body.printing-monitoring .global-nav { display: none !important; }
  body.printing-monitoring .page-footer { display: none !important; }

  /* A4横 — JSで <style id="monitoring-print-page-rule"> を動的挿入 */
  body.printing-monitoring {
    background: white;
    margin: 0;
    padding: 0;
  }
}
