/**
 * iOS Safari Checkbox Fix
 * Fixes checkbox visibility issues on iPhone/iPad
 *
 * Problem: On iOS, custom checkbox styles sometimes make checkboxes invisible
 * Solution: Force proper appearance and prevent transformation issues
 */

/* ============================================
   GLOBAL CHECKBOX FIX
   Applies to all checkboxes in the application
   ============================================ */

input[type="checkbox"] {
    /* Force native checkbox appearance */
    -webkit-appearance: checkbox !important;
    appearance: checkbox !important;

    /* Prevent iOS from scaling or hiding the checkbox */
    -webkit-transform: scale(1) !important;
    transform: scale(1) !important;

    /* Ensure checkbox is visible */
    opacity: 1 !important;

    /* Prevent iOS tap highlight color issues */
    -webkit-tap-highlight-color: transparent;

    /* Ensure minimum size for touch targets */
    min-width: 16px;
    min-height: 16px;
}

/* ============================================
   BOOTSTRAP CHECKBOX FIX
   For Bootstrap form-check-input checkboxes
   ============================================ */

.form-check-input[type="checkbox"],
.form-check-input {
    min-width: 16px !important;
    min-height: 16px !important;
    width: 16px !important;
    height: 16px !important;
    -webkit-appearance: checkbox !important;
    appearance: checkbox !important;
    -webkit-transform: scale(1) !important;
    transform: scale(1) !important;
    opacity: 1 !important;
}

/* ============================================
   CUSTOM CHECKBOX CLASSES
   For application-specific checkbox styles
   ============================================ */

/* Product search checkboxes */
.product-checkbox {
    min-width: 18px !important;
    min-height: 18px !important;
    width: 18px !important;
    height: 18px !important;
    -webkit-appearance: checkbox !important;
    appearance: checkbox !important;
    -webkit-transform: scale(1) !important;
    transform: scale(1) !important;
    opacity: 1 !important;
}

/* Split payment checkboxes */
.split-payment-checkbox input[type="checkbox"] {
    min-width: 20px !important;
    min-height: 20px !important;
    width: 20px !important;
    height: 20px !important;
    -webkit-appearance: checkbox !important;
    appearance: checkbox !important;
    -webkit-transform: scale(1) !important;
    transform: scale(1) !important;
    opacity: 1 !important;
}

/* Select all checkboxes */
#select-all-products,
input[id*="select-all"],
input[id*="SelectAll"] {
    min-width: 18px !important;
    min-height: 18px !important;
    width: 18px !important;
    height: 18px !important;
    -webkit-appearance: checkbox !important;
    appearance: checkbox !important;
    -webkit-transform: scale(1) !important;
    transform: scale(1) !important;
    opacity: 1 !important;
}

/* ============================================
   LABEL INTERACTION FIX
   Ensures labels work properly with checkboxes on iOS
   ============================================ */

input[type="checkbox"] + label,
.form-check-input + label,
.form-check-label {
    /* Prevent text selection on double tap */
    -webkit-user-select: none;
    user-select: none;

    /* Better touch target */
    cursor: pointer;

    /* Prevent iOS from zooming on focus */
    font-size: 16px; /* iOS zoom prevention threshold */
}

/* ============================================
   FOCUS STATES
   Maintains accessibility while fixing iOS issues
   ============================================ */

input[type="checkbox"]:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

.form-check-input:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* ============================================
   DISABLED STATE
   ============================================ */

input[type="checkbox"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   iOS SPECIFIC MEDIA QUERIES
   Additional fixes for iOS devices
   ============================================ */

@supports (-webkit-touch-callout: none) {
    /* iOS specific styles */
    input[type="checkbox"] {
        /* Force checkbox to be clickable */
        pointer-events: auto !important;

        /* Prevent iOS from treating as button */
        -webkit-appearance: checkbox !important;
    }

    /* Larger touch targets for iOS */
    input[type="checkbox"] {
        min-width: 44px !important; /* iOS recommended minimum */
        min-height: 44px !important;
    }

    /* Fix for checkboxes in tables on iOS */
    table input[type="checkbox"] {
        min-width: 44px !important;
        min-height: 44px !important;
        margin: 10px;
    }
}

/* ============================================
   SAFARI SPECIFIC FIXES
   ============================================ */

@supports (-webkit-appearance: none) {
    input[type="checkbox"] {
        -webkit-appearance: checkbox !important;
    }
}

/* ============================================
   PRINT STYLES
   Ensure checkboxes print correctly
   ============================================ */

@media print {
    input[type="checkbox"] {
        -webkit-appearance: checkbox !important;
        appearance: checkbox !important;
        border: 1px solid #000;
    }
}

/* ============================================
   ACCESSIBILITY
   Maintain screen reader compatibility
   ============================================ */

input[type="checkbox"]:not(:visible) {
    /* For custom checkboxes with hidden inputs */
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================
   TESTING UTILITY
   For debugging checkbox visibility issues
   ============================================ */

/*
 Uncomment to test checkbox visibility:
 input[type="checkbox"] {
     border: 2px solid red !important;
     background: yellow !important;
 }
*/