/*
 * iOS Compatibility Fixes
 * Addresses navigation, viewport, and layout issues on iOS devices
 */

/* iOS Safari viewport fixes */
@supports (-webkit-touch-callout: none) {
    /* Target iOS Safari specifically */
    html {
        height: -webkit-fill-available;
    }
    
    body {
        min-height: 100vh;
        min-height: -webkit-fill-available;
        position: relative;
    }
}

/* Fix for iOS Safari address bar causing layout shifts */
@media screen and (max-width: 768px) {
    body {
        width: 100%;
        overflow-x: hidden;
    }
    
    /* Ensure scrolling works on iOS */
    .main-content,
    .page-container,
    .content-wrapper {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        height: 100vh;
        height: -webkit-fill-available;
    }
}

/* iOS Navigation Bar Fixes */
@supports (-webkit-touch-callout: none) {
    .main-navbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        z-index: 1000;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    .navbar-container {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* Fix mobile navigation panel on iOS */
@supports (-webkit-touch-callout: none) {
    .mobile-nav {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: 100vh;
        height: -webkit-fill-available;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    .mobile-nav.open {
        display: flex !important;
    }
}

/* Fix touch event issues on iOS */
@media (max-width: 768px) {
    button,
    a,
    .clickable,
    .btn,
    .mobile-nav-toggle {
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Ensure buttons are tappable */
    button,
    .btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Fix iOS input zoom issue */
@supports (-webkit-touch-callout: none) {
    input,
    textarea,
    select {
        font-size: 16px !important;
    }
}

/* Fix floating elements on iOS */
@supports (-webkit-touch-callout: none) {
    .floating-currency-bar,
    #currency-bar-tab {
        position: fixed;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* Fix dropdown positioning on iOS */
@supports (-webkit-touch-callout: none) {
    .nav-dropdown,
    .profile-menu,
    .dropdown-menu {
        position: fixed !important;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        max-height: 80vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Prevent iOS Safari from adding rounded corners and shadows to elements */
@supports (-webkit-touch-callout: none) {
    input,
    textarea,
    button,
    select {
        -webkit-appearance: none;
        appearance: none;
        border-radius: 0;
    }
    
    button,
    .btn {
        border-radius: 8px;
    }
}

/* Fix iOS safe area insets */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    .main-navbar {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
}

/* Fix iOS scroll bounce */
@supports (-webkit-touch-callout: none) {
    body {
        overscroll-behavior-y: none;
    }
}

/* Fix iOS button active state */
@media (max-width: 768px) {
    button:active,
    .btn:active,
    a:active {
        opacity: 0.7;
        transform: scale(0.98);
    }
}

/* Prevent iOS from highlighting links */
@supports (-webkit-touch-callout: none) {
    a,
    button {
        -webkit-tap-highlight-color: transparent;
    }
}

/* Fix iOS modal/overlay positioning */
@supports (-webkit-touch-callout: none) {
    .modal-overlay,
    .popup-overlay,
    .overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100vh;
        height: -webkit-fill-available;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* Fix iOS hamburger menu positioning */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        .mobile-nav-toggle,
        .hamburger {
            position: relative;
            z-index: 1001;
            -webkit-transform: translateZ(0);
            transform: translateZ(0);
            /* Ensure touch targets are large enough */
            min-width: 44px;
            min-height: 44px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .mobile-nav {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100vh;
            height: -webkit-fill-available;
            z-index: 1000;
            -webkit-transform: translateZ(0);
            transform: translateZ(0);
        }
    }
}

/* Enhanced iOS touch handling */
@supports (-webkit-touch-callout: none) {
    /* Ensure all clickable elements have proper touch handling */
    .nav-link,
    .nav-item,
    .nav-icon,
    .mobile-nav a,
    .mobile-nav button,
    .mobile-nav-link,
    .profile-trigger,
    .profile-menu-item {
        -webkit-tap-highlight-color: rgba(252, 157, 11, 0.2);
        cursor: pointer;
        touch-action: manipulation;
    }

    /* Fix iOS navigation bar click issues */
    .main-navbar {
        pointer-events: auto;
    }

    .main-navbar * {
        pointer-events: auto;
    }

    /* Ensure mobile nav overlay works properly on iOS */
    .mobile-nav {
        touch-action: pan-y;
        pointer-events: none;
    }

    .mobile-nav.open {
        pointer-events: auto;
    }

    .mobile-nav-content {
        pointer-events: auto;
        touch-action: pan-y;
    }
}

/* Fix iOS body scroll issues when mobile nav is open */
@supports (-webkit-touch-callout: none) {
    body.mobile-nav-open {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
}

/* iOS-specific layout fixes */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        /* Fix navbar height on iOS */
        .main-navbar {
            height: 60px;
            min-height: 60px;
        }

        .navbar-container {
            height: 60px;
            min-height: 60px;
        }

        /* Ensure proper spacing for content below navbar */
        body {
            padding-top: 60px !important;
        }

        /* Fix profile dropdown on iOS */
        .profile-dropdown-menu {
            position: fixed !important;
            top: 70px !important;
            right: 10px !important;
            left: auto !important;
            max-height: calc(100vh - 80px);
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }
    }
}

/* Fix iOS stacking context issues */
@supports (-webkit-touch-callout: none) {
    .main-navbar {
        isolation: isolate;
    }

    .mobile-nav {
        isolation: isolate;
    }
}

