/* Print styles: Letter documents (SPEC §8.5) and the layout-independent tag page rules
   (SPEC §6.8). Screen rules here shape only the on-screen print preview (DESIGN §7.22). App
   chrome is hidden by class (.app-nav, .no-print), never by element name. */

/* ---------- Letter documents ---------- */
@page {
  size: letter;
  margin: 0.5in;

  @bottom-right {
    content: 'Page ' counter(page) ' of ' counter(pages);
    font-family: 'Public Sans', sans-serif;
    font-size: 8pt;
    color: #444444;
  }
}

/* ---------- Print preview on screen (DESIGN §7.22) ----------
   The toolbar is velvet: Back first, what is printed and how, then the page actions and Print.
   The Letter sheet sits on a grey stage and is zoomed to fit a narrow screen
   (lib/print.js sets --sheet-zoom); print output never sees the stage or the zoom. */
.print-main > .page {
  max-width: none;
}

.print-view {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--preview-ground);
}

.print-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  min-height: 56px;
  padding: 8px 16px;
  background: var(--velvet);
  color: var(--on-velvet);
}

.print-toolbar :focus-visible {
  outline-color: var(--on-velvet);
}

.print-toolbar-text {
  flex: 1 1 20rem;
  min-width: 0;
}

.print-toolbar-title {
  font-size: 14px;
  font-weight: 700;
  line-height: 20px;
}

.print-toolbar-note {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  color: var(--on-velvet-muted);
  font-size: 13px;
  line-height: 18px;
}

.print-toolbar-note .icon {
  width: 16px;
  height: 16px;
  margin-top: 1px;
}

.print-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Enabled buttons only: a disabled one keeps the shared .btn:disabled look. */
.print-toolbar .btn-secondary:not(:disabled):not([aria-disabled='true']) {
  background: transparent;
  border-color: var(--find-edge);
  color: var(--on-velvet);
}

.print-toolbar > .btn:not(:disabled):hover,
.print-toolbar-actions > .btn-secondary:not(:disabled):hover {
  background: var(--velvet-2);
}

.print-toolbar .btn-primary:not(:disabled) {
  background: #FFFFFF;
  border-color: #FFFFFF;
  color: var(--velvet);
}

.print-toolbar .btn-primary:not(:disabled):hover {
  background: var(--brand-tint);
  border-color: var(--brand-tint);
}

.print-stage {
  overflow-x: auto;
  padding: 24px 16px 48px;
}

/* A document that cannot be shown: the message sits on the stage like a sheet would. */
.print-message {
  width: min(100%, 40rem);
  margin: 0 auto;
}

@media screen {
  .print-doc {
    width: 8.5in;
    min-height: 11in;
    margin: 0 auto;
    padding: 0.5in;
    zoom: var(--sheet-zoom, 1);
    box-shadow: 0 1px 3px rgba(20, 33, 58, 0.16);
  }
}

@media (max-width: 40rem) {
  .print-toolbar {
    position: static;
  }
}

/* The Letter sheet itself (screen and print). */
.print-doc {
  position: relative;
  background: #FFFFFF;
  color: #000000;
  font-family: 'Public Sans', sans-serif;
  font-size: 10pt;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.doc-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12pt 24pt;
  padding-bottom: 10pt;
  margin-bottom: 12pt;
  border-bottom: 1.5pt solid #000000;
}

.doc-issuer {
  min-width: 0;
  flex: 1 1 14rem;
}

.doc-logo {
  display: block;
  max-width: 1.6in;
  max-height: 0.8in;
  width: auto;
  margin-bottom: 6pt;
  object-fit: contain;
}

.doc-company {
  font-weight: 700;
  font-size: 12pt;
}

.doc-title-block {
  min-width: 0;
  text-align: right;
}

.doc-title {
  color: #000000;
  font-family: 'Bodoni Moda', Georgia, serif;
  font-weight: 600;
  font-size: 22pt;
  line-height: 1.1;
}

.doc-meta {
  display: grid;
  gap: 2pt;
  margin: 6pt 0 0;
}

.doc-meta > div {
  display: flex;
  justify-content: flex-end;
  gap: 8pt;
}

.doc-meta dt {
  color: #444444;
}

.doc-meta dd {
  margin: 0;
  font-weight: 700;
}

/* break-word, not the inherited anywhere: cells keep word-width minimums, so a wide line
   table does not split headers and descriptions mid-word. */
.doc-lines {
  width: 100%;
  overflow-wrap: break-word;
  border-collapse: collapse;
  margin: 12pt 0;
  font-variant-numeric: tabular-nums;
}

.doc-lines thead {
  display: table-header-group;
}

.doc-lines th,
.doc-lines td {
  padding: 4pt 6pt;
  border-bottom: 0.75pt solid #999999;
  text-align: left;
  vertical-align: top;
}

.doc-lines th {
  border-bottom: 1.25pt solid #000000;
  font-weight: 700;
}

.doc-lines .num {
  text-align: right;
  white-space: nowrap;
}

.totals {
  margin-left: auto;
  width: min(100%, 3.4in);
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.totals th,
.totals td {
  padding: 2pt 6pt;
  text-align: right;
  font-weight: 400;
  white-space: nowrap;
}

.totals .total-row th,
.totals .total-row td {
  border-top: 1.25pt solid #000000;
  font-weight: 700;
}

.terms {
  margin-top: 14pt;
  font-size: 8.5pt;
  white-space: pre-line;
}

.signatures {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24pt;
  margin-top: 30pt;
}

.signatures > div {
  padding-top: 4pt;
  border-top: 0.75pt solid #000000;
  font-size: 8.5pt;
}

.void-banner {
  margin: 0 0 12pt;
  padding: 6pt 10pt;
  background: #000000;
  color: #FFFFFF;
  font-weight: 700;
  font-size: 11pt;
  letter-spacing: 0.02em;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.void-watermark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
  color: rgba(0, 0, 0, 0.1);
  font-family: 'Public Sans', sans-serif;
  font-weight: 700;
  font-size: 140pt;
  letter-spacing: 0.08em;
}

.void-watermark span {
  transform: rotate(-32deg);
}

/* ---------- Tag pages (SPEC §6.8; faces, fields and rotation transforms are per layout) ---------- */
/* The Letter page number would otherwise be laid out on the label. */
@page tag {
  size: 100mm 15mm;
  margin: 0;

  @bottom-right {
    content: none;
  }
}

@page tag-portrait {
  size: 15mm 100mm;
  margin: 0;

  @bottom-right {
    content: none;
  }
}

.tag-page {
  page: tag;
  position: relative;
  width: 100mm;
  height: 15mm;
  overflow: hidden;
  break-after: page;
  background: #FFFFFF;
  color: #000000;
  font-family: 'Public Sans', sans-serif;
  font-weight: 700;
}

/* tag_rotation 90 / 270: the page turns portrait; the 100 x 15 box inside is rotated by transform. */
.tag-page[data-orient='portrait'] {
  page: tag-portrait;
  width: 15mm;
  height: 100mm;
}

.tag-page:last-child {
  break-after: auto;
}

@media screen {
  .tag-page {
    margin: 0 0 4mm;
    outline: 1px dashed var(--field-border, #767F91);
  }
}

/* ---------- Print ---------- */
@media print {
  html,
  body {
    margin: 0;
    padding: 0;
    background: #FFFFFF;
  }

  body {
    min-height: 0;
    color: #000000;
  }

  .app-nav,
  .app-topbar,
  .no-print,
  .toast-region,
  .skip-link {
    display: none !important;
  }

  .app {
    display: block;
    min-height: 0;
  }

  .app-main,
  .print-main,
  .bare-main {
    min-height: 0;
    padding: 0;
  }

  /* The shell's flex page column would put its gap between tag pages and doc blocks. */
  .page {
    display: block;
    max-width: none;
    gap: 0;
  }

  .print-view {
    display: block;
    min-height: 0;
    padding: 0;
    background: none;
  }

  .print-stage {
    overflow: visible;
    padding: 0;
  }

  .print-doc {
    width: auto;
    min-height: 0;
    padding: 0;
    box-shadow: none;
    zoom: 1 !important;
  }

  .void-watermark {
    position: fixed;
  }

  tr,
  .totals,
  .terms,
  .signatures {
    break-inside: avoid;
  }

  .doc-header {
    break-after: avoid;
  }

  a {
    color: inherit;
    text-decoration: none;
  }
}
