/* ==========================================================================
   ESTILOS DE MAQUETACIÓN DE FACTURA / PRESUPUESTO (HOJA A4 E IMPRESIÓN)
   ========================================================================== */

/* Hoja A4 interactiva en pantalla */
.invoice-sheet {
  --brand-color: #2563eb;
  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border-light: #e2e8f0;
  --bg-subtle: #f8fafc;
  background: #ffffff;
  color: var(--text-main);
  width: 100%;
  max-width: 800px;
  min-height: 1050px;
  margin: 0 auto;
  padding: 40px 48px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  box-sizing: border-box;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  transition: all 0.2s ease;
}

/* Encabezado */
.invoice-header {
  margin-bottom: 24px;
  border-bottom: 2px solid var(--brand-color);
  padding-bottom: 20px;
}

.header-main {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}

.header-brand {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  max-width: 60%;
}

.issuer-logo-wrap {
  max-width: 120px;
  max-height: 70px;
  display: flex;
  align-items: center;
}

.issuer-logo-img {
  max-width: 100%;
  max-height: 70px;
  object-fit: contain;
}

.issuer-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.issuer-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0 0 2px 0;
  line-height: 1.2;
}

.issuer-taxid, .issuer-address, .issuer-location, .issuer-contact {
  font-size: 12px;
  color: var(--text-secondary);
}

.issuer-contact {
  display: flex;
  gap: 12px;
  margin-top: 2px;
}

/* Metadatos del documento */
.header-doc-meta {
  text-align: right;
  min-width: 190px;
}

.doc-badge-type {
  display: inline-block;
  background-color: var(--brand-color);
  color: #ffffff;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 1px;
  padding: 5px 14px;
  border-radius: 4px;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.doc-meta-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}

.meta-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.meta-label {
  color: var(--text-secondary);
}

.meta-val {
  font-weight: 600;
  color: var(--text-main);
}

.meta-val.highlight-number {
  color: var(--brand-color);
  font-weight: 700;
  font-size: 13px;
}

/* Bloque del Cliente */
.invoice-parties {
  margin-bottom: 24px;
}

.party-box {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-left: 4px solid var(--brand-color);
  border-radius: 6px;
  padding: 14px 18px;
}

.party-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  color: var(--brand-color);
  margin-bottom: 6px;
}

.party-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 2px;
}

.party-taxid, .party-address, .party-location {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.party-contact {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  gap: 16px;
}

/* Tabla de Conceptos */
.invoice-table-section {
  margin-bottom: 24px;
  flex-grow: 1;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  color: var(--text-main);
}

.invoice-table th {
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border-light);
  text-align: left;
}

.invoice-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
  color: var(--text-main);
}

.preview-col-idx {
  width: 30px;
  color: var(--text-secondary);
}

.preview-col-desc {
  width: auto;
  color: var(--text-main);
}

.item-desc-text {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-main);
  font-weight: 500;
  line-height: 1.4;
}

.preview-col-qty {
  width: 65px;
  color: var(--text-main);
}

.preview-col-price {
  width: 90px;
  color: var(--text-main);
}

.preview-col-discount {
  width: 60px;
  color: var(--text-secondary);
}

.preview-col-vat {
  width: 60px;
  color: var(--text-secondary);
}

.preview-col-total {
  width: 105px;
  font-weight: 600;
  color: var(--text-main);
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

/* Resumen y Totales */
.invoice-footer-grid {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 20px;
}

.invoice-payment-notes {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.payment-info-box, .notes-box {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12px;
}

.box-title {
  font-weight: 700;
  color: var(--text-main);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.payment-row {
  margin-bottom: 2px;
  color: var(--text-secondary);
}

.iban-text {
  font-family: 'Consolas', 'Courier New', monospace;
  font-weight: 600;
  color: var(--text-main);
  background: #ffffff;
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--border-light);
}

.notes-content {
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
}

/* Caja de Totales */
.invoice-totals-box {
  width: 310px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 14px 18px;
}

.totals-table {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-secondary);
}

.total-row strong {
  color: var(--text-main);
}

.discount-row {
  color: #16a34a;
}

.vat-breakdown-list {
  border-top: 1px dashed var(--border-light);
  border-bottom: 1px dashed var(--border-light);
  padding: 6px 0;
  margin: 4px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tax-summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.tax-summary-val {
  font-weight: 500;
  color: var(--text-main);
}

.irpf-row {
  color: #dc2626;
}

.text-danger {
  color: #dc2626;
}

.grand-total-row {
  margin-top: 6px;
  padding-top: 8px;
  border-top: 2px solid var(--brand-color);
  font-size: 15px;
  font-weight: 800;
  color: var(--text-main);
}

.grand-total-val {
  color: var(--brand-color);
  font-size: 17px;
}

/* Pie de página legal */
.invoice-legal-footer {
  border-top: 1px solid var(--border-light);
  padding-top: 12px;
  text-align: center;
  font-size: 10.5px;
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ==========================================================================
   PLANTILLAS
   ========================================================================== */

/* Plantilla Clásica */
.template-classic {
  border-top: 8px solid var(--brand-color);
  border-radius: 0;
}
.template-classic .invoice-header {
  border-bottom: 1px solid #334155;
}
.template-classic .doc-badge-type {
  background: transparent;
  color: var(--brand-color);
  border: 2px solid var(--brand-color);
  border-radius: 0;
}
.template-classic .party-box {
  border-radius: 0;
  border: 1px solid #cbd5e1;
  border-left: 4px solid #334155;
  background: #ffffff;
}
.template-classic .invoice-table th {
  background-color: #f1f5f9;
  border-bottom: 2px solid #334155;
}

/* Plantilla Minimalista */
.template-minimal {
  box-shadow: none;
  border: 1px solid #e2e8f0;
}
.template-minimal .invoice-header {
  border-bottom: 1px solid #e2e8f0;
}
.template-minimal .doc-badge-type {
  background: transparent;
  color: var(--text-main);
  padding: 0;
  font-size: 18px;
}
.template-minimal .party-box,
.template-minimal .payment-info-box,
.template-minimal .notes-box,
.template-minimal .invoice-totals-box {
  background: transparent;
  border: none;
  padding: 0;
}
.template-minimal .invoice-table th {
  background: transparent;
  border-bottom: 1px solid var(--text-main);
}
.template-minimal .invoice-table td {
  border-bottom: 1px solid #f1f5f9;
}
.template-minimal .grand-total-row {
  border-top: 1px solid var(--text-main);
}

/* ==========================================================================
   ESTILOS DE IMPRESIÓN (PRINT MEDIA)
   ========================================================================== */
@media print {
  @page {
    size: A4 portrait;
    margin: 8mm;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Ocultar elementos de interfaz web */
  .app-header,
  .editor-panel,
  .preview-toolbar,
  .toast-container,
  .modal-backdrop,
  .btn-toggle-view-mobile {
    display: none !important;
  }

  .app-main {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .preview-panel {
    width: 100% !important;
    height: auto !important;
    padding: 0 !important;
    background: transparent !important;
    overflow: visible !important;
  }

  .invoice-sheet {
    box-shadow: none !important;
    border: none !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
  }
}
