@media print {
    @page {
        size: letter landscape;
        margin: 5mm;
    }

    body {
        background: #fff !important;
        color: #000 !important;
        margin: 0;
        padding: 0;
        width: 100%;
        height: auto;
        overflow: visible !important;
    }

    /* Force exact colors for bars and pills */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* HIDE INTERACTIVE ELEMENTS */
    .topbar,
    .sidebar,
    .footer,
    .no-pdf,
    .msg,
    #formMsg,
    #pmeDashboard,
    button,
    .btn,
    .small-btn,
    .pme-actions,
    .top-actions,
    .stats button,
    .config-btn,
    .gantt-month-actions,
    .pme-buttons,
    #btnRefreshPME,
    #btnAddPMEAction,
    #ganttStickyOverlay,
    .gantt-handle-start,
    .gantt-handle-end,
    .pme-action-row .btn-mini,
    .pme-milestone-row .btn-mini,
    .pme-dimension-row .btn-mini {
        display: none !important;
    }

    /* Layout Adjustments */
    .layout {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        height: auto !important;
        width: 100% !important;
    }

    .content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        background: #fff !important;
        color: #000 !important;
        border: none !important;
        box-shadow: none !important;
    }

    /* Force dark text in all headers and text blocks */
    h1,
    h2,
    h3,
    h4,
    p,
    span,
    b,
    strong,
    i,
    input,
    select {
        color: #000 !important;
        -webkit-text-fill-color: #000 !important;
        opacity: 1 !important;
    }

    /* View Visibility based on State */
    #viewContainer,
    #pmeContainer {
        display: none !important;
    }

    /* Annual Export mode global overrides */
    body.annual-export-mode .layout,
    body.annual-export-mode header,
    body.annual-export-mode footer,
    body.annual-export-mode .topbar,
    body.pme-report-mode .layout,
    body.pme-report-mode header,
    body.pme-report-mode footer,
    body.pme-report-mode .topbar {
        display: none !important;
    }

    /* Reporte Ejecutivo PME — misma receta que annual-export-mode: #print-view-container ya se
       muestra (regla #print-view-container:not(:empty) más abajo), solo falta el estilo del reporte.
       #print-only-header es un bloque fijo (logo + "Calendario Institucional") que vive como
       hermano de #print-view-container y por eso siempre se imprime justo después de su contenido;
       el reporte ya trae su propio encabezado, así que aquí queda redundante — se oculta. */
    .pme-report-page { color: #000 !important; }
    body.pme-report-mode #print-only-header { display: none !important; }
    .pme-report-header { text-align: center; border-bottom: 3px solid #000; padding-bottom: 10px; margin-bottom: 16px; }
    .pme-report-header h1 { margin: 0; font-size: 22pt; }
    .pme-report-header p { margin: 4px 0 0; font-size: 10pt; opacity: 0.7; }
    .pme-report-stats { display: flex; justify-content: space-around; margin-bottom: 24px; }
    .pme-report-stat { text-align: center; }
    .pme-report-stat .v { display: block; font-size: 18pt; font-weight: 800; }
    .pme-report-stat .l { display: block; font-size: 9pt; text-transform: uppercase; opacity: 0.7; }
    /* display:block porque el h2 global de la app (components.css) es display:flex — pensado para
       los encabezados de sección del sidebar (bolita + texto), no para el reporte. Chrome tiene un
       bug conocido: un <h2> flex justo después de un salto de página forzado (page-break-before)
       imprime su borde/fondo pero colapsa el texto — de ahí que solo se viera una rayita de color
       sin el nombre de la dimensión. */
    .pme-report-page h2 { display: block; font-size: 13pt; margin: 20px 0 8px; border-bottom: 1px solid #000; padding-bottom: 4px; }
    /* border-collapse:collapse + una tabla que se fragmenta en varias hojas (las de Detalle por
       Dimensión son largas) es un bug conocido de Chrome al imprimir: el borde derecho de la tabla
       se pierde específicamente en las tablas que cruzan un salto de página — las tablas cortas de
       arriba (Salud por Dimensión, Acciones Vencidas) nunca se fragmentan y sí muestran su borde
       bien. border-collapse:separate hace que cada celda dibuje su propio borde en vez de compartir
       una línea con la vecina, y eso sí sobrevive la fragmentación entre páginas. */
    .pme-report-table { width: 100%; box-sizing: border-box; border: 1px solid #999; border-collapse: separate; border-spacing: 0; font-size: 10pt; }
    .pme-report-table th, .pme-report-table td { border: 1px solid #999; padding: 4px 8px; text-align: left; }
    .pme-report-table th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

    .pme-report-section-title { page-break-after: avoid; }

    /* Detalle por dimensión: el nombre de la dimensión y de cada objetivo van como FILAS de la
       tabla (colspan 6), no como un <h2>/<div> aparte. Un heading suelto justo en el borde de un
       salto de página imprimía su borde/fondo pero perdía el texto en Chrome (bug de paginación
       con elementos de bloque) — una fila de tabla no tiene ese problema: Chrome pagina tablas
       fila por fila de forma mucho más confiable. */
    .pme-report-dim-table { margin-bottom: 16px; }
    .pme-report-dim-table + .pme-report-dim-table { page-break-before: always; }
    .pme-report-dim-row td {
        font-size: 14pt;
        font-weight: 900;
        padding: 8px 10px;
        border: none;
        border-left: 8px solid #000;
        background: #f0f0f0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .pme-report-obj-row td {
        font-size: 10pt;
        font-weight: 700;
        color: #333;
        border: none;
        border-bottom: 1px solid #999;
        padding: 8px 8px 4px;
    }
    .pme-report-col-row th { background: #f7f7f7 !important; }
    .pme-report-desc-row td { font-size: 9pt; font-style: italic; color: #555; border-top: none; padding: 2px 8px 6px; }

    body.annual-export-mode .annual-export-page {
        display: block !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* High-visibility Export Header */
    .export-month-header {
        display: block !important;
        text-align: center !important;
        padding: 10px 0 !important;
        margin-bottom: 5px !important;
        border-bottom: 3px solid #000 !important;
        color: #000 !important;
        width: 100% !important;
    }

    .export-month-header .month-name {
        font-size: 32pt !important;
        font-weight: 900 !important;
        text-transform: uppercase !important;
    }

    .export-month-header .year-num {
        font-size: 24pt !important;
        font-weight: 400 !important;
        margin-left: 10px !important;
    }

    body.pme-view #pmeContainer,
    body:not(.pme-view):not(.annual-export-mode) #viewContainer,
    #print-view-container:not(:empty) {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
    }

    #pmeGanttArea,
    #pmeScrollContainer {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
    }

    /* CALENDAR SPECIFIC OVERRIDES */
    .month {
        display: grid !important;
        background: #fff !important;
        border: 1px solid #000 !important;
        gap: 0 !important;
    }

    .dow {
        background: #f0f0f0 !important;
        color: #000 !important;
        border-bottom: 1px solid #000 !important;
        border-right: 1px solid #000 !important;
    }

    .daycell {
        background: #fff !important;
        color: #000 !important;
        border-right: 1px solid #000 !important;
        border-bottom: 1px solid #000 !important;
        min-height: 80px !important;
        page-break-inside: avoid !important;
    }

    .day-num {
        color: #000 !important;
        font-weight: 900 !important;
    }

    .card,
    .mini,
    .card-slim {
        background: #fff !important;
        border: 1px solid #ccc !important;
        color: #000 !important;
        box-shadow: none !important;
        page-break-inside: avoid !important;
    }

    /* GANTT (PME) SPECIFIC ADJUSTMENTS */
    #pmeContainer {
        zoom: 0.75 !important;
        /* Balanced scale to ensure 1-page fit */
    }

    #ganttChart,
    #ganttHeader,
    #ganttChart::before,
    .pme-header-row,
    .pme-dimension-row,
    .pme-action-row,
    .pme-milestone-row,
    .gantt-wrapper {
        background: #fff !important;
        color: #000 !important;
    }

    [data-sticky="true"] {
        position: relative !important;
        left: 0 !important;
        border-right: 1px solid #ccc !important;
        background: #fdfdfd !important;
        width: 280px !important;
        flex: 0 0 280px !important;
        min-width: 280px !important;
        max-width: 280px !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        padding-left: 10px !important;
        padding-right: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        text-align: left !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    .pme-dim-title,
    .pme-action-name {
        text-align: left !important;
        color: #000 !important;
        opacity: 1 !important;
        line-height: 1.1 !important;
    }

    .pme-dim-title {
        font-size: 11.5px !important;
        font-weight: 900 !important;
        white-space: nowrap !important;
    }

    .pme-action-name {
        font-size: 10.5px !important;
        font-weight: 400 !important;
        white-space: normal !important;
        flex: 1 !important;
    }

    /* REDUNDANCY CLEANUP: Force hide repeated titles */
    #pmeContainer h3,
    #viewContainer h2:not(.export-month-title),
    .pme-wrapper h3,
    .content-head h2 {
        display: none !important;
    }

    /* Annual Export Month Title */
    .export-month-title {
        display: block !important;
        color: #000 !important;
        font-size: 24pt !important;
        font-weight: 900 !important;
        margin: 0 0 10px 0 !important;
        padding-bottom: 5px !important;
        border-bottom: 2px solid #000 !important;
        text-transform: uppercase !important;
        text-align: left !important;
    }

    /* Exceptions for Calendar Month Title (Single Month View) */
    #viewContainer .calendar-month-title {
        display: block !important;
        color: #000 !important;
        font-size: 18px !important;
        font-weight: 800 !important;
        margin: 0 !important;
        text-transform: uppercase !important;
    }

    /* Hide navigation buttons in Calendar Header */
    .view-calendar .actions,
    #viewContainer .actions {
        display: none !important;
    }

    .pme-dimension-row,
    .pme-action-row {
        min-height: 0 !important;
        gap: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border-bottom: 1px solid #eee !important;
    }

    /* Force visibility of Header Rows (Weeks, Days, etc) */
    .pme-header-row,
    .pme-header-row div,
    .pme-header-row span {
        color: #000 !important;
        opacity: 1 !important;
        font-weight: 800 !important;
    }

    .pme-header-row:nth-child(2) div,
    .pme-header-row:nth-child(5) div {
        font-size: 11px !important;
        font-weight: 900 !important;
    }

    .gantt-month-nav {
        background: #eee !important;
        color: #333 !important;
        border-right: 1px solid #ddd !important;
    }

    .gantt-v-line {
        border-left: 1px solid #eee !important;
    }

    .gantt-month-divider {
        border-left: 1px solid #bbb !important;
    }

    /* Hitos markers */
    .hito-capsule {
        background: #f0f0f0 !important;
        border: 1px solid #000 !important;
        color: #000 !important;
    }

    /* Print Header Display - ULTRA COMPACT */
    #print-only-header {
        display: flex !important;
        align-items: center;
        gap: 12px;
        border-bottom: 2px solid #000;
        margin-bottom: 4px;
        padding-bottom: 2px;
    }

    .print-logo {
        height: 30px;
        width: auto;
    }

    .print-main-title {
        margin: 0;
        font-size: 12pt;
        font-weight: 900;
        text-transform: uppercase;
    }

    .print-subtitle {
        margin: 0;
        font-size: 8pt;
        font-weight: 700;
    }

    /* Multi-page Annual Export Layout */
    .print-page-break {
        page-break-before: always !important;
        height: 0;
        margin: 0;
    }
}

/* Hidden by default in screen view */
#print-only-header {
    display: none;
}