/*
  PROJECT GRADE7 MISSION SYSTEM
  Print Stylesheet — Version 1.0

  Included on every page via <link>.
  Styles inside @media print only activate when printing.
*/

@media print {

  /* ── Page Setup ── */
  @page {
    size: A4 portrait;
    margin: 20mm 18mm 22mm 20mm;
  }

  @page :first {
    margin-top: 15mm;
  }

  /* ── Hide Screen-Only Elements ── */
  #main-nav,
  .site-footer,
  .btn,
  .btn-outline,
  .btn-primary,
  .nav-toggle,
  .no-print,
  .hero-stats,
  .card-grid,
  .card-footer,
  .section-header .text-muted {
    display: none !important;
  }

  .print-only {
    display: block !important;
  }

  /* ── Base Print Styles ── */
  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body {
    font-family: '微軟正黑體', 'Microsoft JhengHei', 'Noto Sans TC', serif;
    font-size: 11pt;
    line-height: 1.65;
    color: #000;
    background: white;
    display: block;
  }

  h1 { font-size: 18pt; }
  h2 { font-size: 15pt; }
  h3 { font-size: 13pt; }
  h4 { font-size: 11.5pt; }

  a {
    color: #000 !important;
    text-decoration: none !important;
  }

  /* ── Container / Layout ── */
  .container {
    max-width: 100%;
    padding: 0;
  }

  .page-content {
    padding: 0;
  }

  .lesson-page {
    max-width: 100%;
  }

  /* ── Print Header (shown only on print) ── */
  .print-header {
    display: flex !important;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 1.5pt solid #555;
    padding-bottom: 6pt;
    margin-bottom: 14pt;
    font-size: 9pt;
    color: #333;
    font-family: '微軟正黑體', 'Microsoft JhengHei', sans-serif;
  }

  .print-header .ph-title { font-weight: bold; font-size: 10pt; }
  .print-header .ph-code  { font-family: Consolas, 'Courier New', monospace; color: #555; }

  /* ── Hero / Mission Header (print version) ── */
  .hero,
  .mission-header,
  .week-header,
  .subject-hero {
    background: white !important;
    color: #000 !important;
    padding: 0 0 10pt 0 !important;
    margin-bottom: 14pt !important;
    border-bottom: 2pt solid #222;
  }

  .hero-title,
  .mission-title,
  .week-title,
  .subject-hero-title {
    color: #000 !important;
    font-size: 17pt !important;
    margin-bottom: 4pt !important;
  }

  .hero-eyebrow,
  .week-eyebrow,
  .mission-code {
    background: #EEE !important;
    color: #333 !important;
    border: 1pt solid #999 !important;
    font-size: 8pt !important;
    padding: 2pt 6pt !important;
  }

  .hero-desc,
  .mission-subtitle,
  .week-dates,
  .subject-hero-sub {
    color: #333 !important;
    font-size: 10pt !important;
  }

  /* ── Cards (flatten for print) ── */
  .card,
  .lesson-section,
  .review-missions,
  .exercise-box,
  .def-box,
  .key-box,
  .example-box {
    background: white !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  .card           { border: 1pt solid #999; margin-bottom: 8pt; }
  .lesson-section { border: 1pt solid #CCC; padding: 10pt; margin-bottom: 10pt; }
  .card-header    { border-bottom: 1pt solid #CCC !important; padding: 6pt 8pt !important; }
  .card-body      { padding: 8pt !important; }

  /* ── Tables ── */
  table { border-collapse: collapse; width: 100%; font-size: 9.5pt; }

  th, td {
    border: 1pt solid #555 !important;
    padding: 4pt 6pt !important;
    text-align: left;
  }

  th {
    background: #E8E8E8 !important;
    color: #000 !important;
    font-weight: bold;
  }

  .schedule-table th { text-align: center; }
  .schedule-table td { vertical-align: top; min-width: auto; }

  .week-cell { background: #F0F0F0 !important; }
  .boss-cell { background: #F8F8F8 !important; }

  /* ── Badges and Tags (simplified) ── */
  .xp-badge,
  .difficulty,
  .boss-badge,
  .boss-tag,
  .tag,
  .mission-code,
  .mission-check-item .check-xp .xp-badge {
    background: #F5F5F5 !important;
    color: #222 !important;
    border: 0.75pt solid #888 !important;
    border-radius: 2pt !important;
    font-size: 8.5pt !important;
    padding: 1pt 5pt !important;
  }

  /* ── Subject icons (simplified) ── */
  .subject-icon {
    background: #DDD !important;
    color: #000 !important;
    border: 1pt solid #999;
    width: 30pt;
    height: 30pt;
    font-size: 11pt;
  }

  /* ── Lesson Sections ── */
  .lesson-section-title { border-bottom: 1pt solid #999 !important; padding-bottom: 4pt !important; }
  .lesson-section-title::before { background: #555 !important; }

  .key-box {
    background: #F5F5F5 !important;
    border-left: 3pt solid #555 !important;
    padding: 7pt 10pt !important;
  }

  .def-box-header { background: #EEE !important; border-bottom: 1pt solid #CCC !important; }

  .example-box {
    background: #F8FFF8 !important;
    border: 1pt solid #AAA !important;
  }

  /* ── Exercise / Handwriting Boxes ── */
  .exercise-box {
    border: 1.5pt solid #555 !important;
    padding: 8pt !important;
    margin-bottom: 10pt !important;
  }

  .answer-area {
    background: white !important;
    border: 1pt dashed #777 !important;
    min-height: 55pt !important;
    padding: 6pt !important;
  }

  .answer-line {
    border-bottom: 0.75pt solid #888 !important;
    height: 28pt !important;
    margin-bottom: 3pt !important;
    background: transparent !important;
  }

  .exercise-number { color: #000 !important; }

  /* ── Weekly Review Checklist ── */
  .check-box {
    border: 1.5pt solid #555 !important;
    background: white !important;
  }

  .mission-check-item { border-bottom: 0.5pt solid #CCC !important; padding: 5pt 4pt !important; }

  /* ── Navigation within lesson ── */
  .lesson-nav { display: none !important; }

  /* ── Page Break Control ── */
  .exercise-box,
  .lesson-section,
  .def-box,
  .key-box,
  .example-box,
  .mission-check-item {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  h2, h3, h4,
  .lesson-section-title,
  .week-group-header,
  .exercise-number {
    page-break-after: avoid;
    break-after: avoid;
  }

  .section {
    page-break-before: auto;
  }

  /* ── Ensure clean page start for certain pages ── */
  .print-page-break { page-break-before: always; }

  /* ── Session badges (simplified for print) ── */
  .session-badge {
    background: #EEE !important;
    color: #333 !important;
    border: 0.75pt solid #999 !important;
    font-size: 8pt !important;
    padding: 1pt 5pt !important;
    border-radius: 2pt !important;
  }

  /* ── Light review section ── */
  .light-review {
    border-left: 2pt solid #555 !important;
    background: white !important;
  }

  /* ── Daily schedule strip ── */
  .daily-schedule-strip {
    background: #F5F5F5 !important;
    border: 0.75pt solid #CCC !important;
    padding: 5pt 7pt !important;
    font-size: 9pt !important;
  }

  /* ── Lesson Template v2 :: New Elements ── */
  .source-tag {
    background: #EEE !important;
    color: #222 !important;
    border: 0.75pt solid #888 !important;
    font-size: 8pt !important;
    padding: 1pt 5pt !important;
    border-radius: 2pt !important;
  }

  .supply-card {
    background: white !important;
    border: 1pt solid #CCC !important;
    border-left: 3pt solid #888 !important;
    padding: 7pt 10pt !important;
    break-inside: avoid;
  }
  .supply-card-label {
    border-bottom: 0.75pt solid #CCC !important;
    color: #333 !important;
    font-size: 8pt !important;
    margin-bottom: 5pt !important;
    padding-bottom: 4pt !important;
  }

  .training-section {
    background: white !important;
    border-left: 2pt solid #666 !important;
  }
  .training-section .lesson-section-title::before { background: #555 !important; }

  .boss-section {
    border: 1.5pt solid #555 !important;
    background: white !important;
  }
  .boss-section .lesson-section-title { color: #000 !important; }
  .boss-section .lesson-section-title::before { background: #555 !important; }

  .error-table th { background: #EEE !important; font-size: 8.5pt !important; padding: 3pt 5pt !important; }
  .error-table td { height: 38pt !important; padding: 3pt 5pt !important; }

  .tally-card { border: 1pt solid #CCC !important; background: white !important; }
  .tally-row { border-bottom: 0.5pt solid #DDD !important; font-size: 9.5pt !important; padding: 4pt 8pt !important; }
  .tally-total { background: #F5F5F5 !important; padding: 4pt 8pt !important; }
  .tally-row .tally-check { border: 1.5pt solid #555 !important; }

  /* Real checkboxes in print */
  .tally-checkbox {
    -webkit-appearance: checkbox !important;
    appearance: checkbox !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    width: 12pt !important;
    height: 12pt !important;
    min-width: 12pt !important;
  }
  label.tally-row { cursor: default; background: white !important; }
  .tally-row--done .tally-label {
    text-decoration: line-through !important;
    color: #555 !important;
  }

  .supply-card, .training-section, .boss-section, .error-table, .tally-card {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* ── Answer Space Utility Classes ── */
  .answer-space-sm {
    border-bottom: 0.75pt solid #888;
    min-height: 40pt;
    display: block;
    background: white;
    margin: 4pt 0 8pt;
  }
  .answer-space-md {
    border: 1pt dashed #888;
    min-height: 80pt;
    display: block;
    background: white;
    padding: 4pt 6pt;
    margin: 4pt 0 8pt;
  }
  .answer-space-lg {
    border: 1pt dashed #888;
    min-height: 120pt;
    display: block;
    background: white;
    padding: 4pt 6pt;
    margin: 4pt 0 8pt;
  }
  .calculation-space {
    border: 1pt solid #CCC;
    min-height: 70pt;
    display: block;
    background: #FAFAFA;
    padding: 4pt;
    margin: 4pt 0 8pt;
  }
  .note-space {
    border: 0.75pt solid #CCC;
    min-height: 55pt;
    display: block;
    background: #FAFAFA;
    padding: 4pt 6pt;
    margin: 4pt 0 8pt;
  }
  .answer-space-sm, .answer-space-md, .answer-space-lg,
  .calculation-space, .note-space {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* ── Page Break Utilities ── */
  .avoid-break       { page-break-inside: avoid !important; break-inside: avoid !important; }
  .page-break-before { page-break-before: always !important; break-before: page !important; }
  .page-break-after  { page-break-after:  always !important; break-after:  page !important; }

  /* ── Subject Theme: neutralise colour on print ── */
  .subject-hero.math,
  .subject-hero.english,
  .subject-hero.chinese,
  .subject-hero.biology,
  .subject-hero.history,
  .subject-hero.geography,
  .subject-hero.civics {
    background: white !important;
  }

  .mission-header::after { display: none !important; }
  .hero::after           { display: none !important; }

  .key-box {
    background: #F5F5F5 !important;
    border-left-color: #555 !important;
  }

  .lesson-section-title::before { background: #555 !important; }
  .exercise-number              { color: #000 !important; }
  .def-term                     { color: #000 !important; }

  .tally-checkbox:checked {
    background: #555 !important;
    border-color: #555 !important;
  }

  .subject-bar-math,
  .subject-bar-english,
  .subject-bar-chinese,
  .subject-bar-biology,
  .subject-bar-history,
  .subject-bar-geography,
  .subject-bar-civics,
  .subject-bar-boss {
    background: #555 !important;
  }

  .lesson-section {
    border-color: #CCC !important;
  }

  .card {
    border-color: #CCC !important;
  }

  /* ── Image Placeholder ── */
  .image-placeholder {
    background: #F2F2F2 !important;
    border: 1pt solid #BBB !important;
    border-radius: 0 !important;
    min-height: 80pt;
    display: flex !important;
    align-items: center;
    justify-content: center;
    color: #888;
    font-size: 9pt;
    box-shadow: none !important;
  }

  /* ── Answer Page Banner (教師／家長用) ── */
  .answer-page-banner {
    display: block !important;
    background: #FEF3C7 !important;
    border: 1.5pt solid #D97706 !important;
    color: #92400E !important;
    font-weight: bold;
    font-size: 11pt;
    text-align: center;
    padding: 5pt 10pt;
    margin-bottom: 12pt;
    font-family: '微軟正黑體', 'Microsoft JhengHei', sans-serif;
  }

  /* ── Schedule: compact table for print ── */
  .schedule-table th,
  .schedule-table td {
    font-size: 7.5pt !important;
    padding: 3pt 4pt !important;
    line-height: 1.4 !important;
  }
  .schedule-table .cell-code  { font-size: 7pt !important; }
  .schedule-table .cell-title { font-size: 7.5pt !important; }
  .schedule-table a           { display: none !important; }
}
