/* ========================================
   Mobile Safari Fixes for iPhone
   ======================================== */

/* Table Responsive Fixes for Safari/iOS */
.table-responsive {
    /* Enhanced smooth scrolling on iOS */
    -webkit-overflow-scrolling: touch;
    
    /* Prevent table from being cut off */
    overflow-x: auto;
    overflow-y: hidden;
    
    /* Ensure proper rendering on Safari */
    position: relative;
    display: block;
    width: 100%;
    
    /* Prevent horizontal bounce/overscroll */
    overscroll-behavior-x: contain;
}

/* Fix for table appearing cut on mobile Safari */
@media screen and (max-width: 768px) {
    .table-responsive {
        /* Add slight padding to prevent cut-off */
        padding-bottom: 2px;
        margin-bottom: 1rem;
    }
    
    .table-responsive table {
        /* Ensure table doesn't overflow container */
        min-width: 100%;
        margin-bottom: 0;
    }
    
    /* Fix for table cells on mobile */
    .table-responsive td,
    .table-responsive th {
        white-space: nowrap;
        vertical-align: middle;
    }
}

/* ========================================
   SweetAlert2 Toast Fixes for Safari/iOS
   ======================================== */

/* Fix for toast notifications being cut off on iPhone */
.swal2-container {
    /* Ensure container respects safe areas on iPhone */
    padding-top: env(safe-area-inset-top, 0);
    padding-right: env(safe-area-inset-right, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-left: env(safe-area-inset-left, 0);
}

/* Toast notification position fixes */
.swal2-container.swal2-top-right,
.swal2-container.swal2-top-end {
    top: env(safe-area-inset-top, 0);
    right: env(safe-area-inset-right, 0);
    padding: 1rem;
}

.swal2-container.swal2-top-left,
.swal2-container.swal2-top-start {
    top: env(safe-area-inset-top, 0);
    left: env(safe-area-inset-left, 0);
    padding: 1rem;
}

.swal2-container.swal2-top {
    top: env(safe-area-inset-top, 0);
    padding-top: 1rem;
}

.swal2-container.swal2-bottom {
    bottom: env(safe-area-inset-bottom, 0);
    padding-bottom: 1rem;
}

/* Toast popup fixes for mobile */
@media screen and (max-width: 768px) {
    .swal2-popup.swal2-toast {
        /* Ensure toast is fully visible */
        max-width: calc(100vw - 2rem);
        width: auto !important;
        
        /* Better text wrapping on mobile */
        word-wrap: break-word;
        word-break: break-word;
        
        /* Ensure content doesn't overflow */
        overflow: hidden;
        
        /* Proper padding for mobile */
        padding: 0.75rem 1rem;
        
        /* Smooth rendering on Safari */
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    /* Fix for toast title being cut off */
    .swal2-popup.swal2-toast .swal2-title {
        /* Allow text to wrap properly */
        white-space: normal;
        word-wrap: break-word;
        word-break: break-word;
        
        /* Ensure proper spacing */
        margin: 0.5rem 0.5rem 0.5rem 1rem;
        padding: 0;
        
        /* Maximum width to prevent overflow */
        max-width: 100%;
        
        /* Better line height for readability */
        line-height: 1.4;
        
        /* Proper font sizing for mobile */
        font-size: 0.95rem;
    }
    
    /* Fix for toast HTML container */
    .swal2-popup.swal2-toast .swal2-html-container {
        /* Allow text to wrap */
        white-space: normal;
        word-wrap: break-word;
        word-break: break-word;
        
        /* Proper margins */
        margin: 0.5rem 0.5rem 0.5rem 1rem;
        padding: 0;
        
        /* Better font sizing */
        font-size: 0.9rem;
        line-height: 1.4;
        
        /* Prevent overflow */
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Fix for toast icon */
    .swal2-popup.swal2-toast .swal2-icon {
        /* Proper sizing on mobile */
        width: 2rem;
        min-width: 2rem;
        height: 2rem;
        margin: 0 0.5rem 0 0;
    }
    
    /* Fix for toast close button */
    .swal2-popup.swal2-toast .swal2-close {
        /* Ensure close button is visible and tappable */
        width: 1.5rem;
        height: 1.5rem;
        font-size: 1.25rem;
        margin: 0;
        padding: 0;
        
        /* Better tap target size for mobile */
        min-width: 44px;
        min-height: 44px;
    }
}

/* Specific fixes for iPhone X and newer (with notch) */
@supports (padding: max(0px)) {
    @media screen and (max-width: 768px) {
        .swal2-container.swal2-top-right,
        .swal2-container.swal2-top-end {
            top: max(1rem, env(safe-area-inset-top));
            right: max(1rem, env(safe-area-inset-right));
        }
        
        .swal2-container.swal2-top-left,
        .swal2-container.swal2-top-start {
            top: max(1rem, env(safe-area-inset-top));
            left: max(1rem, env(safe-area-inset-left));
        }
        
        .swal2-container.swal2-top {
            top: max(1rem, env(safe-area-inset-top));
        }
    }
}

/* Fix for Safari-specific rendering issues */
@media screen and (max-width: 768px) {
    /* Prevent zoom on input focus (Safari specific) */
    .swal2-popup input,
    .swal2-popup select,
    .swal2-popup textarea {
        font-size: 16px !important;
    }
    
    /* Better touch handling */
    .swal2-popup {
        touch-action: manipulation;
    }
}

/* RTL Support for Arabic */
html[dir="rtl"] .swal2-popup.swal2-toast .swal2-title,
html[dir="rtl"] .swal2-popup.swal2-toast .swal2-html-container {
    text-align: right;
    margin-right: 1rem;
    margin-left: 0.5rem;
}

html[dir="rtl"] .swal2-popup.swal2-toast .swal2-icon {
    margin-right: 0;
    margin-left: 0.5rem;
}
