/* Safari Touch Event Fixes for Syncfusion Blazor Components */

/* Safari-specific touch event improvements */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* Grid component fixes */
    .e-grid {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-overflow-scrolling: touch;
    }
    
    .e-grid .e-gridcontent {
        -webkit-overflow-scrolling: touch;
    }
    
    .e-grid .e-rowcell,
    .e-grid .e-headercell {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        -webkit-touch-callout: none;
    }
    
    /* Specific fixes for buttons inside grid cells */
    .e-grid .e-rowcell button,
    .e-grid .e-rowcell .e-btn,
    .e-grid .e-rowcell [role="button"] {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        touch-action: manipulation;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        pointer-events: auto;
        position: relative;
        z-index: 1;
    }
    
    .e-grid .e-toolbar .e-btn {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    /* Dropdown component fixes */
    .e-dropdownlist {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    .e-dropdownlist input {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    .e-dropdownlist .e-popup {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Button component fixes */
    .e-btn {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    /* Dialog component fixes */
    .e-dialog {
        -webkit-overflow-scrolling: touch;
    }
    
    .e-dialog .e-dlg-content {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Input component fixes */
    .e-input-group input {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    /* Calendar component fixes */
    .e-calendar {
        -webkit-overflow-scrolling: touch;
    }
    
    .e-calendar .e-content {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Numeric textbox fixes */
    .e-numerictextbox input {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    /* Checkbox fixes */
    .e-checkbox {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    .e-checkbox input[type="checkbox"] {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
}

/* Additional Safari touch improvements */
@supports (-webkit-touch-callout: none) {
    /* Force hardware acceleration for better touch performance */
    .e-grid,
    .e-dropdownlist,
    .e-btn,
    .e-dialog {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    /* Improve scrolling performance */
    .e-grid .e-gridcontent,
    .e-dropdownlist .e-popup,
    .e-dialog .e-dlg-content {
        -webkit-overflow-scrolling: touch;
        overflow-scrolling: touch;
    }
}

/* Safari-specific coordinate calculation fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* Fix for coordinate offset issues in Safari */
    .e-grid .e-rowcell:active,
    .e-grid .e-headercell:active {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    /* Improve touch target sizes for Safari */
    .e-grid .e-rowcell,
    .e-grid .e-headercell {
        min-height: 44px; /* Apple's recommended minimum touch target size */
    }
    
    .e-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Fix for Safari's touch event handling */
    .e-grid .e-rowcell *,
    .e-grid .e-headercell * {
        pointer-events: auto;
    }
}

/* Safari-specific animation and transition fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* Disable animations that can cause coordinate issues in Safari */
    .e-grid .e-rowcell,
    .e-grid .e-headercell {
        -webkit-transition: none;
        transition: none;
    }
    
    /* Smooth scrolling for Safari */
    .e-grid .e-gridcontent {
        scroll-behavior: smooth;
        -webkit-scroll-behavior: smooth;
    }
}

/* High DPI Safari fixes */
@media screen and (-webkit-min-device-pixel-ratio: 2) {
    /* Ensure proper scaling on high DPI displays */
    .e-grid,
    .e-dropdownlist,
    .e-btn,
    .e-dialog {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Safari mobile specific fixes */
@media screen and (max-width: 768px) and (-webkit-min-device-pixel-ratio: 0) {
    /* Mobile Safari specific improvements */
    .e-grid .e-rowcell,
    .e-grid .e-headercell {
        padding: 8px 4px;
        font-size: 14px;
    }
    
    .e-btn {
        padding: 8px 12px;
        font-size: 14px;
    }
    
    /* Improve touch responsiveness on mobile Safari */
    .e-grid,
    .e-dropdownlist,
    .e-btn {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
}

/* Safari 2024+ mouse position fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* Fix for Safari cursor misalignment issues */
    body {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    /* Improve cursor accuracy for interactive elements */
    .e-grid .e-rowcell,
    .e-grid .e-headercell,
    .e-btn,
    .e-dropdownlist {
        cursor: pointer;
        position: relative;
        z-index: 1;
    }
    
    /* Force hardware acceleration for better coordinate accuracy */
    .e-grid,
    .e-dropdownlist,
    .e-btn,
    .e-dialog {
        will-change: transform;
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
    }
    
    /* Fix for Safari's viewport scaling coordinate issues */
    @supports (-webkit-touch-callout: none) {
        html {
            -webkit-text-size-adjust: 100%;
            -ms-text-size-adjust: 100%;
        }
        
        /* Prevent coordinate offset from CSS zoom */
        body {
            zoom: 1;
            -webkit-zoom: 1;
        }
    }
    
    /* High DPI display fixes for Safari */
    @media (-webkit-min-device-pixel-ratio: 2) {
        .e-grid .e-rowcell,
        .e-grid .e-headercell {
            /* Ensure crisp rendering on high DPI displays */
            -webkit-font-smoothing: subpixel-antialiased;
            font-smoothing: subpixel-antialiased;
        }
    }
    
    /* Safari specific pointer event fixes */
    .e-grid .e-rowcell:hover,
    .e-grid .e-headercell:hover,
    .e-btn:hover {
        /* Force position recalculation on hover */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}