/* Critical CSS - Above the fold styles */
html, body {
    font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-display: swap; /* Improves font loading performance */
    overflow-x: hidden; /* Prevent horizontal scroll */
}

/* Mobile-first responsive typography */
h1 {
    font-size: clamp(1.75rem, 4vw, 2rem);
    font-weight: 500;
    line-height: 1.2;
    margin-bottom: 1rem;
}

h2 {
    font-size: clamp(1.375rem, 3.5vw, 1.5rem);
    font-weight: 500;
    line-height: 1.3;
    margin-bottom: 0.75rem;
}

h3 {
    font-size: clamp(1.125rem, 3vw, 1.25rem);
    font-weight: 500;
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

/* Mobile-friendly component styles */
.mobile-card {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
}

.mobile-form .mud-input-control {
    margin-bottom: 8px;
}

.mobile-numeric-field input {
    font-size: 16px !important; /* Prevents zoom on iOS */
}

.mobile-text-field input {
    font-size: 16px !important; /* Prevents zoom on iOS */
}

.mobile-switch {
    transform: scale(1.1);
}

.mobile-switch-container {
    padding: 8px 0;
}

.mobile-switch .mud-switch-label {
    font-size: clamp(0.875rem, 2.5vw, 1rem);
    line-height: 1.4;
    margin-left: 8px;
}

.mobile-tip-chip {
    max-width: 100%;
    height: auto !important;
    min-height: 32px;
    padding: 8px 12px !important;
}

.mobile-tip-chip .mud-chip-content {
    flex-wrap: wrap;
    text-align: center;
    justify-content: center;
}

.mobile-button {
    padding: 8px 16px !important;
    min-height: 44px !important; /* Touch target size */
}

.mobile-icon-button {
    min-width: 44px !important;
    min-height: 44px !important;
}

.mobile-calculate-button {
    min-height: 48px !important;
    font-size: 16px !important;
}

.mobile-pdf-button {
    width: 100%;
    max-width: 200px;
}

.mobile-results {
    overflow-x: hidden;
}

/* Responsive grid improvements */
@media (max-width: 599px) {
    .mobile-pdf-button {
        margin-top: 8px;
    }
    
    .mobile-switch-container {
        justify-content: center !important;
        text-align: center;
        padding: 12px 0;
    }
    
    .mobile-switch {
        transform: scale(1.2);
    }
    
    .mobile-switch .mud-switch-label {
        font-size: 14px;
        line-height: 1.3;
        font-weight: 500;
    }
    
    .mobile-tip-chip {
        width: 100%;
        justify-content: center;
        border-radius: 20px;
        margin: 12px 0 !important;
    }
    
    .mobile-tip-chip .mud-chip-content {
        padding: 8px 16px;
        text-align: center;
        line-height: 1.4;
    }
}

/* Small screens and up */
@media (min-width: 600px) {
    .mobile-switch-container {
        justify-content: flex-start !important;
        padding: 8px 0;
    }
    
    .mobile-switch {
        transform: scale(1.1);
    }
    
    .mobile-switch .mud-switch-label {
        font-size: 16px;
        line-height: 1.5;
    }
    
    .mobile-tip-chip {
        margin: 8px 0 !important;
        width: auto;
        min-width: fit-content;
    }
}

/* Performance optimizations */
.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}

.loading-progress circle {
    fill: none;
    stroke: #1976d2;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: #e0e0e0;
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

/* SEO content styling */
.seo-description {
    max-width: 800px;
    margin: 0 auto;
}

.faq-section article {
    margin-bottom: 1.5rem;
}

.cta-section {
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    color: white;
    border-radius: 8px;
}

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

/* Focus improvements for keyboard navigation */
h1:focus {
    outline: 2px solid #1976d2;
    outline-offset: 2px;
}

a:focus,
button:focus {
    outline: 2px solid #1976d2;
    outline-offset: 2px;
}

/* Existing styles */
a, .btn-link {
    color: #0071c1;
}

.btn-primary {
    color: #fff;
    background-color: #1b6ec2;
    border-color: #1861ac;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

.content {
    padding-top: 1.1rem;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid red;
}

.validation-message {
    color: red;
}

/* Enhanced error UI */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    h1 {
        font-size: 1.75rem;
    }
    
    h2 {
        font-size: 1.375rem;
    }
    
    .seo-description {
        padding: 0 1rem;
    }
    
    /* Improve touch targets on mobile */
    button, .mud-button {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Better spacing for mobile */
    .mud-container {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
    
    /* Responsive form elements */
    .mud-input, .mud-select {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    /* Better card spacing on mobile */
    .mud-card {
        margin-bottom: 16px;
    }
}

@media (max-width: 599px) {
    /* Extra small screens */
    .mud-grid-item {
        padding: 8px !important;
    }
    
    .mud-card-content {
        padding: 12px !important;
    }
    
    .mud-button-filled {
        width: 100%;
        margin-bottom: 8px;
    }
}

/* Tablet optimizations */
@media (min-width: 769px) and (max-width: 1024px) {
    .mud-container {
        padding-left: 24px !important;
        padding-right: 24px !important;
    }
}

/* Image optimizations - removed loading property as it's not CSS */
img {
    height: auto;
    max-width: 100%;
}

/* Core Web Vitals optimizations */
* {
    box-sizing: border-box;
}

body {
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin: 0;
    padding: 0;
}

/* Responsive utilities */
.text-responsive {
    font-size: clamp(0.875rem, 2.5vw, 1rem);
}

.heading-responsive {
    font-size: clamp(1.125rem, 4vw, 1.5rem);
}

/* Improved focus for better accessibility */
.mud-button:focus-visible,
.mud-input:focus-visible,
.mud-select:focus-visible {
    outline: 2px solid #1976d2;
    outline-offset: 2px;
}

/* Better touch targets */
@media (pointer: coarse) {
    .mud-button,
    .mud-icon-button,
    .mud-chip {
        min-height: 44px;
        min-width: 44px;
    }
    
    .mud-switch {
        transform: scale(1.2);
        margin: 8px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    .mobile-tip-chip {
        min-height: 44px;
        padding: 12px 16px !important;
    }
}

/* Improved switch interaction */
.mobile-switch .mud-switch-track {
    border-radius: 12px;
}

.mobile-switch:hover .mud-switch-track,
.mobile-switch:focus-within .mud-switch-track {
    box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.3);
}

.mobile-switch .mud-switch-label {
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .mud-card {
        border: 2px solid #000 !important;
    }
    
    .mud-button-filled {
        border: 2px solid #000 !important;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .mobile-switch {
        transform: none !important;
    }
}

/* Landscape mobile optimization */
@media (max-width: 767px) and (orientation: landscape) {
    .mobile-switch-container {
        padding: 6px 0;
    }
    
    .mobile-tip-chip {
        margin: 6px 0 !important;
        font-size: 12px;
    }
}

/* High DPI display optimization */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .mobile-switch .mud-switch-track,
    .mobile-tip-chip {
        border: 0.5px solid rgba(0,0,0,0.1);
    }
}

/* Print styles */
@media print {
    .mud-button,
    .no-print {
        display: none !important;
    }
    
    .mud-card {
        border: 1px solid #000 !important;
        box-shadow: none !important;
    }
}