/**
 * Main CSS - Additional Styles and Optimizations for Proem Abogados
 * Performance-focused styles for PageSpeed 90+ score
 */

/* Critical CSS - Above the fold styles */
.critical-css {
    content-visibility: auto;
}

/* Font Loading Optimization */
.fonts-loaded body {
    font-family: 'Open Sans', sans-serif;
}

.fonts-loaded h1,
.fonts-loaded h2,
.fonts-loaded h3,
.fonts-loaded h4,
.fonts-loaded h5,
.fonts-loaded h6 {
    font-family: 'Playfair Display', serif;
}

/* Performance Optimizations */
img {
    content-visibility: auto;
    contain-intrinsic-size: 300px;
}

/* Optimize Repaints and Reflows */
.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

/* Layout Shift Prevention */
img,
video,
iframe {
    aspect-ratio: attr(width) / attr(height);
    max-width: 100%;
    height: auto;
}

/* Skeleton Loading States */
.skeleton-text {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
    display: inline-block;
    width: 100%;
    height: 1em;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Accessibility Improvements */
.screen-reader-text {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    word-wrap: normal;
}

.screen-reader-text:focus {
    background-color: #f1f1f1;
    border-radius: 3px;
    box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.6);
    clip: auto;
    clip-path: none;
    color: #541D36;
    display: block;
    font-size: 14px;
    font-weight: bold;
    height: auto;
    left: 5px;
    line-height: normal;
    padding: 15px 23px 14px;
    text-decoration: none;
    top: 5px;
    width: auto;
    z-index: 100000;
}

/* Focus Visible for Keyboard Navigation */
*:focus-visible {
    outline: 2px solid #541D36; /* var(--color-primary) */
    outline-offset: 2px;
}

/* Skip Links */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #541D36; /* var(--color-primary) */
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --color-primary: #541D36;
        --color-text: #000000;
        --color-background: #FFFFFF;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
}

/* Touch Target Optimization */
button,
a,
input,
select,
textarea {
    min-height: 44px;
    min-width: 44px;
}

/* Smooth Scrolling with Reduced Motion Support */
@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

/* Container Queries Support (future-proofing) */
@container (min-width: 400px) {
    .service-card {
        padding: 2rem;
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #541D36; /* var(--color-primary) */
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #3A1325; /* var(--color-primary-dark) */
}

/* Print Optimization */
@media print {
    @page {
        margin: 2cm;
    }
    
    body {
        font-size: 12pt;
    }
    
    h1 {
        font-size: 24pt;
    }
    
    h2 {
        font-size: 18pt;
    }
    
    h3 {
        font-size: 14pt;
    }
    
    a[href^="http"]:after {
        content: " (" attr(href) ")";
    }
}

/* Loading States */
.is-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid #541D36; /* var(--color-primary) */
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Utility Classes */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }

/* Responsive Images */
.responsive-img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Lazy Load Placeholder */
img[loading="lazy"] {
    background: #f0f0f0;
}

/* Form Validation States */
.form-group.has-error input,
.form-group.has-error textarea {
    border-color: #dc3545;
}

.form-group.has-success input,
.form-group.has-success textarea {
    border-color: #28a745;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #333333; /* var(--color-text) */
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 2px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    transform: translateX(400px);
    transition: transform 0.3s ease;
    z-index: 1000;
}

.toast.show {
    transform: translateX(0);
}

/* Optimized Grid System */
.grid {
    display: grid;
    gap: var(--grid-gap, 1rem);
}

.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 768px) {
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: 1fr;
    }
}

/* Content Security */
.user-content img {
    max-width: 100%;
    height: auto;
}

.user-content * {
    max-width: 100%;
    word-wrap: break-word;
}

/* Final Performance Boost */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Reduce Motion for Performance */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}