/* ==============================================
   CORE WEB VITALS OPTIMIZATIONS
   Performance CSS for Arrow One Tools
   ============================================== */

/* ---------------------------------------------
   1. CLS (Cumulative Layout Shift) Prevention
   --------------------------------------------- */

/* Reserve space for images to prevent layout shifts */
img {
    max-width: 100%;
    height: auto;
}

/* Lazy loading support */
img[loading="lazy"] {
    opacity: 1;
    transition: opacity 0.3s ease;
}

img.loading {
    opacity: 0;
}

/* Reserve space for common icon sizes */
.tool-icon {
    min-width: 48px;
    min-height: 48px;
}

.nav-icon {
    min-width: 20px;
    display: inline-block;
}

/* Prevent font flash (FOIT/FOUT) */
.fonts-loading body {
    visibility: hidden;
}

.fonts-loaded body {
    visibility: visible;
}

/* Fallback fonts while loading */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

.fonts-loaded body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---------------------------------------------
   2. LCP (Largest Contentful Paint) Optimization
   --------------------------------------------- */

/* Optimize gradient rendering */
.background-gradient {
    will-change: auto;
    contain: paint;
}

/* Critical above-the-fold content priority */
.hero-section {
    contain: layout style;
}

.gradient-text {
    contain: layout style paint;
}

/* ---------------------------------------------
   3. FID (First Input Delay) Optimization
   --------------------------------------------- */

/* Ensure interactive elements respond immediately */
button,
a,
input,
textarea,
select {
    touch-action: manipulation;
}

/* Optimize touch targets for mobile (48x48 minimum) */
.btn-primary,
.btn-secondary,
.browse-btn,
.convert-btn,
.download-btn,
.nav-item {
    min-height: 48px;
    min-width: 48px;
}

/* Reduce paint complexity */
.converter-card,
.feature-card,
.tool-card,
.testimonial-card {
    contain: layout style paint;
    will-change: transform;
}

/* ---------------------------------------------
   4. Mobile-First Responsive Improvements
   --------------------------------------------- */

/* Base mobile styles */
html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
}

/* Improved mobile typography */
@media (max-width: 768px) {
    .gradient-text {
        font-size: clamp(1.75rem, 6vw, 2.5rem);
        word-break: break-word;
        hyphens: auto;
    }

    .subtitle {
        font-size: 1rem;
        line-height: 1.6;
    }

    /* Better touch spacing on mobile */
    .nav-item {
        padding: 12px 16px;
    }

    .footer-links {
        gap: 1rem;
    }

    .footer-links a {
        padding: 8px;
    }
}

/* Extra small devices */
@media (max-width: 375px) {
    html {
        font-size: 14px;
    }

    .container {
        padding: 0.75rem;
    }

    .converter-card {
        padding: 1rem;
    }

    .upload-zone {
        padding: 2rem 1rem;
    }

    .trust-banner {
        flex-direction: column;
        gap: 1rem;
    }
}

/* Tablet optimizations */
@media (min-width: 769px) and (max-width: 1024px) {
    .tools-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .testimonials-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ---------------------------------------------
   5. Accessibility Improvements
   --------------------------------------------- */

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

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

/* Skip link for screen readers */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #667eea;
    color: white;
    padding: 8px 16px;
    z-index: 10000;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
}

/* Reduced motion preference */
@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;
    }

    .upload-icon {
        animation: none;
    }

    .feature-icon {
        animation: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {

    .tool-card,
    .feature-card,
    .testimonial-card {
        border-width: 2px;
    }

    .btn-primary,
    .btn-secondary {
        border: 2px solid currentColor;
    }
}

/* Dark mode is default, but add explicit support */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }
}

/* ---------------------------------------------
   6. Print Styles
   --------------------------------------------- */
@media print {

    .sidebar-nav,
    .mobile-top-bar,
    .background-gradient,
    .trust-banner,
    .testimonials-section {
        display: none !important;
    }

    .container {
        max-width: 100%;
        padding: 0;
    }

    .converter-card {
        box-shadow: none;
        border: 1px solid #ccc;
    }

    body {
        background: white;
        color: black;
    }
}

/* ---------------------------------------------
   7. Performance Optimizations
   --------------------------------------------- */

/* GPU acceleration for smooth animations */
.tool-card:hover,
.feature-card:hover,
.testimonial-card:hover {
    transform: translateY(-4px) translateZ(0);
}

/* Optimize scrolling performance */
.sidebar-menu {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Lazy background images */
[data-bg] {
    background-image: none !important;
}

[data-bg].bg-loaded {
    background-image: attr(data-bg url) !important;
}