/* ==================================================
   MOBILE OPTIMIZATION CSS - UPDATED FOR BETTER SCROLLING
   ==================================================
   Comprehensive fixes for mobile scrolling issues
   ================================================== */

/* Box sizing for all elements */
* {
    box-sizing: border-box;
}

/* CRITICAL: Root level scrolling fixes for mobile */
html {
    /* Allow natural scrolling - no height restrictions */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    /* Critical: Use min-height instead of height to allow content expansion */
    min-height: 100vh;
    /* Enable touch scrolling on body */
    -webkit-overflow-scrolling: touch;
}

/* Main app container - flexible height for natural scrolling */
app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
    /* Don't restrict overflow - let content determine scrolling */
}

/* Universal mobile touch scrolling - applies to ALL touch devices */
@media (any-pointer: coarse), (pointer: coarse), (hover: none), screen and (max-width: 1024px) {
    /* PRIORITY 1: Enable momentum scrolling for ALL elements */
    * {
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* PRIORITY 2: Ensure root elements allow scrolling */
    html {
        overflow: auto !important;
        overflow-y: auto !important;
        touch-action: pan-x pan-y !important;
        /* Remove any height restrictions */
        height: auto !important;
    }
    
    body {
        overflow: auto !important;
        overflow-y: auto !important;
        touch-action: pan-x pan-y !important;
        /* Prevent horizontal scrolling but allow vertical */
        overflow-x: hidden !important;
        /* Use flexible height */
        height: auto !important;
        min-height: 100vh !important;
    }
    
    /* PRIORITY 3: Fix DevExpress containers that often block mobile scrolling */
    .dx-blazor-app-root,
    .dx-blazor-app,
    .xaf-blazor-app,
    app {
        /* Remove overflow restrictions that prevent scrolling */
        overflow: visible !important;
        overflow-y: visible !important;
        /* Use flexible heights */
        height: auto !important;
        min-height: 100vh !important;
        /* Enable momentum scrolling */
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* PRIORITY 4: Fix main content areas */
    .dx-blazor-app-content,
    .main-content,
    .content-wrapper,
    .page-content,
    main {
        /* Allow vertical scrolling */
        overflow-y: auto !important;
        overflow-x: hidden !important;
        /* Enable momentum scrolling */
        -webkit-overflow-scrolling: touch !important;
        /* Allow touch panning */
        touch-action: pan-y !important;
        /* Use flexible sizing */
        flex: 1 !important;
        width: 100% !important;
        /* Remove height restrictions */
        height: auto !important;
        max-height: none !important;
    }
    
    /* PRIORITY 5: Fix DevExpress viewport issues */
    .dx-viewport {
        overflow: visible !important;
        overflow-y: visible !important;
        height: auto !important;
        min-height: 100vh !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* PRIORITY 6: Fix all scrollable containers */
    .scrollable,
    .overflow-auto,
    .overflow-scroll,
    .table-responsive,
    .modal-body,
    [style*="overflow"],
    [data-scroll="true"] {
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-y !important;
    }
}

/* Specific fixes for different mobile screen sizes */
@media screen and (max-width: 768px) {
    /* Tablet and mobile adjustments */
    body {
        /* Ensure body allows natural scrolling */
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* DevExpress containers */
    .dx-blazor-app-root,
    .dx-blazor-app,
    .xaf-blazor-app {
        overflow: visible;
        height: auto;
        min-height: 100vh;
    }
    
    .dx-blazor-app-content {
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        height: auto;
        flex: 1;
    }
    
    /* Container adjustments */
    .container,
    .container-fluid {
        padding-left: 15px;
        padding-right: 15px;
        /* Allow containers to expand naturally */
        height: auto;
    }
    
    /* Form group spacing */
    .form-group,
    .dx-form-group {
        margin-bottom: 20px;
    }
    
    /* Stack form elements vertically */
    .form-row .col,
    .form-row [class*="col-"] {
        flex: 1 1 100%;
        max-width: 100%;
        margin-bottom: 15px;
    }
    
    /* Hide complex components for mobile if needed */
    .d-none-mobile {
        display: none !important;
    }
}

@media screen and (max-width: 480px) {
    /* Phone-specific scrolling fixes */
    html, body {
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-y !important;
        overflow-x: hidden !important;
    }
    
    /* Force all containers to allow scrolling */
    .dx-viewport,
    .dx-blazor-app,
    .dx-blazor-app-root {
        overflow: visible !important;
        height: auto !important;
    }
    
    /* Ensure content areas scroll */
    .dx-blazor-app-content,
    .main-content {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-y !important;
        height: auto !important;
        max-height: none !important;
    }
}

/* Form and input optimizations */
.form-container,
.form-wrapper {
    padding: 15px;
    max-width: 100%;
    /* Allow forms to scroll naturally */
    overflow: visible;
}

/* Fix for DevExpress forms on mobile */
.dx-form,
.dx-form-group {
    width: 100%;
    max-width: none;
    /* Ensure forms don't create scroll conflicts */
    overflow: visible;
}

.dx-texteditor,
.dx-textbox,
.dx-selectbox,
.dx-datebox {
    width: 100% !important;
    min-height: 44px; /* iOS minimum touch target */
}

/* Button optimizations */
.btn, 
.dx-button {
    touch-action: manipulation;
    /* Ensure buttons don't interfere with scrolling */
    position: relative;
}

/* Grid/table responsiveness with proper mobile scrolling */
.dx-datagrid,
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Allow tables to scroll horizontally while maintaining page scroll */
    touch-action: pan-x pan-y;
}

.dx-datagrid-content {
    overflow: visible;
}

/* Modal fixes for mobile scrolling */
.modal-dialog {
    margin: 10px;
    max-height: calc(100vh - 20px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Prevent body scroll when modals are open (iOS fix) */
body.modal-open {
    /* Modified approach - allow scrolling but prevent background scroll */
    position: relative;
    overflow: hidden;
}

/* Calendar and scheduler mobile fixes */
.dx-scheduler,
.dx-calendar {
    overflow: visible;
    -webkit-overflow-scrolling: touch;
    /* Allow internal scrolling */
    touch-action: pan-y;
}

/* Navigation optimizations - prevent navbar from affecting scroll */
.navbar {
    flex-shrink: 0;
    min-height: 56px;
    /* Ensure navbar doesn't interfere with page scrolling */
    position: relative;
    z-index: 1030;
}

/* Touch-friendly navigation */
.nav-link,
.navbar-nav .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 12px 16px;
}

/* Prevent zoom on input focus (iOS) while maintaining scrolling */
input, 
textarea, 
select {
    font-size: 16px;
    max-width: 100%;
    /* Don't interfere with page scrolling */
    touch-action: pan-y;
}

/* Fix for fixed positioned elements on mobile */
.fixed-top,
.fixed-bottom {
    transform: translateZ(0); /* Force GPU acceleration */
    /* Ensure fixed elements don't block touch events */
    pointer-events: auto;
}

/* Phone-specific adjustments */
@media screen and (max-width: 576px) {
    body {
        font-size: 14px;
        /* Ensure body can scroll on phones */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .container {
        max-width: 100%;
        padding: 10px;
        /* Allow container to expand with content */
        height: auto;
    }
    
    /* Larger text inputs for phones */
    .form-control,
    .dx-texteditor-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px 16px;
    }
    
    /* Simplify tables for phones but maintain scrolling */
    .table-responsive {
        font-size: 12px;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Adjust modal for phones */
    .modal-dialog {
        margin: 5px;
        max-width: calc(100vw - 10px);
        /* Ensure modal can scroll */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Phone navigation adjustments */
    .navbar-brand {
        font-size: 1.1rem;
    }
    
    .navbar-toggler {
        border: none;
        padding: 8px 12px;
    }
    
    /* Ensure buttons are touch-friendly and don't block scrolling */
    .btn {
        min-width: 44px !important;
        min-height: 44px !important;
        font-size: 0.875rem !important;
        padding: 0.5rem 0.75rem !important;
        touch-action: manipulation;
    }
}

/* Landscape phone optimizations */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .navbar {
        min-height: 48px;
    }
    
    .nav-link {
        min-height: 40px;
        padding: 8px 12px;
    }
    
    /* Ensure landscape mode allows scrolling */
    body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Accessibility improvements for touch devices */
@media (hover: none) and (pointer: coarse) {
    /* Touch device specific styles */
    .hover-effect:hover {
        /* Disable hover effects on touch devices */
        background-color: initial;
    }
    
    /* Increase button padding for touch */
    .btn {
        padding: 12px 20px;
        touch-action: manipulation;
    }
    
    /* Ensure all interactive elements support touch scrolling */
    button,
    .btn,
    a,
    .nav-link {
        touch-action: manipulation;
    }
}

/* DevExpress Blazor specific mobile fixes */
.dx-theme-bootstrap4 .dx-scrollable-container,
.dx-theme-bootstrap5 .dx-scrollable-container {
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

/* Fix for DevExpress popups on mobile */
.dx-popup-wrapper {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

/* Interview calendar mobile optimizations */
.interview-calendar-container {
    overflow: visible;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

/* Form builder mobile optimizations */
.form-builder-container {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Use flexible height instead of fixed */
    min-height: calc(100vh - 120px);
    height: auto;
    touch-action: pan-y;
}

/* Improve focus visibility on mobile */
.form-control:focus,
.dx-texteditor.dx-state-focused {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    outline: none;
}

/* Loading and error states mobile optimization */
.loading-overlay,
.error-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    /* Allow overlay to be scrollable if content is long */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Button groups and responsive layouts */
@media (max-width: 768px) {
    .btn-group {
        flex-wrap: wrap !important;
        justify-content: flex-start !important;
        gap: 0.5rem !important;
    }
    .btn-group .btn {
        margin-bottom: 0.25rem !important;
        touch-action: manipulation;
    }
}

/* Fix for buttons being cut off in flex containers */
.btn-group {
    display: flex !important;
    flex-wrap: wrap !important;
}

/* CRITICAL: Override any problematic styles that prevent mobile scrolling */
@media (any-pointer: coarse) {
    /* Force override any styles that might prevent scrolling */
    .no-scroll,
    .overflow-hidden {
        overflow: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Ensure all main containers allow scrolling */
    #app,
    [role="main"],
    .main-content,
    .page-content,
    .content {
        overflow: visible !important;
        height: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Fix common scroll-blocking patterns */
    .h-100,
    .height-100 {
        height: auto !important;
        min-height: 100vh !important;
    }
    
    .overflow-hidden {
        overflow: visible !important;
    }
}
