/* ---------------------------------------------------- */
/* 画面表示用スタイル                                   */
/* ---------------------------------------------------- */
body {
    font-family: sans-serif;
    margin: 20px;
    padding: 0;
    background-color: #f4f4f4;
}

h1 {
    color: #333;
    border-bottom: 2px solid #ccc;
    padding-bottom: 10px;
}

/* タイトル＋ページ番号 */
.print-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 15px 0;
    font-weight: bold;
    color: #333;
    font-size: 1.2em;
}

/* 入力欄 */
label[for="titleInput"] {
    font-weight: bold;
    color: #333;
    margin-right: 6px;
}

#titleInput {
    display: inline-block;
    margin: 8px 0 12px 0;
    padding: 4px 8px;
    font-size: 1em;
    border: 1px solid #ccc;
    border-radius: 4px;
}

#printArea {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-top: 10px;
    padding: 10px;
    background-color: #fff;
    border: 1px solid #ddd;
}

.image-item {
    width: 200px; 
    border: 1px solid #e0e0e0;
    padding: 5px;
    text-align: center;
    box-sizing: border-box;
    background-color: #fff;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
}

.image-item img {
    max-width: 100%;
    height: auto;
    max-height: 180px; 
    object-fit: contain;
    display: block;
    margin: 0 auto 5px auto;
}

.image-caption {
    font-size: 0.9em;
    color: #555;
    padding: 3px 0;
}

/* ---------------------------------------------------- */
/* 画面プレビュー時（印刷前）のページ・グリッド調整       */
/* ---------------------------------------------------- */
.print-page {
  display: block;
  width: 100%;
  background: #fff;
  padding: 12px;
  margin-bottom: 25px;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.print-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  justify-content: flex-start;
}

.print-header {
  background-color: #fafafa;
  border-bottom: 1px solid #ddd;
  padding: 6px 10px;
  border-radius: 4px 4px 0 0;
  margin-bottom: 10px;
}


/* ---------------------------------------------------- */
/* 印刷スタイル                                         */
/* ---------------------------------------------------- */
@media print {

  @page {
    size: A4;
    margin: 6mm; /* 余白最小化 */
    @top-left { content: none }
    @top-right { content: none }
    @bottom-left { content: none }
    @bottom-right { content: none }
  }

  body {
    margin: 0;
    background: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  h1, input, button, label[for="titleInput"] {
    display: none !important;
  }

  /* ページヘッダー */
  .print-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    font-size: 9pt;        /* ← さらに小さく */
    color: #000;
    margin: 0 0 1.5mm 0;   /* ← 高さを最小限に */
    line-height: 1.1;
    page-break-after: avoid;
  }

  .print-title, .print-page-number {
    white-space: nowrap;
  }

  .print-page {
    page-break-after: always;
    margin-bottom: 4mm;
    border: none !important;        /* ← 枠線を消す */
    box-shadow: none !important;    /* ← 影も消す */
    background: transparent !important; /* ← 背景色も白化 */
  }

  .print-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2mm; /* ← 行間・列間をさらに詰める */
  }

#printArea {
    border: 0;
}

  .image-item {
    width: 100%;
    padding: 0.8mm;
    border: none !important;
    background: transparent !important;
    break-inside: avoid;
    box-shadow: none !important;
  }

  /* ここが核心：A4縦297mmに5行収まるよう正確に計算 */
  .image-item img {
    width: 100%;
    height: auto;
    max-height: calc((297mm - 12mm - 1.5mm - (2mm * 4)) / 5 - 6px);
    object-fit: contain;
    border: none !important;
    box-shadow: none !important;
    display: block;
    margin: 0 auto;
  }

  .image-caption {
    font-size: 6.5pt;
    color: #000;
    text-align: center;
    margin-top: 0.3mm;
    line-height: 1;
    background: transparent !important;
    border: none !important;
  }
}
