@page {
  size: A4;
  margin: 12mm;
}

@media print {
  html, body {
    height: auto;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    color: #111;
    background: #fff !important;
  }

  /* скрыть то, что не нужно на бумаге */
  .site-header, .site-footer, .global-nav, .sticky, .floating-actions,
  .back-to-top, .cta-bar, .btn.print-hidden { display: none !important; }

  /* основной контейнер на ширину листа, убрать тени и фоны */
  main, .page-section, .content, .container {
    max-width: 100% !important;
    box-shadow: none !important;
    background-image: none !important;
  }

  /* запрет разрыва важных блоков */
  .card, .unit, .unit-card, .lesson, .lesson-card,
  .callout, .toc, .table-wrap, table, figure, img, blockquote {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* логичные разрывы перед крупными разделами если есть такие id */
  section#overview   { break-before: page; }
  section#units      { break-before: page; }
  section#alignment  { break-before: page; }
  section#skills     { break-before: page; }
  section#toolkit    { break-before: page; }
  section#materials  { break-before: page; }
  section#activities { break-before: page; }

  /* не оставлять заголовки одиночными на нижней строке */
  h1, h2, h3 {
    break-after: avoid;
    page-break-after: avoid;
    margin-bottom: 8px;
  }

  /* таблицы - повтор шапки на каждой странице */
  table { width: 100%; border-collapse: collapse; }
  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }
  tr, th, td { break-inside: avoid; page-break-inside: avoid; }

  /* изображения - вписываемся в поле */
  img { max-width: 100% !important; height: auto !important; }

  /* по желанию - выводить URL внешних ссылок */
  a[href^="http"]:after {
    content: " (" attr(href) ")";
    font-size: 10px;
    color: #666;
  }

  /* hide bottom breadcrumbs in print for cleaner output */
  .breadcrumb--bottom { display: none !important; }
  .breadcrumb { display: none !important; }
  .footer, .site-footer { display: none !important; }
  .print-hidden, .curriculum-actions, .print-hint { display: none !important; }

  /* Brickit Demo Lesson pages - специальные стили для печати */
  .brickit-demo .header {
    background: #fff !important;
    color: #111 !important;
    padding: 20px 0 !important;
    page-break-after: avoid;
  }

  .brickit-demo .header::before {
    display: none !important;
  }

  .brickit-demo h1 {
    color: #111 !important;
    font-size: 24px !important;
    margin-bottom: 10px !important;
  }

  .brickit-demo .subtitle {
    color: #333 !important;
    font-size: 16px !important;
    margin-bottom: 15px !important;
  }

  .brickit-demo .meta-info {
    flex-direction: column !important;
    gap: 8px !important;
    margin-top: 15px !important;
  }

  .brickit-demo .meta-item {
    background: #f5f5f5 !important;
    color: #111 !important;
    padding: 6px 12px !important;
  }

  /* Lesson Flow - вертикальный стек, без разрывов внутри карточек */
  .brickit-demo .lesson-flow {
    padding: 20px 0 !important;
    background: #fff !important;
  }

  .brickit-demo .lesson-flow .step-grid {
    gap: 1rem !important;
  }

  .brickit-demo .lesson-flow .step-card {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    box-shadow: none !important;
    border: 1px solid #ddd !important;
    padding: 1rem 1rem 1rem 2.8rem !important;
    margin-bottom: 1rem !important;
    background: #fff !important;
  }

  .brickit-demo .lesson-flow .step-card:hover,
  .brickit-demo .lesson-flow .step-card:focus-within {
    transform: none !important;
    box-shadow: none !important;
  }

  .brickit-demo .lesson-flow .step-card__badge {
    background: #345b45 !important;
    color: #fff !important;
    border: 2px solid #345b45 !important;
  }

  /* Разрывы страниц перед основными разделами */
  .brickit-demo #overview,
  .brickit-demo #goals,
  .brickit-demo #preparation,
  .brickit-demo #steps,
  .brickit-demo .skills {
    break-before: auto;
    page-break-before: auto;
  }

  /* Улучшенная читаемость для всех секций */
  .brickit-demo .overview,
  .brickit-demo .goals,
  .brickit-demo .preparation,
  .brickit-demo .skills {
    padding: 20px 0 !important;
    background: #fff !important;
  }

  .brickit-demo .overview-content {
    box-shadow: none !important;
    border: 1px solid #ddd !important;
    padding: 20px !important;
  }

  .brickit-demo .goal-card,
  .brickit-demo .prep-card {
    box-shadow: none !important;
    border: 1px solid #ddd !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .brickit-demo .tip-box {
    box-shadow: none !important;
    border: 1px solid #ddd !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  /* Таблицы для печати */
  .brickit-demo .skills-table {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .brickit-demo .skills-table th {
    background: #f5f5f5 !important;
    color: #111 !important;
    border: 1px solid #ddd !important;
  }

  .brickit-demo .skills-table td {
    border: 1px solid #ddd !important;
  }

  /* Student Recording Sheet - выделение для печати */
  .brickit-demo .tip-box[style*="background: #f5f5f5"] {
    border: 2px solid #345b45 !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  /* Убрать все эмодзи или заменить на текст при печати (опционально) */
  .brickit-demo .emoji-icon {
    display: none !important;
  }

  /* нумерация страниц - поддерживается не во всех браузерах */
  @page {
    @bottom-center {
      content: counter(page) " / " counter(pages);
      font-size: 10px;
      color: #777;
    }
  }
}

/* служебный класс для ручной защиты от разрыва */
.no-break { break-inside: avoid; page-break-inside: avoid; }

/* Print only Student Recording Sheet mode */
@media print {
  /* Hide body content but keep structure */
  body.print-sheet-only {
    margin: 0 !important;
    padding: 0 !important;
  }
  
  /* Hide everything by default */
  body.print-sheet-only * {
    display: none !important;
  }
  
  /* Show only the sheet container we want to print and all its content */
  body.print-sheet-only .student-recording-sheet-container[data-print-sheet="true"] {
    display: block !important;
  }
  
  body.print-sheet-only .student-recording-sheet-container[data-print-sheet="true"] * {
    display: revert !important;
  }
  
  /* Position the container */
  body.print-sheet-only .student-recording-sheet-container[data-print-sheet="true"] {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 20mm !important;
    background: #fff !important;
    box-shadow: none !important;
  }
  
  /* Hide the button */
  body.print-sheet-only .student-recording-sheet-container[data-print-sheet="true"] .print-sheet-btn,
  body.print-sheet-only .student-recording-sheet-container[data-print-sheet="true"] .print-sheet-btn * {
    display: none !important;
  }
  
  /* Hide the instruction paragraph "Print this worksheet..." */
  body.print-sheet-only .student-recording-sheet-container[data-print-sheet="true"] .tip-box > p:first-child {
    display: none !important;
  }
  
  /* Style the wrapper div */
  body.print-sheet-only .student-recording-sheet-container[data-print-sheet="true"] > div:first-child {
    display: flex !important;
    margin-bottom: 1rem !important;
  }
  
  /* Style the section heading */
  body.print-sheet-only .student-recording-sheet-container[data-print-sheet="true"] .section-subheading {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
  }
  
  /* Style the tip-box */
  body.print-sheet-only .student-recording-sheet-container[data-print-sheet="true"] .tip-box {
    border: none !important;
    background: #fff !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
  }
  
  /* Style the white content box */
  body.print-sheet-only .student-recording-sheet-container[data-print-sheet="true"] .tip-box > div {
    background: #fff !important;
  }
}
