/* ==========================================================================
   ESTILOS ESPECÍFICOS — Generador de Facturas
   ========================================================================== */

/* Estilos globales para inputs dentro del formulario de facturas */
.form-side input,
.form-side select,
.form-side textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--paper-line, #e2e8f0);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink, #1e293b);
  background-color: var(--white, #ffffff);
  box-sizing: border-box;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}

.form-side input:focus,
.form-side select:focus,
.form-side textarea:focus {
  outline: none;
  border-color: var(--azul, #2563eb);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-top: 24px;
  border: 1px solid var(--paper-line, #e2e8f0);
  background: var(--white, #ffffff);
  border-radius: 12px;
  box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1));
}

.tool-intro {
  text-align: center;
  max-width: 700px;
  margin: 0 auto 2.5rem;
  color: #4a5568;
  line-height: 1.6;
}

@media (max-width: 980px) {
  .wrap {
    grid-template-columns: 1fr;
  }
}

.form-side {
  padding: 32px;
  border-right: 1px solid var(--paper-line, #e2e8f0);
  border-radius: 12px 0 0 12px;
  box-sizing: border-box;
}

@media (max-width: 980px) {
  .form-side {
    border-right: none;
    border-bottom: 1px solid var(--paper-line, #e2e8f0);
    border-radius: 12px 12px 0 0;
  }
}

.section-label {
  font-family: var(--mono, monospace);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--ledger-dark, #0f172a);
  margin: 28px 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-label:first-child {
  margin-top: 0;
}

.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--paper-line, #e2e8f0);
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted, #64748b);
  margin-bottom: 4px;
}

textarea {
  resize: vertical;
  min-height: 60px;
}

/* Tabla de Ítems del Formulario */
.items-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

.items-table th {
  font-family: var(--mono, monospace);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted, #64748b);
  text-align: left;
  padding-bottom: 8px;
  font-weight: 600;
}

.items-table td {
  padding: 4px 4px 4px 0;
  vertical-align: top;
}

.items-table input {
  font-size: 13px;
  padding: 8px;
}

.col-desc {
  width: 44%;
}

.col-qty {
  width: 16%;
}

.col-price {
  width: 22%;
}

.col-del {
  width: 8%;
  text-align: center;
}

.del-btn {
  background: none;
  border: none;
  color: #e11d48;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 8px;
  border-radius: 4px;
}

.del-btn:hover {
  background: #ffe4e6;
}

.add-row-btn {
  margin-top: 12px;
  background: #f0fdf4;
  border: 1px dashed var(--ledger, #16a34a);
  color: var(--ledger-dark, #15803d);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--sans, sans-serif);
  transition: background 0.2s;
}

.add-row-btn:hover {
  background: #dcfce7;
}

.print-btn {
  margin-top: 0;
  width: 100%;
  max-width: 560px;
  padding: 14px;
  background: var(--ledger, #16a34a);
  color: var(--white, #ffffff);
  border: none;
  border-radius: 6px;
  font-family: var(--sans, sans-serif);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.2s,
    transform 0.1s;
}

.print-btn:hover {
  background: var(--ledger-dark, #15803d);
}

.print-btn:active {
  transform: translateY(1px);
}

.hint {
  font-size: 12px;
  color: var(--muted, #64748b);
  margin-top: 8px;
  text-align: center;
}

/* Vista Previa de Factura (Hoja A4) */
.preview-side {
  padding: 32px;
  background: #f1f5f9;
  border-radius: 0 12px 12px 0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

@media (max-width: 980px) {
  .preview-side {
    border-radius: 0 0 12px 12px;
  }
}

.invoice-sheet {
  background: var(--white, #ffffff);
  width: 100%;
  max-width: 560px;
  padding: 40px 36px;
  border-radius: 6px;
  box-shadow: var(--shadow-lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1));
  position: relative;
  box-sizing: border-box;
  margin-bottom: 20px;
}

.inv-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid var(--ink, #0f172a);
  padding-bottom: 18px;
  margin-bottom: 24px;
  padding-right: 80px;
}

.inv-head h2 {
  font-family: var(--serif, Georgia, serif);
  font-size: 28px;
  margin: 0 0 4px;
  color: var(--ink, #0f172a);
  font-weight: 600;
}

.inv-num {
  font-family: var(--mono, monospace);
  font-size: 12px;
  color: var(--muted, #64748b);
}

.inv-meta {
  text-align: right;
  font-size: 12px;
  color: var(--muted, #64748b);
  font-family: var(--mono, monospace);
}

.inv-meta div {
  margin-bottom: 2px;
}

.parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 26px;
}

.party-label {
  font-family: var(--mono, monospace);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ledger-dark, #15803d);
  margin-bottom: 6px;
  font-weight: 600;
}

.party-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
  color: var(--ink, #0f172a);
}

.party-detail {
  font-size: 12.5px;
  color: var(--muted, #64748b);
  line-height: 1.5;
  white-space: pre-line;
}

table.inv-items {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 18px;
}

table.inv-items thead th {
  font-family: var(--mono, monospace);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--white, #ffffff);
  background: var(--ink, #0f172a);
  padding: 8px 10px;
  text-align: left;
}

table.inv-items thead th.num {
  text-align: right;
}

table.inv-items tbody td {
  padding: 9px 10px;
  font-size: 13px;
  border-bottom: 1px solid var(--paper-line, #e2e8f0);
}

table.inv-items tbody td.num {
  text-align: right;
  font-family: var(--mono, monospace);
}

.totals {
  margin-left: auto;
  width: 250px;
  font-family: var(--mono, monospace);
  font-size: 13px;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  color: var(--muted, #64748b);
}

.totals-row.grand {
  border-top: 2px solid var(--ink, #0f172a);
  margin-top: 6px;
  padding-top: 10px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink, #0f172a);
}

.notes {
  margin-top: 28px;
  font-size: 12px;
  color: var(--muted, #64748b);
  border-top: 1px dashed var(--paper-line, #e2e8f0);
  padding-top: 14px;
  white-space: pre-line;
}

/* Sello */
/* Corrección del sello de agua */
.watermark {
  position: absolute;
  top: 18px;
  right: 18px;
  font-family: var(--mono, monospace);
  font-size: 10px;
  font-weight: 600;
  color: var(--ledger-dark, #15803d);
  border: 1px solid var(--ledger-dark, #15803d);
  padding: 3px 8px;
  transform: rotate(4deg);
  letter-spacing: 1px;
  opacity: 0.7;
  pointer-events: none;
  background: var(
    --white,
    #ffffff
  ); /* Evita transparencias raras sobre el texto */
}

/* Margen adicional para que el texto de fechas no toque el sello */
.inv-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid var(--ink, #0f172a);
  padding-bottom: 18px;
  margin-bottom: 24px;
  padding-right: 110px; /* Incrementado para dejar hueco al sello ORIGINAL */
}

/* ==========================================================================
   REGLAS DE IMPRESIÓN Y EXPORTACIÓN A PDF
   ========================================================================== */
@media print {
  /* 1. Ocultar todos los elementos de la interfaz web */
  body > *:not(main),
  .navbar,
  .page-header,
  .form-side,
  .print-btn,
  .hint,
  footer,
  footer.footer-modern,
  header {
    display: none !important;
  }

  /* 2. Resetear el lienzo de la página a blanco nativo */
  html,
  body {
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
  }

  /* 3. Anular contenedores intermedios para usar el ancho completo de la página */
  main.container,
  .wrap,
  .preview-side {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* 4. Dar formato de hoja completa a la factura */
  .invoice-sheet {
    box-shadow: none !important;
    border: none !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* 5. Ajustar márgenes de la página física */
  @page {
    size: A4 portrait;
    margin: 15mm 15mm 15mm 15mm;
  }
}

@media print {
  /* Ocultar elementos de la interfaz y el texto descriptivo */
  body > *:not(main),
  .navbar,
  .page-header,
  .form-side,
  .print-btn,
  .hint,
  footer,
  footer.footer-modern,
  header,
  main.container > p {
    /* <--- Añadida esta línea */
    display: none !important;
  }

  /* Resetear el lienzo a blanco */
  html,
  body {
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
  }

  /* Liberar espacio de los contenedores */
  main.container,
  .wrap,
  .preview-side {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Formato de hoja para la factura */
  .invoice-sheet {
    box-shadow: none !important;
    border: none !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  @page {
    size: A4 portrait;
    margin: 15mm;
  }
}

/* ==========================================================================
   ACORDEÓN FAQ Y SEPARACIÓN DE CONTENEDORES
   ========================================================================== */

/* Separación entre tarjetas/contenedores consecutivos */
.manifesto-card + .manifesto-card,
.info-box + .manifesto-card,
.manifesto-card + .info-box {
  margin-top: 32px;
}

/* Lista de Preguntas Frecuentes */
.faq-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.faq-item {
  background: #fafafa;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px 20px;
  transition:
    background 0.2s ease,
    border-color 0.2s ease;
}

.faq-item[open] {
  background: #ffffff;
  border-color: #bbf7d0;
}

.faq-item summary {
  font-size: 15px;
  font-weight: 700;
  color: var(--brand-dark);
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Ocultar el indicador por defecto en Safari/Webkit */
.faq-item summary::-webkit-details-marker {
  display: none;
}

/* Símbolo personalizado + / - */
.faq-item summary::after {
  content: "+";
  font-size: 18px;
  font-weight: bold;
  color: var(--brand);
  margin-left: 12px;
  transition: transform 0.2s ease;
}

.faq-item[open] summary::after {
  content: "−";
}

.faq-item p {
  margin-top: 12px;
  margin-bottom: 0;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ==========================================================================
   ACORDEONES DE AMORTIZACIÓN ANUAL
   ========================================================================== */

.amortization-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.year-accordion {
  background: #ffffff;
  border: 1px solid #e1e4e8;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.year-accordion summary {
  background-color: #f0fdf4;
  color: #15803d;
  padding: 14px 20px;
  font-weight: bold;
  font-size: 1.05em;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.year-accordion summary::-webkit-details-marker {
  color: #15803d;
}

.year-accordion table {
  width: 100%;
  border-collapse: collapse;
}

.year-accordion th,
.year-accordion td {
  padding: 10px 15px;
  text-align: left;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.95em;
}

.year-accordion th {
  background-color: #f8fafc;
  color: #4a5568;
  font-weight: 600;
  font-size: 0.85em;
  text-transform: uppercase;
}
