/* Browser Compatibility CSS - Addresses Safari/Chrome differences */

/* 1. CSS Grid fallbacks for older browsers */
@supports not (display: grid) {
    .grid,
    grid {
        display: flex;
        flex-wrap: wrap;
    }
    
    [class*="grid-template-columns"] {
        display: flex;
    }
}

/* 2. Flexbox vendor prefixes for older Safari versions */
.flex,
row,
.row,
column,
.column {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
}

column,
.column {
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -ms-flex-direction: column;
    flex-direction: column;
}

.flex-wrap {
    -webkit-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
}

.nowrap {
    -webkit-flex-wrap: nowrap;
    -ms-flex-wrap: nowrap;
    flex-wrap: nowrap;
}

/* 3. Justify-content vendor prefixes */
.justify-content-center {
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
}

.justify-content-flex-end {
    -webkit-box-pack: end;
    -webkit-justify-content: flex-end;
    -ms-flex-pack: end;
    justify-content: flex-end;
}

.justify-content-space-between {
    -webkit-box-pack: justify;
    -webkit-justify-content: space-between;
    -ms-flex-pack: justify;
    justify-content: space-between;
}

/* 4. Align-items vendor prefixes */
.align-items-center {
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
}

.align-items-flex-end {
    -webkit-box-align: end;
    -webkit-align-items: flex-end;
    -ms-flex-align: end;
    align-items: flex-end;
}

/* 5. Transform vendor prefixes */
.transform-scale {
    -webkit-transform: scale(0.98);
    -moz-transform: scale(0.98);
    -ms-transform: scale(0.98);
    transform: scale(0.98);
}

/* 6. Transition vendor prefixes */
.transition-all {
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    -ms-transition: all 0.3s ease;
    transition: all 0.3s ease;
}

.transition-background {
    -webkit-transition: background 1s ease;
    -moz-transition: background 1s ease;
    -ms-transition: background 1s ease;
    transition: background 1s ease;
}

/* 7. Safari-specific fixes */
/* Fix for Safari's handling of text-wrap: pretty */
@supports not (text-wrap: pretty) {
    body {
        text-wrap: balance; /* Fallback for Safari */
    }
}

/* Safari flexbox bug fixes */
article {
    -webkit-flex-shrink: 0;
    -ms-flex-negative: 0;
    flex-shrink: 0;
}

/* 8. Box-sizing reset for all elements (Safari consistency) */
*,
*::before,
*::after {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

/* 9. Image rendering consistency */
img {
    -ms-interpolation-mode: bicubic; /* IE */
    image-rendering: -webkit-optimize-contrast; /* Safari */
    image-rendering: crisp-edges; /* Standard */
}

/* 10. Font rendering consistency */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* 11. Safari grid gap fallback */
@supports not (gap: 1rem) {
    .gap-8px > * + * {
        margin-left: 8px;
    }
    
    .gap-1rem > * + * {
        margin-left: 1rem;
    }
    
    column.gap-8px > * + *,
    .column.gap-8px > * + * {
        margin-left: 0;
        margin-top: 8px;
    }
    
    column.gap-1rem > * + *,
    .column.gap-1rem > * + * {
        margin-left: 0;
        margin-top: 1rem;
    }
}

/* 12. Safari overflow handling */
.overflow-hidden {
    overflow: hidden;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* 13. Safari button appearance reset */
button,
input[type="button"],
input[type="submit"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 0; /* Reset Safari's default border-radius */
}

/* 14. Safari input field consistency */
input,
textarea,
select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 0;
}

/* 15. Safari link tap highlight */
a {
    -webkit-tap-highlight-color: transparent;
}

/* 16. Safari text size adjust */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* 17. Safari min-height fix for flex containers */
.min-height-fix {
    min-height: 1px;
}

/* 18. Safari grid auto-fit fallback */
@supports not (grid-template-columns: repeat(auto-fit, minmax(200px, 1fr))) {
    .auto-grid {
        display: flex;
        flex-wrap: wrap;
    }
    
    .auto-grid > * {
        flex: 1 1 200px;
        min-width: 200px;
    }
}

/* 19. Safari position sticky fallback */
@supports not (position: sticky) {
    .sticky {
        position: -webkit-sticky;
        position: sticky;
    }
}

/* 20. Safari backdrop-filter fallback */
@supports not (backdrop-filter: blur(10px)) {
    .backdrop-blur {
        background: rgba(255, 255, 255, 0.8);
    }
}