/*
  Folha de estilos para impressão dos resultados da simulação.
  Carregada com media="print", só é aplicada ao imprimir ou "Guardar como PDF".

  NOTA: Os elementos <details> e .year-details são abertos via JavaScript
  (beforeprint/afterprint em main.js) para garantir visibilidade total.
*/

@media print {

  /* ------------------------------------------------------------------ */
  /* 1. BASE                                                              */
  /* ------------------------------------------------------------------ */

  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  body {
    font-family: Arial, Helvetica, sans-serif;
    background: #fff;
    color: #111;
    font-size: 9.5pt;
    line-height: 1.4;
    margin: 0;
    padding: 0;
  }

  /* ------------------------------------------------------------------ */
  /* 2. ESCONDER ELEMENTOS DA APLICAÇÃO                                   */
  /* ------------------------------------------------------------------ */

  /* Cabeçalho de navegação do site (header + nav) */
  header,
  header nav,
  /* Rodapé do site */
  .app-footer,
  /* Botões de acção */
  .results-actions,
  /* Painel de eventos (formulários inline) */
  .events-panel,
  /* Coluna de toggle */
  .toggle-cell,
  /* Legenda de badges */
  .badge-legend,
  /* Alertas */
  .alert,
  /* Elementos de comparação */
  .sim-col-add,
  .compare-page-header,
  .compare-empty-hint,
  #compare-file-input,
  /* Input oculto de ficheiro */
  #load-file-input,
  /* Modal */
  .modal-overlay {
    display: none !important;
  }

  /* ------------------------------------------------------------------ */
  /* 3. LAYOUT GERAL                                                      */
  /* ------------------------------------------------------------------ */

  main {
    max-width: 100%;
    padding: 0;
    margin: 0;
  }

  /* ------------------------------------------------------------------ */
  /* 4. CABEÇALHO DA SIMULAÇÃO                                            */
  /* ------------------------------------------------------------------ */

  .results-header {
    border-bottom: 2pt solid #333;
    padding-bottom: 10pt;
    margin-bottom: 14pt;
  }

  .results-header-row {
    display: block;
  }

  .results-nome {
    font-size: 16pt;
    font-weight: 700;
    margin-bottom: 3pt;
  }

  .results-nome-label {
    font-size: 9pt;
    font-weight: 400;
    color: #555;
    margin-right: 4pt;
    text-transform: uppercase;
    letter-spacing: .04em;
  }

  .results-descricao {
    font-size: 10pt;
    color: #444;
    margin-bottom: 6pt;
    font-style: italic;
  }

  .results-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 4pt 16pt;
    font-size: 9pt;
    margin-top: 6pt;
  }

  .results-summary span {
    border: 1px solid #bbb;
    padding: 2pt 6pt;
    border-radius: 3pt;
    background: #f7f7f7;
  }

  /* ------------------------------------------------------------------ */
  /* 5. OPÇÕES DETALHADAS DA SIMULAÇÃO                                    */
  /* ------------------------------------------------------------------ */

  /* O JS abre o <details> antes de imprimir; estes estilos tratam da
     apresentação quando ele está aberto */
  .pressupostos-details {
    margin-top: 10pt;
    page-break-inside: avoid;
  }

  .pressupostos-summary {
    font-size: 11pt;
    font-weight: 700;
    color: #222;
    margin-bottom: 8pt;
    list-style: none;
    border-bottom: 1px solid #ccc;
    padding-bottom: 4pt;
  }

  .pressupostos-summary::-webkit-details-marker { display: none; }

  .pressupostos-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5pt 14pt;
    margin-top: 6pt;
  }

  .pressuposto-item {
    page-break-inside: avoid;
  }

  .pressuposto-label {
    display: block;
    font-size: 7.5pt;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #666;
    line-height: 1.2;
  }

  .pressuposto-valor {
    display: block;
    font-size: 9.5pt;
    font-weight: 600;
    color: #111;
  }

  .pressuposto-section-hdr {
    grid-column: 1 / -1;
    border-top: 1px solid #aaa;
    margin-top: 7pt;
    padding-top: 5pt;
    page-break-after: avoid;
  }

  .pressuposto-section-hdr .pressuposto-label {
    font-size: 9pt;
    font-weight: 700;
    color: #111;
    text-transform: none;
    letter-spacing: 0;
  }

  /* ------------------------------------------------------------------ */
  /* 6. TABELA PRINCIPAL DE RESULTADOS                                    */
  /* ------------------------------------------------------------------ */

  .results-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 14pt;
    font-size: 8.5pt;
    page-break-inside: auto;
  }

  .results-table th {
    background: #e8e8e8 !important;
    font-weight: 700;
    border: 1px solid #999;
    padding: 4pt 5pt;
    text-align: right;
    font-size: 8pt;
  }

  .results-table th:first-child { text-align: center; }

  .results-table thead {
    display: table-header-group; /* Repete cabeçalho em cada página */
  }

  .results-table td {
    border: 1px solid #ccc;
    padding: 3pt 5pt;
    text-align: right;
  }

  .results-table td:first-child { text-align: center; }

  /* Linha de cabeçalho do ano */
  .year-header td {
    font-weight: 600;
    background: #f5f5f5 !important;
  }

  /* Ano 0 — destaque ligeiro */
  .year-0-header td {
    background: #ececec !important;
  }

  /* Cores de saldo */
  .saldo-positivo { color: #1a5e2a !important; }
  .saldo-negativo { color: #8b1a1a !important; }

  /* Badges de eventos */
  .event-badge {
    display: inline-block;
    font-size: 6pt;
    font-weight: 700;
    padding: 1pt 3pt;
    border: 1px solid #999;
    border-radius: 2pt;
    margin-left: 2pt;
    vertical-align: middle;
    background: #eee !important;
    color: #333 !important;
  }

  /* ------------------------------------------------------------------ */
  /* 7. DETALHES DO ANO (abertos pelo JS antes de imprimir)              */
  /* ------------------------------------------------------------------ */

  /* A classe .open é adicionada pelo JS; display: table-row mostra a linha */
  .year-details {
    display: none; /* escondido por padrão */
  }
  .year-details.open,
  .year-details.print-open {
    display: table-row !important;
  }

  .year-details-inner {
    padding: 6pt 8pt;
    background: #fafafa !important;
    border-top: 1px solid #ddd;
  }

  /* Tabelas de detalhe lado a lado */
  .detail-tables {
    display: flex;
    gap: 20pt;
    flex-wrap: nowrap;
    align-items: flex-start;
  }

  .detail-table {
    flex: 1;
    min-width: 0;
    border-collapse: collapse;
    font-size: 8pt;
  }

  .detail-table caption {
    font-weight: 700;
    font-size: 8.5pt;
    text-align: left;
    padding-bottom: 4pt;
    border-bottom: 1px solid #bbb;
    margin-bottom: 3pt;
    caption-side: top;
  }

  .detail-table td {
    padding: 2pt 4pt;
    border: none;
    border-bottom: 1px solid #eee;
    vertical-align: top;
  }

  .detail-table td:last-child {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  .detail-table tr:last-child td { border-bottom: none; }

  .detail-table .total-row td {
    font-weight: 700;
    border-top: 1.5px solid #888;
    border-bottom: none;
    padding-top: 3pt;
  }

  /* ------------------------------------------------------------------ */
  /* 8. QUEBRAS DE PÁGINA                                                 */
  /* ------------------------------------------------------------------ */

  h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }

  .results-header { page-break-after: avoid; }

  .pressupostos-details { page-break-after: always; }

  /* Cada par (linha-resumo + linha-detalhe) deve ficar junto */
  .year-header { page-break-inside: avoid; page-break-after: avoid; }
  .year-details { page-break-before: avoid; }

  /* ------------------------------------------------------------------ */
  /* 9. RESUMO DE OPERAÇÕES DO ANO                                        */
  /* ------------------------------------------------------------------ */

  .year-ops-summary {
    margin-top: 6pt;
    margin-bottom: 0;
    padding: 5pt 7pt;
    border: 1px solid #bbc8e0;
    background: #f0f4ff !important;
    border-radius: 3pt;
    page-break-inside: avoid;
  }

  .year-ops-title {
    display: block;
    font-size: 7.5pt;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #3a4a80;
    margin-bottom: 4pt;
  }

  .year-ops-list {
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .year-ops-list li {
    display: flex;
    align-items: baseline;
    gap: 5pt;
    font-size: 8pt;
    padding: 1pt 0;
    border-bottom: 1px solid #dde4f5;
  }

  .year-ops-list li:last-child { border-bottom: none; }

  .ops-icon {
    display: inline-block;
    font-size: 6pt;
    font-weight: 700;
    padding: 1pt 4pt;
    border-radius: 2pt;
    white-space: nowrap;
    flex-shrink: 0;
    border: 1px solid;
  }

  .ops-icon--vnd  { background: #fff0e0 !important; border-color: #d08020; color: #7a4800; }
  .ops-icon--mv   { background: #ffeaea !important; border-color: #d04040; color: #800000; }
  .ops-icon--cmp  { background: #e0f0ff !important; border-color: #2060c0; color: #003a80; }
  .ops-icon--liq  { background: #f0ffe0 !important; border-color: #50a020; color: #2a5c00; }
  .ops-icon--amort { background: #f5f0ff !important; border-color: #8050c0; color: #4a1a80; }
  .ops-icon--rnd  { background: #e0fff8 !important; border-color: #20a080; color: #005c40; }

}
