/* A4 와이드(가로) 인쇄 전용 스타일
   화면에서는 #print-root 가 숨겨져 있고, 인쇄할 때만 나타납니다. */

#print-root { display: none; }

@media print {
  @page {
    size: A4 landscape;   /* 297mm × 210mm */
    margin: 10mm 10mm 12mm;
  }

  html, body {
    background: #fff !important;
    color: #000;
    font-size: 9.5pt;
    line-height: 1.35;
  }

  /* 화면 UI는 전부 숨김 */
  .app, .topbar, .tabbar, .sheet-bg, .toast, main { display: none !important; }

  #print-root {
    display: block !important;
    width: 100%;
    font-family: "Pretendard Variable", Pretendard, "Malgun Gothic", sans-serif;
  }

  /* ── 문서 머리글 ─────────────────────────────── */
  .p-head {
    display: flex;
    align-items: flex-end;
    border-bottom: 2.2pt solid #000;
    padding-bottom: 4pt;
    margin-bottom: 8pt;
  }
  .p-head h1 {
    margin: 0;
    font-size: 16pt;
    font-weight: 800;
    letter-spacing: -0.5pt;
  }
  .p-head .co { font-size: 9pt; margin-left: 8pt; color: #333; }
  .p-head .meta {
    margin-left: auto;
    text-align: right;
    font-size: 8.5pt;
    color: #333;
    line-height: 1.5;
  }

  /* ── 대장 표 ─────────────────────────────────── */
  table.p-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
  }
  table.p-table th,
  table.p-table td {
    border: 0.6pt solid #666;
    padding: 3.2pt 4pt;
    vertical-align: top;
    word-break: break-all;
    overflow-wrap: anywhere;
  }
  table.p-table thead th {
    background: #e8ebea !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    font-size: 8.8pt;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
  }
  table.p-table thead { display: table-header-group; }  /* 페이지마다 머리행 반복 */
  table.p-table tr { page-break-inside: avoid; }
  table.p-table td.c { text-align: center; white-space: nowrap; }
  table.p-table td.type {
    text-align: center;
    font-size: 8.2pt;
    line-height: 1.25;
    word-break: keep-all;
  }
  table.p-table td.num {
    text-align: center;
    font-family: Consolas, monospace;
    font-size: 7.4pt;
    letter-spacing: -0.2pt;
    white-space: nowrap;
    line-height: 1.3;
  }
  table.p-table td.txt { font-size: 8.6pt; }
  table.p-table td.fac { font-size: 8.4pt; font-weight: 600; }
  table.p-table td.open { font-weight: 700; }

  /* 열 너비 (합계 100%) */
  .w-no    { width: 9.5%; }
  .w-date  { width: 6.5%; }
  .w-fac   { width: 9.5%; }
  .w-mgr   { width: 4.5%; }
  .w-tel   { width: 7.5%; }
  .w-rcv   { width: 4.5%; }
  .w-type  { width: 8.5%; }
  .w-body  { width: 20.5%; }
  .w-act   { width: 18%; }
  .w-stat  { width: 4.5%; }
  .w-done  { width: 6.5%; }

  /* ── 요약 줄 ─────────────────────────────────── */
  .p-sum {
    display: flex;
    gap: 14pt;
    font-size: 9pt;
    margin: 0 0 6pt;
    padding: 4pt 6pt;
    background: #f2f4f3 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    border: 0.6pt solid #999;
  }
  .p-sum b { font-weight: 800; }

  /* ── 개별 보고서 ─────────────────────────────── */
  .p-report { page-break-after: always; }
  .p-report:last-child { page-break-after: auto; }

  table.p-form {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
  }
  table.p-form th,
  table.p-form td {
    border: 0.6pt solid #666;
    padding: 5pt 7pt;
    vertical-align: top;
    font-size: 10pt;
  }
  table.p-form td.type-cell { word-break: keep-all; font-size: 9pt; line-height: 1.35; }
  table.p-form td.mealcell {
    font-size: 8.8pt; line-height: 1.5; padding: 4pt 7pt;
  }
  table.p-form td.mealcell span {
    display: inline-block; margin-right: 12pt; white-space: nowrap;
  }
  table.p-form td.mealcell b { font-weight: 800; margin-right: 3pt; }
  table.p-form td.mealcell i {
    font-style: normal; font-family: Consolas, monospace;
    font-size: 8pt; color: #444; margin-left: 3pt;
  }
  table.p-form td.mealcell span.asof {
    display: block; margin-top: 2pt; font-size: 8pt; color: #666;
  }
  table.p-form th {
    background: #e8ebea !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    width: 11%;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
  }
  table.p-form td.long { white-space: pre-wrap; }
  table.p-form td.long .none { display: block; margin-top: 3pt; color: #888; font-size: 8.5pt; }
  table.p-form td.body-cell { height: 26mm; }
  table.p-form td.act-cell { height: 24mm; }

  .p-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 4pt;
    margin-top: 3pt;
  }
  .p-photos img {
    height: 34mm;
    max-width: 46mm;
    object-fit: cover;
    border: 0.6pt solid #999;
  }

  .p-sign {
    margin-top: 7pt;
    display: flex;
    justify-content: flex-end;
    gap: 0;
    font-size: 9pt;
  }
  .p-sign .cell {
    border: 0.6pt solid #666;
    width: 26mm;
    text-align: center;
  }
  .p-sign .cell .t {
    background: #e8ebea !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    border-bottom: 0.6pt solid #666;
    padding: 2.5pt 0;
    font-weight: 700;
  }
  .p-sign .cell .s { height: 15mm; }

  .p-foot {
    margin-top: 6pt;
    padding-top: 3pt;
    border-top: 0.6pt solid #999;
    font-size: 8pt;
    color: #444;
    display: flex;
  }
  .p-foot .r { margin-left: auto; }

  /* ── 주간 시설 리포트 ────────────────────────── */
  .p-week { page-break-after: always; }
  .p-week:last-child { page-break-after: auto; }

  table.p-facbox {
    width: 100%; border-collapse: collapse; table-layout: fixed; margin-bottom: 5pt;
  }
  table.p-facbox th, table.p-facbox td {
    border: 0.6pt solid #666; padding: 4pt 6pt; font-size: 9pt; vertical-align: middle;
  }
  table.p-facbox th {
    background: #e8ebea !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
    width: 7.5%; font-weight: 700; text-align: center; white-space: nowrap;
  }
  table.p-facbox td.nm { font-weight: 800; font-size: 10.5pt; }
  table.p-facbox td.c { text-align: center; white-space: nowrap; }

  table.p-weektbl {
    width: 100%; border-collapse: collapse; table-layout: fixed;
  }
  table.p-weektbl th, table.p-weektbl td {
    border: 0.6pt solid #666; padding: 3pt 4pt;
    font-size: 8.6pt; vertical-align: top; word-break: break-all; overflow-wrap: anywhere;
  }
  table.p-weektbl thead th {
    background: #e8ebea !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
    text-align: center; font-weight: 700; font-size: 8.8pt; vertical-align: middle;
  }
  table.p-weektbl thead th.sub { font-size: 8pt; font-weight: 600; }
  table.p-weektbl thead { display: table-header-group; }
  table.p-weektbl tr { page-break-inside: avoid; }
  table.p-weektbl td.c { text-align: center; white-space: nowrap; }
  table.p-weektbl td.ty { font-size: 8pt; font-weight: 600; word-break: keep-all; }
  table.p-weektbl td.ct { font-size: 8.4pt; line-height: 1.4; }
  table.p-weektbl td.mark { font-weight: 800; font-size: 11pt; }
  table.p-weektbl tr.empty-day td { height: 7mm; }
  table.p-weektbl td.ct span.ad { display: block; line-height: 1.35; }
  table.p-weektbl td.ct span.ad + span.ad { margin-top: 1.5pt; }

  /* ── 통계 보고서 ─────────────────────────────── */
  .p-kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5pt;
    margin-bottom: 8pt;
  }
  .p-kpi {
    border: 0.6pt solid #666;
    padding: 6pt 8pt;
  }
  .p-kpi .n {
    font-family: Consolas, monospace;
    font-size: 19pt;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.5pt;
  }
  .p-kpi .l { font-size: 8.5pt; color: #333; margin-top: 1pt; }
  .p-kpi.warn .n { color: #B5341F; }

  .p-cols {
    display: grid;
    grid-template-columns: 1.1fr 1.1fr 1fr;
    gap: 8pt;
    align-items: start;
  }
  .p-block { break-inside: avoid; page-break-inside: avoid; }
  .p-block h2 {
    margin: 0 0 3pt;
    font-size: 9.5pt;
    font-weight: 800;
    padding-bottom: 2pt;
    border-bottom: 1.2pt solid #000;
  }
  table.p-stat {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
  }
  table.p-stat td {
    border-bottom: 0.5pt solid #bbb;
    padding: 3pt 2pt;
    font-size: 8.6pt;
    vertical-align: middle;
  }
  table.p-stat td.nm { width: 36%; font-weight: 600; word-break: keep-all; }
  table.p-stat td.gr { width: 36%; padding-right: 5pt; }
  table.p-stat td.vl {
    width: 28%;
    text-align: right;
    font-family: Consolas, monospace;
    font-size: 8.2pt;
    letter-spacing: -0.2pt;
    white-space: nowrap;
  }
  .p-track {
    height: 6pt;
    background: #e6e9e8 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .p-fill {
    height: 6pt;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .p-empty { font-size: 8.5pt; color: #666; padding: 4pt 0; }
  table.p-stat td.wkc {
    width: 34%; font-family: Consolas, monospace;
    font-size: 7.6pt; letter-spacing: -0.3pt; white-space: nowrap; font-weight: 600;
  }
  table.p-stat td.cs {
    width: 72%; font-size: 8.2pt; font-weight: 500;
    line-height: 1.3; word-break: keep-all;
  }

  .p-open { margin-top: 9pt; }
  .p-open h2 { break-after: avoid; page-break-after: avoid; }
  .p-open h2 {
    margin: 0 0 3pt; font-size: 9.5pt; font-weight: 800;
    padding-bottom: 2pt; border-bottom: 1.2pt solid #000;
  }
  .p-open h2 span { font-weight: 600; font-size: 8.5pt; color: #444; margin-left: 5pt; }
}
