/**
 * Cheat Sheet Studio - Print Stylesheet
 * Optimized for monochrome / grayscale laser printing on A4 portrait
 */

@page {
  size: A4 portrait;
  margin: 0;
}

@media print {
  html,
  body,
  body.itools-body {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    font-family: var(--font-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    overflow: visible !important;
  }

  /* Hide application UI, chrome, toolbar, modals, overlays */
  .itools-navbar,
  .itools-footer,
  header.app-header,
  nav.toolbar,
  .subheader-toolbar,
  .page-nav-bar,
  .grid-overlay,
  .selection-box,
  .drag-origin-placeholder,
  .drag-ghost,
  .grid-selection-tooltip,
  .edit-handles,
  .section-toolbar,
  .resize-handle,
  .page-settings-btn,
  .btn,
  .modal-backdrop,
  .modal-dialog,
  .toast-container,
  #toast-container,
  .no-print {
    display: none !important;
  }

  .itools-body,
  .itools-main,
  .module-viewport,
  .tool-workspace,
  .cheatsheet-workspace,
  .app-container {
    display: block !important;
    position: static !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    overflow: visible !important;
  }

  .app-workspace {
    padding: 0 !important;
    margin: 0 !important;
    background: none !important;
    display: block !important;
    overflow: visible !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    position: static !important;
  }

  .zoom-wrapper {
    transform: none !important;
    gap: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    position: static !important;
  }

  /* Exact A4 Sheet: 210mm x 297mm with identical 10mm padding as editor visual */
  .page-sheet {
    display: flex !important;
    flex-direction: column !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 10mm !important;
    box-shadow: none !important;
    border: none !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    background: #ffffff !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    position: relative !important;
  }

  /* Don't force page break after the last page */
  .page-sheet:last-of-type {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  /* If a page is hidden in view-single-page mode */
  .page-sheet.is-hidden {
    display: none !important;
  }

  /* Canvas inside page-sheet: exactly 190mm x 277mm matching editor visual */
  .page-canvas {
    width: 190mm !important;
    height: 277mm !important;
    min-height: 277mm !important;
    max-height: 277mm !important;
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    position: relative !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Sheet Header: identical proportions and 10mm inset as editor visual */
  .sheet-header {
    height: 9mm !important;
    min-height: 9mm !important;
    max-height: 9mm !important;
    display: flex !important;
    align-items: flex-end !important;
    justify-content: space-between !important;
    border-bottom: 2px solid #000000 !important;
    padding-bottom: 1.5mm !important;
    margin-bottom: 2mm !important;
    flex-shrink: 0 !important;
    box-sizing: border-box !important;
  }

  .sheet-header-left {
    display: flex !important;
    align-items: baseline !important;
    gap: 10px !important;
    overflow: hidden !important;
  }

  .sheet-title {
    font-size: 13pt !important;
    font-weight: 800 !important;
    letter-spacing: -0.01em !important;
    color: #000000 !important;
    white-space: nowrap !important;
    line-height: 1 !important;
  }

  .sheet-subtitle {
    font-size: 8pt !important;
    font-weight: 500 !important;
    color: #333333 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.05em !important;
    white-space: nowrap !important;
    line-height: 1 !important;
  }

  .sheet-header-right {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    font-size: 8pt !important;
    color: #333333 !important;
    font-weight: 600 !important;
    white-space: nowrap !important;
    line-height: 1 !important;
  }

  /* Sheet Grid matching 12 cols x 14mm with 2mm gap */
  .sheet-grid {
    display: grid !important;
    grid-template-columns: repeat(12, 14mm) !important;
    grid-auto-rows: 14mm !important;
    gap: 2mm !important;
    width: 190mm !important;
    flex: 1 !important;
    position: relative !important;
    box-sizing: border-box !important;
  }

  /* Sheet Footer */
  .sheet-footer {
    height: 6mm !important;
    min-height: 6mm !important;
    max-height: 6mm !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    border-top: 1px solid #000000 !important;
    padding-top: 1mm !important;
    margin-top: 2mm !important;
    flex-shrink: 0 !important;
    font-size: 8pt !important;
    color: #333333 !important;
    font-weight: 600 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    box-sizing: border-box !important;
  }

  /* Crisp borders & high contrast for monochrome laser printing */
  .sheet-section {
    border: 1px solid #000000 !important;
    background: #ffffff !important;
    box-shadow: none !important;
  }

  /* Border styles in print */
  .border-style-square .sheet-section {
    border: 1px solid #000000 !important;
    border-radius: 0 !important;
  }
  .border-style-rounded .sheet-section {
    border: 1px solid #000000 !important;
    border-radius: 6px !important;
  }
  .border-style-rounded .section-header {
    border-top-left-radius: 5px !important;
    border-top-right-radius: 5px !important;
  }
  .border-style-invisible .sheet-section {
    border: none !important;
  }
  .border-style-left-border .sheet-section {
    border: none !important;
    border-left: 3px solid #000000 !important;
    border-radius: 0 !important;
  }

  /* Title styles in print */
  .title-style-grey .section-header {
    background: #eeeeee !important;
    border-bottom: 1px solid #000000 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .title-style-grey .section-header-title {
    color: #000000 !important;
  }

  .title-style-badge .section-header {
    background: transparent !important;
    border-bottom: none !important;
    padding: 0 6px 0 0 !important;
    height: 20px !important;
    align-items: stretch !important;
  }
  .title-style-badge .section-header-left {
    flex: 0 1 auto !important;
    align-items: stretch !important;
  }
  .title-style-badge .section-header-title {
    background: #000000 !important;
    color: #ffffff !important;
    padding: 0 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    font-size: 7.5pt !important;
    font-weight: 700 !important;
    letter-spacing: 0.05em !important;
    width: fit-content !important;
    margin: 0 !important;
    line-height: 1 !important;
    border-radius: 0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .border-style-rounded.title-style-badge .section-header-title,
  .border-style-rounded .title-style-badge .section-header-title,
  .title-style-badge.border-style-rounded .section-header-title,
  .title-style-badge .border-style-rounded .section-header-title {
    border-radius: 0 0 5px 0 !important;
    border-top-left-radius: 5px !important;
  }

  .border-style-square.title-style-badge .section-header-title,
  .border-style-square .title-style-badge .section-header-title,
  .border-style-left-border.title-style-badge .section-header-title,
  .border-style-left-border .title-style-badge .section-header-title,
  .border-style-invisible.title-style-badge .section-header-title,
  .border-style-invisible .title-style-badge .section-header-title {
    border-radius: 0 !important;
  }

  .title-style-text .section-header {
    background: transparent !important;
    border-bottom: none !important;
    padding: 3px 6px 1px 6px !important;
  }
  .title-style-text .section-header-title {
    color: #000000 !important;
    font-weight: 800 !important;
  }

  .title-style-underline .section-header {
    background: transparent !important;
    border-bottom: 1.5px solid #000000 !important;
    padding: 2px 6px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .title-style-underline .section-header-title {
    color: #000000 !important;
    font-weight: 800 !important;
  }

  .section-header {
    background: #eeeeee !important;
    border-bottom: 1px solid #000000 !important;
    color: #000000 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .section-header-title {
    font-size: 8.5pt !important;
    font-weight: 700 !important;
    letter-spacing: 0.05em !important;
  }

  .section-content {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .cs-table th {
    background: #eeeeee !important;
    border-bottom: 1px solid #000000 !important;
    color: #000000 !important;
    font-weight: 700 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cs-table tr:nth-child(even) {
    background: #f7f7f7 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cs-table td {
    border-bottom: 1px solid #cccccc !important;
    color: #000000 !important;
  }

  code, kbd {
    color: #000000 !important;
    border-color: #777777 !important;
    background: #f2f2f2 !important;
  }

  /* Content Themes in Print */
  .content-style-minimal .cs-table {
    border-top: 1.5px solid #000000 !important;
    border-bottom: 1.5px solid #000000 !important;
  }
  .content-style-minimal .cs-table th {
    background: transparent !important;
    border-bottom: 1px solid #000000 !important;
  }
  .content-style-minimal .cs-table td {
    background: transparent !important;
    border-bottom: 1px solid #e0e0e0 !important;
  }
  .content-style-minimal .cs-table tr:nth-child(even) td {
    background: transparent !important;
  }
  .content-style-minimal code {
    background: transparent !important;
    border: none !important;
  }
  .content-style-minimal kbd {
    background: transparent !important;
    border: 1px solid #777777 !important;
    box-shadow: none !important;
  }

  .content-style-grid .cs-table {
    border: 1px solid #000000 !important;
  }
  .content-style-grid .cs-table th {
    background: #e4e4e7 !important;
    border: 1px solid #000000 !important;
  }
  .content-style-grid .cs-table td {
    border: 1px solid #000000 !important;
  }
  .content-style-grid .cs-table tr:nth-child(even) td {
    background: #f4f4f4 !important;
  }
  .content-style-grid kbd {
    background: #ffffff !important;
    border: 1px solid #000000 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  .content-style-modern .cs-table th {
    background: transparent !important;
    border-bottom: 1.5px solid #000000 !important;
    color: #000000 !important;
  }
  .content-style-modern .cs-table td {
    background: transparent !important;
    border-bottom: 1px solid #e0e0e0 !important;
  }
  .content-style-modern .cs-table tr:nth-child(even) td {
    background: transparent !important;
  }
  .content-style-modern kbd {
    background: #f2f2f2 !important;
    border: 1px solid #888888 !important;
    border-radius: 999px !important;
    box-shadow: none !important;
  }
}
