/**
 * Mobile-specific styles for Esamepatente.com
 * Optimized for touch interfaces and small screens
 */

/* ============================================
   SAFE AREA SUPPORT (iPhone notch, etc.)
   ============================================ */
:root {
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

/* ============================================
   TOUCH OPTIMIZATION
   ============================================ */
@media (max-width: 1024px) {
    /* Migliora tap target (minimo 44x44px per Apple HIG) - SOLO per form elements */
    input[type="radio"],
    input[type="checkbox"],
    select {
        min-height: 44px;
        min-width: 44px;
        touch-action: manipulation;
    }

    /* Rimuovi highlight tap su iOS */
    * {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
    }

    /* Smooth scrolling */
    html {
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }

    /* Previeni zoom accidentale su input focus (iOS) */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ============================================
   BOTTOM NAVIGATION BAR (Mobile Only)
   ============================================ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(64px + var(--safe-area-bottom));
    background: white;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: var(--safe-area-bottom);
    z-index: 40;
    box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
}

.dark .bottom-nav {
    background: #1f2937;
    border-top-color: #374151;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    color: #6b7280;
    text-decoration: none;
    transition: all 0.2s;
    border-radius: 12px;
    min-width: 64px;
}

.dark .bottom-nav-item {
    color: #9ca3af;
}

.bottom-nav-item:active {
    transform: scale(0.95);
    background: #f3f4f6;
}

.dark .bottom-nav-item:active {
    background: #374151;
}

.bottom-nav-item.active {
    color: #2563eb;
}

.dark .bottom-nav-item.active {
    color: #60a5fa;
}

.bottom-nav-item svg {
    width: 24px;
    height: 24px;
    margin-bottom: 4px;
}

.bottom-nav-item span {
    font-size: 11px;
    font-weight: 600;
}

/* Spazio per bottom nav */
@media (max-width: 1024px) {
    body.has-bottom-nav {
        padding-bottom: calc(80px + var(--safe-area-bottom));
    }
}

/* ============================================
   STICKY ACTION BAR (Quiz/Simulazione)
   ============================================ */
/* Sticky su smartphone (< 768px) */
@media (max-width: 767px) {
    .sticky-action-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-top: 2px solid #e5e7eb;
        padding: 12px 16px;
        padding-bottom: calc(12px + var(--safe-area-bottom));
        z-index: 50;
        box-shadow: 0 -10px 25px -5px rgba(0, 0, 0, 0.1);
    }

    .dark .sticky-action-bar {
        background: #1f2937;
        border-top-color: #374151;
    }

    /* Spazio per sticky action bar solo su smartphone */
    .has-sticky-action {
        padding-bottom: calc(80px + var(--safe-area-bottom)) !important;
    }
}

/* Non-sticky su iPad (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .sticky-action-bar {
        position: relative;
        background: transparent;
        border-top: none;
        padding: 16px 0 0 0;
        margin-top: 24px;
        box-shadow: none;
    }

    .dark .sticky-action-bar {
        background: transparent;
        border-top: none;
    }

    /* Nessuno spazio extra su iPad */
    .has-sticky-action {
        padding-bottom: 0 !important;
    }
}

/* Stili comuni del bottone per tutti i device mobili */
@media (max-width: 1023px) {
    .sticky-action-bar button {
        width: 100%;
        padding: 16px;
        font-size: 18px;
        font-weight: 700;
        border-radius: 12px;
        transition: all 0.2s;
    }

    .sticky-action-bar button:active {
        transform: scale(0.98);
    }
}

/* ============================================
   DASHBOARD CAROUSEL (Mobile)
   ============================================ */
@media (max-width: 1024px) {
    .stats-carousel {
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE/Edge */
        padding-bottom: 16px;
    }

    .stats-carousel::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }

    .stats-carousel-item {
        scroll-snap-align: center;
        min-width: 280px;
        flex-shrink: 0;
    }

    /* Carousel dots indicator */
    .carousel-dots {
        display: flex;
        justify-content: center;
        gap: 8px;
        margin-top: 12px;
    }

    .carousel-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #d1d5db;
        transition: all 0.3s;
    }

    .carousel-dot.active {
        width: 24px;
        border-radius: 4px;
        background: #2563eb;
    }

    .dark .carousel-dot {
        background: #4b5563;
    }

    .dark .carousel-dot.active {
        background: #60a5fa;
    }
}

/* ============================================
   ENHANCED RADIO BUTTONS (Mobile)
   ============================================ */
@media (max-width: 1024px) {
    /* Opzioni risposta più grandi e touch-friendly */
    .quiz-option {
        padding: 20px !important;
        margin-bottom: 12px;
        border-radius: 16px !important;
        border-width: 3px !important;
        transition: all 0.2s;
    }

    .quiz-option:active {
        transform: scale(0.98);
        background: #eff6ff;
    }

    .dark .quiz-option:active {
        background: #1e3a8a;
    }

    .quiz-option input[type="radio"] {
        width: 24px !important;
        height: 24px !important;
        margin-top: 0 !important;
    }

    /* Animazione selezione */
    .quiz-option input[type="radio"]:checked + div {
        animation: pulse-once 0.3s ease-out;
    }

    @keyframes pulse-once {
        0%, 100% { transform: scale(1); }
        50% { transform: scale(1.02); }
    }

    /* Visual feedback per risposta selezionata */
    .quiz-option:has(input:checked) {
        background: #dbeafe !important;
        border-color: #2563eb !important;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
    }

    .dark .quiz-option:has(input:checked) {
        background: #1e3a8a !important;
        border-color: #60a5fa !important;
    }
}

/* ============================================
   FULLSCREEN TOGGLE BUTTON (Desktop Only)
   ============================================ */
@media (min-width: 1024px) {
    #fullscreen-toggle {
        position: fixed;
        top: calc(80px + var(--safe-area-top));
        right: 16px;
        width: 48px;
        height: 48px;
        border-radius: 50%;
        background: rgba(37, 99, 235, 0.9);
        color: white;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24px;
        cursor: pointer;
        z-index: 30;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        transition: all 0.2s;
    }

    #fullscreen-toggle:active {
        transform: scale(0.9);
        background: rgba(29, 78, 216, 0.9);
    }
}

/* ============================================
   SWIPE INDICATOR
   ============================================ */
@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
}

/* ============================================
   MOBILE HEADER IMPROVEMENTS
   ============================================ */
@media (max-width: 1024px) {
    /* Navbar più compatta su mobile */
    nav {
        padding-top: var(--safe-area-top);
    }

    /* Timer più visibile su mobile */
    .timer-mobile-enhanced {
        font-size: 18px;
        font-weight: 800;
        padding: 10px 16px;
        border-radius: 12px;
    }

    /* Progress bar più sottile su mobile */
    .progress-bar-mobile {
        height: 6px;
        position: fixed;
        top: calc(56px + var(--safe-area-top));
        left: 0;
        right: 0;
        z-index: 20;
    }
}

/* ============================================
   IMPROVED CARDS (Dashboard)
   ============================================ */
@media (max-width: 1024px) {
    .dashboard-card {
        border-radius: 20px;
        padding: 24px;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    }

    .dashboard-card:active {
        transform: scale(0.98);
        transition: transform 0.1s;
    }

    /* Card principale più prominente */
    .dashboard-main-card {
        background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
        color: white;
        margin: -8px -4px 16px -4px;
        border-radius: 24px;
        padding: 28px;
    }
}

/* ============================================
   LOADING SKELETON (Performance)
   ============================================ */
.skeleton {
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 8px;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.dark .skeleton {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
}

/* ============================================
   ANIMATIONS (Mobile Optimized)
   ============================================ */
@media (max-width: 1024px) {
    /* Riduce animazioni se utente preferisce reduced motion */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }

    /* Animazioni ottimizzate per mobile */
    .fade-in {
        animation: fadeIn 0.3s ease-out;
    }

    @keyframes fadeIn {
        from { opacity: 0; transform: translateY(10px); }
        to { opacity: 1; transform: translateY(0); }
    }

    .slide-up {
        animation: slideUp 0.3s ease-out;
    }

    @keyframes slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
}

/* ============================================
   UTILITY CLASSES (Mobile)
   ============================================ */
@media (max-width: 1024px) {
    .hide-scrollbar {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .hide-scrollbar::-webkit-scrollbar {
        display: none;
    }

    .safe-area-padding-top {
        padding-top: var(--safe-area-top);
    }

    .safe-area-padding-bottom {
        padding-bottom: var(--safe-area-bottom);
    }

    .touch-manipulation {
        touch-action: manipulation;
    }

    /* Evita selezione testo accidentale */
    .no-select {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
}

/* ============================================
   ACCESSIBILITY (Mobile)
   ============================================ */
@media (max-width: 1024px) {
    /* Focus visibile per navigazione keyboard */
    *:focus-visible {
        outline: 3px solid #2563eb;
        outline-offset: 2px;
    }

    .dark *:focus-visible {
        outline-color: #60a5fa;
    }

    /* Aumenta contrasto per testo su mobile */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* ============================================
   LANDSCAPE MODE OPTIMIZATIONS
   ============================================ */
@media (max-width: 1024px) and (orientation: landscape) {
    /* Riduci padding in landscape per massimizzare spazio */
    .landscape-compact {
        padding-top: 8px !important;
        padding-bottom: 8px !important;
    }

    /* Removed nav height override - navbar must maintain constant h-16 (64px) */

    .bottom-nav {
        height: calc(52px + var(--safe-area-bottom));
    }
}

/* ============================================
   PRINT STYLES (Mobile)
   ============================================ */
@media print {
    .bottom-nav,
    .sticky-action-bar,
    #fullscreen-toggle,
    nav {
        display: none !important;
    }
}
