/* Layout Shift Prevention CSS - Addresses PageSpeed CLS Issues */
/* Target elements from PageSpeed Insights screenshots */

/* Fix for FontBootstrap icons - ensures consistent loading */
.fontbootstrap-icons {
    font-display: swap;
    font-family: 'bootstrap-icons';
}

/* Support Our Free Service section - prevent layout shift */
.donation-section {
    min-height: 160px; /* Reserve exact space for donation content */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem 0;
}

.donation-section h3 {
    margin-bottom: 1rem;
    font-size: 1.5rem;
    font-weight: 600;
    text-align: center;
}

.donation-section p {
    margin-bottom: 1.5rem;
    text-align: center;
    max-width: 600px;
}

/* PayPal button container stability */
.paypal-button-container {
    min-height: 50px;
    width: 100%;
    max-width: 200px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Prevent button layout shifts */
.paypal-donation-button {
    width: 100%;
    max-width: 200px;
    height: 44px; /* Fixed height for PayPal button */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background-color: #0d6efd;
    color: white;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: background-color 0.2s ease;
}

.paypal-donation-button:hover {
    background-color: #0056b3;
    color: white;
}

/* Body and main element stability */
body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
    margin: 0;
    padding: 0;
}

body.bg-dark {
    background-color: #212529 !important;
    color: #dee2e6 !important;
}

body.text-light {
    color: #f8f9fa !important;
}

/* Main content stability */
main {
    flex: 1;
    min-height: calc(100vh - 200px); /* Account for navbar and footer */
}

/* Navbar height stability */
.navbar {
    height: 60px; /* Fixed navbar height */
    min-height: 60px;
    padding: 0.5rem 1rem;
}

/* Container stability */
.container, .container-fluid {
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;
    margin-right: auto;
    margin-left: auto;
}

/* Bootstrap row stability */
.row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -15px;
    margin-left: -15px;
}

/* Column stability */
.col, .col-12, .col-md-6, .col-lg-4 {
    position: relative;
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;
    min-height: 1px; /* Prevent collapse */
}

/* Hero section stability */
.hero-section {
    min-height: 400px;
    padding: 3rem 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Upload area stability - critical for CLS */
.upload-area,
.drag-drop-area,
.drop-zone {
    min-height: 320px; /* Fixed height prevents major layout shift */
    border: 3px dashed var(--bs-border-color, #6c757d);
    border-radius: 10px;
    padding: 2rem;
    text-align: center;
    background-color: var(--bs-body-bg, #fff);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    transition: none; /* Remove transitions to prevent CLS */
    z-index: 1; /* Lower than dropdown menus */
}

/* File conversion cards stability */
.conversion-card {
    height: 280px; /* Fixed height prevents layout shift */
    margin-bottom: 1.5rem;
    border-radius: 15px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background-color: var(--bs-dark, #343a40);
    border: 1px solid var(--bs-secondary, #6c757d);
}

.conversion-card-body {
    padding: 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* FAQ section stability */
.faq-section {
    min-height: 400px; /* Reserve space for FAQ cards */
    padding: 3rem 0;
}

.faq-card {
    min-height: 200px; /* Fixed height for FAQ cards */
    margin-bottom: 1.5rem;
    background-color: var(--bs-dark, #343a40);
    border: 1px solid var(--bs-secondary, #6c757d);
    border-radius: 10px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.faq-card h5 {
    margin-bottom: 1rem;
    color: var(--bs-light, #f8f9fa);
}

.faq-card p {
    margin-bottom: 0;
    color: var(--bs-light, #f8f9fa);
    opacity: 0.9;
}

/* Footer stability */
.footer {
    min-height: 120px; /* Reserve footer space */
    margin-top: auto;
    background-color: var(--bs-dark, #343a40);
    color: var(--bs-light, #f8f9fa);
    padding: 2rem 0;
    border-top: 1px solid var(--bs-secondary, #6c757d);
}

/* Button stability */
.btn {
    min-height: 38px; /* Prevent button height changes */
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
    border: 1px solid transparent;
    font-weight: 400;
    line-height: 1.5;
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: none; /* Remove transitions to prevent CLS */
}

/* Image optimization - prevent layout shift */
img {
    max-width: 100%;
    height: auto;
    vertical-align: middle;
}

/* Logo stability */
.navbar-brand img {
    height: 32px; /* Fixed logo height */
    width: auto;
}

/* Dropdown menu stability - Fixed z-index issue */
.dropdown-menu {
    min-width: 200px; /* Prevent width changes */
    max-height: 400px; /* Prevent excessive height */
    overflow-y: auto;
    z-index: 1055 !important; /* Critical: Above upload area */
    position: absolute !important;
    background-color: var(--bs-dark, #343a40) !important;
    border: 1px solid var(--bs-secondary, #6c757d) !important;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4) !important;
}

/* Loading states */
.spinner-border {
    width: 2rem;
    height: 2rem;
    border: 0.25em solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
}

@keyframes spinner-border {
    to { transform: rotate(360deg); }
}

/* Mobile responsiveness without layout shifts */
@media (max-width: 768px) {
    .hero-section {
        min-height: 300px;
        padding: 2rem 0;
    }
    
    .upload-area,
    .drag-drop-area,
    .drop-zone {
        min-height: 280px;
        padding: 1.5rem 1rem;
    }
    
    .conversion-card {
        height: auto;
        min-height: 220px;
    }
    
    .faq-card {
        min-height: 160px;
    }
    
    .donation-section {
        min-height: 140px;
        padding: 1.5rem 0;
    }
    
    .navbar {
        height: auto;
        min-height: 56px;
    }
    
    .container-fluid {
        padding-right: 10px;
        padding-left: 10px;
    }
}

/* Accessibility improvements */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Focus states for keyboard navigation */
.btn:focus,
.form-control:focus {
    outline: 2px solid var(--bs-primary, #0d6efd);
    outline-offset: 2px;
}

/* Optimize fonts for performance */
@font-face {
    font-family: 'bootstrap-icons';
    font-display: swap;
}

@font-face {
    font-family: 'Font Awesome 6 Free';
    font-display: swap;
}

/* Critical above-the-fold content */
.above-fold {
    contain: layout;
}

/* Prevent cumulative layout shift for dynamic content */
.dynamic-content {
    min-height: 50px;
    transition: none;
}

/* Ensure stable grid layout */
.container {
    max-width: 1200px;
}

@media (min-width: 576px) {
    .container {
        max-width: 540px;
    }
}

@media (min-width: 768px) {
    .container {
        max-width: 720px;
    }
    
    .col-md-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

@media (min-width: 992px) {
    .container {
        max-width: 960px;
    }
    
    .col-lg-4 {
        flex: 0 0 33.333333%;
        max-width: 33.333333%;
    }
}

@media (min-width: 1200px) {
    .container {
        max-width: 1140px;
    }
}