/* --- ESTILOS GENERALES Y DISEÑO RESPONSIVO --- */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: Arial, sans-serif; }
body { background-color: #f4f6f9; color: #333333; padding: 20px; }
.container { max-width: 1200px; margin: 0 auto; background: #ffffff; padding: 20px; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }

/* --- CABECERA Y BOTONES --- */
.header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 15px; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 2px solid #eeeeee; }
.controls { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.btn { padding: 12px 24px; font-size: 16px; font-weight: bold; border: none; border-radius: 6px; cursor: pointer; transition: background 0.2s; }
.btn-edit { background-color: #0076d6; color: white; }
.btn-save { background-color: #28a745; color: white; display: none; }
.btn-cancel { background-color: #dc3545; color: white; }
.btn-confirm { background-color: #28a745; color: white; }
.btn-pdf { background-color: #17a2b8; color: white; }

/* --- REGLAS PARA MODO EDICIÓN --- */
.edit-active .btn-edit { background-color: #6c757d; }
.edit-active .btn-save { display: inline-block; }
.edit-active .calendar-grid { background-color: #fffdf0; }
.edit-active #btnPDF { display: none; }

/* --- CABECERA FUSIONADA DEL MES Y DÍAS --- */
.calendar-month-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #005fbd; 
    color: white;
    padding: 15px 20px;
    border-radius: 4px 4px 0 0; 
    font-size: 22px;
    text-transform: uppercase;
    font-weight: bold;
}

.btn-nav { background: none; border: none; color: white; font-size: 24px; cursor: pointer; padding: 0 15px; transition: transform 0.2s; }
.btn-nav:hover { transform: scale(1.3); }
.edit-active .btn-nav { opacity: 0.3; cursor: not-allowed; pointer-events: none; } 

.weekdays-header { 
    display: grid; 
    grid-template-columns: repeat(7, 1fr); 
    text-align: center; 
    font-weight: bold; 
    background-color: #0076d6; 
    color: white; 
    padding: 10px 0; 
    border-radius: 0 0 4px 4px; 
    margin-bottom: 5px; 
}

/* --- CUADRÍCULA DEL CALENDARIO --- */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); transition: background-color 0.3s; }
.day-cell { background-color: #ffffff; border: 1px solid #dddddd; min-height: initial; display: flex; flex-direction: column; }
.day-number { font-weight: bold; font-size: 16px; margin-bottom: 4px; display: block; text-align: right; }
.day-cell.weekend { background-color: #e9ecef; }

/* --- SECCIONES INTERNAS DE CADA DÍA --- */
.section-row { display: flex; flex-direction: column; font-size: 14px; }
.section-value { border-radius: 4px; min-height: 28px; word-break: break-all; text-align: center; }

/* Contenedores de Inputs */
.cell-input-wrapper { display: none; }
.edit-active .section-value { display: none; }
.edit-active .cell-input-wrapper { display: block; }
.edit-active .double-input-group { display: flex; }

.cell-input { width: 100%; padding: 8px; font-size: 14px; border: 2px solid #0076d6; border-radius: 4px; }

/* Estructuras especiales (Doble y Borrado) */
.double-input-group { align-items: center; gap: 4px; }
.double-input-group .cell-input { width: 100%; }
.double-input-group .separator { font-weight: bold; color: #0076d6; }

.extra-input-wrapper { display: flex; gap: 4px; }
.extra-input-wrapper .cell-input { flex-grow: 1; }
.btn-remove-ref { background-color: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer; padding: 0 10px; font-weight: bold; font-size: 14px; }

/* Botón Añadir Refuerzo */
.btn-add-ref { display: none; margin-top: auto; padding: 6px; font-size: 12px; font-weight: bold; background-color: #17a2b8; color: white; border: none; border-radius: 4px; cursor: pointer; }
.edit-active .btn-add-ref { display: block; }

/* --- ESTILOS ESPECÍFICOS PARA GUARDIAS (ORDENADOR) --- */
span[id*="-guardia"].section-value, 
span[id*="-labRef"].section-value,
input[data-field^="guardia"].cell-input,
input[data-field="labRef"].cell-input {
    font-size: 16px;
    text-transform: uppercase;
}

/* --- VENTANA EMERGENTE Y LISTA DE CAMBIOS --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.6); display: flex; justify-content: center; align-items: center; opacity: 0; pointer-events: none; transition: opacity 0.2s ease; z-index: 1000; }
.modal-overlay.modal-open { opacity: 1; pointer-events: auto; }
.modal-content { background: white; padding: 30px; border-radius: 8px; max-width: 500px; width: 90%; box-shadow: 0 4px 15px rgba(0,0,0,0.2); text-align: center; }
.modal-content h3 { margin-bottom: 15px; font-size: 20px; }
.modal-content p { margin-bottom: 15px; font-size: 16px; color: #444444; }
.modal-actions { display: flex; justify-content: center; gap: 15px; }

.changes-container { text-align: left; background: #f8f9fa; padding: 15px; border-radius: 5px; margin-bottom: 20px; font-size: 14px; max-height: 200px; overflow-y: auto; border: 1px solid #eeeeee; }
.change-day-block { margin-bottom: 12px; }
.change-item { margin-left: 15px; display: block; color: #0076d6; font-family: monospace; font-size: 13px; }

/* --- ADAPTACIÓN MÓVIL (OPCIÓN 2: TODO A LA VISTA) --- */
@media (orientation: portrait) {
    body { padding: 5px; }
    .container { padding: 5px; }
    .header { flex-direction: column; text-align: center; }
    .calendar-month-header { font-size: 16px; padding: 10px; }
    .btn-nav { font-size: 18px; padding: 0 10px; }
    .weekdays-header { display: none; } 
    .day-cell { padding: 3px; }
    .day-number { font-size: 12px; }
    .section-value { font-size: 9px; min-height: 20px; word-break: break-word; }
    .cell-input { font-size: 10px; padding: 2px; }
    .btn-add-ref { font-size: 8px; padding: 4px 2px; }
    .btn-remove-ref { font-size: 10px; padding: 0 4px; }
    
    /* Reducción específica a 12px para las guardias en móvil */
    span[id*="-guardia"].section-value, 
    span[id*="-labRef"].section-value,
    input[data-field^="guardia"].cell-input,
    input[data-field="labRef"].cell-input {
        font-size: 12px;
    }
}

/* --- CONFIGURACIÓN DE IMPRESIÓN / EXPORTACIÓN A PDF EN APAISADO --- */
@media print {
    @page { 
        size: landscape; 
        margin: 8mm; 
    }
    
    body { background-color: #ffffff; padding: 0; }
    .container { box-shadow: none; padding: 0; max-width: 100%; }
    
    /* Ocultar elementos interactivos de la web en la impresión */
    .header, .btn-nav, .btn-add-ref { display: none !important; }
    
    /* Transformar la cabecera en un título limpio para el folio */
    .calendar-month-header {
        background-color: transparent !important;
        color: #333333 !important;
        justify-content: center !important;
        padding: 0 0 10px 0 !important;
        font-size: 28px !important;
    }
    
    /* Forzar rejilla horizontal perfecta de los días de la semana */
    .weekdays-header {
        display: grid !important;
        grid-template-columns: repeat(7, 1fr) !important;
        background-color: #0076d6 !important;
        color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        padding: 10px 0;
        font-size: 14px;
        border-radius: 4px 4px 0 0;
    }
    
    .calendar-grid { display: grid !important; grid-template-columns: repeat(7, 1fr) !important; gap: 4px; }
    
    .day-cell {
        min-height: 105px;
        page-break-inside: avoid;
        background-color: #ffffff !important;
        border: 1px solid #cccccc !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        padding: 4px;
    }
    
    .day-cell.weekend { background-color: #e9ecef !important; }
    .day-number { font-size: 14px; margin-bottom: 2px; }
    .section-value { -webkit-print-color-adjust: exact; print-color-adjust: exact; font-size: 11px; min-height: 22px; }
    
    /* Proporción para destacar guardias en la impresión sin saturar el espacio */
    span[id*="-guardia"].section-value, 
    span[id*="-labRef"].section-value {
        font-size: 13px !important;
    }
}