/* ============================================================
   @media print — controls how the sheet renders to PDF / paper.
   ============================================================ */

@page {
  size: A4;
  margin: 2cm;
}

.sheet[data-margins='narrow'] { --print-margin: 1.4cm; }
.sheet[data-margins='normal'] { --print-margin: 2cm; }
.sheet[data-margins='wide']   { --print-margin: 2.8cm; }

@media print {
  html, body {
    background: #fff !important;
    color: #000 !important;
  }

  /* Hide everything except the sheet itself. */
  .app-header,
  .panel--browser,
  .panel__head,
  .sheet__footer,
  .source-card__actions,
  .source-card__drag,
  .modal,
  .toast { display: none !important; }

  /* Smart page-break: keep the source title with the first lines of
     its body. Without this a page can end with a lone title and push
     the whole text to the next page. */
  .source-card__head {
    page-break-after: avoid;
    break-after: avoid;
  }
  .source-card__text {
    widows: 3;
    orphans: 3;
  }

  body { display: block; }
  .app-main { display: block; padding: 0; }

  .panel,
  .panel--sheet {
    border: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    background: #fff !important;
    width: 100%;
    max-width: none;
  }

  .sheet {
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
  }

  /* Top row: בס"ד / date — only visible in print, FIRST line on page. */
  .sheet__print-header {
    display: flex !important;
    justify-content: space-between;
    align-items: baseline;
    margin: 0 0 0.3cm 0;
    font-family: 'Frank Ruhl Libre', serif;
    font-size: 11pt;
    color: #222;
  }
  .sheet__print-header-right { text-align: right; }
  .sheet__print-header-left  { text-align: left; direction: ltr; }
  .sheet__print-header > span:empty { display: none; }

  /* Title — sits BELOW the chip row but ABOVE the sources. */
  .sheet__print-title {
    display: block !important;
    text-align: center;
    font-family: 'Frank Ruhl Libre', serif;
    font-size: 18pt;
    font-weight: 700;
    margin: 0 0 0.8cm 0;
    padding-bottom: 0.3cm;
    border-bottom: 1px solid #000;
  }
  /* Suppress the old pseudo-element title (it would appear *above* the
     print-header because pseudo-elements render at the start of the
     element they're on). */
  .sheet::before { display: none !important; content: '' !important; }

  .source-list {
    gap: 0.7cm;
  }

  .source-card {
    border: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    /* Allow long sources to overflow to the next page rather than
       leaving the previous page blank when they don't fit. */
  }

  /* Divider line between sources — gated by the user setting.
     Use border-top: 0 explicitly in the "off" case so it wins against
     any later rule that might set a border (e.g. bw-high-contrast). */
  .sheet[data-show-dividers='true'] .source-card + .source-card {
    border-top: 1px solid #999 !important;
    padding-top: 0.5cm !important;
  }
  .sheet[data-show-dividers='false'] .source-card + .source-card {
    border-top: 0 !important;
    padding-top: 0.5cm !important;
  }

  .source-card__head { gap: 0.4em; }

  .source-card__badge { display: none; }

  .source-card__number {
    color: #000 !important;
    font-weight: 700;
  }

  .source-card__title {
    font-family: 'Frank Ruhl Libre', serif;
    font-size: 13pt;
    font-weight: 700;
    color: #000 !important;
    border: 0 !important;
    background: transparent !important;
    padding: 0 !important;
  }

  .source-card__text {
    font-family: 'Frank Ruhl Libre', serif;
    color: #000 !important;
    border: 0 !important;
    background: transparent !important;
    padding: 0 !important;
    line-height: 1.7;
  }

  /* Hide number column when disabled */
  .sheet[data-show-numbering='false'] .source-card__number { display: none !important; }
}
