/* Hermes Tenkhah dedicated print module v1
   Owns the full A4 preview and print layout for the Tenkhah panel.
   Print ownership is intentionally centralized in this module.
*/

#tenkhah-print-root {
  position: fixed;
  top: 0;
  left: -10000px;
  width: 210mm;
  height: 297mm;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
  background: #fff;
}

.tenkhah-print-preview-shell {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  padding: 14px;
  border: 1px solid #dbe3ef;
  border-radius: 18px;
  background: #eef2f7;
  box-sizing: border-box;
}

.tenkhah-print-controls {
  grid-template-columns: repeat(3, minmax(170px, 1fr)) !important;
  align-items: end !important;
}

.tenkhah-print-controls #print-number[readonly] {
  direction: ltr;
  text-align: left;
  font-weight: 900;
  background: #f8fafc;
  color: #111827;
}

.tenkhah-print-sheet,
.tenkhah-print-sheet * {
  box-sizing: border-box;
}

.tenkhah-print-sheet {
  width: 210mm;
  min-width: 210mm;
  max-width: 210mm;
  height: 297mm;
  min-height: 297mm;
  max-height: 297mm;
  margin: 0 auto;
  padding: 10mm;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  color: #111827;
  border: 0;
  box-shadow: 0 8px 30px rgba(15, 23, 42, .12);
  direction: rtl;
  font-family: Vazirmatn, Tahoma, Arial, sans-serif;
}

.tenkhah-print-header {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58mm;
  align-items: stretch;
  gap: 5mm;
  min-height: 20mm;
  margin: 0 0 3mm;
  padding: 0 0 3mm;
  border-bottom: 1px solid #94a3b8;
}

.tenkhah-print-title {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tenkhah-print-title h1 {
  width: 100%;
  margin: 0;
  padding: 0;
  color: #111827;
  font-size: 21pt;
  line-height: 1.2;
  font-weight: 950;
  text-align: center;
  white-space: nowrap;
}

.tenkhah-print-meta {
  min-width: 58mm;
  max-width: 58mm;
  min-height: 17mm;
  padding: 2mm 3mm;
  display: grid;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 1mm;
  border: 1px solid #94a3b8;
  border-radius: 2.5mm;
  background: #fff;
}

.tenkhah-print-meta-row {
  min-width: 0;
  display: grid;
  grid-template-columns: 25mm minmax(0, 1fr);
  align-items: center;
  column-gap: 2mm;
  white-space: nowrap;
  overflow: hidden;
}

.tenkhah-print-meta-row span,
.tenkhah-print-meta-row b {
  display: block;
  min-width: 0;
  margin: 0;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
}

.tenkhah-print-meta-row span {
  color: #475569;
  font-size: 9pt;
  font-weight: 850;
}

.tenkhah-print-meta-row b {
  color: #111827;
  font-size: 9.5pt;
  font-weight: 950;
  direction: ltr;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.tenkhah-print-period {
  flex: 0 0 auto;
  margin: 0 0 2.5mm;
  padding: 2mm 3mm;
  border: 1px solid #cbd5e1;
  border-radius: 2mm;
  background: #fff;
  color: #1f2937;
  text-align: center;
  font-size: 9.5pt;
  font-weight: 900;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tenkhah-print-summary {
  flex: 0 0 auto;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2mm;
  margin: 0 0 2.5mm;
}

.tenkhah-print-summary > div {
  min-width: 0;
  min-height: 15mm;
  padding: 2mm;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid #cbd5e1;
  border-radius: 2mm;
  background: #fff;
}

.tenkhah-print-summary span,
.tenkhah-print-summary b {
  white-space: nowrap;
  overflow: hidden;
}

.tenkhah-print-summary span {
  color: #475569;
  font-size: 8.2pt;
  line-height: 1.2;
}

.tenkhah-print-summary b {
  margin-top: 1mm;
  color: #111827;
  font-size: 10pt;
  font-weight: 950;
  direction: ltr;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.tenkhah-print-summary .manual-opening {
  border-color: #fda4af;
}

.tenkhah-print-table-wrap {
  flex: 0 0 auto;
  width: 100%;
  overflow: visible;
}

.tenkhah-print-table {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  table-layout: fixed;
  border-collapse: collapse;
  background: #fff;
}

.tenkhah-print-table thead {
  display: table-header-group;
}

.tenkhah-print-table tr {
  break-inside: avoid;
  page-break-inside: avoid;
}

.tenkhah-print-table th,
.tenkhah-print-table td {
  padding: 1.2mm 1.4mm;
  border: 1px solid #94a3b8;
  background: #fff;
  color: #111827;
  font-size: 8.2pt;
  line-height: 1.25;
  vertical-align: middle;
}

.tenkhah-print-table th {
  font-weight: 950;
  white-space: nowrap;
}

.tenkhah-print-table th:nth-child(1),
.tenkhah-print-table td:nth-child(1) {
  width: 9mm;
  text-align: center;
}

.tenkhah-print-table th:nth-child(2),
.tenkhah-print-table td:nth-child(2) {
  width: 21mm;
  white-space: nowrap;
}

.tenkhah-print-table th:nth-child(3),
.tenkhah-print-table td:nth-child(3) {
  width: auto;
}

.tenkhah-print-table th:nth-child(4),
.tenkhah-print-table td:nth-child(4),
.tenkhah-print-table th:nth-child(5),
.tenkhah-print-table td:nth-child(5),
.tenkhah-print-table th:nth-child(6),
.tenkhah-print-table td:nth-child(6) {
  width: 25mm;
  direction: ltr;
  text-align: right;
  white-space: nowrap;
  font-size: 8pt;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.tenkhah-print-desc {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tenkhah-print-empty {
  height: 14mm;
  text-align: center;
  color: #64748b;
}

.tenkhah-print-flex-space {
  flex: 1 1 auto;
  min-height: 3mm;
  background: #fff;
}

.tenkhah-print-footer {
  flex: 0 0 auto;
  margin-top: auto;
  break-inside: avoid;
  page-break-inside: avoid;
  background: #fff;
}

.tenkhah-print-balances {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1.5mm;
  margin: 0;
  padding: 2mm;
  border: 1px solid #94a3b8;
  border-radius: 2mm;
  background: #fff;
  color: #111827;
  font-size: 8.2pt;
  line-height: 1.25;
}

.tenkhah-print-balances > span {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .8mm;
  white-space: nowrap;
  overflow: hidden;
}

.tenkhah-print-balances b {
  direction: ltr;
  text-align: right;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}

.tenkhah-print-signatures {
  min-height: 31mm;
  margin: 5mm 0 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5mm;
  align-items: stretch;
  background: #fff;
}

.tenkhah-print-signature {
  min-width: 0;
  min-height: 31mm;
  padding: 3mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  border: 1px solid #94a3b8;
  border-radius: 2mm;
  background: #fff;
  color: #111827;
  text-align: center;
}

.tenkhah-print-signature strong {
  font-size: 9.5pt;
  font-weight: 950;
  white-space: nowrap;
}

.tenkhah-print-signature span {
  margin-top: auto;
  padding-top: 2mm;
  color: #64748b;
  font-size: 8pt;
  white-space: nowrap;
}

@media (max-width: 840px) {
  .tenkhah-print-controls {
    grid-template-columns: 1fr !important;
  }

  .tenkhah-print-preview-shell {
    padding: 8px;
  }
}

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

  html,
  body {
    width: 210mm !important;
    height: 297mm !important;
    min-width: 210mm !important;
    min-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: #fff !important;
    background-image: none !important;
  }

  html::before,
  html::after,
  body::before,
  body::after {
    display: none !important;
    content: none !important;
    background: none !important;
  }

  body.tenkhah-printing > *:not(#tenkhah-print-root) {
    display: none !important;
  }

  body.tenkhah-printing #tenkhah-print-root {
    position: static !important;
    inset: auto !important;
    display: block !important;
    visibility: visible !important;
    pointer-events: auto !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: 0 !important;
    overflow: hidden !important;
    background: #fff !important;
    background-image: none !important;
  }

  body.tenkhah-printing .tenkhah-print-sheet {
    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;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
    background-image: none !important;
    color: #111827 !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  body.tenkhah-printing .tenkhah-print-sheet,
  body.tenkhah-printing .tenkhah-print-sheet * {
    text-shadow: none !important;
    box-shadow: none !important;
  }

  body.tenkhah-printing .tenkhah-print-footer {
    margin-top: auto !important;
  }
}
