/* ==========================================================================
   Square Ibis — print: shipping labels (A6 thermal / A4 4-up) and A4 documents
   Black on white, physical units (mm/pt), nothing decorative in print.
   ========================================================================== */

body[data-layout="print"] .aurora, body[data-layout="print"] .grain { display: none; }
body[data-layout="print"] { background: #e7e8ef; }
:root[data-theme="dark"] body[data-layout="print"] { background: #14161e; }

.print-page { position: relative; z-index: 1; min-height: 100vh; padding: 78px 20px 48px; }

.print-toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--panel-solid) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-strong);
  color: var(--text);
}
.pt-group { display: flex; align-items: center; gap: 6px; }
.pt-group svg { width: 18px; height: 18px; color: var(--accent); }
.pt-count { font-size: 12.5px; color: var(--text-3); margin-inline-start: 4px; }
.pt-spacer { flex: 1; }
.pt-chip { height: 32px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-size: 12.5px; font-weight: 500; }
.pt-chip:hover { color: var(--text); background: var(--surface-2); }
.pt-chip[aria-pressed="true"] { color: #fff; background: var(--grad); border-color: transparent; }

.print-empty { text-align: center; color: var(--text-2); margin-top: 20vh; }
.print-error { display: flex; justify-content: center; padding-top: 12vh; }
.pe-box { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 420px; text-align: center; color: var(--text); }
.pe-box svg { width: 32px; height: 32px; color: var(--rose); }
.pe-box h1 { font-size: 20px; }
.pe-box p { color: var(--text-2); }

/* ---------- sheets ---------- */

.sheets { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.sheet { background: #fff; color: #000; box-shadow: 0 10px 34px -12px rgba(0, 0, 0, .45); }
.sheet.a6 { width: 100mm; height: 150mm; overflow: hidden; }
.sheet.a4 { width: 210mm; height: 297mm; display: grid; grid-template-columns: 105mm 105mm; grid-template-rows: 148.5mm 148.5mm; overflow: hidden; }
.sheet.a4 .cell { position: relative; overflow: hidden; outline: .2mm dashed #9a9a9a; outline-offset: -.1mm; }
.sheet.a4 .label { width: 105mm; height: 148.5mm; }

/* ---------- label ---------- */

.label {
  box-sizing: border-box;
  width: 100mm;
  height: 150mm;
  padding: 3.2mm 3.6mm 2.6mm;
  display: flex;
  flex-direction: column;
  gap: 1.6mm;
  background: #fff;
  color: #000;
  font-family: "Inter", "IBM Plex Sans Arabic", Arial, sans-serif;
  font-size: 8.5pt;
  line-height: 1.22;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
  overflow: hidden;
}
.label[lang="ar"] { font-family: "IBM Plex Sans Arabic", "Inter", Arial, sans-serif; }
.label .mono, .lb-tracking, .lb-phones { font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; }
.lb-head { display: flex; align-items: baseline; justify-content: space-between; gap: 2mm; padding-bottom: 1.2mm; border-bottom: .45mm solid #000; }

.lb-logo { height: 7mm; max-width: 24mm; object-fit: contain; align-self: center; filter: grayscale(1) contrast(1.15); }
.lb-company { font-size: 11pt; font-weight: 800; letter-spacing: -.01em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-cphone { font-size: 8.5pt; font-weight: 600; white-space: nowrap; }

.lb-code { display: flex; flex-direction: column; align-items: center; gap: .6mm; }
.lb-barcode { display: block; height: 15mm; color: #000; }
.lb-tracking { font-size: 13pt; font-weight: 700; letter-spacing: .06em; }

.lb-dest { display: grid; grid-template-columns: minmax(0, 1fr) auto; border: .55mm solid #000; }
.lb-wilaya { display: flex; flex-direction: column; justify-content: center; padding: 1.6mm 2.4mm; min-width: 0; }
.lb-wcode { font-size: 30pt; font-weight: 800; line-height: .95; letter-spacing: -.02em; }
.lb-wname { font-size: 13pt; font-weight: 800; text-transform: uppercase; line-height: 1.05; margin-top: .6mm; overflow-wrap: anywhere; }
.lb-commune { font-size: 10.5pt; font-weight: 600; margin-top: .4mm; overflow-wrap: anywhere; }
.lb-side { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1mm; padding: 1.2mm 1.6mm; border-inline-start: .55mm solid #000; }
.lb-qr { width: 21mm; height: 21mm; color: #000; display: block; }
.lb-type { font-size: 7.5pt; font-weight: 800; letter-spacing: .04em; padding: .5mm 1.5mm; border: .35mm solid #000; text-align: center; white-space: nowrap; }
.lb-type.inv, .lb-flag.inv { background: #000; color: #fff; }
.lb-deskname { font-size: 8.5pt; font-weight: 700; padding: .8mm 1.6mm; border: .35mm dashed #000; }

.lb-k { font-size: 6.8pt; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.label[lang="ar"] .lb-k { letter-spacing: 0; font-size: 7.5pt; }
.lb-ar { font-family: "IBM Plex Sans Arabic", Arial, sans-serif; font-weight: 600; letter-spacing: 0; text-transform: none; margin-inline-start: 1.5mm; }
.lb-to { display: flex; flex-direction: column; gap: .4mm; }
.lb-name { font-size: 12pt; font-weight: 800; overflow-wrap: anywhere; }
.lb-phones { font-size: 11pt; font-weight: 700; letter-spacing: .01em; }
.lb-address { font-size: 8.5pt; overflow-wrap: anywhere; max-height: 7.5mm; overflow: hidden; }

.lb-cod { display: flex; align-items: center; justify-content: space-between; gap: 2mm; padding: 1.4mm 2.4mm; border: .8mm solid #000; }
.lb-cod .lb-k { font-size: 7.5pt; max-width: 30mm; line-height: 1.15; }
.lb-amount { font-size: 22pt; font-weight: 800; letter-spacing: -.02em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.lb-amount small { font-size: 11pt; font-weight: 700; }

.lb-meta { display: flex; flex-direction: column; gap: .7mm; font-size: 8.3pt; min-height: 0; overflow: hidden; }
.lb-row { display: flex; gap: 1.5mm; align-items: baseline; min-width: 0; }
.lb-row .lb-v { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lb-row.two { justify-content: space-between; }
.lb-flags { display: flex; flex-wrap: wrap; gap: 1mm; }
.lb-flag { font-size: 6.8pt; font-weight: 800; padding: .3mm 1.3mm; border: .3mm solid #000; letter-spacing: .03em; }
.lb-note { font-size: 8pt; max-height: 7mm; overflow: hidden; }

.lb-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: baseline; gap: 2mm; padding-top: 1mm; border-top: .35mm solid #000; font-size: 7pt; }
.lb-foot > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-date { white-space: nowrap; }

/* ---------- A4 documents ---------- */

.docs { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.doc {
  box-sizing: border-box;
  width: 210mm;
  min-height: 297mm;
  padding: 12mm 12mm 10mm;
  display: flex;
  flex-direction: column;
  gap: 4mm;
  background: #fff;
  color: #000;
  font-family: "Inter", "IBM Plex Sans Arabic", Arial, sans-serif;
  font-size: 9pt;
  line-height: 1.3;
  box-shadow: 0 10px 34px -12px rgba(0, 0, 0, .45);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.doc .mono { font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8mm; padding-bottom: 3mm; border-bottom: .6mm solid #000; }
.doc-company { display: flex; flex-direction: column; gap: .6mm; font-size: 8.5pt; }
.doc-company b { font-size: 14pt; font-weight: 800; text-transform: uppercase; letter-spacing: -.01em; }
.doc-id { display: flex; flex-direction: column; align-items: flex-end; gap: 1mm; text-align: end; }
.doc-title { font-size: 15pt; font-weight: 800; letter-spacing: -.01em; }
.doc-bc { width: 52mm; height: 10mm; color: #000; display: block; }
.doc-number { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 9.5pt; font-weight: 700; letter-spacing: .05em; }
.doc-sub { font-size: 12pt; font-weight: 700; }
.doc-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2mm 6mm; margin: 0; padding: 2.5mm 3mm; border: .3mm solid #000; }
.doc-meta div { min-width: 0; }
.doc-meta dt { font-size: 6.8pt; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #333; }
.doc-meta dd { margin: .3mm 0 0; font-size: 9pt; font-weight: 600; overflow-wrap: anywhere; }
.doc-h2 { font-size: 10.5pt; font-weight: 800; margin-top: 2mm; }
.doc-note { font-size: 8.5pt; margin: 0; }

.doc-table { width: 100%; border-collapse: collapse; font-size: 8.3pt; }
.doc-table thead { display: table-header-group; }
.doc-table th { text-align: start; font-size: 6.8pt; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; padding: 1.4mm 1.2mm; border-top: .45mm solid #000; border-bottom: .45mm solid #000; }
.doc-table td { padding: 1.4mm 1.2mm; border-bottom: .2mm solid #8a8a8a; vertical-align: top; overflow-wrap: anywhere; }
.doc-table tr { break-inside: avoid; page-break-inside: avoid; }
.doc-table tfoot td { font-weight: 800; border-top: .45mm solid #000; border-bottom: .45mm solid #000; }
.doc-table small { font-size: 7.3pt; }
.doc-table .c-n { width: 7mm; text-align: center; }
.doc-table .c-r { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
.doc-table .c-box { width: 14mm; text-align: center; }
.doc-table .c-reason { width: 30mm; }
.doc-table .c-sig { width: 24mm; }
.doc-bc-sm { width: 34mm; height: 6.5mm; color: #000; display: block; }
.doc-trk { font-size: 7.5pt; font-weight: 700; margin-top: .3mm; }
.doc .box { display: inline-block; width: 4.5mm; height: 4.5mm; border: .35mm solid #000; }

.doc-summary { align-self: flex-end; width: 82mm; display: flex; flex-direction: column; border: .45mm solid #000; margin-top: 2mm; }
.doc-summary > div { display: flex; justify-content: space-between; gap: 4mm; padding: 1.4mm 2.4mm; border-bottom: .2mm solid #8a8a8a; font-size: 9pt; }
.doc-summary > div:last-child { border-bottom: 0; }
.doc-summary b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-summary .total { background: #000; color: #fff; font-size: 11pt; font-weight: 800; }
.doc-summary .warn b { text-decoration: underline; }

.doc-signs { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6mm; margin-top: auto; padding-top: 6mm; break-inside: avoid; }
.doc-sign { display: flex; flex-direction: column; gap: 1.5mm; font-size: 8pt; font-weight: 700; }
.doc-sign i { display: block; height: 20mm; border: .3mm solid #000; }
.doc-foot { display: flex; justify-content: space-between; font-size: 7pt; color: #444; padding-top: 2mm; border-top: .2mm solid #8a8a8a; }

/* ---------- print ---------- */

@media print {
  html, body, body[data-layout="print"] { background: #fff !important; }
  body[data-layout="print"] #root { z-index: auto; }
  .print-toolbar, .toasts, .loading-line { display: none !important; }
  .print-page { padding: 0; min-height: 0; }
  .sheets, .docs { display: block; gap: 0; }
  .sheet { box-shadow: none; margin: 0; break-after: page; page-break-after: always; }
  .sheet:last-child { break-after: auto; page-break-after: auto; }
  .sheet.a4 .cell { outline-color: #bbb; }
  .doc { width: auto; min-height: 0; padding: 0; box-shadow: none; break-after: page; }
  .doc:last-child { break-after: auto; }
}

@media screen and (max-width: 860px) {
  .sheets, .docs { align-items: flex-start; overflow-x: auto; }
  .print-page { padding-top: 112px; }
}
