/* 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.8pt;
    color: #C01A1A;
    font-weight: 700;
    line-height: 1.5;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .p-head .meta b { color: #C01A1A; }

  /* ── 대장 표 ─────────────────────────────────── */
  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.res { font-weight: 700; margin-top: 2pt; }
  table.p-routetbl td.fac {
    font-weight: 800; font-size: 9pt; word-break: keep-all; vertical-align: middle;
  }
  table.p-routetbl td.num { font-family: Consolas, monospace; font-size: 8pt; }
  table.p-routetbl tr.quiet td { color: #888; font-size: 8pt; }
  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-trend { margin-bottom: 8pt; }
  .p-trend-head {
    display: flex; align-items: baseline; gap: 8pt;
    border-bottom: 1.2pt solid #000; padding-bottom: 2.5pt; margin-bottom: 5pt;
  }
  .p-trend-head b { font-size: 10.5pt; font-weight: 800; }
  .p-trend-head span { font-size: 8.5pt; color: #444; }
  .p-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 10pt; }
  .p-chart { break-inside: avoid; }
  .p-chart .chart-head { display: flex; flex-wrap: wrap; gap: 3pt 8pt; padding-bottom: 3pt; }
  .p-chart .chart-head b { font-size: 9pt; font-weight: 800; }
  .p-chart .chart-head .legend { display: flex; gap: 7pt; margin-left: auto; }
  .p-chart .chart-head .lg {
    display: inline-flex; align-items: center; gap: 3pt; font-size: 7.6pt; font-weight: 700; color: #333;
  }
  .p-chart .chart-head .lg i {
    width: 7pt; height: 7pt; border-radius: 2pt; display: inline-block;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .p-chart .chart { width: 100%; height: auto; }
  .p-chart .chart .g { stroke: #ccc; stroke-width: 1; }
  .p-chart .chart .ax { font-size: 8px; fill: #666; }
  .p-chart .chart .val { font-size: 10px; font-weight: 800; }

  /* 민원 유형별 건수·증감 표 */
  table.p-ttbl { width: 100%; border-collapse: collapse; margin-top: 3pt; }
  .p-ttbl tr { break-inside: avoid; page-break-inside: avoid; }
  .p-tthead {
    display: flex; align-items: baseline; gap: 8pt;
    margin-top: 8pt; padding-bottom: 2pt; border-bottom: 1pt solid #16211C;
  }
  .p-tthead b { font-size: 10pt; font-weight: 800; }
  .p-tthead span { font-size: 8pt; color: #444; }
  .p-ttbl th, .p-ttbl td {
    border: .5pt solid #b9c2c0; padding: 2.6pt 3pt;
    text-align: center; font-size: 8.2pt; line-height: 1.25;
  }
  .p-ttbl thead th { background: #e8edeb; font-weight: 800; font-size: 8pt; }
  .p-ttbl thead th.now { background: #d6e5df; }
  .p-ttbl thead th em { display: block; font-style: normal; font-size: 6.6pt; font-weight: 600; color: #777; }
  .p-ttbl td.ty, .p-ttbl th.ty { text-align: left; font-weight: 600; width: 15%; }
  .p-ttbl td.ty i {
    display: inline-block; width: 5pt; height: 5pt; border-radius: 1pt;
    margin-right: 3pt; vertical-align: .5pt;
  }
  .p-ttbl td.tv { font-family: var(--mono, monospace); }
  .p-ttbl td.tv.u { background: #f7e7e2; color: #A0301B; font-weight: 800; }
  .p-ttbl td.tv.d { background: #e6efec; color: #17544A; font-weight: 800; }
  .p-ttbl td.sm, .p-ttbl th.sm { background: #f2f5f4; font-weight: 800; }
  .p-ttbl th.df, .p-ttbl td.df { width: 9%; }
  .p-ttbl tr.tot td { background: #eef2f0; font-weight: 800; border-top: 1pt solid #16211C; }
  .p-ttbl .tup { color: #A0301B; font-weight: 800; }
  .p-ttbl .tdn { color: #17544A; font-weight: 800; }
  .p-ttbl .tsm { color: #888; }
  .p-ttfoot { font-size: 7.6pt; color: #555; padding-top: 2.5pt; }

  .p-cols {
    display: grid;
    grid-template-columns: 1.1fr 1.1fr 1fr;
    gap: 8pt;
    align-items: start;
  }
  .p-block { break-inside: auto; }
  .p-block h2 { break-after: avoid; page-break-after: avoid; }
  table.p-stat tr { 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; }

  /* ── 담당 배송기사별 민원 (보고서 맨 아래) ────────── */
  .p-drv { margin-top: 10pt; break-inside: auto; }
  .p-drv h2 {
    margin: 0 0 3pt; font-size: 9.5pt; font-weight: 800;
    padding-bottom: 2pt; border-bottom: 1.2pt solid #000;
    break-after: avoid; page-break-after: avoid;
  }
  .p-drv h2 span { font-weight: 600; font-size: 8.5pt; color: #444; margin-left: 5pt; }
  .p-drvtbl tr { break-inside: avoid; page-break-inside: avoid; }
  .p-drvtbl td b { font-weight: 800; }
  .p-drvtbl td i { font-style: normal; font-size: 7.6pt; color: #555; }
  .p-drvtbl .tylist { line-height: 1.5; }
  .p-drvtbl .tylist span {
    display: inline-block; border: 0.5pt solid #b9c2c0; border-radius: 2pt;
    padding: 0.5pt 3.5pt; margin: 0 3pt 1.5pt 0; font-size: 8pt;
  }
  .p-drvtbl .tylist span.none { border: 0; }
  .p-drvtbl .sumrow td {
    background: #eef2f0; font-weight: 800; border-top: 1pt solid #000;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}

@media print {
  /* ─── 일일보고 (민원 퇴치 100일작전) ────────────── */
  .p-daily .p-head h1 .sub {
    font-size: 11pt; font-weight: 700; color: #444; margin-left: 8pt;
    padding-left: 8pt; border-left: 1pt solid #999;
  }

  .p-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5pt; margin-bottom: 7pt; }
  .p-kpis .k {
    border: 0.8pt solid #666; border-radius: 2pt; padding: 4pt 8pt;
    display: flex; align-items: baseline; gap: 6pt;
  }
  .p-kpis .k b { font-size: 15pt; font-weight: 800; }
  .p-kpis .k span { font-size: 8.5pt; color: #444; }
  .p-kpis .k.warn b { color: #B3311B; }

  table.p-dtbl {
    width: 100%; border-collapse: collapse; table-layout: fixed; margin-bottom: 9pt;
  }
  table.p-dtbl th, table.p-dtbl td {
    border: 0.6pt solid #666; padding: 3.5pt 4pt; font-size: 9pt; vertical-align: middle;
  }
  table.p-dtbl thead th {
    background: #e8ebea !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
    text-align: center; font-weight: 700; font-size: 9pt;
  }
  table.p-dtbl td.c { text-align: center; }
  table.p-dtbl td.dt { font-family: Consolas, monospace; font-size: 8.6pt; white-space: nowrap; }
  table.p-dtbl td.n { font-family: Consolas, monospace; color: #999; }
  table.p-dtbl td.n.hit { color: #000; font-weight: 800; font-size: 9.6pt; }
  table.p-dtbl td.sum { font-weight: 800; background: #f4f6f5 !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.p-dtbl tr.wk td { background: #fafafa !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.p-dtbl tr.zero td { color: #aaa; }
  table.p-dtbl tr.tot td {
    background: #e8ebea !important; font-weight: 800;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  table.p-dtbl tr.tot td.n { color: #000; }

  .p-notehead {
    display: flex; align-items: baseline; gap: 8pt;
    font-size: 10.5pt; font-weight: 800;
    border-bottom: 1.2pt solid #000; padding-bottom: 2.5pt; margin-bottom: 5pt;
  }
  .p-notehead span { font-size: 8.5pt; font-weight: 500; color: #444; margin-left: auto; }

  table.p-ntbl { width: 100%; border-collapse: collapse; table-layout: fixed; }
  table.p-ntbl th, table.p-ntbl 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-ntbl thead th {
    background: #e8ebea !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
    text-align: center; font-weight: 700; vertical-align: middle;
  }
  table.p-ntbl thead { display: table-header-group; }
  table.p-ntbl tr { page-break-inside: avoid; break-inside: avoid; }
  table.p-ntbl td.c { text-align: center; }
  table.p-ntbl td.no { font-family: Consolas, monospace; color: #666; }
  table.p-ntbl td.dt { font-family: Consolas, monospace; font-size: 8.2pt; white-space: nowrap; }
  table.p-ntbl td.dt i { font-style: normal; color: #666; font-size: 7.6pt; }
  table.p-ntbl td.fac { font-weight: 800; word-break: keep-all; }
  table.p-ntbl td.ty { font-size: 8.2pt; font-weight: 600; word-break: keep-all; }
  table.p-ntbl td.ty b.urg {
    display: inline-block; background: #B3311B !important; color: #fff;
    font-size: 7.4pt; padding: 0.5pt 3.5pt; border-radius: 2pt; margin-left: 3pt;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  table.p-ntbl td.ct { line-height: 1.4; }
  table.p-ntbl td.st { font-size: 8.2pt; font-weight: 700; word-break: keep-all; }
  table.p-ntbl td.empty { color: #888; padding: 10pt 0; }

  .p-sign { margin-top: 8pt; display: flex; justify-content: flex-end; }
  .p-sign table { border-collapse: collapse; }
  .p-sign th, .p-sign td { border: 0.6pt solid #666; font-size: 8.6pt; text-align: center; }
  .p-sign th {
    background: #e8ebea !important; padding: 3pt 8pt; font-weight: 700;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .p-sign td { width: 62pt; height: 30pt; }
}

@media print {
  /* ─── A4 세로로 뽑을 때 (일일보고) ─────────────── */
  #print-root.portrait .p-head h1 { font-size: 14pt; }
  #print-root.portrait .p-head h1 .sub { font-size: 10pt; }
  #print-root.portrait .p-head .meta { font-size: 7.8pt; }
  #print-root.portrait .p-kpis .k { padding: 3pt 6pt; }
  #print-root.portrait .p-kpis .k b { font-size: 13pt; }
  #print-root.portrait table.p-dtbl th,
  #print-root.portrait table.p-dtbl td { font-size: 8.4pt; padding: 3pt 2.5pt; }
  #print-root.portrait table.p-dtbl thead th { font-size: 8pt; word-break: keep-all; line-height: 1.3; }
  #print-root.portrait table.p-ntbl th,
  #print-root.portrait table.p-ntbl td { font-size: 8pt; padding: 2.6pt 3pt; }
  #print-root.portrait table.p-ntbl td.ty { font-size: 7.6pt; }
  #print-root.portrait table.p-ntbl td.st { font-size: 7.6pt; }
  #print-root.portrait .p-sign td { width: 52pt; height: 28pt; }
}
