@media print {
  /* 1. Ocultar menús y elementos de interfaz de pantalla */
  #toolbar,
  #tab-bar,
  #status-bar,
  #file-import-excel,
  #file-import-msp,
  .cashflow-controls,
  .gantt_grid_head_cell .gantt_sort,
  .grid-btn-add {
    display: none !important;
  }

  /* 2. Configurar la página de impresión en apaisado (Landscape) auto-escalable (A0, A1, A2, A3, A4) */
  @page {
    size: landscape;
    margin: 8mm 12mm 12mm 12mm;
  }

  /* 3. Permitir impresión de fondos de color en navegadores */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* 4. Forzar que todo el contenido sea visible y fluya hacia abajo */
  body, html {
    height: auto !important;
    overflow: visible !important;
    background-color: #ffffff !important;
    color: #000000 !important;
    font-family: 'Inter', -apple-system, sans-serif;
  }

  #main-content {
    height: auto !important;
    overflow: visible !important;
    display: block !important;
    background-color: #ffffff !important;
  }

  /* 5. Forzar a que todas las vistas se muestren de forma secuencial, cada una en una hoja */
  .view {
    display: block !important;
    opacity: 1 !important;
    height: auto !important;
    overflow: visible !important;
    page-break-after: always !important; /* Salto de página entre vistas */
    position: relative;
    padding-top: 30px; /* Espacio para el encabezado inyectado */
  }

  /* Evitar saltos de página rotos dentro de las vistas */
  #gantt-view, #cashflow-view, #resources-view {
    page-break-inside: avoid !important;
  }

  /* === HOJA 1: DIAGRAMA DE GANTT === */
  #gantt-container {
    height: 190mm !important; /* Altura ideal en hoja A3 */
    width: 100% !important;
    border: 1px solid #dddddd !important;
    background-color: #ffffff !important;
  }

  /* Cambiar colores de DHTMLX Gantt a tema claro para impresión */
  .gantt_container,
  .gantt_grid,
  .gantt_task,
  .gantt_task_row,
  .gantt_grid_data .gantt_row,
  .gantt_grid_data .gantt_row.odd,
  .gantt_scale_line {
    background-color: #ffffff !important;
    color: #000000 !important;
  }

  .gantt_grid_head_cell {
    background-color: #f1f5f9 !important;
    color: #0f172a !important;
    border-bottom: 2px solid #cbd5e1 !important;
    border-right: 1px solid #e2e8f0 !important;
    font-weight: bold;
  }

  .gantt_cell, 
  .gantt_task_cell {
    border-right: 1px solid #e2e8f0 !important;
    border-bottom: 1px solid #e2e8f0 !important;
    color: #334155 !important;
  }

  /* Colores de las barras en papel */
  .gantt_task_line {
    background-color: #3498db !important;
    border: 1px solid #2980b9 !important;
  }
  .gantt_task_line.critical-task {
    background-color: #ef4444 !important;
    border-color: #dc2626 !important;
  }
  .gantt_task_line.project-task {
    background-color: #64748b !important;
    border-color: #475569 !important;
  }
  .gantt_task_line.milestone-task {
    background-color: #f59e0b !important;
  }

  .gantt_task_link {
    border-color: #94a3b8 !important;
  }
  .gantt_link_arrow {
    border-left-color: #94a3b8 !important;
  }

  /* === HOJA 2: CASHFLOW === */
  #cashflow-chart-container {
    height: 100mm !important;
    margin-bottom: 20px;
    border: 1px solid #e2e8f0;
    padding: 15px;
    background-color: #f8fafc !important;
  }

  #cashflow-canvas {
    width: 100% !important;
    height: 100% !important;
    max-height: 95mm !important;
  }

  #cashflow-table-container {
    height: auto !important;
    overflow: visible !important;
    border-top: none;
    padding: 0;
  }

  /* === HOJA 3: RECURSOS === */
  #resources-table-container {
    height: auto !important;
    overflow: visible !important;
    border-top: none;
    padding: 0;
  }

  /* Estilos de tablas generales para impresión clara */
  table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin-top: 15px;
  }

  th {
    background-color: #f1f5f9 !important;
    color: #0f172a !important;
    border-bottom: 2px solid #cbd5e1 !important;
    padding: 8px 12px !important;
    font-weight: bold !important;
  }

  td {
    border-bottom: 1px solid #e2e8f0 !important;
    padding: 8px 12px !important;
    color: #334155 !important;
    background-color: #ffffff !important;
  }

  tr:nth-child(even) td {
    background-color: #f8fafc !important;
  }

  /* Fila de totales en recursos */
  .total-row td {
    font-weight: bold !important;
    background-color: #f1f5f9 !important;
    border-top: 2px solid #cbd5e1 !important;
    color: #0f172a !important;
  }

  /* === CABECERA Y PIE DE PÁGINA CORPORATIVOS DE IMPRESIÓN === */
  .view::before {
    content: "V-PROJECTS | REPORTES Y PLANIFICACIÓN DE PROYECTOS";
    display: block;
    position: absolute;
    top: -5px;
    left: 0;
    width: 100%;
    font-size: 14px;
    font-weight: bold;
    color: #0f172a;
    border-bottom: 2px solid #3498db;
    padding-bottom: 5px;
    letter-spacing: 0.5px;
  }

  /* Agregar leyenda dinámica según la sección */
  #gantt-view::before {
    content: "V-PROJECTS | DIAGRAMA DE GANTT Y CRONOGRAMA CORPORATIVO - CLIENTE: VJF STUDIO SRL";
  }
  #cashflow-view::before {
    content: "V-PROJECTS | CONTROL PRESUPUESTARIO Y FLUJO DE CAJA (CASHFLOW) - CLIENTE: VJF STUDIO SRL";
  }
  #resources-view::before {
    content: "V-PROJECTS | ASIGNACIÓN DE RECURSOS Y RENDIMIENTO DE PERSONAL - CLIENTE: VJF STUDIO SRL";
  }

  /* Cuadro de Firmas corporativo en la última hoja */
  #resources-view::after {
    content: "Responsable de Obra: _______________________      |      Auditor General: _______________________ \A\A V-Projects v1.0 | Desarrollado para el Ecosistema V-Control-T (vcontrolt.com)";
    display: block;
    margin-top: 40px;
    padding-top: 15px;
    border-top: 1px dashed #cbd5e1;
    font-size: 10px;
    color: #64748b;
    white-space: pre-wrap;
    text-align: center;
    line-height: 1.5;
  }
}
