/* print.css - Redesigned for Elegance */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+JP:wght@400;700&family=Noto+Sans+JP:wght@400;700&display=swap');

@media print {
  /* Force override of screen styles for printing */
  html, body {
    padding: 0 !important;
    margin: 0 !important;
  }
  .cover-page, .spine-page, .toc-page, .print-section {
    margin: 0 !important;
    box-shadow: none !important;
    border: none !important;
  }
  @page {
    size: A4;
    margin: 0;
  }

  body {
    margin: 0;
    padding: 0;
    font-family: 'Noto Serif JP', serif;
    font-size: 10pt;
    line-height: 1.8;
    background-color: #fff; /* Ensure white background */
    -webkit-print-color-adjust: exact; /* Force printing of colors and backgrounds */
    color-adjust: exact;
  }

  /* --- Helper Classes --- */
  .page-break-after {
    page-break-after: always;
  }

  .background-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: -1;
  }

  /* --- Cover Page --- */
  .cover-page {
    width: 210mm;
    height: 297mm;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    box-sizing: border-box;
    position: relative;
  }

  .cover-title-block {
    border: 4px double #8B4513; /* SaddleBrown */
    padding: 2cm 3cm;
    position: relative;
    z-index: 1;
    background-color: rgba(255, 255, 255, 0.6);
  }

  .cover-page h1 {
    font-family: 'Noto Serif JP', serif;
    font-size: 32pt;
    color: #333;
    font-weight: 700;
    margin: 0;
    text-shadow: none;
  }

  .cover-page .name-placeholder {
    margin-top: 1.5cm;
    padding-top: 0.5cm;
    font-size: 14pt;
    color: #555;
    width: 80%;
  }
  
  .name-placeholder-line {
      border-bottom: 1px solid #8B4513;
      width: 60%;
      margin: 1cm auto 0;
      font-size: 12pt;
      color: #777;
      text-align: left; /* Align text to the left */
  }

  /* --- Spine Page --- */
  .spine-page {
    width: 210mm;
    height: 297mm;
    display: flex;
    justify-content: center;
    align-items: stretch;
    box-sizing: border-box;
    position: relative;
  }

  .spine-content {
    width: 20mm;
    height: 100%;
    display: flex;
    flex-direction: column; /* Stack title and date */
    justify-content: center;
    align-items: center;
    border-left: 1px dashed #999;
    border-right: 1px dashed #999;
    padding: 3cm 0; /* Add padding */
    box-sizing: border-box;
    position: relative;
    z-index: 1;
    background-color: rgba(255, 255, 255, 0.6);
  }

  .spine-text {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-family: 'Noto Serif JP', serif;
    font-size: 18pt;
    letter-spacing: 0.2em;
    white-space: nowrap;
    color: #333;
    flex-grow: 1; /* Allow title to take space */
  }
  .spine-date {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 10pt;
    color: #777;
    padding-top: 1em;
    border-top: 1px solid #999;
    height: 8cm; /* Provides space to write */
  }

  /* --- Table of Contents --- */
  .toc-page {
    padding: 2cm;
    width: 210mm;
    height: 297mm;
    box-sizing: border-box;
  }
  .toc-page h2 {
    font-family: 'Noto Sans JP', sans-serif;
    text-align: center;
    border-bottom: 2px solid #8B4513;
    padding-bottom: 10px;
    margin-bottom: 1cm;
    color: #8B4513;
  }
  #toc-list {
    list-style-type: none;
    padding: 0;
    font-size: 12pt;
    column-count: 2;
    column-gap: 1.5cm;
  }
  .toc-item {
    display: flex;
    margin-bottom: 0.5em;
  }
  .toc-item .toc-title {
    font-family: 'Noto Serif JP', serif;
    order: 1;
  }
  .toc-item .toc-dots {
    flex-grow: 1;
    border-bottom: 1px dotted #999;
    margin: 0 0.4em 0.3em;
    order: 2;
  }
  .toc-item .toc-page-num {
    font-family: 'Noto Sans JP', sans-serif;
    order: 3;
  }

  /* --- Content Pages --- */
  .print-section {
    padding: 2.5cm 2cm; /* Top/Bottom, Left/Right */
    height: 297mm; /* A4 height */
    position: relative;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
  }

  .page-header, .page-footer {
    position: absolute;
    width: calc(100% - 4cm); /* 210mm - 2*2cm padding */
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 8pt;
    color: #888;
  }
  .page-header {
    top: 1cm;
    text-align: right;
  }
  .page-footer {
    bottom: 1cm;
    text-align: center;
  }

  .section-title {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 18pt;
    color: #8B4513;
    border-bottom: 1px solid #8B4513;
    padding-bottom: 5px;
    margin-bottom: 1cm;
  }

  h5 {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 14pt;
    color: #333;
    border-left: 4px solid #c59c70;
    padding-left: 10px;
    margin-top: 1cm;
  }

  .print-field {
    display: flex;
    align-items: baseline;
    margin-bottom: 1.2em;
    border-bottom: 1px dotted #ddd;
    padding-bottom: 0.6em;
  }
  .print-field label {
    font-weight: 700;
    font-family: 'Noto Sans JP', sans-serif;
    width: 30%;
    padding-right: 1em;
    flex-shrink: 0;
  }
  .print-field span {
    width: 70%;
  }

  .printable-empty-field[data-type="textarea"] {
    height: 10.8em; /* 6行分 */
    border: 1px solid #eee;
    background-image: linear-gradient(to bottom, #f9f9f9 1px, transparent 1px);
    background-size: 100% 1.8em;
  }

  .memo-field {
    margin-top: auto; /* Push to bottom */
    padding-top: 1cm;
  }
  .memo-title {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 12pt;
    border-bottom: 1px solid #999;
    padding-bottom: 5px;
    margin-bottom: 1em;
  }
  .memo-box {
    flex-grow: 1;
    border: 1px solid #ccc;
    padding: 10px;
    background-image: linear-gradient(to bottom, #e9e9e9 1px, transparent 1px);
    background-size: 100% 1.8em;
    min-height: 5.4em; /* At least 3 lines */
  }

  /* Hide elements not for printing */
  .d-print-none {
    display: none !important;
  }

  .print-section:last-of-type {
    position: relative;
    isolation: isolate;
  }

  .print-section:last-of-type::after {
    content: "";
    background-image: url(../img/flowersBK.png);
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    opacity: 0.2;
  }
}

/* Styles for screen preview */
body {
    background-color: #e8e8e8; /* Light grey background for preview area */
}
.cover-page, .spine-page, .toc-page, .print-section {
    margin: 1cm auto;
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
    border: 1px solid #ccc;
}
.cover-page h1, .spine-text, .toc-page h2, .section-title {
    text-shadow: none !important;
}
.d-print-none {
  text-align: center;
  margin-bottom: 1rem;
}