/* =============================================================================
   RESPONSIVE DESIGN (MOBILE & TABLET)
   ============================================================================= */

@media (max-width: 768px) {
    /* Header adjustments */
    .header-content {
        padding: 0 10px;
    }
    
    .logo-title {
        font-size: 1.1rem;
    }
    
    .logo-title .clover-icon {
        width: 32px;
        height: 32px;
        margin-bottom: 0;
        margin-right: 5px;
    }
    
    /* Hide user info on mobile to save space */
    #user-info {
        display: none;
    }
    
    /* Compact nav */
    .header-content nav {
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    /* Smaller icons in nav */
    .header-content nav a,
    .header-content nav i#whatsapp-message {
        font-size: 1.2rem !important;
        margin-right: 5px !important;
    }
    
    /* Compact logout button */
    #logout-button {
        padding: 5px 10px;
        font-size: 0.9rem;
    }

    .logo-title span {
        /* Keep title visible but maybe smaller */
        font-size: 1rem;
    }
    
    /* Tab strip scrollable */
    .tab-strip {
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 5px;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }
    
    /* Quadrifoglio selector stacking */
    .quadrifoglio-selector {
        flex-direction: column;
        align-items: stretch;
    }

    /* Fix for select width on mobile */
    .quadrifoglio-select-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    .quadrifoglio-select-group select {
        width: 100%;
        max-width: 100%; /* Crucial for preventing overflow */
    }

    .controls-row {
        flex-direction: column;
        align-items: stretch;
    }
    .section-filter-group, .actions-group {
        width: 100%;
        justify-content: space-between;
    }
    .actions-group .btn {
        flex: 1;
    }

    /* Table to Cards transformation for Contributi */
    .contributi-table, 
    .contributi-table thead, 
    .contributi-table tbody, 
    .contributi-table th, 
    .contributi-table td, 
    .contributi-table tr { 
        display: block; 
    }
    
    /* Hide table headers visually */
    .contributi-table thead tr { 
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    .contributi-table tr { 
        border: 1px solid #ddd; 
        margin-bottom: 15px; 
        border-radius: 8px;
        background: #fff;
        padding: 15px;
        position: relative;
        box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    }
    
    /* Hide content preview row on mobile to save space, or style it differently */
    .contributi-table tr.content-preview-row {
        display: none; 
    }

    .contributi-table td { 
        /* Behave like a "row" */
        border: none;
        border-bottom: 1px solid #eee; 
        position: relative;
        padding-left: 40%; 
        text-align: right; 
        white-space: normal;
        min-height: 35px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
    }
    
    .contributi-table td:last-child {
        border-bottom: none;
    }
    
    .contributi-table td:before { 
        /* Now like a table header */
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        left: 10px;
        width: 35%; 
        padding-right: 10px; 
        white-space: nowrap;
        text-align: left;
        font-weight: 600;
        content: attr(data-label);
        color: #555;
    }

    /* Specific adjustments for columns */
    
    /* ID: Hide or keep small */
    .contributi-table td[data-label="ID"] { 
        display: none; 
    } 
    
    /* Drag Handle: Position absolute top right */
    .contributi-table td[data-label="Sposta"] {
        position: absolute;
        top: 10px;
        right: 10px;
        width: auto;
        padding: 0;
        border: none;
        min-height: auto;
    }
    .contributi-table td[data-label="Sposta"]:before { content: none; }

    /* Titolo: Prominent at top */
    .contributi-table td[data-label="Titolo"] {
        display: block;
        text-align: left;
        padding-left: 0;
        padding-right: 30px; /* Space for drag handle */
        font-size: 1.1rem;
        font-weight: 600;
        color: var(--primary-dark);
        border-bottom: 2px solid var(--primary-color);
        margin-bottom: 10px;
        padding-bottom: 10px;
    }
    .contributi-table td[data-label="Titolo"]:before { content: none; }
    
    /* Azioni: Bottom row, full width buttons */
    .contributi-table td[data-label="Azioni"] {
        padding-left: 0;
        justify-content: space-around;
        margin-top: 10px;
        border-top: 1px solid #eee;
        padding-top: 10px;
    }
    .contributi-table td[data-label="Azioni"]:before { content: none; }
    
    .contributi-table td[data-label="Azioni"] .btn-icon {
        font-size: 1.2rem;
        padding: 10px;
        background-color: #f8f9fa;
        border-radius: 50%;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Modal adjustments */
    .modal-content {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }
    
    .modal-body {
        flex: 1;
        overflow-y: auto;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    /* Export section */
    .export-section {
        flex-direction: column;
        align-items: stretch;
    }
    .export-section .form-group {
        width: 100%;
        justify-content: space-between;
    }
}
