/* Browser Compatibility & Cross-Platform Enhancements */

/* Chrome Mobile Specific Fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* Chrome Android scroll fix */
    body {
        -webkit-overflow-scrolling: auto;
    }
    
    /* Chrome touch optimization */
    .chrome-touch {
        touch-action: manipulation;
    }
    
    /* Chrome form validation */
    input:invalid {
        box-shadow: none;
        border-color: #dc3545;
    }
    
    input:valid {
        border-color: #28a745;
    }
}

/* Safari Mobile Specific Fixes */
@supports (-webkit-touch-callout: none) {
    /* Safari iOS fixes */
    .safari-fix {
        -webkit-appearance: none;
        -webkit-border-radius: 10px;
        border-radius: 10px;
    }
    
    /* Safari input focus fix */
    input, textarea, select {
        -webkit-appearance: none;
        appearance: none;
        border-radius: 10px;
    }
    
    /* Safari button fix */
    button, .btn {
        -webkit-appearance: none;
        appearance: none;
    }
    
    /* Safari sticky position fix */
    .sticky-safari {
        position: -webkit-sticky;
        position: sticky;
    }
    
    /* Safari overflow fix */
    .safari-overflow {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Safari transform fix */
    .safari-transform {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    /* Safari backdrop filter */
    .safari-backdrop {
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
    }
}

/* Firefox Mobile Compatibility */
@-moz-document url-prefix() {
    /* Firefox specific fixes */
    .firefox-fix {
        -moz-appearance: none;
        appearance: none;
    }
    
    /* Firefox input styling */
    input[type="text"],
    input[type="email"],
    input[type="password"] {
        -moz-appearance: none;
        appearance: none;
    }
    
    /* Firefox button styling */
    button::-moz-focus-inner {
        border: 0;
        padding: 0;
    }
}

/* Edge Mobile Compatibility */
@supports (-ms-ime-align: auto) {
    .edge-fix {
        -ms-touch-action: manipulation;
        touch-action: manipulation;
    }
}

/* Samsung Internet Browser */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .samsung-internet {
        /* Samsung Internet specific optimizations */
        -webkit-tap-highlight-color: rgba(184, 134, 11, 0.2);
    }
}

/* Opera Mobile */
@media all and (-webkit-min-device-pixel-ratio: 0) and (min-color-index: 0) {
    .opera-mobile {
        /* Opera mobile optimizations */
        -o-touch-action: manipulation;
        touch-action: manipulation;
    }
}

/* UC Browser */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .uc-browser {
        /* UC Browser optimizations */
        -webkit-text-size-adjust: 100%;
    }
}

/* iOS Specific Enhancements */
@supports (-webkit-touch-callout: none) {
    /* iOS 15+ enhancements */
    @media (min-resolution: 2dppx) {
        .ios-retina {
            image-rendering: -webkit-optimize-contrast;
        }
    }
    
    /* iOS dark mode support */
    @media (prefers-color-scheme: dark) {
        .ios-dark {
            background-color: #1c1c1e;
            color: #ffffff;
        }
    }
    
    /* iOS safe area support */
    .ios-safe-area {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    /* iOS keyboard handling */
    .ios-keyboard-fix {
        /* Fix for iOS keyboard covering inputs */
        padding-bottom: env(keyboard-inset-height, 0px);
    }
}

/* Android Specific Enhancements */
@media screen and (max-width: 768px) {
    /* Android Chrome address bar fix */
    .android-viewport {
        min-height: 100vh;
        min-height: calc(var(--vh, 1vh) * 100);
    }
    
    /* Android input zoom prevention */
    @viewport {
        width: device-width;
        zoom: 1.0;
        user-zoom: fixed;
    }
    
    /* Android touch feedback */
    .android-ripple {
        position: relative;
        overflow: hidden;
    }
    
    .android-ripple::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        border-radius: 50%;
        background: rgba(184, 134, 11, 0.3);
        transform: translate(-50%, -50%);
        transition: width 0.3s, height 0.3s;
    }
    
    .android-ripple:active::before {
        width: 200px;
        height: 200px;
    }
}

/* WebView Compatibility */
.webview-fix {
    /* Fix for embedded WebView browsers */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* PWA Support */
@media (display-mode: standalone) {
    .pwa-mode {
        /* Adjustments for PWA mode */
        padding-top: 20px;
    }
    
    .pwa-header {
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .high-contrast {
        border: 2px solid;
        background: Window;
        color: WindowText;
    }
    
    .btn {
        border: 2px solid ButtonText;
        background: ButtonFace;
        color: ButtonText;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .respect-motion-preference {
        animation: none !important;
        transition: none !important;
    }
    
    .scroll-behavior-auto {
        scroll-behavior: auto !important;
    }
}

/* Print Compatibility */
@media print {
    .print-optimize {
        -webkit-print-color-adjust: exact;
        color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .no-print {
        display: none !important;
    }
    
    .print-only {
        display: block !important;
    }
}

/* Screen Reader Optimization */
@media (prefers-reduced-motion: reduce) {
    .screen-reader-optimized {
        animation: none;
        transition: none;
    }
}

/* Touch Device Specific */
@media (pointer: coarse) {
    .touch-optimized {
        /* Larger touch targets for touch devices */
        min-height: 44px;
        min-width: 44px;
        padding: 12px;
    }
    
    .touch-button {
        padding: 15px 20px;
        font-size: 16px;
    }
}

/* Mouse/Trackpad Device Specific */
@media (pointer: fine) {
    .mouse-optimized {
        /* Smaller, more precise interactions for mouse users */
        padding: 8px 12px;
    }
    
    .hover-effects:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
}

/* Cross-Browser Font Rendering */
.font-optimize {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: "kern" 1;
    font-kerning: normal;
}

/* Flexbox Fallbacks */
.flex-fallback {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
}

.flex-center-fallback {
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
}

/* Grid Fallbacks */
.grid-fallback {
    display: -ms-grid;
    display: grid;
}

/* CSS Custom Properties Fallbacks */
.custom-props-fallback {
    background: #B8860B; /* Fallback */
    background: var(--primary-color, #B8860B);
    
    color: #2C3E50; /* Fallback */
    color: var(--text-color, #2C3E50);
}

/* Viewport Units Fallbacks */
.viewport-fallback {
    height: 100vh; /* Fallback */
    height: calc(var(--vh, 1vh) * 100);
}

/* Clip-path Fallbacks */
.clippath-fallback {
    /* Fallback for browsers that don't support clip-path */
    border-radius: 10px;
    overflow: hidden;
}

@supports (clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%)) {
    .clippath-fallback {
        border-radius: 0;
        clip-path: polygon(0 0, 100% 0, 95% 100%, 0 100%);
    }
}

/* Backdrop Filter Fallbacks */
.backdrop-fallback {
    background: rgba(255, 255, 255, 0.9); /* Fallback */
}

@supports (backdrop-filter: blur(10px)) {
    .backdrop-fallback {
        background: rgba(255, 255, 255, 0.7);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
}

/* Sticky Position Fallbacks */
.sticky-fallback {
    position: relative; /* Fallback */
    position: -webkit-sticky;
    position: sticky;
    top: 0;
}

/* Object-fit Fallbacks */
.object-fit-fallback {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

@supports (object-fit: cover) {
    .object-fit-fallback {
        background: none;
        object-fit: cover;
    }
}