
@media print {
  /* Print: usa el ancho real de página, evita recortes raros */
  body{ max-width:none !important; margin:0 !important; padding:0 !important; }
  #reporte{ max-width:none !important; }
  /* Reporte: evitar márgenes/encajonamientos indeseables en bloques inline (p.ej. Horario semanal) */
  #reporte .inline-block{ display:block !important; width:100% !important; margin-top:6px !important; }
  #reporte #rep_horario_block.inline-block .bd{ padding:0 !important; }
  #reporte #rep_horario_block.inline-block table.res{ width:100% !important; max-width:720px !important; margin:0 auto !important; display:table !important; }
  #reporte #rep_horario_block.inline-block th, 
  #reporte #rep_horario_block.inline-block td{ padding-left:8px !important; padding-right:8px !important; }
  .no-page-break { page-break-inside: auto; break-inside: auto; }
  .motivos-block{ page-break-inside:auto; break-inside:auto; orphans:4; widows:4; }
  .motivos-block .hd{ page-break-after:avoid; break-after:avoid; }
  .motivos-texto {
    white-space: pre-wrap;
    word-wrap: break-word;
    page-break-inside: auto;
    break-inside: auto;
    orphans: 4;
    widows: 4;
  }
  h3, h4, .section-title { page-break-after: avoid; break-after: avoid; }
  table { page-break-inside: auto; }
  tr { page-break-inside: avoid; break-inside: avoid; }
  .allow-break { page-break-inside: auto; break-inside: auto; }
  .inline-block{ page-break-inside:auto; break-inside:auto; }
}



        :root {
            --brand: #F26B21;
            --brand-50: #FFF4EE;
            --brand-100: #FFE5D4;
            --ink: #0f172a;
            --muted: #64748b;
            --line: #e5e5e5;
            /* línea de tablas del reporte */
            --surface: #ffffff;
        }

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

        body {
            max-width: 980px;
            margin: 18px auto;
            font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
            color: var(--ink);
            padding: 16px;
            background: linear-gradient(180deg, #fff, #fffdf9);
        }

        @media (min-width: 1020px) {
            body {
                padding: 18px 0;
            }
        }

        h2 {
            margin: 0 0 8px;
            color: #111
        }

        .muted {
            color: var(--muted);
            font-size: 12px
        }

        .sec {
            border: 1px solid #e2e8f0;
            border-radius: 14px;
            padding: 14px;
            margin: 12px 0;
            box-shadow: 0 2px 10px rgba(0, 0, 0, .04);
            background: var(--surface)
        }

        .sec h3 {
            margin: 0 0 10px;
            color: var(--brand);
            display: flex;
            align-items: center;
            gap: 8px;
            font-weight: 900;
            letter-spacing: .2px
        }

        .sec h3::before {
            content: "";
            width: 10px;
            height: 10px;
            border-radius: 999px;
            background: var(--brand);
            box-shadow: 0 0 0 6px var(--brand-50)
        }

        .grid2 {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 12px
        }
        
        /* Ajuste para el nuevo grid de 3 columnas en la sección salarial */
        .grid3 {
            display: grid;
            grid-template-columns: 1fr 1fr 1fr;
            gap: 12px
        }

        .row {
            display: flex;
            gap: 8px;
            align-items: center;
            flex-wrap: wrap
        }

        input, select, textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #e2e8f0;
            border-radius: 10px;
            font: inherit;
            background: #fff;
            min-width: 0;
            transition: border-color .2s, box-shadow .2s
        }

        textarea {
            min-height: 70px;
            resize: vertical
        }

        input[readonly] {
            background: #f9fafb
        }

        input:focus, select:focus, textarea:focus {
            outline: none;
            border-color: var(--brand);
            box-shadow: 0 0 0 3px var(--brand-100)
        }

        .pill {
            display: inline-block;
            padding: 2px 8px;
            border-radius: 999px;
            background: #f6f6f6;
            font-size: 12px
        }

        .pill-diurna {
            background: #E8FAF0;
            color: #0A7A3B
        }

        .pill-mixta {
            background: #EEF5FF;
            color: #1A58A6
        }

        .pill-nocturna {
            background: #F3E8FF;
            color: #6B21A8
        }

        .notice {
            background: #FFF4F4;
            border: 1px solid #F5C2C2;
            color: #B20000;
            border-radius: 10px;
            padding: 10px;
            margin-bottom: 12px;
            font-size: 14px;
            display: none
        }

        table.res {
            width: 100%;
            border-collapse: collapse;
            margin-top: 8px;
            font-size: 14px;
            background: #fff
        }

        table.res td {
            padding: 6px;
            border-bottom: 1px dashed #e6e6e6;
            vertical-align: top
        }

        table.res td:nth-child(2) {
            text-align: right;
            white-space: nowrap
        }

        .total {
            font-weight: 700;
            font-size: 18px
        }

        /* ===== Reporte ===== */
        #reporte, #reporte-sdi, #reporte_horario { /* AÑADIDO ID DE REPORTE SDI */
            display: none;
            margin-top: 16px;
            border: 1px solid #e2e8f0;
            border-radius: 10px;
            padding: 12px;
            background: #fff;
            box-shadow: 0 2px 10px rgba(0, 0, 0, .04);
            width: min(100%, 8.5in);
            margin-left: auto;
            margin-right: auto;
        }

        #reporte_horario { /* REPORTE HORARIO */
            display: none;
            margin-top: 16px;
            border: 2px solid var(--line);
            border-radius: 16px;
            padding: 16px;
            background: #fff;
            box-shadow: 0 10px 30px rgba(2,6,23,.06);
        }

        /* 🔽 Leyenda superior removida */
        #reporte h2, #reporte-sdi h2 {
            margin: 6px 0 12px;
            text-align: center;
            position: relative;
            font-weight: 900
        }

        #reporte h2::after, #reporte-sdi h2::after {
            content: "";
            display: block;
            width: 120px;
            height: 4px;
            background: var(--brand);
            margin: 8px auto 0;
            border-radius: 3px
        }

        #reporte .blk, #reporte-sdi .blk {
            margin-top: 10px
        }
        
        #reporte .blk > div:first-child, #reporte-sdi .blk > div:first-child {
            background: var(--brand-50);
            border-left: 4px solid var(--brand);
            padding: 6px 8px;
            font-weight: 800;
            border-radius: 6px
        }
        
        #reporte-sdi .blk { /* Estilo específico para SDI Reporte */
            background: #f8fafc;
            border: 1px solid #e2e8f0;
            padding: 12px;
            border-radius: 8px;
            margin-bottom: 15px;
        }
        
        #reporte-sdi .blk h4 {
            color: var(--brand);
            margin: 0 0 8px;
            border-bottom: 1px dashed #e2e8f0;
            padding-bottom: 4px;
        }
        #reporte-sdi .blk p {
            margin: 6px 0;
            line-height: 1.5;
        }
        #reporte-sdi .blk ul {
            margin: 8px 0 0 18px;
            padding: 0;
        }
        
        /* ➡️ Caja cerrada en tablas del reporte (FIX completo de bordes) */
        #reporte table, #reporte-sdi table, #reporte_horario table {
            width: 100%;
            border-collapse: separate;
            border-spacing: 0;
            background: #fff;
            border: 1px solid var(--line);
            border-radius: 8px;
            overflow: hidden
        }

        #reporte th, #reporte td, #reporte-sdi th, #reporte-sdi td, #reporte_horario th, #reporte_horario td {
            padding: 6px 8px;
            word-break: break-word;
            overflow-wrap: anywhere;
            border-right: 1px solid var(--line);
            border-bottom: 1px solid var(--line);
            font-size: 13px
        }

        #reporte th, #reporte-sdi th {
            background: var(--brand-50);
            text-align: left
        }

        #reporte tr th:first-child, #reporte tr td:first-child, #reporte-sdi tr th:first-child, #reporte-sdi tr td:first-child {
            border-left: 1px solid var(--line)
        }

        #reporte tr:first-child th, #reporte tr:first-child td, #reporte-sdi tr:first-child th, #reporte-sdi tr:first-child td {
            border-top: 1px solid var(--line)
        }

        #reporte .t-right, #reporte-sdi .t-right {
            text-align: right;
            white-space: nowrap
        }

        #reporte .total-row td, #reporte-sdi .total-row td {
            font-weight: 700
        }

        /* Estilos de botones (para manejar disabled) */
        #btn-calcular, #btn-print-2, #btn-reporte-sdi, #btn-reporte-principal, #btn-print-sdi { 
            background: #0f172a;
            color: #fff;
            border: none;
            padding: 9px 12px;
            border-radius: 10px;
            cursor: pointer;
            transition: background 0.2s, opacity 0.2s;
        }
        #btn-reporte-sdi {
            background: #344869; 
        }
        #btn-reporte-principal {
            background: #F26B21; 
        }
        #btn-calcular {
            background: var(--brand);
            color: #fff
        }

        /* Estilos de deshabilitado */
        #btn-copy-json[disabled], #btn-reporte-principal[disabled], #btn-reporte-sdi[disabled] {
            opacity: 0.5;
            cursor: not-allowed;
            box-shadow: none;
        }


        #btn-volver, #btn-volver-sdi, #btn-volver-principal {
            background: #e5e7eb;
            color: #111;
            border: none;
            padding: 9px 12px;
            border-radius: 10px;
            cursor: pointer
        }

        .badge-jor {
            display: inline-block;
            padding: 2px 8px;
            border-radius: 999px;
            font-size: 12px
        }

        .badge-diurna {
            background: #E8FAF0;
            color: #0A7A3B
        }

        .badge-mixta {
            background: #EEF5FF;
            color: #1A58A6
        }

        .badge-nocturna {
            background: #F3E8FF;
            color: #6B21A8
        }

        .hl-indem td {
            background: #FFF8E1
        }

        .obs-box {
            border: 2px solid #cbd5e1;
            border-radius: 10px;
            padding: 10px;
            margin-top: 10px;
            background: #fff
        }

        .obs-box h4 {
            margin: 0 0 6px;
            color: var(--ink)
        }

        .obs-box ol {
            margin: 6px 0 0 18px
        }

        .obs-badge {
            display: inline-block;
            background: #eef2ff;
            color: #1e3a8a;
            border-radius: 999px;
            padding: 2px 8px;
            font-size: 12px
        }

        .row.no-print button {
            border: none;
            border-radius: 12px;
            padding: 10px 14px
        }


        #btn-copy-json {
            background: #334155;
            color: #fff
        }

        .fab-edit {
            position: fixed;
            right: 16px;
            bottom: 16px;
            display: none;
            align-items: center;
            gap: 8px;
            padding: 12px 14px;
            border-radius: 999px;
            background: var(--brand);
            color: #fff;
            border: none;
            box-shadow: 0 10px 25px rgba(0, 0, 0, .15);
            font-weight: 700;
            z-index: 9999
        }

        body.report-mode .fab-edit {
            display: inline-flex
        }

        @media (max-width: 920px) {
            .grid2 {
                grid-template-columns: 1fr
            }
            .grid3 {
                grid-template-columns: 1fr
            }


            table.res {
                display: block;
                overflow: auto;
                -webkit-overflow-scrolling: touch
            }

            #reporte, #reporte-sdi, #reporte_horario {
                padding: 10px;
                border-radius: 12px
            }

            #reporte table, #reporte-sdi table, #reporte_horario table {
                table-layout: fixed
            }

            #reporte th, #reporte td, #reporte-sdi th, #reporte-sdi td, #reporte_horario th, #reporte_horario td {
                white-space: normal
            }
        }

        @media (max-width: 640px) {
            body {
                padding: 10px
            }

            h2 {
                font-size: 18px
            }

            .row.no-print button {
                width: 100%
            }

            .sec {
                padding: 12px
            }
        }

        /* Impresión: Carta */
        @page {
            size: 8.5in 11in;
            margin: 0.6in;
        }
        
        /* Oculta los reportes no seleccionados y muestra el activo en impresión */
        @media print {
            /* Mostrar únicamente el reporte activo en impresión */
            .report-mode-sdi #reporte { display: none !important; }
            .report-mode-sdi #reporte-sdi { display: block !important; }
            .report-mode-sdi #reporte_horario { display: none !important; }

            .report-mode-horario #reporte { display: none !important; }
            .report-mode-horario #reporte-sdi { display: none !important; }
            .report-mode-horario #reporte_horario { display: block !important; }

            /* Default: reporte finiquito/indemnización */
            .report-mode:not(.report-mode-sdi):not(.report-mode-horario) #reporte { display: block !important; }
            .report-mode:not(.report-mode-sdi):not(.report-mode-horario) #reporte-sdi { display: none !important; }
            .report-mode:not(.report-mode-sdi):not(.report-mode-horario) #reporte_horario { display: none !important; }
body > :not(#reporte):not(#reporte-sdi):not(#reporte_horario) {
                display: none !important
            }

            #reporte, #reporte-sdi, #reporte_horario {
                display: block !important;
                border: none;
                padding: 0;
                box-shadow: none;
                width: auto;
                max-width: none;
                margin: 0
            }

            #reporte .no-print, #reporte-sdi .no-print, #reporte_horario .no-print {
                display: none !important
            }

            #reporte .blk, #reporte table, #reporte tr, #reporte h2, #reporte .obs-box, 
            #reporte-sdi .blk, #reporte-sdi table, #reporte-sdi tr, #reporte-sdi h2,
            #reporte_horario .blk, #reporte_horario table, #reporte_horario tr, #reporte_horario h2, #reporte_horario .obs-box {
                break-inside: avoid;
                page-break-inside: avoid;
            }

            /* --- FIX: evitar que el título quede solo en una hoja (huérfano) --- */
            #reporte h2, #reporte-sdi h2, #reporte_horario h2 {
                break-inside: auto !important;
                page-break-inside: auto !important;
                break-after: avoid-page !important;
                page-break-after: avoid !important;
            }
            /* Permitir que los bloques grandes fluyan si no caben completos; no forzar salto del siguiente bloque */
            #reporte .blk, #reporte-sdi .blk, #reporte_horario .blk {
                break-inside: auto !important;
                page-break-inside: auto !important;
            }
            /* Evitar salto entre título y primer bloque */
            #reporte h2 + .blk, #reporte-sdi h2 + .blk, #reporte_horario h2 + .blk {
                break-before: avoid-page !important;
                page-break-before: avoid !important;
            }

            #reporte table thead, #reporte-sdi table thead, #reporte_horario table thead {
                display: table-header-group;
            }

            #reporte table tfoot, #reporte-sdi table tfoot, #reporte_horario table tfoot {
                display: table-footer-group;
            }

            html.print-compact body {
                font-size: 11pt;
            }

            html.print-compact #reporte h2, html.print-compact #reporte-sdi h2, html.print-compact #reporte_horario h2 {
                margin: 4px 0 8px;
            }

            html.print-compact #reporte .blk, html.print-compact #reporte-sdi .blk, html.print-compact #reporte_horario .blk {
                margin-top: 6px;
            }

            html.print-compact #reporte th,
            html.print-compact #reporte td,
            html.print-compact #reporte-sdi th,
            html.print-compact #reporte-sdi td,
            html.print-compact #reporte_horario th,
            html.print-compact #reporte_horario td {
                padding: 3px 5px;
                font-size: 10.5pt;
            }

            html.print-compact #reporte .obs-box, html.print-compact #reporte-sdi .obs-box, html.print-compact #reporte_horario .obs-box {
                padding: 8px;
                border-width: 1px;
            }
        }

        /* === SAFE UI HOTFIX (CSS-only; no JS touched) === */

        /* Inputs stretch and don't overlap */
        label {
            display: flex;
            flex-direction: column;
            gap: 6px;
            min-width: 0
        }

        input, select, textarea {
            width: 100%;
            max-width: 100%;
            box-sizing: border-box;
        }

        /* Grid improvements (if grid2 exists) */
        .grid2 {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 16px;
            justify-content: center;
            align-items: start
        }

        .grid2 > * {
            min-width: 0
        }

        @media (max-width: 900px) {
            .grid2 {
                grid-template-columns: 1fr
            }
        }

        /* Full-width helper (if used by the file) */
        label.full, .span2, .boxed {
            grid-column: 1 / -1
        }
        .span3 {
            grid-column: 1 / -1
        }

        /* Container centering for aesthetics (if .sec exists) */
        .sec {
            overflow: hidden
        }

        @media (min-width: 1024px) {
            .grid2 {
                max-width: 880px;
                margin: 0 auto
            }
        }

        /* Comfortable field sizing */
        :root {
            --field-font: 16px;
            --label-font: 15px;
            --field-pad-y: 12px;
            --field-pad-x: 14px;
            --field-radius: 12px;
            --grid-gap: 16px;
        }

        label {
            font-size: var(--label-font)
        }

        input, select, textarea {
            font-size: var(--field-font);
            padding: var(--field-pad-y) var(--field-pad-x);
            border-radius: var(--field-radius);
            line-height: 1.35;
        }

    
/* ===== Selector de tipo de horario (UX) ===== */
.opt-card{
  display:flex; gap:10px; padding:12px;
  border:1px solid var(--line); border-radius:14px;
  background:#fff; cursor:pointer; align-items:flex-start;
  flex:1 1 240px;
}
.opt-card:hover{ border-color: var(--brand); }
.opt-card input{ margin-top:4px; }
.mode-weekly, .mode-cycle{ display:none; }

/* Bloque de Motivos en Reporte (fuera de tabla para impresión estable) */
.motivos-block{ margin-top:10px; border:1px solid var(--line); border-radius:12px; overflow:hidden; }
.motivos-block .hd{ background:#f1f5f9; padding:8px 12px; font-weight:800; color:#0f172a; }
.motivos-block .bd{ padding:10px 12px; color:#334155; white-space:pre-wrap; word-wrap:break-word; }

/* Bloques inline (fuera de tabla, pero sin convertirse en "sección") */
.inline-block{ margin-top:8px; border:1px solid var(--line); border-radius:12px; overflow:hidden; }
.inline-block .hd{ background:#f8fafc; padding:8px 12px; font-weight:800; color:#0f172a; }
.inline-block .bd{ padding:10px 12px; color:#334155; }
.inline-block table.res{ margin:0; border-radius:0; }




/* Lite UI collapses (Vista Esencial) */
html.jmac-lite .advanced-block{display:none !important;}
