/**
 * ERP Brenta - Responsive & Cross-Browser CSS
 * Ottimizzazioni per compatibilità e responsive design
 * Version: 1.0
 */

/* ========================================
   RESET & BASE STYLES
   ======================================== */

/* Box-sizing border-box per tutti gli elementi */
*, *::before, *::after {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Previeni overflow orizzontale */
body {
    overflow-x: hidden;
    position: relative;
}

/* ========================================
   TYPOGRAPHY RESPONSIVE
   ======================================== */

/* Font sizes responsive */
@media (max-width: 1400px) {
    .text-5xl, .text-6xl {
        font-size: clamp(2rem, 5vw, 3.5rem) !important;
    }
}

@media (max-width: 1024px) {
    .text-4xl {
        font-size: clamp(1.75rem, 4vw, 2.25rem) !important;
    }
    .text-3xl {
        font-size: clamp(1.5rem, 3.5vw, 1.875rem) !important;
    }
}

@media (max-width: 768px) {
    .text-xl, .text-2xl {
        font-size: clamp(1rem, 2.5vw, 1.25rem) !important;
    }

    h1, h2, h3, h4 {
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }
}

/* ========================================
   CONTAINER & SPACING RESPONSIVE
   ======================================== */

/* Container responsive */
@media (max-width: 640px) {
    .container {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
}

/* Padding responsive */
@media (max-width: 768px) {
    .py-20, .py-24 {
        padding-top: 3rem !important;
        padding-bottom: 3rem !important;
    }

    .px-6, .px-8, .px-10 {
        padding-left: 1.5rem !important;
        padding-right: 1.5rem !important;
    }
}

@media (max-width: 480px) {
    .py-20, .py-24 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }

    .p-6, .p-8 {
        padding: 1rem !important;
    }
}

/* ========================================
   GRID & FLEXBOX RESPONSIVE
   ======================================== */

/* Grid responsive improvements */
@media (max-width: 1024px) {
    .grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .lg\:grid-cols-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 768px) {
    .md\:grid-cols-2, .md\:grid-cols-3, .md\:grid-cols-4, .md\:grid-cols-5 {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }

    .gap-8 {
        gap: 1rem !important;
    }
}

@media (max-width: 640px) {
    .grid-cols-2 {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }
}

/* Flexbox responsive */
@media (max-width: 640px) {
    .sm\:flex-row {
        flex-direction: column !important;
    }

    .flex {
        flex-wrap: wrap;
    }
}

/* ========================================
   BUTTONS & CTA RESPONSIVE
   ======================================== */

/* Buttons responsive */
@media (max-width: 640px) {
    .px-8, .px-10 {
        padding-left: 1.5rem !important;
        padding-right: 1.5rem !important;
    }

    .py-4, .py-5 {
        padding-top: 0.875rem !important;
        padding-bottom: 0.875rem !important;
    }

    .text-lg {
        font-size: 1rem !important;
    }
}

/* Touch target size - min 44x44px per accessibilità mobile */
@media (hover: none) and (pointer: coarse) {
    a, button, summary, input[type="submit"], input[type="button"] {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ========================================
   IMAGES & MEDIA RESPONSIVE
   ======================================== */

/* Images responsive */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Lazy loading support */
img[loading="lazy"] {
    display: block;
}

/* Picture element support */
picture {
    display: block;
    width: 100%;
}

/* ========================================
   HERO SECTION RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    .hero-section {
        min-height: auto !important;
    }

    section.py-24 {
        padding-top: 2.5rem !important;
        padding-bottom: 2.5rem !important;
    }
}

/* ========================================
   CARDS & SHADOWS RESPONSIVE
   ======================================== */

/* Cards responsive */
@media (max-width: 768px) {
    .rounded-2xl {
        border-radius: 1rem !important;
    }

    .rounded-xl {
        border-radius: 0.75rem !important;
    }

    .shadow-2xl {
        -webkit-box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        -moz-box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    }
}

/* ========================================
   GRADIENTS - CROSS BROWSER
   ======================================== */

/* Gradient compatibility */
.bg-gradient-to-br {
    background-image: -webkit-linear-gradient(top left, var(--tw-gradient-stops));
    background-image: -moz-linear-gradient(top left, var(--tw-gradient-stops));
    background-image: -o-linear-gradient(top left, var(--tw-gradient-stops));
    background-image: linear-gradient(to bottom right, var(--tw-gradient-stops));
}

.bg-gradient-to-r {
    background-image: -webkit-linear-gradient(left, var(--tw-gradient-stops));
    background-image: -moz-linear-gradient(left, var(--tw-gradient-stops));
    background-image: -o-linear-gradient(left, var(--tw-gradient-stops));
    background-image: linear-gradient(to right, var(--tw-gradient-stops));
}

/* ========================================
   TRANSITIONS - CROSS BROWSER
   ======================================== */

/* Transitions */
.transition-all, .transition-colors, .transition-transform {
    -webkit-transition-property: all;
    -moz-transition-property: all;
    -o-transition-property: all;
    transition-property: all;

    -webkit-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    -moz-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    -o-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);

    -webkit-transition-duration: 300ms;
    -moz-transition-duration: 300ms;
    -o-transition-duration: 300ms;
    transition-duration: 300ms;
}

/* Transform */
.transform {
    -webkit-transform: translateZ(0);
    -moz-transform: translateZ(0);
    -ms-transform: translateZ(0);
    -o-transform: translateZ(0);
    transform: translateZ(0);
}

.hover\:scale-105:hover {
    -webkit-transform: scale(1.05);
    -moz-transform: scale(1.05);
    -ms-transform: scale(1.05);
    -o-transform: scale(1.05);
    transform: scale(1.05);
}

/* ========================================
   BACKDROP BLUR - CROSS BROWSER
   ======================================== */

.backdrop-blur-sm {
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

/* Fallback per browser senza supporto backdrop-filter */
@supports not (backdrop-filter: blur(4px)) {
    .backdrop-blur-sm {
        background-color: rgba(255, 255, 255, 0.8) !important;
    }
}

/* ========================================
   FLEXBOX - IE11 FIXES
   ======================================== */

/* IE11 flex fixes */
.flex {
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
}

.inline-flex {
    display: -webkit-inline-box;
    display: -webkit-inline-flex;
    display: -moz-inline-box;
    display: -ms-inline-flexbox;
    display: inline-flex;
}

.items-center {
    -webkit-box-align: center;
    -webkit-align-items: center;
    -moz-box-align: center;
    -ms-flex-align: center;
    align-items: center;
}

.justify-center {
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -moz-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
}

.justify-between {
    -webkit-box-pack: justify;
    -webkit-justify-content: space-between;
    -moz-box-pack: justify;
    -ms-flex-pack: justify;
    justify-content: space-between;
}

/* ========================================
   GRID - IE11 FALLBACK
   ======================================== */

/* Grid fallback per IE11 */
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
    .grid {
        display: -ms-grid;
        display: grid;
    }

    .grid > * {
        -ms-grid-column: 1;
        -ms-grid-row: auto;
    }
}

/* ========================================
   DETAILS/SUMMARY - CROSS BROWSER
   ======================================== */

/* Details/Summary styling cross-browser */
details summary {
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

details summary::-webkit-details-marker {
    display: none;
}

details summary::marker {
    display: none;
}

/* ========================================
   SCROLLBAR STYLING
   ======================================== */

/* Custom scrollbar per WebKit browsers */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: #888 #f1f1f1;
}

/* ========================================
   ACCESSIBILITY IMPROVEMENTS
   ======================================== */

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

/* Skip to main content */
.skip-to-main {
    position: absolute;
    left: -9999px;
    z-index: 999;
    padding: 1em;
    background-color: #008755;
    color: white;
    text-decoration: none;
}

.skip-to-main:focus {
    left: 50%;
    transform: translateX(-50%);
    top: 1em;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        -webkit-animation-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        -webkit-animation-iteration-count: 1 !important;
        animation-iteration-count: 1 !important;
        -webkit-transition-duration: 0.01ms !important;
        -moz-transition-duration: 0.01ms !important;
        -o-transition-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    /* Nascondi elementi non necessari in stampa */
    nav, .no-print, button, .bg-gradient-to-br {
        display: none !important;
    }

    /* Ottimizza per stampa */
    body {
        font-size: 12pt;
        color: #000;
        background: #fff;
    }

    a[href]::after {
        content: " (" attr(href) ")";
    }

    /* Evita page break in elementi importanti */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }

    img, table, figure {
        page-break-inside: avoid;
    }
}

/* ========================================
   LANDSCAPE ORIENTATION MOBILE
   ======================================== */

@media (max-height: 500px) and (orientation: landscape) {
    .py-20, .py-24 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }

    .text-5xl, .text-6xl {
        font-size: 2rem !important;
    }
}

/* ========================================
   HIGH DPI / RETINA DISPLAYS
   ======================================== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Ottimizzazioni per display retina */
    img {
        -webkit-font-smoothing: antialiased;
    }
}

/* ========================================
   DARK MODE SUPPORT (PREP)
   ======================================== */

@media (prefers-color-scheme: dark) {
    /* Preparazione per dark mode - da implementare */
    /* body {
        background-color: #1a1a1a;
        color: #ffffff;
    } */
}

/* ========================================
   UTILITY CLASSES CROSS-BROWSER
   ======================================== */

/* Opacity cross-browser */
.opacity-10 {
    opacity: 0.1;
    filter: alpha(opacity=10); /* IE8 */
}

.opacity-90 {
    opacity: 0.9;
    filter: alpha(opacity=90); /* IE8 */
}

/* Border radius cross-browser */
.rounded-full {
    -webkit-border-radius: 9999px;
    -moz-border-radius: 9999px;
    border-radius: 9999px;
}

.rounded-lg {
    -webkit-border-radius: 0.5rem;
    -moz-border-radius: 0.5rem;
    border-radius: 0.5rem;
}

.rounded-xl {
    -webkit-border-radius: 0.75rem;
    -moz-border-radius: 0.75rem;
    border-radius: 0.75rem;
}

.rounded-2xl {
    -webkit-border-radius: 1rem;
    -moz-border-radius: 1rem;
    border-radius: 1rem;
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
   ======================================== */

/* Hardware acceleration */
.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

/* Contenimento repaint */
.contain-paint {
    contain: paint;
}

/* ========================================
   SAFE AREA INSETS (iOS notch)
   ======================================== */

@supports (padding: max(0px)) {
    .container {
        padding-left: max(1.5rem, env(safe-area-inset-left));
        padding-right: max(1.5rem, env(safe-area-inset-right));
    }
}

/* ========================================
   BROWSER-SPECIFIC FIXES
   ======================================== */

/* Safari-specific fixes */
@media not all and (min-resolution:.001dpcm) {
    @supports (-webkit-appearance:none) {
        .backdrop-blur-sm {
            -webkit-backdrop-filter: blur(4px);
        }
    }
}

/* Edge-specific fixes */
@supports (-ms-ime-align:auto) {
    .grid {
        display: -ms-grid;
    }
}

/* Firefox-specific fixes */
@-moz-document url-prefix() {
    .transform {
        -moz-transform: translateZ(0);
    }
}
