/* Browser Compatibility Fixes */

/* IE11 Flexbox Fixes */
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
    .row {
        display: block;
    }
    
    .col-1-2, .col-1-3, .col-2-3, .col-1-4 {
        display: inline-block;
        vertical-align: top;
    }
    
    .col-1-2 {
        width: 49%;
    }
    
    .col-1-3 {
        width: 32.33%;
    }
    
    .col-2-3 {
        width: 65.66%;
    }
    
    .col-1-4 {
        width: 24%;
    }
    
    .header-container {
        display: block;
        position: relative;
    }
    
    .logo {
        display: inline-block;
        vertical-align: middle;
    }
    
    .main-nav {
        display: inline-block;
        vertical-align: middle;
    }
    
    .secondary-nav {
        display: inline-block;
        vertical-align: middle;
        position: absolute;
        right: 20px;
        top: 50%;
        transform: translateY(-50%);
    }
}

/* Safari Flexbox Fixes */
@media not all and (min-resolution:.001dpcm) { 
    @supports (-webkit-appearance:none) {
        .safari-flexbox-fix {
            display: inline-block;
        }
    }
}

/* Firefox Specific Fixes */
@-moz-document url-prefix() {
    .firefox-fix {
        display: inline-block;
    }
}

/* Edge Specific Fixes */
@supports (-ms-ime-align:auto) {
    .edge-fix {
        display: inline-block;
    }
}

/* Performance Optimizations */
.hardware-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Reduce Animation for Users Who Prefer Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Print Optimizations */
@media print {
    .no-print {
        display: none !important;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
    }
    
    abbr[title]:after {
        content: " (" attr(title) ")";
    }
    
    .ir a:after,
    a[href^="javascript:"]:after,
    a[href^="#"]:after {
        content: "";
    }
    
    pre, blockquote {
        border: 1px solid #999;
        page-break-inside: avoid;
    }
    
    thead {
        display: table-header-group;
    }
    
    tr, img {
        page-break-inside: avoid;
    }
    
    img {
        max-width: 100% !important;
    }
    
    @page {
        margin: 0.5cm;
    }
    
    p, h2, h3 {
        orphans: 3;
        widows: 3;
    }
    
    h2, h3 {
        page-break-after: avoid;
    }
}

/* Accessibility Enhancements */
.visually-hidden {
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap;
}

/* Focus Styles for Keyboard Navigation */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Skip to Content Link */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-primary);
    color: white;
    padding: 8px;
    z-index: 100;
    transition: top 0.3s ease;
}

.skip-to-content:focus {
    top: 0;
}

/* High Contrast Mode Support */
@media (forced-colors: active) {
    .btn {
        border: 1px solid;
    }
    
    .btn-primary {
        border: 2px solid;
    }
}

/* Loading Performance Optimizations */
.content-visibility-auto {
    content-visibility: auto;
    contain-intrinsic-size: 1px 1000px;
}

/* Fallbacks for CSS Variables */
.header {
    background-color: #0a3d62; /* Fallback for var(--color-primary-dark) */
}

.btn-primary {
    background-color: #0a3d62; /* Fallback for var(--color-primary) */
    color: #ffffff; /* Fallback for white */
}

/* Optimized Box Shadows */
.optimized-shadow {
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* Optimized Transitions */
.optimized-transition {
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Optimized Animations */
@keyframes optimized-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Prevent FOIT (Flash of Invisible Text) */
.font-display {
    font-display: swap;
}

/* Prevent Layout Shifts */
.aspect-ratio-box {
    position: relative;
    height: 0;
    padding-top: 56.25%; /* 16:9 Aspect Ratio */
    overflow: hidden;
}

.aspect-ratio-box img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Prevent Text Overflow */
.text-ellipsis {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Prevent Image Overflow */
img {
    max-width: 100%;
    height: auto;
}

/* Prevent Form Element Overflow */
input, select, textarea {
    max-width: 100%;
}

/* Prevent Table Overflow */
table {
    table-layout: fixed;
    width: 100%;
}

/* Prevent Code Overflow */
pre, code {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Prevent Long URL Overflow */
a {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Prevent Long Word Overflow */
p, h1, h2, h3, h4, h5, h6 {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Prevent Horizontal Scrolling */
body {
    overflow-x: hidden;
}

/* Prevent Tap Highlight on Mobile */
* {
    -webkit-tap-highlight-color: transparent;
}

/* Prevent Text Selection on Interactive Elements */
button, .btn, .nav-link {
    user-select: none;
}

/* Prevent Zoom on Input Focus on iOS */
@media screen and (max-width: 767px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px;
    }
}

/* Prevent Fixed Position Issues on iOS */
.ios-fixed-fix {
    position: fixed;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Prevent Scroll Chaining */
.prevent-scroll-chaining {
    overscroll-behavior: contain;
}

/* Prevent Rubber Band Effect */
html {
    overscroll-behavior: none;
}

/* Prevent Pull-to-Refresh */
body {
    overscroll-behavior-y: contain;
}

/* Prevent Pinch Zoom */
.prevent-zoom {
    touch-action: pan-x pan-y;
}

/* Prevent Text Size Adjustment */
html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Prevent Font Boosting */
.prevent-font-boost {
    max-height: 1000000px;
}

/* Prevent Selection Color Override */
::selection {
    background-color: var(--color-primary);
    color: white;
}

/* Prevent Scrollbar Jump */
html {
    scrollbar-gutter: stable;
}

/* Prevent Focus Ring on Mouse Click */
:focus:not(:focus-visible) {
    outline: none;
}

/* Prevent Focus Visible on Touch */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Prevent Default Focus Styles */
:focus {
    outline: none;
}

/* Prevent Default Button Styles */
button {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

/* Prevent Default Input Styles */
input {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

/* Prevent Default Select Styles */
select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

/* Prevent Default Checkbox Styles */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 18px;
    height: 18px;
    border: 1px solid var(--color-gray);
    border-radius: 3px;
    position: relative;
    cursor: pointer;
}

input[type="checkbox"]:checked {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 6px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Prevent Default Radio Styles */
input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 18px;
    height: 18px;
    border: 1px solid var(--color-gray);
    border-radius: 50%;
    position: relative;
    cursor: pointer;
}

input[type="radio"]:checked {
    border-color: var(--color-primary);
}

input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--color-primary);
}

/* Prevent Default File Input Styles */
input[type="file"] {
    width: 0.1px;
    height: 0.1px;
    opacity: 0;
    overflow: hidden;
    position: absolute;
    z-index: -1;
}

input[type="file"] + label {
    display: inline-block;
    padding: 10px 20px;
    background-color: var(--color-gray-light);
    color: var(--color-text);
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

input[type="file"] + label:hover {
    background-color: var(--color-gray);
}

input[type="file"] + label i {
    margin-right: 5px;
}

/* Prevent Default Range Input Styles */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 5px;
    border-radius: 5px;
    background-color: var(--color-gray-light);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background-color: var(--color-primary);
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background-color: var(--color-primary);
    cursor: pointer;
    border: none;
}

/* Prevent Default Number Input Styles */
input[type="number"] {
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Prevent Default Search Input Styles */
input[type="search"] {
    -webkit-appearance: none;
}

input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration {
    -webkit-appearance: none;
}

/* Prevent Default Textarea Styles */
textarea {
    resize: vertical;
}

/* Prevent Default Button Focus Styles */
button::-moz-focus-inner {
    border: 0;
}

/* Prevent Default Link Styles */
a {
    text-decoration: none;
    color: var(--color-primary);
}

/* Prevent Default List Styles */
ul, ol {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Prevent Default Table Styles */
table {
    border-collapse: collapse;
    border-spacing: 0;
}

/* Prevent Default Fieldset Styles */
fieldset {
    border: none;
    padding: 0;
    margin: 0;
}

/* Prevent Default Legend Styles */
legend {
    padding: 0;
    margin: 0;
}

/* Prevent Default Address Styles */
address {
    font-style: normal;
}

/* Prevent Default Quote Styles */
blockquote, q {
    quotes: none;
}

blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}

/* Prevent Default Code Styles */
code, kbd, pre, samp {
    font-family: monospace, monospace;
}

/* Prevent Default Small Styles */
small {
    font-size: 80%;
}

/* Prevent Default Sub and Sup Styles */
sub, sup {
    font-size: 75%;
    line-height: 0;
    position: relative;
    vertical-align: baseline;
}

sup {
    top: -0.5em;
}

sub {
    bottom: -0.25em;
}

/* Prevent Default Audio Styles */
audio:not([controls]) {
    display: none;
    height: 0;
}

/* Prevent Default Video Styles */
video {
    max-width: 100%;
    height: auto;
}

/* Prevent Default Canvas Styles */
canvas {
    display: inline-block;
}

/* Prevent Default SVG Styles */
svg:not(:root) {
    overflow: hidden;
}

/* Prevent Default Figure Styles */
figure {
    margin: 0;
}

/* Prevent Default HR Styles */
hr {
    box-sizing: content-box;
    height: 0;
    overflow: visible;
}

/* Prevent Default Template Styles */
template {
    display: none;
}

/* Prevent Default Hidden Styles */
[hidden] {
    display: none;
}
