/* Invoice print — full-width, readable on A4 and A5 */

@page {
  size: auto;
  margin: 7mm;
}

/* Screen preview inside modal */
.print-preview-frame {
  background: #d0d4da;
  padding: 1rem;
  border-radius: 8px;
  overflow: auto;
  max-height: 72vh;
}

.print-preview-frame .print-invoice {
  width: 100%;
  max-width: min(148mm, 100%);
  margin: 0 auto;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.2);
}

/* Mobile / narrow screen: keep preview readable inside modal */
@media (max-width: 900px) {
  .print-preview-frame {
    padding: 0.5rem;
    max-height: none;
    overflow-x: hidden;
    background: transparent;
  }

  .print-preview-frame .print-invoice {
    max-width: 100%;
    width: 100%;
    box-shadow: none;
    font-size: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 8px;
  }

  .print-preview-frame .inv-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .print-preview-frame .inv-logo,
  .print-preview-frame .inv-logo-fallback {
    width: 40px;
    height: 40px;
    font-size: 13px;
  }

  .print-preview-frame .inv-shop-name {
    font-size: 15px;
  }

  .print-preview-frame .inv-meta {
    min-width: 0;
    width: 100%;
  }

  .print-preview-frame .inv-info {
    grid-template-columns: 1fr;
  }

  .print-preview-frame .inv-bottom {
    grid-template-columns: 1fr;
  }

  .print-preview-frame .inv-signatures {
    gap: 16px;
    margin-top: 16px;
  }

  .print-preview-frame .inv-items {
    table-layout: auto;
  }

  .print-preview-frame .inv-items th,
  .print-preview-frame .inv-items td {
    padding: 4px 3px;
    font-size: 9px;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .print-preview-frame .col-row { width: auto; }
  .print-preview-frame .col-title { width: auto; }
  .print-preview-frame .col-qty { width: auto; }
  .print-preview-frame .col-price,
  .print-preview-frame .col-amount {
    width: auto;
    white-space: normal;
    font-size: 8.5px;
  }

  .print-preview-frame .inv-totals td {
    font-size: 10px;
    padding: 3px 2px;
  }

  .print-preview-frame .inv-totals td:last-child {
    white-space: normal;
    font-size: 10px;
  }

  .print-preview-frame .inv-totals tr.total td {
    font-size: 11px;
  }

  .print-preview-frame .inv-plate-body {
    font-size: 11px;
    padding: 3px 6px;
  }

  /* Stack item rows as cards on narrow preview */
  .print-preview-frame .inv-items thead {
    display: none;
  }

  .print-preview-frame .inv-items,
  .print-preview-frame .inv-items tbody,
  .print-preview-frame .inv-items tr,
  .print-preview-frame .inv-items td {
    display: block;
    width: 100%;
  }

  .print-preview-frame .inv-items tr {
    border: 1px solid #bbb;
    border-radius: 4px;
    margin-bottom: 6px;
    overflow: hidden;
    background: #fff;
  }

  .print-preview-frame .inv-items td {
    border: none;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    padding: 5px 8px;
    font-size: 10px;
    text-align: left;
  }

  .print-preview-frame .inv-items td:last-child {
    border-bottom: none;
  }

  .print-preview-frame .inv-items td::before {
    content: attr(data-label);
    font-weight: 700;
    color: #666;
    flex-shrink: 0;
  }

  .print-preview-frame .inv-items .col-row {
    background: #f3f3f3;
  }

  .print-preview-frame .col-price,
  .print-preview-frame .col-amount {
    direction: ltr;
  }
}

.print-invoice {
  --inv-accent: #c41e3a;
  --inv-border: #999;
  --inv-muted: #555;
  font-family: 'Vazirmatn', Tahoma, Arial, sans-serif;
  direction: rtl;
  color: #111;
  background: #fff;
  box-sizing: border-box;
  width: 100%;
  font-size: 11px;
  line-height: 1.45;
  padding: 0;
}

.print-invoice *,
.print-invoice *::before,
.print-invoice *::after {
  box-sizing: border-box;
}

/* ===== Header ===== */
.print-invoice .inv-header {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 10px;
  border-bottom: 2.5px solid var(--inv-accent);
  padding-bottom: 8px;
  margin-bottom: 10px;
  width: 100%;
}

.print-invoice .inv-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.print-invoice .inv-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 4px;
}

.print-invoice .inv-logo-fallback {
  background: var(--inv-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
}

.print-invoice .inv-shop-name {
  font-size: 18px;
  font-weight: 800;
  color: var(--inv-accent);
  line-height: 1.2;
}

.print-invoice .inv-shop-info {
  font-size: 10px;
  color: var(--inv-muted);
  margin-top: 2px;
}

.print-invoice .inv-meta {
  flex-shrink: 0;
  border: 1px solid #ccc;
  background: #f5f5f5;
  border-radius: 4px;
  padding: 6px 10px;
  min-width: 150px;
}

.print-invoice .inv-title {
  font-weight: 800;
  color: var(--inv-accent);
  font-size: 13px;
  margin-bottom: 4px;
  text-align: center;
}

.print-invoice .inv-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11px;
  margin-top: 2px;
}

.print-invoice .inv-meta-row span {
  color: var(--inv-muted);
}

/* ===== Customer / Vehicle ===== */
.print-invoice .inv-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
  width: 100%;
}

.print-invoice .inv-block {
  border: 1px solid var(--inv-border);
  border-radius: 4px;
  padding: 7px 9px;
  background: #fafafa;
}

.print-invoice .inv-block h4 {
  margin: 0 0 4px;
  font-size: 10px;
  color: var(--inv-muted);
  font-weight: 700;
  border-bottom: 1px solid #e5e5e5;
  padding-bottom: 3px;
}

.print-invoice .inv-block-main {
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 3px;
}

.print-invoice .inv-plate-row {
  margin: 5px 0;
}

.print-invoice .inv-plate {
  display: inline-flex;
  align-items: stretch;
  border: 1.5px solid #1a365d;
  border-radius: 3px;
  overflow: hidden;
  background: #fff;
  color: #111;
  font-weight: 800;
  line-height: 1;
}

.print-invoice .inv-plate-iran {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #1e4f9b;
  color: #fff;
  padding: 3px 5px;
  min-width: 28px;
}

.print-invoice .inv-plate-iran-label {
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.print-invoice .inv-plate-iran-code {
  font-size: 11px;
  font-weight: 800;
}

.print-invoice .inv-plate-body {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  font-size: 13px;
}

.print-invoice .inv-plate-letter {
  min-width: 1em;
  text-align: center;
}

.print-invoice .inv-vehicle-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  color: #333;
}

/* ===== Items table ===== */
.print-invoice .inv-items {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
  table-layout: fixed;
}

.print-invoice .inv-items th,
.print-invoice .inv-items td {
  border: 1px solid var(--inv-border);
  padding: 5px 6px;
  text-align: right;
  vertical-align: middle;
  font-size: 11px;
}

.print-invoice .inv-items th {
  background: #ececec;
  font-weight: 700;
  font-size: 10px;
}

.print-invoice .col-row { width: 8%; text-align: center; }
.print-invoice .col-title { width: 42%; }
.print-invoice .col-qty { width: 10%; text-align: center; }
.print-invoice .col-price,
.print-invoice .col-amount {
  width: 20%;
  white-space: nowrap;
  direction: ltr;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.print-invoice .tag {
  display: inline-block;
  font-size: 9px;
  color: #555;
  background: #eee;
  border-radius: 2px;
  padding: 0 4px;
  font-weight: 600;
}

.print-invoice .text-center { text-align: center; }

/* ===== Bottom ===== */
.print-invoice .inv-bottom {
  display: grid;
  grid-template-columns: 1fr 42%;
  gap: 10px;
  align-items: start;
  width: 100%;
  margin-bottom: 14px;
}

.print-invoice .inv-notes {
  font-size: 11px;
  padding: 6px 8px;
  background: #fffbea;
  border: 1px dashed #c9a227;
  border-radius: 4px;
  margin-bottom: 8px;
  min-height: 36px;
}

.print-invoice .inv-notes-empty {
  background: transparent;
  border-color: transparent;
  min-height: 0;
  padding: 0;
  margin: 0;
}

.print-invoice .inv-footer {
  font-size: 10px;
  color: var(--inv-muted);
  line-height: 1.5;
}

.print-invoice .inv-totals-wrap {
  border: 1px solid var(--inv-border);
  border-radius: 4px;
  padding: 4px 6px;
  background: #fafafa;
}

.print-invoice .inv-totals {
  width: 100%;
  border-collapse: collapse;
}

.print-invoice .inv-totals td {
  border: none;
  padding: 3px 4px;
  font-size: 11px;
}

.print-invoice .inv-totals td:first-child {
  color: var(--inv-muted);
  white-space: nowrap;
}

.print-invoice .inv-totals td:last-child {
  text-align: left;
  direction: ltr;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.print-invoice .inv-totals tr.total td {
  font-weight: 800;
  font-size: 13px;
  border-top: 2px solid #222;
  padding-top: 6px;
  color: #000;
}

.print-invoice .inv-totals tr.remain td {
  color: var(--inv-accent);
  font-weight: 800;
}

/* ===== Signatures ===== */
.print-invoice .inv-signatures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 28px;
  width: 100%;
  page-break-inside: avoid;
}

.print-invoice .inv-signature {
  text-align: center;
  border-top: 1px solid #777;
  padding-top: 6px;
  font-size: 11px;
  color: #444;
  min-height: 48px;
}

/* ===== Print media ===== */
@media print {
  html, body {
    background: #fff !important;
    color: #000 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }

  .app-shell,
  .modal-overlay,
  .toast-container,
  .loading-screen {
    display: none !important;
  }

  #print-area {
    display: block !important;
    position: static !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    visibility: visible !important;
  }

  #print-area.hidden {
    display: none !important;
  }

  .print-invoice {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 11px !important;
    box-shadow: none !important;
  }

  .print-invoice .inv-shop-name { font-size: 17px !important; }
  .print-invoice .inv-block-main { font-size: 12px !important; }
  .print-invoice .inv-items th,
  .print-invoice .inv-items td { font-size: 11px !important; padding: 5px 6px !important; }
  .print-invoice .inv-totals tr.total td { font-size: 13px !important; }

  .print-invoice .inv-logo,
  .print-invoice .inv-logo-fallback {
    width: 46px !important;
    height: 46px !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .print-invoice .inv-plate-iran,
  .print-invoice .inv-items th,
  .print-invoice .inv-logo-fallback,
  .print-invoice .inv-meta {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .print-invoice .inv-schematic {
    break-inside: avoid;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px dashed #999;
  }

  .print-invoice .inv-schematic-title {
    font-size: 10px;
    font-weight: 700;
    margin-bottom: 4px;
  }

  .print-invoice .vs-biw-print {
    position: relative;
    aspect-ratio: 1024 / 400;
    width: 100%;
    overflow: hidden;
    background: #f3ead8;
  }

  .print-invoice .vs-biw-print .vs-biw-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill;
  }

  .print-invoice .vs-biw-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  .print-invoice .vs-biw-zone {
    fill: transparent;
  }

  .print-invoice .vs-biw-zone.is-active {
    fill: rgba(196, 30, 58, 0.4);
    stroke: #c41e3a;
    stroke-width: 2;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .print-invoice .inv-schematic-legend {
    font-size: 9px;
    color: #555;
    margin-top: 3px;
  }
}
