/* ==========================================
   더보다 AI - 보고서 출력용 스타일 (A4 세로)
   v2.0 전면 재작성 — 인쇄 품질 최적화
   ========================================== */

@media print {

  /* ── A4 Setup ── */
  @page {
    size: A4 portrait;
    margin: 0;
  }

  /* ── 인쇄 색상 강제 적용 ── */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  /* ── UI 요소 완전 숨기기 ── */
  .sidebar, .topbar, .topbar-actions, .toast-container,
  .no-print, .tab-nav-buttons, .btn,
  .section-header .btn, #save-btn, #preview-btn,
  .preview-toolbar {
    display: none !important;
  }

  /* ── 미리보기 래퍼 배경 제거 ── */
  body, html {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .preview-wrap {
    background: #fff !important;
    padding: 0 !important;
  }
  .report-viewer {
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* ── 기본 보고서 페이지 ── */
  .report-page {
    width: 210mm;
    min-height: 297mm;
    padding: 15mm 15mm 20mm;
    margin: 0 !important;
    background: #fff !important;
    color: #0a1628 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    border: none !important;
    page-break-after: always;
    position: relative;
    box-sizing: border-box;
    font-family: 'Pretendard Variable', 'Nanum Square Neo', 'Noto Sans KR', sans-serif;
    font-size: 9.5pt;
    line-height: 1.55;
  }
  .report-page:last-child {
    page-break-after: avoid;
  }

  /* ──────────────────────────────────
     표지 (풀 배경 모던 레이아웃)
     ────────────────────────────────── */
  .cover-page {
    display: flex !important;
    flex-direction: column !important;
    padding: 0 !important;
    height: 297mm;
    overflow: hidden;
    background: #1a3669 !important;
    color: #fff !important;
  }
  .cover-page * { color: #fff !important; }
  .cover-top {
    padding: 12mm 12mm 0;
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
  }
  .cover-doc-label {
    font-size: 7pt;
    color: rgba(255,255,255,0.5) !important;
    letter-spacing: 0.15em;
    font-weight: 500;
  }
  .cover-hero {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 12mm;
  }
  .cover-glass {
    background: rgba(255,255,255,0.08) !important;
    border: 0.3mm solid rgba(255,255,255,0.12) !important;
    border-radius: 5mm;
    padding: 11mm 12mm;
    width: 100%;
    max-width: 130mm;
  }
  .cover-accent-line {
    width: 12mm;
    height: 0.8mm;
    background: #4a90d9 !important;
    border-radius: 0.5mm;
    margin-bottom: 5mm;
  }
  .cover-title {
    font-size: 22pt !important;
    font-weight: 700;
    color: #fff !important;
    margin-bottom: 1.5mm;
    line-height: 1.2;
  }
  .cover-subtitle {
    font-size: 9pt;
    color: rgba(255,255,255,0.45) !important;
    letter-spacing: 0.06em;
    margin-bottom: 6mm;
  }
  .cover-address {
    font-size: 10pt;
    color: rgba(255,255,255,0.85) !important;
    font-weight: 500;
    margin-bottom: 8mm;
    line-height: 1.6;
  }
  .cover-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
  }
  .cover-info-item {
    padding: 2.5mm 0;
    border-bottom: 0.3mm solid rgba(255,255,255,0.08) !important;
  }
  .cover-info-label {
    font-size: 6.5pt;
    color: rgba(255,255,255,0.4) !important;
    letter-spacing: 0.05em;
    margin-bottom: 0.5mm;
  }
  .cover-info-value {
    font-size: 9pt;
    font-weight: 600;
    color: #fff !important;
  }
  .cover-bottom {
    padding: 0 12mm 9mm;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
  }
  .cover-bottom-left {
    font-size: 7pt;
    color: rgba(255,255,255,0.3) !important;
    line-height: 1.6;
  }
  .cover-bottom-logo {
    height: 16mm !important;
  }

  /* ──────────────────────────────────
     간지 (섹션 구분 페이지)
     ────────────────────────────────── */
  .divider-page {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    height: 297mm;
    padding: 0 !important;
    page-break-after: always;
  }
  .divider-line { width: 12mm; height: 0.8mm; background: #4a90d9 !important; margin-bottom: 6mm; border-radius: 1mm; }
  .divider-num { font-size: 9pt; font-weight: 700; color: #4a90d9 !important; letter-spacing: 0.1em; margin-bottom: 3mm; }
  .divider-title { font-size: 18pt; font-weight: 700; color: #1a3669 !important; margin-bottom: 2mm; }
  .divider-sub { font-size: 9pt; color: #4a6a8a !important; }

  /* ──────────────────────────────────
     페이지 머릿글 / 바닥글
     ────────────────────────────────── */
  .rpt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1.5pt solid #4a90d9;
    padding-bottom: 2.5mm;
    margin-bottom: 5mm;
  }
  .rpt-header-brand { font-size: 8.5pt; font-weight: 700; color: #4a90d9 !important; }
  .rpt-header-right { font-size: 7.5pt; color: #4a6a8a !important; }

  .rpt-page-title {
    font-size: 14pt;
    font-weight: 700;
    color: #0a1628 !important;
    margin-bottom: 4mm;
  }

  .rpt-section-title {
    font-size: 9.5pt;
    font-weight: 700;
    color: #4a90d9 !important;
    margin: 4mm 0 2.5mm;
    padding-left: 2.5mm;
    border-left: 2.5pt solid #4a90d9;
  }

  .rpt-footer {
    position: absolute;
    bottom: 8mm;
    left: 15mm;
    right: 15mm;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 0.4pt solid #d8e2ec;
    padding-top: 1.5mm;
    font-size: 7pt;
    color: #4a6a8a !important;
  }

  /* ──────────────────────────────────
     표 스타일
     ────────────────────────────────── */
  .info-table, .checklist-table, .fixed-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8.5pt;
    margin-bottom: 3mm;
  }
  .info-table th, .checklist-table th {
    background: #4a90d9 !important;
    color: #fff !important;
    font-weight: 600;
    padding: 2mm 3mm;
    text-align: left;
    font-size: 7.5pt;
  }
  .info-table td, .checklist-table td {
    padding: 2mm 3mm;
    border-bottom: 0.3pt solid #d8e2ec;
  }
  .info-table .label-cell {
    color: #4a6a8a !important;
    font-weight: 600;
    font-size: 8pt;
    width: 25%;
    background: #f8fafc !important;
  }

  /* ── 판정 뱃지 ── */
  .status-badge {
    display: inline-block;
    font-size: 7pt;
    font-weight: 700;
    padding: 0.8mm 2.5mm;
    border-radius: 20pt;
  }
  .status-badge.good { background: #f0fff4 !important; color: #27ae60 !important; }
  .status-badge.normal { background: #fff8e1 !important; color: #e67e22 !important; }
  .status-badge.bad { background: #fff8e1 !important; color: #d35400 !important; }
  .status-badge.danger { background: #fff0f0 !important; color: #c0392b !important; }
  .status-badge.na { background: #f4f7fb !important; color: #7a8fa3 !important; }

  /* ── 평면도 이미지 ── */
  #preview-floorplan { max-height: 85mm !important; overflow: hidden; }
  #preview-floorplan img { max-height: 85mm !important; object-fit: contain !important; }

  /* ── 판정 기준 테이블 ── */
  .criteria-table { width: 100%; border-collapse: collapse; font-size: 8pt; margin-bottom: 3mm; }
  .criteria-table th { background: #f4f7fb !important; padding: 2mm 3mm; font-weight: 600; border-bottom: 0.5pt solid #d8e2ec; text-align: left; }
  .criteria-table td { padding: 1.5mm 3mm; border-bottom: 0.3pt solid #eef2f7; }
  .criteria-badge { display: inline-block; padding: 0.5mm 2.5mm; border-radius: 20pt; font-size: 7pt; font-weight: 700; }

  /* ──────────────────────────────────
     사진 그리드
     ────────────────────────────────── */
  .photo-grid {
    display: grid;
    gap: 2mm;
    margin: 2mm 0 3mm;
  }
  .photo-grid[data-cols="1"] { grid-template-columns: 1fr; }
  .photo-grid[data-cols="2"] { grid-template-columns: 1fr 1fr; }
  .photo-grid[data-cols="3"] { grid-template-columns: 1fr 1fr 1fr; }
  .photo-grid[data-cols="4"] { grid-template-columns: 1fr 1fr; }
  .photo-grid[data-cols="6"] { grid-template-columns: 1fr 1fr 1fr; }
  .photo-grid[data-cols="8"] { grid-template-columns: 1fr 1fr; }

  .photo-cell img {
    width: 100%;
    height: auto;
    max-height: 50mm;
    object-fit: cover;
    border: 0.3pt solid #d8e2ec;
    border-radius: 1.5pt;
    display: block;
  }
  .photo-cell-caption {
    font-size: 7pt;
    color: #4a6a8a !important;
    text-align: center;
    padding: 0.5mm 1mm;
    background: #f8fafc !important;
    margin-top: 0.5mm;
  }

  /* ──────────────────────────────────
     진단 카드
     ────────────────────────────────── */
  .diag-card {
    border: 0.5pt solid #d8e2ec;
    border-radius: 3pt;
    margin-bottom: 3mm;
    overflow: hidden;
    page-break-inside: avoid;
  }
  .diag-card-header {
    background: #f4f7fb !important;
    padding: 2mm 3mm;
    border-bottom: 0.3pt solid #d8e2ec;
  }
  .diag-card-title { font-size: 9pt; font-weight: 700; color: #0a1628 !important; }
  .diag-card-body { padding: 2.5mm 3mm; }
  .diag-label { font-size: 8pt; font-weight: 600; color: #4a90d9 !important; margin: 2mm 0 1mm; }
  .diag-text { font-size: 8.5pt; color: #4a6a8a !important; line-height: 1.5; margin-bottom: 2mm; white-space: pre-wrap; }

  /* ── 세부판정 테이블 ── */
  .sj-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8pt;
    margin-bottom: 2mm;
  }
  .sj-table th {
    background: #f4f7fb !important;
    padding: 1.5mm 3mm;
    font-weight: 600;
    text-align: left;
    border-bottom: 0.5pt solid #d8e2ec;
  }
  .sj-table td {
    padding: 1.5mm 3mm;
    border-bottom: 0.3pt solid #eef2f7;
  }

  /* ──────────────────────────────────
     종합판단 전용
     ────────────────────────────────── */
  .summary-overall {
    display: flex;
    align-items: center;
    gap: 3mm;
    padding: 3mm 4mm;
    background: #f4f7fb !important;
    border: 0.5pt solid #d8e2ec;
    border-radius: 3pt;
    margin-bottom: 4mm;
    page-break-inside: avoid;
  }
  .overall-label { font-size: 9pt; font-weight: 700; color: #0a1628 !important; }

  /* ── 전문가 의견 박스 ── */
  .expert-box {
    border: 0.5pt solid #d8e2ec;
    border-radius: 3pt;
    padding: 3mm 4mm;
    margin-bottom: 3mm;
    page-break-inside: avoid;
  }
  .expert-box-title { font-size: 9pt; font-weight: 700; color: #4a90d9 !important; margin-bottom: 2mm; }
  .expert-box-text { font-size: 8.5pt; color: #4a6a8a !important; line-height: 1.6; white-space: pre-wrap; }

  /* ──────────────────────────────────
     Page Break 규칙 (핵심)
     ────────────────────────────────── */

  /* 카드 단위로 분리 금지 — 카드 전체가 다음 페이지로 */
  .diag-card,
  .expert-box,
  .summary-overall,
  .photo-grid {
    page-break-inside: avoid;
  }

  /* 표 단위로 분리 금지 */
  .info-table,
  .checklist-table,
  .sj-table,
  .criteria-table,
  .cover-info-grid {
    page-break-inside: avoid;
  }

  /* 제목 뒤에서 끊기지 않도록 */
  .rpt-page-title,
  .rpt-section-title,
  .diag-card-header,
  h1, h2, h3 {
    page-break-after: avoid;
  }

  /* 표지/간지는 반드시 단독 페이지 */
  .cover-page,
  .divider-page {
    page-break-after: always;
    page-break-before: auto;
  }

  /* ──────────────────────────────────
     기타
     ────────────────────────────────── */
  .empty-text { font-size: 8pt; color: #aab8c2 !important; font-style: italic; }

  /* 빈 페이지 숨기기용 (내용 없는 마지막 페이지) */
  .report-page:empty { display: none; }
}
