/**
 * 印刷用スタイルシート
 * 保険シミュレーション結果の印刷レイアウトを最適化
 * 2ページ構成：1ページ目（縦向き・サマリー）、2ページ目（横向き・2カラム表）
 */

@media print {
    /* ========================================
       基本設定
    ======================================== */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    
    body {
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
        font-size: 12pt;
        line-height: 1.6;
        color: #000;
        background: white;
        margin: 0;
        padding: 0;
    }
    
    /* ========================================
       不要な要素を非表示
    ======================================== */
    .header,
    .insurance-sim-header,
    .progress-container,
    .navigation-buttons,
    .step-navigation,
    .button-container,
    #restartBtn,
    #saveBtn,
    #printBtn,
    .modal,
    .wizard-navigation,
    .mode-selection,
    .step-content:not(#step6),
    #step1, #step2, #step3, #step4, #step5 {
        display: none !important;
    }
    
    /* ========================================
       メインコンテンツ
    ======================================== */
    .insurance-simulation-container,
    .container,
    .wizard-container {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 0;
        box-shadow: none;
        border: none;
    }
    
    .wizard-content {
        padding: 0;
        margin: 0;
    }
    
    /* ========================================
       結果表示エリア
    ======================================== */
    #step6 {
        display: block !important;
        padding: 0;
        margin: 0;
    }
    
    /* ========================================
       1ページ目：サマリー情報（縦向き）
    ======================================== */
    @page :first {
        size: A4 portrait;
        margin: 20mm 15mm;
    }
    
    /* 結果ヘッダー */
    .results-header {
        page-break-after: avoid;
        margin-bottom: 30px;
        padding: 20px;
        background-color: #f0f9ff !important;
        border: 2px solid #0284c7;
        border-radius: 8px;
        text-align: center;
    }
    
    .results-header h2 {
        font-size: 24pt;
        font-weight: bold;
        color: #0c4a6e;
        margin: 0 0 10px 0;
    }
    
    .results-header .subtitle {
        font-size: 14pt;
        color: #075985;
        margin: 0;
    }
    
    /* ========================================
       2ページ目：詳細表（横向き・2カラム）
    ======================================== */
    @page :nth(2) {
        size: A4 landscape;
        margin: 15mm 10mm;
    }
    
    /* 年度別詳細表 */
    .results-table {
        page-break-before: always;
        display: block;
        columns: 2;
        column-gap: 30px;
        column-rule: 1px solid #cbd5e1;
    }
    
    .results-table h3 {
        font-size: 16pt;
        font-weight: bold;
        color: #1e293b;
        margin: 0 0 20px 0;
        text-align: center;
        column-span: all;
        page-break-after: avoid;
    }
    
    /* テーブルスタイル */
    table {
        width: 100%;
        border-collapse: collapse;
        break-inside: avoid-column;
        margin-bottom: 20px;
        font-size: 9pt;
    }
    
    thead {
        display: table-header-group;
        break-inside: avoid;
    }
    
    tbody {
        display: table-row-group;
    }
    
    th, td {
        border: 1px solid #cbd5e1;
        padding: 6px 8px;
    }
    
    th {
        background-color: #e0f2fe !important;
        font-weight: 600;
        color: #0c4a6e;
        text-align: center;
        font-size: 8pt;
        position: sticky;
        top: 0;
    }
    
    td {
        background-color: white;
        color: #334155;
        text-align: right;
        font-size: 8pt;
    }
    
    /* 年齢列 */
    th:first-child,
    td:first-child {
        width: 40px;
        text-align: center;
        font-weight: 600;
        background-color: #f8fafc !important;
    }
    
    /* 強調行 */
    tr.highlight {
        break-inside: avoid;
    }
    
    tr.highlight td {
        background-color: #fef3c7 !important;
        font-weight: 600;
        color: #92400e;
    }
    
    /* 小計行 */
    tr.subtotal td {
        background-color: #f0f9ff !important;
        font-weight: 600;
        border-top: 2px solid #0284c7;
    }
    
    /* 合計行 */
    tr.total td {
        background-color: #dbeafe !important;
        font-weight: bold;
        font-size: 9pt;
        border-top: 3px double #0284c7;
    }
    
    /* グラフエリア */
    .chart-container {
        page-break-inside: avoid;
        margin: 30px 0;
        padding: 20px;
        border: 1px solid #e2e8f0;
        background-color: white;
        min-height: 250px;
    }
    
    .chart-title {
        font-size: 14pt;
        font-weight: 600;
        color: #334155;
        margin-bottom: 15px;
        text-align: center;
    }
    
    canvas {
        max-width: 100% !important;
        max-height: 300px !important;
        display: block;
        margin: 0 auto;
    }
    
    /* サマリーカード */
    .summary-cards {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px;
        margin-bottom: 30px;
        page-break-inside: avoid;
    }
    
    .summary-card {
        padding: 20px;
        border: 2px solid #cbd5e1;
        border-radius: 8px;
        background-color: #f8fafc !important;
    }
    
    .summary-card.primary {
        background-color: #eff6ff !important;
        border-color: #3b82f6;
    }
    
    .summary-card.danger {
        background-color: #fef2f2 !important;
        border-color: #ef4444;
    }
    
    .summary-card .label {
        font-size: 12pt;
        color: #64748b;
        margin-bottom: 8px;
        font-weight: 600;
    }
    
    .summary-card .value {
        font-size: 20pt;
        font-weight: bold;
        color: #0f172a;
    }
    
    .summary-card.danger .value {
        color: #dc2626;
    }
    
    /* ユーザー入力サマリー（1ページ目） */
    .user-input-summary {
        page-break-before: avoid;
        page-break-after: always;
        margin-top: 30px;
        padding: 20px;
        background-color: #fafafa !important;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
    }
    
    .user-input-summary h3 {
        font-size: 16pt;
        font-weight: 600;
        margin-bottom: 20px;
        color: #1f2937;
        text-align: center;
    }
    
    #userInputTable {
        display: none; /* 1ページ目では非表示 */
    }
    
    /* 入力内容の要約表示 */
    .input-summary-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 15px;
    }
    
    .input-summary-item {
        display: flex;
        justify-content: space-between;
        padding: 10px;
        background-color: white;
        border-left: 3px solid #3b82f6;
        padding-left: 15px;
    }
    
    .input-summary-item .label {
        font-weight: 600;
        color: #475569;
    }
    
    .input-summary-item .value {
        color: #0f172a;
        font-weight: 500;
    }
    
    /* ========================================
       改ページ制御
    ======================================== */
    h2, h3, h4 {
        page-break-after: avoid;
    }
    
    /* テーブル行の改ページ制御 */
    tr {
        page-break-inside: avoid;
    }
    
    /* 年度ごとのグループを保持 */
    tbody tr:nth-child(5n) {
        page-break-after: auto;
    }
    
    /* ========================================
       ページ番号とヘッダー/フッター
    ======================================== */
    @page {
        @bottom-center {
            content: counter(page) " / " counter(pages);
            font-size: 10pt;
            color: #64748b;
        }
    }
    
    /* 印刷日時 */
    .print-footer {
        position: fixed;
        bottom: 5mm;
        left: 0;
        right: 0;
        text-align: center;
        font-size: 9pt;
        color: #94a3b8;
    }
    
    .print-footer::before {
        content: "印刷日: " attr(data-date);
    }
    
    /* ========================================
       注意事項（2ページ目下部）
    ======================================== */
    .disclaimer {
        column-span: all;
        margin-top: 30px;
        padding: 15px;
        border: 2px solid #fbbf24;
        background-color: #fffbeb !important;
        font-size: 9pt;
        page-break-inside: avoid;
        text-align: center;
    }
    
    .disclaimer strong {
        color: #92400e;
        display: block;
        margin-bottom: 5px;
    }
    
    .disclaimer p {
        margin: 5px 0;
        color: #78350f;
    }
}

/* 印刷プレビュー時のスタイル調整 */
@media print and (color) {
    /* カラー印刷対応 */
    .summary-card.primary {
        background-color: #dbeafe !important;
    }
    
    .summary-card.success {
        background-color: #d1fae5 !important;
    }
    
    .summary-card.warning {
        background-color: #fed7aa !important;
    }
    
    .summary-card.danger {
        background-color: #fee2e2 !important;
    }
}

/* モノクロ印刷対応 */
@media print and (monochrome) {
    * {
        color: black !important;
        background-color: white !important;
    }
    
    th {
        background-color: #f0f0f0 !important;
        border: 2px solid black !important;
    }
    
    td {
        border: 1px solid black !important;
    }
}