/* ============================================================
   Print — estilos para @media print (PDF vía Ctrl+P)
   ============================================================ */

/* Elementos marcados como "solo impresión" — ocultos en pantalla */
.print-only { display: none; }

@media print {
  /* ========== Reset a tema claro ========== */
  :root {
    --bg-0: #ffffff;
    --bg-1: #ffffff;
    --bg-2: #ffffff;
    --bg-3: #f3f4f6;
    --text-hi: #0a0a0a;
    --text-md: #1f2937;
    --text-lo: #4b5563;
    --text-dim: #6b7280;
    --border-subtle: #d1d5db;
    --border: #9ca3af;
    --accent: #0369a1;
    --accent-dim: transparent;
  }

  html, body, .app-shell, .main, .page {
    background: #ffffff !important;
    color: #0a0a0a !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body { font-size: 10pt; line-height: 1.35; }

  /* ========== Ocultar chrome ========== */
  .sidebar,
  .topbar,
  .app-shell__footer,
  #modalRoot,
  .toast-stack,
  .page__actions,
  .table-wrap__header button,
  .form-actions,
  .nav,
  .sidebar__footer,
  [data-delete-linea],
  .empty {
    display: none !important;
  }

  .app-shell {
    display: block !important;
    grid-template-columns: 1fr !important;
  }
  .main { display: block !important; }

  /* ========== Layout A4 ========== */
  @page {
    size: Letter;
    margin: 16mm 14mm;
  }

  .page { padding: 0 !important; }

  /* ========== Sólo mostramos lo marcado como .print-sheet ========== */
  .page__header { display: none !important; }
  #cotContent > .table-wrap,
  #cotContent > .grid {
    /* ocultos — el layout print usa su propio markup */
    display: none !important;
  }

  /* El bloque print se vuelve visible */
  .print-only { display: block !important; }

  /* ========== Encabezado de la hoja ========== */
  .print-sheet {
    color: #0a0a0a;
    font-family: 'Inter', system-ui, sans-serif;
  }

  .print-header {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12mm;
    align-items: start;
    padding-bottom: 6mm;
    border-bottom: 1.5pt solid #0a0a0a;
    margin-bottom: 6mm;
  }

  .print-emisora {
    font-size: 9pt;
    line-height: 1.4;
  }
  .print-emisora__name {
    font-size: 12pt;
    font-weight: 700;
    letter-spacing: 0.02em;
    margin-bottom: 2mm;
  }
  .print-emisora__rfc {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9pt;
    color: #374151;
  }

  .print-header__meta {
    text-align: right;
    font-size: 9pt;
  }
  .print-header__meta h1 {
    font-size: 22pt;
    font-weight: 300;
    letter-spacing: 0.2em;
    color: #0369a1;
    margin: 0 0 4mm 0;
    line-height: 1;
  }
  .print-header__meta .meta-row {
    display: flex;
    justify-content: flex-end;
    gap: 4mm;
    margin-top: 1.5mm;
  }
  .print-header__meta .meta-label {
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 8pt;
  }
  .print-header__meta .meta-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
  }

  /* ========== Cliente ========== */
  .print-client {
    margin-bottom: 6mm;
    font-size: 9.5pt;
  }
  .print-client__label {
    font-size: 8pt;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6b7280;
    margin-bottom: 1.5mm;
    font-weight: 600;
  }
  .print-client__name {
    font-size: 12pt;
    font-weight: 700;
    margin-bottom: 1mm;
  }
  .print-client__detail {
    line-height: 1.5;
    color: #374151;
  }

  /* ========== Tabla de líneas ========== */
  .print-lines {
    width: 100%;
    border-collapse: collapse;
    font-size: 9pt;
    margin-bottom: 5mm;
  }
  .print-lines thead th {
    background: #f3f4f6;
    border-bottom: 1pt solid #0a0a0a;
    padding: 2mm 2mm;
    text-align: left;
    font-weight: 700;
    font-size: 8.5pt;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  .print-lines tbody td {
    padding: 2mm 2mm;
    border-bottom: 0.5pt solid #d1d5db;
    vertical-align: top;
  }
  .print-lines .col-num { width: 8mm; text-align: center; color: #6b7280; }
  .print-lines .col-qty { width: 14mm; text-align: right; font-family: 'JetBrains Mono', monospace; }
  .print-lines .col-money { width: 26mm; text-align: right; font-family: 'JetBrains Mono', monospace; }
  .print-lines .col-desc {
    /* Descripción permite word wrap; evita que el renglón se corte entre páginas */
    page-break-inside: avoid;
  }
  .print-lines tbody tr { page-break-inside: avoid; }

  /* ========== Totales ========== */
  .print-totals {
    display: grid;
    grid-template-columns: 1fr 60mm;
    gap: 4mm;
    margin-bottom: 6mm;
    font-size: 9.5pt;
  }
  .print-totals__left { /* vacío o notas */
    font-size: 9pt;
    color: #374151;
  }
  .print-totals__table {
    border-collapse: collapse;
    width: 100%;
  }
  .print-totals__table td {
    padding: 1.5mm 2mm;
    font-family: 'JetBrains Mono', monospace;
    font-size: 9.5pt;
  }
  .print-totals__table td:first-child {
    color: #374151;
    font-family: 'Inter', sans-serif;
  }
  .print-totals__table td:last-child {
    text-align: right;
  }
  .print-totals__total td {
    border-top: 1.2pt solid #0a0a0a;
    padding-top: 2.5mm;
    padding-bottom: 2.5mm;
    font-weight: 700;
    font-size: 11pt;
  }
  .print-totals__total td:first-child { color: #0a0a0a; }

  /* ========== Footer: condiciones, notas, vigencia ========== */
  .print-footer {
    border-top: 0.5pt solid #d1d5db;
    padding-top: 4mm;
    font-size: 8.5pt;
    color: #374151;
    line-height: 1.5;
  }
  .print-footer__section {
    margin-bottom: 3mm;
  }
  .print-footer__label {
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 7.5pt;
    font-weight: 700;
    color: #6b7280;
    margin-bottom: 1mm;
    display: block;
  }
  .print-footer__vigencia {
    padding: 2mm 3mm;
    background: #fef3c7;
    border-left: 2pt solid #d97706;
    font-weight: 600;
    color: #78350f;
    margin-bottom: 3mm;
    font-size: 9pt;
  }

  /* ========== Misc ========== */
  a, a:visited { color: inherit; text-decoration: none; }

  /* Logo placeholder — se sustituye cuando haya logo real */
  .print-logo-box {
    width: 42mm;
    height: 14mm;
    border: 0.5pt dashed #9ca3af;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    font-size: 8pt;
    margin-bottom: 3mm;
  }
}
