/* ===== Performance & Accessibility Optimizations ===== */

/* ===== IMAGE OPTIMIZATIONS ===== */
img {
    height: auto;
    max-width: 100%;
    object-fit: cover;
    /* Lazy loading hint for browsers that support it */
    loading: lazy;
    /* Improve image rendering */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: optimize-contrast;
    /* Prevent layout shift */
    aspect-ratio: attr(width) / attr(height);
}

/* Hero images and featured images */
.hero-image,
.featured-image,
.project-image {
    width: 100%;
    height: auto;
    object-fit: cover;
    border-radius: 12px;
    /* Critical images should load immediately */
    loading: eager;
}

/* Responsive images for different screen sizes */
@media (max-width: 768px) {
    .hero-image {
        max-height: 300px;
    }

    .project-image,
    .service-image {
        max-height: 200px;
    }
}

@media (max-width: 480px) {
    .hero-image {
        max-height: 250px;
    }

    .project-image,
    .service-image {
        max-height: 180px;
    }
}

/* ===== FONT OPTIMIZATIONS ===== */
/* Improve font loading performance */
@font-face {
    font-family: 'Inter';
    font-display: swap; /* Show fallback font while loading */
    src: url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');
}

/* Fallback fonts for better loading */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    /* Improve text rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* ===== SCROLLING OPTIMIZATIONS ===== */
html {
    scroll-behavior: smooth;
    /* Better scrolling on iOS */
    -webkit-overflow-scrolling: touch;
}

/* Smooth scroll for all devices */
* {
    scroll-behavior: smooth;
}

/* ===== ANIMATION PERFORMANCE ===== */
/* Use transform instead of changing layout properties for better performance */
.fade-up,
.slide-in,
.scale-in {
    will-change: transform, opacity;
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */
/* Skip to main content link */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--accent-color);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
    z-index: 1001;
    transition: top 0.3s ease;
}

.skip-to-main:focus {
    top: 6px;
}

/* Improved focus indicators */
:focus {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Remove outline for mouse users but keep for keyboard users */
:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

/* Ensure minimum touch target size (44px) */
@media (pointer: coarse) {
    .btn,
    .nav-link,
    .social-link,
    .mobile-menu-btn,
    button,
    a {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */
/* GPU acceleration for smooth animations */
.service-card,
.project-card,
.testimonial-card,
.btn,
.nav-menu {
    transform: translateZ(0);
    will-change: transform;
}

/* Optimize repaints */
.navbar,
.footer {
    contain: layout style paint;
}

/* ===== TOUCH OPTIMIZATIONS ===== */
/* Prevent 300ms click delay on mobile */
a,
button,
.btn,
.nav-link {
    touch-action: manipulation;
}

/* Remove highlight on touch */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Allow text selection for content */
p,
h1, h2, h3, h4, h5, h6,
.text-content,
.form-group input,
.form-group textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* ===== CONTRAST AND COLOR ACCESSIBILITY ===== */
/* Ensure sufficient contrast ratios */
:root {
    --text-contrast-ratio: 4.5; /* WCAG AA standard */
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --text-secondary: #000000;
        --accent-color: #0066cc;
    }

    .btn {
        border: 2px solid currentColor;
    }

    .service-card,
    .project-card,
    .testimonial-card {
        border: 2px solid var(--border-color);
    }
}

/* ===== DARK MODE OPTIMIZATIONS ===== */
/* Reduce white backgrounds in dark mode to prevent eye strain */
[data-theme="dark"] img {
    filter: brightness(0.9);
}

[data-theme="dark"] .hero-image,
[data-theme="dark"] .featured-image {
    filter: brightness(0.8) contrast(1.1);
}

/* ===== RESPONSIVE TYPOGRAPHY ===== */
/* Fluid typography that scales with viewport */
h1 {
    font-size: clamp(1.75rem, 5vw + 1rem, 4rem);
    line-height: 1.1;
}

h2 {
    font-size: clamp(1.5rem, 4vw + 1rem, 3rem);
    line-height: 1.2;
}

h3 {
    font-size: clamp(1.25rem, 3vw + 1rem, 2rem);
    line-height: 1.3;
}

p {
    font-size: clamp(0.875rem, 2vw + 0.5rem, 1.125rem);
    line-height: 1.6;
    max-width: 65ch; /* Optimal reading length */
}

/* ===== FORM OPTIMIZATIONS ===== */
/* Prevent zoom on input focus on iOS */
input,
textarea,
select {
    font-size: 16px !important; /* Prevents zoom on iOS */
}

/* Better form field appearance on mobile */
@media (max-width: 768px) {
    .form-group input,
    .form-group textarea,
    .form-group select {
        padding: 1rem;
        border-radius: 8px;
        border: 2px solid var(--border-color);
        background: var(--bg-primary);
        color: var(--text-primary);
        transition: border-color 0.3s ease, box-shadow 0.3s ease;
        /* Better touch targets */
        min-height: 48px;
    }

    .form-group textarea {
        min-height: 120px;
        resize: vertical;
    }
}

/* ===== LOADING STATES ===== */
/* Loading skeleton for better perceived performance */
.loading-skeleton {
    background: linear-gradient(90deg,
        var(--bg-secondary) 25%,
        var(--bg-tertiary) 50%,
        var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ===== PRINT OPTIMIZATIONS ===== */
@media print {
    /* Hide unnecessary elements */
    .navbar,
    .mobile-menu-btn,
    .theme-toggle,
    .hero-buttons,
    .cta-section,
    .social-links {
        display: none !important;
    }

    /* Optimize for printing */
    * {
        background: transparent !important;
        color: black !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    body {
        font-size: 12pt;
        line-height: 1.4;
    }

    h1, h2, h3 {
        page-break-after: avoid;
    }

    p, blockquote {
        orphans: 3;
        widows: 3;
    }

    .service-card,
    .project-card {
        page-break-inside: avoid;
        border: 1px solid #ccc;
        margin-bottom: 1rem;
        padding: 1rem;
    }
}

/* ===== BROWSER-SPECIFIC OPTIMIZATIONS ===== */
/* Safari specific optimizations */
@supports (-webkit-appearance: none) {
    .navbar {
        -webkit-backdrop-filter: blur(20px);
        backdrop-filter: blur(20px);
    }
}

/* Firefox specific optimizations */
@-moz-document url-prefix() {
    .service-card,
    .project-card {
        image-rendering: -moz-crisp-edges;
    }
}

/* Edge specific optimizations */
@supports (-ms-ime-align: auto) {
    .btn {
        -ms-touch-action: manipulation;
    }
}

/* ===== NETWORK-AWARE OPTIMIZATIONS ===== */
/* Reduce animations on slow connections */
@media (prefers-reduced-data: reduce) {
    .hero-image,
    .project-image {
        display: none;
    }

    .loading-skeleton {
        animation: none;
        background: var(--bg-secondary);
    }

    * {
        transition: none !important;
        animation: none !important;
    }
}