/* ============================================================
   IMPRESSÃO — 9 TICKETS POR FOLHA A4 (grade 3x3)
   ============================================================ */
@media print {
  @page {
    size: A4 portrait;
    margin: 6mm;
  }

  body * {
    visibility: hidden;
  }

  #print-area,
  #print-area * {
    visibility: visible;
  }

  #print-area {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }

  /* Cada folha ocupa uma página inteira */
  .a4-sheet {
    width: 198mm;      /* A4 - margens (210 - 6 - 6) */
    height: 285mm;     /* A4 - margens (297 - 6 - 6) */
    page-break-after: always;
    break-after: page;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    background: #fff;
  }

  .a4-sheet:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  /* Grade 3x3 */
  .a4-grid {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 2mm;
  }

  .ticket {
    width: 100%;
    height: 100%;
    border: 1px dashed #333;
    padding: 2mm;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-family: 'Inter', sans-serif;
    color: #000;
    background: #fff;
    overflow: hidden;
    font-size: 7.5pt;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .ticket-vazio {
    border: 1px dashed #ccc;
  }

  #modal-etiqueta .modal-header,
  #modal-etiqueta .modal-footer {
    display: none !important;
  }
}

/* ============================================================
   ESTILO VISUAL DO TICKET
   ============================================================ */
.a4-sheet {
  width: 198mm;
  min-height: 285mm;
  margin: 0 auto 20px;
  padding: 6mm;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  box-sizing: border-box;
}

.a4-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 2mm;
}

.ticket {
  width: 100%;
  height: 100%;
  min-height: 90mm;
  border: 1px dashed #333;
  padding: 2mm;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-family: 'Inter', sans-serif;
  font-size: 7.5pt;
  color: #000;
  background: #fff;
  overflow: hidden;
}

.ticket-vazio {
  border: 1px dashed #ccc;
}

/* Cabeçalho */
.ticket-header {
  border-bottom: 1px solid #000;
  padding-bottom: 1mm;
  margin-bottom: 1mm;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 4px;
  flex-wrap: wrap;
}

.ticket-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.ticket-title strong {
  font-size: 9pt;
  font-weight: 800;
}

.ticket-canal {
  font-size: 6.5pt;
  background: #f1f5f9;
  padding: 1px 4px;
  border-radius: 3px;
  white-space: nowrap;
}

/* Badge de retirada */
.ticket-badge-retirada {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: #10b981;
  color: #fff;
  font-size: 6pt;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 2px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.ticket-retirada {
  border: 2px solid #10b981 !important;
  background: linear-gradient(180deg, #ecfdf5 0%, #ffffff 15%) !important;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* Cliente */
.ticket-cliente {
  font-size: 7pt;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 1mm;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Corpo */
.ticket-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 1mm;
}

.ticket-peca {
  border-bottom: 1px dashed #94a3b8;
  padding-bottom: 1mm;
  margin-bottom: 1mm;
}

.ticket-peca:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

/* Cabeçalho da peça (quando múltiplas) */
.ticket-peca-header {
  background: #f1f5f9;
  padding: 0.5mm 1.5mm;
  border-radius: 2px;
  margin-bottom: 0.5mm;
}

.ticket-peca-num {
  font-size: 6pt;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Produto */
.ticket-produto {
  font-size: 7pt;
  font-weight: 700;
  line-height: 1.15;
  margin-bottom: 0.5mm;
}

.ticket-linha {
  display: inline-block;
  font-size: 5.5pt;
  font-weight: 600;
  padding: 0 2px;
  border-radius: 2px;
  margin-left: 2px;
  vertical-align: middle;
}

/* ============================================================
   CAMPOS — 1 POR LINHA COM SEPARADOR
   ============================================================ */
.ticket-campos {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 0.5mm;
}

.campo-linha {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 2px;
  padding: 0.5mm 0;
  border-bottom: 1px solid #e2e8f0;
  font-size: 6.5pt;
  line-height: 1.25;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.campo-linha:last-child {
  border-bottom: none;
}

.campo-linha strong {
  flex-shrink: 0;
  color: #475569;
  font-weight: 600;
  white-space: normal;
  word-break: break-word;
}

.campo-linha span {
  color: #0f172a;
  font-weight: 600;
  word-break: break-word;
}

/* ⭐ Gravação a Laser — fundo azul */
.campo-linha.campo-laser {
  background: #dbeafe !important;
  border-left: 2px solid #3b82f6;
  padding-left: 2mm;
  margin: 0 -1mm;
  padding-right: 1mm;
}

.campo-linha.campo-laser strong {
  color: #1e40af;
}

.campo-linha.campo-laser span {
  color: #1e3a8a;
  font-weight: 700;
}

/* ⭐ Gema — cor via inline style */
.campo-linha.campo-gema {
  border-left: 2px solid #94a3b8;
  padding-left: 2mm;
  margin: 0 -1mm;
  padding-right: 1mm;
}

/* Rodapé */
.ticket-footer {
  border-top: 1px solid #000;
  padding-top: 0.5mm;
  font-size: 6pt;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #555;
}

/* ============================================================
   AJUSTES PARA MUITOS CAMPOS / PEÇAS
   ============================================================ */
/* Quando tem muitas peças, reduz a fonte */
.ticket-body:has(.ticket-peca:nth-child(3)) .campo-linha {
  font-size: 6pt;
  padding: 0.3mm 0;
}

.ticket-body:has(.ticket-peca:nth-child(3)) .ticket-produto {
  font-size: 6.5pt;
}

/* Muitos campos no mesmo produto */
.ticket-campos:has(.campo-linha:nth-child(9)) .campo-linha {
  font-size: 5.5pt;
  line-height: 1.15;
  padding: 0.2mm 0;
}

/* ============================================================
   PREVIEW NO MODAL
   ============================================================ */
#print-preview-container {
  max-height: 60vh;
  overflow-y: auto;
  padding: 10px;
  background: #e2e8f0;
  border-radius: 8px;
}

body.dark-mode #print-preview-container {
  background: #0f172a;
}

body.dark-mode .a4-sheet {
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}



/* ⭐ PRAZO NA ETIQUETA */
.ticket-prazo {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 1px 4px;
  background: #ecfeff;
  border: 1px solid #a5f3fc;
  border-radius: 3px;
  font-size: 6pt;
  color: #0891b2;
  margin-bottom: 1mm;
  font-weight: 600;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.ticket-prazo span {
  font-weight: 400;
  opacity: 0.75;
}

.ticket-prazo-atrasado {
  background: #fef2f2 !important;
  border-color: #fecaca !important;
  color: #dc2626 !important;
}

.ticket-prazo-atrasado i {
  animation: none;
}



/* ============================================================
   BADGES DE IDENTIFICAÇÃO RÁPIDA (ENVIO FULL / BANHADO A OURO)
   ============================================================ */
.ticket-badges-rapidos {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-bottom: 1mm;
}

.ticket-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1.5px 5px;
  border-radius: 3px;
  font-size: 6pt;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
  white-space: nowrap;
}

/* 🔴 Envio Full — vermelho */
.ticket-badge-full {
  background: #dc2626;
  color: #ffffff;
  border: 1px solid #991b1b;
}

.ticket-badge-full i {
  font-size: 6pt;
}

/* 🟡 Banhado a Ouro — amarelo */
.ticket-badge-banhado {
  background: #fbbf24;
  color: #78350f;
  border: 1px solid #d97706;
}

.ticket-badge-banhado i {
  font-size: 6pt;
}

/* ============================================================
   DESTAQUE DE GEMAS (fundo colorido)
   ============================================================ */
.campo-linha.campo-gema {
  border-left: 3px solid #94a3b8;
  padding-left: 4px;
  margin: 0 -1mm;
  padding-right: 2mm;
  font-weight: 600;
}

.campo-linha.campo-gema strong {
  font-weight: 700;
}

/* ============================================================
   AJUSTE PARA MUITOS BADGES
   ============================================================ */
.ticket-badges-rapidos .ticket-badge:only-child {
  /* só 1 badge - fica mais destacado */
}

/* ============================================================
   TIPO DE FRETE NA ETIQUETA
   ============================================================ */
.ticket-frete {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 5px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 3px;
  font-size: 6.5pt;
  color: #475569;
  margin-bottom: 1mm;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.ticket-frete i {
  font-size: 6.5pt;
}

/* PAC — amarelo */
.ticket-frete.ticket-frete-pac {
  background: #fef3c7;
  border-color: #fde68a;
  color: #92400e;
}

/* SEDEX — azul */
.ticket-frete.ticket-frete-sedex {
  background: #e0f2fe;
  border-color: #7dd3fc;
  color: #0369a1;
}

/* Full — vermelho */
.ticket-frete.ticket-frete-full {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

/* Retirada — verde */
.ticket-frete.ticket-frete-retirada {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

/* Motoboy — roxo */
.ticket-frete.ticket-frete-motoboy {
  background: #f3e8ff;
  border-color: #d8b4fe;
  color: #6b21a8;
}