/*
 * 인쇄 CSS 단일 소스. 클라이언트 뷰어와 서버 조판 HTML 이 이 파일 하나를 `<link>` 로 가리킨다.
 * 경로는 `PRINT_STYLESHEET_HREF` 로만 참조한다.
 */

/* ── 기준선 초기화 ─────────────────────────────────────────────
 * Tailwind preflight 에서 이 문서에 닿는 규칙만 골라 옮긴 것. 클라이언트 뷰어는 preflight
 * 아래에서 돌고 서버 조판 HTML 에는 그게 없어, 없으면 두 경로의 행 높이가 갈린다.
 *
 * 값을 임의로 바꾸지 않는다. 고칠 때는 `node_modules/tailwindcss/preflight.css` 와 대조한다.
 * `:where()` 는 특이도를 0 으로 만들어 아래의 실제 규칙이 언제나 이기게 한다.
 */
:where(.print-preview-root, .print-document) {
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  tab-size: 4;
  font-family: Arial, Helvetica, sans-serif;
}

:where(.print-preview-root, .print-document),
:where(.print-preview-root, .print-document) :where(*, *::before, *::after) {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0 solid;
}

:where(.print-preview-root, .print-document) :where(h1, h2, h3, h4, h5, h6) {
  font-size: inherit;
  font-weight: inherit;
}

:where(.print-preview-root, .print-document) :where(table) {
  text-indent: 0;
  border-color: inherit;
  border-collapse: collapse;
}

:where(.print-preview-root, .print-document) :where(img, svg) {
  display: block;
  vertical-align: middle;
  max-width: 100%;
  height: auto;
}

:where(.print-preview-root, .print-document) :where(button, input, select) {
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
  border-radius: 0;
  background-color: transparent;
  opacity: 1;
}

/* ── 문서 수준 초기화 ───────────────────────────────────────────
 * `body` 는 위 초기화가 닿지 않는 조상이다. 서버 껍데기에는 기본 여백 8px 이 남아 툴바가
 * 잘리고 인쇄에서 용지마다 여백이 더 붙는다. 껍데기가 이 클래스로 규칙을 집어 간다.
 */
.print-viewer-body {
  margin: 0;
}

/* ── 전체 레이아웃 ─────────────────────────────────────────── */
.print-preview-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #6b6b6b;
  overflow: hidden;
}

/* ── 툴바 ──────────────────────────────────────────────────── */
.print-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 5px 16px;
  background: #3c3c3c;
  color: #fff;
  flex-shrink: 0;
  z-index: 10;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.toolbar-actions {
  margin-left: 8px;
  padding-left: 12px;
  border-left: 1px solid #555;
}

/* 허브에서는 DS IconButton 이던 자리 — 여기서는 순수 button */
.toolbar-button {
  color: #fff;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 4px 8px;
  min-width: unset;
  font-size: 13px;
  line-height: 1.4;
  border-radius: 4px;
  cursor: pointer;
}

.toolbar-button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.toolbar-button:disabled {
  color: #666;
  opacity: 1;
  cursor: default;
}

.toolbar-select {
  background: #555;
  border: 1px solid #777;
  color: #fff;
  font-size: 13px;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
}

.page-select {
  min-width: 96px;
  text-align: center;
}

.zoom-select {
  min-width: 80px;
}

/* ── 캔버스 래퍼 ───────────────────────────────────────────── */
.print-canvas-wrapper {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 40px 40px;
}

/* ── 페이지 래퍼 (스크롤 뷰에서 각 페이지 구분) ─────────── */
.print-page-wrapper {
  display: flex;
  justify-content: center;
  padding: 24px 0;
}

.print-loading {
  color: #fff;
  font-size: 14px;
  padding: 48px 0;
}

.print-measure-root {
  position: fixed;
  top: -10000px;
  left: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
}

/* ── 인쇄 문서 ─────────────────────────────────────────────── */
.print-document {
  background: #fff;
  /* 허브 테마(다크모드 포함)를 타지 않도록 문서는 색을 직접 고정한다 */
  color: #000;
  font-family: 'Malgun Gothic', 'Apple SD Gothic Neo', '맑은 고딕', sans-serif;
  /* A4 세로: 794 × 1123px 고정 — 절대 변하지 않음 */
  width: 794px;
  height: 1123px;
  padding: 32px 32px 24px;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* A4 가로: 1123 × 794px 고정 */
.print-document--landscape {
  width: 1123px;
  height: 794px;
}

.print-footer {
  margin-top: auto;
  padding-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  font-size: 10px;
  color: #555;
}

.print-footer-org {
  text-align: left;
}

.print-footer-page {
  text-align: center;
}

.report-title {
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  margin: 0 0 4px;
  letter-spacing: 6px;
}

.print-header-node {
  margin-bottom: 6px;
  font-size: 11px;
  width: 100%;
  box-sizing: border-box;
}

.print-date {
  text-align: right;
  font-size: 10.5px;
  color: #333;
  margin-bottom: 6px;
}

.print-header-node .print-date {
  margin-bottom: 0;
}

/* ── 결재선 ────────────────────────────────────────────────── */
/* 오른쪽 정렬이 관행이라 margin-left:auto 로 민다 */
.approval-table {
  border-collapse: collapse;
  margin: 0 0 6px auto;
  table-layout: fixed;
  font-size: 10px;
}

.approval-label-col {
  width: 22px;
}

.approval-slot-col {
  width: 58px;
}

.approval-table .approval-label {
  border: 1px solid #888;
  background: #f0f0f0;
  text-align: center;
  vertical-align: middle;
  font-weight: bold;
  padding: 2px;
  /* 세로쓰기 — 칸이 좁아 가로로는 들어가지 않는다 */
  writing-mode: vertical-rl;
  letter-spacing: 2px;
}

.approval-table .approval-title {
  border: 1px solid #888;
  background: #f0f0f0;
  text-align: center;
  font-weight: normal;
  padding: 2px 3px;
  height: 16px;
}

.approval-table .approval-slot {
  border: 1px solid #888;
  text-align: center;
  vertical-align: middle;
  /* 도장 자리라 높이를 고정한다 — 칸마다 높이가 달라지면 표가 흔들린다 */
  height: 42px;
  padding: 2px;
}

.approval-stamp {
  display: block;
  margin: 0 auto;
  max-width: 40px;
  max-height: 34px;
  object-fit: contain;
}

.approval-name {
  display: block;
  font-size: 10px;
}

.approval-date {
  display: block;
  font-size: 8px;
  color: #666;
  margin-top: 1px;
}

/* 테이블 컨테이너 — flex:1로 남은 높이 전부 차지, 넘치면 hidden */
.print-body {
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── 테이블 ────────────────────────────────────────────────── */
.print-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  table-layout: fixed;
}

.print-document:not(.print-document--landscape) .print-table {
  width: calc(100% - 2px);
}

.print-table .header-cell {
  background: #f0f0f0;
  border: 1px solid #888;
  padding: 5px 3px;
  text-align: center;
  font-weight: bold;
  /* \n 줄바꿈 지원 */
  white-space: pre-line;
  word-break: keep-all;
  line-height: 1.4;
  vertical-align: middle;
}

.print-table .header-sub-offset {
  background: #f0f0f0;
  border: 1px solid #888;
}

.print-table .data-cell {
  border: 1px solid #bbb;
  padding: 3px 5px;
  vertical-align: middle;
  word-break: break-word;
  white-space: pre-line;
}

.print-table .sub-cell {
  border: 1px solid #bbb;
  border-top: none;
  padding: 2px 8px;
  text-align: left;
  color: #333;
  font-size: 10.5px;
  word-break: break-word;
  white-space: pre-line;
}

.print-table .main-row + .sub-row .sub-cell {
  border-top: none;
}

/* splitKey 셀: 상/하 동일 높이로 분할 */
.print-table .data-cell--split {
  padding: 0 !important;
  height: 1px; /* flex 자식이 height:100% 사용 가능하도록 */
}

.split-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.split-half {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 5px;
  word-break: break-word;
  white-space: pre-line;
  min-height: 18px;
}

.split-half + .split-half {
  border-top: 1px solid #bbb;
}

.print-table .subtotal-row td {
  background: #f5f5f5;
  border: 1px solid #bbb;
  padding: 3px 10px;
  text-align: left;
  font-weight: bold;
  font-size: 11px;
}

@media screen {
  .print-page-wrapper .print-body {
    overflow: visible;
  }
}

/* ── 인쇄 시 스타일 ────────────────────────────────────────── */
@media print {
  /* @page 크기와 방향은 양식마다 달라 여기 두지 않는다. `pageRuleFor` 가 만든다 */

  .print-preview-root {
    background: none;
    height: auto;
    overflow: visible;
  }

  .print-toolbar {
    display: none;
  }

  .print-canvas-wrapper {
    overflow: visible;
    padding: 0;
    display: block;
  }

  /* 인쇄 시 zoom 리셋 */
  .print-canvas-wrapper > div {
    zoom: 1 !important;
  }

  /* 페이지 래퍼: 패딩 제거, 각 페이지마다 페이지 나누기 */
  .print-page-wrapper {
    padding: 0;
    display: block;
    page-break-after: always;
    break-after: always;
  }

  .print-page-wrapper:last-child {
    page-break-after: avoid;
    break-after: avoid;
  }

  /* 인쇄 문서: screen과 동일한 px 유지 → 96dpi 기준 A4 실치수 */
  .print-document {
    width: 794px;
    height: 1123px;
    box-shadow: none;
    padding: 32px 32px 24px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .print-document--landscape {
    width: 1123px;
    height: 794px;
  }

  .print-table {
    page-break-inside: auto;
  }

  .print-table tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }
}
