/* Mobile Optimizations for Tables and Forms */

/* Tables responsive */
@media (max-width: 768px) {
    .table-responsive {
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    .table {
        font-size: 0.85rem;
        margin-bottom: 0;
    }
    
    .table th,
    .table td {
        padding: 0.75rem 0.5rem;
        border-bottom: 1px solid var(--border-light);
        vertical-align: middle;
    }
    
    .table th {
        background: var(--primary-light);
        color: var(--primary-dark);
        font-weight: 600;
        font-size: 0.8rem;
        white-space: nowrap;
    }
    
    /* Colonnes d'actions sur mobile */
    .table .actions-column {
        width: 100px;
        text-align: center;
    }
    
    .table .actions-column .btn {
        padding: 6px 10px;
        font-size: 0.75rem;
        margin: 2px;
    }
    
    /* Masquer certaines colonnes sur mobile */
    .table .desktop-only {
        display: none;
    }
    
    /* Style card pour les lignes importantes */
    .table .card-row {
        background: var(--white);
        border-radius: 8px;
        margin-bottom: 0.5rem;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
    
    .table .card-row td {
        border: none;
        padding: 1rem 0.75rem;
    }
    
    .table .card-row:first-child td:first-child {
        border-top-left-radius: 8px;
        border-top-right-radius: 8px;
    }
    
    .table .card-row:last-child td:first-child {
        border-bottom-left-radius: 8px;
        border-bottom-right-radius: 8px;
    }
}

/* Formulaires sur mobile */
@media (max-width: 768px) {
    .form-container {
        padding: 1rem;
    }
    
    .form-group {
        margin-bottom: 1.5rem;
    }
    
    .form-label {
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text-dark);
        margin-bottom: 0.5rem;
        display: block;
    }
    
    .form-control,
    .form-select,
    .searchable-dropdown {
        font-size: 16px; /* Évite le zoom sur iOS */
        padding: 12px 16px;
        border-radius: 8px;
        border: 2px solid var(--border);
        transition: all 0.3s ease;
        min-height: 48px; /* Taille tactile recommandée */
    }
    
    .form-control:focus,
    .form-select:focus {
        border-color: var(--primary);
        box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
        outline: none;
    }
    
    .form-text {
        font-size: 0.8rem;
        color: var(--text-muted);
        margin-top: 0.5rem;
    }
    
    /* Boutons de formulaire */
    .form-actions {
        padding: 1.5rem 0;
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    
    .btn {
        padding: 12px 24px;
        font-size: 1rem;
        font-weight: 600;
        border-radius: 8px;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        transition: all 0.3s ease;
    }
    
    .btn-primary {
        background: linear-gradient(135deg, var(--primary), var(--primary-dark));
        border: none;
        color: white;
    }
    
    .btn-primary:hover,
    .btn-primary:active {
        background: linear-gradient(135deg, var(--primary-dark), var(--primary));
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.3);
    }
    
    .btn-secondary {
        background: var(--gray-100);
        border: 2px solid var(--border);
        color: var(--text-dark);
    }
    
    .btn-secondary:hover,
    .btn-secondary:active {
        background: var(--gray-200);
        border-color: var(--gray-300);
    }
    
    .btn-danger {
        background: linear-gradient(135deg, var(--danger), var(--danger-dark));
        border: none;
        color: white;
    }
    
    /* Checkbox et radio sur mobile */
    .form-check {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 0;
        min-height: 48px;
    }
    
    .form-check-input {
        width: 20px;
        height: 20px;
        margin: 0;
        cursor: pointer;
    }
    
    .form-check-label {
        font-size: 1rem;
        cursor: pointer;
        flex-grow: 1;
    }
    
    /* Textarea */
    .form-control[type="textarea"],
    textarea.form-control {
        min-height: 120px;
        resize: vertical;
        line-height: 1.5;
    }
    
    /* File input */
    .form-control[type="file"] {
        padding: 8px 12px;
        background: var(--gray-50);
        border: 2px dashed var(--border);
    }
    
    .form-control[type="file"]:focus {
        border-style: solid;
        border-color: var(--primary);
    }
}

/* Modal sur mobile */
@media (max-width: 768px) {
    .modal {
        padding: 1rem;
    }
    
    .modal-dialog {
        margin: 0;
        width: 100%;
        max-width: none;
        height: 100vh;
        display: flex;
        align-items: stretch;
    }
    
    .modal-content {
        border-radius: 12px 12px 0 0;
        border: none;
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        max-height: 100vh;
        overflow: hidden;
    }
    
    .modal-header {
        padding: 1.5rem 1.5rem 1rem;
        border-bottom: 1px solid var(--border-light);
        flex-shrink: 0;
    }
    
    .modal-title {
        font-size: 1.2rem;
        font-weight: 700;
    }
    
    .modal-body {
        padding: 1.5rem;
        overflow-y: auto;
        flex-grow: 1;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-footer {
        padding: 1rem 1.5rem 1.5rem;
        border-top: 1px solid var(--border-light);
        flex-shrink: 0;
        display: flex;
        flex-direction: column-reverse;
        gap: 1rem;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }
    
    .close-btn,
    .btn-close {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--gray-100);
        border: none;
        color: var(--text-muted);
        font-size: 1.2rem;
    }
}

/* Pagination sur mobile */
@media (max-width: 768px) {
    .pagination-container {
        padding: 1rem 0;
    }
    
    .pagination {
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .page-item {
        margin: 0;
    }
    
    .page-link {
        padding: 10px 14px;
        font-size: 0.9rem;
        border-radius: 6px;
        border: 2px solid var(--border);
        color: var(--text-dark);
        background: var(--white);
        transition: all 0.3s ease;
        min-width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .page-link:hover,
    .page-link:focus {
        background: var(--primary-light);
        border-color: var(--primary);
        color: var(--primary-dark);
        text-decoration: none;
    }
    
    .page-item.active .page-link {
        background: var(--primary);
        border-color: var(--primary);
        color: white;
    }
    
    .page-item.disabled .page-link {
        background: var(--gray-100);
        border-color: var(--gray-300);
        color: var(--text-muted);
        cursor: not-allowed;
    }
    
    /* Simplifier la pagination sur très petits écrans */
    .pagination-simple {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
    }
    
    .pagination-info {
        font-size: 0.85rem;
        color: var(--text-muted);
        text-align: center;
        flex-grow: 1;
    }
}

/* Dropdown et Select sur mobile */
@media (max-width: 768px) {
    .dropdown-menu {
        border-radius: 12px;
        border: none;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
        padding: 0.5rem 0;
        max-height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .dropdown-item {
        padding: 12px 20px;
        font-size: 1rem;
        color: var(--text-dark);
        transition: all 0.2s ease;
        display: flex;
        align-items: center;
        gap: 12px;
        min-height: 48px;
    }
    
    .dropdown-item:hover,
    .dropdown-item:focus {
        background: var(--primary-light);
        color: var(--primary-dark);
    }
    
    .dropdown-item.active {
        background: var(--primary);
        color: white;
    }
    
    .dropdown-divider {
        margin: 0.5rem 0;
        border-color: var(--border-light);
    }
    
    /* Select personnalisé */
    .form-select {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
        background-repeat: no-repeat;
        background-position: right 16px center;
        background-size: 16px 12px;
        padding-right: 48px;
    }
    
    .form-select:focus {
        box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
    }
}

/* Loading states sur mobile */
@media (max-width: 768px) {
    .loading-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(255, 255, 255, 0.9);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 9999;
        backdrop-filter: blur(4px);
    }
    
    .loading-spinner {
        width: 48px;
        height: 48px;
        border: 4px solid var(--border-light);
        border-top-color: var(--primary);
        border-radius: 50%;
        animation: spin 1s linear infinite;
    }
    
    @keyframes spin {
        to { transform: rotate(360deg); }
    }
    
    .loading-text {
        font-size: 1rem;
        color: var(--text-muted);
        text-align: center;
        margin-top: 1rem;
    }
}

/* Toast notifications sur mobile */
@media (max-width: 768px) {
    .toast-container {
        position: fixed;
        top: calc(var(--mobile-header-height) + 1rem);
        left: 1rem;
        right: 1rem;
        z-index: 9998;
    }
    
    .toast {
        border-radius: 12px;
        border: none;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
        margin-bottom: 1rem;
        font-size: 0.9rem;
    }
    
    .toast-header {
        padding: 1rem 1rem 0.5rem;
        background: transparent;
        border-bottom: none;
    }
    
    .toast-body {
        padding: 0.5rem 1rem 1rem;
    }
}

/* Accessibilité tactile */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .form-control,
    .form-select,
    .page-link,
    .dropdown-item,
    .form-check-input {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Espacement tactile pour les petits éléments */
    .close-btn,
    .btn-sm,
    .pagination .page-link {
        padding: 12px;
    }
}
