/* 
 * PWA Native App Experience
 * Si attiva SOLO quando l'app è installata (standalone mode)
 * Non influisce sulla versione browser
 */

/* ========================================
   RILEVAMENTO STANDALONE MODE
   ======================================== */

/* Media query per rilevare quando l'app è installata */
@media (display-mode: standalone) {
    body {
        --is-pwa: 1;
    }
}

/* Classe aggiunta via JS quando è standalone */
body.pwa-standalone {
    /* Padding per safe area (notch, navigation bar) */
    padding-top: env(safe-area-inset-top);
    padding-bottom: calc(env(safe-area-inset-bottom) + 70px); /* 70px = bottom nav */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* ========================================
   BOTTOM NAVIGATION BAR (Stile Android)
   ======================================== */

@media (display-mode: standalone) {
    /* Nascondi menu desktop originale con più specificità */
    .navbar,
    header.navbar,
    nav.navbar,
    .top-nav,
    header nav,
    .desktop-nav {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        overflow: hidden !important;
    }

    /* Evita conflitti con sidebar mobile */
    .mobile-menu,
    .mobile-sidebar {
        display: none !important;
    }

    /* Container bottom nav */
    body::after {
        content: '';
        display: block;
        height: 70px;
        width: 100%;
    }

    /* Bottom Navigation Bar */
    .pwa-bottom-nav {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        min-height: 60px !important;
        max-height: 80px !important;
        height: auto !important;
        background: linear-gradient(180deg, rgba(21, 21, 30, 0.98) 0%, rgba(21, 21, 30, 1) 100%);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        padding: 8px 0 !important;
        padding-bottom: calc(8px + env(safe-area-inset-bottom)) !important;
        z-index: 99999 !important;
        box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.5);
        justify-content: space-around;
        align-items: center;
        transform: translate3d(0, 0, 0) !important;
        will-change: transform;
        -webkit-transform: translate3d(0, 0, 0) !important;
        pointer-events: auto !important;
        visibility: visible !important;
        opacity: 1 !important;
        overflow: visible !important;
    }

    .pwa-bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        color: #888;
        font-size: 0.7rem;
        font-weight: 500;
        padding: 8px 12px;
        border-radius: 12px;
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
        min-width: 60px;
        position: relative;
    }

    .pwa-bottom-nav-item i {
        font-size: 1.4rem;
        margin-bottom: 4px;
        transition: all 0.2s;
    }

    /* Stato attivo */
    .pwa-bottom-nav-item.active {
        color: #e10600;
    }

    .pwa-bottom-nav-item.active i {
        transform: scale(1.1);
    }

    /* Indicatore attivo */
    .pwa-bottom-nav-item.active::before {
        content: '';
        position: absolute;
        top: -2px;
        left: 50%;
        transform: translateX(-50%);
        width: 30px;
        height: 3px;
        background: #e10600;
        border-radius: 0 0 3px 3px;
    }

    /* Tap feedback */
    .pwa-bottom-nav-item:active {
        transform: scale(0.95);
        background: rgba(225, 6, 0, 0.1);
    }

    /* Badge notifiche */
    .pwa-bottom-nav-item .badge {
        position: absolute;
        top: 4px;
        right: 8px;
        background: #e10600;
        color: white;
        font-size: 0.65rem;
        padding: 2px 5px;
        border-radius: 10px;
        min-width: 18px;
        text-align: center;
        font-weight: 700;
    }
}

/* ========================================
   HEADER MOBILE APP-STYLE
   ======================================== */

@media (display-mode: standalone) {
    /* Header app-style fisso in alto */
    .pwa-header {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        padding-top: env(safe-area-inset-top);
        background: linear-gradient(180deg, rgba(21, 21, 30, 0.98) 0%, rgba(21, 21, 30, 0.95) 100%);
        backdrop-filter: blur(20px);
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        z-index: 9998;
        align-items: center;
        justify-content: space-between;
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    }

    .pwa-header-title {
        font-size: 1.1rem;
        font-weight: 700;
        color: white;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .pwa-header-title i {
        color: #e10600;
        font-size: 1.3rem;
    }

    .pwa-header-actions {
        display: flex;
        gap: 8px;
    }

    .pwa-header-btn {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.05);
        border: none;
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.2rem;
        cursor: pointer;
        transition: all 0.2s;
    }

    .pwa-header-btn:active {
        background: rgba(225, 6, 0, 0.2);
        transform: scale(0.9);
    }

    /* Aggiungi padding al contenuto per header con spazio ottimale */
    .container,
    main,
    .main-content,
    .content-wrapper,
    .page-content {
        margin-top: calc(56px + env(safe-area-inset-top)) !important;
        padding-top: 20px !important;
        padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
        min-height: calc(100vh - 136px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* Rimuovi margin negativo che potrebbe essere stato aggiunto */
    body > .container:first-of-type,
    body > main:first-of-type {
        margin-top: calc(56px + env(safe-area-inset-top)) !important;
    }
    
    /* Forza max-width per contenuti */
    .container {
        max-width: 100% !important;
        width: 100% !important;
        padding-left: 15px !important;
        padding-right: 15px !important;
    }
}

/* ========================================
   BOTTONI TOUCH-FRIENDLY
   ======================================== */

@media (display-mode: standalone) {
    /* SOLO bottoni con classe specifica diventano touch-friendly */
    /* NON modificare tutti i bottoni - troppo invasivo */
    
    button.pwa-touch,
    .btn.pwa-touch,
    a.btn.pwa-touch {
        min-height: 48px !important;
        padding: 12px 24px !important;
        border-radius: 12px !important;
        font-size: 1rem !important;
        font-weight: 600 !important;
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
        cursor: pointer;
    }

    /* Feedback tattile solo su bottoni specifici */
    button.pwa-touch:active,
    .btn.pwa-touch:active {
        transform: scale(0.97) !important;
    }

    /* Submit buttons mantengono stile minimo */
    button[type="submit"]:not(.no-pwa-style),
    input[type="submit"]:not(.no-pwa-style) {
        min-height: 44px;
        padding: 10px 20px;
    }

    /* Link NON diventano bottoni automaticamente */
}

/* ========================================
   CARD E CONTENUTI
   ======================================== */

@media (display-mode: standalone) {
    /* Griglia eventi - forza layout a colonna singola */
    .events-grid,
    #eventsGrid {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        width: 100% !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        box-sizing: border-box !important;
    }
    
    /* Card più compatte e moderne */
    .card:not(.no-pwa-style),
    .item-card:not(.no-pwa-style),
    .content-card:not(.no-pwa-style),
    .event-card {
        border-radius: 16px !important;
        padding: 16px !important;
        margin-bottom: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        margin-top: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        position: relative !important;
        left: 0 !important;
        right: 0 !important;
    }
    
    /* Tap feedback solo su card cliccabili */
    .card.clickable:active,
    .card[onclick]:active,
    a .card:active,
    .event-card:active {
        transform: scale(0.98);
    }
}

/* ========================================
   HOME PAGE - FIX OVERFLOW DELICATO
   ======================================== */

@media (display-mode: standalone) {
    /* Grid responsive - mantieni layout originale ma previeni overflow */
    .stats-grid,
    .leghe-grid,
    .cta-grid {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)) !important;
        gap: 12px !important;
    }
    
    /* Previeni overflow del testo nelle card */
    .stat-card,
    .lega-card,
    .cta-card {
        overflow: hidden !important;
        box-sizing: border-box !important;
    }
    
    /* Text truncation solo se necessario */
    .stat-label,
    .stat-trend,
    .lega-name,
    .evento-name {
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    /* Hero section - padding ridotto */
    .hero-dynamic {
        padding: 1.5rem !important;
    }
    
    .hero-title {
        font-size: 2rem !important;
    }
    
    .hero-subtitle {
        font-size: 1.05rem !important;
    }
    
    /* Section titles - fix overflow */
    .section-header {
        padding: 0 !important;
        margin-bottom: 1rem !important;
    }
    
    .section-title {
        font-size: 1.4rem !important;
        font-weight: 700 !important;
        white-space: nowrap !important;
        overflow: visible !important;
        text-overflow: clip !important;
        display: flex !important;
        align-items: center !important;
        gap: 0.5rem !important;
        width: auto !important;
        max-width: 70% !important;
    }
    
    .section-title i {
        font-size: 1.2rem !important;
        flex-shrink: 0 !important;
    }
    
    .section-link {
        font-size: 0.85rem !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
    }
    
    /* Content grid - fix overflow delle card grandi */
    .content-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 1.5rem !important;
        margin-bottom: 2rem !important;
    }
    
    .top-piloti-card,
    .eventi-card,
    .news-card {
        width: 100% !important;
        max-width: 100% !important;
        padding: 1.2rem !important;
        box-sizing: border-box !important;
    }
    
    /* News feed carousel - scroll snap */
    .news-grid {
        padding: 0 !important;
        overflow: visible !important;
    }
    
    .news-carousel {
        display: flex !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        scroll-snap-type: x mandatory !important;
        scroll-behavior: smooth !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 1rem !important;
        padding: 0 1rem !important;
        width: 100% !important;
        scrollbar-width: none !important;
    }
    
    .news-carousel::-webkit-scrollbar {
        display: none !important;
    }
    
    .news-carousel .news-card {
        flex: 0 0 85% !important;
        width: 85% !important;
        max-width: 85% !important;
        scroll-snap-align: center !important;
        scroll-snap-stop: always !important;
    }
    
    /* Nascondi frecce carousel su mobile */
    .carousel-btn {
        display: none !important;
    }
    
    /* Fix header news con live e aggiorna */
    .section-header {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 0.5rem !important;
        flex-wrap: nowrap !important;
    }
    
    .badge-live {
        font-size: 0.6rem !important;
        padding: 0.2rem 0.5rem !important;
        margin-left: 0.3rem !important;
    }
    
    .refresh-btn {
        padding: 0.4rem 0.8rem !important;
        font-size: 0.75rem !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
    }
    
    .refresh-btn i {
        font-size: 0.75rem !important;
    }
}

/* ========================================
   LISTE OTTIMIZZATE
   ======================================== */

@media (display-mode: standalone) {
    .list-group.pwa-list {
        gap: 0 !important;
    }

    .list-group-item.pwa-list-item {
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
        border-top: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
        margin-bottom: 0 !important;
    }
}

/* ========================================
   FORM INPUTS OTTIMIZZATI
   ======================================== */

@media (display-mode: standalone) {
    /* FORM INPUTS - Modifiche minime e opzionali */
    input.pwa-input,
    select.pwa-input,
    textarea.pwa-input {
        min-height: 48px !important;
        padding: 12px 16px !important;
        border-radius: 12px !important;
    }

    /* NON modificare tutti gli input globalmente */
}

/* ========================================
   TABELLE RESPONSIVE MOBILE
   ======================================== */

@media (display-mode: standalone) {
    /* TABELLE - Modifiche minime */
    /* NON modificare tutte le tabelle - troppo invasivo */
    
    table.pwa-table {
        border-radius: 16px !important;
        overflow: hidden;
    }
}

/* ========================================
   SWIPE GESTURES & ANIMAZIONI
   ======================================== */

@media (display-mode: standalone) {
    /* Animazione ingresso pagina */
    @keyframes slideInUp {
        from {
            opacity: 0;
            transform: translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .container,
    main,
    .main-content {
        animation: slideInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Pull to refresh indicator */
    body.pwa-standalone::before {
        content: '';
        position: fixed;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: rgba(225, 6, 0, 0.1);
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0;
        transition: opacity 0.2s;
        pointer-events: none;
        z-index: 10000;
    }

    /* Smooth scroll nativo ottimizzato */
    html {
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
        overflow-y: scroll;
        overflow-x: hidden;
        height: 100%;
    }
    
    /* Body scrolling migliorato */
    body {
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
        overflow-x: hidden;
        touch-action: pan-y;
        overscroll-behavior-y: none !important;
        overscroll-behavior-x: none !important;
        height: 100%;
    }
    
    /* Contenuti scrollabili */
    .container,
    main,
    .main-content {
        -webkit-overflow-scrolling: touch !important;
        overflow-y: auto;
        overflow-x: hidden;
    }
}

/* ========================================
   FLOATING ACTION BUTTON (FAB)
   ======================================== */

@media (display-mode: standalone) {
    .pwa-fab {
        display: flex !important;
        position: fixed;
        bottom: calc(80px + env(safe-area-inset-bottom));
        right: 16px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: linear-gradient(135deg, #e10600 0%, #b00500 100%);
        color: white;
        box-shadow: 0 4px 20px rgba(225, 6, 0, 0.4);
        border: none;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        z-index: 9997;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .pwa-fab:active {
        transform: scale(0.9);
        box-shadow: 0 2px 10px rgba(225, 6, 0, 0.5);
    }

    /* Animazione pulsazione */
    @keyframes fab-pulse {
        0% {
            box-shadow: 0 4px 20px rgba(225, 6, 0, 0.4);
        }
        50% {
            box-shadow: 0 4px 30px rgba(225, 6, 0, 0.6);
        }
        100% {
            box-shadow: 0 4px 20px rgba(225, 6, 0, 0.4);
        }
    }

    .pwa-fab.pulse {
        animation: fab-pulse 2s infinite;
    }
}

/* ========================================
   BADGES & CHIPS
   ======================================== */

@media (display-mode: standalone) {
    /* BADGES - Modifiche minime */
    .badge.pwa-badge,
    .chip.pwa-chip {
        padding: 6px 12px !important;
        border-radius: 20px !important;
        font-size: 0.8rem !important;
        font-weight: 600 !important;
    }
    
    /* NON modificare tutti i badge globalmente */
}

/* ========================================
   MODAL E POPUP - CENTRATI E OTTIMIZZATI
   ======================================== */

@media (display-mode: standalone) {
    /* MODAL/POPUP - Centrato FORZATO */
    .modal,
    .popup,
    .dialog,
    .event-modal,
    div[class*="modal"],
    div[id*="modal"],
    div[id*="Modal"] {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        right: auto !important;
        bottom: auto !important;
        transform: translate(-50%, -50%) !important;
        -webkit-transform: translate(-50%, -50%) !important;
        width: 90vw !important;
        max-width: 550px !important;
        height: auto !important;
        max-height: 85vh !important;
        margin: 0 !important;
        padding: 0 !important;
        border-radius: 20px !important;
        background: rgba(21, 21, 30, 0.98) !important;
        backdrop-filter: blur(30px) !important;
        -webkit-backdrop-filter: blur(30px) !important;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8) !important;
        z-index: 100000 !important;
        overflow: hidden !important;
        display: none !important;
        position: fixed !important;
    }
    
    /* Modal ATTIVO - Mostra quando ha classe active */
    .modal.active,
    .popup.active,
    .dialog.active,
    .event-modal.active,
    div[class*="modal"].active,
    div[id*="modal"].active,
    div[id*="Modal"].active,
    #createEventModal.active,
    #createCampionatoModal.active {
        display: flex !important;
        flex-direction: column !important;
        visibility: visible !important;
        opacity: 1 !important;
        z-index: 200000 !important;
        position: fixed !important;
    }
    
    /* Contenuto modal evento scrollabile */
    #createEventModal.active .modal-content {
        overflow-y: auto !important;
        overflow-x: hidden !important;
        max-height: 80vh !important;
    }
    
    /* Form evento più largo */
    #createEventModal.active {
        max-width: 90vw !important;
        width: 90vw !important;
    }
    
    /* Modal-dialog (Bootstrap) */
    .modal-dialog {
        position: relative !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        transform: none !important;
        -webkit-transform: none !important;
    }
    
    /* Modal content wrapper */
    .modal-content,
    .event-modal-content {
        position: relative !important;
        width: 100% !important;
        margin: 0 !important;
        border: none !important;
        border-radius: 20px !important;
        background: transparent !important;
        display: flex !important;
        flex-direction: column !important;
        max-height: 85vh !important;
        transform: none !important;
    }
    
    /* Modal quando nascosto */
    .modal:not(.show):not([style*="display: block"]):not([style*="display: flex"]) {
        display: none !important;
    }
    
    /* Modal attivo */
    .modal.show,
    .modal.active,
    .modal[style*="display: block"],
    .modal[style*="display: flex"],
    .popup.show,
    .dialog.show {
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* Header modal */
    .modal-header {
        padding: 20px !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
        flex-shrink: 0 !important;
    }
    
    /* Body modal scrollabile */
    .modal-body {
        padding: 20px !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        flex: 1 !important;
        max-height: calc(80vh - 120px) !important;
    }
    
    /* Footer modal */
    .modal-footer {
        padding: 16px 20px !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
        flex-shrink: 0 !important;
    }
    
    /* Backdrop modal */
    .modal-backdrop,
    .backdrop {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        background: rgba(0, 0, 0, 0.7) !important;
        backdrop-filter: blur(5px) !important;
        z-index: 99999 !important;
    }
    
    /* Anteprima tracciato / evento */
    .modal-anteprima,
    [id*="anteprima"],
    [class*="anteprima"] {
        width: 95vw !important;
        max-width: 600px !important;
        max-height: 85vh !important;
    }
    
    /* Immagini dentro modal */
    .modal img,
    .popup img {
        max-width: 100% !important;
        height: auto !important;
        display: block !important;
        margin: 0 auto !important;
        border-radius: 12px !important;
    }
}

/* ========================================
   TABELLE E LISTE OTTIMIZZATE
   ======================================== */

@media (display-mode: standalone) {
    /* Tabelle responsive */
    table,
    .main-standings-table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: 0.9rem !important;
    }
    
    /* Header tabella */
    table thead th {
        padding: 12px 8px !important;
        font-size: 0.85rem !important;
        white-space: nowrap !important;
        position: sticky !important;
        top: 0 !important;
        background: rgba(21, 21, 30, 0.95) !important;
        z-index: 10 !important;
    }
    
    /* Righe tabella */
    table tbody td {
        padding: 12px 8px !important;
        font-size: 0.9rem !important;
        vertical-align: middle !important;
    }
    
    /* Badge team nelle tabelle */
    .badge-team-ranking {
        display: inline-block !important;
        max-width: 100px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }
    
    /* Rank badge */
    .rank-badge {
        display: inline-flex !important;
        align-items: center !important;
        gap: 4px !important;
        padding: 4px 10px !important;
        border-radius: 12px !important;
        font-size: 0.85rem !important;
        font-weight: 600 !important;
        white-space: nowrap !important;
    }
    
    /* Container tabella scrollabile */
    .full-width-table {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        margin: 0 -15px !important;
        padding: 0 15px !important;
    }
    
    /* Stats grid ottimizzato */
    .stats-grid {
        display: grid !important;
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
        gap: 12px !important;
        margin-bottom: 20px !important;
    }
    
    .stat-card {
        padding: 12px !important;
        border-radius: 12px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 4px !important;
        min-height: 90px !important;
    }
    
    .stat-card i {
        font-size: 1.5rem !important;
        margin-bottom: 4px !important;
        opacity: 0.9 !important;
    }
    
    .stat-number {
        font-size: 1.8rem !important;
        font-weight: 700 !important;
        display: block !important;
        line-height: 1 !important;
    }
    
    .stat-label {
        font-size: 0.7rem !important;
        opacity: 0.7 !important;
        display: block !important;
        line-height: 1.2 !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
        max-width: 100% !important;
        overflow: visible !important;
        white-space: normal !important;
        word-wrap: break-word !important;
    }
    
    .stat-trend {
        font-size: 0.65rem !important;
        opacity: 0.6 !important;
        margin-top: 2px !important;
    }
}

@media (display-mode: standalone) {
    .skeleton {
        background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.05) 75%);
        background-size: 200% 100%;
        animation: skeleton-loading 1.5s infinite;
        border-radius: 8px;
    }

    @keyframes skeleton-loading {
        0% {
            background-position: 200% 0;
        }
        100% {
            background-position: -200% 0;
        }
    }

    /* Spinner moderno */
    .spinner,
    .loading {
        width: 40px;
        height: 40px;
        border: 3px solid rgba(255, 255, 255, 0.1);
        border-top-color: #e10600;
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
    }

    @keyframes spin {
        to {
            transform: rotate(360deg);
        }
    }
}

/* ========================================
   OTTIMIZZAZIONI SPECIFICHE ANDROID
   ======================================== */

@media (display-mode: standalone) and (max-width: 768px) {
    /* Rimuovi outline focus (già gestito con box-shadow) */
    *:focus {
        outline: none !important;
    }

    /* Previeni zoom accidentale su input */
    input,
    select,
    textarea {
        font-size: 16px !important; /* Previene zoom su iOS */
    }

    /* Ottimizza rendering */
    * {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    /* Migliora performance scroll con GPU acceleration */
    .card,
    .list-group-item,
    img {
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
    
    /* Ottimizza rendering immagini */
    img {
        image-rendering: -webkit-optimize-contrast;
    }
    
    /* Riduce repaints su elementi animati */
    .pwa-bottom-nav,
    .pwa-header,
    .pwa-fab {
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }

    /* Nascondi scrollbar ma mantieni funzionalità */
    ::-webkit-scrollbar {
        width: 0;
        height: 0;
    }

    /* Pull to refresh styling */
    body {
        overscroll-behavior-y: contain;
    }
}

/* ========================================
   SKELETON LOADING
   ======================================== */

@media (display-mode: standalone) {
    /* NON sovrascrivere colori globali - usa solo per elementi specifici */
    
    /* Solo card hanno background scuro */
    .pwa-card-dark {
        background: rgba(21, 21, 30, 0.8) !important;
    }
    
    /* NON forzare colori su tutti i link - troppo invasivo */
    /* Lascia che il tema originale gestisca i colori */
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

@media (display-mode: standalone) {
    .hide-on-pwa {
        display: none !important;
    }

    .show-on-pwa {
        display: block !important;
    }

    .text-touch {
        font-size: 1rem !important;
        line-height: 1.6 !important;
    }

    .mt-safe {
        margin-top: env(safe-area-inset-top) !important;
    }

    .mb-safe {
        margin-bottom: env(safe-area-inset-bottom) !important;
    }

    .p-safe {
        padding-top: env(safe-area-inset-top) !important;
        padding-bottom: env(safe-area-inset-bottom) !important;
        padding-left: env(safe-area-inset-left) !important;
        padding-right: env(safe-area-inset-right) !important;
    }
}
/* ========================================
   LOADER INIZIALE (Prima Volta)
   ======================================== */

.pwa-initial-loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #0d0d13 0%, #1a0a0a 100%);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.pwa-initial-loader.show {
    opacity: 1;
}

.pwa-initial-loader.fade-out {
    opacity: 0;
}

.pwa-loader-content {
    text-align: center;
    padding: 40px;
}

/* Logo animato */
.pwa-logo-animate {
    width: 140px;
    height: 140px;
    margin: 0 auto 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #e10600 0%, #b00500 100%);
    border-radius: 35px;
    box-shadow: 
        0 10px 40px rgba(225, 6, 0, 0.6),
        0 0 60px rgba(225, 6, 0, 0.4),
        inset 0 0 40px rgba(255, 255, 255, 0.1);
    animation: logoEntrance 1s cubic-bezier(0.34, 1.56, 0.64, 1), logoGlow 2s ease-in-out infinite;
    position: relative;
    overflow: hidden;
}

/* Retroilluminazione pulsante */
.pwa-logo-animate::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
    animation: rotateGlow 4s linear infinite;
}

.pwa-logo-animate::after {
    content: '';
    position: absolute;
    inset: 3px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 100%);
    border-radius: 32px;
    z-index: 1;
}

.pwa-loader-icon {
    width: 80px;
    height: 80px;
    object-fit: contain;
    position: relative;
    z-index: 2;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
    animation: iconFloat 2s ease-in-out infinite;
}

@keyframes logoEntrance {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.15) rotate(10deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

@keyframes logoGlow {
    0%, 100% {
        box-shadow: 
            0 10px 40px rgba(225, 6, 0, 0.6),
            0 0 60px rgba(225, 6, 0, 0.4),
            inset 0 0 40px rgba(255, 255, 255, 0.1);
    }
    50% {
        box-shadow: 
            0 15px 50px rgba(225, 6, 0, 0.8),
            0 0 80px rgba(225, 6, 0, 0.6),
            inset 0 0 50px rgba(255, 255, 255, 0.15);
    }
}

@keyframes rotateGlow {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

@keyframes iconFloat {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-8px);
    }
}

/* Logo per esteso */
.pwa-loader-logo {
    max-width: 250px;
    height: auto;
    margin: 0 auto 15px;
    display: block;
    animation: fadeInUp 0.6s ease 0.3s both;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.5));
}

.pwa-loader-subtitle {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.7);
    margin: 0 0 40px 0;
    animation: fadeInUp 0.6s ease 0.5s both;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Spinner animato */
.pwa-loader-spinner {
    display: flex;
    justify-content: center;
    gap: 8px;
    animation: fadeInUp 0.6s ease 0.7s both;
}

.spinner-bar {
    width: 4px;
    height: 30px;
    background: linear-gradient(180deg, #e10600 0%, rgba(225, 6, 0, 0.3) 100%);
    border-radius: 2px;
    animation: barPulse 1s ease-in-out infinite;
}

.spinner-bar:nth-child(1) {
    animation-delay: 0s;
}

.spinner-bar:nth-child(2) {
    animation-delay: 0.15s;
}

.spinner-bar:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes barPulse {
    0%, 100% {
        transform: scaleY(0.5);
        opacity: 0.5;
    }
    50% {
        transform: scaleY(1);
        opacity: 1;
    }
}