/* ============================================
   MOBILE RESPONSIVE STYLES
   Ottimizzazione completa per web app mobile
   ============================================ */

/* Hamburger Menu Button */
.hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
    padding: 10px;
    z-index: 1002;
    background: transparent;
    border: none;
}

.hamburger span {
    width: 28px;
    height: 3px;
    background: var(--text-light);
    border-radius: 3px;
    transition: all 0.3s ease;
}

.hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translateY(11px);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translateY(-11px);
}

/* Mobile Overlay */
.mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: -1;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0s 0.3s;
    pointer-events: none;
}

.mobile-overlay.active {
    z-index: 999;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0s 0s;
    pointer-events: auto;
}

/* ==================== RESPONSIVE BREAKPOINTS ==================== */

/* Tablet - 1024px and below */
@media (max-width: 1024px) {
    .container {
        padding: 0 15px;
    }
    
    /* Cards grid 2 columns on tablet */
    .team-grid,
    .lega-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
}

/* Mobile - 768px and below */
@media (max-width: 768px) {
    /* Show hamburger menu */
    .hamburger {
        display: flex;
    }
    
    /* Navbar adjustments */
    .navbar .container {
        position: relative;
    }
    
    .logo-img {
        height: 28px;
    }
    
    .logo-text {
        font-size: 1.4rem;
    }
    
    /* Mobile menu */
    .nav-menu {
        position: fixed;
        top: 0;
        right: -100%;
        width: 80%;
        max-width: 320px;
        height: 100vh;
        background: var(--secondary);
        flex-direction: column;
        align-items: flex-start;
        padding: 80px 2rem 2rem;
        gap: 0;
        transition: right 0.3s ease;
        overflow-y: auto;
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.5);
        z-index: 1001;
    }
    
    .nav-menu.active {
        right: 0;
    }
    
    .nav-menu > li {
        width: 100%;
        border-bottom: 1px solid var(--border);
    }
    
    .nav-menu > li > a {
        display: block;
        padding: 1rem 0;
        width: 100%;
        color: var(--text-light);
        font-size: 1.1rem;
    }
    
    /* User menu in mobile */
    .user-menu {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        background: transparent;
        padding: 1rem 0;
        width: 100%;
    }
    
    .user-menu .username {
        font-size: 1.1rem;
    }
    
    .user-menu .badge {
        align-self: flex-start;
    }
    
    .user-menu .dropdown {
        position: static;
        width: 100%;
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
        background: var(--bg-card);
        border-radius: 8px;
        padding: 0.5rem;
        margin-top: 0.5rem;
        box-shadow: none;
    }
    
    .user-menu .dropdown a {
        padding: 0.75rem;
        font-size: 1rem;
    }
    
    /* Notification bell in mobile menu */
    .notification-bell {
        margin-bottom: 1rem;
    }
    
    /* Auth buttons */
    .btn-login,
    .btn-register {
        width: 100%;
        text-align: center;
        padding: 0.75rem 1rem;
        margin: 0.5rem 0;
    }
    
    /* Cards - Single column on mobile */
    .team-grid,
    .lega-grid,
    .feature-grid,
    .stats-grid,
    .races-grid,
    .profile-grid,
    .cars-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    /* Hero sections */
    .hero {
        padding: 3rem 0;
    }
    
    .hero h1 {
        font-size: 2rem;
        line-height: 1.2;
    }
    
    .hero p {
        font-size: 1rem;
    }
    
    /* Profile hero */
    .profile-hero {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }
    
    .profile-avatar {
        width: 100px;
        height: 100px;
    }
    
    /* Forms */
    .form-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .form-group {
        margin-bottom: 1.25rem;
    }
    
    .form-group label {
        font-size: 1rem;
        margin-bottom: 0.5rem;
        display: block;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 0.875rem;
        width: 100%;
        border-radius: 8px;
    }
    
    .form-group textarea {
        min-height: 120px;
        resize: vertical;
    }
    
    /* Better checkbox and radio buttons on mobile */
    .form-check-input {
        width: 24px;
        height: 24px;
        margin-right: 0.75rem;
    }
    
    .form-check-label {
        font-size: 1rem;
        line-height: 1.5;
    }
    
    /* Color picker on mobile */
    input[type="color"] {
        width: 100%;
        height: 60px;
        border: none;
        border-radius: 8px;
        cursor: pointer;
    }
    
    /* File inputs */
    input[type="file"] {
        padding: 1rem;
        border: 2px dashed var(--border);
        border-radius: 8px;
        cursor: pointer;
    }
    
    .btn {
        width: 100%;
        padding: 1rem;
        font-size: 1rem;
        min-height: 48px;
        border-radius: 8px;
        font-weight: 600;
    }
    
    .btn-group {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .btn-group .btn {
        width: 100%;
    }
    
    /* Modals */
    .modal-content {
        width: 95%;
        max-width: 100%;
        max-height: 90vh;
        margin: 5vh auto;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    /* Tables - Scroll horizontally */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
    }
    
    table {
        min-width: 600px;
        font-size: 0.85rem;
        display: block;
        overflow-x: auto;
    }
    
    table thead {
        position: sticky;
        top: 0;
        background: var(--bg-card);
        z-index: 10;
    }
    
    table th,
    table td {
        padding: 0.75rem 0.5rem;
        white-space: nowrap;
    }
    
    /* Alternative: Card layout for tables on mobile */
    .table-card-mobile {
        display: none;
    }
    
    @supports (display: grid) {
        .table-card-mobile {
            display: block;
        }
        
        .table-card-mobile .table-card-item {
            background: var(--bg-card);
            border-radius: 8px;
            padding: 1rem;
            margin-bottom: 1rem;
            border: 1px solid var(--border);
        }
        
        .table-card-mobile .table-card-row {
            display: flex;
            justify-content: space-between;
            padding: 0.5rem 0;
            border-bottom: 1px solid var(--border);
        }
        
        .table-card-mobile .table-card-row:last-child {
            border-bottom: none;
        }
        
        .table-card-mobile .table-card-label {
            font-weight: 600;
            color: var(--text-gray);
        }
        
        .table-card-mobile .table-card-value {
            color: var(--text-light);
            text-align: right;
        }
    }
    
    /* Calendar filters */
    .year-selector,
    .race-filter {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .year-selector button {
        width: 100%;
    }
    
    /* Stats grid */
    .profile-stats {
        grid-template-columns: 1fr;
    }
    
    /* Super admin bar */
    .super-admin-bar {
        display: none; /* Hide on mobile or make scrollable */
    }
    
    /* Notifications popup */
    .notifications-popup {
        right: 0;
        left: 0;
        width: 100vw;
        max-width: 100vw;
        border-radius: 0;
        max-height: 70vh;
        top: 70px;
    }
    
    .notification-item {
        padding: 1rem;
        border-radius: 8px;
    }
    
    .notification-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .notification-actions {
        width: 100%;
        display: flex;
        gap: 0.5rem;
        margin-top: 0.75rem;
    }
    
    .notification-actions button {
        flex: 1;
        padding: 0.75rem;
        font-size: 0.9rem;
    }
    
    /* Flash messages on mobile */
    .flash-messages {
        position: fixed;
        top: 70px;
        left: 0;
        right: 0;
        z-index: 9999;
        padding: 0 1rem;
    }
    
    .alert {
        padding: 1rem;
        font-size: 0.95rem;
        border-radius: 8px;
        margin-bottom: 0.5rem;
    }
    
    .alert-close {
        font-size: 1.5rem;
        padding: 0 0.5rem;
    }
    
    /* Team/Lega detail headers */
    .team-header,
    .lega-header {
        flex-direction: column;
        padding: 2rem 1rem;
    }
    
    .team-logo,
    .lega-logo {
        width: 80px;
        height: 80px;
        font-size: 2rem;
    }
    
    .team-actions,
    .lega-actions {
        width: 100%;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .btn-action {
        width: 100%;
        justify-content: center;
    }
    
    /* Event cards */
    .evento-item {
        padding: 1rem;
    }
    
    /* Championship creation */
    .gare-container {
        padding: 1rem;
        gap: 1rem;
    }
    
    .gara-card {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .gara-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }
    
    .gara-header h3 {
        font-size: 1.1rem;
    }
    
    .gara-actions {
        width: 100%;
        display: flex;
        gap: 0.5rem;
    }
    
    .gara-actions button {
        flex: 1;
        padding: 0.75rem 0.5rem;
        font-size: 0.9rem;
    }
    
    /* Race details in gara card */
    .gara-details {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        margin-top: 1rem;
    }
    
    .gara-detail-item {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 6px;
    }
    
    /* Circuito/Auto selection modals on mobile */
    .cars-modal,
    .circuiti-modal {
        padding: 1rem;
    }
    
    .cars-modal-grid,
    .circuiti-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .car-modal-card,
    .circuito-card {
        padding: 0.75rem;
    }
    
    .car-modal-image,
    .circuito-image {
        height: 120px;
    }
    
    /* Search and filter on mobile */
    .search-filter-container {
        flex-direction: column;
        gap: 1rem;
    }
    
    .search-input,
    .filter-select {
        width: 100%;
        font-size: 16px;
        padding: 0.875rem;
    }
}

/* Small mobile - 480px and below */
@media (max-width: 480px) {
    .logo-img {
        height: 24px;
    }
    
    .logo-text {
        font-size: 1.2rem;
    }
    
    .nav-menu {
        width: 90%;
        padding: 70px 1.5rem 1.5rem;
    }
    
    .hero h1 {
        font-size: 1.75rem;
    }
    
    .modal-content {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
    }
    
    /* Smaller cards padding */
    .card,
    .team-card,
    .lega-card {
        padding: 1rem;
    }
    
    /* Tighter spacing */
    .content-section {
        padding: 2rem 0;
    }
    
    /* Car cards 1 column on very small screens */
    .cars-modal-grid {
        grid-template-columns: 1fr;
    }
}

/* Landscape mobile - max-height */
@media (max-height: 600px) and (orientation: landscape) {
    .nav-menu {
        padding: 60px 1.5rem 1rem;
        font-size: 0.95rem;
    }
    
    .nav-menu > li > a {
        padding: 0.75rem 0;
    }
    
    .hero {
        padding: 2rem 0;
    }
}

/* Touch improvements */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .btn,
    button,
    a.btn-action {
        min-height: 44px;
        padding: 0.75rem 1.5rem;
    }
    
    /* Remove hover effects on touch devices */
    .card:hover,
    .team-card:hover,
    .lega-card:hover {
        transform: none;
    }
    
    /* Tap highlight color */
    * {
        -webkit-tap-highlight-color: rgba(225, 6, 0, 0.2);
    }
}
